MRAS
Multi Rocket Avionics System
Loading...
Searching...
No Matches
NativeTextLogger.h
1//
2// Created by Tom Danvers on 13/12/2022.
3//
4
5#ifndef MRAS_NATIVETEXTLOGGER_H
6#define MRAS_NATIVETEXTLOGGER_H
7
8
9#include "TextLogger.h"
10#include "MRAS_Config.h"
11#include "system_messages/TextLogMsg.h"
12#include <cstdio>
13#include <cstdarg>
14
21public:
22 explicit NativeTextLogger(uint8_t id) : TextLogger(id) {};
23
30 void _log(const char *fmt, va_list args) override;
31
32 int8_t setup() override {
33 log("Setup...");
34 printf(MRAS_STARTUP_STRING);
35 return 0;
36 }
37
38 int8_t loop() override {
39 return 0;
40 }
41
42 const char* get_name() override {
43 return "NativeTextLogger";
44 }
45};
46
47void NativeTextLogger::_log(const char *fmt, va_list args) {
48 // https://stackoverflow.com/questions/20639632/how-to-wrap-printf-into-a-function-or-macro
49 auto* msg = new TextLogMsg();
50 vsprintf(msg->text, fmt, args);
51 printf("%s", msg->text);
52 publish(msg);
53}
54
55
56#endif //MRAS_NATIVETEXTLOGGER_H
A TextLogger that is compatible with the Native MRAS build environment.
Definition: NativeTextLogger.h:20
void _log(const char *fmt, va_list args) override
Log a message to the console.
Definition: NativeTextLogger.h:47
const char * get_name() override
Definition: NativeTextLogger.h:42
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