mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-04-20 11:02:14 +02:00
Fix off-by-one bug in RTW protocol decoder.
The RTW decoder formula encKey - 133 was off by one versus the RTW encoder (which maps command N to encKey N + 132). This caused every non-My RTW command to decode as the wrong button (e.g. Up decoded as My, Down as MyUp). Also adds rawCmd diagnostic field to received frames for protocol debugging.
This commit is contained in:
parent
e82417475b
commit
26400c534f
5 changed files with 18 additions and 4 deletions
|
|
@ -153,7 +153,8 @@ void somfy_frame_t::decodeFrame(byte* frame) {
|
|||
this->checksum = decoded[1] & 0b1111;
|
||||
this->encKey = decoded[0];
|
||||
// Lets first determine the protocol.
|
||||
this->cmd = (somfy_commands)((decoded[1] >> 4));
|
||||
this->rawCmd = decoded[1] >> 4;
|
||||
this->cmd = (somfy_commands)(this->rawCmd);
|
||||
if(this->cmd == somfy_commands::RTWProto) {
|
||||
if(this->encKey >= 160) {
|
||||
this->proto = radio_proto::RTS;
|
||||
|
|
@ -165,7 +166,7 @@ void somfy_frame_t::decodeFrame(byte* frame) {
|
|||
}
|
||||
else if(this->encKey >= 133) {
|
||||
this->proto = radio_proto::RTW;
|
||||
this->cmd = this->encKey == 133 ? somfy_commands::My : (somfy_commands)(this->encKey - 133);
|
||||
this->cmd = (somfy_commands)(this->encKey - 132);
|
||||
}
|
||||
}
|
||||
else this->proto = radio_proto::RTS;
|
||||
|
|
@ -4418,6 +4419,11 @@ bool Transceiver::receive(somfy_rx_t *rx) {
|
|||
//Serial.printf("Processing receive %d\n", rx_queue.length);
|
||||
rx_queue.pop(rx);
|
||||
this->frame.decodeFrame(rx);
|
||||
if(this->frame.valid) {
|
||||
ESP_LOGI(TAG, "RX ADDR:%d CMD:%s RAW_CMD:0x%X KEY:0x%02X PROTO:%u",
|
||||
this->frame.remoteAddress, translateSomfyCommand(this->frame.cmd).c_str(),
|
||||
this->frame.rawCmd, this->frame.encKey, (uint8_t)this->frame.proto);
|
||||
}
|
||||
this->emitFrame(&this->frame, rx);
|
||||
return this->frame.valid;
|
||||
}
|
||||
|
|
@ -4431,6 +4437,7 @@ void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
|
|||
json->addElem("address", (uint32_t)frame->remoteAddress);
|
||||
json->addElem("rcode", (uint32_t)frame->rollingCode);
|
||||
json->addElem("command", translateSomfyCommand(frame->cmd).c_str());
|
||||
json->addElem("rawCmd", frame->rawCmd);
|
||||
json->addElem("rssi", (int32_t)frame->rssi);
|
||||
json->addElem("bits", rx->bit_length);
|
||||
json->addElem("proto", static_cast<uint8_t>(frame->proto));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue