Skip to content

Commit

Permalink
adds sys logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bytecod3 committed Aug 12, 2024
1 parent 1f7f996 commit 110f03a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 11 deletions.
23 changes: 23 additions & 0 deletions n4-flight-software/src/custom_time.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions n4-flight-software/src/custom_time.h
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>

extern char tstamp[]; // to hold a human readable timestamp
void convertTimestamp(unsigned long);

#endif
File renamed without changes.
2 changes: 1 addition & 1 deletion n4-flight-software/src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

#include "logger.h"
#include "data-types.h"
#include "data_types.h"

telemetry_type_t t;
char pckt_buff[50];
Expand Down
2 changes: 1 addition & 1 deletion n4-flight-software/src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <Arduino.h>
#include <SerialFlash.h>
#include "data-types.h"
#include "data_types.h"

class DataLogger {
private:
Expand Down
6 changes: 4 additions & 2 deletions n4-flight-software/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions n4-flight-software/src/system_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions n4-flight-software/src/system_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Arduino.h>
#include <FS.h>
#include <SPIFFS.h>
#include "custom_time.h"

class SystemLogger {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#include <Arduino.h>

char* convertTimestamp(unsigned long);

void convertTimestamp(unsigned long);
ma
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*!****************************************************************************
* @file custom-time.c
* @brief This file implements functions to convert time in milliseconds to
Expand All @@ -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);
}

0 comments on commit 110f03a

Please sign in to comment.