2020-04-27 16:36:39 +00: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).
|
|
|
|
*/
|
|
|
|
class SerialConsole : public StreamAPI, public RedirectablePrint
|
|
|
|
{
|
|
|
|
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-03 03:21:42 +00:00
|
|
|
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual size_t write(uint8_t c) override
|
2020-05-03 03:21:42 +00:00
|
|
|
{
|
|
|
|
if (c == '\n') // prefix any newlines with carriage return
|
|
|
|
RedirectablePrint::write('\r');
|
|
|
|
return RedirectablePrint::write(c);
|
|
|
|
}
|
2020-06-08 23:06:59 +00:00
|
|
|
|
|
|
|
protected:
|
2021-05-03 06:46:30 +00: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;
|
2020-04-27 16:36:39 +00:00
|
|
|
};
|
|
|
|
|
2021-03-10 07:21:30 +00:00
|
|
|
// A simple wrapper to allow non class aware code write to the console
|
|
|
|
void consolePrintf(const char *format, ...);
|
2021-03-24 22:15:15 +00:00
|
|
|
void consoleInit();
|
2021-03-10 07:21:30 +00:00
|
|
|
|
2021-03-24 22:15:15 +00:00
|
|
|
extern SerialConsole *console;
|