Fix byte order in NEC protocol implementation (#2534)

This commit is contained in:
Sergey V. DUDANOV 2021-11-17 21:35:50 +04:00 committed by GitHub
parent 06994c0dfc
commit 6f9439e1bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,14 +17,14 @@ void NECProtocol::encode(RemoteTransmitData *dst, const NECData &data) {
dst->set_carrier_frequency(38000); dst->set_carrier_frequency(38000);
dst->item(HEADER_HIGH_US, HEADER_LOW_US); dst->item(HEADER_HIGH_US, HEADER_LOW_US);
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint16_t mask = 1; mask; mask <<= 1) {
if (data.address & mask) if (data.address & mask)
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else else
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US); dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
} }
for (uint32_t mask = 1UL << 15; mask; mask >>= 1) { for (uint16_t mask = 1; mask; mask <<= 1) {
if (data.command & mask) if (data.command & mask)
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US); dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
else else
@ -41,7 +41,7 @@ optional<NECData> NECProtocol::decode(RemoteReceiveData src) {
if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US)) if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
return {}; return {};
for (uint32_t mask = 1UL << 15; mask != 0; mask >>= 1) { for (uint16_t mask = 1; mask; mask <<= 1) {
if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) { if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
data.address |= mask; data.address |= mask;
} else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) { } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
@ -51,7 +51,7 @@ optional<NECData> NECProtocol::decode(RemoteReceiveData src) {
} }
} }
for (uint32_t mask = 1UL << 15; mask != 0; mask >>= 1) { for (uint16_t mask = 1; mask; mask <<= 1) {
if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) { if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
data.command |= mask; data.command |= mask;
} else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) { } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {