Skip to content

Commit 5c90715

Browse files
authored
Merge pull request #24 from cjkas/scz/fix-asa-go-encoding
Fix off-by-one bug in RTW protocol decoder.
2 parents e824174 + 26400c5 commit 5c90715

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

data-src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ <h1 style="text-align: center;"><img src="icon.png" style="width:50px;float:left
992992
</div>
993993
</div>
994994
<div id="divFrameLog" class="subtab-content frame-log" style="display:none;margin:0px;padding:0px;">
995-
<div class="frame-header"><span>Key</span><span>Address</span><span>Command</span><span>Code</span><span>RSSI</span><span>Bits</span><span style="text-align:center;width:77px;">Time</span></div>
995+
<div class="frame-header"><span>Key</span><span>Address</span><span>Command</span><span>Code</span><span>RSSI</span><span>Bits</span><span style="text-align:center;width:77px;">Time</span><span>Raw</span></div>
996996
<div id="divFrames" class="frame-list"></div>
997997
<div class="button-container" style="text-align:center">
998998
<button type="button" class="btnCopyFrame" style="display:inline-block;width:44%;" onclick="somfy.framesToClipboard();">Copy</button>

data-src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2934,7 +2934,8 @@ class Somfy {
29342934
proto = '-V';
29352935
break;
29362936
}
2937-
let html = `<span>${frame.encKey}</span><span>${frame.address}</span><span>${frame.command}<sup>${frame.stepSize ? frame.stepSize : ''}</sup></span><span>${frame.rcode}</span><span>${frame.rssi}dBm</span><span>${frame.bits}${proto}</span><span>${fnFmtTime(frame.time)}</span><div class="frame-pulses">`;
2937+
let rawCmdHex = (typeof frame.rawCmd === 'number') ? `0x${frame.rawCmd.toString(16).toUpperCase()}` : '';
2938+
let html = `<span>${frame.encKey}</span><span>${frame.address}</span><span>${frame.command}<sup>${frame.stepSize ? frame.stepSize : ''}</sup></span><span>${frame.rcode}</span><span>${frame.rssi}dBm</span><span>${frame.bits}${proto}</span><span>${fnFmtTime(frame.time)}</span><span>${rawCmdHex}</span><div class="frame-pulses">`;
29382939
for (let i = 0; i < frame.pulses.length; i++) {
29392940
if (i !== 0) html += ',';
29402941
html += `${frame.pulses[i]}`;

data-src/main.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@ div.frame-header > span {
832832
text-align: right;
833833
white-space:nowrap;
834834
}
835+
div.frame-row > span:nth-child(8),
836+
div.frame-header > span:nth-child(8) {
837+
width: 40px;
838+
text-align: center;
839+
}
835840

836841
div.frame-list > div:nth-child(2n+1) {
837842
background: beige;

src/Somfy.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ void somfy_frame_t::decodeFrame(byte* frame) {
153153
this->checksum = decoded[1] & 0b1111;
154154
this->encKey = decoded[0];
155155
// Lets first determine the protocol.
156-
this->cmd = (somfy_commands)((decoded[1] >> 4));
156+
this->rawCmd = decoded[1] >> 4;
157+
this->cmd = (somfy_commands)(this->rawCmd);
157158
if(this->cmd == somfy_commands::RTWProto) {
158159
if(this->encKey >= 160) {
159160
this->proto = radio_proto::RTS;
@@ -165,7 +166,7 @@ void somfy_frame_t::decodeFrame(byte* frame) {
165166
}
166167
else if(this->encKey >= 133) {
167168
this->proto = radio_proto::RTW;
168-
this->cmd = this->encKey == 133 ? somfy_commands::My : (somfy_commands)(this->encKey - 133);
169+
this->cmd = (somfy_commands)(this->encKey - 132);
169170
}
170171
}
171172
else this->proto = radio_proto::RTS;
@@ -4418,6 +4419,11 @@ bool Transceiver::receive(somfy_rx_t *rx) {
44184419
//Serial.printf("Processing receive %d\n", rx_queue.length);
44194420
rx_queue.pop(rx);
44204421
this->frame.decodeFrame(rx);
4422+
if(this->frame.valid) {
4423+
ESP_LOGI(TAG, "RX ADDR:%d CMD:%s RAW_CMD:0x%X KEY:0x%02X PROTO:%u",
4424+
this->frame.remoteAddress, translateSomfyCommand(this->frame.cmd).c_str(),
4425+
this->frame.rawCmd, this->frame.encKey, (uint8_t)this->frame.proto);
4426+
}
44214427
this->emitFrame(&this->frame, rx);
44224428
return this->frame.valid;
44234429
}
@@ -4431,6 +4437,7 @@ void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
44314437
json->addElem("address", (uint32_t)frame->remoteAddress);
44324438
json->addElem("rcode", (uint32_t)frame->rollingCode);
44334439
json->addElem("command", translateSomfyCommand(frame->cmd).c_str());
4440+
json->addElem("rawCmd", frame->rawCmd);
44344441
json->addElem("rssi", (int32_t)frame->rssi);
44354442
json->addElem("bits", rx->bit_length);
44364443
json->addElem("proto", static_cast<uint8_t>(frame->proto));

src/Somfy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ struct somfy_frame_t {
189189
uint8_t bitLength = 56;
190190
uint16_t pulseCount = 0;
191191
uint8_t stepSize = 0;
192+
uint8_t rawCmd = 0;
192193
void print();
193194
void encode80BitFrame(byte *frame, uint8_t repeat);
194195
byte calc80Checksum(byte b0, byte b1, byte b2);

0 commit comments

Comments
 (0)