Dependencies: mbed MODSERIAL FATFileSystem
Diff: MbedLogger/MbedLogger.cpp
- Revision:
- 35:2f66ea4863d5
- Parent:
- 34:9b66c5188051
- Child:
- 36:966a86937e17
--- a/MbedLogger/MbedLogger.cpp Wed Dec 20 20:24:15 2017 +0000 +++ b/MbedLogger/MbedLogger.cpp Wed Dec 20 22:44:02 2017 +0000 @@ -6,6 +6,17 @@ _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_string,state_ID,timer,depth_cmd,depth(ft),pitch_cmd,pitch(deg), bce_cmd, bce(mm), batt_cmd, batt(mm)\n"); + + //file pointer is a class variable, close the file after you are done writing to it +} + //creates a new file each time it's called void MbedLogger::createNewFiles() { @@ -102,6 +113,30 @@ pc().printf("\n\rLog file closed.\n\r"); } +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\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() {