@@ -70,6 +70,7 @@ VeDirectFrameHandler::VeDirectFrameHandler() :
70
70
_name(" " ),
71
71
_value(" " ),
72
72
_tmpFrame(),
73
+ _debugIn(0 ),
73
74
_lastByteMillis(0 ),
74
75
_lastUpdate(0 )
75
76
{
@@ -82,6 +83,18 @@ void VeDirectFrameHandler::init(int8_t rx, int8_t tx, Print* msgOut)
82
83
_msgOut = msgOut;
83
84
}
84
85
86
+ void VeDirectFrameHandler::dumpDebugBuffer () {
87
+ _msgOut->printf (" [VE.Direct] serial input:" );
88
+ for (int i = 0 ; i < _debugIn; ++i) {
89
+ if (i % 16 == 0 ) {
90
+ _msgOut->printf (" \r\n [VE.Direct] " );
91
+ }
92
+ _msgOut->printf (" %02x " , _debugBuffer[i]);
93
+ }
94
+ _msgOut->println (" " );
95
+ _debugIn = 0 ;
96
+ }
97
+
85
98
void VeDirectFrameHandler::loop ()
86
99
{
87
100
while ( VedirectSerial.available ()) {
@@ -94,6 +107,7 @@ void VeDirectFrameHandler::loop()
94
107
// to decode a new frame once more data arrives.
95
108
if (IDLE != _state && _lastByteMillis + 500 < millis ()) {
96
109
_msgOut->printf (" [VE.Direct] Resetting state machine (was %d) after timeout\r\n " , _state);
110
+ dumpDebugBuffer ();
97
111
_checksum = 0 ;
98
112
_state = IDLE;
99
113
_tmpFrame = { };
@@ -107,6 +121,12 @@ void VeDirectFrameHandler::loop()
107
121
*/
108
122
void VeDirectFrameHandler::rxData (uint8_t inbyte)
109
123
{
124
+ _debugBuffer[_debugIn] = inbyte;
125
+ _debugIn = (_debugIn + 1 ) % _debugBuffer.size ();
126
+ if (0 == _debugIn) {
127
+ _msgOut->println (" [VE.Direct] ERROR: debug buffer overrun!" );
128
+ }
129
+
110
130
// if (mStop) return;
111
131
if ( (inbyte == ' :' ) && (_state != CHECKSUM) ) {
112
132
_prevState = _state; // hex frame can interrupt TEXT
@@ -268,6 +288,9 @@ void VeDirectFrameHandler::textRxEvent(char * name, char * value) {
268
288
* is created in the public buffer.
269
289
*/
270
290
void VeDirectFrameHandler::frameEndEvent (bool valid) {
291
+ // TODO this should be toggled by a "verbose logging" switch
292
+ dumpDebugBuffer ();
293
+
271
294
if ( valid ) {
272
295
_tmpFrame.P = _tmpFrame.V * _tmpFrame.I ;
273
296
0 commit comments