Agra-GPS / FreePilot_V2-3

Dependencies:   FreePilot PinDetect mbed-src

Fork of FreePilot_V2-2 by Agra-GPS

Config.cpp

Committer:
maximbolduc
Date:
2015-01-16
Revision:
26:dc00998140af
Child:
28:5905886c76ee

File content as of revision 26:dc00998140af:

#include "mbed.h"
#include <string>
#include "Config.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 */)
{
    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.
    }
}