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:
tnhnrl
Date:
Tue Oct 23 20:35:16 2018 +0000
Revision:
79:3688c3a0d7f4
Parent:
74:d281aaef9766
Child:
82:0981b9ada820
SD card logger working

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 };
tnhnrl 62:d502889e74f1 33
tnhnrl 62:d502889e74f1 34 class MbedLogger {
tnhnrl 62:d502889e74f1 35 public:
tnhnrl 62:d502889e74f1 36 MbedLogger(string file_system_input_string); //constructor
tnhnrl 62:d502889e74f1 37
tnhnrl 62:d502889e74f1 38 void createTestLog(); //test log function
tnhnrl 62:d502889e74f1 39
tnhnrl 62:d502889e74f1 40 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 41
tnhnrl 62:d502889e74f1 42 //save float array to file (append each time)
tnhnrl 62:d502889e74f1 43 void saveDataToFile(int input_state, float *input);
tnhnrl 62:d502889e74f1 44
tnhnrl 62:d502889e74f1 45 //REVISED METHOD to save data (same as OpenLog)
tnhnrl 62:d502889e74f1 46 void recordData(int current_state);
tnhnrl 62:d502889e74f1 47
tnhnrl 62:d502889e74f1 48 //print the directory to the screen
tnhnrl 62:d502889e74f1 49 void printMbedDirectory();
tnhnrl 62:d502889e74f1 50
tnhnrl 62:d502889e74f1 51 //print the current MBED log file
tnhnrl 62:d502889e74f1 52 void printCurrentLogFile();
tnhnrl 62:d502889e74f1 53
tnhnrl 62:d502889e74f1 54 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 55 void transmitCurrentLogFileLine(bool next_line);
tnhnrl 62:d502889e74f1 56
tnhnrl 62:d502889e74f1 57 //transmit data when receive confirmation
tnhnrl 62:d502889e74f1 58 //void transmitCurrentLogFile();
tnhnrl 62:d502889e74f1 59
tnhnrl 62:d502889e74f1 60 // Create the data packet
tnhnrl 62:d502889e74f1 61 void createDataPacket();
tnhnrl 62:d502889e74f1 62
tnhnrl 62:d502889e74f1 63 // Transmit the data packet
tnhnrl 62:d502889e74f1 64 void transmitDataPacket();
tnhnrl 62:d502889e74f1 65
tnhnrl 62:d502889e74f1 66 // read transmit packet from Python program
tnhnrl 62:d502889e74f1 67 int readTransmitPacket();
tnhnrl 62:d502889e74f1 68
tnhnrl 62:d502889e74f1 69 // REOPEN LINE READER
tnhnrl 62:d502889e74f1 70 void reOpenLineReader();
tnhnrl 62:d502889e74f1 71
tnhnrl 62:d502889e74f1 72 // OPEN LINE READER
tnhnrl 62:d502889e74f1 73 bool openLineReader();
tnhnrl 62:d502889e74f1 74
tnhnrl 62:d502889e74f1 75 //read packet
tnhnrl 62:d502889e74f1 76 void readPacketInSeries();
tnhnrl 62:d502889e74f1 77
tnhnrl 62:d502889e74f1 78 //get the number of packets
tnhnrl 69:919ac8d7e023 79 int getNumberOfPacketsInCurrentLog();
tnhnrl 62:d502889e74f1 80
tnhnrl 62:d502889e74f1 81 // END TRANSMISSION AND CLOSE FILE
tnhnrl 62:d502889e74f1 82 void endTransmissionCloseFile();
tnhnrl 62:d502889e74f1 83
tnhnrl 62:d502889e74f1 84 //open a file to write to it
tnhnrl 62:d502889e74f1 85 void openWriteFile();
tnhnrl 62:d502889e74f1 86
tnhnrl 62:d502889e74f1 87 bool checkForIncomingData();
tnhnrl 62:d502889e74f1 88
tnhnrl 62:d502889e74f1 89 void endReceiveData();
tnhnrl 62:d502889e74f1 90
tnhnrl 62:d502889e74f1 91 void copyFileExample();
tnhnrl 62:d502889e74f1 92
tnhnrl 62:d502889e74f1 93 int calcCrcOneArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 94 int calcCrcTwoArray(int *input_array, int array_length);
tnhnrl 62:d502889e74f1 95
tnhnrl 62:d502889e74f1 96 int calcCrcOne(); //used with vector _data_packet, cleaning up later
tnhnrl 62:d502889e74f1 97 int calcCrcTwo();
tnhnrl 62:d502889e74f1 98
tnhnrl 62:d502889e74f1 99 int calcCrcOneString (string string_input);
tnhnrl 62:d502889e74f1 100
tnhnrl 62:d502889e74f1 101 int calcCrcTwoString (string string_input);
tnhnrl 62:d502889e74f1 102
tnhnrl 62:d502889e74f1 103 //NEW for logging actual time
tnhnrl 62:d502889e74f1 104 void setLogTime(); //set a local time
tnhnrl 62:d502889e74f1 105
tnhnrl 62:d502889e74f1 106 int getSystemTime(); //parse the time to record to the log file
tnhnrl 62:d502889e74f1 107
tnhnrl 62:d502889e74f1 108 //NEW
tnhnrl 62:d502889e74f1 109 int sendReply();
tnhnrl 62:d502889e74f1 110 void sendReplyPacketNumber(int packet_number);
tnhnrl 62:d502889e74f1 111
tnhnrl 62:d502889e74f1 112 void resetReplyPacket();
tnhnrl 62:d502889e74f1 113
tnhnrl 62:d502889e74f1 114 void openNewMissionFile();
tnhnrl 62:d502889e74f1 115
tnhnrl 62:d502889e74f1 116 void setDataCounter(int input_counter);
tnhnrl 62:d502889e74f1 117
tnhnrl 62:d502889e74f1 118 void closeIncompleteFile();
tnhnrl 62:d502889e74f1 119
tnhnrl 62:d502889e74f1 120 void initializeLogFile();
tnhnrl 62:d502889e74f1 121
tnhnrl 62:d502889e74f1 122 int fileTransmitState();
tnhnrl 62:d502889e74f1 123
tnhnrl 62:d502889e74f1 124 int testGetFileSize();
tnhnrl 62:d502889e74f1 125
tnhnrl 62:d502889e74f1 126 int getFileSize(string filename);
tnhnrl 62:d502889e74f1 127
tnhnrl 62:d502889e74f1 128 void createEmptyLog();
tnhnrl 62:d502889e74f1 129
tnhnrl 62:d502889e74f1 130 int debugFileState();
tnhnrl 62:d502889e74f1 131
tnhnrl 62:d502889e74f1 132 //TICKER AND FUNCTION TO RECEIVE DATA
tnhnrl 62:d502889e74f1 133 void activateReceivePacket();
tnhnrl 62:d502889e74f1 134 void receiveMissionDataWithTicker();
tnhnrl 62:d502889e74f1 135
tnhnrl 62:d502889e74f1 136 void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise
tnhnrl 62:d502889e74f1 137
tnhnrl 62:d502889e74f1 138 void specifyFileForTransmit(string input_string);
tnhnrl 62:d502889e74f1 139 void transmitFileFromDirectory(int file_number);
tnhnrl 62:d502889e74f1 140 void accessMbedDirectory();
tnhnrl 62:d502889e74f1 141
tnhnrl 62:d502889e74f1 142 int getFilePointerState();
tnhnrl 62:d502889e74f1 143 void testToggleFilePointer();
tnhnrl 62:d502889e74f1 144
tnhnrl 62:d502889e74f1 145 bool isTransmissionComplete();
tnhnrl 62:d502889e74f1 146 int currentPacketNumber();
tnhnrl 62:d502889e74f1 147 void eraseFile();
tnhnrl 62:d502889e74f1 148
tnhnrl 62:d502889e74f1 149 string _received_filename; //testing
tnhnrl 62:d502889e74f1 150
tnhnrl 74:d281aaef9766 151 void receiveSequenceFile();
tnhnrl 62:d502889e74f1 152 void receiveMissionDataWithFSM(); //for use in Finite State Machine
tnhnrl 62:d502889e74f1 153
tnhnrl 62:d502889e74f1 154 void openReceiveFile(string filename); //create a file with an input filename
tnhnrl 62:d502889e74f1 155
tnhnrl 62:d502889e74f1 156 void setTransmissionComplete(bool transmit_complete_status);
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 73:f6f378311c8d 172 void 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 73:f6f378311c8d 177
tnhnrl 73:f6f378311c8d 178 bool endTransmitPacket(); //used to exit FSM with Python
tnhnrl 73:f6f378311c8d 179
tnhnrl 73:f6f378311c8d 180 void blastData();
tnhnrl 73:f6f378311c8d 181
tnhnrl 73:f6f378311c8d 182 void transmitOnePacket();
tnhnrl 73:f6f378311c8d 183
tnhnrl 73:f6f378311c8d 184 void transmitMultiplePackets();
tnhnrl 62:d502889e74f1 185
tnhnrl 62:d502889e74f1 186 private:
tnhnrl 62:d502889e74f1 187 int _file_number;
tnhnrl 62:d502889e74f1 188
tnhnrl 62:d502889e74f1 189 char _file_name[256]; //file name placeholder
tnhnrl 62:d502889e74f1 190 char _line_buffer[256]; //line buffer used to read file line by line
tnhnrl 62:d502889e74f1 191
tnhnrl 79:3688c3a0d7f4 192 FILE *_fp; //the file pointer
tnhnrl 62:d502889e74f1 193
tnhnrl 62:d502889e74f1 194 vector <int> _data_packet;
tnhnrl 62:d502889e74f1 195
tnhnrl 62:d502889e74f1 196 std::vector<int>::iterator _it;
tnhnrl 62:d502889e74f1 197
tnhnrl 62:d502889e74f1 198 int _current_line_length;
tnhnrl 62:d502889e74f1 199
tnhnrl 62:d502889e74f1 200 int _packet_number;
tnhnrl 62:d502889e74f1 201 int _total_number_of_packets;
tnhnrl 62:d502889e74f1 202 string _log_file_string;
tnhnrl 62:d502889e74f1 203
tnhnrl 62:d502889e74f1 204 int _reply_byte;
tnhnrl 62:d502889e74f1 205 int _reply_byte2;
tnhnrl 62:d502889e74f1 206 int _reply_byte3;
tnhnrl 62:d502889e74f1 207 int _reply_byte4;
tnhnrl 62:d502889e74f1 208 int _previous_reply_byte;
tnhnrl 62:d502889e74f1 209
tnhnrl 62:d502889e74f1 210 bool _file_transmission; //breaks out of loop in State Machine
tnhnrl 62:d502889e74f1 211
tnhnrl 74:d281aaef9766 212 float _data_log[37]; //for logging all of the data from the outer and inner loops and so on
tnhnrl 62:d502889e74f1 213
tnhnrl 62:d502889e74f1 214 int _confirmed_packet_number;
tnhnrl 62:d502889e74f1 215
tnhnrl 62:d502889e74f1 216 bool _still_transmitting_data;
tnhnrl 62:d502889e74f1 217
tnhnrl 62:d502889e74f1 218 int _transmit_counter;
tnhnrl 62:d502889e74f1 219
tnhnrl 62:d502889e74f1 220 int _file_transmission_state; //needed to test out what's going on with receiver
tnhnrl 62:d502889e74f1 221
tnhnrl 62:d502889e74f1 222 int _number_of_packets[2];
tnhnrl 62:d502889e74f1 223
tnhnrl 62:d502889e74f1 224 Ticker _mbed_transmit_ticker;
tnhnrl 62:d502889e74f1 225 Ticker _mbed_receive_ticker;
tnhnrl 62:d502889e74f1 226
tnhnrl 62:d502889e74f1 227 volatile bool _mbed_transmit_loop;
tnhnrl 62:d502889e74f1 228 volatile bool _mbed_receive_loop;
tnhnrl 62:d502889e74f1 229
tnhnrl 62:d502889e74f1 230 string _file_system_string;
tnhnrl 62:d502889e74f1 231 string _full_file_path_string;
tnhnrl 62:d502889e74f1 232
tnhnrl 62:d502889e74f1 233 bool _file_transmission_complete; //was volatile screwing up the state of this?
tnhnrl 63:6cb0405fc6e6 234
tnhnrl 63:6cb0405fc6e6 235 int _log_file_line_counter;
tnhnrl 68:8f549749b8ce 236
tnhnrl 68:8f549749b8ce 237 int _transmit_packet_num;
tnhnrl 69:919ac8d7e023 238
tnhnrl 69:919ac8d7e023 239 bool _fsm_transmit_complete;
tnhnrl 73:f6f378311c8d 240
tnhnrl 73:f6f378311c8d 241 bool _end_transmit_packet;
tnhnrl 74:d281aaef9766 242
tnhnrl 74:d281aaef9766 243 bool _end_sequence_transmission;
tnhnrl 62:d502889e74f1 244 };
tnhnrl 62:d502889e74f1 245
tnhnrl 62:d502889e74f1 246 #endif