Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
maximbolduc
Date:
Sat Mar 14 17:57:42 2015 +0000
Revision:
52:2b44e1b2f33b
Parent:
35:f9caeb8ca31e
Child:
53:7b17d99ba7ee
fixed motor direction

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
maximbolduc 52:2b44e1b2f33b 34 fprintf(fp, "$ID,%d\r\n",_ID);//address
maximbolduc 52:2b44e1b2f33b 35 fprintf(fp, "$BTMODE,%d\r\n",_btMode);//bluetooth mode
maximbolduc 52:2b44e1b2f33b 36
maximbolduc 52:2b44e1b2f33b 37 fprintf(fp, "$PA,%f\r\n",phaseadv);//phase advance
maximbolduc 52:2b44e1b2f33b 38 fprintf(fp, "$TC,%f\r\n",tcenter);//tcenter
maximbolduc 52:2b44e1b2f33b 39 fprintf(fp, "$FG,%f\r\n",fgain);//filter gain
maximbolduc 52:2b44e1b2f33b 40 fprintf(fp, "$SC,%f\r\n",scale);//scale
maximbolduc 52:2b44e1b2f33b 41 fprintf(fp, "$AP,%f\r\n",avgpos);//avgpos
maximbolduc 52:2b44e1b2f33b 42 fprintf(fp,"$GYRO,%i\r\n",gyro_pos);
maximbolduc 52:2b44e1b2f33b 43 fprintf(fp,"$GPSBAUD,%d\r\n",gps_baud);
maximbolduc 52:2b44e1b2f33b 44 fprintf(fp,"$HEIGHT,%f\r\n",antennaheight);
maximbolduc 52:2b44e1b2f33b 45 fprintf(fp,"$PID,%f,%f,%f\r\n", kp,ki,kd);
maximbolduc 52:2b44e1b2f33b 46 fprintf(fp, "$LOOKA,%f\r\n", lookaheadtime);//lookahead time
maximbolduc 52:2b44e1b2f33b 47
jhedmonton 28:5905886c76ee 48 fclose(fp);
jhedmonton 28:5905886c76ee 49 }
jhedmonton 28:5905886c76ee 50
jhedmonton 28:5905886c76ee 51 int Config_SetID()
jhedmonton 28:5905886c76ee 52 {
jhedmonton 28:5905886c76ee 53 char mac[6];
jhedmonton 28:5905886c76ee 54 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 55 return( mac[3] << 16 | mac[4] << 8 | mac[5] << 0);
jhedmonton 28:5905886c76ee 56 }
jhedmonton 28:5905886c76ee 57
jhedmonton 28:5905886c76ee 58 int Config_GetID()
jhedmonton 28:5905886c76ee 59 {
jhedmonton 28:5905886c76ee 60 char mac[6];
jhedmonton 28:5905886c76ee 61 mbed_mac_address(mac);
jhedmonton 28:5905886c76ee 62 int id = mac[3] << 16 | mac[4] << 8 | mac[5] << 0; // Bytes 4-6 form the unique idenfitfier
jhedmonton 28:5905886c76ee 63
jhedmonton 28:5905886c76ee 64 return id;
jhedmonton 28:5905886c76ee 65 }