Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
maximbolduc
Date:
Tue Jan 27 12:22:10 2015 +0000
Revision:
30:3afafa1ef16b
Parent:
28:5905886c76ee
Child:
32:c57bc701d65c
Added a bunch f little stuff and cleaned the code.; Distance from line as well as psoition from line(right, left,on) is now working as well.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maximbolduc 26:dc00998140af 1 #include "mbed.h"
maximbolduc 26:dc00998140af 2 #include <string>
maximbolduc 26:dc00998140af 3 #include "Config.h"
jhedmonton 28:5905886c76ee 4 #include "base.h"
jhedmonton 28:5905886c76ee 5
maximbolduc 26:dc00998140af 6 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
maximbolduc 30:3afafa1ef16b 7 char* line;
jhedmonton 28:5905886c76ee 8
maximbolduc 26:dc00998140af 9 void Config_Startup()
maximbolduc 26:dc00998140af 10 {
maximbolduc 26:dc00998140af 11 FILE * fp;
maximbolduc 26:dc00998140af 12 char line[256];
jhedmonton 28:5905886c76ee 13
maximbolduc 26:dc00998140af 14 //fp = fopen("/local/config.txt", "w");
maximbolduc 26:dc00998140af 15 //fprintf(fp, "BT,000666624C6A\r\nPA,0\r\nTC,4.5\r\nFG,30\r\nSC,2.7\r\nAP,-4"); //Rewrite text file for TESTING
maximbolduc 26:dc00998140af 16 //fclose(fp);
jhedmonton 28:5905886c76ee 17
maximbolduc 26:dc00998140af 18 fp = fopen("/local/config.txt", "r");
jhedmonton 28:5905886c76ee 19
maximbolduc 26:dc00998140af 20 while (fgets(line, sizeof(line), fp)) //Read through config file line by line
maximbolduc 26:dc00998140af 21 Dispatch(line, true); //Send line to dispatcher, true indicates its coming from the config file
jhedmonton 28:5905886c76ee 22
maximbolduc 26:dc00998140af 23 fclose(fp);
maximbolduc 26:dc00998140af 24 }
jhedmonton 28:5905886c76ee 25
jhedmonton 28:5905886c76ee 26 void Config_Save()
maximbolduc 26:dc00998140af 27 {
jhedmonton 28:5905886c76ee 28 FILE * fp;
jhedmonton 28:5905886c76ee 29 fp = fopen("/local/config.txt", "w");
jhedmonton 28:5905886c76ee 30
maximbolduc 30:3afafa1ef16b 31 //sprintf("$ID,%d\r\n$BTMODE,%d\r\n$PA,%f\r\n$TC,%f\r\n
jhedmonton 28:5905886c76ee 32 fprintf(fp, "$ID,%d\r\n",_ID);//address
jhedmonton 28:5905886c76ee 33 fprintf(fp, "$BTMODE,%d\r\n",_btMode);//bluetooth mode
jhedmonton 28:5905886c76ee 34 fprintf(fp, "$PA,%f\r\n",phaseadv);//phase advance
jhedmonton 28:5905886c76ee 35 fprintf(fp, "$TC,%f\r\n",tcenter);//tcenter
jhedmonton 28:5905886c76ee 36 fprintf(fp, "$FG,%f\r\n",fgain);//filter gain
jhedmonton 28:5905886c76ee 37 fprintf(fp, "$SC,%f\r\n",scale);//scale
jhedmonton 28:5905886c76ee 38 fprintf(fp, "$AP,%f\r\n",avgpos);//avgpos
jhedmonton 28:5905886c76ee 39
jhedmonton 28:5905886c76ee 40 fprintf(fp,"$GYRO,%i\r\n",gyro_position);
jhedmonton 28:5905886c76ee 41 fprintf(fp,"$GPSBAUD,%d\r\n",gps_baud);
maximbolduc 30:3afafa1ef16b 42 fprintf(fp,"$HEIGHT,%f\r\n",antennaheight);
maximbolduc 30:3afafa1ef16b 43 fprintf(fp,"$a_zBias,%f\r\n",a_zBias);
maximbolduc 30:3afafa1ef16b 44 fprintf(fp,"$a_yBias,%f\r\n",a_yBias);
maximbolduc 30:3afafa1ef16b 45 fprintf(fp,"$a_zBias,%f\r\n",a_zBias);
maximbolduc 30:3afafa1ef16b 46 fprintf(fp,"$w_xBias,%f\r\n",w_xBias);
maximbolduc 30:3afafa1ef16b 47 fprintf(fp,"$w_yBias,%f\r\n",w_yBias);
maximbolduc 30:3afafa1ef16b 48 fprintf(fp,"$w_zBias,%f\r\n",w_zBias);
jhedmonton 28:5905886c76ee 49
jhedmonton 28:5905886c76ee 50 fclose(fp);
jhedmonton 28:5905886c76ee 51 }
jhedmonton 28:5905886c76ee 52
jhedmonton 28:5905886c76ee 53 int Config_SetID()
jhedmonton 28:5905886c76ee 54 {
jhedmonton 28:5905886c76ee 55 char mac[6];
jhedmonton 28:5905886c76ee 56 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 57 return( mac[3] << 16 | mac[4] << 8 | mac[5] << 0);
jhedmonton 28:5905886c76ee 58 }
jhedmonton 28:5905886c76ee 59
jhedmonton 28:5905886c76ee 60 int Config_GetID()
jhedmonton 28:5905886c76ee 61 {
jhedmonton 28:5905886c76ee 62 char mac[6];
jhedmonton 28:5905886c76ee 63 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 64 int id = mac[3] << 16 | mac[4] << 8 | mac[5] << 0; // Bytes 4-6 form the unique idenfitfier
jhedmonton 28:5905886c76ee 65
jhedmonton 28:5905886c76ee 66 return id;
jhedmonton 28:5905886c76ee 67 }