Browse Source

broker publish with protocol included

mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
7cfde70d85
2 changed files with 15 additions and 8 deletions
  1. +15
    -4
      code/espurna/rfbridge.cpp
  2. +0
    -4
      code/espurna/rfbridge.h

+ 15
- 4
code/espurna/rfbridge.cpp View File

@ -92,6 +92,8 @@ static std::unique_ptr<RfbLearn> _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<uint8_t>& 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<uint8_t>& 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<uint8_t>(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 <typename T>
@ -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();


+ 0
- 4
code/espurna/rfbridge.h View File

@ -14,11 +14,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#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);


Loading…
Cancel
Save