Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing Issue while added new ir library #2024

Open
Vrushabhgada opened this issue Aug 8, 2023 · 9 comments
Open

Facing Issue while added new ir library #2024

Vrushabhgada opened this issue Aug 8, 2023 · 9 comments

Comments

@Vrushabhgada
Copy link

Version/revision of the library used v2.8.6

Describe the bug

I had followed the steps provided in Adding support for a new IR protocol to added new ac protocol
It showed as UNKNOWN Protocol even after following all the steps
On debugging came to know following condition is failing present in IRrecv.cpp->_matchGeneric under if (use_bits) condition
`if (!result.success)

    return 0;` 

I couldn't understand what is the exact working of IRrecv::matchData and IRrecv::_matchGeneric function

To Reproduce

data.txt

Please refer to the data.txt file containing the raw values of remote and following is the output of the auto_analyse_raw_data.py file

`Found 227 timing entries.
Potential Mark Candidates:
[3402, 656]
Potential Space Candidates:
[1334, 1008, 300]

Guessing encoding type:
Looks like it uses space encoding. Yay!

Guessing key value:
kHdrMark = 3402
kHdrSpace = 1334
kBitMark = 600
kOneSpace = 1001
kZeroSpace = 273

Decoding protocol based on analysis so far:

kHdrMark+kHdrSpace+1110101000110010000010100000000000000000001001001100010011100000000111000000000000000000000000000000000010011110
Bits: 112
Hex: 0xEA320A000024C4E01C000000009E (MSB first)
0x7900000000380723240000504C57 (LSB first)
Dec: 4750048350230980578690287332753566 (MSB first)
2454171562042885653260110014729303 (LSB first)
Bin: 0b1110101000110010000010100000000000000000001001001100010011100000000111000000000000000000000000000000000010011110 (MSB first)
0b0111100100000000000000000000000000000000001110000000011100100011001001000000000000000000010100000100110001010111 (LSB first)

Total Nr. of suspected bits: 112`

Please refer to the attached file which i have created for new protocol
`// Copyright 2023 Vrushabh Gada
/// @file
/// @brief Support for BlueStar A/C protocols.

// Supports:
// Brand: BlueStar

#include
#include "IRrecv.h"
#include "IRsend.h"
#include "IRutils.h"

// Constants
const uint16_t kBluestarTick = 500;
const uint16_t kBluestarHdrMark = 3400;
const uint16_t kBluestarHdrSpace = 1334;
const uint16_t kBluestarBitMark = 600;
const uint16_t kBluestarOneSpace = 1000;
const uint16_t kBluestarZeroSpace = kBluestarBitMark;
const uint16_t kBluestarMinGap = 40000;

#if SEND_BLUESTAR
/// Send a Bluestar Toilet formatted message.
/// Status: STABLE / Working.
/// @param[in] data The message to be sent.
/// @param[in] nbits The number of bits of message to be sent.
/// @param[in] repeat The number of times the command is to be repeated.
/// @see #706
void IRsend::sendBluestar(const uint64_t data, const uint16_t nbits,
const uint16_t repeat) {
sendGeneric(kBluestarHdrMark, kBluestarHdrSpace,
kBluestarBitMark, kBluestarOneSpace,
kBluestarBitMark, kBluestarZeroSpace,
kBluestarBitMark, kBluestarMinGap,
data, nbits, 38, true, repeat, kDutyDefault);
}
#endif // SEND_BLUESTAR

#if DECODE_BLUESTAR
/// Decode the supplied Bluestar Toilet message.
/// Status: Stable / Known working.
/// @param[in,out] results Ptr to the data to decode & where to store the result
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @return True if it can decode it, false if it can't.
/// @see #706
bool IRrecv::decodeBluestar(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
if (strict && nbits != kBluestarBits)
return false; // We expect Bluestar to be a certain sized message.

uint64_t data = 0;

// Match Header + Data + Footer
if (!matchGeneric(results->rawbuf + offset, &data,
results->rawlen - offset, nbits,
kBluestarHdrMark, kBluestarHdrSpace,
kBluestarBitMark, kBluestarOneSpace,
kBluestarBitMark, kBluestarZeroSpace,
kBluestarBitMark, kBluestarMinGap, true)) return false;
// Success
results->bits = nbits;
results->value = data;
results->decode_type = decode_type_t::BLUESTAR;
results->command = 0;
results->address = 0;
return true;
}
#endif // DECODE_BLUESTAR
`

Expected behaviour

it should have identity the signal as BLUESTAR protocol

Output of raw data from IRrecvDumpV2.ino or V3 (if applicable)

uint16_t rawData[227] = {3408, 1332, 602, 1008, 604, 1006, 606, 1002, 610, 262, 608, 1002, 600, 300, 582, 1000, 600, 272, 610, 262, 608, 266, 606, 1004, 608, 1000, 600, 272, 610, 264, 606, 1002, 610, 264, 606, 266, 606, 294, 576, 266, 604, 268, 600, 1010, 604, 268, 600, 1008, 604, 268, 602, 272, 600, 298, 582, 292, 580, 266, 606, 266, 602, 270, 602, 296, 574, 274, 608, 262, 610, 262, 606, 268, 602, 296, 576, 268, 600, 272, 610, 264, 604, 264, 608, 292, 578, 268, 602, 272, 600, 270, 610, 264, 606, 1002, 600, 302, 580, 292, 578, 1002, 612, 998, 602, 298, 574, 272, 608, 264, 608, 1000, 600, 274, 608, 262, 608, 1000, 610, 1000, 602, 1006, 606, 266, 604, 270, 600, 270, 610, 290, 580, 294, 578, 268, 602, 268, 602, 270, 600, 1008, 606, 1004, 608, 1000, 610, 264, 608, 262, 608, 264, 604, 294, 576, 298, 572, 272, 610, 262, 606, 264, 608, 294, 576, 294, 576, 270, 600, 272, 608, 266, 606, 292, 578, 266, 604, 268, 602, 272, 600, 298, 582, 292, 580, 266, 604, 268, 604, 268, 602, 296, 576, 298, 582, 262, 606, 264, 606, 268, 604, 296, 576, 296, 574, 270, 612, 262, 608, 264, 606, 268, 604, 268, 604, 1008, 602, 294, 576, 1006, 606, 266, 606, 1002, 608, 1002, 598, 1010, 602, 294, 574}; // UNKNOWN 501A1597

What brand/model IR demodulator are you using?

brand = BLUESTAR

I have followed the steps in the Troubleshooting Guide & read the FAQ

Yes.

Has this library/code previously worked as expected for you?

No

@NiKiZe
Copy link
Collaborator

NiKiZe commented Aug 8, 2023

So this is for a bluestar AC unit?
Do you have the exact model of both remote and unit as well?

@crankyoldgit
Copy link
Owner

@Vrushabhgada Please provide a link to your github branch with all of the changes you've made. What you've provided so far is an incomplete picture.

Also, auto_analyse_raw_data.py would have warned you that the protocol is using more than 64bits, and as such, couldn't use the <= 64 bit versions of the generic code it generated.
e.g.
// DANGER: More than 64 bits detected. A uint64_t for 'data' won't work!
&
// Alternative >64bit function to send TBD messages

It reported that:

Total Nr. of suspected bits: 112

Which is larger than 64bit, so it can't be stored in a uint64_t. It needs to be stored in a uint8_t[14]. i.e. A 14 byte array.

@Vrushabhgada
Copy link
Author

Please refer the below github repo
https://github.com/Vrushabhgada/IRBlueStartProtocol

Also I didn't got any warning

image

@crankyoldgit
Copy link
Owner

That's because you didn't follow the instructions correctly in [Adding support for a new IR protocol](Adding support for a new IR protocol). i.e. See the comment "... If you use the -g -n TestExample arguments to the program, ..."

I'll take a look at your repo shortly.

@crankyoldgit
Copy link
Owner

crankyoldgit commented Aug 8, 2023

Please refer the below github repo
https://github.com/Vrushabhgada/IRBlueStartProtocol

FYI, it is best to fork the repo, rather than create/upload a new one. That way I people can easily track & see what changes you've made, and you can more easily merge changes back into the original fork too.

@crankyoldgit
Copy link
Owner

After a very quick look, I am sure your first problem is as I said before, you're using the wrong sort of decode routine structure etc for the bit size of the message. The -g option while generating code, will warn you about that.
I suggest you look at the MITSUBISHI112 code for some pointers.

#if SEND_MITSUBISHI112
/// Send a Mitsubishi 112-bit A/C formatted message. (MITSUBISHI112)
/// Status: Stable / Reported as working.
/// @param[in] data The message to be sent.
/// @param[in] nbytes The number of bytes of message to be sent.
/// @param[in] repeat The number of times the command is to be repeated.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/947
void IRsend::sendMitsubishi112(const unsigned char data[],
const uint16_t nbytes,
const uint16_t repeat) {
if (nbytes < kMitsubishi112StateLength)
return; // Not enough bytes to send a proper message.
sendGeneric(kMitsubishi112HdrMark, kMitsubishi112HdrSpace,
kMitsubishi112BitMark, kMitsubishi112OneSpace,
kMitsubishi112BitMark, kMitsubishi112ZeroSpace,
kMitsubishi112BitMark, kMitsubishi112Gap,
data, nbytes, 38, false, repeat, 50);
}
#endif // SEND_MITSUBISHI112
#if (DECODE_MITSUBISHI112 || DECODE_TCL112AC)
/// Decode the supplied Mitsubishi/TCL 112-bit A/C message.
/// (MITSUBISHI112, TCL112AC)
/// Status: STABLE / Reported as working.
/// @param[in,out] results Ptr to the data to decode & where to store the result
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @note Note Mitsubishi112 & Tcl112Ac are basically the same protocol.
/// The only significant difference I can see is Mitsubishi112 has a
/// slightly longer header mark. We will use that to determine which
/// variant it should be. The other differences require full decoding and
/// only only with certain settings.
/// There are some other timing differences too, but the tolerances will
/// overlap.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/619
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/947
bool IRrecv::decodeMitsubishi112(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
if (results->rawlen < (2 * nbits) + kHeader + kFooter - 1 + offset)
return false;
if (nbits % 8 != 0) return false; // Not a multiple of an 8 bit byte.
if (strict) { // Do checks to see if it matches the spec.
if (nbits != kMitsubishi112Bits && nbits != kTcl112AcBits) return false;
}
decode_type_t typeguess = decode_type_t::UNKNOWN;
uint16_t hdrspace;
uint16_t bitmark;
uint16_t onespace;
uint16_t zerospace;
uint32_t gap;
uint8_t tolerance = _tolerance;
// Header
#if DECODE_MITSUBISHI112
if (matchMark(results->rawbuf[offset], kMitsubishi112HdrMark,
kMitsubishi112HdrMarkTolerance, 0)) {
typeguess = decode_type_t::MITSUBISHI112;
hdrspace = kMitsubishi112HdrSpace;
bitmark = kMitsubishi112BitMark;
onespace = kMitsubishi112OneSpace;
zerospace = kMitsubishi112ZeroSpace;
gap = kMitsubishi112Gap;
}
#endif // DECODE_MITSUBISHI112
#if (DECODE_TCL112AC || DECODE_TEKNOPOINT)
if (typeguess == decode_type_t::UNKNOWN && // We didn't match Mitsubishi112
matchMark(results->rawbuf[offset], kTcl112AcHdrMark,
kTcl112AcHdrMarkTolerance, 0)) {
typeguess = decode_type_t::TCL112AC;
hdrspace = kTcl112AcHdrSpace;
bitmark = kTcl112AcBitMark;
onespace = kTcl112AcOneSpace;
zerospace = kTcl112AcZeroSpace;
gap = kTcl112AcGap;
tolerance += kTcl112AcTolerance;
}
#endif // (DECODE_TCL112AC || DECODE_TEKNOPOINT)
if (typeguess == decode_type_t::UNKNOWN) return false; // No header matched.
offset++;
uint16_t used = matchGeneric(results->rawbuf + offset, results->state,
results->rawlen - offset, nbits,
0, // Skip the header as we matched it earlier.
hdrspace, bitmark, onespace, bitmark, zerospace,
bitmark, gap,
true, tolerance, 0, false);
if (!used) return false;
if (strict) {
// Header validation: Codes start with 0x23CB26
if (results->state[0] != 0x23 || results->state[1] != 0xCB ||
results->state[2] != 0x26) return false;
// TCL112 and MITSUBISHI112 share the exact same checksum.
if (!IRTcl112Ac::validChecksum(results->state, nbits / 8)) return false;
}
// Success
results->decode_type = typeguess;
results->bits = nbits;
// No need to record the state as we stored it as we decoded it.
// As we use result->state, we don't record value, address, or command as it
// is a union data type.
return true;
}
#endif // DECODE_MITSUBISHI112 || DECODE_TCL112AC

or MitsubishiHeavy's decode:
#if DECODE_MITSUBISHIHEAVY
/// Decode the supplied Mitsubishi Heavy Industries A/C message.
/// Status: BETA / Appears to be working. Needs testing against a real device.
/// @param[in,out] results Ptr to the data to decode & where to store the result
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// Typically kMitsubishiHeavy88Bits or kMitsubishiHeavy152Bits (def).
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @return True if it can decode it, false if it can't.
bool IRrecv::decodeMitsubishiHeavy(decode_results* results, uint16_t offset,
const uint16_t nbits, const bool strict) {
if (strict) {
switch (nbits) {
case kMitsubishiHeavy88Bits:
case kMitsubishiHeavy152Bits:
break;
default:
return false; // Not what is expected
}
}
uint16_t used;
used = matchGeneric(results->rawbuf + offset, results->state,
results->rawlen - offset, nbits,
kMitsubishiHeavyHdrMark, kMitsubishiHeavyHdrSpace,
kMitsubishiHeavyBitMark, kMitsubishiHeavyOneSpace,
kMitsubishiHeavyBitMark, kMitsubishiHeavyZeroSpace,
kMitsubishiHeavyBitMark, kMitsubishiHeavyGap, true,
_tolerance, 0, false);
if (used == 0) return false;
offset += used;
// Compliance
switch (nbits) {
case kMitsubishiHeavy88Bits:
if (strict && !(IRMitsubishiHeavy88Ac::checkZjsSig(results->state) &&
IRMitsubishiHeavy88Ac::validChecksum(results->state)))
return false;
results->decode_type = MITSUBISHI_HEAVY_88;
break;
case kMitsubishiHeavy152Bits:
if (strict && !(IRMitsubishiHeavy152Ac::checkZmsSig(results->state) &&
IRMitsubishiHeavy152Ac::validChecksum(results->state)))
return false;
results->decode_type = MITSUBISHI_HEAVY_152;
break;
default:
return false;
}
// Success
results->bits = nbits;
// No need to record the state as we stored it as we decoded it.
// As we use result->state, we don't record value, address, or command as it
// is a union data type.
return true;
}
#endif // DECODE_MITSUBISHIHEAVY

or decodeCarrierAC64(), which is a bit simpler/cleaner:
#if DECODE_CARRIER_AC64
/// Decode the supplied Carrier 64-bit HVAC message.
/// Status: STABLE / Known to be working.
/// @param[in,out] results Ptr to the data to decode & where to store the decode
/// result.
/// @param[in] offset The starting index to use when attempting to decode the
/// raw data. Typically/Defaults to kStartOffset.
/// @param[in] nbits The number of data bits to expect.
/// @param[in] strict Flag indicating if we should perform strict matching.
/// @return A boolean. True if it can decode it, false if it can't.
bool IRrecv::decodeCarrierAC64(decode_results *results, uint16_t offset,
const uint16_t nbits, const bool strict) {
if (results->rawlen < 2 * nbits + kHeader + kFooter - 1 + offset)
return false; // Can't possibly be a valid Carrier message.
if (strict && nbits != kCarrierAc64Bits)
return false; // We expect Carrier to be 64 bits of message.
if (!matchGeneric(results->rawbuf + offset, &(results->value),
results->rawlen - offset, nbits,
kCarrierAc64HdrMark, kCarrierAc64HdrSpace,
kCarrierAc64BitMark, kCarrierAc64OneSpace,
kCarrierAc64BitMark, kCarrierAc64ZeroSpace,
kCarrierAc64BitMark, kCarrierAc64Gap, true,
kUseDefTol, kMarkExcess, false)) return false;
// Compliance
if (strict && !IRCarrierAc64::validChecksum(results->value)) return false;
// Success
results->bits = nbits;
results->decode_type = CARRIER_AC64;
results->address = 0;
results->command = 0;
return true;
}
#endif // DECODE_CARRIER_AC64

@Vrushabhgada
Copy link
Author

Ok. Thanks for the help will follow the suggested instruction and let you know .

@tushangpatel
Copy link

how can i create library which use any state data for send method for example sendxyz(uint8_t state[],length,repaet) ...help me

@tushangpatel
Copy link

i have state[14] data but it use for particular protocol and it for send--model this type so i made sendxyz method for any state data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants