ve.diect with hex asnync messages
ignore async hex messeage on older devices
This commit is contained in:
parent
40cee1f9ca
commit
b8e06bf824
@ -60,6 +60,7 @@ VeDirectFrameHandler::VeDirectFrameHandler() :
|
|||||||
_state(IDLE),
|
_state(IDLE),
|
||||||
_checksum(0),
|
_checksum(0),
|
||||||
_textPointer(0),
|
_textPointer(0),
|
||||||
|
_hexSize(0),
|
||||||
_name(""),
|
_name(""),
|
||||||
_value(""),
|
_value(""),
|
||||||
_tmpFrame(),
|
_tmpFrame(),
|
||||||
@ -99,7 +100,9 @@ void VeDirectFrameHandler::rxData(uint8_t inbyte)
|
|||||||
{
|
{
|
||||||
//if (mStop) return;
|
//if (mStop) return;
|
||||||
if ( (inbyte == ':') && (_state != CHECKSUM) ) {
|
if ( (inbyte == ':') && (_state != CHECKSUM) ) {
|
||||||
|
_prevState = _state; //hex frame can interrupt TEXT
|
||||||
_state = RECORD_HEX;
|
_state = RECORD_HEX;
|
||||||
|
_hexSize = 0;
|
||||||
}
|
}
|
||||||
if (_state != RECORD_HEX) {
|
if (_state != RECORD_HEX) {
|
||||||
_checksum += inbyte;
|
_checksum += inbyte;
|
||||||
@ -177,10 +180,7 @@ void VeDirectFrameHandler::rxData(uint8_t inbyte)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RECORD_HEX:
|
case RECORD_HEX:
|
||||||
if (hexRxEvent(inbyte)) {
|
_state = hexRxEvent(inbyte);
|
||||||
_checksum = 0;
|
|
||||||
_state = IDLE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,10 +279,27 @@ void VeDirectFrameHandler::logE(const char * module, const char * error) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* hexRxEvent
|
* hexRxEvent
|
||||||
* This function included for continuity and possible future use.
|
* This function records hex answers or async messages
|
||||||
*/
|
*/
|
||||||
bool VeDirectFrameHandler::hexRxEvent(uint8_t inbyte) {
|
int VeDirectFrameHandler::hexRxEvent(uint8_t inbyte) {
|
||||||
return true; // stubbed out for future
|
int ret=RECORD_HEX; // default - continue recording until end of frame
|
||||||
|
|
||||||
|
switch (inbyte) {
|
||||||
|
case '\n':
|
||||||
|
// restore previous state
|
||||||
|
ret=_prevState;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_hexSize++;
|
||||||
|
if (_hexSize>=VE_MAX_HEX_LEN) { // oops -buffer overflow - something went wrong, we abort
|
||||||
|
logE(MODULE,"hexRx buffer overflow - aborting read");
|
||||||
|
_hexSize=0;
|
||||||
|
ret=IDLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VeDirectFrameHandler::isDataValid() {
|
bool VeDirectFrameHandler::isDataValid() {
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#define VE_MAX_NAME_LEN 9 // VE.Direct Protocol: max name size is 9 including /0
|
#define VE_MAX_NAME_LEN 9 // VE.Direct Protocol: max name size is 9 including /0
|
||||||
#define VE_MAX_VALUE_LEN 33 // VE.Direct Protocol: max value size is 33 including /0
|
#define VE_MAX_VALUE_LEN 33 // VE.Direct Protocol: max value size is 33 including /0
|
||||||
|
#define VE_MAX_HEX_LEN 100 // Maximum size of hex frame - max payload 34 byte (=68 char) + safe buffer
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t PID; // product id
|
uint16_t PID; // product id
|
||||||
@ -69,12 +71,14 @@ private:
|
|||||||
void textRxEvent(char *, char *);
|
void textRxEvent(char *, char *);
|
||||||
void frameEndEvent(bool); // copy temp struct to public struct
|
void frameEndEvent(bool); // copy temp struct to public struct
|
||||||
void logE(const char *, const char *);
|
void logE(const char *, const char *);
|
||||||
bool hexRxEvent(uint8_t);
|
int hexRxEvent(uint8_t);
|
||||||
|
|
||||||
//bool mStop; // not sure what Victron uses this for, not using
|
//bool mStop; // not sure what Victron uses this for, not using
|
||||||
int _state; // current state
|
int _state; // current state
|
||||||
|
int _prevState; // previous state
|
||||||
uint8_t _checksum; // checksum value
|
uint8_t _checksum; // checksum value
|
||||||
char * _textPointer; // pointer to the private buffer we're writing to, name or value
|
char * _textPointer; // pointer to the private buffer we're writing to, name or value
|
||||||
|
int _hexSize; // length of hex buffer
|
||||||
char _name[VE_MAX_VALUE_LEN]; // buffer for the field name
|
char _name[VE_MAX_VALUE_LEN]; // buffer for the field name
|
||||||
char _value[VE_MAX_VALUE_LEN]; // buffer for the field value
|
char _value[VE_MAX_VALUE_LEN]; // buffer for the field value
|
||||||
veStruct _tmpFrame{}; // private struct for received name and value pairs
|
veStruct _tmpFrame{}; // private struct for received name and value pairs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user