From 4b7db73e743bb15a15ad8a2566479a6de18adb45 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 8 Jun 2019 17:18:38 +0200 Subject: [PATCH] cosemtic changes --- src/ems.cpp | 28 +++++++++++++++++++--------- src/emsuart.cpp | 10 ++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/ems.cpp b/src/ems.cpp index 1f88c34d2..548bd9848 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -550,6 +550,15 @@ void _ems_sendTelegram() { return; } + // if we're preventing all outbound traffic, quit + if (EMS_Sys_Status.emsTxDisabled) { + EMS_TxQueue.shift(); // remove from queue + if (ems_getLogging() != EMS_SYS_LOGGING_NONE) { + myDebug_P(PSTR("in Listen Mode. All Tx is disabled.")); + } + return; + } + // get the first in the queue, which is at the head // we don't remove from the queue yet _EMS_TxTelegram EMS_TxTelegram = EMS_TxQueue.first(); @@ -561,19 +570,18 @@ void _ems_sendTelegram() { } // if we're in raw mode just fire and forget - // e.g. send 0B 88 02 00 20 if (EMS_TxTelegram.action == EMS_TX_TELEGRAM_RAW) { - _EMS_RxTelegram EMS_RxTelegram; // create new Rx object - - EMS_TxTelegram.data[EMS_TxTelegram.length - 1] = _crcCalculator(EMS_TxTelegram.data, EMS_TxTelegram.length); // add the CRC - EMS_RxTelegram.length = EMS_TxTelegram.length; // full length of telegram - EMS_RxTelegram.telegram = EMS_TxTelegram.data; - EMS_RxTelegram.timestamp = millis(); // now if (EMS_Sys_Status.emsLogging != EMS_SYS_LOGGING_NONE) { + _EMS_RxTelegram EMS_RxTelegram; // create new Rx object + EMS_RxTelegram.length = EMS_TxTelegram.length; // full length of telegram + EMS_RxTelegram.telegram = EMS_TxTelegram.data; + EMS_RxTelegram.timestamp = millis(); // now _debugPrintTelegram("Sending raw: ", &EMS_RxTelegram, COLOR_CYAN, true); } + + EMS_TxTelegram.data[EMS_TxTelegram.length - 1] = _crcCalculator(EMS_TxTelegram.data, EMS_TxTelegram.length); // add the CRC emsuart_tx_buffer(EMS_TxTelegram.data, EMS_TxTelegram.length); // send the telegram to the UART Tx - EMS_TxQueue.shift(); // remove from queue + EMS_TxQueue.shift(); // and remove from queue return; } @@ -2023,7 +2031,9 @@ void ems_doReadCommand(uint16_t type, uint8_t dest, bool forceRefresh) { // if we're preventing all outbound traffic, quit if (EMS_Sys_Status.emsTxDisabled) { - myDebug_P(PSTR("in Listen Mode. All Tx is disabled.")); + if (ems_getLogging() != EMS_SYS_LOGGING_NONE) { + myDebug_P(PSTR("in Listen Mode. All Tx is disabled.")); + } return; } diff --git a/src/emsuart.cpp b/src/emsuart.cpp index 1b6e4e227..5a9d96d5c 100644 --- a/src/emsuart.cpp +++ b/src/emsuart.cpp @@ -182,11 +182,13 @@ void ICACHE_FLASH_ATTR emsuart_tx_brk() { // automatically be sent when the tx fifo is empty tmp = (1 << UCBRK); USC0(EMSUART_UART) |= (tmp); // set bit - if (EMS_Sys_Status.emsTxMode <= 2) { - delayMicroseconds(EMSUART_TX_BRK_WAIT); // classic mode - } else if (EMS_Sys_Status.emsTxMode == 3) { + + if (EMS_Sys_Status.emsTxMode <= 2) { // classic mode + delayMicroseconds(EMSUART_TX_BRK_WAIT); + } else if (EMS_Sys_Status.emsTxMode == 3) { // junkers mode delayMicroseconds(EMSUART_TX_WAIT_BRK - EMSUART_TX_LAG); // 1144 (11 Bits) } + USC0(EMSUART_UART) &= ~(tmp); // clear bit } @@ -204,7 +206,7 @@ static inline void ICACHE_FLASH_ATTR emsuart_loopback(bool enable) { * Send to Tx, ending with a */ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) { - if (EMS_Sys_Status.emsTxMode == 0) { // Classic logic + if (EMS_Sys_Status.emsTxMode == 0) { // classic mode logic for (uint8_t i = 0; i < len; i++) { USF(EMSUART_UART) = buf[i]; }