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:
Mon Jun 18 14:45:37 2018 +0000
Revision:
62:d502889e74f1
Child:
63:6cb0405fc6e6
in process of making an exit command on timeout from data transmission

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