-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.h
164 lines (141 loc) · 3.82 KB
/
Logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include <Arduino.h>
#include <WiFiNINA.h>
#include "GarageControl.h"
/*
t
Logging.h
Arduino macros and function definitions for logging
if MNDEBUG is defined then output is sent to the Serial port else it is not compiled.
When outputting the Log commands repace Serial.print(ln) output
There are also functions to send ANSI escape sequences to allow output in colour and at specific screen locations
The serial monitor needs to be able to support these ANSI sequences. A free example is PuTTY.
Author: (c) M. Naylor 2022
History:
Ver 1.0 Initial version
*/
/*
Debug Config
*/
constexpr auto BAUD_RATE = 115200;
namespace MN ::Utils
{
void ResetBoard ( const __FlashStringHelper *pErrMsg );
}
class Logger : public Stream
{
public:
virtual void LogStart () = 0;
virtual bool CanDetectClientConnect () = 0;
virtual void SetConnectCallback ( voidFuncPtrParam ) {};
private:
};
class SerialLogger : public Logger
{
public:
const uint32_t BAUD_RATE = 115200;
void LogStart ();
bool CanDetectClientConnect ();
int available ();
int read ();
int peek ();
size_t write ( String Msg );
size_t write ( uint8_t c );
size_t write ( const uint8_t *buffer, size_t size );
};
/*
Telnet
This class is used to allow an incoming telnet connection. It only outputs and does not process incoming data
It does require an active (connected) network WiFi session
*/
constexpr uint16_t default_mcast_port = 0xFEEE;
class CTelnet : public Logger
{
public:
operator bool ();
void begin ( uint32_t s = default_mcast_port );
void LogStart ();
bool CanDetectClientConnect ();
void SetConnectCallback ( voidFuncPtrParam pConnectCallback ) override;
int available ();
private:
// char buff [ 32 ];
bool isConnected ();
size_t write ( String Msg );
size_t write ( uint8_t c );
size_t write ( const uint8_t *buffer, size_t size );
void DoConnect ();
int read ();
int peek ();
WiFiServer *m_pmyServer = nullptr;
WiFiClient m_myClient;
uint16_t m_telnetPort;
bool m_bClientConnected = false;
voidFuncPtrParam m_ConnectCallback = nullptr;
};
extern CTelnet Telnet;
/// @brief This class sends VT220 sequences to the supplied logger
class ansiVT220Logger
{
public:
// defines for ansi terminal sequences
// colours
enum colours : uint8_t {
FG_BLACK = 30,
FG_RED,
FG_GREEN,
FG_YELLOW,
FG_BLUE,
FG_MAGENTA,
FG_CYAN,
FG_WHITE,
BG_BLACK = 40,
BG_RED,
BG_GREEN,
BG_YELLOW,
BG_BLUE,
BG_MAGENTA,
BG_CYAN,
BG_WHITE,
FG_BRIGHTBLACK = 90,
FG_BRIGHTRED,
FG_BRIGHTGREEN,
FG_BRIGHTYELLOW,
FG_BRIGHTBLUE,
FG_BRIGHTMAGENTA,
FG_BRIGHTCYAN,
FG_BRIGHTWHITE,
BG_BRIGHTBLACK = 100,
BG_BRIGHTRED,
BG_BRIGHTGREEN,
BG_BRIGHTYELLOW,
BG_BRIGHTBLUE,
BG_BRIGHTMAGENTA,
BG_BRIGHTCYAN,
BG_BRIGHTWHITE
};
const static uint8_t MAX_COLS = 132;
const static uint8_t MAX_ROWS = 25;
ansiVT220Logger ( Logger &logger ) : m_logger ( logger ) {};
void ClearScreen ();
void AT ( uint8_t row, uint8_t col, String s );
void COLOUR_AT ( colours FGColour, colours BGColour, uint8_t row, uint8_t col, String s );
void RestoreCursor ( void );
void SaveCursor ( void );
void ClearLine ( uint8_t row );
void ClearPartofLine ( uint8_t row, uint8_t start_col, uint8_t toclear );
static void OnClientConnect ( void *ptr );
void LogStart ();
private:
Logger &m_logger;
const String CSI = F ( "\x1b[" );
const String SAVE_CURSOR = F ( "\x1b[s" );
const String RESTORE_CURSOR = F ( "\x1b[u" );
const String CLEAR_LINE = F ( "\x1b[2K" );
const String RESET_COLOURS = F ( "\x1b[0m" );
const String CLEAR_SCREEN = F ( "\x1b[2J" );
static String OSC;
static String WINDOW_TITLE;
static String SCREEN_SIZE132;
static String STRING_TERMINATOR;
};