From 5028bbdcf05a1e17c27d8b6e6fafb7048886ecf6 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Wed, 26 Aug 2020 12:37:41 +0300 Subject: [PATCH] fix sender timing typo, fix code unpacking --- code/espurna/rfbridge.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/code/espurna/rfbridge.cpp b/code/espurna/rfbridge.cpp index 2b4fc208..c0eef0c0 100644 --- a/code/espurna/rfbridge.cpp +++ b/code/espurna/rfbridge.cpp @@ -709,17 +709,22 @@ void _rfbEnqueue(uint8_t protocol, uint16_t timing, uint8_t bits, RfbMessage::co _rfb_message_queue.push_back(RfbMessage{protocol, timing, bits, code, repeats}); } -void _rfbEnqueue(const char* code, unsigned char repeats = 1u) { +void _rfbEnqueue(const char* message, unsigned char repeats = 1u) { uint8_t buffer[RfbMessage::BufferSize] { 0u }; - if (hexDecode(code, strlen(code), buffer, sizeof(buffer))) { + if (hexDecode(message, strlen(message), buffer, sizeof(buffer))) { + const auto bytes = _rfb_bytes_for_bits(buffer[4]); + + uint8_t raw_code[sizeof(RfbMessage::code_type)] { 0u }; + std::memcpy(&raw_code[sizeof(raw_code) - bytes], &buffer[5], bytes); + RfbMessage::code_type code; - std::memcpy(&code, &buffer[5], _rfb_bits_for_bytes(buffer[4])); - code = _rfb_bswap(code); + std::memcpy(&code, raw_code, sizeof(code)); - _rfbEnqueue(buffer[1], (buffer[3] << 8) | buffer[2], buffer[4], code, repeats); - } else { - DEBUG_MSG_P(PSTR("[RF] Cannot decode the message\n")); + _rfbEnqueue(buffer[1], (buffer[2] << 8) | buffer[3], buffer[4], _rfb_bswap(code), repeats); + return; } + + DEBUG_MSG_P(PSTR("[RF] Cannot decode the message\n")); } void _rfbLearnImpl() { @@ -737,6 +742,8 @@ void _rfbSendImpl(const RfbMessage& message) { _rfb_modem->setPulseLength(message.timing); } + yield(); + _rfb_modem->send(message.code, message.bits); _rfb_modem->resetAvailable();