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:
Thu Feb 15 02:40:30 2018 +0000
Revision:
46:030be9f5c793
Child:
49:47ffa4feb6db
reduced array sizes to reduce class sizes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tnhnrl 46:030be9f5c793 1 #ifndef MBEDLOGGER_HPP
tnhnrl 46:030be9f5c793 2 #define MBEDLOGGER_HPP
tnhnrl 46:030be9f5c793 3
tnhnrl 46:030be9f5c793 4 #include "mbed.h"
tnhnrl 46:030be9f5c793 5 #include <string>
tnhnrl 46:030be9f5c793 6 using namespace std;
tnhnrl 46:030be9f5c793 7
tnhnrl 46:030be9f5c793 8 #include "SDFileSystem.h"
tnhnrl 46:030be9f5c793 9
tnhnrl 46:030be9f5c793 10 #include <vector>
tnhnrl 46:030be9f5c793 11
tnhnrl 46:030be9f5c793 12 enum {
tnhnrl 46:030be9f5c793 13 HEADER_117,
tnhnrl 46:030be9f5c793 14 HEADER_101,
tnhnrl 46:030be9f5c793 15 PACKET_NUM,
tnhnrl 46:030be9f5c793 16 TOTAL_NUM_PACKETS,
tnhnrl 46:030be9f5c793 17 PACKET_SIZE,
tnhnrl 46:030be9f5c793 18 END_TRANSMISSION,
tnhnrl 46:030be9f5c793 19 TRANSMIT_PACKET_1,
tnhnrl 46:030be9f5c793 20 TRANSMIT_PACKET_2,
tnhnrl 46:030be9f5c793 21 PACKET_CRC_ONE,
tnhnrl 46:030be9f5c793 22 PACKET_CRC_TWO,
tnhnrl 46:030be9f5c793 23 RANDOM_CHAR
tnhnrl 46:030be9f5c793 24 };
tnhnrl 46:030be9f5c793 25
tnhnrl 46:030be9f5c793 26 class MbedLogger {
tnhnrl 46:030be9f5c793 27 public:
tnhnrl 46:030be9f5c793 28 MbedLogger(string file_system_input_string); //constructor
tnhnrl 46:030be9f5c793 29
tnhnrl 46:030be9f5c793 30 void createTestLog(); //test log function
tnhnrl 46:030be9f5c793 31
tnhnrl 46:030be9f5c793 32 void appendLogFile(int current_state, int option); //check if you have orphaned file pointers before this (file should not be open already)
tnhnrl 46:030be9f5c793 33
tnhnrl 46:030be9f5c793 34 //one log file type for now
tnhnrl 46:030be9f5c793 35 void openSDFile();
tnhnrl 46:030be9f5c793 36
tnhnrl 46:030be9f5c793 37 void copySDFile(); //copy SD card files
tnhnrl 46:030be9f5c793 38
tnhnrl 46:030be9f5c793 39 //save float array to file (append each time)
tnhnrl 46:030be9f5c793 40 void saveDataToFile(int input_state, float *input);
tnhnrl 46:030be9f5c793 41
tnhnrl 46:030be9f5c793 42 //REVISED METHOD to save data (same as OpenLog)
tnhnrl 46:030be9f5c793 43 void recordData(int current_state);
tnhnrl 46:030be9f5c793 44
tnhnrl 46:030be9f5c793 45 //print the directory to the screen
tnhnrl 46:030be9f5c793 46 void printMbedDirectory();
tnhnrl 46:030be9f5c793 47
tnhnrl 46:030be9f5c793 48 //print the current MBED log file
tnhnrl 46:030be9f5c793 49 void printCurrentLogFile();
tnhnrl 46:030be9f5c793 50
tnhnrl 46:030be9f5c793 51 //open file for transmit
tnhnrl 46:030be9f5c793 52 void openFileForTransmit();
tnhnrl 46:030be9f5c793 53
tnhnrl 46:030be9f5c793 54 //transmit data when receive confirmation
tnhnrl 46:030be9f5c793 55 void transmitCurrentLogFileLine(bool next_line);
tnhnrl 46:030be9f5c793 56
tnhnrl 46:030be9f5c793 57 //transmit data when receive confirmation
tnhnrl 46:030be9f5c793 58 //void transmitCurrentLogFile();
tnhnrl 46:030be9f5c793 59
tnhnrl 46:030be9f5c793 60 // Create the data packet
tnhnrl 46:030be9f5c793 61 void createDataPacket();
tnhnrl 46:030be9f5c793 62
tnhnrl 46:030be9f5c793 63 // Transmit the data packet
tnhnrl 46:030be9f5c793 64 void transmitDataPacket();
tnhnrl 46:030be9f5c793 65
tnhnrl 46:030be9f5c793 66 // read transmit packet from Python program
tnhnrl 46:030be9f5c793 67 int readTransmitPacket();
tnhnrl 46:030be9f5c793 68
tnhnrl 46:030be9f5c793 69 // REOPEN LINE READER
tnhnrl 46:030be9f5c793 70 void reOpenLineReader();
tnhnrl 46:030be9f5c793 71
tnhnrl 46:030be9f5c793 72 // OPEN LINE READER
tnhnrl 46:030be9f5c793 73 bool openLineReader();
tnhnrl 46:030be9f5c793 74
tnhnrl 46:030be9f5c793 75 //read packet
tnhnrl 46:030be9f5c793 76 void readPacketInSeries();
tnhnrl 46:030be9f5c793 77
tnhnrl 46:030be9f5c793 78 //get the number of packets
tnhnrl 46:030be9f5c793 79 void getNumberOfPacketsInCurrentLog();
tnhnrl 46:030be9f5c793 80
tnhnrl 46:030be9f5c793 81 // END TRANSMISSION AND CLOSE FILE
tnhnrl 46:030be9f5c793 82 void endTransmissionCloseFile();
tnhnrl 46:030be9f5c793 83
tnhnrl 46:030be9f5c793 84 //open a file to write to it
tnhnrl 46:030be9f5c793 85 void openWriteFile();
tnhnrl 46:030be9f5c793 86
tnhnrl 46:030be9f5c793 87 bool checkForIncomingData();
tnhnrl 46:030be9f5c793 88
tnhnrl 46:030be9f5c793 89 void endReceiveData();
tnhnrl 46:030be9f5c793 90
tnhnrl 46:030be9f5c793 91 void copyFileExample();
tnhnrl 46:030be9f5c793 92
tnhnrl 46:030be9f5c793 93 int calcCrcOne(); //used only when creating the data packet, apparently you need to pass array size to function
tnhnrl 46:030be9f5c793 94
tnhnrl 46:030be9f5c793 95 int calcCrcTwo(); //used only when creating the data packet, apparently you need to pass array size to function
tnhnrl 46:030be9f5c793 96
tnhnrl 46:030be9f5c793 97 int calcCrcOneString (string string_input);
tnhnrl 46:030be9f5c793 98
tnhnrl 46:030be9f5c793 99 int calcCrcTwoString (string string_input);
tnhnrl 46:030be9f5c793 100
tnhnrl 46:030be9f5c793 101 //NEW for logging actual time
tnhnrl 46:030be9f5c793 102 void setLogTime(); //set a local time
tnhnrl 46:030be9f5c793 103
tnhnrl 46:030be9f5c793 104 int getSystemTime(); //parse the time to record to the log file
tnhnrl 46:030be9f5c793 105
tnhnrl 46:030be9f5c793 106 //NEW
tnhnrl 46:030be9f5c793 107 int sendReply();
tnhnrl 46:030be9f5c793 108 void sendReplyPacketNumber(int packet_number);
tnhnrl 46:030be9f5c793 109
tnhnrl 46:030be9f5c793 110 void resetReplyPacket();
tnhnrl 46:030be9f5c793 111
tnhnrl 46:030be9f5c793 112 void openNewMissionFile();
tnhnrl 46:030be9f5c793 113
tnhnrl 46:030be9f5c793 114 void setDataCounter(int input_counter);
tnhnrl 46:030be9f5c793 115
tnhnrl 46:030be9f5c793 116 void closeIncompleteFile();
tnhnrl 46:030be9f5c793 117
tnhnrl 46:030be9f5c793 118 void initializeLogFile();
tnhnrl 46:030be9f5c793 119
tnhnrl 46:030be9f5c793 120 int fileTransmitState();
tnhnrl 46:030be9f5c793 121
tnhnrl 46:030be9f5c793 122 int testGetFileSize();
tnhnrl 46:030be9f5c793 123
tnhnrl 46:030be9f5c793 124 int getFileSize(string filename);
tnhnrl 46:030be9f5c793 125
tnhnrl 46:030be9f5c793 126 void createEmptyLog();
tnhnrl 46:030be9f5c793 127
tnhnrl 46:030be9f5c793 128 int debugFileState();
tnhnrl 46:030be9f5c793 129
tnhnrl 46:030be9f5c793 130 //TICKER AND FUNCTION TO TRANSMIT DATA
tnhnrl 46:030be9f5c793 131 void activateTransmitPacket();
tnhnrl 46:030be9f5c793 132 void transmitDataWithTicker();
tnhnrl 46:030be9f5c793 133
tnhnrl 46:030be9f5c793 134 //TICKER AND FUNCTION TO RECEIVE DATA
tnhnrl 46:030be9f5c793 135 void activateReceivePacket();
tnhnrl 46:030be9f5c793 136 void receiveMissionDataWithTicker();
tnhnrl 46:030be9f5c793 137
tnhnrl 46:030be9f5c793 138 void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise
tnhnrl 46:030be9f5c793 139 void closeSDLogFile(); //this is using the file name from the timer to create sd card file names
tnhnrl 46:030be9f5c793 140
tnhnrl 46:030be9f5c793 141 void specifyFileForTransmit(string input_string);
tnhnrl 46:030be9f5c793 142 void transmitFileFromDirectory(int file_number);
tnhnrl 46:030be9f5c793 143 void accessMbedDirectory();
tnhnrl 46:030be9f5c793 144
tnhnrl 46:030be9f5c793 145 int getFilePointerState();
tnhnrl 46:030be9f5c793 146 void testToggleFilePointer();
tnhnrl 46:030be9f5c793 147
tnhnrl 46:030be9f5c793 148 int getNumberOfPackets();
tnhnrl 46:030be9f5c793 149
tnhnrl 46:030be9f5c793 150 void readTransmitPacketOneChar();
tnhnrl 46:030be9f5c793 151
tnhnrl 46:030be9f5c793 152 bool isTransmissionComplete();
tnhnrl 46:030be9f5c793 153
tnhnrl 46:030be9f5c793 154 int currentPacketNumber();
tnhnrl 46:030be9f5c793 155
tnhnrl 46:030be9f5c793 156 private:
tnhnrl 46:030be9f5c793 157 int _f; //file name number
tnhnrl 46:030be9f5c793 158 char _file_name[256]; //file name placeholder
tnhnrl 46:030be9f5c793 159 int _file_number;
tnhnrl 46:030be9f5c793 160
tnhnrl 46:030be9f5c793 161 FILE *_fp; //the file is a class member variable
tnhnrl 46:030be9f5c793 162
tnhnrl 46:030be9f5c793 163 char _line_buffer[256];
tnhnrl 46:030be9f5c793 164
tnhnrl 46:030be9f5c793 165 vector <int> _data_packet;
tnhnrl 46:030be9f5c793 166
tnhnrl 46:030be9f5c793 167 std::vector<int>::iterator _it;
tnhnrl 46:030be9f5c793 168
tnhnrl 46:030be9f5c793 169 int _current_line_length;
tnhnrl 46:030be9f5c793 170
tnhnrl 46:030be9f5c793 171 int _packet_number;
tnhnrl 46:030be9f5c793 172 int _total_number_of_packets;
tnhnrl 46:030be9f5c793 173 string _log_file_string;
tnhnrl 46:030be9f5c793 174
tnhnrl 46:030be9f5c793 175 int _reply_byte;
tnhnrl 46:030be9f5c793 176 int _reply_byte2;
tnhnrl 46:030be9f5c793 177 int _reply_byte3;
tnhnrl 46:030be9f5c793 178 int _reply_byte4;
tnhnrl 46:030be9f5c793 179 int _previous_reply_byte;
tnhnrl 46:030be9f5c793 180
tnhnrl 46:030be9f5c793 181 bool _file_transmission; //breaks out of loop in State Machine
tnhnrl 46:030be9f5c793 182
tnhnrl 46:030be9f5c793 183 float _data_log[11]; //for logging all of the data from the outer and inner loops and so on
tnhnrl 46:030be9f5c793 184
tnhnrl 46:030be9f5c793 185 int _confirmed_packet_number;
tnhnrl 46:030be9f5c793 186
tnhnrl 46:030be9f5c793 187 bool _still_transmitting_data;
tnhnrl 46:030be9f5c793 188
tnhnrl 46:030be9f5c793 189 int _transmit_counter;
tnhnrl 46:030be9f5c793 190
tnhnrl 46:030be9f5c793 191 int _file_transmission_state; //needed to test out what's going on with receiver
tnhnrl 46:030be9f5c793 192
tnhnrl 46:030be9f5c793 193 int _number_of_packets[2];
tnhnrl 46:030be9f5c793 194
tnhnrl 46:030be9f5c793 195 Ticker _mbed_transmit_ticker;
tnhnrl 46:030be9f5c793 196 Ticker _mbed_receive_ticker;
tnhnrl 46:030be9f5c793 197
tnhnrl 46:030be9f5c793 198 volatile bool _mbed_transmit_loop;
tnhnrl 46:030be9f5c793 199 volatile bool _mbed_receive_loop;
tnhnrl 46:030be9f5c793 200
tnhnrl 46:030be9f5c793 201 string _file_system_string;
tnhnrl 46:030be9f5c793 202 string _SD_file_name_string;
tnhnrl 46:030be9f5c793 203 string _full_file_path_string;
tnhnrl 46:030be9f5c793 204
tnhnrl 46:030be9f5c793 205 volatile bool _file_transmission_complete;
tnhnrl 46:030be9f5c793 206 };
tnhnrl 46:030be9f5c793 207
tnhnrl 46:030be9f5c793 208 #endif