add check for max telegram length

This commit is contained in:
Paul
2019-06-23 23:55:16 +02:00
parent 22a91a11f1
commit 4b28a1d9b5
2 changed files with 6 additions and 16 deletions

View File

@@ -67,9 +67,9 @@ static void ICACHE_FLASH_ATTR emsuart_recvTask(os_event_t * events) {
// validate and transmit the EMS buffer, excluding the BRK
if (length == 2) {
// it's a poll or status code, single byte
// it's a poll or status code, single byte and ok to send on
ems_parseTelegram((uint8_t *)pCurrent->buffer, 1);
} else if ((length > 4) && (pCurrent->buffer[length - 2] != 0x00)) {
} else if ((length > 4) && (length <= EMS_MAXBUFFERSIZE) && (pCurrent->buffer[length - 2] != 0x00)) {
// ignore double BRK at the end, possibly from the Tx loopback
// also telegrams with no data value
ems_parseTelegram((uint8_t *)pCurrent->buffer, length - 1); // transmit EMS buffer, excluding the BRK
@@ -159,16 +159,6 @@ void ICACHE_FLASH_ATTR emsuart_start() {
ETS_UART_INTR_ENABLE();
}
/*
* set loopback mode and clear Tx/Rx FIFO
*/
static inline void ICACHE_FLASH_ATTR emsuart_loopback(bool enable) {
if (enable)
USC0(EMSUART_UART) |= (1 << UCLBE); // enable loopback
else
USC0(EMSUART_UART) &= ~(1 << UCLBE); // disable loopback
}
/*
* Send to Tx, ending with a <BRK>
*/
@@ -205,7 +195,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
// worst case, we'll see an additional Rx-BRK...
if (!(USIS(EMSUART_UART) & (1 << UIBD))) {
// no bus collision - send terminating BRK signal
emsuart_loopback(true);
USC0(EMSUART_UART) |= (1 << UCLBE); // enable loopback
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
// wait until BRK detected...
@@ -216,7 +206,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
USC0(EMSUART_UART) &= ~(1 << UCBRK); // clear <BRK>
USIC(EMSUART_UART) = (1 << UIBD); // clear BRK detect IRQ
emsuart_loopback(false); // disable loopback mode
USC0(EMSUART_UART) &= ~(1 << UCLBE); // disable loopback
}
ETS_UART_INTR_ENABLE(); // receive anything from FIFO...

View File

@@ -13,7 +13,7 @@
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no stop bits, 1 parity)
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
#define EMS_MAXBUFFERS 10 // buffers for circular filling to avoid collisions
#define EMS_MAXBUFFERS 5 // buffers for circular filling to avoid collisions
#define EMS_MAXBUFFERSIZE 32 // max size of the buffer. packets are max 32 bytes to support EMS 1.0
#define EMSUART_BIT_TIME 104 // bit time @9600 baud