Adding ignore bits to narrow compare of received codes (#650)

* Adding bitmask to narrow compare of received codes
Updated test to add mask configuration

* Lint

* Handle bitmask as ignore characters per review comment

* Fixed test to cover ignore bits

* Lint

* Eliminate separate set_mask method per review comment
This commit is contained in:
mtl010957
2019-06-26 14:47:34 -05:00
committed by Otto Winter
parent 0dfab4d93c
commit 49f9ad66db
4 changed files with 32 additions and 3 deletions
@@ -216,13 +216,22 @@ uint32_t decode_binary_string(const std::string &data) {
return ret;
}
uint32_t decode_binary_string_mask(const std::string &data) {
uint32_t ret = 0;
for (char c : data) {
ret <<= 1UL;
ret |= (c != 'x');
}
return ret;
}
bool RCSwitchRawReceiver::matches(RemoteReceiveData src) {
uint32_t decoded_code;
uint8_t decoded_nbits;
if (!this->protocol_.decode(src, &decoded_code, &decoded_nbits))
return false;
return decoded_nbits == this->nbits_ && decoded_code == this->code_;
return decoded_nbits == this->nbits_ && (decoded_code & this->mask_) == (this->code_ & this->mask_);
}
bool RCSwitchDumper::dump(RemoteReceiveData src) {
for (uint8_t i = 1; i <= 7; i++) {