2020-04-27 09:36:39 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "RedirectablePrint.h"
|
|
|
|
|
#include "StreamAPI.h"
|
|
|
|
|
/**
|
|
|
|
|
* Provides both debug printing and, if the client starts sending protobufs to us, switches to send/receive protobufs
|
|
|
|
|
* (and starts dropping debug printing - FIXME, eventually those prints should be encapsulated in protobufs).
|
|
|
|
|
*/
|
2022-12-22 18:24:42 +01:00
|
|
|
class SerialConsole : public StreamAPI, public RedirectablePrint, private concurrency::OSThread
|
2020-04-27 09:36:39 -07:00
|
|
|
{
|
2024-06-30 16:41:27 -07:00
|
|
|
/**
|
|
|
|
|
* If true we are talking to a smart host and all messages (including log messages) must be framed as protobufs.
|
|
|
|
|
*/
|
|
|
|
|
bool usingProtobufs = false;
|
|
|
|
|
|
2020-04-27 09:36:39 -07:00
|
|
|
public:
|
|
|
|
|
SerialConsole();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* we override this to notice when we've received a protobuf over the serial stream. Then we shunt off
|
|
|
|
|
* debug serial output.
|
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool handleToRadio(const uint8_t *buf, size_t len) override;
|
2020-05-02 20:21:42 -07:00
|
|
|
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual size_t write(uint8_t c) override
|
2020-05-02 20:21:42 -07:00
|
|
|
{
|
|
|
|
|
if (c == '\n') // prefix any newlines with carriage return
|
|
|
|
|
RedirectablePrint::write('\r');
|
|
|
|
|
return RedirectablePrint::write(c);
|
|
|
|
|
}
|
2020-06-08 16:06:59 -07:00
|
|
|
|
2022-12-22 18:24:42 +01:00
|
|
|
virtual int32_t runOnce() override;
|
|
|
|
|
|
2023-01-04 10:37:27 +01:00
|
|
|
void flush();
|
2025-09-24 16:45:40 +02:00
|
|
|
void rxInt();
|
2023-01-04 10:37:27 +01:00
|
|
|
|
2020-06-08 16:06:59 -07:00
|
|
|
protected:
|
2021-05-03 14:46:30 +08:00
|
|
|
/// Check the current underlying physical link to see if the client is currently connected
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool checkIsConnected() override;
|
2024-06-30 16:41:27 -07:00
|
|
|
|
2025-09-24 16:45:40 +02:00
|
|
|
virtual void onNowHasData(uint32_t fromRadioNum) override;
|
|
|
|
|
|
2024-06-30 16:41:27 -07:00
|
|
|
/// Possibly switch to protobufs if we see a valid protobuf message
|
|
|
|
|
virtual void log_to_serial(const char *logLevel, const char *format, va_list arg);
|
2020-04-27 09:36:39 -07:00
|
|
|
};
|
|
|
|
|
|
2021-03-10 15:21:30 +08:00
|
|
|
// A simple wrapper to allow non class aware code write to the console
|
|
|
|
|
void consolePrintf(const char *format, ...);
|
2021-03-25 06:15:15 +08:00
|
|
|
void consoleInit();
|
2021-03-10 15:21:30 +08:00
|
|
|
|
2024-06-30 16:41:27 -07:00
|
|
|
extern SerialConsole *console;
|