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
MbedLogger/MbedLogger.cpp
- Committer:
- tnhnrl
- Date:
- 2017-12-21
- Revision:
- 39:58375ca6b6ff
- Parent:
- 36:966a86937e17
File content as of revision 39:58375ca6b6ff:
#include "MbedLogger.hpp" #include "StaticDefs.hpp" MbedLogger::MbedLogger() { _f = 0; _file_number = 0; } //one log file only, works faster void MbedLogger::openFile() { //create a file for writing to it (overwrites existing file) _fp = fopen("/local/LOG000.csv", "w"); //write the header fprintf(_fp,"state_ID,timer,depth_cmd,depth(ft),pitch_cmd,pitch(deg), bce_cmd, bce(mm), batt_cmd, batt(mm)\n"); //the file pointer is a class variable, close the file after you are done writing to it } void MbedLogger::saveDataToFile(int input_state, float *input) { //write to the file (header and data) 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]); } void MbedLogger::printMbedDirectory() { DirectoryList dir( "/local" ); if ( dir.error_check() ) error( "directory could not be opened\r\n" ); for ( int i = 0; i < dir.size(); i++ ) printf( "%s\r\n", dir[ i ].c_str() ); } void MbedLogger::printCurrentLogFile() { //open the file for reading FILE *fp = fopen("/local/Log000.csv", "r"); // http://people.cs.uchicago.edu/~dmfranklin/tutorials/fgets.txt //while not end of file, read through line by line??? char buffer[500]; //read the file line by line (and print each line) pc().printf("\n\rCURRENT MBED LOG FILE /local/Log%03d.csv:\n\n\r",_file_number); while (!feof(fp)) { // read in the line and make sure it was successful if (fgets(buffer,500,fp) != NULL) { pc().printf("%s\r",buffer); //pc().printf("%d: %s\n\r",lineno++,buffer); } } //close the file fclose(fp); pc().printf("\n\rLog file closed.\n\r"); } //ONLY CLOSE THE FILE WITH THIS //always close the file when you're done using it void MbedLogger::closeFile() { fclose(_fp); pc().printf("\n\rDEBUG: Log file closed.\n\r"); }