diff --git a/code/espurna/rfbridge.cpp b/code/espurna/rfbridge.cpp index a3857f9a..ce22b2ad 100644 --- a/code/espurna/rfbridge.cpp +++ b/code/espurna/rfbridge.cpp @@ -92,6 +92,8 @@ static std::unique_ptr _rfb_learn; // EFM8BB1 PROTOCOL PARSING // ----------------------------------------------------------------------------- +constexpr uint8_t RfbDefaultProtocol { 0u }; + constexpr uint8_t CodeStart { 0xAAu }; constexpr uint8_t CodeEnd { 0x55u }; @@ -591,11 +593,12 @@ void _rfbParse(uint8_t code, const std::vector& payload) { #endif #if BROKER_SUPPORT - RfbridgeBroker::Publish(buffer + 6); + RfbridgeBroker::Publish(RfbDefaultProtocol, buffer + 6); #endif } break; } + case CodeRecvProto: case CodeRecvBucket: { _rfbAckImpl(); @@ -604,14 +607,21 @@ void _rfbParse(uint8_t code, const std::vector& payload) { DEBUG_MSG_P(PSTR("[RF] Received %s code: %s\n"), (CodeRecvProto == code) ? "advanced" : "bucket", buffer ); + #if MQTT_SUPPORT mqttSend(MQTT_TOPIC_RFIN, buffer, false, false); #endif + +#if BROKER_SUPPORT + // ref. https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/0xA6#example-of-a-received-decoded-protocol + RfbridgeBroker::Publish(payload[0], buffer + 2); +#endif } else { - DEBUG_MSG_P(PSTR("[RF] Received code %02X (%u bytes)\n"), code, payload.size()); + DEBUG_MSG_P(PSTR("[RF] Received 0x%02X (%u bytes)\n"), code, payload.size()); } break; } + } } @@ -625,6 +635,7 @@ void _rfbReceiveImpl() { continue; } + // narrowing is justified, as `c` can only contain byte-sized value if (!_rfb_parser.loop(static_cast(c))) { _rfb_parser.reset(); } @@ -665,7 +676,7 @@ size_t _rfb_bits_for_bytes(size_t bits) { return bytes; } -// TODO: 'Code' long unsigned int != uint32_t, thus the specialization +// TODO: RCSwitch code type: long unsigned int != uint32_t, thus the specialization static_assert(sizeof(uint32_t) == sizeof(long unsigned int), ""); template @@ -1172,7 +1183,7 @@ void rfbSetup() { _rfb_repeat = getSetting("rfbRepeat", RFB_SEND_TIMES); - // Note: as rfbridge protocol is simplictic enough, we rely on Serial queue to deliver timely updates + // Note: as rfbridge protocol is simplistic enough, we rely on Serial queue to deliver timely updates // learn / command acks / etc. are not queued, only RF messages are espurnaRegisterLoop([]() { _rfbReceiveImpl(); diff --git a/code/espurna/rfbridge.h b/code/espurna/rfbridge.h index f1df96df..e0304f6f 100644 --- a/code/espurna/rfbridge.h +++ b/code/espurna/rfbridge.h @@ -14,11 +14,7 @@ Copyright (C) 2016-2019 by Xose PĂ©rez #include "broker.h" -#if RFB_PROVIDER == RFB_PROVIDER_EFM8BB1 -BrokerDeclare(RfbridgeBroker, void(const char* code)); -#elif RFB_PROVIDER == RFB_PROVIDER_RCSWITCH BrokerDeclare(RfbridgeBroker, void(unsigned char protocol, const char* code)); -#endif void rfbStatus(unsigned char id, bool status); void rfbLearn(unsigned char id, bool status);