Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
jhedmonton
Date:
Wed Jan 21 02:54:26 2015 +0000
Revision:
28:5905886c76ee
Parent:
26:dc00998140af
Child:
30:3afafa1ef16b
Changes to config, adding a base.cpp to move globals

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