Merge pull request #6399 from s-hadinger/ir_hash

Rename "Data" to "Hash" and limit to 32 bits when receiving UNKNOWN IR protocol
This commit is contained in:
Theo Arends 2019-09-10 21:03:38 +02:00 committed by GitHub
commit 33baadfafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 18 deletions

View File

@ -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

View File

@ -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"

View File

@ -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 "\":["));

View File

@ -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 "\":";