Skip to content

Commit

Permalink
[FL-1800] IRDA: enc/decoder refactoring, Add NEC42 (#705)
Browse files Browse the repository at this point in the history
* WIP: IRDA: multilen protocol refactoring, NEC42
* IRDA: Refactoring encoder/decoder

Co-authored-by: あく <[email protected]>
  • Loading branch information
Albert Kharisov and skotopes authored Sep 15, 2021
1 parent 4768177 commit 4f233ff
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp
for(int i = 0; i < timings_len; ++i) {
message_decoded = irda_decode(decoder_handler, level, timings[i]);
if((i == timings_len - 2) && level && message_decoded) {
/* In case we end with space timing - message can be decoded at last mark.
* Exception - SIRC protocol, which has variable message length (12/15/20),
* and decoder recognizes protocol by silence time before next message
* or by timeout (irda_check_decoder_ready()). */
/* In case we end with space timing - message can be decoded at last mark */
break;
} else if(i < timings_len - 1) {
mu_check(!message_decoded);
Expand Down Expand Up @@ -225,17 +222,16 @@ MU_TEST(test_mix) {
RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
RUN_DECODER(test_decoder_sirc_input5, test_decoder_sirc_expected5);
RUN_DECODER(test_decoder_nec_input3, test_decoder_nec_expected3);
RUN_DECODER(test_decoder_rc5_input5, test_decoder_rc5_expected5);
RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
RUN_DECODER(test_decoder_sirc_input3, test_decoder_sirc_expected3);
}

MU_TEST(test_decoder_nec1) {
MU_TEST(test_decoder_nec) {
RUN_DECODER(test_decoder_nec_input1, test_decoder_nec_expected1);
}

MU_TEST(test_decoder_nec2) {
RUN_DECODER(test_decoder_nec_input2, test_decoder_nec_expected2);
RUN_DECODER(test_decoder_nec_input3, test_decoder_nec_expected3);
}

MU_TEST(test_decoder_unexpected_end_in_sequence) {
Expand Down Expand Up @@ -295,6 +291,8 @@ MU_TEST(test_encoder_rc6) {
MU_TEST(test_encoder_decoder_all) {
RUN_ENCODER_DECODER(test_nec);
RUN_ENCODER_DECODER(test_necext);
RUN_ENCODER_DECODER(test_nec42);
RUN_ENCODER_DECODER(test_nec42ext);
RUN_ENCODER_DECODER(test_samsung32);
RUN_ENCODER_DECODER(test_rc6);
RUN_ENCODER_DECODER(test_rc5);
Expand All @@ -312,8 +310,7 @@ MU_TEST_SUITE(test_irda_decoder_encoder) {
MU_RUN_TEST(test_decoder_rc6);
MU_RUN_TEST(test_encoder_rc6);
MU_RUN_TEST(test_decoder_unexpected_end_in_sequence);
MU_RUN_TEST(test_decoder_nec1);
MU_RUN_TEST(test_decoder_nec2);
MU_RUN_TEST(test_decoder_nec);
MU_RUN_TEST(test_decoder_samsung32);
MU_RUN_TEST(test_decoder_necext1);
MU_RUN_TEST(test_mix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,45 @@ const IrdaMessage test_decoder_nec_expected2[] = {
{IrdaProtocolNEC, 0x00, 0x0A, true},
};

const uint32_t test_decoder_nec_input3[] = {
200000, 8862, 4452, 562, 563, 559, 1681, 563, 1646, 567, 586, 556, 569, 563, 583, 559, 571, 561, 1675, 559, 565, 567, 1673, 561, 561, 561, 592, 561, 565, 567, 579, 563, 567, 565, 584, 558, 1652, 561, 592, 561, 561, 561, 1679, 565, 560, 562, 584, 558, 1659, 564, 585, 557, 566, 566, 1675, 559, 1649, 564, 589, 564, 1649, 564, 1668, 566, 565, 567, 1669, 565,
43470, 8896, 4432, 561, 561, 561, 1679, 565, 1648, 565, 581, 561, 568, 564, 586, 567, 558, 564, 1676, 558, 564, 558, 1681, 563, 563, 559, 587, 566, 565, 567, 582, 561, 564, 558, 595, 558, 1650, 563, 590, 563, 563, 559, 1674, 560, 570, 562, 587, 566, 1645, 568, 586, 556, 565, 567, 1672, 562, 1651, 562, 584, 558, 1658, 566, 1671, 563, 561, 561, 1679, 565,
200000, 8881, 4383, 569, 549, 573, 548, 574, 541, 571, 550, 572, 547, 575, 539, 573, 551, 571, 1651, 573, 545, 567, 554, 568, 548, 574, 1652, 572, 547, 575, 1645, 568, 1661, 573, 545, 567, 1657, 567, 554, 568, 547, 575, 1652, 572, 547, 575, 539, 573, 1657, 567, 550, 572, 545, 577, 1651, 573, 1648, 576, 545, 567, 1659, 575, 1645, 568, 555, 567, 1657, 567,
38995, 8883, 4369, 573, 543, 569, 552, 570, 549, 573, 541, 571, 553, 569, 548, 574, 543, 569, 1658, 566, 550, 572, 548, 574, 546, 566, 1653, 571, 553, 569, 1654, 570, 1654, 570, 551, 571, 1651, 573, 547, 575, 545, 567, 1653, 571, 552, 570, 547, 575, 1649, 564, 556, 566, 550, 572, 1655, 569, 1656, 568, 546, 566, 1664, 570, 1653, 571, 547, 565, 1663, 571,
200000, 8987, 4504, 561, 593, 539, 589, 533, 596, 515, 586, 536, 592, 540, 588, 534, 595, 517, 1713, 541, 1664, 570, 1686, 558, 596, 515, 587, 535, 593, 539, 1691, 543, 1689, 565, 588, 513, 1691, 563, 1668, 617, 1613, 641, 1615, 567, 587, 535, 593, 519, 610, 512, 590, 542, 1714, 510, 593, 539, 1691, 563, 591, 510, 1720, 535, 594, 518, 584, 538, 591, 541,
39546, 8990, 4501, 565, 590, 542, 586, 536, 593, 508, 593, 539, 589, 543, 585, 537, 592, 509, 1720, 545, 1660, 615, 1642, 561, 567, 534, 594, 538, 590, 542, 1688, 535, 1696, 558, 595, 517, 1687, 567, 1664, 621, 1635, 619, 1611, 561, 594, 538, 590, 511, 617, 515, 586, 536, 1721, 513, 589, 543, 1687, 568, 587, 514, 1691, 563, 590, 511, 591, 541, 587, 535,
200000, 8986, 4505, 560, 594, 538, 590, 542, 586, 515, 586, 536, 593, 539, 589, 533, 595, 517, 1714, 540, 587, 535, 594, 518, 1713, 542, 586, 515, 587, 535, 1722, 543, 1662, 562, 592, 540, 1664, 570, 585, 537, 591, 541, 1689, 545, 584, 538, 590, 542, 1688, 536, 593, 539, 589, 512, 590, 542, 586, 536, 1720, 514, 588, 544, 585, 537, 591, 541, 587, 514,
40671, 8986, 4505, 560, 594, 538, 590, 542, 586, 515, 587, 535, 593, 539, 589, 533, 595, 516, 1714, 541, 587, 535, 594, 518, 1712, 542, 586, 515, 587, 535, 1722, 543, 1662, 561, 592, 540, 1664, 570, 585, 537, 591, 541, 1689, 545, 584, 538, 590, 542, 1688, 536, 593, 539, 589, 512, 590, 542, 586, 536, 1720, 514, 588, 544, 585, 537, 591, 541, 587, 514,
200000, 8990, 4500, 566, 1692, 562, 1668, 566, 588, 534, 594, 518, 584, 538, 591, 541, 587, 535, 1669, 565, 589, 543, 1688, 536, 592, 540, 1691, 563, 1667, 567, 1664, 621, 1635, 568, 586, 515, 587, 535, 593, 539, 589, 543, 1662, 562, 592, 540, 588, 534, 594, 518, 585, 537, 591, 541, 587, 514, 587, 535, 594, 538, 590, 542, 586, 515, 586, 536, 593, 539,
39544, 8993, 4498, 567, 1690, 564, 1666, 568, 586, 536, 593, 508, 593, 539, 589, 543, 585, 537, 1668, 566, 588, 544, 1687, 537, 591, 541, 1690, 564, 1666, 568, 1663, 561, 1696, 569, 585, 516, 586, 536, 593, 539, 589, 543, 1661, 562, 592, 540, 588, 534, 594, 517, 584, 538, 591, 541, 587, 514, 587, 535, 593, 539, 589, 543, 585, 516, 586, 536, 592, 540,
200000, 8894, 4456, 589, 1676, 589, 571, 582, 574, 589, 571, 582, 1683, 582, 1677, 588, 1682, 583, 574, 589, 568, 585, 1682, 583, 1678, 587, 1680, 585, 574, 589, 565, 588, 575, 588, 1675, 590, 567, 586, 1681, 584, 571, 582, 1685, 590, 568, 585, 569, 584, 1685, 590, 567, 586, 1678, 587, 574, 589, 1672, 582, 578, 585, 1679, 586, 1674, 591, 572, 591, 1672, 582,
39632, 8912, 4464, 560, 1703, 562, 598, 565, 594, 559, 594, 559, 1711, 564, 1698, 567, 1697, 568, 593, 560, 595, 568, 1698, 567, 1698, 567, 1693, 561, 602, 561, 596, 567, 590, 563, 1704, 561, 594, 559, 1707, 568, 591, 562, 1697, 568, 596, 567, 590, 563, 1700, 565, 596, 567, 1693, 561, 599, 564, 1701, 564, 589, 564, 1706, 559, 1704, 561, 597, 566, 1700, 565,
200000, 9018, 4500, 565, 1666, 568, 1689, 565, 588, 513, 1691, 615, 1616, 618, 1639, 564, 1667, 567, 587, 535, 594, 538, 563, 538, 590, 542, 586, 536, 593, 508, 593, 539, 589, 543, 1688, 535, 592, 540, 588, 544, 585, 537, 591, 510, 1694, 560, 1670, 564, 1693, 562, 1669, 565, 1692, 542, 1689, 565, 588, 534, 595, 517, 585, 537, 591, 541, 587, 535, 568, 544, 584, 538, 591, 541, 1663, 560, 1696, 569, 1662, 562, 1695, 539, 1692, 614, 1616, 566, 1691, 563, 1667, 567,
23184, 9012, 4505, 560, 1697, 537, 1693, 561, 593, 508, 1696, 569, 1662, 562, 1695, 560, 1671, 563, 591, 541, 587, 535, 594, 518, 584, 538, 590, 542, 586, 515, 613, 509, 593, 539, 1692, 542, 585, 537, 592, 540, 588, 534, 594, 518, 1687, 567, 1663, 560, 1697, 568, 1662, 562, 1695, 539, 1692, 563, 591, 541, 587, 514, 588, 544, 584, 538, 590, 542, 586, 515, 587, 535, 593, 539, 1666, 568, 1689, 565, 1665, 569, 1688, 536, 1695, 570, 1661, 562, 1694, 561, 1670, 564,
200000, 8835, 4446, 537, 562, 539, 562, 539, 1663, 540, 1667, 536, 1669, 534, 560, 531, 573, 539, 559, 532, 1672, 531, 570, 531, 564, 537, 563, 538, 561, 540, 1660, 533, 1677, 536, 561, 540, 557, 534, 567, 534, 1668, 535, 1672, 531, 1675, 538, 555, 536, 1674, 539, 1665, 538, 1666, 537, 1671, 532, 563, 538, 1669, 534, 566, 535, 558, 533, 1677, 536, 562, 539, 558, 533, 568, 533, 1668, 535, 566, 535, 1670, 533, 1667, 536, 568, 533, 1671, 532, 1672, 531, 1676, 537,
22779, 8870, 4437, 535,
92592, 8861, 4414, 538,
};

const IrdaMessage test_decoder_nec_expected3[] = {
{IrdaProtocolNECext, 0x286, 0xB649, false},
{IrdaProtocolNECext, 0x286, 0xB649, false},
{IrdaProtocolNECext, 0x6880, 0xB649, false},
{IrdaProtocolNECext, 0x6880, 0xB649, false},
{IrdaProtocolNECext, 0x6380, 0x150F, false},
{IrdaProtocolNECext, 0x6380, 0x150F, false},
{IrdaProtocolNECext, 0x6480, 0x849, false},
{IrdaProtocolNECext, 0x6480, 0x849, false},
{IrdaProtocolNECext, 0x7A83, 0x8, false},
{IrdaProtocolNECext, 0x7A83, 0x8, false},
{IrdaProtocolNEC, 0x71, 0x4A, false},
{IrdaProtocolNEC, 0x71, 0x4A, false},
{IrdaProtocolNEC42, 0x7B, 0x0, false},
{IrdaProtocolNEC42, 0x7B, 0x0, false},
{IrdaProtocolNEC42, 0x11C, 0x12, false},
};


const IrdaMessage test_nec[] = {
{IrdaProtocolNEC, 0x00, 0x00, false},
{IrdaProtocolNEC, 0x01, 0x00, false},
Expand Down Expand Up @@ -209,4 +248,61 @@ const IrdaMessage test_nec[] = {
{IrdaProtocolNEC, 0x55, 0x55, true},
};

const IrdaMessage test_nec42[] = {
{IrdaProtocolNEC42, 0x0000, 0x00, false},
{IrdaProtocolNEC42, 0x0001, 0x00, false},
{IrdaProtocolNEC42, 0x0001, 0x80, false},
{IrdaProtocolNEC42, 0x0000, 0x80, false},
{IrdaProtocolNEC42, 0x0000, 0x00, false},
{IrdaProtocolNEC42, 0x0000, 0x00, true},
{IrdaProtocolNEC42, 0x0000, 0x00, false},
{IrdaProtocolNEC42, 0x0000, 0x00, true},
{IrdaProtocolNEC42, 0x1FFF, 0xFF, false},
{IrdaProtocolNEC42, 0x1FFE, 0xFF, false},
{IrdaProtocolNEC42, 0x1FFE, 0x7F, false},
{IrdaProtocolNEC42, 0x1FFF, 0x7F, false},
{IrdaProtocolNEC42, 0x1FFF, 0xFF, false},
{IrdaProtocolNEC42, 0x1FFF, 0xFF, true},
{IrdaProtocolNEC42, 0x0AAA, 0x55, false},
{IrdaProtocolNEC42, 0x1555, 0xAA, false},
{IrdaProtocolNEC42, 0x1555, 0x55, false},
{IrdaProtocolNEC42, 0x0AAA, 0xAA, false},
{IrdaProtocolNEC42, 0x0AAA, 0xAA, true},
{IrdaProtocolNEC42, 0x0AAA, 0xAA, false},
{IrdaProtocolNEC42, 0x0AAA, 0xAA, true},
{IrdaProtocolNEC42, 0x0AAA, 0xAA, true},
{IrdaProtocolNEC42, 0x1555, 0x55, false},
{IrdaProtocolNEC42, 0x1555, 0x55, true},
{IrdaProtocolNEC42, 0x1555, 0x55, true},
{IrdaProtocolNEC42, 0x1555, 0x55, true},
};

const IrdaMessage test_nec42ext[] = {
{IrdaProtocolNEC42ext, 0x0000000, 0x0000, false},
{IrdaProtocolNEC42ext, 0x0000001, 0x0000, false},
{IrdaProtocolNEC42ext, 0x0000001, 0x8000, false},
{IrdaProtocolNEC42ext, 0x0000000, 0x8000, false},
{IrdaProtocolNEC42ext, 0x0000000, 0x0000, false},
{IrdaProtocolNEC42ext, 0x0000000, 0x0000, true},
{IrdaProtocolNEC42ext, 0x0000000, 0x0000, false},
{IrdaProtocolNEC42ext, 0x0000000, 0x0000, true},
{IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, false},
{IrdaProtocolNEC42ext, 0x3F000FE, 0xF00F, false},
{IrdaProtocolNEC42ext, 0x3F000FE, 0x700F, false},
{IrdaProtocolNEC42ext, 0x3F000FF, 0x700F, false},
{IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, false},
{IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, true},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0x5555, false},
{IrdaProtocolNEC42ext, 0x1555555, 0xAAAA, false},
{IrdaProtocolNEC42ext, 0x1555555, 0x5555, false},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true},
{IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true},
{IrdaProtocolNEC42ext, 0x1555555, 0x5555, false},
{IrdaProtocolNEC42ext, 0x1555555, 0x5555, true},
{IrdaProtocolNEC42ext, 0x1555555, 0x5555, true},
{IrdaProtocolNEC42ext, 0x1555555, 0x5555, true},
};

Loading

0 comments on commit 4f233ff

Please sign in to comment.