Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Revision:
28:5905886c76ee
Parent:
26:dc00998140af
Child:
30:3afafa1ef16b
--- a/Config.cpp	Mon Jan 19 01:35:34 2015 +0000
+++ b/Config.cpp	Wed Jan 21 02:54:26 2015 +0000
@@ -1,45 +1,68 @@
 #include "mbed.h"
 #include <string>
 #include "Config.h"
- 
+#include "base.h"
+
 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
- 
+
 void Config_Startup()
 {
     FILE * fp;
     char line[256];
- 
+
     //fp = fopen("/local/config.txt", "w");
     //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
     //fclose(fp);
-    
+
     fp = fopen("/local/config.txt", "r");
-    
+
     while (fgets(line, sizeof(line), fp)) //Read through config file line by line
         Dispatch(line, true); //Send line to dispatcher, true indicates its coming from the config file
- 
+
     fclose(fp);
 }
- 
- 
-void Dispatch(char* line, bool config /* = false */)
+
+void Config_Save()
 {
-    char* pointer;
-    char* Data[5]; //Can have max of 5 peices of data split by commas
-    int index = 0;
- 
-    //Split data at commas
-    pointer = strtok(line, ",");
-    while(pointer != NULL) {
-        Data[index] = pointer;
-        pointer = strtok(NULL, ",");
-        index++;
-    }
- 
-    //Check ID of read data and set the corresponding variable.
-    if(strcmp(Data[0], "BT") == 0) {
-        //Check BT adress here
-    } else {
-        //Unrecognized config setting detected.
-    }
-}
\ No newline at end of file
+    FILE * fp;
+    fp = fopen("/local/config.txt", "w");
+    
+    fprintf(fp, "$ID,%d\r\n",_ID);//address
+    fprintf(fp, "$BTMODE,%d\r\n",_btMode);//bluetooth mode
+    fprintf(fp, "$PA,%f\r\n",phaseadv);//phase advance
+    fprintf(fp, "$TC,%f\r\n",tcenter);//tcenter
+    fprintf(fp, "$FG,%f\r\n",fgain);//filter gain
+    fprintf(fp, "$SC,%f\r\n",scale);//scale
+    fprintf(fp, "$AP,%f\r\n",avgpos);//avgpos
+
+    fprintf(fp,"$GYRO,%i\r\n",gyro_position);
+    fprintf(fp,"$GPSBAUD,%d\r\n",gps_baud);
+    fprintf(fp,"$HEIGHT,%d\r\n",antennaheight);
+    fprintf(fp,"$a_zBias,%d\r\n",a_zBias);
+    fprintf(fp,"$a_yBias,%d\r\n",a_yBias);
+    fprintf(fp,"$a_zBias,%d\r\n",a_zBias);
+    fprintf(fp,"$w_xBias,%d\r\n",w_xBias);
+    fprintf(fp,"$w_yBias,%d\r\n",w_yBias);
+    fprintf(fp,"$w_zBias,%d\r\n",w_zBias);
+   
+
+    fclose(fp);
+    
+    
+}
+
+int Config_SetID()
+{
+    char mac[6];
+    mbed_mac_address(mac);
+    return( mac[3] << 16 | mac[4] << 8  | mac[5] << 0);
+} 
+
+int Config_GetID()
+{
+    char mac[6];
+    mbed_mac_address(mac);
+    int id = mac[3] << 16 | mac[4] << 8  | mac[5] << 0; // Bytes 4-6 form the unique idenfitfier
+
+    return id;
+}