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
Diff: MbedLogger/MbedLogger.hpp
- Revision:
- 46:030be9f5c793
- Child:
- 49:47ffa4feb6db
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedLogger/MbedLogger.hpp Thu Feb 15 02:40:30 2018 +0000 @@ -0,0 +1,208 @@ +#ifndef MBEDLOGGER_HPP +#define MBEDLOGGER_HPP + +#include "mbed.h" +#include <string> +using namespace std; + +#include "SDFileSystem.h" + +#include <vector> + +enum { + HEADER_117, + HEADER_101, + PACKET_NUM, + TOTAL_NUM_PACKETS, + PACKET_SIZE, + END_TRANSMISSION, + TRANSMIT_PACKET_1, + TRANSMIT_PACKET_2, + PACKET_CRC_ONE, + PACKET_CRC_TWO, + RANDOM_CHAR +}; + +class MbedLogger { +public: + MbedLogger(string file_system_input_string); //constructor + + void createTestLog(); //test log function + + void appendLogFile(int current_state, int option); //check if you have orphaned file pointers before this (file should not be open already) + + //one log file type for now + void openSDFile(); + + void copySDFile(); //copy SD card files + + //save float array to file (append each time) + void saveDataToFile(int input_state, float *input); + + //REVISED METHOD to save data (same as OpenLog) + void recordData(int current_state); + + //print the directory to the screen + void printMbedDirectory(); + + //print the current MBED log file + void printCurrentLogFile(); + + //open file for transmit + void openFileForTransmit(); + + //transmit data when receive confirmation + void transmitCurrentLogFileLine(bool next_line); + + //transmit data when receive confirmation + //void transmitCurrentLogFile(); + + // Create the data packet + void createDataPacket(); + + // Transmit the data packet + void transmitDataPacket(); + + // read transmit packet from Python program + int readTransmitPacket(); + + // REOPEN LINE READER + void reOpenLineReader(); + + // OPEN LINE READER + bool openLineReader(); + + //read packet + void readPacketInSeries(); + + //get the number of packets + void getNumberOfPacketsInCurrentLog(); + + // END TRANSMISSION AND CLOSE FILE + void endTransmissionCloseFile(); + + //open a file to write to it + void openWriteFile(); + + bool checkForIncomingData(); + + void endReceiveData(); + + void copyFileExample(); + + int calcCrcOne(); //used only when creating the data packet, apparently you need to pass array size to function + + int calcCrcTwo(); //used only when creating the data packet, apparently you need to pass array size to function + + int calcCrcOneString (string string_input); + + int calcCrcTwoString (string string_input); + + //NEW for logging actual time + void setLogTime(); //set a local time + + int getSystemTime(); //parse the time to record to the log file + + //NEW + int sendReply(); + void sendReplyPacketNumber(int packet_number); + + void resetReplyPacket(); + + void openNewMissionFile(); + + void setDataCounter(int input_counter); + + void closeIncompleteFile(); + + void initializeLogFile(); + + int fileTransmitState(); + + int testGetFileSize(); + + int getFileSize(string filename); + + void createEmptyLog(); + + int debugFileState(); + + //TICKER AND FUNCTION TO TRANSMIT DATA + void activateTransmitPacket(); + void transmitDataWithTicker(); + + //TICKER AND FUNCTION TO RECEIVE DATA + void activateReceivePacket(); + void receiveMissionDataWithTicker(); + + void closeLogFile(); //this sets pointer to null and checks if it is closed otherwise + void closeSDLogFile(); //this is using the file name from the timer to create sd card file names + + void specifyFileForTransmit(string input_string); + void transmitFileFromDirectory(int file_number); + void accessMbedDirectory(); + + int getFilePointerState(); + void testToggleFilePointer(); + + int getNumberOfPackets(); + + void readTransmitPacketOneChar(); + + bool isTransmissionComplete(); + + int currentPacketNumber(); + +private: + int _f; //file name number + char _file_name[256]; //file name placeholder + int _file_number; + + FILE *_fp; //the file is a class member variable + + char _line_buffer[256]; + + vector <int> _data_packet; + + std::vector<int>::iterator _it; + + int _current_line_length; + + int _packet_number; + int _total_number_of_packets; + string _log_file_string; + + int _reply_byte; + int _reply_byte2; + int _reply_byte3; + int _reply_byte4; + int _previous_reply_byte; + + bool _file_transmission; //breaks out of loop in State Machine + + float _data_log[11]; //for logging all of the data from the outer and inner loops and so on + + int _confirmed_packet_number; + + bool _still_transmitting_data; + + int _transmit_counter; + + int _file_transmission_state; //needed to test out what's going on with receiver + + int _number_of_packets[2]; + + Ticker _mbed_transmit_ticker; + Ticker _mbed_receive_ticker; + + volatile bool _mbed_transmit_loop; + volatile bool _mbed_receive_loop; + + string _file_system_string; + string _SD_file_name_string; + string _full_file_path_string; + + volatile bool _file_transmission_complete; +}; + +#endif \ No newline at end of file