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.hpp@69:919ac8d7e023, 2018-06-29 (annotated)
- Committer:
- tnhnrl
- Date:
- Fri Jun 29 14:21:22 2018 +0000
- Revision:
- 69:919ac8d7e023
- Parent:
- 68:8f549749b8ce
- Child:
- 73:f6f378311c8d
transmitting data seems to work fine, 10 hz (0.1 sec transmit)
Who changed what in which revision?
User | Revision | Line number | New 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 | 62:d502889e74f1 | 10 | enum { |
tnhnrl | 62:d502889e74f1 | 11 | HEADER_117, |
tnhnrl | 62:d502889e74f1 | 12 | HEADER_101, |
tnhnrl | 62:d502889e74f1 | 13 | PACKET_NUM, |
tnhnrl | 62:d502889e74f1 | 14 | TOTAL_NUM_PACKETS, |
tnhnrl | 62:d502889e74f1 | 15 | PACKET_SIZE, |
tnhnrl | 62:d502889e74f1 | 16 | END_TRANSMISSION, |
tnhnrl | 62:d502889e74f1 | 17 | TRANSMIT_PACKET_1, |
tnhnrl | 62:d502889e74f1 | 18 | TRANSMIT_PACKET_2, |
tnhnrl | 62:d502889e74f1 | 19 | PACKET_CRC_ONE, |
tnhnrl | 62:d502889e74f1 | 20 | PACKET_CRC_TWO, |
tnhnrl | 62:d502889e74f1 | 21 | RANDOM_CHAR, |
tnhnrl | 62:d502889e74f1 | 22 | COMMAND_ONE, |
tnhnrl | 62:d502889e74f1 | 23 | COMMAND_TWO |
tnhnrl | 62:d502889e74f1 | 24 | }; |
tnhnrl | 62:d502889e74f1 | 25 | |
tnhnrl | 62:d502889e74f1 | 26 | class MbedLogger { |
tnhnrl | 62:d502889e74f1 | 27 | public: |
tnhnrl | 62:d502889e74f1 | 28 | MbedLogger(string file_system_input_string); //constructor |
tnhnrl | 62:d502889e74f1 | 29 | |
tnhnrl | 62:d502889e74f1 | 30 | void createTestLog(); //test log function |
tnhnrl | 62:d502889e74f1 | 31 | |
tnhnrl | 62:d502889e74f1 | 32 | void appendLogFile(int current_state, int option); //check if you have orphaned file pointers before this (file should not be open already) |
tnhnrl | 62:d502889e74f1 | 33 | |
tnhnrl | 62:d502889e74f1 | 34 | //save float array to file (append each time) |
tnhnrl | 62:d502889e74f1 | 35 | void saveDataToFile(int input_state, float *input); |
tnhnrl | 62:d502889e74f1 | 36 | |
tnhnrl | 62:d502889e74f1 | 37 | //REVISED METHOD to save data (same as OpenLog) |
tnhnrl | 62:d502889e74f1 | 38 | void recordData(int current_state); |
tnhnrl | 62:d502889e74f1 | 39 | |
tnhnrl | 62:d502889e74f1 | 40 | //print the directory to the screen |
tnhnrl | 62:d502889e74f1 | 41 | void printMbedDirectory(); |
tnhnrl | 62:d502889e74f1 | 42 | |
tnhnrl | 62:d502889e74f1 | 43 | //print the current MBED log file |
tnhnrl | 62:d502889e74f1 | 44 | void printCurrentLogFile(); |
tnhnrl | 62:d502889e74f1 | 45 | |
tnhnrl | 62:d502889e74f1 | 46 | //open file for transmit |
tnhnrl | 62:d502889e74f1 | 47 | void openFileForTransmit(); |
tnhnrl | 62:d502889e74f1 | 48 | |
tnhnrl | 62:d502889e74f1 | 49 | //transmit data when receive confirmation |
tnhnrl | 62:d502889e74f1 | 50 | void transmitCurrentLogFileLine(bool next_line); |
tnhnrl | 62:d502889e74f1 | 51 | |
tnhnrl | 62:d502889e74f1 | 52 | //transmit data when receive confirmation |
tnhnrl | 62:d502889e74f1 | 53 | //void transmitCurrentLogFile(); |
tnhnrl | 62:d502889e74f1 | 54 | |
tnhnrl | 62:d502889e74f1 | 55 | // Create the data packet |
tnhnrl | 62:d502889e74f1 | 56 | void createDataPacket(); |
tnhnrl | 62:d502889e74f1 | 57 | |
tnhnrl | 62:d502889e74f1 | 58 | // Transmit the data packet |
tnhnrl | 62:d502889e74f1 | 59 | void transmitDataPacket(); |
tnhnrl | 62:d502889e74f1 | 60 | |
tnhnrl | 62:d502889e74f1 | 61 | // read transmit packet from Python program |
tnhnrl | 62:d502889e74f1 | 62 | int readTransmitPacket(); |
tnhnrl | 62:d502889e74f1 | 63 | |
tnhnrl | 62:d502889e74f1 | 64 | // REOPEN LINE READER |
tnhnrl | 62:d502889e74f1 | 65 | void reOpenLineReader(); |
tnhnrl | 62:d502889e74f1 | 66 | |
tnhnrl | 62:d502889e74f1 | 67 | // OPEN LINE READER |
tnhnrl | 62:d502889e74f1 | 68 | bool openLineReader(); |
tnhnrl | 62:d502889e74f1 | 69 | |
tnhnrl | 62:d502889e74f1 | 70 | //read packet |
tnhnrl | 62:d502889e74f1 | 71 | void readPacketInSeries(); |
tnhnrl | 62:d502889e74f1 | 72 | |
tnhnrl | 62:d502889e74f1 | 73 | //get the number of packets |
tnhnrl | 69:919ac8d7e023 | 74 | int getNumberOfPacketsInCurrentLog(); |
tnhnrl | 62:d502889e74f1 | 75 | |
tnhnrl | 62:d502889e74f1 | 76 | // END TRANSMISSION AND CLOSE FILE |
tnhnrl | 62:d502889e74f1 | 77 | void endTransmissionCloseFile(); |
tnhnrl | 62:d502889e74f1 | 78 | |
tnhnrl | 62:d502889e74f1 | 79 | //open a file to write to it |
tnhnrl | 62:d502889e74f1 | 80 | void openWriteFile(); |
tnhnrl | 62:d502889e74f1 | 81 | |
tnhnrl | 62:d502889e74f1 | 82 | bool checkForIncomingData(); |
tnhnrl | 62:d502889e74f1 | 83 | |
tnhnrl | 62:d502889e74f1 | 84 | void endReceiveData(); |
tnhnrl | 62:d502889e74f1 | 85 | |
tnhnrl | 62:d502889e74f1 | 86 | void copyFileExample(); |
tnhnrl | 62:d502889e74f1 | 87 | |
tnhnrl | 62:d502889e74f1 | 88 | int calcCrcOneArray(int *input_array, int array_length); |
tnhnrl | 62:d502889e74f1 | 89 | int calcCrcTwoArray(int *input_array, int array_length); |
tnhnrl | 62:d502889e74f1 | 90 | |
tnhnrl | 62:d502889e74f1 | 91 | int calcCrcOne(); //used with vector _data_packet, cleaning up later |
tnhnrl | 62:d502889e74f1 | 92 | int calcCrcTwo(); |
tnhnrl | 62:d502889e74f1 | 93 | |
tnhnrl | 62:d502889e74f1 | 94 | int calcCrcOneString (string string_input); |
tnhnrl | 62:d502889e74f1 | 95 | |
tnhnrl | 62:d502889e74f1 | 96 | int calcCrcTwoString (string string_input); |
tnhnrl | 62:d502889e74f1 | 97 | |
tnhnrl | 62:d502889e74f1 | 98 | //NEW for logging actual time |
tnhnrl | 62:d502889e74f1 | 99 | void setLogTime(); //set a local time |
tnhnrl | 62:d502889e74f1 | 100 | |
tnhnrl | 62:d502889e74f1 | 101 | int getSystemTime(); //parse the time to record to the log file |
tnhnrl | 62:d502889e74f1 | 102 | |
tnhnrl | 62:d502889e74f1 | 103 | //NEW |
tnhnrl | 62:d502889e74f1 | 104 | int sendReply(); |
tnhnrl | 62:d502889e74f1 | 105 | void sendReplyPacketNumber(int packet_number); |
tnhnrl | 62:d502889e74f1 | 106 | |
tnhnrl | 62:d502889e74f1 | 107 | void resetReplyPacket(); |
tnhnrl | 62:d502889e74f1 | 108 | |
tnhnrl | 62:d502889e74f1 | 109 | void openNewMissionFile(); |
tnhnrl | 62:d502889e74f1 | 110 | |
tnhnrl | 62:d502889e74f1 | 111 | void setDataCounter(int input_counter); |
tnhnrl | 62:d502889e74f1 | 112 | |
tnhnrl | 62:d502889e74f1 | 113 | void closeIncompleteFile(); |
tnhnrl | 62:d502889e74f1 | 114 | |
tnhnrl | 62:d502889e74f1 | 115 | void initializeLogFile(); |
tnhnrl | 62:d502889e74f1 | 116 | |
tnhnrl | 62:d502889e74f1 | 117 | int fileTransmitState(); |
tnhnrl | 62:d502889e74f1 | 118 | |
tnhnrl | 62:d502889e74f1 | 119 | int testGetFileSize(); |
tnhnrl | 62:d502889e74f1 | 120 | |
tnhnrl | 62:d502889e74f1 | 121 | int getFileSize(string filename); |
tnhnrl | 62:d502889e74f1 | 122 | |
tnhnrl | 62:d502889e74f1 | 123 | void createEmptyLog(); |
tnhnrl | 62:d502889e74f1 | 124 | |
tnhnrl | 62:d502889e74f1 | 125 | int debugFileState(); |
tnhnrl | 62:d502889e74f1 | 126 | |
tnhnrl | 62:d502889e74f1 | 127 | //TICKER AND FUNCTION TO RECEIVE DATA |
tnhnrl | 62:d502889e74f1 | 128 | void activateReceivePacket(); |
tnhnrl | 62:d502889e74f1 | 129 | void receiveMissionDataWithTicker(); |
tnhnrl | 62:d502889e74f1 | 130 | |
tnhnrl | 62:d502889e74f1 | 131 | void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise |
tnhnrl | 62:d502889e74f1 | 132 | |
tnhnrl | 62:d502889e74f1 | 133 | void specifyFileForTransmit(string input_string); |
tnhnrl | 62:d502889e74f1 | 134 | void transmitFileFromDirectory(int file_number); |
tnhnrl | 62:d502889e74f1 | 135 | void accessMbedDirectory(); |
tnhnrl | 62:d502889e74f1 | 136 | |
tnhnrl | 62:d502889e74f1 | 137 | int getFilePointerState(); |
tnhnrl | 62:d502889e74f1 | 138 | void testToggleFilePointer(); |
tnhnrl | 62:d502889e74f1 | 139 | |
tnhnrl | 62:d502889e74f1 | 140 | int getNumberOfPackets(); |
tnhnrl | 62:d502889e74f1 | 141 | |
tnhnrl | 62:d502889e74f1 | 142 | void readTransmitPacketOneChar(); |
tnhnrl | 62:d502889e74f1 | 143 | |
tnhnrl | 62:d502889e74f1 | 144 | bool isTransmissionComplete(); |
tnhnrl | 62:d502889e74f1 | 145 | int currentPacketNumber(); |
tnhnrl | 62:d502889e74f1 | 146 | void eraseFile(); |
tnhnrl | 62:d502889e74f1 | 147 | |
tnhnrl | 62:d502889e74f1 | 148 | string _received_filename; //testing |
tnhnrl | 62:d502889e74f1 | 149 | |
tnhnrl | 62:d502889e74f1 | 150 | void receiveMissionDataWithFSM(); //for use in Finite State Machine |
tnhnrl | 62:d502889e74f1 | 151 | |
tnhnrl | 62:d502889e74f1 | 152 | void openReceiveFile(string filename); //create a file with an input filename |
tnhnrl | 62:d502889e74f1 | 153 | |
tnhnrl | 62:d502889e74f1 | 154 | void setTransmissionComplete(bool transmit_complete_status); |
tnhnrl | 62:d502889e74f1 | 155 | |
tnhnrl | 62:d502889e74f1 | 156 | void sendStatus(); |
tnhnrl | 62:d502889e74f1 | 157 | |
tnhnrl | 62:d502889e74f1 | 158 | void intCreateDataPacket(int data_buffer[],int payload_length); |
tnhnrl | 63:6cb0405fc6e6 | 159 | |
tnhnrl | 63:6cb0405fc6e6 | 160 | int getLogSize(); //used in state machine |
tnhnrl | 67:c86a4b464682 | 161 | |
tnhnrl | 67:c86a4b464682 | 162 | string _heading_string; |
tnhnrl | 68:8f549749b8ce | 163 | |
tnhnrl | 68:8f549749b8ce | 164 | void continuouslyTransmitData(); |
tnhnrl | 68:8f549749b8ce | 165 | |
tnhnrl | 68:8f549749b8ce | 166 | void continuouslyTransmitDataNoTimer(); |
tnhnrl | 68:8f549749b8ce | 167 | |
tnhnrl | 68:8f549749b8ce | 168 | void transmitPacketNumber(int line_or_packet_number); |
tnhnrl | 68:8f549749b8ce | 169 | |
tnhnrl | 69:919ac8d7e023 | 170 | void checkForPythonTransmitRequest(); |
tnhnrl | 68:8f549749b8ce | 171 | |
tnhnrl | 68:8f549749b8ce | 172 | bool fsmTransmitData(); |
tnhnrl | 68:8f549749b8ce | 173 | |
tnhnrl | 68:8f549749b8ce | 174 | void setTransmitPacketNumber(int packet_number); |
tnhnrl | 69:919ac8d7e023 | 175 | |
tnhnrl | 69:919ac8d7e023 | 176 | void createDataPacket(char line_buffer_sent[], int line_length_sent); |
tnhnrl | 62:d502889e74f1 | 177 | |
tnhnrl | 62:d502889e74f1 | 178 | private: |
tnhnrl | 62:d502889e74f1 | 179 | int _file_number; |
tnhnrl | 62:d502889e74f1 | 180 | |
tnhnrl | 62:d502889e74f1 | 181 | char _file_name[256]; //file name placeholder |
tnhnrl | 62:d502889e74f1 | 182 | char _line_buffer[256]; //line buffer used to read file line by line |
tnhnrl | 62:d502889e74f1 | 183 | |
tnhnrl | 62:d502889e74f1 | 184 | FILE *_fp; //the file is a class member variable |
tnhnrl | 62:d502889e74f1 | 185 | |
tnhnrl | 62:d502889e74f1 | 186 | vector <int> _data_packet; |
tnhnrl | 62:d502889e74f1 | 187 | |
tnhnrl | 62:d502889e74f1 | 188 | std::vector<int>::iterator _it; |
tnhnrl | 62:d502889e74f1 | 189 | |
tnhnrl | 62:d502889e74f1 | 190 | int _current_line_length; |
tnhnrl | 62:d502889e74f1 | 191 | |
tnhnrl | 62:d502889e74f1 | 192 | int _packet_number; |
tnhnrl | 62:d502889e74f1 | 193 | int _total_number_of_packets; |
tnhnrl | 62:d502889e74f1 | 194 | string _log_file_string; |
tnhnrl | 62:d502889e74f1 | 195 | |
tnhnrl | 62:d502889e74f1 | 196 | int _reply_byte; |
tnhnrl | 62:d502889e74f1 | 197 | int _reply_byte2; |
tnhnrl | 62:d502889e74f1 | 198 | int _reply_byte3; |
tnhnrl | 62:d502889e74f1 | 199 | int _reply_byte4; |
tnhnrl | 62:d502889e74f1 | 200 | int _previous_reply_byte; |
tnhnrl | 62:d502889e74f1 | 201 | |
tnhnrl | 62:d502889e74f1 | 202 | bool _file_transmission; //breaks out of loop in State Machine |
tnhnrl | 62:d502889e74f1 | 203 | |
tnhnrl | 67:c86a4b464682 | 204 | float _data_log[14]; //for logging all of the data from the outer and inner loops and so on |
tnhnrl | 62:d502889e74f1 | 205 | |
tnhnrl | 62:d502889e74f1 | 206 | int _confirmed_packet_number; |
tnhnrl | 62:d502889e74f1 | 207 | |
tnhnrl | 62:d502889e74f1 | 208 | bool _still_transmitting_data; |
tnhnrl | 62:d502889e74f1 | 209 | |
tnhnrl | 62:d502889e74f1 | 210 | int _transmit_counter; |
tnhnrl | 62:d502889e74f1 | 211 | |
tnhnrl | 62:d502889e74f1 | 212 | int _file_transmission_state; //needed to test out what's going on with receiver |
tnhnrl | 62:d502889e74f1 | 213 | |
tnhnrl | 62:d502889e74f1 | 214 | int _number_of_packets[2]; |
tnhnrl | 62:d502889e74f1 | 215 | |
tnhnrl | 62:d502889e74f1 | 216 | Ticker _mbed_transmit_ticker; |
tnhnrl | 62:d502889e74f1 | 217 | Ticker _mbed_receive_ticker; |
tnhnrl | 62:d502889e74f1 | 218 | |
tnhnrl | 62:d502889e74f1 | 219 | volatile bool _mbed_transmit_loop; |
tnhnrl | 62:d502889e74f1 | 220 | volatile bool _mbed_receive_loop; |
tnhnrl | 62:d502889e74f1 | 221 | |
tnhnrl | 62:d502889e74f1 | 222 | string _file_system_string; |
tnhnrl | 62:d502889e74f1 | 223 | string _full_file_path_string; |
tnhnrl | 62:d502889e74f1 | 224 | |
tnhnrl | 62:d502889e74f1 | 225 | bool _file_transmission_complete; //was volatile screwing up the state of this? |
tnhnrl | 63:6cb0405fc6e6 | 226 | |
tnhnrl | 63:6cb0405fc6e6 | 227 | int _log_file_line_counter; |
tnhnrl | 68:8f549749b8ce | 228 | |
tnhnrl | 68:8f549749b8ce | 229 | int _transmit_packet_num; |
tnhnrl | 69:919ac8d7e023 | 230 | |
tnhnrl | 69:919ac8d7e023 | 231 | bool _fsm_transmit_complete; |
tnhnrl | 62:d502889e74f1 | 232 | }; |
tnhnrl | 62:d502889e74f1 | 233 | |
tnhnrl | 62:d502889e74f1 | 234 | #endif |