Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL FATFileSystem
Diff: MbedLogger/MbedLogger.cpp
- Revision:
- 99:9d0849f5fcd7
- Parent:
- 87:6d95f853dab3
--- a/MbedLogger/MbedLogger.cpp Mon May 20 18:57:23 2019 +0000 +++ b/MbedLogger/MbedLogger.cpp Fri Jun 28 13:59:11 2019 +0000 @@ -20,7 +20,7 @@ _log_file_line_counter = 0; //used to set timer in finite state machine based on size of log //heading string is 254 bytes long, FIXED LENGTH - _heading_string = "StateStr,St#,TimeSec,DepthCmd,DepthFt,PitchCmd,PitchDeg,RudderPWM,RudderCmdDeg,HeadDeg,bceCmd,bce_mm,battCmd,batt_mm,PitchRateDegSec,depth_rate_fps,SystemAmps,SystemVolts,AltChRd,Int_PSI,BCE_p,i,d,BATT_p,i,d,DEPTH_p,i,d,fq,db,PITCH_p,i,d,HEAD_p,i,d,fq,db\n"; + _heading_string = "StateStr,St#,TimeSec,DepthCmd,DepthFt,PitchCmd,PitchDeg,RudderPWM,RudderCmdDeg,HeadDeg,bceCmd,bce_mm,battCmd,batt_mm,PitchRateDegSec,depth_rate_fps,SystemAmps,SystemVolts,AltChRd,Alt_m,Int_PSI,BCE_p,i,d,BATT_p,i,d,DEPTH_p,i,d,fq,db,PITCH_p,i,d,HEAD_p,i,d,fq,db\n"; //edit by CAM _diag_heading_string = "Diagnostics file header \n"; _fsm_transmit_complete = false; @@ -71,32 +71,34 @@ _data_log[13] = sensors().getCurrentInput(); // i_in _data_log[14] = sensors().getVoltageInput(); // v_in _data_log[15] = sensors().getAltimeterChannelReadings(); // Altimeter Channel Readings - _data_log[16] = sensors().getInternalPressurePSI(); // int_press_PSI + _data_log[16] = sensors().getAltimeterReading_m(); // Altimeter Distance Reading (m) + _data_log[17] = sensors().getInternalPressurePSI(); // int_press_PSI //BCE_p,i,d,freq,deadband - _data_log[17] = bce().getControllerP(); - _data_log[18] = bce().getControllerI(); - _data_log[19] = bce().getControllerD(); + _data_log[18] = bce().getControllerP(); + _data_log[19] = bce().getControllerI(); + _data_log[20] = bce().getControllerD(); - _data_log[20] = batt().getControllerP(); - _data_log[21] = batt().getControllerI(); - _data_log[22] = batt().getControllerD(); + _data_log[21] = batt().getControllerP(); + _data_log[22] = batt().getControllerI(); + _data_log[23] = batt().getControllerD(); - _data_log[23] = depthLoop().getControllerP(); - _data_log[24] = depthLoop().getControllerI(); - _data_log[25] = depthLoop().getControllerD(); - _data_log[26] = depthLoop().getFilterFrequency(); - _data_log[27] = depthLoop().getDeadband(); + _data_log[24] = depthLoop().getControllerP(); + _data_log[25] = depthLoop().getControllerI(); + _data_log[26] = depthLoop().getControllerD(); + _data_log[27] = depthLoop().getFilterFrequency(); + _data_log[28] = depthLoop().getDeadband(); - _data_log[28] = pitchLoop().getControllerP(); - _data_log[29] = pitchLoop().getControllerI(); - _data_log[30] = pitchLoop().getControllerD(); + _data_log[29] = pitchLoop().getControllerP(); + _data_log[30] = pitchLoop().getControllerI(); + _data_log[31] = pitchLoop().getControllerD(); - _data_log[31] = headingLoop().getControllerP(); - _data_log[32] = headingLoop().getControllerI(); - _data_log[33] = headingLoop().getControllerD(); - _data_log[34] = headingLoop().getFilterFrequency(); - _data_log[35] = headingLoop().getDeadband(); + _data_log[32] = headingLoop().getControllerP(); + _data_log[33] = headingLoop().getControllerI(); + _data_log[34] = headingLoop().getControllerD(); + _data_log[35] = headingLoop().getFilterFrequency(); + _data_log[36] = headingLoop().getDeadband(); + string string_state; string_state= "UNKNOWN"; //default just in case. @@ -148,12 +150,12 @@ //below this format is used for data transmission, each packet needs to be 254 characters long (not counting newline char) //verified that this generates the correct line length of 254 using SOLELY an mbed 08/16/2018 - fprintf(_fp, "%17s,%.2d,%10d,%5.1f,%5.1f,%6.1f,%6.1f,%4.0f,%4.0f,%6.1f,%5.1f,%6.1f,%5.1f,%6.1f,%6.1f,%6.1f,%6.3f,%6.2f,%5.0f,%6.2f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%6.2f,%5.3f,%5.3f,%4.1f,%4.1f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%4.1f,%4.1f\n", + fprintf(_fp, "%17s,%.2d,%10d,%5.1f,%5.1f,%6.1f,%6.1f,%4.0f,%4.0f,%6.1f,%5.1f,%6.1f,%5.1f,%6.1f,%6.1f,%6.1f,%6.3f,%6.2f,%5.0f,%4.1f,%6.2f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%6.2f,%5.3f,%5.3f,%4.1f,%4.1f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%4.1f,%4.1f\n", // edit by CAM string_state.c_str(),current_state, data_log_time-start_time, //note offset relative to start _data_log[0],_data_log[1],_data_log[2],_data_log[3],_data_log[4],_data_log[5],_data_log[6],_data_log[7],_data_log[8],_data_log[9],_data_log[10],_data_log[11],_data_log[12],_data_log[13],_data_log[14],_data_log[15], _data_log[16],_data_log[17],_data_log[18],_data_log[19],_data_log[20],_data_log[21],_data_log[22],_data_log[23],_data_log[24],_data_log[25],_data_log[26],_data_log[27],_data_log[28],_data_log[29],_data_log[30], - _data_log[31],_data_log[32],_data_log[33],_data_log[34],_data_log[35]); + _data_log[31],_data_log[32],_data_log[33],_data_log[34],_data_log[35],_data_log[36]); //each line in the file is 160 characters long text-wise, check this with a file read } @@ -960,48 +962,48 @@ while (xbee().readable() && !data_transmission_complete) { incoming_byte = xbee().getc(); //getc returns an unsigned char cast to an int - //xbee().printf("DEBUG: State 0\n\r"); + xbee().printf("DEBUG: State 0 || byte: %d\n\r",incoming_byte); switch(process_state) { case HEADER_117: //continue processing if (incoming_byte == 117){ process_state = HEADER_101; - //xbee().printf("DEBUG: Case 117\n\r"); + xbee().printf("DEBUG: Case 117\n\r"); } //end transmission else if (incoming_byte == 16) { process_state = END_TRANSMISSION; - //xbee().printf("DEBUG: State 16 (END_TRANSMISSION)\n\r"); + xbee().printf("DEBUG: State 16 (END_TRANSMISSION)\n\r"); } else { process_state = HEADER_117; // ??? - //xbee().printf("DEBUG: State Header 117\n\r"); + xbee().printf("DEBUG: State Header 117\n\r"); } break; case HEADER_101: if(incoming_byte == 101) { process_state = PACKET_NUM; - //xbee().printf("DEBUG: Case 101\n\r"); + xbee().printf("DEBUG: Case 101\n\r"); } break; case PACKET_NUM: receive_packet_number = incoming_byte; process_state = TOTAL_NUM_PACKETS; - //xbee().printf("DEBUG: Case PACKET_NUM\n\r"); + xbee().printf("DEBUG: Case PACKET_NUM\n\r"); break; case TOTAL_NUM_PACKETS: receive_total_number_packets = incoming_byte; process_state = PACKET_SIZE; - //xbee().printf("DEBUG: Case TOTAL_NUM_PACKETS\n\r"); + xbee().printf("DEBUG: Case TOTAL_NUM_PACKETS\n\r"); break; case PACKET_SIZE: receive_packet_size = incoming_byte; - //xbee().printf("DEBUG: Case PACKET_SIZE\n\r"); + xbee().printf("DEBUG: Case PACKET_SIZE\n\r"); //write the header stuff to it char_buffer[0] = 117; @@ -1011,7 +1013,7 @@ char_buffer[4] = receive_packet_size; // tests confirmed that packet number is zero, number of packets is 12, packet size is 12 - //xbee().printf("char_buffer 2/3/4: %d %d %d\n\r", receive_packet_number,receive_total_number_packets,receive_packet_size); + xbee().printf("char_buffer 2/3/4: %d %d %d\n\r", receive_packet_number,receive_total_number_packets,receive_packet_size); //process packet data, future version will append for larger data sizes, 0xFFFF @@ -1027,7 +1029,8 @@ serial_timeout = 0; //reset the timeout } else { - serial_timeout++; + serial_timeout++; + //xbee().printf("DEBUG: timeout = %d\n\r",serial_timeout); } // When full data packet is received... @@ -1048,14 +1051,14 @@ int calc_crc_one = calcCrcOne(); int calc_crc_two = calcCrcTwo(); - //xbee().printf("DEBUG: calc crc 1: %d, crc 2: %d\n\r", calc_crc_one, calc_crc_two); + xbee().printf("DEBUG: calc crc 1: %d, crc 2: %d\n\r", calc_crc_one, calc_crc_two); // first confirm that the checksum is correct if ((calc_crc_one == checksum_one) and (calc_crc_two == checksum_two)) { - //xbee().printf("DEBUG: checksums are good!\n\r"); + xbee().printf("DEBUG: checksums are good!\n\r"); - //xbee().printf("receive_packet_number %d and _confirmed_packet_number %d\n\r", receive_packet_number, _confirmed_packet_number); //debug + xbee().printf("receive_packet_number %d and _confirmed_packet_number %d\n\r", receive_packet_number, _confirmed_packet_number); //debug // // CHECKSUM CORRECT & get the filename from the first packet (check that you receive first packet) // if (receive_packet_number == 0) { @@ -1111,36 +1114,36 @@ break; } -// //counter breaks out of the loop if no data received -// if (serial_timeout >= 10000) { -// //xbee().printf("break serial_timeout %d\n\r", serial_timeout); -// break; -// } + //counter breaks out of the loop if no data received + if (serial_timeout >= 1000) { + xbee().printf("break serial_timeout %d\n\r", serial_timeout); + break; + } } break; case END_TRANSMISSION: if (xbee().getc() == 16) { - //xbee().printf("DEBUG: END_TRANSMISSION REACHED: 1. \n\r"); + xbee().printf("DEBUG: END_TRANSMISSION REACHED: 1. \n\r"); if (xbee().getc() == 16) { - //xbee().printf("DEBUG: END_TRANSMISSION REACHED: 2. \n\r"); + xbee().printf("DEBUG: END_TRANSMISSION REACHED: 2. \n\r"); _end_sequence_transmission = true; //endReceiveData(); } } - //xbee().printf("DEBUG: END_TRANSMISSION REACHED: 5. \n\r"); + xbee().printf("DEBUG: END_TRANSMISSION REACHED: 5. \n\r"); //process_state = HEADER_117; //don't do this unless the check is wrong - //xbee().printf("END_TRANSMISSION process_state is %d\n\r", process_state); //should be 5 (debug) 02/06/2018 + xbee().printf("END_TRANSMISSION process_state is %d\n\r", process_state); //should be 5 (debug) 02/06/2018 data_transmission_complete = true; break; }//END OF SWITCH if (data_transmission_complete) { - //xbee().printf("DEBUG: checkForIncomingData data_transmission_complete \n\r"); + xbee().printf("DEBUG: checkForIncomingData data_transmission_complete \n\r"); break; //out of while loop } } // while loop @@ -1302,13 +1305,14 @@ // initialize and close the file // log file freezes at 0x0000006c void MbedLogger::initializeLogFile() { + char buf[256]; string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? + _full_file_path_string = file_name_string; - char buf[256]; xbee().printf("%s file system init\n\r", _file_system_string.c_str()); sprintf(buf, "%s mbedlogger():initializelogfile: file system init\n\r", _file_system_string.c_str()); - appendDiagFile(buf,1); + appendDiagFile(buf,1); //try to open this file... _fp = fopen(file_name_string.c_str(), "r"); @@ -1538,9 +1542,7 @@ void MbedLogger::receiveSequenceFile() { //restart each time _end_sequence_transmission = false; - openNewMissionFile(); - //zero will be reserved for the file name, future _confirmed_packet_number = 1; //in sendReply() function that transmits a reply for incoming data @@ -1559,7 +1561,7 @@ counter++; - sendReply(); //bad name, should call it send request or something + sendReply(); //bad name, should call it send request or something CAM if (_end_sequence_transmission) break;