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

Committer:
joel_ssc
Date:
Mon May 13 19:25:26 2019 +0000
Revision:
92:52a91656458a
Parent:
87:6d95f853dab3
version for first flight test, timeouts not yet set correctly

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);
tnhnrl 62:d502889e74f1 54
tnhnrl 62:d502889e74f1 55 //print the directory to the screen
tnhnrl 62:d502889e74f1 56 void printMbedDirectory();
tnhnrl 62:d502889e74f1 57
tnhnrl 62:d502889e74f1 58 //print the current MBED log file
tnhnrl 62:d502889e74f1 59 void printCurrentLogFile();
tnhnrl 62:d502889e74f1 60
tnhnrl 62:d502889e74f1 61 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 62 void transmitCurrentLogFileLine(bool next_line);
tnhnrl 62:d502889e74f1 63
tnhnrl 62:d502889e74f1 64 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 65 //void transmitCurrentLogFile();
tnhnrl 62:d502889e74f1 66
tnhnrl 62:d502889e74f1 67 // Create the data packet
tnhnrl 62:d502889e74f1 68 void createDataPacket();
tnhnrl 62:d502889e74f1 69
tnhnrl 62:d502889e74f1 70 // Transmit the data packet
tnhnrl 62:d502889e74f1 71 void transmitDataPacket();
tnhnrl 62:d502889e74f1 72
tnhnrl 62:d502889e74f1 73 // read transmit packet from Python program
tnhnrl 62:d502889e74f1 74 int readTransmitPacket();
tnhnrl 62:d502889e74f1 75
tnhnrl 62:d502889e74f1 76 // REOPEN LINE READER
tnhnrl 62:d502889e74f1 77 void reOpenLineReader();
tnhnrl 62:d502889e74f1 78
tnhnrl 62:d502889e74f1 79 // OPEN LINE READER
tnhnrl 62:d502889e74f1 80 bool openLineReader();
tnhnrl 62:d502889e74f1 81
tnhnrl 62:d502889e74f1 82 //read packet
tnhnrl 62:d502889e74f1 83 void readPacketInSeries();
tnhnrl 62:d502889e74f1 84
tnhnrl 62:d502889e74f1 85 //get the number of packets
tnhnrl 69:919ac8d7e023 86 int getNumberOfPacketsInCurrentLog();
tnhnrl 62:d502889e74f1 87
tnhnrl 62:d502889e74f1 88 // END TRANSMISSION AND CLOSE FILE
tnhnrl 62:d502889e74f1 89 void endTransmissionCloseFile();
tnhnrl 62:d502889e74f1 90
tnhnrl 62:d502889e74f1 91 //open a file to write to it
tnhnrl 62:d502889e74f1 92 void openWriteFile();
tnhnrl 62:d502889e74f1 93
tnhnrl 62:d502889e74f1 94 bool checkForIncomingData();
tnhnrl 62:d502889e74f1 95
tnhnrl 62:d502889e74f1 96 void endReceiveData();
tnhnrl 62:d502889e74f1 97
tnhnrl 62:d502889e74f1 98 void copyFileExample();
tnhnrl 62:d502889e74f1 99
tnhnrl 62:d502889e74f1 100 int calcCrcOneArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 101 int calcCrcTwoArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 102
tnhnrl 62:d502889e74f1 103 int calcCrcOne(); //used with vector _data_packet, cleaning up later
tnhnrl 62:d502889e74f1 104 int calcCrcTwo();
tnhnrl 62:d502889e74f1 105
tnhnrl 62:d502889e74f1 106 int calcCrcOneString (string string_input);
tnhnrl 62:d502889e74f1 107
tnhnrl 62:d502889e74f1 108 int calcCrcTwoString (string string_input);
tnhnrl 62:d502889e74f1 109
tnhnrl 62:d502889e74f1 110 //NEW for logging actual time
joel_ssc 86:ba3a118b0080 111 void setLogTime(long int setting_time); //set a local time
tnhnrl 62:d502889e74f1 112
joel_ssc 86:ba3a118b0080 113 time_t getSystemTime(); //parse the time to record to the log file
tnhnrl 62:d502889e74f1 114
tnhnrl 62:d502889e74f1 115 //NEW
tnhnrl 62:d502889e74f1 116 int sendReply();
tnhnrl 62:d502889e74f1 117 void sendReplyPacketNumber(int packet_number);
tnhnrl 62:d502889e74f1 118
tnhnrl 62:d502889e74f1 119 void resetReplyPacket();
tnhnrl 62:d502889e74f1 120
tnhnrl 62:d502889e74f1 121 void openNewMissionFile();
tnhnrl 62:d502889e74f1 122
tnhnrl 62:d502889e74f1 123 void setDataCounter(int input_counter);
tnhnrl 62:d502889e74f1 124
tnhnrl 62:d502889e74f1 125 void closeIncompleteFile();
tnhnrl 62:d502889e74f1 126
tnhnrl 62:d502889e74f1 127 void initializeLogFile();
joel_ssc 82:0981b9ada820 128 void initializeDiagFile(int print_diag);
tnhnrl 62:d502889e74f1 129
tnhnrl 62:d502889e74f1 130 int fileTransmitState();
tnhnrl 62:d502889e74f1 131
tnhnrl 62:d502889e74f1 132 int testGetFileSize();
tnhnrl 62:d502889e74f1 133
tnhnrl 62:d502889e74f1 134 int getFileSize(string filename);
tnhnrl 62:d502889e74f1 135
tnhnrl 62:d502889e74f1 136 void createEmptyLog();
tnhnrl 62:d502889e74f1 137
tnhnrl 62:d502889e74f1 138 int debugFileState();
tnhnrl 62:d502889e74f1 139
tnhnrl 62:d502889e74f1 140 //TICKER AND FUNCTION TO RECEIVE DATA
tnhnrl 62:d502889e74f1 141 void activateReceivePacket();
tnhnrl 62:d502889e74f1 142 void receiveMissionDataWithTicker();
tnhnrl 62:d502889e74f1 143
tnhnrl 62:d502889e74f1 144 void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise
joel_ssc 82:0981b9ada820 145 void closeDiagFile();
tnhnrl 62:d502889e74f1 146
tnhnrl 62:d502889e74f1 147 void specifyFileForTransmit(string input_string);
tnhnrl 62:d502889e74f1 148 void transmitFileFromDirectory(int file_number);
tnhnrl 62:d502889e74f1 149 void accessMbedDirectory();
tnhnrl 62:d502889e74f1 150
tnhnrl 62:d502889e74f1 151 int getFilePointerState();
tnhnrl 62:d502889e74f1 152 void testToggleFilePointer();
tnhnrl 62:d502889e74f1 153
tnhnrl 62:d502889e74f1 154 bool isTransmissionComplete();
tnhnrl 62:d502889e74f1 155 int currentPacketNumber();
tnhnrl 62:d502889e74f1 156 void eraseFile();
tnhnrl 62:d502889e74f1 157
tnhnrl 62:d502889e74f1 158 string _received_filename; //testing
tnhnrl 62:d502889e74f1 159
tnhnrl 74:d281aaef9766 160 void receiveSequenceFile();
tnhnrl 62:d502889e74f1 161 void receiveMissionDataWithFSM(); //for use in Finite State Machine
tnhnrl 62:d502889e74f1 162
tnhnrl 62:d502889e74f1 163 void openReceiveFile(string filename); //create a file with an input filename
tnhnrl 62:d502889e74f1 164
tnhnrl 62:d502889e74f1 165 void setTransmissionComplete(bool transmit_complete_status);
tnhnrl 62:d502889e74f1 166
tnhnrl 62:d502889e74f1 167 void intCreateDataPacket(int data_buffer[],int payload_length);
tnhnrl 63:6cb0405fc6e6 168
tnhnrl 63:6cb0405fc6e6 169 int getLogSize(); //used in state machine
tnhnrl 67:c86a4b464682 170
tnhnrl 67:c86a4b464682 171 string _heading_string;
joel_ssc 82:0981b9ada820 172 string _diag_heading_string;
tnhnrl 68:8f549749b8ce 173
tnhnrl 68:8f549749b8ce 174 void continuouslyTransmitData();
tnhnrl 68:8f549749b8ce 175
tnhnrl 68:8f549749b8ce 176 void continuouslyTransmitDataNoTimer();
tnhnrl 68:8f549749b8ce 177
tnhnrl 68:8f549749b8ce 178 void transmitPacketNumber(int line_or_packet_number);
tnhnrl 68:8f549749b8ce 179
tnhnrl 69:919ac8d7e023 180 void checkForPythonTransmitRequest();
tnhnrl 68:8f549749b8ce 181
tnhnrl 73:f6f378311c8d 182 void fsmTransmitData();
tnhnrl 68:8f549749b8ce 183
tnhnrl 68:8f549749b8ce 184 void setTransmitPacketNumber(int packet_number);
tnhnrl 69:919ac8d7e023 185
tnhnrl 69:919ac8d7e023 186 void createDataPacket(char line_buffer_sent[], int line_length_sent);
tnhnrl 73:f6f378311c8d 187
tnhnrl 73:f6f378311c8d 188 bool endTransmitPacket(); //used to exit FSM with Python
tnhnrl 73:f6f378311c8d 189
tnhnrl 73:f6f378311c8d 190 void blastData();
tnhnrl 73:f6f378311c8d 191
tnhnrl 73:f6f378311c8d 192 void transmitOnePacket();
tnhnrl 73:f6f378311c8d 193
tnhnrl 73:f6f378311c8d 194 void transmitMultiplePackets();
tnhnrl 62:d502889e74f1 195
tnhnrl 62:d502889e74f1 196 private:
tnhnrl 62:d502889e74f1 197 int _file_number;
tnhnrl 62:d502889e74f1 198
tnhnrl 62:d502889e74f1 199 char _file_name[256]; //file name placeholder
tnhnrl 62:d502889e74f1 200 char _line_buffer[256]; //line buffer used to read file line by line
tnhnrl 62:d502889e74f1 201
joel_ssc 82:0981b9ada820 202 FILE *_fp; //the log file pointer
joel_ssc 82:0981b9ada820 203 FILE *_fp2; // the diag file pointer
tnhnrl 62:d502889e74f1 204
tnhnrl 62:d502889e74f1 205 vector <int> _data_packet;
tnhnrl 62:d502889e74f1 206
tnhnrl 62:d502889e74f1 207 std::vector<int>::iterator _it;
tnhnrl 62:d502889e74f1 208
tnhnrl 62:d502889e74f1 209 int _current_line_length;
tnhnrl 62:d502889e74f1 210
tnhnrl 62:d502889e74f1 211 int _packet_number;
tnhnrl 62:d502889e74f1 212 int _total_number_of_packets;
tnhnrl 62:d502889e74f1 213 string _log_file_string;
tnhnrl 62:d502889e74f1 214
tnhnrl 62:d502889e74f1 215 int _reply_byte;
tnhnrl 62:d502889e74f1 216 int _reply_byte2;
tnhnrl 62:d502889e74f1 217 int _reply_byte3;
tnhnrl 62:d502889e74f1 218 int _reply_byte4;
tnhnrl 62:d502889e74f1 219 int _previous_reply_byte;
tnhnrl 62:d502889e74f1 220
tnhnrl 62:d502889e74f1 221 bool _file_transmission; //breaks out of loop in State Machine
tnhnrl 62:d502889e74f1 222
tnhnrl 74:d281aaef9766 223 float _data_log[37]; //for logging all of the data from the outer and inner loops and so on
tnhnrl 62:d502889e74f1 224
tnhnrl 62:d502889e74f1 225 int _confirmed_packet_number;
tnhnrl 62:d502889e74f1 226
joel_ssc 86:ba3a118b0080 227 int _default_timestamp_time;
joel_ssc 87:6d95f853dab3 228 int _time_set;
joel_ssc 86:ba3a118b0080 229
tnhnrl 62:d502889e74f1 230 bool _still_transmitting_data;
tnhnrl 62:d502889e74f1 231
tnhnrl 62:d502889e74f1 232 int _transmit_counter;
tnhnrl 62:d502889e74f1 233
tnhnrl 62:d502889e74f1 234 int _file_transmission_state; //needed to test out what's going on with receiver
tnhnrl 62:d502889e74f1 235
tnhnrl 62:d502889e74f1 236 int _number_of_packets[2];
tnhnrl 62:d502889e74f1 237
tnhnrl 62:d502889e74f1 238 Ticker _mbed_transmit_ticker;
tnhnrl 62:d502889e74f1 239 Ticker _mbed_receive_ticker;
tnhnrl 62:d502889e74f1 240
tnhnrl 62:d502889e74f1 241 volatile bool _mbed_transmit_loop;
tnhnrl 62:d502889e74f1 242 volatile bool _mbed_receive_loop;
tnhnrl 62:d502889e74f1 243
tnhnrl 62:d502889e74f1 244 string _file_system_string;
tnhnrl 62:d502889e74f1 245 string _full_file_path_string;
joel_ssc 82:0981b9ada820 246 string _full_diagfile_path_string;
tnhnrl 62:d502889e74f1 247
tnhnrl 62:d502889e74f1 248 bool _file_transmission_complete; //was volatile screwing up the state of this?
tnhnrl 63:6cb0405fc6e6 249
tnhnrl 63:6cb0405fc6e6 250 int _log_file_line_counter;
tnhnrl 68:8f549749b8ce 251
tnhnrl 68:8f549749b8ce 252 int _transmit_packet_num;
tnhnrl 69:919ac8d7e023 253
tnhnrl 69:919ac8d7e023 254 bool _fsm_transmit_complete;
tnhnrl 73:f6f378311c8d 255
tnhnrl 73:f6f378311c8d 256 bool _end_transmit_packet;
tnhnrl 74:d281aaef9766 257
tnhnrl 74:d281aaef9766 258 bool _end_sequence_transmission;
tnhnrl 62:d502889e74f1 259 };
tnhnrl 62:d502889e74f1 260
tnhnrl 62:d502889e74f1 261 #endif