mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
ignore null telegrams
This commit is contained in:
25
src/ems.cpp
25
src/ems.cpp
@@ -579,33 +579,34 @@ void _createValidate() {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Entry point TODO: tidy up
|
* Entry point triggered by an interrupt in emsuart.cpp
|
||||||
|
* length is only data bytes, excluding the BRK
|
||||||
|
* Read commands are asynchronous as they're handled by the interrupt
|
||||||
|
* When a telegram is processed we forcefully erase it from the stack to prevent overflow
|
||||||
*/
|
*/
|
||||||
void ems_parseTelegram(uint8_t * telegram, uint8_t length) {
|
void ems_parseTelegram(uint8_t * telegram, uint8_t length) {
|
||||||
_ems_readTelegram(telegram, length);
|
if ((length != 0) && (telegram[0] != 0x00)) {
|
||||||
// now clear it just be safe
|
_ems_readTelegram(telegram, length);
|
||||||
for (uint8_t i = 0; i < EMS_MAXBUFFERSIZE; i++) {
|
|
||||||
telegram[i] = 0x00;
|
|
||||||
}
|
}
|
||||||
|
// now clear the Rx buffer just be safe and prevent duplicates
|
||||||
|
for (uint8_t i = 0; i < EMS_MAXBUFFERSIZE; telegram[i++] = 0x00)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the main logic that parses the telegram message, triggered by an interrupt in emsuart.cpp
|
* the main logic that parses the telegram message
|
||||||
* length is only data bytes, excluding the BRK
|
|
||||||
* Read commands are asynchronous as they're handled by the interrupt
|
|
||||||
* When we receive a Poll Request we need to send any Tx packages quickly within a 200ms window
|
* When we receive a Poll Request we need to send any Tx packages quickly within a 200ms window
|
||||||
*/
|
*/
|
||||||
void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
|
void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
|
||||||
// check if we just received a single byte
|
|
||||||
// it could well be a Poll request from the boiler for us, which will have a value of 0x8B (0x0B | 0x80)
|
|
||||||
// or either a return code like 0x01 or 0x04 from the last Write command
|
|
||||||
|
|
||||||
// create the Rx package
|
// create the Rx package
|
||||||
static _EMS_RxTelegram EMS_RxTelegram;
|
static _EMS_RxTelegram EMS_RxTelegram;
|
||||||
EMS_RxTelegram.length = length;
|
EMS_RxTelegram.length = length;
|
||||||
EMS_RxTelegram.telegram = telegram;
|
EMS_RxTelegram.telegram = telegram;
|
||||||
EMS_RxTelegram.timestamp = millis();
|
EMS_RxTelegram.timestamp = millis();
|
||||||
|
|
||||||
|
// check if we just received a single byte
|
||||||
|
// it could well be a Poll request from the boiler for us, which will have a value of 0x8B (0x0B | 0x80)
|
||||||
|
// or either a return code like 0x01 or 0x04 from the last Write command
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
uint8_t value = telegram[0]; // 1st byte of data package
|
uint8_t value = telegram[0]; // 1st byte of data package
|
||||||
|
|
||||||
|
|||||||
@@ -71,14 +71,9 @@ static void emsuart_rx_intr_handler(void * para) {
|
|||||||
* The full buffer is sent to the ems_parseTelegram() function in ems.cpp.
|
* The full buffer is sent to the ems_parseTelegram() function in ems.cpp.
|
||||||
*/
|
*/
|
||||||
static void ICACHE_FLASH_ATTR emsuart_recvTask(os_event_t * events) {
|
static void ICACHE_FLASH_ATTR emsuart_recvTask(os_event_t * events) {
|
||||||
// get next free EMS Receive buffer
|
|
||||||
_EMSRxBuf * pCurrent = pEMSRxBuf;
|
_EMSRxBuf * pCurrent = pEMSRxBuf;
|
||||||
pEMSRxBuf = paEMSRxBuf[++emsRxBufIdx % EMS_MAXBUFFERS];
|
ems_parseTelegram((uint8_t *)pCurrent->buffer, (pCurrent->writePtr) - 1); // transmit EMS buffer, excluding the BRK
|
||||||
|
pEMSRxBuf = paEMSRxBuf[++emsRxBufIdx % EMS_MAXBUFFERS]; // next free EMS Receive buffer
|
||||||
// transmit EMS buffer, excluding the BRK
|
|
||||||
if (pCurrent->writePtr > 1) {
|
|
||||||
ems_parseTelegram((uint8_t *)pCurrent->buffer, (pCurrent->writePtr) - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user