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.hpp
00001 #ifndef MBEDLOGGER_HPP 00002 #define MBEDLOGGER_HPP 00003 00004 #include "mbed.h" 00005 #include <string> 00006 using namespace std; 00007 00008 #include <vector> 00009 00010 #include <fstream> 00011 00012 enum { 00013 HEADER_117, 00014 HEADER_101, 00015 PACKET_NUM, 00016 TOTAL_NUM_PACKETS, 00017 PACKET_SIZE, 00018 END_TRANSMISSION, 00019 TRANSMIT_PACKET_1, 00020 TRANSMIT_PACKET_2, 00021 PACKET_CRC_ONE, 00022 PACKET_CRC_TWO, 00023 RANDOM_CHAR, 00024 COMMAND_ONE, 00025 COMMAND_TWO, 00026 HEADER_1E, 00027 HEADER_1F, 00028 PACKET_NO_1, 00029 PACKET_NO_2, 00030 END_TX_1, 00031 END_TX_2 00032 }; 00033 //struct for saving names of log and diag files 00034 //struct logFiles { 00035 // string diagFile; 00036 // string logFile; 00037 // }; 00038 00039 00040 class MbedLogger { 00041 public: 00042 MbedLogger(string file_system_input_string); //constructor 00043 00044 void createTestLog(); //test log function 00045 // logFiles logFilesStruct; 00046 00047 void appendLogFile(int current_state, int option); //check if you have orphaned file pointers before this (file should not be open already) 00048 void appendDiagFile(char *printf_string, int flushclose); 00049 //save float array to file (append each time) 00050 void saveDataToFile(int input_state, float *input); 00051 00052 //REVISED METHOD to save data (same as OpenLog) 00053 void recordData(int current_state); 00054 00055 //print the directory to the screen 00056 void printMbedDirectory(); 00057 00058 //print the current MBED log file 00059 void printCurrentLogFile(); 00060 00061 //transmit data when receive confirmation 00062 void transmitCurrentLogFileLine(bool next_line); 00063 00064 //transmit data when receive confirmation 00065 //void transmitCurrentLogFile(); 00066 00067 // Create the data packet 00068 void createDataPacket(); 00069 00070 // Transmit the data packet 00071 void transmitDataPacket(); 00072 00073 // read transmit packet from Python program 00074 int readTransmitPacket(); 00075 00076 // REOPEN LINE READER 00077 void reOpenLineReader(); 00078 00079 // OPEN LINE READER 00080 bool openLineReader(); 00081 00082 //read packet 00083 void readPacketInSeries(); 00084 00085 //get the number of packets 00086 int getNumberOfPacketsInCurrentLog(); 00087 00088 // END TRANSMISSION AND CLOSE FILE 00089 void endTransmissionCloseFile(); 00090 00091 //open a file to write to it 00092 void openWriteFile(); 00093 00094 bool checkForIncomingData(); 00095 00096 void endReceiveData(); 00097 00098 void copyFileExample(); 00099 00100 int calcCrcOneArray(int *input_array, int array_length); 00101 int calcCrcTwoArray(int *input_array, int array_length); 00102 00103 int calcCrcOne(); //used with vector _data_packet, cleaning up later 00104 int calcCrcTwo(); 00105 00106 int calcCrcOneString (string string_input); 00107 00108 int calcCrcTwoString (string string_input); 00109 00110 //NEW for logging actual time 00111 void setLogTime(long int setting_time); //set a local time 00112 00113 time_t getSystemTime(); //parse the time to record to the log file 00114 00115 //NEW 00116 int sendReply(); 00117 void sendReplyPacketNumber(int packet_number); 00118 00119 void resetReplyPacket(); 00120 00121 void openNewMissionFile(); 00122 00123 void setDataCounter(int input_counter); 00124 00125 void closeIncompleteFile(); 00126 00127 void initializeLogFile(); 00128 void initializeDiagFile(int print_diag); 00129 00130 int fileTransmitState(); 00131 00132 int testGetFileSize(); 00133 00134 int getFileSize(string filename); 00135 00136 void createEmptyLog(); 00137 00138 int debugFileState(); 00139 00140 //TICKER AND FUNCTION TO RECEIVE DATA 00141 void activateReceivePacket(); 00142 void receiveMissionDataWithTicker(); 00143 00144 void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise 00145 void closeDiagFile(); 00146 00147 void specifyFileForTransmit(string input_string); 00148 void transmitFileFromDirectory(int file_number); 00149 void accessMbedDirectory(); 00150 00151 int getFilePointerState(); 00152 void testToggleFilePointer(); 00153 00154 bool isTransmissionComplete(); 00155 int currentPacketNumber(); 00156 void eraseFile(); 00157 00158 string _received_filename; //testing 00159 00160 void receiveSequenceFile(); 00161 void receiveMissionDataWithFSM(); //for use in Finite State Machine 00162 00163 void openReceiveFile(string filename); //create a file with an input filename 00164 00165 void setTransmissionComplete(bool transmit_complete_status); 00166 00167 void intCreateDataPacket(int data_buffer[],int payload_length); 00168 00169 int getLogSize(); //used in state machine 00170 00171 string _heading_string; 00172 string _diag_heading_string; 00173 00174 void continuouslyTransmitData(); 00175 00176 void continuouslyTransmitDataNoTimer(); 00177 00178 void transmitPacketNumber(int line_or_packet_number); 00179 00180 void checkForPythonTransmitRequest(); 00181 00182 void fsmTransmitData(); 00183 00184 void setTransmitPacketNumber(int packet_number); 00185 00186 void createDataPacket(char line_buffer_sent[], int line_length_sent); 00187 00188 bool endTransmitPacket(); //used to exit FSM with Python 00189 00190 void blastData(); 00191 00192 void transmitOnePacket(); 00193 00194 void transmitMultiplePackets(); 00195 00196 private: 00197 int _file_number; 00198 00199 char _file_name[256]; //file name placeholder 00200 char _line_buffer[256]; //line buffer used to read file line by line 00201 00202 FILE *_fp; //the log file pointer 00203 FILE *_fp2; // the diag file pointer 00204 00205 vector <int> _data_packet; 00206 00207 std::vector<int>::iterator _it; 00208 00209 int _current_line_length; 00210 00211 int _packet_number; 00212 int _total_number_of_packets; 00213 string _log_file_string; 00214 00215 int _reply_byte; 00216 int _reply_byte2; 00217 int _reply_byte3; 00218 int _reply_byte4; 00219 int _previous_reply_byte; 00220 00221 bool _file_transmission; //breaks out of loop in State Machine 00222 00223 float _data_log[37]; //for logging all of the data from the outer and inner loops and so on 00224 00225 int _confirmed_packet_number; 00226 00227 int _default_timestamp_time; 00228 int _time_set; 00229 00230 bool _still_transmitting_data; 00231 00232 int _transmit_counter; 00233 00234 int _file_transmission_state; //needed to test out what's going on with receiver 00235 00236 int _number_of_packets[2]; 00237 00238 Ticker _mbed_transmit_ticker; 00239 Ticker _mbed_receive_ticker; 00240 00241 volatile bool _mbed_transmit_loop; 00242 volatile bool _mbed_receive_loop; 00243 00244 string _file_system_string; 00245 string _full_file_path_string; 00246 string _full_diagfile_path_string; 00247 00248 bool _file_transmission_complete; //was volatile screwing up the state of this? 00249 00250 int _log_file_line_counter; 00251 00252 int _transmit_packet_num; 00253 00254 bool _fsm_transmit_complete; 00255 00256 bool _end_transmit_packet; 00257 00258 bool _end_sequence_transmission; 00259 }; 00260 00261 #endif
Generated on Thu Jul 14 2022 10:54:35 by 1.7.2