most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
tnhnrl
Date:
Thu Dec 21 23:13:44 2017 +0000
Revision:
39:58375ca6b6ff
Parent:
36:966a86937e17
Pool-tested code with Mbed logging and OpenLog (SD card)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 32:f2f8ae34aadc 1 #include "MbedLogger.hpp"
tnhnrl 32:f2f8ae34aadc 2 #include "StaticDefs.hpp"
tnhnrl 32:f2f8ae34aadc 3
tnhnrl 32:f2f8ae34aadc 4 MbedLogger::MbedLogger() {
tnhnrl 32:f2f8ae34aadc 5 _f = 0;
tnhnrl 32:f2f8ae34aadc 6 _file_number = 0;
tnhnrl 32:f2f8ae34aadc 7 }
tnhnrl 32:f2f8ae34aadc 8
tnhnrl 35:2f66ea4863d5 9 //one log file only, works faster
tnhnrl 35:2f66ea4863d5 10 void MbedLogger::openFile() {
tnhnrl 35:2f66ea4863d5 11 //create a file for writing to it (overwrites existing file)
tnhnrl 35:2f66ea4863d5 12 _fp = fopen("/local/LOG000.csv", "w");
tnhnrl 35:2f66ea4863d5 13
tnhnrl 35:2f66ea4863d5 14 //write the header
tnhnrl 39:58375ca6b6ff 15 fprintf(_fp,"state_ID,timer,depth_cmd,depth(ft),pitch_cmd,pitch(deg), bce_cmd, bce(mm), batt_cmd, batt(mm)\n");
tnhnrl 35:2f66ea4863d5 16
tnhnrl 39:58375ca6b6ff 17 //the file pointer is a class variable, close the file after you are done writing to it
tnhnrl 32:f2f8ae34aadc 18 }
tnhnrl 32:f2f8ae34aadc 19
tnhnrl 36:966a86937e17 20 void MbedLogger::saveDataToFile(int input_state, float *input) {
tnhnrl 34:9b66c5188051 21 //write to the file (header and data)
tnhnrl 36:966a86937e17 22 fprintf(_fp, "%d,%0.1f,%0.1f,%0.1f,%0.1f,%0.1f,%0.1f,%0.1f,%0.1f,%0.1f\n",input_state,input[0],input[1],input[2],input[3],input[4],input[5],input[6],input[7],input[8]);
tnhnrl 32:f2f8ae34aadc 23 }
tnhnrl 32:f2f8ae34aadc 24
tnhnrl 32:f2f8ae34aadc 25 void MbedLogger::printMbedDirectory() {
tnhnrl 32:f2f8ae34aadc 26 DirectoryList dir( "/local" );
tnhnrl 32:f2f8ae34aadc 27
tnhnrl 32:f2f8ae34aadc 28 if ( dir.error_check() )
tnhnrl 32:f2f8ae34aadc 29 error( "directory could not be opened\r\n" );
tnhnrl 32:f2f8ae34aadc 30
tnhnrl 32:f2f8ae34aadc 31 for ( int i = 0; i < dir.size(); i++ )
tnhnrl 32:f2f8ae34aadc 32 printf( "%s\r\n", dir[ i ].c_str() );
tnhnrl 32:f2f8ae34aadc 33 }
tnhnrl 32:f2f8ae34aadc 34
tnhnrl 35:2f66ea4863d5 35 void MbedLogger::printCurrentLogFile() {
tnhnrl 35:2f66ea4863d5 36 //open the file for reading
tnhnrl 35:2f66ea4863d5 37 FILE *fp = fopen("/local/Log000.csv", "r");
tnhnrl 35:2f66ea4863d5 38
tnhnrl 35:2f66ea4863d5 39 // http://people.cs.uchicago.edu/~dmfranklin/tutorials/fgets.txt
tnhnrl 35:2f66ea4863d5 40
tnhnrl 35:2f66ea4863d5 41 //while not end of file, read through line by line???
tnhnrl 35:2f66ea4863d5 42 char buffer[500];
tnhnrl 35:2f66ea4863d5 43
tnhnrl 35:2f66ea4863d5 44 //read the file line by line (and print each line)
tnhnrl 36:966a86937e17 45 pc().printf("\n\rCURRENT MBED LOG FILE /local/Log%03d.csv:\n\n\r",_file_number);
tnhnrl 35:2f66ea4863d5 46 while (!feof(fp)) {
tnhnrl 35:2f66ea4863d5 47 // read in the line and make sure it was successful
tnhnrl 35:2f66ea4863d5 48 if (fgets(buffer,500,fp) != NULL) {
tnhnrl 35:2f66ea4863d5 49 pc().printf("%s\r",buffer);
tnhnrl 35:2f66ea4863d5 50 //pc().printf("%d: %s\n\r",lineno++,buffer);
tnhnrl 35:2f66ea4863d5 51 }
tnhnrl 35:2f66ea4863d5 52 }
tnhnrl 35:2f66ea4863d5 53
tnhnrl 35:2f66ea4863d5 54 //close the file
tnhnrl 35:2f66ea4863d5 55 fclose(fp);
tnhnrl 35:2f66ea4863d5 56 pc().printf("\n\rLog file closed.\n\r");
tnhnrl 35:2f66ea4863d5 57 }
tnhnrl 35:2f66ea4863d5 58
tnhnrl 32:f2f8ae34aadc 59 //ONLY CLOSE THE FILE WITH THIS
tnhnrl 32:f2f8ae34aadc 60 //always close the file when you're done using it
tnhnrl 32:f2f8ae34aadc 61 void MbedLogger::closeFile() {
tnhnrl 32:f2f8ae34aadc 62 fclose(_fp);
tnhnrl 36:966a86937e17 63 pc().printf("\n\rDEBUG: Log file closed.\n\r");
tnhnrl 32:f2f8ae34aadc 64 }