From 05e96041167a8b87a4cb6b1b5d489f3abdaf128e Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 10 Sep 2019 20:45:27 +0200 Subject: [PATCH] Change rename "Data" to "Hash" and limit to 32 bits when receiving UNKNOWN IR protocol (see DECODE_HASH from IRremoteESP8266) --- sonoff/_changelog.ino | 1 + sonoff/i18n.h | 1 + sonoff/xdrv_05_irremote.ino | 31 +++++++++++++++++++++---------- sonoff/xdrv_05_irremote_full.ino | 27 +++++++++++++++++++-------- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 8a84f0bd9..ed88da8c4 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * 6.6.0.12 20190910 * Redesign command Tariff to now default to 0 (=disabled) and allowing to set both Standard Time (ST) and Daylight Savings Time (DST) start hour * Commands Tariff1 22,23 = Tariff1 (Off-Peak) ST,DST Tariff2 (Standard) 6,7 = Tariff2 ST,DST Tariff9 0/1 = Weekend toggle (1 = Off-Peak during weekend) + * Change rename "Data" to "Hash" and limit to 32 bits when receiving UNKNOWN IR protocol (see DECODE_HASH from IRremoteESP8266) * * 6.6.0.11 20190907 * Change Settings crc calculation allowing short term backward compatibility diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 0aba9f63d..e44b4a928 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -385,6 +385,7 @@ #define D_JSON_IR_BITS "Bits" #define D_JSON_IR_DATA "Data" #define D_JSON_IR_DATALSB "DataLSB" + #define D_JSON_IR_HASH "Hash" #define D_JSON_IR_RAWDATA "RawData" #define D_JSON_IR_REPEAT "Repeat" #define D_CMND_IRHVAC "IRHVAC" diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index cc0614264..db5332081 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -129,13 +129,21 @@ void IrReceiveCheck(void) if (irrecv->decode(&results)) { char hvalue[65]; // Max 256 bits - if (results.bits > 64) { - // This emulates IRutils resultToHexidecimal and may needs a larger IR_RCV_BUFFER_SIZE - uint32_t digits2 = results.bits / 8; - if (results.bits % 8) { digits2++; } - ToHex_P((unsigned char*)results.state, digits2, hvalue, sizeof(hvalue)); // Get n-bit value as hex 56341200 + + iridx = results.decode_type; + if ((iridx < 0) || (iridx > 14)) { iridx = 0; } // UNKNOWN + + if (iridx) { + if (results.bits > 64) { + // This emulates IRutils resultToHexidecimal and may needs a larger IR_RCV_BUFFER_SIZE + uint32_t digits2 = results.bits / 8; + if (results.bits % 8) { digits2++; } + ToHex_P((unsigned char*)results.state, digits2, hvalue, sizeof(hvalue)); // Get n-bit value as hex 56341200 + } else { + IrUint64toHex(results.value, hvalue, results.bits); // Get 64bit value as hex 00123456 + } } else { - IrUint64toHex(results.value, hvalue, results.bits); // Get 64bit value as hex 00123456 + IrUint64toHex(results.value, hvalue, 32); // UNKNOWN is always 32 bits hash } AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_IRR "Echo %d, RawLen %d, Overflow %d, Bits %d, Value 0x%s, Decode %d"), @@ -146,16 +154,19 @@ void IrReceiveCheck(void) if (!irsend_active && (now - ir_lasttime > IR_TIME_AVOID_DUPLICATE)) { ir_lasttime = now; - iridx = results.decode_type; - if ((iridx < 0) || (iridx > 14)) { iridx = 0; } // UNKNOWN char svalue[64]; if (Settings.flag.ir_receive_decimal) { ulltoa(results.value, svalue, 10); } else { snprintf_P(svalue, sizeof(svalue), PSTR("\"0x%s\""), hvalue); } - ResponseTime_P(PSTR(",\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":%s"), - GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, svalue); + ResponseTime_P(PSTR(",\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d"), + GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits); + if (iridx) { + ResponseAppend_P(PSTR(",\"" D_JSON_IR_DATA "\":%s"), svalue); + } else { + ResponseAppend_P(PSTR(",\"" D_JSON_IR_HASH "\":%s"), svalue); + } if (Settings.flag3.receive_raw) { ResponseAppend_P(PSTR(",\"" D_JSON_IR_RAWDATA "\":[")); diff --git a/sonoff/xdrv_05_irremote_full.ino b/sonoff/xdrv_05_irremote_full.ino index 3c82bee21..d35c5f4ba 100644 --- a/sonoff/xdrv_05_irremote_full.ino +++ b/sonoff/xdrv_05_irremote_full.ino @@ -177,20 +177,31 @@ String sendIRJsonState(const struct decode_results &results) { json += resultToHexidecimal(&results); json += "\""; } else { - json += ",\"" D_JSON_IR_DATA "\":"; + if (UNKNOWN != results.decode_type) { + json += ",\"" D_JSON_IR_DATA "\":"; + } else { + json += ",\"" D_JSON_IR_HASH "\":"; + } if (Settings.flag.ir_receive_decimal) { char svalue[32]; ulltoa(results.value, svalue, 10); json += svalue; } else { char hvalue[64]; - IrUint64toHex(results.value, hvalue, results.bits); // Get 64bit value as hex 0x00123456 - json += "\""; - json += hvalue; - json += "\",\"" D_JSON_IR_DATALSB "\":\""; - IrUint64toHex(reverseBitsInBytes64(results.value), hvalue, results.bits); // Get 64bit value as hex 0x00123456, LSB - json += hvalue; - json += "\""; + if (UNKNOWN != results.decode_type) { + IrUint64toHex(results.value, hvalue, results.bits); // Get 64bit value as hex 0x00123456 + json += "\""; + json += hvalue; + json += "\",\"" D_JSON_IR_DATALSB "\":\""; + IrUint64toHex(reverseBitsInBytes64(results.value), hvalue, results.bits); // Get 64bit value as hex 0x00123456, LSB + json += hvalue; + json += "\""; + } else { // UNKNOWN + IrUint64toHex(results.value, hvalue, 32); // Unknown is always 32 bits + json += "\""; + json += hvalue; + json += "\""; + } } } json += ",\"" D_JSON_IR_REPEAT "\":";