Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
maximbolduc
Date:
Sat Feb 21 13:47:37 2015 +0000
Revision:
35:f9caeb8ca31e
Parent:
Config.cpp@34:c2bc9f9be7ff
Child:
52:2b44e1b2f33b
little basic autosteer routine

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 34:c2bc9f9be7ff 21 {
maximbolduc 34:c2bc9f9be7ff 22
maximbolduc 34:c2bc9f9be7ff 23 pc.puts(line);
maximbolduc 26:dc00998140af 24 Dispatch(line, true); //Send line to dispatcher, true indicates its coming from the config file
maximbolduc 34:c2bc9f9be7ff 25 }
maximbolduc 26:dc00998140af 26 fclose(fp);
maximbolduc 26:dc00998140af 27 }
jhedmonton 28:5905886c76ee 28
jhedmonton 28:5905886c76ee 29 void Config_Save()
maximbolduc 26:dc00998140af 30 {
jhedmonton 28:5905886c76ee 31 FILE * fp;
jhedmonton 28:5905886c76ee 32 fp = fopen("/local/config.txt", "w");
maximbolduc 30:3afafa1ef16b 33 //sprintf("$ID,%d\r\n$BTMODE,%d\r\n$PA,%f\r\n$TC,%f\r\n
jhedmonton 28:5905886c76ee 34 fprintf(fp, "$ID,%d\r\n",_ID);//address
jhedmonton 28:5905886c76ee 35 fprintf(fp, "$BTMODE,%d\r\n",_btMode);//bluetooth mode
jhedmonton 28:5905886c76ee 36 fprintf(fp, "$PA,%f\r\n",phaseadv);//phase advance
jhedmonton 28:5905886c76ee 37 fprintf(fp, "$TC,%f\r\n",tcenter);//tcenter
jhedmonton 28:5905886c76ee 38 fprintf(fp, "$FG,%f\r\n",fgain);//filter gain
jhedmonton 28:5905886c76ee 39 fprintf(fp, "$SC,%f\r\n",scale);//scale
jhedmonton 28:5905886c76ee 40 fprintf(fp, "$AP,%f\r\n",avgpos);//avgpos
maximbolduc 32:c57bc701d65c 41 fprintf(fp,"$GYRO,%i\r\n",gyro_pos);
jhedmonton 28:5905886c76ee 42 fprintf(fp,"$GPSBAUD,%d\r\n",gps_baud);
maximbolduc 30:3afafa1ef16b 43 fprintf(fp,"$HEIGHT,%f\r\n",antennaheight);
jhedmonton 28:5905886c76ee 44 fclose(fp);
jhedmonton 28:5905886c76ee 45 }
jhedmonton 28:5905886c76ee 46
jhedmonton 28:5905886c76ee 47 int Config_SetID()
jhedmonton 28:5905886c76ee 48 {
jhedmonton 28:5905886c76ee 49 char mac[6];
jhedmonton 28:5905886c76ee 50 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 51 return( mac[3] << 16 | mac[4] << 8 | mac[5] << 0);
jhedmonton 28:5905886c76ee 52 }
jhedmonton 28:5905886c76ee 53
jhedmonton 28:5905886c76ee 54 int Config_GetID()
jhedmonton 28:5905886c76ee 55 {
jhedmonton 28:5905886c76ee 56 char mac[6];
jhedmonton 28:5905886c76ee 57 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 58 int id = mac[3] << 16 | mac[4] << 8 | mac[5] << 0; // Bytes 4-6 form the unique idenfitfier
jhedmonton 28:5905886c76ee 59
jhedmonton 28:5905886c76ee 60 return id;
jhedmonton 28:5905886c76ee 61 }