From e7f2d194ae0846dab4cee75643736c808b8b7942 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 4 Jun 2020 22:22:36 +0200 Subject: [PATCH] clang style formatting --- src/emsesp.cpp | 10 ++++++---- src/roomcontrol.cpp | 40 ++++++++++++++++++++-------------------- src/roomcontrol.h | 11 ++++++----- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 99c9c2da9..940cbd6a5 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -564,9 +564,11 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { uint8_t first_value = data[0]; if (((first_value & 0x7F) == txservice_.ems_bus_id()) && (length > 1)) { // if we ask ourself at roomcontrol for version e.g. 0B 98 02 ... - Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data, length); - rxservice_.add(data, length); // just for logging - return; // it's an echo + Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data); +#ifdef EMSESP_DEBUG + rxservice_.add(data, length); // just for logging, if compiled with additional debugging +#endif + return; // it's an echo } // are we waiting for a response from a recent Tx Read or Write? @@ -627,7 +629,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { return; } else { // check if there is a message for the roomcontroller - Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data, length); + Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data); // add to RxQueue, what ever it is. rxservice_.add(data, length); } diff --git a/src/roomcontrol.cpp b/src/roomcontrol.cpp index ec17eae7f..12f08be15 100644 --- a/src/roomcontrol.cpp +++ b/src/roomcontrol.cpp @@ -18,19 +18,16 @@ #include "roomcontrol.h" -MAKE_PSTR(logger_name, "roomctrl") - namespace emsesp { -uint32_t rc_time_ = 0; -uint16_t hc_ = EMS_VALUE_USHORT_NOTSET; -int16_t remotetemp[4] = { - EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET -}; +uint32_t rc_time_ = 0; +uint16_t hc_ = EMS_VALUE_USHORT_NOTSET; +int16_t remotetemp[4] = {EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET}; + /** * set the temperature, */ -void Roomctrl::set_remotetemp(uint8_t hc, int16_t temp){ +void Roomctrl::set_remotetemp(uint8_t hc, int16_t temp) { remotetemp[hc] = temp; } @@ -47,9 +44,9 @@ void Roomctrl::send(uint8_t addr) { if (remotetemp[hc_] == EMS_VALUE_SHORT_NOTSET) { return; } - if (millis() - rc_time_ > 60000) { // send every minute - rc_time_ = millis(); - temperature(addr, 0x00); // send to all + if (uuid::get_uptime() - rc_time_ > SEND_INTERVAL) { // send every minute + rc_time_ = uuid::get_uptime(); // use EMS-ESP's millis() to prevent overhead + temperature(addr, 0x00); // send to all } else { // acknowledge every poll, otherwise the master shows error A11-822 EMSuart::send_poll(addr); @@ -59,16 +56,19 @@ void Roomctrl::send(uint8_t addr) { /** * check if there is a message for the remote room controller */ -void Roomctrl::check(uint8_t addr, uint8_t * data, const uint8_t length) { +void Roomctrl::check(uint8_t addr, uint8_t * data) { uint8_t hc_num = addr - ADDR; + // check address, reply only on addresses 0x18..0x1B if (hc_num > 3) { return; } + // no reply if the temperature is not set if (remotetemp[hc_num] == EMS_VALUE_SHORT_NOTSET) { return; } + // for now we only reply to version and remote temperature if (data[2] == 0x02) { version(addr, data[0]); @@ -114,14 +114,14 @@ void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset) void Roomctrl::temperature(uint8_t addr, uint8_t dst) { uint8_t data[10]; uint8_t hc_ = addr - ADDR; - data[0] = addr; - data[1] = dst; - data[2] = 0xAF; - data[3] = 0; - data[4] = (uint8_t)(remotetemp[hc_] >> 8); - data[5] = (uint8_t)(remotetemp[hc_] & 0xFF); - data[6] = 0; - data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC + data[0] = addr; + data[1] = dst; + data[2] = 0xAF; + data[3] = 0; + data[4] = (uint8_t)(remotetemp[hc_] >> 8); + data[5] = (uint8_t)(remotetemp[hc_] & 0xFF); + data[6] = 0; + data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC EMSuart::transmit(data, 8); } diff --git a/src/roomcontrol.h b/src/roomcontrol.h index 14c68552e..b4917173a 100644 --- a/src/roomcontrol.h +++ b/src/roomcontrol.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EMSESP_ROOMCTRL_H -#define EMSESP_ROOMCTRL_H +#ifndef EMSESP_ROOMCONTROL_H +#define EMSESP_ROOMCONTROL_H #include "emsesp.h" #include "telegram.h" @@ -29,15 +29,16 @@ namespace emsesp { class Roomctrl { public: static void send(uint8_t addr); - static void check(uint8_t addr, uint8_t * data, const uint8_t length); + static void check(uint8_t addr, uint8_t * data); static void set_remotetemp(uint8_t hc, int16_t temp); private: - #define ADDR 0x18 + static constexpr uint8_t ADDR = 0x18; + static constexpr uint32_t SEND_INTERVAL = 60000; // 1 minute + static void version(uint8_t addr, uint8_t dst); static void unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset); static void temperature(uint8_t addr, uint8_t dst); - }; } // namespace emsesp