update with altimeter, swimfile.txt endleg.txt, etc see changes_13sep.txt also reset_PI()

Dependencies:   mbed MODSERIAL FATFileSystem

Committer:
joel_ssc
Date:
Fri Sep 13 19:15:40 2019 +0000
Revision:
104:426224a55f5f
Parent:
102:0f430de62447
slight change  includes reset_PI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 62:d502889e74f1 1 #ifndef MBEDLOGGER_HPP
tnhnrl 62:d502889e74f1 2 #define MBEDLOGGER_HPP
tnhnrl 62:d502889e74f1 3
tnhnrl 62:d502889e74f1 4 #include "mbed.h"
tnhnrl 62:d502889e74f1 5 #include <string>
tnhnrl 62:d502889e74f1 6 using namespace std;
tnhnrl 62:d502889e74f1 7
tnhnrl 62:d502889e74f1 8 #include <vector>
tnhnrl 62:d502889e74f1 9
tnhnrl 73:f6f378311c8d 10 #include <fstream>
tnhnrl 73:f6f378311c8d 11
tnhnrl 62:d502889e74f1 12 enum {
tnhnrl 62:d502889e74f1 13 HEADER_117,
tnhnrl 62:d502889e74f1 14 HEADER_101,
tnhnrl 62:d502889e74f1 15 PACKET_NUM,
tnhnrl 62:d502889e74f1 16 TOTAL_NUM_PACKETS,
tnhnrl 62:d502889e74f1 17 PACKET_SIZE,
tnhnrl 62:d502889e74f1 18 END_TRANSMISSION,
tnhnrl 62:d502889e74f1 19 TRANSMIT_PACKET_1,
tnhnrl 62:d502889e74f1 20 TRANSMIT_PACKET_2,
tnhnrl 62:d502889e74f1 21 PACKET_CRC_ONE,
tnhnrl 62:d502889e74f1 22 PACKET_CRC_TWO,
tnhnrl 62:d502889e74f1 23 RANDOM_CHAR,
tnhnrl 62:d502889e74f1 24 COMMAND_ONE,
tnhnrl 73:f6f378311c8d 25 COMMAND_TWO,
tnhnrl 73:f6f378311c8d 26 HEADER_1E,
tnhnrl 74:d281aaef9766 27 HEADER_1F,
tnhnrl 74:d281aaef9766 28 PACKET_NO_1,
tnhnrl 74:d281aaef9766 29 PACKET_NO_2,
tnhnrl 74:d281aaef9766 30 END_TX_1,
tnhnrl 74:d281aaef9766 31 END_TX_2
tnhnrl 62:d502889e74f1 32 };
joel_ssc 82:0981b9ada820 33 //struct for saving names of log and diag files
joel_ssc 82:0981b9ada820 34 //struct logFiles {
joel_ssc 82:0981b9ada820 35 // string diagFile;
joel_ssc 82:0981b9ada820 36 // string logFile;
joel_ssc 82:0981b9ada820 37 // };
tnhnrl 62:d502889e74f1 38
joel_ssc 82:0981b9ada820 39
tnhnrl 62:d502889e74f1 40 class MbedLogger {
tnhnrl 62:d502889e74f1 41 public:
tnhnrl 62:d502889e74f1 42 MbedLogger(string file_system_input_string); //constructor
tnhnrl 62:d502889e74f1 43
tnhnrl 62:d502889e74f1 44 void createTestLog(); //test log function
joel_ssc 82:0981b9ada820 45 // logFiles logFilesStruct;
tnhnrl 62:d502889e74f1 46
tnhnrl 62:d502889e74f1 47 void appendLogFile(int current_state, int option); //check if you have orphaned file pointers before this (file should not be open already)
joel_ssc 82:0981b9ada820 48 void appendDiagFile(char *printf_string, int flushclose);
tnhnrl 62:d502889e74f1 49 //save float array to file (append each time)
tnhnrl 62:d502889e74f1 50 void saveDataToFile(int input_state, float *input);
tnhnrl 62:d502889e74f1 51
tnhnrl 62:d502889e74f1 52 //REVISED METHOD to save data (same as OpenLog)
tnhnrl 62:d502889e74f1 53 void recordData(int current_state);
joel_ssc 102:0f430de62447 54 void recordData_short(int current_state);
joel_ssc 102:0f430de62447 55 void recordData_long(int current_state);
tnhnrl 62:d502889e74f1 56
tnhnrl 62:d502889e74f1 57 //print the directory to the screen
tnhnrl 62:d502889e74f1 58 void printMbedDirectory();
tnhnrl 62:d502889e74f1 59
tnhnrl 62:d502889e74f1 60 //print the current MBED log file
tnhnrl 62:d502889e74f1 61 void printCurrentLogFile();
tnhnrl 62:d502889e74f1 62
tnhnrl 62:d502889e74f1 63 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 64 void transmitCurrentLogFileLine(bool next_line);
tnhnrl 62:d502889e74f1 65
tnhnrl 62:d502889e74f1 66 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 67 //void transmitCurrentLogFile();
tnhnrl 62:d502889e74f1 68
tnhnrl 62:d502889e74f1 69 // Create the data packet
tnhnrl 62:d502889e74f1 70 void createDataPacket();
tnhnrl 62:d502889e74f1 71
tnhnrl 62:d502889e74f1 72 // Transmit the data packet
tnhnrl 62:d502889e74f1 73 void transmitDataPacket();
tnhnrl 62:d502889e74f1 74
tnhnrl 62:d502889e74f1 75 // read transmit packet from Python program
tnhnrl 62:d502889e74f1 76 int readTransmitPacket();
tnhnrl 62:d502889e74f1 77
tnhnrl 62:d502889e74f1 78 // REOPEN LINE READER
tnhnrl 62:d502889e74f1 79 void reOpenLineReader();
tnhnrl 62:d502889e74f1 80
tnhnrl 62:d502889e74f1 81 // OPEN LINE READER
tnhnrl 62:d502889e74f1 82 bool openLineReader();
tnhnrl 62:d502889e74f1 83
tnhnrl 62:d502889e74f1 84 //read packet
tnhnrl 62:d502889e74f1 85 void readPacketInSeries();
tnhnrl 62:d502889e74f1 86
tnhnrl 62:d502889e74f1 87 //get the number of packets
tnhnrl 69:919ac8d7e023 88 int getNumberOfPacketsInCurrentLog();
tnhnrl 62:d502889e74f1 89
tnhnrl 62:d502889e74f1 90 // END TRANSMISSION AND CLOSE FILE
tnhnrl 62:d502889e74f1 91 void endTransmissionCloseFile();
tnhnrl 62:d502889e74f1 92
tnhnrl 62:d502889e74f1 93 //open a file to write to it
tnhnrl 62:d502889e74f1 94 void openWriteFile();
tnhnrl 62:d502889e74f1 95
tnhnrl 62:d502889e74f1 96 bool checkForIncomingData();
tnhnrl 62:d502889e74f1 97
tnhnrl 62:d502889e74f1 98 void endReceiveData();
tnhnrl 62:d502889e74f1 99
tnhnrl 62:d502889e74f1 100 void copyFileExample();
tnhnrl 62:d502889e74f1 101
tnhnrl 62:d502889e74f1 102 int calcCrcOneArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 103 int calcCrcTwoArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 104
tnhnrl 62:d502889e74f1 105 int calcCrcOne(); //used with vector _data_packet, cleaning up later
tnhnrl 62:d502889e74f1 106 int calcCrcTwo();
tnhnrl 62:d502889e74f1 107
tnhnrl 62:d502889e74f1 108 int calcCrcOneString (string string_input);
tnhnrl 62:d502889e74f1 109
tnhnrl 62:d502889e74f1 110 int calcCrcTwoString (string string_input);
tnhnrl 62:d502889e74f1 111
tnhnrl 62:d502889e74f1 112 //NEW for logging actual time
joel_ssc 86:ba3a118b0080 113 void setLogTime(long int setting_time); //set a local time
tnhnrl 62:d502889e74f1 114
joel_ssc 86:ba3a118b0080 115 time_t getSystemTime(); //parse the time to record to the log file
tnhnrl 62:d502889e74f1 116
tnhnrl 62:d502889e74f1 117 //NEW
tnhnrl 62:d502889e74f1 118 int sendReply();
tnhnrl 62:d502889e74f1 119 void sendReplyPacketNumber(int packet_number);
tnhnrl 62:d502889e74f1 120
tnhnrl 62:d502889e74f1 121 void resetReplyPacket();
tnhnrl 62:d502889e74f1 122
tnhnrl 62:d502889e74f1 123 void openNewMissionFile();
tnhnrl 62:d502889e74f1 124
tnhnrl 62:d502889e74f1 125 void setDataCounter(int input_counter);
tnhnrl 62:d502889e74f1 126
tnhnrl 62:d502889e74f1 127 void closeIncompleteFile();
tnhnrl 62:d502889e74f1 128
tnhnrl 62:d502889e74f1 129 void initializeLogFile();
joel_ssc 82:0981b9ada820 130 void initializeDiagFile(int print_diag);
tnhnrl 62:d502889e74f1 131
tnhnrl 62:d502889e74f1 132 int fileTransmitState();
tnhnrl 62:d502889e74f1 133
tnhnrl 62:d502889e74f1 134 int testGetFileSize();
tnhnrl 62:d502889e74f1 135
tnhnrl 62:d502889e74f1 136 int getFileSize(string filename);
tnhnrl 62:d502889e74f1 137
tnhnrl 62:d502889e74f1 138 void createEmptyLog();
tnhnrl 62:d502889e74f1 139
tnhnrl 62:d502889e74f1 140 int debugFileState();
tnhnrl 62:d502889e74f1 141
tnhnrl 62:d502889e74f1 142 //TICKER AND FUNCTION TO RECEIVE DATA
tnhnrl 62:d502889e74f1 143 void activateReceivePacket();
tnhnrl 62:d502889e74f1 144 void receiveMissionDataWithTicker();
tnhnrl 62:d502889e74f1 145
tnhnrl 62:d502889e74f1 146 void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise
joel_ssc 82:0981b9ada820 147 void closeDiagFile();
tnhnrl 62:d502889e74f1 148
tnhnrl 62:d502889e74f1 149 void specifyFileForTransmit(string input_string);
tnhnrl 62:d502889e74f1 150 void transmitFileFromDirectory(int file_number);
tnhnrl 62:d502889e74f1 151 void accessMbedDirectory();
tnhnrl 62:d502889e74f1 152
tnhnrl 62:d502889e74f1 153 int getFilePointerState();
tnhnrl 62:d502889e74f1 154 void testToggleFilePointer();
tnhnrl 62:d502889e74f1 155
tnhnrl 62:d502889e74f1 156 bool isTransmissionComplete();
tnhnrl 62:d502889e74f1 157 int currentPacketNumber();
tnhnrl 62:d502889e74f1 158 void eraseFile();
tnhnrl 62:d502889e74f1 159
tnhnrl 62:d502889e74f1 160 string _received_filename; //testing
tnhnrl 62:d502889e74f1 161
tnhnrl 74:d281aaef9766 162 void receiveSequenceFile();
tnhnrl 62:d502889e74f1 163 void receiveMissionDataWithFSM(); //for use in Finite State Machine
tnhnrl 62:d502889e74f1 164
tnhnrl 62:d502889e74f1 165 void openReceiveFile(string filename); //create a file with an input filename
tnhnrl 62:d502889e74f1 166
tnhnrl 62:d502889e74f1 167 void setTransmissionComplete(bool transmit_complete_status);
tnhnrl 62:d502889e74f1 168
tnhnrl 62:d502889e74f1 169 void intCreateDataPacket(int data_buffer[],int payload_length);
tnhnrl 63:6cb0405fc6e6 170
tnhnrl 63:6cb0405fc6e6 171 int getLogSize(); //used in state machine
tnhnrl 67:c86a4b464682 172
tnhnrl 67:c86a4b464682 173 string _heading_string;
joel_ssc 102:0f430de62447 174 string _heading_string2;
joel_ssc 82:0981b9ada820 175 string _diag_heading_string;
tnhnrl 68:8f549749b8ce 176
tnhnrl 68:8f549749b8ce 177 void continuouslyTransmitData();
tnhnrl 68:8f549749b8ce 178
tnhnrl 68:8f549749b8ce 179 void continuouslyTransmitDataNoTimer();
tnhnrl 68:8f549749b8ce 180
tnhnrl 68:8f549749b8ce 181 void transmitPacketNumber(int line_or_packet_number);
tnhnrl 68:8f549749b8ce 182
tnhnrl 69:919ac8d7e023 183 void checkForPythonTransmitRequest();
tnhnrl 68:8f549749b8ce 184
tnhnrl 73:f6f378311c8d 185 void fsmTransmitData();
tnhnrl 68:8f549749b8ce 186
tnhnrl 68:8f549749b8ce 187 void setTransmitPacketNumber(int packet_number);
tnhnrl 69:919ac8d7e023 188
tnhnrl 69:919ac8d7e023 189 void createDataPacket(char line_buffer_sent[], int line_length_sent);
tnhnrl 73:f6f378311c8d 190
tnhnrl 73:f6f378311c8d 191 bool endTransmitPacket(); //used to exit FSM with Python
tnhnrl 73:f6f378311c8d 192
tnhnrl 73:f6f378311c8d 193 void blastData();
tnhnrl 73:f6f378311c8d 194
tnhnrl 73:f6f378311c8d 195 void transmitOnePacket();
tnhnrl 73:f6f378311c8d 196
tnhnrl 73:f6f378311c8d 197 void transmitMultiplePackets();
tnhnrl 62:d502889e74f1 198
tnhnrl 62:d502889e74f1 199 private:
tnhnrl 62:d502889e74f1 200 int _file_number;
tnhnrl 62:d502889e74f1 201
tnhnrl 62:d502889e74f1 202 char _file_name[256]; //file name placeholder
tnhnrl 62:d502889e74f1 203 char _line_buffer[256]; //line buffer used to read file line by line
tnhnrl 62:d502889e74f1 204
joel_ssc 82:0981b9ada820 205 FILE *_fp; //the log file pointer
joel_ssc 82:0981b9ada820 206 FILE *_fp2; // the diag file pointer
tnhnrl 62:d502889e74f1 207
tnhnrl 62:d502889e74f1 208 vector <int> _data_packet;
tnhnrl 62:d502889e74f1 209
tnhnrl 62:d502889e74f1 210 std::vector<int>::iterator _it;
tnhnrl 62:d502889e74f1 211
tnhnrl 62:d502889e74f1 212 int _current_line_length;
tnhnrl 62:d502889e74f1 213
tnhnrl 62:d502889e74f1 214 int _packet_number;
tnhnrl 62:d502889e74f1 215 int _total_number_of_packets;
tnhnrl 62:d502889e74f1 216 string _log_file_string;
tnhnrl 62:d502889e74f1 217
tnhnrl 62:d502889e74f1 218 int _reply_byte;
tnhnrl 62:d502889e74f1 219 int _reply_byte2;
tnhnrl 62:d502889e74f1 220 int _reply_byte3;
tnhnrl 62:d502889e74f1 221 int _reply_byte4;
tnhnrl 62:d502889e74f1 222 int _previous_reply_byte;
tnhnrl 62:d502889e74f1 223
tnhnrl 62:d502889e74f1 224 bool _file_transmission; //breaks out of loop in State Machine
tnhnrl 62:d502889e74f1 225
tnhnrl 74:d281aaef9766 226 float _data_log[37]; //for logging all of the data from the outer and inner loops and so on
tnhnrl 62:d502889e74f1 227
tnhnrl 62:d502889e74f1 228 int _confirmed_packet_number;
tnhnrl 62:d502889e74f1 229
joel_ssc 86:ba3a118b0080 230 int _default_timestamp_time;
joel_ssc 87:6d95f853dab3 231 int _time_set;
joel_ssc 86:ba3a118b0080 232
tnhnrl 62:d502889e74f1 233 bool _still_transmitting_data;
tnhnrl 62:d502889e74f1 234
tnhnrl 62:d502889e74f1 235 int _transmit_counter;
tnhnrl 62:d502889e74f1 236
tnhnrl 62:d502889e74f1 237 int _file_transmission_state; //needed to test out what's going on with receiver
tnhnrl 62:d502889e74f1 238
tnhnrl 62:d502889e74f1 239 int _number_of_packets[2];
tnhnrl 62:d502889e74f1 240
tnhnrl 62:d502889e74f1 241 Ticker _mbed_transmit_ticker;
tnhnrl 62:d502889e74f1 242 Ticker _mbed_receive_ticker;
tnhnrl 62:d502889e74f1 243
tnhnrl 62:d502889e74f1 244 volatile bool _mbed_transmit_loop;
tnhnrl 62:d502889e74f1 245 volatile bool _mbed_receive_loop;
tnhnrl 62:d502889e74f1 246
tnhnrl 62:d502889e74f1 247 string _file_system_string;
tnhnrl 62:d502889e74f1 248 string _full_file_path_string;
joel_ssc 82:0981b9ada820 249 string _full_diagfile_path_string;
tnhnrl 62:d502889e74f1 250
tnhnrl 62:d502889e74f1 251 bool _file_transmission_complete; //was volatile screwing up the state of this?
tnhnrl 63:6cb0405fc6e6 252
tnhnrl 63:6cb0405fc6e6 253 int _log_file_line_counter;
tnhnrl 68:8f549749b8ce 254
tnhnrl 68:8f549749b8ce 255 int _transmit_packet_num;
tnhnrl 69:919ac8d7e023 256
tnhnrl 69:919ac8d7e023 257 bool _fsm_transmit_complete;
tnhnrl 73:f6f378311c8d 258
tnhnrl 73:f6f378311c8d 259 bool _end_transmit_packet;
tnhnrl 74:d281aaef9766 260
tnhnrl 74:d281aaef9766 261 bool _end_sequence_transmission;
tnhnrl 62:d502889e74f1 262 };
tnhnrl 62:d502889e74f1 263
tnhnrl 62:d502889e74f1 264 #endif