From 054f83555c859fcbe8e0bef8f4d194cb5148895a Mon Sep 17 00:00:00 2001 From: proddy Date: Fri, 4 Jan 2019 11:24:31 +0100 Subject: [PATCH] 1.2.4. remove duplicate scan ids --- CHANGELOG.md | 7 +++---- src/ems.cpp | 34 ++++++++++++++++++++++------------ src/ems.h | 3 +++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3a90d07..f6ca1d081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.2.4] 2019-01-03 +## [1.2.4] 2019-01-04 -### Fixed +### Changed -- RC35 fetching current temp -- MQTT data max set to 600 and resolved a memory issue +- Scanning known EMS Devices now ignores duplicates (https://github.com/proddy/EMS-ESP-Boiler/pull/30) ## [1.2.3] 2019-01-03 diff --git a/src/ems.cpp b/src/ems.cpp index de1550a47..bfa7a298a 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -80,10 +80,6 @@ const _Thermostat_Type Thermostat_Types[] = { }; -// calculate sizes of arrays -uint8_t _Model_Types_max = ArraySize(Model_Types); // number of models -uint8_t _Thermostat_Types_max = ArraySize(Thermostat_Types); // number of defined thermostat types - const _EMS_Type EMS_Types[] = { // common @@ -133,9 +129,13 @@ const _EMS_Type EMS_Types[] = { }; -uint8_t _EMS_Types_max = ArraySize(EMS_Types); // number of defined types -// reserve space for the data we collect from the Boiler and Thermostat +// calculate sizes of arrays +uint8_t _EMS_Types_max = ArraySize(EMS_Types); // number of defined types +uint8_t _Model_Types_max = ArraySize(Model_Types); // number of models +uint8_t _Thermostat_Types_max = ArraySize(Thermostat_Types); // number of defined thermostat types + +// these structs contain the data we store from the Boiler and Thermostat _EMS_Boiler EMS_Boiler; _EMS_Thermostat EMS_Thermostat; @@ -1410,12 +1410,22 @@ _EMS_MODEL_ID ems_getBoilerModel() { * Find the versions of our connected devices */ void ems_scanDevices() { - // send Version request to all known EMS devices myDebug("Scanning EMS bus for devices. This may take a few seconds."); - for (int i = 0; i < _Model_Types_max; i++) { - if ((Model_Types[i].model_id != EMS_MODEL_NONE) && (Model_Types[i].model_id != EMS_MODEL_SERVICEKEY)) { - ems_doReadCommand(EMS_TYPE_Version, Model_Types[i].type_id); - } + + // copy over the IDs from Model-type to a list + std::list Device_Ids; + for (_Model_Type mt : Model_Types) { + Device_Ids.push_back(mt.type_id); + } + // remove duplicates and reserved IDs (like our own device) + Device_Ids.sort(); + Device_Ids.unique(); + Device_Ids.remove(EMS_MODEL_NONE); + Device_Ids.remove(EMS_MODEL_SERVICEKEY); + + // send the read command with Version command + for (uint8_t type_id : Device_Ids) { + ems_doReadCommand(EMS_TYPE_Version, type_id); } } @@ -1444,7 +1454,7 @@ void ems_printAllTypes() { if (Model_Types[j].model_id == Thermostat_Types[i].model_id) { int index = _ems_findModel(Model_Types[j].model_id); if (index != -1) { - myDebug(" %s [ID 0x%02X] Product ID:%d read_supported:%s write_supported:%s", + myDebug(" %s [ID 0x%02X] Product ID:%d Read supported:%s Write supported:%s", Model_Types[index].model_string, Model_Types[index].type_id, Model_Types[index].product_id, diff --git a/src/ems.h b/src/ems.h index 7a6fe9b2c..3214ddc76 100644 --- a/src/ems.h +++ b/src/ems.h @@ -11,6 +11,9 @@ #include // https://github.com/rlogiacco/CircularBuffer #include +#include +#include + // EMS IDs #define EMS_ID_NONE 0x00 // Fixed - used as a dest in broadcast messages and empty type IDs #define EMS_ID_ME 0x0B // Fixed - our device, hardcoded as "Service Key"