Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Committer:
maximbolduc
Date:
Fri Jan 16 17:26:07 2015 +0000
Revision:
26:dc00998140af
Child:
28:5905886c76ee
added some stuff

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"
maximbolduc 26:dc00998140af 4
maximbolduc 26:dc00998140af 5 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
maximbolduc 26:dc00998140af 6
maximbolduc 26:dc00998140af 7 void Config_Startup()
maximbolduc 26:dc00998140af 8 {
maximbolduc 26:dc00998140af 9 FILE * fp;
maximbolduc 26:dc00998140af 10 char line[256];
maximbolduc 26:dc00998140af 11
maximbolduc 26:dc00998140af 12 //fp = fopen("/local/config.txt", "w");
maximbolduc 26:dc00998140af 13 //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 14 //fclose(fp);
maximbolduc 26:dc00998140af 15
maximbolduc 26:dc00998140af 16 fp = fopen("/local/config.txt", "r");
maximbolduc 26:dc00998140af 17
maximbolduc 26:dc00998140af 18 while (fgets(line, sizeof(line), fp)) //Read through config file line by line
maximbolduc 26:dc00998140af 19 Dispatch(line, true); //Send line to dispatcher, true indicates its coming from the config file
maximbolduc 26:dc00998140af 20
maximbolduc 26:dc00998140af 21 fclose(fp);
maximbolduc 26:dc00998140af 22 }
maximbolduc 26:dc00998140af 23
maximbolduc 26:dc00998140af 24
maximbolduc 26:dc00998140af 25 void Dispatch(char* line, bool config /* = false */)
maximbolduc 26:dc00998140af 26 {
maximbolduc 26:dc00998140af 27 char* pointer;
maximbolduc 26:dc00998140af 28 char* Data[5]; //Can have max of 5 peices of data split by commas
maximbolduc 26:dc00998140af 29 int index = 0;
maximbolduc 26:dc00998140af 30
maximbolduc 26:dc00998140af 31 //Split data at commas
maximbolduc 26:dc00998140af 32 pointer = strtok(line, ",");
maximbolduc 26:dc00998140af 33 while(pointer != NULL) {
maximbolduc 26:dc00998140af 34 Data[index] = pointer;
maximbolduc 26:dc00998140af 35 pointer = strtok(NULL, ",");
maximbolduc 26:dc00998140af 36 index++;
maximbolduc 26:dc00998140af 37 }
maximbolduc 26:dc00998140af 38
maximbolduc 26:dc00998140af 39 //Check ID of read data and set the corresponding variable.
maximbolduc 26:dc00998140af 40 if(strcmp(Data[0], "BT") == 0) {
maximbolduc 26:dc00998140af 41 //Check BT adress here
maximbolduc 26:dc00998140af 42 } else {
maximbolduc 26:dc00998140af 43 //Unrecognized config setting detected.
maximbolduc 26:dc00998140af 44 }
maximbolduc 26:dc00998140af 45 }