MRAS
Multi Rocket Avionics System
Loading...
Searching...
No Matches
ArduinoTextLogger.h
1//
2// Created by robos on 17/12/2022.
3//
4
5#ifndef MRAS_ARDUINOTEXTLOGGER_H
6#define MRAS_ARDUINOTEXTLOGGER_H
7
8#include "Arduino.h"
9#include "TextLogger.h"
10#include <cstdio>
11#include <cstdarg>
12#include "MRAS_Config.h"
13#include "system_messages/TextLogMsg.h"
14
21private:
22 long _baud;
23public:
30 explicit ArduinoTextLogger(uint8_t id, long baud) : TextLogger(id) {
31 _baud = baud;
32 };
33
40 void _log(const char *fmt, va_list args) override;
41
47 int8_t setup() override {
48 Serial.begin(_baud);
49 log("Successfully set up Serial connection");
50 Serial.println(MRAS_STARTUP_STRING);
51 return 0;
52 }
53
59 int8_t loop() override {
60 return 0;
61 }
62
63 SUBSYSTEM_NAME("ArduinoTextLogger")
64};
65
66
67void ArduinoTextLogger::_log(const char *fmt, va_list args) {
68 // https://stackoverflow.com/questions/20639632/how-to-wrap-printf-into-a-function-or-macro
69 auto* msg = new TextLogMsg();
70 vsprintf(msg->text, fmt, args);
71 Serial.print(msg->text);
72 publish(msg);
73}
74
75#endif //MRAS_ARDUINOTEXTLOGGER_H
A TextLogger that logs to the Arduino Serial connection.
Definition: ArduinoTextLogger.h:20
void _log(const char *fmt, va_list args) override
Log a message to the Arduino Serial connection.
Definition: ArduinoTextLogger.h:67
int8_t setup() override
Set up the Serial connection.
Definition: ArduinoTextLogger.h:47
ArduinoTextLogger(uint8_t id, long baud)
Construct a new Arduino Text Logger object.
Definition: ArduinoTextLogger.h:30
int8_t loop() override
Do nothing.
Definition: ArduinoTextLogger.h:59
void publish(SystemMessage *msg)
Definition: Subsystem.cpp:51
A base class for ArduinoTextLogger and NativeTextLogger.
Definition: TextLogger.h:18
A message containing text to be logged.
Definition: TextLogMsg.h:15