From 9ce1a5b488273763d15e7bc5642c06d9dde7aba4 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 25 May 2019 11:21:13 +0200 Subject: [PATCH] poll from milli to micro secs for better accuracy --- src/ems-esp.cpp | 2 +- src/ems.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index b5f3b386d..f8e21cf31 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -339,7 +339,7 @@ void showInfo() { if (ems_getBusConnected()) { myDebug_P(PSTR(" Bus is connected")); - myDebug_P(PSTR(" Rx: Poll=%d ms, # Rx telegrams read=%d, # CRC errors=%d"), ems_getPollFrequency(), EMS_Sys_Status.emsRxPgks, EMS_Sys_Status.emxCrcErr); + myDebug_P(PSTR(" Rx: Poll=%d microsecs, # Rx telegrams read=%d, # CRC errors=%d"), ems_getPollFrequency(), EMS_Sys_Status.emsRxPgks, EMS_Sys_Status.emxCrcErr); if (ems_getTxCapable()) { myDebug_P(PSTR(" Tx: available, Tx delay is %d, # Tx telegrams sent=%d"), ems_getTxDelay(), EMS_Sys_Status.emsTxPkgs); diff --git a/src/ems.cpp b/src/ems.cpp index aedbe4651..7242fdea7 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -680,12 +680,13 @@ void _ems_readTelegram(uint8_t * telegram, uint8_t length) { // 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) { - uint8_t value = telegram[0]; // 1st byte of data package - - EMS_Sys_Status.emsPollFrequency = (EMS_RxTelegram.timestamp - _last_emsPollFrequency); - _last_emsPollFrequency = EMS_RxTelegram.timestamp; + uint32_t timenow_microsecs = micros(); + EMS_Sys_Status.emsPollFrequency = (timenow_microsecs - _last_emsPollFrequency); + _last_emsPollFrequency = timenow_microsecs; // check first for a Poll for us + uint8_t value = telegram[0]; // 1st byte of data package + if ((value & 0x7F) == EMS_ID_ME) { EMS_Sys_Status.emsTxCapable = true;