diff --git a/n4-flight-software/src/custom_time.cpp b/n4-flight-software/src/custom_time.cpp new file mode 100644 index 0000000..2a4dd98 --- /dev/null +++ b/n4-flight-software/src/custom_time.cpp @@ -0,0 +1,23 @@ +/*!**************************************************************************** + * @file custom-time.c + * @brief This file implements functions to convert time in milliseconds to + * a human readable format to be used for logging time + *******************************************************************************/ + + +#include "custom_time.h" + +char tstamp[50]; +int minute=0, sec=0, msec=0; + +/*!**************************************************************************** + * @brief convert time in milliseconds to minutes, seconds and time that are human readable + * @param msec time in milliseconds, got from millis() function + *******************************************************************************/ +void convertTimestamp(unsigned long msec) { + minute = ((msec / 1000) / 60) % 60; + sec = (msec / 1000) % 60; + msec = msec % 1000; + + sprintf(tstamp, "%d:%d:%ul", minute, sec, msec); +} diff --git a/n4-flight-software/src/custom_time.h b/n4-flight-software/src/custom_time.h new file mode 100644 index 0000000..d176c89 --- /dev/null +++ b/n4-flight-software/src/custom_time.h @@ -0,0 +1,15 @@ +/*!**************************************************************************** + * @file custom-time.h + * @brief This file defines functions needed for time conversions + * for data logging + *******************************************************************************/ + +#ifndef CUSTOM_TIME_H +#define CUSTOM_TIME_H + +#include + +extern char tstamp[]; // to hold a human readable timestamp +void convertTimestamp(unsigned long); + +#endif \ No newline at end of file diff --git a/n4-flight-software/src/data-types.h b/n4-flight-software/src/data_types.h similarity index 100% rename from n4-flight-software/src/data-types.h rename to n4-flight-software/src/data_types.h diff --git a/n4-flight-software/src/logger.cpp b/n4-flight-software/src/logger.cpp index a3e35b6..83f958c 100644 --- a/n4-flight-software/src/logger.cpp +++ b/n4-flight-software/src/logger.cpp @@ -3,7 +3,7 @@ */ #include "logger.h" -#include "data-types.h" +#include "data_types.h" telemetry_type_t t; char pckt_buff[50]; diff --git a/n4-flight-software/src/logger.h b/n4-flight-software/src/logger.h index a2070f5..e0ae8a3 100644 --- a/n4-flight-software/src/logger.h +++ b/n4-flight-software/src/logger.h @@ -16,7 +16,7 @@ #include #include -#include "data-types.h" +#include "data_types.h" class DataLogger { private: diff --git a/n4-flight-software/src/main.cpp b/n4-flight-software/src/main.cpp index 2d4e6bc..30420d7 100644 --- a/n4-flight-software/src/main.cpp +++ b/n4-flight-software/src/main.cpp @@ -25,8 +25,8 @@ #include "mpu.h" #include "SerialFlash.h" #include "logger.h" -#include "data-types.h" -#include "custom-time.h" +#include "data_types.h" +#include "custom_time.h" #include "states.h" #include "system_logger.h" #include "system_log_levels.h" @@ -1222,6 +1222,8 @@ void setup(){ /* initialize the system logger */ InitSPIFFS(); + + /* mode 0 resets the system log file by clearing all the current contents */ system_logger.logToFile(SPIFFS, 0, rocket_ID, level, system_log_file, "Game Time!"); debugln(); diff --git a/n4-flight-software/src/pin-assignment.MD b/n4-flight-software/src/pin_assignment.MD similarity index 100% rename from n4-flight-software/src/pin-assignment.MD rename to n4-flight-software/src/pin_assignment.MD diff --git a/n4-flight-software/src/system_logger.cpp b/n4-flight-software/src/system_logger.cpp index 1ca8cf7..6e7d9c8 100644 --- a/n4-flight-software/src/system_logger.cpp +++ b/n4-flight-software/src/system_logger.cpp @@ -3,13 +3,16 @@ void SystemLogger::logToFile (fs::FS &fs, uint8_t mode, const char* client, uint8_t log_level, const char* file, const char* msg) { char log_buffer[100]; // get the timestamp - uint32_t timestamp = millis(); + unsigned long raw_timestamp = millis(); + + // convert the timestamp to human readable format + convertTimestamp(raw_timestamp); // construct the log message // timestamp clientID log_level msg sprintf(log_buffer, - "%d %s %s %s\n", - timestamp, + "%c %d %s %s %s\n", + tstamp, client, this->getLogLevelString(log_level), msg diff --git a/n4-flight-software/src/system_logger.h b/n4-flight-software/src/system_logger.h index c2ebe32..12d569b 100644 --- a/n4-flight-software/src/system_logger.h +++ b/n4-flight-software/src/system_logger.h @@ -4,6 +4,7 @@ #include #include #include +#include "custom_time.h" class SystemLogger { public: diff --git a/n4-flight-software/src/custom-time.h b/n4-flight-software/test/log_time_fmt_test/custom-time.h similarity index 89% rename from n4-flight-software/src/custom-time.h rename to n4-flight-software/test/log_time_fmt_test/custom-time.h index 60d2c64..9bb2e05 100644 --- a/n4-flight-software/src/custom-time.h +++ b/n4-flight-software/test/log_time_fmt_test/custom-time.h @@ -9,6 +9,6 @@ #include -char* convertTimestamp(unsigned long); - +void convertTimestamp(unsigned long); +ma #endif \ No newline at end of file diff --git a/n4-flight-software/src/custom-time.cpp b/n4-flight-software/test/log_time_fmt_test/log_time_fmt_test.ino similarity index 83% rename from n4-flight-software/src/custom-time.cpp rename to n4-flight-software/test/log_time_fmt_test/log_time_fmt_test.ino index a191d96..beb849b 100644 --- a/n4-flight-software/src/custom-time.cpp +++ b/n4-flight-software/test/log_time_fmt_test/log_time_fmt_test.ino @@ -1,3 +1,4 @@ + /*!**************************************************************************** * @file custom-time.c * @brief This file implements functions to convert time in milliseconds to @@ -14,12 +15,23 @@ int minute=0, sec=0, msec=0; * @brief convert time in milliseconds to minutes, seconds and time that are human readable * @param msec time in milliseconds, got from millis() function *******************************************************************************/ -char* convertTimestamp(unsigned long msec) { +void convertTimestamp(unsigned long msec) { minute = ((msec/1000)/60) % 60; sec = (msec/1000) % 60; msec = msec%1000; sprintf(tstamp, "%d:%d:%ul", minute, sec, msec); - return tstamp; } + +void setup() { + Serial.begin(115200); + +} + +void loop() { + convertTimestamp(millis()); + Serial.println(tstamp); + delay(200); +} +