Просмотр исходного кода

[FL-1684] IRDA Add SIRC protocol (#693)

* IRDA HAL: Fill buffer refactoring
* IRDA: Add SIRC protocol
* IRDA: correct adr/cmd bit length
* Disable Unit tests

Co-authored-by: あく <alleteam@gmail.com>
Albert Kharisov 4 лет назад
Родитель
Сommit
fbccb9fbaf
36 измененных файлов с 1215 добавлено и 222 удалено
  1. 16 2
      applications/irda/cli/irda-cli.cpp
  2. 6 6
      applications/irda/irda-app-file-parser.cpp
  3. 2 2
      applications/irda/scene/irda-app-scene-edit-delete.cpp
  4. 1 1
      applications/irda/scene/irda-app-scene-learn-enter-name.cpp
  5. 2 2
      applications/irda/scene/irda-app-scene-learn-success.cpp
  6. 4 4
      applications/irda_monitor/irda_monitor.c
  7. 106 29
      applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c
  8. 1 1
      applications/tests/irda_decoder_encoder/test_data/irda_nec_test_data.srcdata
  9. 1 1
      applications/tests/irda_decoder_encoder/test_data/irda_necext_test_data.srcdata
  10. 1 1
      applications/tests/irda_decoder_encoder/test_data/irda_rc5_test_data.srcdata
  11. 1 1
      applications/tests/irda_decoder_encoder/test_data/irda_rc6_test_data.srcdata
  12. 1 1
      applications/tests/irda_decoder_encoder/test_data/irda_samsung_test_data.srcdata
  13. 485 0
      applications/tests/irda_decoder_encoder/test_data/irda_sirc_test_data.srcdata
  14. 9 0
      core/furi/common_defines.h
  15. 5 5
      firmware/targets/f6/furi-hal/furi-hal-irda.c
  16. 99 54
      lib/irda/encoder_decoder/common/irda_common_decoder.c
  17. 18 9
      lib/irda/encoder_decoder/common/irda_common_encoder.c
  18. 13 22
      lib/irda/encoder_decoder/common/irda_common_i.h
  19. 31 8
      lib/irda/encoder_decoder/common/irda_common_protocol_defs.c
  20. 54 15
      lib/irda/encoder_decoder/irda.c
  21. 23 5
      lib/irda/encoder_decoder/irda.h
  22. 6 3
      lib/irda/encoder_decoder/irda_i.h
  23. 71 19
      lib/irda/encoder_decoder/irda_protocol_defs_i.h
  24. 3 3
      lib/irda/encoder_decoder/nec/irda_decoder_nec.c
  25. 5 4
      lib/irda/encoder_decoder/nec/irda_encoder_nec.c
  26. 4 4
      lib/irda/encoder_decoder/nec/irda_nec_spec.c
  27. 1 1
      lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c
  28. 4 4
      lib/irda/encoder_decoder/rc5/irda_rc5_spec.c
  29. 4 4
      lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c
  30. 2 2
      lib/irda/encoder_decoder/rc6/irda_rc6_spec.c
  31. 5 5
      lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c
  32. 2 2
      lib/irda/encoder_decoder/samsung/irda_samsung_spec.c
  33. 92 0
      lib/irda/encoder_decoder/sirc/irda_decoder_sirc.c
  34. 89 0
      lib/irda/encoder_decoder/sirc/irda_encoder_sirc.c
  35. 38 0
      lib/irda/encoder_decoder/sirc/irda_sirc_spec.c
  36. 10 2
      lib/irda/worker/irda_worker.c

+ 16 - 2
applications/irda/cli/irda-cli.cpp

@@ -25,9 +25,9 @@ static void signal_received_callback(void* context, IrdaWorkerSignal* received_s
             sizeof(buf),
             sizeof(buf),
             "%s, A:0x%0*lX, C:0x%0*lX%s\r\n",
             "%s, A:0x%0*lX, C:0x%0*lX%s\r\n",
             irda_get_protocol_name(message->protocol),
             irda_get_protocol_name(message->protocol),
-            irda_get_protocol_address_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4),
             message->address,
             message->address,
-            irda_get_protocol_command_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
             message->command,
             message->command,
             message->repeat ? " R" : "");
             message->repeat ? " R" : "");
         cli_write(cli, (uint8_t*)buf, buf_cnt);
         cli_write(cli, (uint8_t*)buf, buf_cnt);
@@ -98,6 +98,20 @@ static bool parse_message(const char* str, IrdaMessage* message) {
         return false;
         return false;
     }
     }
 
 
+    uint32_t address_length = irda_get_protocol_address_length(protocol);
+    uint32_t address_mask = (1LU << address_length) - 1;
+    if(address != (address & address_mask)) {
+        printf("Address out of range (mask 0x%08lX): 0x%lX\r\n", address_mask, address);
+        return false;
+    }
+
+    uint32_t command_length = irda_get_protocol_command_length(protocol);
+    uint32_t command_mask = (1LU << command_length) - 1;
+    if(command != (command & command_mask)) {
+        printf("Command out of range (mask 0x%08lX): 0x%lX\r\n", command_mask, command);
+        return false;
+    }
+
     message->protocol = protocol;
     message->protocol = protocol;
     message->address = address;
     message->address = address;
     message->command = command;
     message->command = command;

+ 6 - 6
applications/irda/irda-app-file-parser.cpp

@@ -45,9 +45,9 @@ size_t IrdaAppFileParser::stringify_message(
         "%.31s %.31s A:%0*lX C:%0*lX\n",
         "%.31s %.31s A:%0*lX C:%0*lX\n",
         name,
         name,
         irda_get_protocol_name(protocol),
         irda_get_protocol_name(protocol),
-        irda_get_protocol_address_length(protocol),
+        ROUND_UP_TO(irda_get_protocol_address_length(protocol), 4),
         message.address,
         message.address,
-        irda_get_protocol_command_length(protocol),
+        ROUND_UP_TO(irda_get_protocol_command_length(protocol), 4),
         message.command);
         message.command);
 
 
     furi_assert(written < buf_size);
     furi_assert(written < buf_size);
@@ -162,8 +162,8 @@ std::unique_ptr<IrdaAppFileParser::IrdaFileSignal>
         return nullptr;
         return nullptr;
     }
     }
 
 
-    int address_length = irda_get_protocol_address_length(protocol);
-    uint32_t address_mask = (1LU << (4 * address_length)) - 1;
+    uint32_t address_length = irda_get_protocol_address_length(protocol);
+    uint32_t address_mask = (1LU << address_length) - 1;
     if(address != (address & address_mask)) {
     if(address != (address & address_mask)) {
         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30);
         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30);
         FURI_LOG_E(
         FURI_LOG_E(
@@ -176,8 +176,8 @@ std::unique_ptr<IrdaAppFileParser::IrdaFileSignal>
         return nullptr;
         return nullptr;
     }
     }
 
 
-    int command_length = irda_get_protocol_command_length(protocol);
-    uint32_t command_mask = (1LU << (4 * command_length)) - 1;
+    uint32_t command_length = irda_get_protocol_command_length(protocol);
+    uint32_t command_mask = (1LU << command_length) - 1;
     if(command != (command & command_mask)) {
     if(command != (command & command_mask)) {
         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30);
         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30);
         FURI_LOG_E(
         FURI_LOG_E(

+ 2 - 2
applications/irda/scene/irda-app-scene-edit-delete.cpp

@@ -29,9 +29,9 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
                 "%s\n%s\nA=0x%0*lX C=0x%0*lX",
                 "%s\n%s\nA=0x%0*lX C=0x%0*lX",
                 remote_manager->get_button_name(app->get_current_button()).c_str(),
                 remote_manager->get_button_name(app->get_current_button()).c_str(),
                 irda_get_protocol_name(message->protocol),
                 irda_get_protocol_name(message->protocol),
-                irda_get_protocol_address_length(message->protocol),
+                ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4),
                 message->address,
                 message->address,
-                irda_get_protocol_command_length(message->protocol),
+                ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
                 message->command);
                 message->command);
         } else {
         } else {
             app->set_text_store(
             app->set_text_store(

+ 1 - 1
applications/irda/scene/irda-app-scene-learn-enter-name.cpp

@@ -13,7 +13,7 @@ void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
             0,
             0,
             "%.4s_%0*lX",
             "%.4s_%0*lX",
             irda_get_protocol_name(message->protocol),
             irda_get_protocol_name(message->protocol),
-            irda_get_protocol_command_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
             message->command);
             message->command);
     } else {
     } else {
         auto raw_signal = signal.get_raw_signal();
         auto raw_signal = signal.get_raw_signal();

+ 2 - 2
applications/irda/scene/irda-app-scene-learn-success.cpp

@@ -27,9 +27,9 @@ void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
         app->set_text_store(
         app->set_text_store(
             1,
             1,
             "A: 0x%0*lX\nC: 0x%0*lX\n",
             "A: 0x%0*lX\nC: 0x%0*lX\n",
-            irda_get_protocol_address_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4),
             message->address,
             message->address,
-            irda_get_protocol_command_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
             message->command);
             message->command);
         dialog_ex_set_header(dialog_ex, app->get_text_store(0), 95, 10, AlignCenter, AlignCenter);
         dialog_ex_set_header(dialog_ex, app->get_text_store(0), 95, 10, AlignCenter, AlignCenter);
         dialog_ex_set_text(dialog_ex, app->get_text_store(1), 75, 23, AlignLeft, AlignTop);
         dialog_ex_set_text(dialog_ex, app->get_text_store(1), 75, 23, AlignLeft, AlignTop);

+ 4 - 4
applications/irda_monitor/irda_monitor.c

@@ -64,18 +64,18 @@ static void signal_received_callback(void* context, IrdaWorkerSignal* received_s
             sizeof(irda_monitor->display_text),
             sizeof(irda_monitor->display_text),
             "%s\nA:0x%0*lX\nC:0x%0*lX\n%s\n",
             "%s\nA:0x%0*lX\nC:0x%0*lX\n%s\n",
             irda_get_protocol_name(message->protocol),
             irda_get_protocol_name(message->protocol),
-            irda_get_protocol_address_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4),
             message->address,
             message->address,
-            irda_get_protocol_command_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
             message->command,
             message->command,
             message->repeat ? " R" : "");
             message->repeat ? " R" : "");
         view_port_update(irda_monitor->view_port);
         view_port_update(irda_monitor->view_port);
         printf(
         printf(
             "== %s, A:0x%0*lX, C:0x%0*lX%s ==\r\n",
             "== %s, A:0x%0*lX, C:0x%0*lX%s ==\r\n",
             irda_get_protocol_name(message->protocol),
             irda_get_protocol_name(message->protocol),
-            irda_get_protocol_address_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4),
             message->address,
             message->address,
-            irda_get_protocol_command_length(message->protocol),
+            ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4),
             message->command,
             message->command,
             message->repeat ? " R" : "");
             message->repeat ? " R" : "");
     } else {
     } else {

+ 106 - 29
applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c

@@ -7,6 +7,7 @@
 #include "test_data/irda_samsung_test_data.srcdata"
 #include "test_data/irda_samsung_test_data.srcdata"
 #include "test_data/irda_rc6_test_data.srcdata"
 #include "test_data/irda_rc6_test_data.srcdata"
 #include "test_data/irda_rc5_test_data.srcdata"
 #include "test_data/irda_rc5_test_data.srcdata"
+#include "test_data/irda_sirc_test_data.srcdata"
 
 
 #define RUN_ENCODER(data, expected) \
 #define RUN_ENCODER(data, expected) \
     run_encoder((data), COUNT_OF(data), (expected), COUNT_OF(expected))
     run_encoder((data), COUNT_OF(data), (expected), COUNT_OF(expected))
@@ -14,6 +15,8 @@
 #define RUN_DECODER(data, expected) \
 #define RUN_DECODER(data, expected) \
     run_decoder((data), COUNT_OF(data), (expected), COUNT_OF(expected))
     run_decoder((data), COUNT_OF(data), (expected), COUNT_OF(expected))
 
 
+#define RUN_ENCODER_DECODER(data) run_encoder_decoder((data), COUNT_OF(data))
+
 static IrdaDecoderHandler* decoder_handler;
 static IrdaDecoderHandler* decoder_handler;
 static IrdaEncoderHandler* encoder_handler;
 static IrdaEncoderHandler* encoder_handler;
 
 
@@ -33,27 +36,44 @@ static void compare_message_results(
     mu_check(message_decoded->protocol == message_expected->protocol);
     mu_check(message_decoded->protocol == message_expected->protocol);
     mu_check(message_decoded->command == message_expected->command);
     mu_check(message_decoded->command == message_expected->command);
     mu_check(message_decoded->address == message_expected->address);
     mu_check(message_decoded->address == message_expected->address);
-    mu_check(message_decoded->repeat == message_expected->repeat);
+    if((message_expected->protocol == IrdaProtocolSIRC) ||
+       (message_expected->protocol == IrdaProtocolSIRC15) ||
+       (message_expected->protocol == IrdaProtocolSIRC20)) {
+        mu_check(message_decoded->repeat == false);
+    } else {
+        mu_check(message_decoded->repeat == message_expected->repeat);
+    }
 }
 }
 
 
-static void
-    run_encoder_fill_array(IrdaEncoderHandler* handler, uint32_t* timings, uint32_t* timings_len) {
+/* Encodes signal and merges same levels (high+high, low+low) */
+static void run_encoder_fill_array(
+    IrdaEncoderHandler* handler,
+    uint32_t* timings,
+    uint32_t* timings_len,
+    bool* start_level) {
     uint32_t duration = 0;
     uint32_t duration = 0;
-    bool level = false; // start from space
+    bool level = false;
     bool level_read;
     bool level_read;
     IrdaStatus status = IrdaStatusError;
     IrdaStatus status = IrdaStatusError;
     int i = 0;
     int i = 0;
+    bool first = true;
 
 
     while(1) {
     while(1) {
         status = irda_encode(handler, &duration, &level_read);
         status = irda_encode(handler, &duration, &level_read);
-        if(level_read != level) {
-            level = level_read;
+        if(first) {
+            if(start_level) *start_level = level_read;
+            first = false;
+            timings[0] = 0;
+        } else if(level_read != level) {
             ++i;
             ++i;
+            furi_assert(i < *timings_len);
+            timings[i] = 0;
         }
         }
+        level = level_read;
         timings[i] += duration;
         timings[i] += duration;
+
         furi_assert((status == IrdaStatusOk) || (status == IrdaStatusDone));
         furi_assert((status == IrdaStatusOk) || (status == IrdaStatusDone));
         if(status == IrdaStatusDone) break;
         if(status == IrdaStatusDone) break;
-        furi_assert(i < *timings_len);
     }
     }
 
 
     *timings_len = i + 1;
     *timings_len = i + 1;
@@ -66,8 +86,9 @@ static void run_encoder(
     const uint32_t expected_timings[],
     const uint32_t expected_timings[],
     uint32_t expected_timings_len) {
     uint32_t expected_timings_len) {
     uint32_t* timings = 0;
     uint32_t* timings = 0;
-    uint32_t timings_len = 0;
+    uint32_t timings_len = 200;
     uint32_t j = 0;
     uint32_t j = 0;
+    timings = furi_alloc(sizeof(uint32_t) * timings_len);
 
 
     for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
     for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
         const IrdaMessage* message = &input_messages[message_counter];
         const IrdaMessage* message = &input_messages[message_counter];
@@ -76,44 +97,51 @@ static void run_encoder(
         }
         }
 
 
         timings_len = 200;
         timings_len = 200;
-        timings = furi_alloc(sizeof(uint32_t) * timings_len);
-        run_encoder_fill_array(encoder_handler, timings, &timings_len);
+        run_encoder_fill_array(encoder_handler, timings, &timings_len, NULL);
         furi_assert(timings_len <= 200);
         furi_assert(timings_len <= 200);
 
 
         for(int i = 0; i < timings_len; ++i, ++j) {
         for(int i = 0; i < timings_len; ++i, ++j) {
-            mu_check(MATCH_BIT_TIMING(timings[i], expected_timings[j], 120));
+            mu_check(MATCH_TIMING(timings[i], expected_timings[j], 120));
             mu_assert(j < expected_timings_len, "encoded more timings than expected");
             mu_assert(j < expected_timings_len, "encoded more timings than expected");
         }
         }
-
-        free(timings);
     }
     }
+    free(timings);
     mu_assert(j == expected_timings_len, "encoded less timings than expected");
     mu_assert(j == expected_timings_len, "encoded less timings than expected");
 }
 }
 
 
 static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t input_messages_len) {
 static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t input_messages_len) {
     uint32_t* timings = 0;
     uint32_t* timings = 0;
-    uint32_t timings_len = 0;
+    uint32_t timings_len = 200;
     bool level = false;
     bool level = false;
+    timings = furi_alloc(sizeof(uint32_t) * timings_len);
 
 
     for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
     for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) {
         const IrdaMessage* message_encoded = &input_messages[message_counter];
         const IrdaMessage* message_encoded = &input_messages[message_counter];
         if(!message_encoded->repeat) {
         if(!message_encoded->repeat) {
             irda_reset_encoder(encoder_handler, message_encoded);
             irda_reset_encoder(encoder_handler, message_encoded);
-            level = false;
         }
         }
 
 
         timings_len = 200;
         timings_len = 200;
-        timings = furi_alloc(sizeof(uint32_t) * timings_len);
-        run_encoder_fill_array(encoder_handler, timings, &timings_len);
+        run_encoder_fill_array(encoder_handler, timings, &timings_len, &level);
         furi_assert(timings_len <= 200);
         furi_assert(timings_len <= 200);
 
 
         const IrdaMessage* message_decoded = 0;
         const IrdaMessage* message_decoded = 0;
         for(int i = 0; i < timings_len; ++i) {
         for(int i = 0; i < timings_len; ++i) {
             message_decoded = irda_decode(decoder_handler, level, timings[i]);
             message_decoded = irda_decode(decoder_handler, level, timings[i]);
-            if(i < timings_len - 1)
+            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()). */
+                break;
+            } else if(i < timings_len - 1) {
                 mu_check(!message_decoded);
                 mu_check(!message_decoded);
-            else
+            } else {
+                if(!message_decoded) {
+                    message_decoded = irda_check_decoder_ready(decoder_handler);
+                }
                 mu_check(message_decoded);
                 mu_check(message_decoded);
+            }
             level = !level;
             level = !level;
         }
         }
         if(message_decoded) {
         if(message_decoded) {
@@ -121,9 +149,8 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp
         } else {
         } else {
             mu_check(0);
             mu_check(0);
         }
         }
-
-        free(timings);
     }
     }
+    free(timings);
 }
 }
 
 
 static void run_decoder(
 static void run_decoder(
@@ -131,21 +158,49 @@ static void run_decoder(
     uint32_t input_delays_len,
     uint32_t input_delays_len,
     const IrdaMessage* message_expected,
     const IrdaMessage* message_expected,
     uint32_t message_expected_len) {
     uint32_t message_expected_len) {
-    const IrdaMessage* message_decoded = 0;
+    IrdaMessage message_decoded_check_local;
     bool level = 0;
     bool level = 0;
     uint32_t message_counter = 0;
     uint32_t message_counter = 0;
+    const IrdaMessage* message_decoded = 0;
 
 
     for(uint32_t i = 0; i < input_delays_len; ++i) {
     for(uint32_t i = 0; i < input_delays_len; ++i) {
+        const IrdaMessage* message_decoded_check = 0;
+
+        if(input_delays[i] > IRDA_RAW_RX_TIMING_DELAY_US) {
+            message_decoded_check = irda_check_decoder_ready(decoder_handler);
+            if(message_decoded_check) {
+                /* irda_decode() can reset message, but we have to call irda_decode() to perform real
+                 * simulation: irda_check() by timeout, then irda_decode() when meet edge */
+                message_decoded_check_local = *message_decoded_check;
+                message_decoded_check = &message_decoded_check_local;
+            }
+        }
+
         message_decoded = irda_decode(decoder_handler, level, input_delays[i]);
         message_decoded = irda_decode(decoder_handler, level, input_delays[i]);
-        if(message_decoded) {
+
+        if(message_decoded_check || message_decoded) {
+            mu_assert(
+                !(message_decoded_check && message_decoded),
+                "both messages decoded: check_ready() and irda_decode()");
+
+            if(message_decoded_check) {
+                message_decoded = message_decoded_check;
+            }
+
             mu_assert(message_counter < message_expected_len, "decoded more than expected");
             mu_assert(message_counter < message_expected_len, "decoded more than expected");
-            if(message_counter >= message_expected_len) break;
             compare_message_results(message_decoded, &message_expected[message_counter]);
             compare_message_results(message_decoded, &message_expected[message_counter]);
+
             ++message_counter;
             ++message_counter;
         }
         }
         level = !level;
         level = !level;
     }
     }
 
 
+    message_decoded = irda_check_decoder_ready(decoder_handler);
+    if(message_decoded) {
+        compare_message_results(message_decoded, &message_expected[message_counter]);
+        ++message_counter;
+    }
+
     mu_assert(message_counter == message_expected_len, "decoded less than expected");
     mu_assert(message_counter == message_expected_len, "decoded less than expected");
 }
 }
 
 
@@ -155,6 +210,7 @@ MU_TEST(test_decoder_samsung32) {
 
 
 MU_TEST(test_mix) {
 MU_TEST(test_mix) {
     RUN_DECODER(test_decoder_rc5_input2, test_decoder_rc5_expected2);
     RUN_DECODER(test_decoder_rc5_input2, test_decoder_rc5_expected2);
+    RUN_DECODER(test_decoder_sirc_input1, test_decoder_sirc_expected1);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
     // can use encoder data for decoding, but can't do opposite
     // can use encoder data for decoding, but can't do opposite
     RUN_DECODER(test_encoder_rc6_expected1, test_encoder_rc6_input1);
     RUN_DECODER(test_encoder_rc6_expected1, test_encoder_rc6_input1);
@@ -162,12 +218,16 @@ MU_TEST(test_mix) {
     RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
     RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
     RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
     RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
     RUN_DECODER(test_decoder_rc5_input1, test_decoder_rc5_expected1);
     RUN_DECODER(test_decoder_rc5_input1, test_decoder_rc5_expected1);
+    RUN_DECODER(test_decoder_sirc_input2, test_decoder_sirc_expected2);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
+    RUN_DECODER(test_decoder_sirc_input4, test_decoder_sirc_expected4);
     RUN_DECODER(test_decoder_nec_input2, test_decoder_nec_expected2);
     RUN_DECODER(test_decoder_nec_input2, test_decoder_nec_expected2);
     RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
     RUN_DECODER(test_decoder_rc6_input1, test_decoder_rc6_expected1);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_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_rc5_input5, test_decoder_rc5_expected5);
     RUN_DECODER(test_decoder_rc5_input5, test_decoder_rc5_expected5);
     RUN_DECODER(test_decoder_samsung32_input1, test_decoder_samsung32_expected1);
     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_nec1) {
@@ -191,6 +251,20 @@ MU_TEST(test_decoder_necext1) {
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
     RUN_DECODER(test_decoder_necext_input1, test_decoder_necext_expected1);
 }
 }
 
 
+MU_TEST(test_encoder_sirc) {
+    RUN_ENCODER(test_encoder_sirc_input1, test_encoder_sirc_expected1);
+    RUN_ENCODER(test_encoder_sirc_input2, test_encoder_sirc_expected2);
+}
+
+MU_TEST(test_decoder_sirc) {
+    RUN_DECODER(test_decoder_sirc_input3, test_decoder_sirc_expected3);
+    RUN_DECODER(test_decoder_sirc_input1, test_decoder_sirc_expected1);
+    RUN_DECODER(test_decoder_sirc_input2, test_decoder_sirc_expected2);
+    RUN_DECODER(test_decoder_sirc_input4, test_decoder_sirc_expected4);
+    RUN_DECODER(test_decoder_sirc_input5, test_decoder_sirc_expected5);
+    RUN_ENCODER_DECODER(test_sirc);
+}
+
 MU_TEST(test_decoder_rc5) {
 MU_TEST(test_decoder_rc5) {
     RUN_DECODER(test_decoder_rc5x_input1, test_decoder_rc5x_expected1);
     RUN_DECODER(test_decoder_rc5x_input1, test_decoder_rc5x_expected1);
     RUN_DECODER(test_decoder_rc5_input1, test_decoder_rc5_expected1);
     RUN_DECODER(test_decoder_rc5_input1, test_decoder_rc5_expected1);
@@ -219,16 +293,19 @@ MU_TEST(test_encoder_rc6) {
 }
 }
 
 
 MU_TEST(test_encoder_decoder_all) {
 MU_TEST(test_encoder_decoder_all) {
-    run_encoder_decoder(test_nec_all, COUNT_OF(test_nec_all));
-    run_encoder_decoder(test_necext_all, COUNT_OF(test_necext_all));
-    run_encoder_decoder(test_samsung32_all, COUNT_OF(test_samsung32_all));
-    run_encoder_decoder(test_rc6_all, COUNT_OF(test_rc6_all));
-    run_encoder_decoder(test_rc5_all, COUNT_OF(test_rc5_all));
+    RUN_ENCODER_DECODER(test_nec);
+    RUN_ENCODER_DECODER(test_necext);
+    RUN_ENCODER_DECODER(test_samsung32);
+    RUN_ENCODER_DECODER(test_rc6);
+    RUN_ENCODER_DECODER(test_rc5);
+    RUN_ENCODER_DECODER(test_sirc);
 }
 }
 
 
 MU_TEST_SUITE(test_irda_decoder_encoder) {
 MU_TEST_SUITE(test_irda_decoder_encoder) {
     MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
     MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
 
 
+    MU_RUN_TEST(test_encoder_sirc);
+    MU_RUN_TEST(test_decoder_sirc);
     MU_RUN_TEST(test_encoder_rc5x);
     MU_RUN_TEST(test_encoder_rc5x);
     MU_RUN_TEST(test_encoder_rc5);
     MU_RUN_TEST(test_encoder_rc5);
     MU_RUN_TEST(test_decoder_rc5);
     MU_RUN_TEST(test_decoder_rc5);

+ 1 - 1
applications/tests/irda_decoder_encoder/test_data/irda_nec_test_data.srcdata

@@ -178,7 +178,7 @@ const IrdaMessage test_decoder_nec_expected2[] = {
     {IrdaProtocolNEC,     0x00,      0x0A,   true},
     {IrdaProtocolNEC,     0x00,      0x0A,   true},
 };
 };
 
 
-const IrdaMessage test_nec_all[] = {
+const IrdaMessage test_nec[] = {
     {IrdaProtocolNEC,     0x00,      0x00,  false},
     {IrdaProtocolNEC,     0x00,      0x00,  false},
     {IrdaProtocolNEC,     0x01,      0x00,  false},
     {IrdaProtocolNEC,     0x01,      0x00,  false},
     {IrdaProtocolNEC,     0x01,      0x80,  false},
     {IrdaProtocolNEC,     0x01,      0x80,  false},

+ 1 - 1
applications/tests/irda_decoder_encoder/test_data/irda_necext_test_data.srcdata

@@ -223,7 +223,7 @@ const IrdaMessage test_decoder_necext_expected1[] = {
 
 
 
 
 
 
-const IrdaMessage test_necext_all[] = {
+const IrdaMessage test_necext[] = {
     {IrdaProtocolNECext,     0x0000,      0x00,  false},
     {IrdaProtocolNECext,     0x0000,      0x00,  false},
     {IrdaProtocolNECext,     0x0001,      0x00,  false},
     {IrdaProtocolNECext,     0x0001,      0x00,  false},
     {IrdaProtocolNECext,     0x0001,      0x80,  false},
     {IrdaProtocolNECext,     0x0001,      0x80,  false},

+ 1 - 1
applications/tests/irda_decoder_encoder/test_data/irda_rc5_test_data.srcdata

@@ -128,7 +128,7 @@ const IrdaMessage test_decoder_rc5_expected_all_repeats[] = {
 };
 };
 
 
 
 
-const IrdaMessage test_rc5_all[] = {
+const IrdaMessage test_rc5[] = {
     {IrdaProtocolRC5,     0x1F,      0x3F,  false},
     {IrdaProtocolRC5,     0x1F,      0x3F,  false},
     {IrdaProtocolRC5,     0x00,      0x00,  false},
     {IrdaProtocolRC5,     0x00,      0x00,  false},
     {IrdaProtocolRC5,     0x10,      0x01,  false},
     {IrdaProtocolRC5,     0x10,      0x01,  false},

+ 1 - 1
applications/tests/irda_decoder_encoder/test_data/irda_rc6_test_data.srcdata

@@ -65,7 +65,7 @@ const uint32_t test_encoder_rc6_expected1[] = {
 };
 };
 
 
 
 
-const IrdaMessage test_rc6_all[] = {
+const IrdaMessage test_rc6[] = {
     {IrdaProtocolRC6,     0x00,      0x00,  false},     // t 0
     {IrdaProtocolRC6,     0x00,      0x00,  false},     // t 0
     {IrdaProtocolRC6,     0x80,      0x00,  false},     // t 1
     {IrdaProtocolRC6,     0x80,      0x00,  false},     // t 1
     {IrdaProtocolRC6,     0x80,      0x01,  false},     // t 0
     {IrdaProtocolRC6,     0x80,      0x01,  false},     // t 0

+ 1 - 1
applications/tests/irda_decoder_encoder/test_data/irda_samsung_test_data.srcdata

@@ -221,7 +221,7 @@ const IrdaMessage test_decoder_samsung32_expected1[] = {
     {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true},
     {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true},
 };
 };
 
 
-const IrdaMessage test_samsung32_all[] = {
+const IrdaMessage test_samsung32[] = {
     {IrdaProtocolSamsung32,     0x00,      0x00,  false},
     {IrdaProtocolSamsung32,     0x00,      0x00,  false},
     {IrdaProtocolSamsung32,     0x01,      0x00,  false},
     {IrdaProtocolSamsung32,     0x01,      0x00,  false},
     {IrdaProtocolSamsung32,     0x01,      0x80,  false},
     {IrdaProtocolSamsung32,     0x01,      0x80,  false},

+ 485 - 0
applications/tests/irda_decoder_encoder/test_data/irda_sirc_test_data.srcdata

@@ -0,0 +1,485 @@
+const uint32_t test_decoder_sirc_input1[] = {  /* 121 timings */
+1000000,    2420, 608, 1194, 608, 596, 604, 1198, 603, 591, 610, 1192, 609, 596, 605, 599, 601, 593, 607, 597, 604, 590, 610, 594, 606, 1196,
+    25957,  2426, 603, 1199, 603, 591, 610, 1192, 610, 594, 606, 1196, 606, 599, 603, 591, 609, 595, 606, 598, 602, 592, 609, 596, 605, 1197,
+    25960,  2423, 606, 1196, 606, 599, 602, 1200, 602, 592, 609, 1193, 609, 596, 606, 599, 602, 592, 609, 595, 605, 600, 601, 593, 608, 1194,
+1000000,    2422, 607, 1195, 607, 598, 603, 1199, 604, 590, 610, 1192, 610, 594, 606, 598, 603, 591, 609, 595, 605, 600, 601, 593, 607, 1195,
+    25955,  2418, 610, 1192, 610, 594, 606, 1196, 606, 599, 602, 1200, 602, 592, 608, 596, 604, 590, 611, 594, 607, 597, 603, 591, 609, 1193,
+    25959,  2424, 604, 1198, 604, 590, 610, 1192, 610, 594, 606, 1196, 605, 600, 601, 593, 608, 597, 603, 591, 610, 595, 606, 598, 602, 1200,
+1000000,    2424, 605, 599, 601, 593, 607, 597, 603, 591, 610, 594, 606, 1196, 606, 1196, 605, 600, 601, 593, 608, 597, 604, 590, 611, 1191,
+    26586,  2425, 604, 590, 611, 593, 607, 598, 603, 591, 610, 595, 606, 1196, 606, 1196, 606, 599, 602, 592, 608, 596, 604, 590, 611, 1191,
+    26586,  2424, 604, 590, 611, 593, 607, 598, 603, 591, 609, 595, 605, 1197, 605, 1197, 604, 590, 611, 593, 607, 597, 603, 591, 610, 1192,
+1000000,    2424, 604, 1198, 604, 590, 611, 1191, 610, 594, 606, 598, 603, 1199, 602, 1200, 602, 592, 609, 595, 605, 600, 601, 593, 608, 1194,
+    25386,  2419, 610, 1192, 610, 594, 606, 1196, 607, 597, 603, 591, 610, 1192, 609, 1193, 610, 594, 606, 598, 602, 592, 609, 595, 605, 1197,
+    25385,  2421, 608, 1194, 608, 596, 605, 1197, 605, 599, 601, 593, 608, 1194, 608, 1194, 608, 596, 605, 589, 611, 594, 607, 597, 604, 1198,
+1000000,    2426, 603, 1199, 602, 1200, 602, 1200, 602, 592, 608, 1194, 608, 596, 604, 590, 611, 594, 607, 597, 603, 591, 610, 594, 606, 1196, 605, 600, 601, 593, 608, 596, 604, 590, 610, 594, 607, 1195, 606, 598, 603, 591,
+    15078,  2419, 610, 1192, 610, 1192, 610, 1192, 610, 594, 606, 1196, 605, 600, 601, 593, 608, 597, 604, 590, 610, 595, 606, 598, 602, 1200, 602, 592, 608, 597, 604, 590, 611, 594, 607, 597, 603, 1199, 603, 591, 609, 595,
+    15075,  2422, 607, 1195, 607, 1195, 607, 1195, 607, 597, 604, 1198, 603, 591, 610, 594, 606, 598, 603, 591, 609, 595, 605, 600, 601, 1191, 611, 594, 607, 597, 603, 591, 610, 594, 606, 598, 602, 1200, 602, 592, 608, 596,
+1000000,    2422, 607, 1195, 606, 599, 602, 592, 608, 596, 604, 590, 610, 1192, 610, 594, 606, 599, 602, 592, 608, 596, 604, 590, 610, 1192,
+    26585,  2426, 602, 1200, 602, 592, 608, 596, 604, 590, 611, 594, 607, 1195, 607, 598, 603, 591, 610, 594, 606, 598, 603, 591, 609, 1193,
+    26586,  2425, 604, 1198, 603, 591, 610, 594, 606, 598, 602, 592, 609, 1193, 608, 597, 605, 600, 601, 593, 607, 597, 604, 590, 610, 1192,
+1000000,    2418, 610, 594, 606, 598, 603, 1199, 603, 1199, 603, 1199, 603, 1199, 603, 1199, 603, 591, 610, 1192, 610, 594, 606, 1196, 606, 1196, 606, 1196, 606, 598, 602, 592, 609, 1193, 609, 1193, 609, 1193, 609, 595, 605, 599,
+    11557,  2418, 611, 594, 607, 598, 603, 1199, 603, 1199, 603, 1199, 602, 1200, 602, 1200, 601, 593, 608, 1194, 607, 597, 604, 1198, 603, 1199, 603, 1199, 602, 592, 608, 596, 604, 1198, 603, 1199, 603, 1199, 603, 591, 609, 595,
+    11561,  2424, 604, 590, 610, 594, 607, 1195, 606, 1196, 606, 1196, 606, 1196, 606, 1196, 605, 600, 601, 1191, 611, 594, 607, 1195, 607, 1195, 607, 1195, 607, 597, 603, 591, 610, 1192, 610, 1192, 610, 1192, 610, 594, 606, 598,
+1000000,    2424, 604, 590, 611, 594, 607, 1195, 607, 1195, 607, 1195, 607, 1195, 607, 1195, 606, 598, 603, 1199, 602, 592, 609, 1193, 608, 1194, 608, 1194, 608, 596, 604, 590, 611, 1191, 611, 1191, 611, 1191, 611, 594, 607, 598,
+    11559,  2427, 602, 592, 608, 596, 605, 1197, 604, 1198, 604, 1198, 604, 1198, 604, 1198, 604, 590, 610, 1192, 610, 595, 606, 1196, 606, 1196, 606, 1196, 606, 599, 603, 591, 609, 1193, 609, 1193, 609, 1193, 608, 597, 605, 589,
+    11567,  2418, 610, 595, 607, 597, 603, 1199, 603, 1199, 602, 1200, 602, 1200, 601, 1201, 601, 593, 608, 1194, 607, 598, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595, 605, 1197, 605, 1197, 605, 1197, 604, 590, 611, 594,
+1000000,    2421, 608, 597, 604, 590, 610, 1192, 610, 1192, 609, 1193, 609, 1193, 609, 1193, 608, 596, 605, 1197, 604, 590, 610, 1192, 611, 1191, 610, 1192, 610, 594, 606, 598, 603, 1199, 603, 1199, 602, 1200, 602, 592, 608, 596,
+    11561,  2424, 604, 590, 610, 594, 606, 1196, 606, 1196, 606, 1196, 606, 1196, 605, 1197, 605, 600, 601, 1201, 601, 593, 607, 1195, 607, 1195, 606, 1196, 606, 598, 602, 592, 608, 1194, 608, 1194, 607, 1195, 607, 597, 603, 591,
+    11564,  2421, 607, 597, 604, 590, 610, 1192, 610, 1192, 610, 1192, 610, 1192, 610, 1192, 609, 595, 606, 1196, 606, 598, 602, 1200, 601, 1201, 601, 1201, 601, 593, 607, 598, 603, 1199, 603, 1199, 602, 1200, 602, 592, 608, 596,
+1000000,    2420, 609, 595, 606, 598, 602, 1200, 602, 1200, 602, 1200, 602, 1200, 602, 1200, 602, 592, 608, 1194, 608, 596, 604, 1198, 603, 1199, 603, 1199, 603, 591, 610, 594, 606, 1196, 606, 1196, 606, 1196, 606, 598, 602, 592,
+    11565,  2420, 609, 595, 605, 600, 601, 1201, 601, 1201, 601, 1201, 601, 1201, 601, 1201, 601, 593, 607, 1195, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595, 605, 1197, 605, 1197, 605, 1197, 605, 599, 601, 593,
+    11563,  2422, 607, 597, 603, 591, 609, 1193, 609, 1193, 608, 1194, 608, 1194, 608, 1194, 582, 623, 603, 1199, 603, 591, 610, 1202, 599, 1203, 599, 1203, 599, 595, 581, 623, 577, 1225, 601, 1201, 601, 1201, 601, 593, 582, 623,
+1000000,    2425, 602, 1200, 602, 1200, 602, 592, 608, 1194, 608, 1194, 607, 1195, 607, 1195, 607, 597, 603, 1199, 602, 592, 609, 1193, 608, 1194, 608, 1194, 607, 597, 603, 601, 575, 1227, 599, 1203, 599, 1203, 573, 621, 580, 625,
+    10931,  2426, 578, 1224, 578, 1224, 578, 616, 585, 1217, 585, 1217, 585, 1217, 585, 1217, 585, 620, 580, 1222, 580, 624, 577, 1225, 577, 1225, 577, 1225, 577, 617, 583, 622, 580, 1222, 580, 1222, 579, 1223, 579, 625, 576, 618,
+    10936,  2421, 583, 1219, 583, 1219, 582, 622, 579, 1223, 578, 1224, 578, 1224, 578, 1224, 578, 616, 584, 1218, 584, 621, 580, 1222, 579, 1223, 579, 1223, 579, 625, 576, 618, 583, 1219, 582, 1220, 582, 1220, 582, 622, 578, 616,
+1000000,    2419, 584, 620, 580, 1222, 580, 624, 576, 1226, 576, 1226, 576, 1226, 576, 1226, 576, 618, 582, 1220, 582, 622, 579, 1223, 578, 1224, 579, 1223, 578, 616, 585, 619, 581, 1221, 581, 1221, 581, 1221, 580, 624, 576, 618,
+    11563,  2422, 582, 622, 579, 1223, 578, 616, 585, 1217, 585, 1217, 584, 1218, 584, 1218, 583, 622, 579, 1223, 579, 625, 575, 1216, 585, 1217, 585, 1217, 585, 619, 581, 623, 577, 1225, 577, 1225, 577, 1225, 576, 618, 583, 621,
+    11558,  2427, 577, 617, 584, 1218, 583, 621, 579, 1223, 579, 1223, 578, 1224, 578, 1224, 578, 647, 553, 1249, 553, 651, 549, 1253, 548, 1254, 549, 1253, 549, 645, 555, 649, 551, 1251, 551, 1251, 551, 1251, 550, 654, 546, 648,
+1000000,    2456, 548, 646, 554, 650, 551, 653, 547, 1255, 547, 1255, 547, 1255, 547, 1255, 547, 647, 554, 1248, 554, 650, 551, 1251, 551, 1251, 551, 1251, 551, 653, 547, 647, 554, 1248, 554, 1248, 554, 1248, 553, 651, 550, 644,
+    12112,  2449, 555, 649, 551, 654, 547, 647, 554, 1248, 554, 1248, 553, 1249, 553, 1249, 553, 651, 549, 1253, 549, 645, 555, 1247, 555, 1247, 555, 1247, 554, 650, 550, 655, 547, 1244, 557, 1224, 578, 1224, 579, 615, 585, 619,
+    12139,  2423, 580, 624, 576, 618, 582, 622, 578, 1224, 578, 1224, 578, 1224, 578, 1224, 578, 616, 584, 1218, 584, 620, 580, 1222, 580, 1222, 581, 1221, 580, 624, 577, 617, 584, 1218, 584, 1218, 584, 1218, 584, 620, 581, 623,
+1000000,    2422, 582, 1220, 581, 623, 578, 616, 584, 1218, 584, 1218, 584, 1218, 584, 1218, 584, 620, 580, 1222, 580, 624, 576, 1226, 577, 1225, 576, 1226, 576, 618, 583, 622, 579, 1223, 578, 1224, 577, 1225, 577, 617, 585, 619,
+    11559,  2426, 577, 1225, 577, 617, 583, 621, 579, 1223, 579, 1223, 578, 1224, 578, 1224, 578, 616, 584, 1218, 584, 620, 580, 1222, 580, 1222, 579, 1223, 579, 625, 575, 650, 550, 1252, 550, 1252, 549, 1253, 549, 645, 556, 648,
+    11531,  2453, 549, 1253, 548, 646, 555, 649, 551, 1251, 551, 1251, 550, 1252, 549, 1253, 549, 645, 556, 1246, 555, 649, 552, 1219, 582, 1220, 582, 1220, 582, 622, 578, 616, 585, 1217, 584, 1218, 584, 1218, 584, 620, 581, 623,
+1000000,    2428, 576, 618, 582, 1220, 583, 622, 579, 1223, 578, 1224, 578, 1224, 578, 1224, 578, 616, 585, 1217, 585, 619, 582, 1220, 582, 1220, 582, 1220, 582, 622, 578, 616, 585, 1217, 585, 1217, 584, 1218, 584, 620, 581, 623,
+    11557,  2427, 577, 617, 584, 1218, 583, 621, 580, 1222, 580, 1222, 580, 1222, 580, 1222, 580, 624, 576, 1246, 555, 649, 552, 1250, 552, 1250, 551, 1251, 551, 653, 548, 646, 554, 1248, 555, 1247, 555, 1247, 555, 649, 551, 653,
+    11528,  2447, 556, 648, 552, 1250, 552, 653, 548, 1254, 548, 1254, 547, 1245, 557, 1245, 557, 647, 553, 1249, 552, 652, 549, 1253, 548, 1254, 548, 1254, 548, 646, 555, 649, 551, 1251, 551, 1251, 551, 1251, 551, 643, 557, 647,
+1000000,    2418, 610, 594, 606, 598, 603, 1199, 603, 1199, 602, 1200, 602, 1200, 602, 1200, 602, 592, 608, 1194, 608, 596, 604, 1198, 604, 1198, 604, 1198, 603, 591, 610, 594, 606, 1196, 606, 1196, 605, 1197, 605, 599, 601, 593,
+    11563,  2422, 606, 598, 602, 592, 608, 1194, 608, 1194, 608, 1194, 607, 1195, 607, 1195, 607, 597, 603, 1199, 603, 591, 609, 1193, 609, 1193, 609, 1193, 608, 596, 605, 599, 601, 1201, 600, 1191, 611, 1191, 611, 593, 606, 598,
+    11558,  2427, 601, 593, 607, 597, 603, 1199, 603, 1199, 603, 1199, 602, 1200, 602, 1200, 601, 593, 607, 1195, 607, 597, 603, 1199, 603, 1199, 602, 1200, 602, 592, 608, 596, 604, 1198, 604, 1198, 604, 1198, 603, 591, 609, 595,
+1000000,    2424, 605, 1197, 604, 600, 600, 1191, 610, 1192, 610, 1192, 610, 1192, 609, 1193, 609, 595, 605, 1197, 606, 598, 602, 1200, 602, 1200, 601, 1201, 601, 593, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595,
+    10937,  2420, 609, 1193, 609, 595, 605, 1197, 605, 1197, 605, 1197, 605, 1197, 605, 1197, 605, 600, 601, 1201, 601, 593, 608, 1194, 608, 1194, 608, 1194, 609, 595, 605, 599, 601, 1201, 601, 1201, 601, 1201, 601, 593, 608, 596,
+    10936,  2420, 608, 1194, 608, 596, 604, 1198, 605, 1197, 605, 1197, 605, 1197, 605, 1197, 605, 600, 601, 1201, 601, 593, 607, 1195, 608, 1194, 608, 1194, 608, 596, 604, 600, 600, 1202, 601, 1201, 601, 1201, 601, 593, 607, 597,
+1000000,    2420, 609, 1193, 608, 1194, 608, 596, 579, 625, 600, 1202, 600, 1202, 600, 1202, 600, 594, 607, 1195, 607, 597, 603, 1199, 603, 1199, 602, 1200, 602, 592, 609, 595, 605, 1197, 605, 1197, 605, 1197, 604, 600, 600, 594,
+    11561,  2423, 605, 1197, 605, 1197, 605, 599, 601, 593, 607, 1195, 607, 1195, 607, 1195, 607, 597, 604, 1198, 603, 591, 610, 1192, 610, 1192, 610, 1192, 610, 594, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 610, 594,
+    11563,  2421, 608, 1194, 608, 1194, 608, 596, 605, 599, 601, 1201, 602, 1200, 602, 1200, 602, 592, 609, 1193, 609, 595, 605, 1197, 606, 1196, 606, 1196, 606, 598, 602, 592, 609, 1193, 609, 1193, 610, 1192, 610, 594, 607, 597,
+1000000,    2428, 576, 1226, 600, 1192, 610, 594, 606, 598, 602, 1200, 602, 592, 609, 595, 605, 600, 601, 593, 607, 597, 603, 591, 609, 1193,
+    25955,  2427, 601, 1190, 610, 1192, 610, 594, 606, 598, 602, 1200, 601, 593, 607, 597, 603, 591, 610, 594, 606, 598, 602, 592, 608, 1194,
+    25957,  2425, 604, 1198, 603, 1199, 603, 591, 609, 595, 605, 1197, 605, 599, 601, 593, 607, 598, 603, 591, 610, 594, 606, 598, 602, 1200,
+    25952,  2420, 608, 1194, 608, 1194, 608, 596, 604, 601, 600, 1191, 610, 594, 606, 598, 603, 591, 609, 595, 605, 599, 601, 593, 608, 1194,
+1000000,    2421, 607, 597, 603, 1199, 603, 591, 610, 594, 606, 1196, 605, 600, 576, 618, 583, 621, 604, 601, 575, 619, 606, 598, 603, 1199,
+    26576,  2424, 605, 600, 576, 1226, 601, 593, 608, 596, 604, 1198, 604, 600, 600, 594, 607, 597, 603, 591, 609, 595, 606, 598, 602, 1200,
+    26579,  2420, 583, 621, 605, 1197, 604, 600, 601, 593, 607, 1195, 607, 597, 604, 590, 610, 594, 607, 597, 603, 591, 610, 594, 606, 1196,
+    26584,  2426, 603, 591, 609, 1193, 609, 595, 605, 599, 601, 1201, 601, 593, 607, 597, 603, 591, 610, 594, 606, 598, 603, 591, 609, 1193,
+1000000,    2418, 610, 594, 606, 598, 602, 592, 609, 595, 605, 1197, 605, 1197, 605, 600, 602, 592, 608, 1194, 608, 596, 605, 1197, 605, 1197, 604, 1198, 604, 600, 601, 593, 607, 1195, 607, 1195, 607, 1195, 607, 597, 603, 591,
+    13368,  2419, 610, 594, 606, 598, 602, 592, 608, 596, 605, 1197, 604, 1198, 604, 600, 601, 593, 607, 1195, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595, 605, 1197, 605, 1197, 605, 1197, 604, 601, 600, 594,
+    13362,  2425, 604, 601, 600, 594, 607, 597, 603, 591, 610, 1192, 610, 1192, 610, 594, 606, 598, 603, 1199, 602, 592, 609, 1193, 609, 1193, 608, 1194, 608, 596, 604, 601, 600, 1191, 610, 1192, 610, 1192, 610, 594, 607, 597,
+1000000,    2427, 601, 1201, 601, 593, 582, 623, 603, 1199, 578, 1224, 603, 1199, 577, 617, 584, 620, 605, 1197, 605, 600, 601, 1201, 601, 1201, 601, 1201, 601, 593, 582, 622, 603, 1199, 603, 1199, 578, 1224, 603, 591, 610, 594,
+    12139,  2423, 605, 1197, 605, 600, 601, 593, 608, 1194, 608, 1194, 607, 1195, 607, 597, 604, 600, 601, 1201, 601, 593, 607, 1195, 608, 1194, 608, 1194, 583, 622, 604, 601, 600, 1202, 575, 1227, 601, 1201, 576, 618, 607, 597,
+    12137,  2424, 604, 1198, 604, 590, 610, 594, 607, 1195, 607, 1195, 607, 1195, 607, 597, 604, 601, 600, 1202, 600, 594, 607, 1195, 606, 1196, 581, 1221, 607, 597, 603, 591, 610, 1202, 600, 1202, 576, 1226, 602, 592, 609, 595,
+1000000,    2422, 607, 1195, 607, 597, 603, 591, 585, 619, 606, 1196, 606, 1196, 581, 624, 577, 617, 609, 1193, 584, 621, 605, 1197, 604, 1198, 604, 1198, 604, 590, 610, 595, 581, 1221, 605, 1197, 605, 1197, 605, 599, 601, 593,
+    12763,  2427, 603, 1199, 603, 591, 609, 595, 605, 599, 577, 1225, 602, 1200, 601, 593, 583, 622, 604, 1198, 604, 590, 610, 1192, 610, 1192, 610, 1192, 610, 594, 606, 598, 603, 1199, 603, 1199, 603, 1199, 603, 591, 610, 594,
+    12763,  2427, 602, 1200, 601, 593, 608, 596, 604, 600, 600, 1202, 601, 1201, 601, 593, 607, 597, 604, 1198, 604, 590, 610, 1192, 610, 1192, 611, 1191, 610, 594, 607, 598, 578, 1224, 603, 1199, 603, 1199, 603, 591, 610, 594,
+1000000,    2422, 607, 597, 603, 591, 610, 1192, 610, 594, 606, 1196, 580, 1222, 605, 600, 601, 593, 583, 1219, 608, 596, 579, 1223, 604, 1198, 604, 1198, 604, 590, 610, 594, 606, 1196, 606, 1196, 606, 1196, 606, 599, 602, 592,
+    12765,  2425, 603, 591, 610, 594, 606, 1196, 606, 598, 602, 1200, 601, 1201, 601, 593, 582, 623, 604, 1198, 604, 590, 610, 1192, 610, 1192, 609, 1193, 609, 596, 605, 599, 601, 1201, 601, 1201, 601, 1201, 600, 594, 607, 597,
+    12758,  2421, 607, 597, 603, 591, 609, 1193, 609, 595, 605, 1197, 605, 1197, 605, 599, 601, 593, 607, 1195, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595, 580, 1222, 605, 1197, 605, 1197, 605, 600, 600, 594,
+1000000,    2422, 580, 625, 601, 1201, 601, 593, 608, 596, 604, 1198, 604, 1198, 604, 600, 600, 594, 607, 1195, 607, 597, 603, 1199, 603, 1199, 603, 1199, 578, 616, 609, 595, 606, 1196, 606, 1196, 606, 1196, 581, 624, 602, 592,
+    12766,  2424, 605, 599, 601, 1201, 601, 593, 608, 596, 604, 1198, 604, 1198, 579, 625, 601, 593, 608, 1194, 608, 596, 604, 1198, 580, 1222, 605, 1197, 605, 599, 602, 592, 608, 1194, 609, 1193, 609, 1193, 609, 596, 605, 599,
+    12759,  2420, 608, 597, 604, 1198, 604, 590, 610, 594, 606, 1196, 606, 1196, 606, 598, 602, 592, 608, 1194, 607, 597, 604, 1198, 603, 1199, 603, 1199, 602, 592, 609, 595, 605, 1197, 605, 1197, 605, 1197, 604, 600, 601, 593,
+1000000,    2429, 600, 1202, 575, 1227, 599, 595, 606, 598, 602, 1200, 602, 1200, 602, 592, 609, 595, 605, 1197, 605, 599, 601, 1201, 601, 1201, 601, 1201, 601, 593, 607, 597, 603, 1199, 603, 1199, 603, 1199, 603, 591, 609, 595,
+    12136,  2425, 603, 1199, 603, 1199, 603, 591, 609, 595, 605, 1197, 605, 1197, 605, 599, 601, 593, 608, 1194, 608, 596, 604, 1198, 604, 1198, 603, 1199, 603, 591, 609, 595, 606, 1196, 606, 1196, 605, 1197, 605, 599, 601, 593,
+    12137,  2424, 604, 1198, 603, 1199, 603, 591, 609, 595, 606, 1196, 605, 1197, 605, 599, 601, 593, 607, 1195, 607, 597, 603, 1199, 603, 1199, 603, 1199, 602, 592, 609, 595, 605, 1197, 605, 1197, 604, 1198, 604, 600, 600, 594,
+1000000,    2429, 574, 1228, 573, 1229, 573, 1229, 573, 1229, 573, 621, 581, 624, 577, 617, 583, 622, 580, 1222, 579, 625, 576, 1226, 577, 1225, 576, 1226, 577, 617, 584, 620, 581, 1221, 580, 1222, 579, 1223, 579, 625, 577, 617,
+    12142,  2419, 584, 1218, 584, 1218, 583, 1219, 583, 1219, 582, 623, 578, 616, 585, 619, 581, 623, 578, 1224, 577, 617, 584, 1218, 584, 1218, 584, 1218, 584, 620, 580, 624, 576, 1226, 575, 1227, 500, 1353, 523, 620, 582, 622, /* failed, noise pollution 500, 1353 timings */
+    12134,  2427, 576, 1226, 576, 1226, 576, 1226, 576, 1226, 576, 618, 583, 622, 579, 625, 576, 618, 583, 1219, 583, 673, 527, 1223, 579, 1223, 579, 1223, 579, 625, 576, 618, 582, 1220, 582, 1220, 582, 1220, 582, 622, 578, 616,
+    12140,  2421, 582, 1220, 581, 1221, 581, 1221, 580, 1222, 580, 624, 576, 618, 582, 622, 578, 616, 585, 1217, 584, 620, 581, 1221, 580, 1222, 580, 1222, 580, 624, 576, 618, 582, 1220, 582, 1220, 582, 1220, 582, 623, 578, 616,
+1000000,    2419, 584, 672, 528, 625, 577, 617, 583, 1219, 582, 1220, 581, 1221, 582, 622, 578, 616, 585, 1217, 583, 621, 580, 1222, 580, 1222, 580, 1222, 580, 624, 576, 618, 583, 1219, 583, 1219, 582, 1220, 583, 621, 580, 624,
+    12732,  2427, 577, 617, 584, 672, 528, 676, 524, 1226, 576, 1226, 576, 1226, 576, 618, 583, 621, 579, 1223, 579, 625, 575, 1227, 575, 1227, 575, 1227, 575, 671, 529, 675, 526, 1224, 578, 1224, 578, 1224, 578, 616, 585, 619,
+    12738,  2421, 583, 621, 580, 624, 576, 618, 582, 1220, 582, 1220, 583, 1219, 583, 621, 579, 625, 576, 1226, 576, 670, 530, 1220, 582, 1220, 582, 1220, 581, 624, 577, 617, 584, 1218, 583, 1219, 583, 1219, 583, 622, 580, 624,
+1000000,    2430, 599, 1192, 609, 595, 605, 1197, 580, 624, 601, 1201, 601, 593, 607, 597, 603, 591, 610, 594, 606, 598, 602, 592, 608, 1194,
+    25958,  2423, 605, 1197, 604, 600, 575, 1227, 600, 594, 606, 1196, 606, 598, 602, 592, 608, 596, 604, 601, 600, 594, 607, 597, 603, 1199,
+    25949,  2422, 607, 1195, 606, 598, 603, 1199, 602, 592, 608, 1194, 608, 596, 604, 600, 601, 593, 607, 597, 604, 600, 600, 594, 607, 1195,
+    25958,  2423, 606, 1196, 606, 598, 602, 1200, 602, 592, 608, 1194, 608, 596, 605, 600, 601, 593, 607, 597, 603, 591, 610, 594, 606, 1196,
+    25957,  2425, 604, 1198, 603, 591, 610, 1192, 610, 594, 606, 1196, 606, 598, 602, 592, 609, 595, 605, 599, 602, 592, 608, 596, 604, 1198,
+    25956,  2426, 604, 1198, 603, 591, 610, 1192, 610, 594, 606, 1196, 606, 598, 602, 592, 608, 597, 605, 599, 601, 593, 607, 597, 603, 1199,
+    25952,  2420, 609, 1193, 608, 596, 604, 1198, 604, 590, 610, 1192, 610, 594, 606, 598, 602, 592, 608, 596, 605, 599, 601, 593, 607, 1195,
+1000000,    2422, 583, 1219, 608, 596, 605, 1197, 580, 624, 601, 1201, 601, 593, 608, 596, 604, 600, 601, 593, 607, 597, 604, 590, 610, 1202,
+    25955,  2427, 603, 1199, 603, 591, 609, 1193, 610, 594, 606, 1196, 607, 597, 603, 591, 609, 595, 606, 598, 602, 592, 609, 595, 605, 1197,
+    25957,  2425, 604, 1198, 604, 590, 610, 1192, 610, 594, 581, 1221, 606, 598, 602, 592, 608, 596, 605, 599, 601, 593, 607, 597, 604, 1198,
+    25954,  2418, 610, 1192, 610, 594, 606, 1196, 605, 599, 601, 1201, 601, 593, 608, 596, 604, 590, 610, 594, 606, 598, 603, 591, 609, 1193,
+    25958,  2424, 604, 1198, 604, 590, 610, 1192, 610, 594, 606, 1196, 606, 598, 602, 592, 609, 595, 605, 600, 601, 593, 607, 597, 603, 1199,
+    25953,  2419, 610, 1192, 609, 595, 605, 1197, 605, 600, 601, 1201, 600, 594, 607, 597, 603, 591, 609, 595, 605, 599, 601, 593, 608, 1194,
+    25954,  2418, 611, 1191, 610, 594, 606, 1196, 606, 598, 602, 1200, 602, 592, 608, 596, 604, 601, 600, 594, 607, 597, 603, 591, 609, 1193,
+    25958,  2424, 605, 1197, 605, 599, 601, 1201, 600, 594, 607, 1195, 607, 597, 603, 591, 609, 596, 605, 599, 602, 592, 608, 596, 605, 1197,
+    25954,  2428, 601, 1190, 610, 594, 607, 1195, 606, 598, 602, 1200, 602, 592, 608, 596, 604, 590, 610, 594, 606, 598, 603, 591, 609, 1193,
+    25960,  2422, 607, 1195, 606, 598, 602, 1200, 602, 592, 609, 1193, 609, 595, 605, 599, 601, 593, 607, 597, 604, 590, 610, 594, 606, 1196,
+    25957,  2424, 605, 1197, 604, 600, 600, 1202, 601, 593, 607, 1195, 607, 597, 603, 591, 610, 594, 606, 598, 603, 591, 609, 595, 606, 1196,
+1000000,    2421, 608, 1194, 608, 596, 604, 1198, 604, 601, 575, 1227, 601, 593, 607, 598, 604, 600, 600, 594, 607, 598, 604, 601, 600, 1202,
+    25953,  2419, 609, 1193, 609, 596, 605, 1197, 605, 600, 601, 1201, 601, 593, 607, 597, 603, 591, 610, 594, 606, 599, 602, 592, 608, 1194,
+    25958,  2424, 605, 1197, 605, 600, 601, 1201, 600, 594, 607, 1195, 606, 598, 602, 592, 609, 595, 605, 600, 601, 593, 608, 596, 604, 1198,
+1000000,    2423, 606, 1196, 606, 598, 602, 1200, 602, 592, 608, 1194, 608, 597, 604, 590, 610, 594, 607, 597, 603, 591, 610, 594, 606, 1196,
+    25958,  2424, 605, 1197, 604, 600, 601, 1201, 601, 593, 607, 1195, 607, 597, 604, 590, 610, 595, 607, 597, 603, 591, 610, 594, 607, 1195,
+    25961,  2421, 608, 1194, 608, 596, 605, 1197, 605, 600, 601, 1201, 601, 593, 607, 597, 603, 591, 610, 594, 606, 598, 602, 592, 609, 1193,
+1000000,    2429, 601, 1201, 601, 593, 607, 1195, 608, 596, 604, 1198, 604, 600, 601, 593, 607, 597, 604, 590, 611, 593, 607, 597, 604, 1198,
+    25959,  2422, 607, 1195, 607, 597, 603, 1199, 603, 591, 609, 1193, 610, 594, 606, 598, 602, 592, 609, 595, 605, 599, 602, 592, 608, 1194,
+    25959,  2421, 608, 1194, 607, 597, 603, 1199, 603, 591, 610, 1192, 610, 594, 606, 598, 603, 591, 609, 595, 605, 599, 602, 592, 608, 1194,
+    25959,  2422, 608, 1194, 608, 596, 604, 1198, 604, 590, 611, 1201, 601, 593, 607, 597, 604, 590, 610, 594, 607, 597, 603, 591, 609, 1193,
+    25962,  2418, 610, 1192, 610, 594, 606, 1196, 607, 597, 603, 1199, 603, 591, 609, 595, 605, 599, 602, 592, 608, 596, 605, 599, 601, 1201,
+
+1000000,    2357, 610, 1183, 592, 1191, 614, 1179, 595, 1188, 618, 584, 613, 1180, 593, 588, 613, 1190, 612, 590, 605, 587, 613, 589, 605, 587,
+    25398,  2355, 623, 1180, 591, 1181, 627, 1186, 589, 1183, 618, 584, 616, 1187, 587, 584, 614, 1189, 615, 587, 605, 587, 615, 587, 609, 593,
+1000000,    2383, 609, 1214, 600, 612, 580, 1213, 608, 614, 583, 1210, 605, 607, 586, 616, 611, 1192, 599, 613, 608, 614, 579, 613, 615, 607,
+    26670,  2387, 601, 1212, 600, 612, 589, 1214, 603, 609, 586, 1217, 595, 607, 594, 618, 606, 1187, 602, 610, 609, 613, 588, 614, 610, 612,
+1000000,    2445, 582, 1221, 603, 548, 602, 1191, 609, 572, 602, 1191, 609, 542, 607, 544, 631, 1172, 603, 568, 606, 545, 605, 566, 608, 543,
+    26263,  2414, 611, 1192, 607, 544, 606, 1197, 602, 569, 606, 1197, 602, 539, 611, 540, 635, 1168, 606, 565, 610, 541, 608, 563, 587, 564,
+};
+
+const IrdaMessage test_decoder_sirc_expected1[] = {
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x60, false},
+    {IrdaProtocolSIRC,         0x10,   0x60, false},
+    {IrdaProtocolSIRC,         0x10,   0x60, false},
+    {IrdaProtocolSIRC,         0x10,   0x65, false},
+    {IrdaProtocolSIRC,         0x10,   0x65, false},
+    {IrdaProtocolSIRC,         0x10,   0x65, false},
+    {IrdaProtocolSIRC20,       0x410,  0x17, false},
+    {IrdaProtocolSIRC20,       0x410,  0x17, false},
+    {IrdaProtocolSIRC20,       0x410,  0x17, false},
+    {IrdaProtocolSIRC,         0x10,   0x21, false},
+    {IrdaProtocolSIRC,         0x10,   0x21, false},
+    {IrdaProtocolSIRC,         0x10,   0x21, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7B, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7B, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7B, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x78, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x78, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x78, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x79, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x79, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x79, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7A, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7C, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7D, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7D, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x7D, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x73, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x73, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x73, false},
+    {IrdaProtocolSIRC,         0x10,   0x13, false},
+    {IrdaProtocolSIRC,         0x10,   0x13, false},
+    {IrdaProtocolSIRC,         0x10,   0x13, false},
+    {IrdaProtocolSIRC,         0x10,   0x13, false},
+    {IrdaProtocolSIRC,         0x10,   0x12, false},
+    {IrdaProtocolSIRC,         0x10,   0x12, false},
+    {IrdaProtocolSIRC,         0x10,   0x12, false},
+    {IrdaProtocolSIRC,         0x10,   0x12, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x30, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x30, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x30, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x39, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x39, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x39, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x31, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x31, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x31, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x34, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x34, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x34, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x32, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x32, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x32, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x33, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x33, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x33, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x0F, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x0F, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x0F, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x38, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x38, false},
+    {IrdaProtocolSIRC20,       0x73A,  0x38, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x10,   0x15, false},
+    {IrdaProtocolSIRC,         0x01,   0x2F, false},
+    {IrdaProtocolSIRC,         0x01,   0x2F, false},
+    {IrdaProtocolSIRC,         0x01,   0x15, false},
+    {IrdaProtocolSIRC,         0x01,   0x15, false},
+    {IrdaProtocolSIRC,         0x01,   0x15, false},
+    {IrdaProtocolSIRC,         0x01,   0x15, false},
+};
+
+
+//   command (0x55)    address (0x0A)       SIRC
+//   1 0 1 0 1 0 1     0 1 0 1 0
+//   2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+//
+//   command (0x7F)    address (0x1F)       SIRC
+//   1 1 1 1 1 1 1     1 1 1 1 1
+//   2400, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+//
+//   command (0x00)    address (0x00)       SIRC
+//   0 0 0 0 0 0 0     0 0 0 0 0
+//   2400, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
+//
+//   command (0x53)    address (0x0D)       SIRC
+//   1 1 0 0 1 0 1     1 0 1 1 0
+//   2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600,
+
+const uint32_t test_decoder_sirc_input2[] = {
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 600, /* failed - should be skipped */
+
+1000000, 2400, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+1000000, 2400, 600, 1200, 600, 600, /* failed - should be skipped */
+1000000, 2400, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+1000000, 2400, 600, 1200, 600,  /* failed - should be skipped */
+         2400, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+1000000, 2400, 600, 1200, 600, 600, /* failed - should be skipped */
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+
+1000000, 2400, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600,
+
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600,
+};
+
+const IrdaMessage test_decoder_sirc_expected2[] = {
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    /* failed - 13 data bits */
+
+    {IrdaProtocolSIRC, 0x1F, 0x7F, false},
+    /* failed - 2 data bits */
+    {IrdaProtocolSIRC, 0x1F, 0x7F, false},
+    /* failed - sudden end */
+    {IrdaProtocolSIRC, 0x1F, 0x7F, false},
+    /* failed */
+    {IrdaProtocolSIRC, 0x0A, 0x55, false},
+
+    {IrdaProtocolSIRC, 0x00, 0x00, false},
+
+    {IrdaProtocolSIRC, 0x0D, 0x53, false},
+};
+
+
+//   command (0x13)    address (0xFD)       SIRC15
+//   1 1 0 0 1 0 0     1 0 1 1 1 1 1 1
+//   2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+//
+//   command (0x53)    address (0x7D)       SIRC15
+//   1 1 0 0 1 0 1     1 0 1 1 1 1 1 0
+//   2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+//
+//   command (0x53)    address (0x0D)       SIRC15
+//   1 1 0 0 1 0 1     1 0 1 1 0 0 0 0
+//   2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+
+const uint32_t test_decoder_sirc_input3[] = {
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+  10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+  10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+  10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+  10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 600, 600, 600,
+
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+
+  10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200,
+};
+
+const IrdaMessage test_decoder_sirc_expected3[] = {
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x0D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x0D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x0D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x0D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x0D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0xFD, 0x13, false},
+};
+
+const uint32_t test_decoder_sirc_input4[] = {
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+};
+
+const IrdaMessage test_decoder_sirc_expected4[] = {
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},      //    {IrdaProtocolSIRC20, 0x15, 0x3ED3, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+};
+
+const uint32_t test_decoder_sirc_input5[] = {
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+1000000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600,
+};
+
+const IrdaMessage test_decoder_sirc_expected5[] = {
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC20, 0xFB5, 0x53, false},
+};
+
+
+
+
+const IrdaMessage test_encoder_sirc_input1[] = {
+    {IrdaProtocolSIRC, 0xA, 0x55, false},
+};
+
+const uint32_t test_encoder_sirc_expected1[] = {
+10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600,
+};
+
+
+
+
+const IrdaMessage test_encoder_sirc_input2[] = {
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
+};
+
+const uint32_t test_encoder_sirc_expected2[] = {
+    10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600, /* 2 low levels in row */
+    18000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600, /* 2 low levels in row */
+    18000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, 600,
+};
+
+const IrdaMessage test_sirc[] = {
+    {IrdaProtocolSIRC20, 0x1FFF, 0x7F, false},
+    {IrdaProtocolSIRC20, 0x1FFF, 0x7F, true},
+    {IrdaProtocolSIRC20, 0x1FFF, 0x7F, true},
+    {IrdaProtocolSIRC, 0x00, 0x00, false},
+    {IrdaProtocolSIRC, 0x00, 0x00, true},
+    {IrdaProtocolSIRC, 0x00, 0x00, true},
+
+    {IrdaProtocolSIRC, 0x1A, 0x22, false},
+    {IrdaProtocolSIRC, 0x1A, 0x22, true},
+    {IrdaProtocolSIRC, 0x1A, 0x22, true},
+    {IrdaProtocolSIRC, 0x17, 0x0A, false},
+
+    {IrdaProtocolSIRC15, 0x7D, 0x53, false},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
+    {IrdaProtocolSIRC15, 0x7D, 0x53, true},
+    {IrdaProtocolSIRC15, 0x71, 0x0, false},
+    {IrdaProtocolSIRC15, 0x15, 0x01, false},
+    {IrdaProtocolSIRC15, 0x01, 0x15, false},
+
+    {IrdaProtocolSIRC20, 0xAA, 0x55, false},
+    {IrdaProtocolSIRC20, 0x331, 0x71, false},
+
+    {IrdaProtocolSIRC, 0x00, 0x00, false},
+    {IrdaProtocolSIRC, 0x1F, 0x7F, false},
+    {IrdaProtocolSIRC15, 0x00, 0x00, false},
+    {IrdaProtocolSIRC15, 0xFF, 0x7F, false},
+    {IrdaProtocolSIRC20, 0x00, 0x00, false},
+    {IrdaProtocolSIRC20, 0x1FFF, 0x7F, false},
+};
+

+ 9 - 0
core/furi/common_defines.h

@@ -19,6 +19,15 @@
     })
     })
 #endif
 #endif
 
 
+#ifndef ROUND_UP_TO
+#define ROUND_UP_TO(a, b)       \
+    ({                          \
+        __typeof__(a) _a = (a); \
+        __typeof__(b) _b = (b); \
+        _a / _b + !!(_a % _b);  \
+    })
+#endif
+
 #ifndef CLAMP
 #ifndef CLAMP
 #define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
 #define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
 #endif
 #endif

+ 5 - 5
firmware/targets/f6/furi-hal/furi-hal-irda.c

@@ -442,7 +442,7 @@ static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift
         buffer->polarity[polarity_counter++] = IRDA_TX_CCMR_LOW;
         buffer->polarity[polarity_counter++] = IRDA_TX_CCMR_LOW;
     }
     }
 
 
-    for (*size = 0; (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == FuriHalIrdaTxGetDataStateOk); ++(*size), ++polarity_counter) {
+    for (*size = 0; (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == FuriHalIrdaTxGetDataStateOk);) {
         if (irda_tim_tx.tx_timing_rest_duration > 0) {
         if (irda_tim_tx.tx_timing_rest_duration > 0) {
             if (irda_tim_tx.tx_timing_rest_duration > 0xFFFF) {
             if (irda_tim_tx.tx_timing_rest_duration > 0xFFFF) {
                 buffer->data[*size] = 0xFFFF;
                 buffer->data[*size] = 0xFFFF;
@@ -453,6 +453,8 @@ static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift
             }
             }
             irda_tim_tx.tx_timing_rest_duration -= buffer->data[*size];
             irda_tim_tx.tx_timing_rest_duration -= buffer->data[*size];
             buffer->polarity[polarity_counter] = irda_tim_tx.tx_timing_rest_level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW;
             buffer->polarity[polarity_counter] = irda_tim_tx.tx_timing_rest_level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW;
+            ++(*size);
+            ++polarity_counter;
             continue;
             continue;
         }
         }
 
 
@@ -467,18 +469,16 @@ static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift
                  */
                  */
                 status = FuriHalIrdaTxGetDataStateOk;
                 status = FuriHalIrdaTxGetDataStateOk;
             }
             }
-            --(*size);
-            --polarity_counter;
         } else if ((num_of_impulses - 1) > 0xFFFF) {
         } else if ((num_of_impulses - 1) > 0xFFFF) {
             irda_tim_tx.tx_timing_rest_duration = num_of_impulses - 1;
             irda_tim_tx.tx_timing_rest_duration = num_of_impulses - 1;
             irda_tim_tx.tx_timing_rest_status = status;
             irda_tim_tx.tx_timing_rest_status = status;
             irda_tim_tx.tx_timing_rest_level = level;
             irda_tim_tx.tx_timing_rest_level = level;
-            --(*size);
-            --polarity_counter;
             status = FuriHalIrdaTxGetDataStateOk;
             status = FuriHalIrdaTxGetDataStateOk;
         } else {
         } else {
             buffer->polarity[polarity_counter] = level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW;
             buffer->polarity[polarity_counter] = level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW;
             buffer->data[*size] = num_of_impulses - 1;
             buffer->data[*size] = num_of_impulses - 1;
+            ++(*size);
+            ++polarity_counter;
         }
         }
     }
     }
 
 

+ 99 - 54
lib/irda/encoder_decoder/common/irda_common_decoder.c

@@ -4,8 +4,34 @@
 #include <stdbool.h>
 #include <stdbool.h>
 #include <furi.h>
 #include <furi.h>
 #include "irda_i.h"
 #include "irda_i.h"
+#include <stdint.h>
 
 
-static void irda_common_decoder_reset_state(IrdaCommonDecoder* common_decoder);
+static void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder);
+
+static inline size_t consume_samples(uint32_t* array, size_t len, size_t shift) {
+    furi_assert(len >= shift);
+    len -= shift;
+    for (int i = 0; i < len; ++i)
+        array[i] = array[i + shift];
+
+    return len;
+}
+
+static inline void accumulate_lsb(IrdaCommonDecoder* decoder, bool bit) {
+    uint16_t index = decoder->databit_cnt / 8;
+    uint8_t shift = decoder->databit_cnt % 8;   // LSB first
+
+    if (!shift)
+        decoder->data[index] = 0;
+
+    if (bit) {
+        decoder->data[index] |= (0x1 << shift);           // add 1
+    } else {
+        (void) decoder->data[index];                      // add 0
+    }
+
+    ++decoder->databit_cnt;
+}
 
 
 static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
 static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
     furi_assert(decoder);
     furi_assert(decoder);
@@ -16,8 +42,7 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
     // align to start at Mark timing
     // align to start at Mark timing
     if (!start_level) {
     if (!start_level) {
         if (decoder->timings_cnt > 0) {
         if (decoder->timings_cnt > 0) {
-            --decoder->timings_cnt;
-            shift_left_array(decoder->timings, decoder->timings_cnt, 1);
+            decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
         }
         }
     }
     }
 
 
@@ -30,25 +55,22 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) {
         uint16_t preamble_mark = decoder->protocol->timings.preamble_mark;
         uint16_t preamble_mark = decoder->protocol->timings.preamble_mark;
         uint16_t preamble_space = decoder->protocol->timings.preamble_space;
         uint16_t preamble_space = decoder->protocol->timings.preamble_space;
 
 
-        if ((MATCH_PREAMBLE_TIMING(decoder->timings[0], preamble_mark, preamble_tolerance))
-            && (MATCH_PREAMBLE_TIMING(decoder->timings[1], preamble_space, preamble_tolerance))) {
+        if ((MATCH_TIMING(decoder->timings[0], preamble_mark, preamble_tolerance))
+            && (MATCH_TIMING(decoder->timings[1], preamble_space, preamble_tolerance))) {
             result = true;
             result = true;
         }
         }
 
 
-        decoder->timings_cnt -= 2;
-        shift_left_array(decoder->timings, decoder->timings_cnt, 2);
+        decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 2);
     }
     }
 
 
     return result;
     return result;
 }
 }
 
 
-/* Pulse Distance-Width Modulation */
-IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder) {
+/* Pulse Distance Modulation */
+IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder) {
     furi_assert(decoder);
     furi_assert(decoder);
 
 
     uint32_t* timings = decoder->timings;
     uint32_t* timings = decoder->timings;
-    uint16_t index = 0;
-    uint8_t shift = 0;
     IrdaStatus status = IrdaStatusError;
     IrdaStatus status = IrdaStatusError;
     uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
     uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
     uint16_t bit1_mark = decoder->protocol->timings.bit1_mark;
     uint16_t bit1_mark = decoder->protocol->timings.bit1_mark;
@@ -59,7 +81,7 @@ IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder) {
     while (1) {
     while (1) {
         // Stop bit
         // Stop bit
         if ((decoder->databit_cnt == decoder->protocol->databit_len) && (decoder->timings_cnt == 1)) {
         if ((decoder->databit_cnt == decoder->protocol->databit_len) && (decoder->timings_cnt == 1)) {
-            if (MATCH_BIT_TIMING(timings[0], bit1_mark, bit_tolerance)) {
+            if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)) {
                 decoder->timings_cnt = 0;
                 decoder->timings_cnt = 0;
                 status = IrdaStatusReady;
                 status = IrdaStatusReady;
             } else {
             } else {
@@ -69,23 +91,17 @@ IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder) {
         }
         }
 
 
         if (decoder->timings_cnt >= 2) {
         if (decoder->timings_cnt >= 2) {
-            index = decoder->databit_cnt / 8;
-            shift = decoder->databit_cnt % 8;   // LSB first
-            if (!shift)
-                decoder->data[index] = 0;
-            if (MATCH_BIT_TIMING(timings[0], bit1_mark, bit_tolerance)
-                && MATCH_BIT_TIMING(timings[1], bit1_space, bit_tolerance)) {
-                decoder->data[index] |= (0x1 << shift);           // add 1
-            } else if (MATCH_BIT_TIMING(timings[0], bit0_mark, bit_tolerance)
-                && MATCH_BIT_TIMING(timings[1], bit0_space, bit_tolerance)) {
-                (void) decoder->data[index];                      // add 0
+            if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)
+                && MATCH_TIMING(timings[1], bit1_space, bit_tolerance)) {
+                accumulate_lsb(decoder, 1);
+            } else if (MATCH_TIMING(timings[0], bit0_mark, bit_tolerance)
+                && MATCH_TIMING(timings[1], bit0_space, bit_tolerance)) {
+                accumulate_lsb(decoder, 0);
             } else {
             } else {
                 status = IrdaStatusError;
                 status = IrdaStatusError;
                 break;
                 break;
             }
             }
-            ++decoder->databit_cnt;
-            decoder->timings_cnt -= 2;
-            shift_left_array(decoder->timings, decoder->timings_cnt, 2);
+            decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 2);
         } else {
         } else {
             status = IrdaStatusOk;
             status = IrdaStatusOk;
             break;
             break;
@@ -107,8 +123,8 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder) {
         bool* switch_detect = &decoder->switch_detect;
         bool* switch_detect = &decoder->switch_detect;
         furi_assert((*switch_detect == true) || (*switch_detect == false));
         furi_assert((*switch_detect == true) || (*switch_detect == false));
 
 
-        bool single_timing = MATCH_BIT_TIMING(timing, bit, tolerance);
-        bool double_timing = MATCH_BIT_TIMING(timing, 2*bit, tolerance);
+        bool single_timing = MATCH_TIMING(timing, bit, tolerance);
+        bool double_timing = MATCH_TIMING(timing, 2*bit, tolerance);
 
 
         if(!single_timing && !double_timing) {
         if(!single_timing && !double_timing) {
             status = IrdaStatusError;
             status = IrdaStatusError;
@@ -134,19 +150,13 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder) {
                 *switch_detect = 0;
                 *switch_detect = 0;
         }
         }
 
 
-        --decoder->timings_cnt;
-        shift_left_array(decoder->timings, decoder->timings_cnt, 1);
+        decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
         status = IrdaStatusOk;
         status = IrdaStatusOk;
         bool level = (decoder->level + decoder->timings_cnt) % 2;
         bool level = (decoder->level + decoder->timings_cnt) % 2;
 
 
         if (decoder->databit_cnt < decoder->protocol->databit_len) {
         if (decoder->databit_cnt < decoder->protocol->databit_len) {
             if (*switch_detect) {
             if (*switch_detect) {
-                uint8_t index = decoder->databit_cnt / 8;
-                uint8_t shift = decoder->databit_cnt % 8;   // LSB first
-                if (!shift)
-                    decoder->data[index] = 0;
-                decoder->data[index] |= (level << shift);
-                ++decoder->databit_cnt;
+                accumulate_lsb(decoder, level);
             }
             }
             if (decoder->databit_cnt == decoder->protocol->databit_len) {
             if (decoder->databit_cnt == decoder->protocol->databit_len) {
                 if (level) {
                 if (level) {
@@ -169,6 +179,46 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder) {
     return status;
     return status;
 }
 }
 
 
+/* Pulse Width Modulation */
+IrdaStatus irda_common_decode_pwm(IrdaCommonDecoder* decoder) {
+    furi_assert(decoder);
+
+    uint32_t* timings = decoder->timings;
+    IrdaStatus status = IrdaStatusOk;
+    uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
+    uint16_t bit1_mark = decoder->protocol->timings.bit1_mark;
+    uint16_t bit1_space = decoder->protocol->timings.bit1_space;
+    uint16_t bit0_mark = decoder->protocol->timings.bit0_mark;
+
+    while (decoder->timings_cnt) {
+        bool level = (decoder->level + decoder->timings_cnt + 1) % 2;
+
+        if (level) {
+            if (MATCH_TIMING(timings[0], bit1_mark, bit_tolerance)) {
+                accumulate_lsb(decoder, 1);
+            } else if (MATCH_TIMING(timings[0], bit0_mark, bit_tolerance)) {
+                accumulate_lsb(decoder, 0);
+            } else {
+                status = IrdaStatusError;
+                break;
+            }
+        } else {
+            if (!MATCH_TIMING(timings[0], bit1_space, bit_tolerance)) {
+                status = IrdaStatusError;
+                break;
+            }
+        }
+        decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
+
+        if (decoder->databit_cnt == decoder->protocol->databit_len) {
+            status = IrdaStatusReady;
+            break;
+        }
+    }
+
+    return status;
+}
+
 IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration) {
 IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration) {
     furi_assert(decoder);
     furi_assert(decoder);
 
 
@@ -176,7 +226,7 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t
     IrdaStatus status = IrdaStatusError;
     IrdaStatus status = IrdaStatusError;
 
 
     if (decoder->level == level) {
     if (decoder->level == level) {
-        decoder->timings_cnt = 0;
+        irda_common_decoder_reset(decoder);
     }
     }
     decoder->level = level;   // start with low level (Space timing)
     decoder->level = level;   // start with low level (Space timing)
 
 
@@ -242,32 +292,27 @@ void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) {
     return decoder;
     return decoder;
 }
 }
 
 
-void irda_common_decoder_set_context(void* decoder, void* context) {
-    IrdaCommonDecoder* common_decoder = decoder;
-    common_decoder->context = context;
-}
-
-void irda_common_decoder_free(void* decoder) {
+void irda_common_decoder_free(IrdaCommonDecoder* decoder) {
     furi_assert(decoder);
     furi_assert(decoder);
     free(decoder);
     free(decoder);
 }
 }
 
 
-void irda_common_decoder_reset_state(IrdaCommonDecoder* common_decoder) {
-    common_decoder->state = IrdaCommonDecoderStateWaitPreamble;
-    common_decoder->databit_cnt = 0;
-    common_decoder->switch_detect = false;
-    common_decoder->message.protocol = IrdaProtocolUnknown;
-    if ((common_decoder->protocol->timings.preamble_mark == 0) && (common_decoder->timings_cnt > 0)) {
-        --common_decoder->timings_cnt;
-        shift_left_array(common_decoder->timings, common_decoder->timings_cnt, 1);
+void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder) {
+    decoder->state = IrdaCommonDecoderStateWaitPreamble;
+    decoder->databit_cnt = 0;
+    decoder->switch_detect = false;
+    decoder->message.protocol = IrdaProtocolUnknown;
+    if (decoder->protocol->timings.preamble_mark == 0) {
+        if (decoder->timings_cnt > 0) {
+            decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
+        }
     }
     }
 }
 }
 
 
-void irda_common_decoder_reset(void* decoder) {
+void irda_common_decoder_reset(IrdaCommonDecoder* decoder) {
     furi_assert(decoder);
     furi_assert(decoder);
-    IrdaCommonDecoder* common_decoder = decoder;
 
 
-    irda_common_decoder_reset_state(common_decoder);
-    common_decoder->timings_cnt = 0;
+    irda_common_decoder_reset_state(decoder);
+    decoder->timings_cnt = 0;
 }
 }
 
 

+ 18 - 9
lib/irda/encoder_decoder/common/irda_common_encoder.c

@@ -35,6 +35,7 @@ IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* d
     if (even_timing)        /* start encoding from space */
     if (even_timing)        /* start encoding from space */
         ++encoder->bits_encoded;
         ++encoder->bits_encoded;
     ++encoder->timings_encoded;
     ++encoder->timings_encoded;
+    encoder->timings_sum += *duration;
 
 
     bool finish = (encoder->bits_encoded == encoder->protocol->databit_len);
     bool finish = (encoder->bits_encoded == encoder->protocol->databit_len);
     finish |= (encoder->bits_encoded == (encoder->protocol->databit_len-1)) && *level && !even_timing;
     finish |= (encoder->bits_encoded == (encoder->protocol->databit_len-1)) && *level && !even_timing;
@@ -46,6 +47,7 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
     furi_assert(duration);
     furi_assert(duration);
     furi_assert(level);
     furi_assert(level);
 
 
+    bool done = false;
     const IrdaTimings* timings = &encoder->protocol->timings;
     const IrdaTimings* timings = &encoder->protocol->timings;
     uint8_t index = encoder->bits_encoded / 8;
     uint8_t index = encoder->bits_encoded / 8;
     uint8_t shift = encoder->bits_encoded % 8;   // LSB first
     uint8_t shift = encoder->bits_encoded % 8;   // LSB first
@@ -53,9 +55,11 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
 
 
     // stop bit
     // stop bit
     if (encoder->bits_encoded == encoder->protocol->databit_len) {
     if (encoder->bits_encoded == encoder->protocol->databit_len) {
+        furi_assert(!encoder->protocol->no_stop_bit);
         *duration = timings->bit1_mark;
         *duration = timings->bit1_mark;
         *level = true;
         *level = true;
         ++encoder->timings_encoded;
         ++encoder->timings_encoded;
+        encoder->timings_sum += *duration;
         return IrdaStatusDone;
         return IrdaStatusDone;
     }
     }
 
 
@@ -68,8 +72,14 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio
         ++encoder->bits_encoded;
         ++encoder->bits_encoded;
     }
     }
 
 
+    if ((encoder->bits_encoded == encoder->protocol->databit_len)
+        && encoder->protocol->no_stop_bit) {
+        done = true;
+    }
+
     ++encoder->timings_encoded;
     ++encoder->timings_encoded;
-    return IrdaStatusOk;
+    encoder->timings_sum += *duration;
+    return done ? IrdaStatusDone : IrdaStatusOk;
 }
 }
 
 
 IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
 IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
@@ -80,12 +90,13 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
     const IrdaTimings* timings = &encoder->protocol->timings;
     const IrdaTimings* timings = &encoder->protocol->timings;
 
 
     switch (encoder->state) {
     switch (encoder->state) {
-    case IrdaCommonEncoderStateSpace:
+    case IrdaCommonEncoderStateSilence:
         *duration = encoder->protocol->timings.silence_time;
         *duration = encoder->protocol->timings.silence_time;
         *level = false;
         *level = false;
         status = IrdaStatusOk;
         status = IrdaStatusOk;
         encoder->state = IrdaCommonEncoderStatePreamble;
         encoder->state = IrdaCommonEncoderStatePreamble;
         ++encoder->timings_encoded;
         ++encoder->timings_encoded;
+        encoder->timings_sum = 0;
         break;
         break;
     case IrdaCommonEncoderStatePreamble:
     case IrdaCommonEncoderStatePreamble:
         if (timings->preamble_mark) {
         if (timings->preamble_mark) {
@@ -98,6 +109,7 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
                 encoder->state = IrdaCommonEncoderStateEncode;
                 encoder->state = IrdaCommonEncoderStateEncode;
             }
             }
             ++encoder->timings_encoded;
             ++encoder->timings_encoded;
+            encoder->timings_sum += *duration;
             break;
             break;
         } else {
         } else {
             encoder->state = IrdaCommonEncoderStateEncode;
             encoder->state = IrdaCommonEncoderStateEncode;
@@ -110,9 +122,10 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo
                 encoder->state = IrdaCommonEncoderStateEncodeRepeat;
                 encoder->state = IrdaCommonEncoderStateEncodeRepeat;
             } else {
             } else {
                 encoder->timings_encoded = 0;
                 encoder->timings_encoded = 0;
+                encoder->timings_sum = 0;
                 encoder->bits_encoded = 0;
                 encoder->bits_encoded = 0;
                 encoder->switch_detect = 0;
                 encoder->switch_detect = 0;
-                encoder->state = IrdaCommonEncoderStateSpace;
+                encoder->state = IrdaCommonEncoderStateSilence;
             }
             }
         }
         }
         break;
         break;
@@ -144,8 +157,9 @@ void irda_common_encoder_free(IrdaCommonEncoder* encoder) {
 void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
 void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
     furi_assert(encoder);
     furi_assert(encoder);
     encoder->timings_encoded = 0;
     encoder->timings_encoded = 0;
+    encoder->timings_sum = 0;
     encoder->bits_encoded = 0;
     encoder->bits_encoded = 0;
-    encoder->state = IrdaCommonEncoderStateSpace;
+    encoder->state = IrdaCommonEncoderStateSilence;
     encoder->switch_detect = 0;
     encoder->switch_detect = 0;
 
 
     uint8_t bytes_to_clear = encoder->protocol->databit_len / 8
     uint8_t bytes_to_clear = encoder->protocol->databit_len / 8
@@ -153,8 +167,3 @@ void irda_common_encoder_reset(IrdaCommonEncoder* encoder) {
     memset(encoder->data, 0, bytes_to_clear);
     memset(encoder->data, 0, bytes_to_clear);
 }
 }
 
 
-void irda_common_encoder_set_context(void* decoder, void* context) {
-    IrdaCommonEncoder* common_encoder = decoder;
-    common_encoder->context = context;
-}
-

+ 13 - 22
lib/irda/encoder_decoder/common/irda_common_i.h

@@ -5,11 +5,8 @@
 #include "irda_i.h"
 #include "irda_i.h"
 
 
 
 
-#define MATCH_BIT_TIMING(x, v, delta)       (  ((x) < (v + delta)) \
-                                            && ((x) > (v - delta)))
-
-#define MATCH_PREAMBLE_TIMING(x, v, delta)  (  ((x) < ((v) * (1 + (delta)))) \
-                                            && ((x) > ((v) * (1 - (delta)))))
+#define MATCH_TIMING(x, v, delta)       (  ((x) < (v + delta)) \
+                                        && ((x) > (v - delta)))
 
 
 typedef struct IrdaCommonDecoder IrdaCommonDecoder;
 typedef struct IrdaCommonDecoder IrdaCommonDecoder;
 typedef struct IrdaCommonEncoder IrdaCommonEncoder;
 typedef struct IrdaCommonEncoder IrdaCommonEncoder;
@@ -21,6 +18,7 @@ typedef IrdaStatus (*IrdaCommonEncode)(IrdaCommonEncoder* encoder, uint32_t* out
 typedef struct {
 typedef struct {
     IrdaTimings timings;
     IrdaTimings timings;
     bool     manchester_start_from_space;
     bool     manchester_start_from_space;
+    bool     no_stop_bit;
     uint32_t databit_len;
     uint32_t databit_len;
     IrdaCommonDecode decode;
     IrdaCommonDecode decode;
     IrdaCommonDecode decode_repeat;
     IrdaCommonDecode decode_repeat;
@@ -36,7 +34,7 @@ typedef enum {
 } IrdaCommonStateDecoder;
 } IrdaCommonStateDecoder;
 
 
 typedef enum {
 typedef enum {
-    IrdaCommonEncoderStateSpace,
+    IrdaCommonEncoderStateSilence,
     IrdaCommonEncoderStatePreamble,
     IrdaCommonEncoderStatePreamble,
     IrdaCommonEncoderStateEncode,
     IrdaCommonEncoderStateEncode,
     IrdaCommonEncoderStateEncodeRepeat,
     IrdaCommonEncoderStateEncodeRepeat,
@@ -44,13 +42,13 @@ typedef enum {
 
 
 struct IrdaCommonDecoder {
 struct IrdaCommonDecoder {
     const IrdaCommonProtocolSpec* protocol;
     const IrdaCommonProtocolSpec* protocol;
-    IrdaCommonStateDecoder state;
-    IrdaMessage message;
+    void* context;
     uint32_t timings[6];
     uint32_t timings[6];
+    IrdaMessage message;
+    IrdaCommonStateDecoder state;
     uint8_t timings_cnt;
     uint8_t timings_cnt;
-    void* context;
     bool switch_detect;
     bool switch_detect;
-    uint32_t level;
+    bool level;
     uint16_t databit_cnt;
     uint16_t databit_cnt;
     uint8_t data[];
     uint8_t data[];
 };
 };
@@ -60,30 +58,23 @@ struct IrdaCommonEncoder {
     IrdaCommonStateEncoder state;
     IrdaCommonStateEncoder state;
     bool switch_detect;
     bool switch_detect;
     uint32_t bits_encoded;
     uint32_t bits_encoded;
+    uint32_t timings_sum;
     uint32_t timings_encoded;
     uint32_t timings_encoded;
     void* context;
     void* context;
     uint8_t data[];
     uint8_t data[];
 };
 };
 
 
-
-static inline void shift_left_array(uint32_t *array, uint32_t len, uint32_t shift) {
-    for (int i = 0; i < len; ++i)
-        array[i] = array[i + shift];
-}
-
-
 IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
 IrdaMessage* irda_common_decode(IrdaCommonDecoder *decoder, bool level, uint32_t duration);
-IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder);
+IrdaStatus irda_common_decode_pdm(IrdaCommonDecoder* decoder);
+IrdaStatus irda_common_decode_pwm(IrdaCommonDecoder* decoder);
 IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder);
 IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder);
-void irda_common_decoder_set_context(void* decoder, void* context);
 void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec *protocol);
 void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec *protocol);
-void irda_common_decoder_free(void* decoder);
-void irda_common_decoder_reset(void* decoder);
+void irda_common_decoder_free(IrdaCommonDecoder* decoder);
+void irda_common_decoder_reset(IrdaCommonDecoder* decoder);
 
 
 IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
 IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
 IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
 IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
 IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
 IrdaStatus irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity);
-void irda_common_encoder_set_context(void* decoder, void* context);
 void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol);
 void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol);
 void irda_common_encoder_free(IrdaCommonEncoder* encoder);
 void irda_common_encoder_free(IrdaCommonEncoder* encoder);
 void irda_common_encoder_reset(IrdaCommonEncoder* encoder);
 void irda_common_encoder_reset(IrdaCommonEncoder* encoder);

+ 31 - 8
lib/irda/encoder_decoder/common/irda_common_protocol_defs.c

@@ -3,8 +3,8 @@
 
 
 const IrdaCommonProtocolSpec protocol_nec = {
 const IrdaCommonProtocolSpec protocol_nec = {
     .timings = {
     .timings = {
-        .preamble_mark = IRDA_NEC_PREAMBULE_MARK,
-        .preamble_space = IRDA_NEC_PREAMBULE_SPACE,
+        .preamble_mark = IRDA_NEC_PREAMBLE_MARK,
+        .preamble_space = IRDA_NEC_PREAMBLE_SPACE,
         .bit1_mark = IRDA_NEC_BIT1_MARK,
         .bit1_mark = IRDA_NEC_BIT1_MARK,
         .bit1_space = IRDA_NEC_BIT1_SPACE,
         .bit1_space = IRDA_NEC_BIT1_SPACE,
         .bit0_mark = IRDA_NEC_BIT0_MARK,
         .bit0_mark = IRDA_NEC_BIT0_MARK,
@@ -14,7 +14,8 @@ const IrdaCommonProtocolSpec protocol_nec = {
         .silence_time = IRDA_NEC_SILENCE,
         .silence_time = IRDA_NEC_SILENCE,
     },
     },
     .databit_len = 32,
     .databit_len = 32,
-    .decode = irda_common_decode_pdwm,
+    .no_stop_bit = false,
+    .decode = irda_common_decode_pdm,
     .encode = irda_common_encode_pdwm,
     .encode = irda_common_encode_pdwm,
     .interpret = irda_decoder_nec_interpret,
     .interpret = irda_decoder_nec_interpret,
     .decode_repeat = irda_decoder_nec_decode_repeat,
     .decode_repeat = irda_decoder_nec_decode_repeat,
@@ -23,8 +24,8 @@ const IrdaCommonProtocolSpec protocol_nec = {
 
 
 const IrdaCommonProtocolSpec protocol_samsung32 = {
 const IrdaCommonProtocolSpec protocol_samsung32 = {
     .timings = {
     .timings = {
-        .preamble_mark = IRDA_SAMSUNG_PREAMBULE_MARK,
-        .preamble_space = IRDA_SAMSUNG_PREAMBULE_SPACE,
+        .preamble_mark = IRDA_SAMSUNG_PREAMBLE_MARK,
+        .preamble_space = IRDA_SAMSUNG_PREAMBLE_SPACE,
         .bit1_mark = IRDA_SAMSUNG_BIT1_MARK,
         .bit1_mark = IRDA_SAMSUNG_BIT1_MARK,
         .bit1_space = IRDA_SAMSUNG_BIT1_SPACE,
         .bit1_space = IRDA_SAMSUNG_BIT1_SPACE,
         .bit0_mark = IRDA_SAMSUNG_BIT0_MARK,
         .bit0_mark = IRDA_SAMSUNG_BIT0_MARK,
@@ -34,7 +35,8 @@ const IrdaCommonProtocolSpec protocol_samsung32 = {
         .silence_time = IRDA_SAMSUNG_SILENCE,
         .silence_time = IRDA_SAMSUNG_SILENCE,
     },
     },
     .databit_len = 32,
     .databit_len = 32,
-    .decode = irda_common_decode_pdwm,
+    .no_stop_bit = false,
+    .decode = irda_common_decode_pdm,
     .encode = irda_common_encode_pdwm,
     .encode = irda_common_encode_pdwm,
     .interpret = irda_decoder_samsung32_interpret,
     .interpret = irda_decoder_samsung32_interpret,
     .decode_repeat = irda_decoder_samsung32_decode_repeat,
     .decode_repeat = irda_decoder_samsung32_decode_repeat,
@@ -43,8 +45,8 @@ const IrdaCommonProtocolSpec protocol_samsung32 = {
 
 
 const IrdaCommonProtocolSpec protocol_rc6 = {
 const IrdaCommonProtocolSpec protocol_rc6 = {
     .timings = {
     .timings = {
-        .preamble_mark = IRDA_RC6_PREAMBULE_MARK,
-        .preamble_space = IRDA_RC6_PREAMBULE_SPACE,
+        .preamble_mark = IRDA_RC6_PREAMBLE_MARK,
+        .preamble_space = IRDA_RC6_PREAMBLE_SPACE,
         .bit1_mark = IRDA_RC6_BIT,
         .bit1_mark = IRDA_RC6_BIT,
         .preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE,
         .preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE,
         .bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
         .bit_tolerance = IRDA_RC6_BIT_TOLERANCE,
@@ -77,3 +79,24 @@ const IrdaCommonProtocolSpec protocol_rc5 = {
     .encode_repeat = NULL,
     .encode_repeat = NULL,
 };
 };
 
 
+const IrdaCommonProtocolSpec protocol_sirc = {
+    .timings = {
+        .preamble_mark = IRDA_SIRC_PREAMBLE_MARK,
+        .preamble_space = IRDA_SIRC_PREAMBLE_SPACE,
+        .bit1_mark = IRDA_SIRC_BIT1_MARK,
+        .bit1_space = IRDA_SIRC_BIT1_SPACE,
+        .bit0_mark = IRDA_SIRC_BIT0_MARK,
+        .bit0_space = IRDA_SIRC_BIT0_SPACE,
+        .preamble_tolerance = IRDA_SIRC_PREAMBLE_TOLERANCE,
+        .bit_tolerance = IRDA_SIRC_BIT_TOLERANCE,
+        .silence_time = IRDA_SIRC_SILENCE,
+    },
+    .databit_len = 20,  /* 12/15/20 */
+    .no_stop_bit = true,
+    .decode = irda_common_decode_pwm,
+    .encode = irda_common_encode_pdwm,
+    .interpret = irda_decoder_sirc_interpret,
+    .decode_repeat = NULL,
+    .encode_repeat = irda_encoder_sirc_encode_repeat,
+};
+

+ 54 - 15
lib/irda/encoder_decoder/irda.c

@@ -12,14 +12,15 @@
 typedef struct {
 typedef struct {
     IrdaAlloc alloc;
     IrdaAlloc alloc;
     IrdaDecode decode;
     IrdaDecode decode;
-    IrdaReset reset;
+    IrdaDecoderReset reset;
     IrdaFree free;
     IrdaFree free;
+    IrdaDecoderCheckReady check_ready;
 } IrdaDecoders;
 } IrdaDecoders;
 
 
 typedef struct {
 typedef struct {
-    IrdaEncoderReset reset;
     IrdaAlloc alloc;
     IrdaAlloc alloc;
     IrdaEncode encode;
     IrdaEncode encode;
+    IrdaEncoderReset reset;
     IrdaFree free;
     IrdaFree free;
 } IrdaEncoders;
 } IrdaEncoders;
 
 
@@ -39,19 +40,6 @@ typedef struct {
 } IrdaEncoderDecoder;
 } IrdaEncoderDecoder;
 
 
 static const IrdaEncoderDecoder irda_encoder_decoder[] = {
 static const IrdaEncoderDecoder irda_encoder_decoder[] = {
-    {
-      .decoder = {
-          .alloc = irda_decoder_rc5_alloc,
-          .decode = irda_decoder_rc5_decode,
-          .reset = irda_decoder_rc5_reset,
-          .free = irda_decoder_rc5_free},
-      .encoder = {
-          .alloc = irda_encoder_rc5_alloc,
-          .encode = irda_encoder_rc5_encode,
-          .reset = irda_encoder_rc5_reset,
-          .free = irda_encoder_rc5_free},
-      .get_protocol_spec = irda_rc5_get_spec,
-    },
     {
     {
       .decoder = {
       .decoder = {
           .alloc = irda_decoder_nec_alloc,
           .alloc = irda_decoder_nec_alloc,
@@ -78,6 +66,19 @@ static const IrdaEncoderDecoder irda_encoder_decoder[] = {
           .free = irda_encoder_samsung32_free},
           .free = irda_encoder_samsung32_free},
       .get_protocol_spec = irda_samsung32_get_spec,
       .get_protocol_spec = irda_samsung32_get_spec,
     },
     },
+    {
+      .decoder = {
+          .alloc = irda_decoder_rc5_alloc,
+          .decode = irda_decoder_rc5_decode,
+          .reset = irda_decoder_rc5_reset,
+          .free = irda_decoder_rc5_free},
+      .encoder = {
+          .alloc = irda_encoder_rc5_alloc,
+          .encode = irda_encoder_rc5_encode,
+          .reset = irda_encoder_rc5_reset,
+          .free = irda_encoder_rc5_free},
+      .get_protocol_spec = irda_rc5_get_spec,
+    },
     {
     {
       .decoder = {
       .decoder = {
           .alloc = irda_decoder_rc6_alloc,
           .alloc = irda_decoder_rc6_alloc,
@@ -91,8 +92,26 @@ static const IrdaEncoderDecoder irda_encoder_decoder[] = {
           .free = irda_encoder_rc6_free},
           .free = irda_encoder_rc6_free},
       .get_protocol_spec = irda_rc6_get_spec,
       .get_protocol_spec = irda_rc6_get_spec,
     },
     },
+    {
+      .decoder = {
+          .alloc = irda_decoder_sirc_alloc,
+          .decode = irda_decoder_sirc_decode,
+          .reset = irda_decoder_sirc_reset,
+          .check_ready = irda_decoder_sirc_check_ready,
+          .free = irda_decoder_sirc_free},
+      .encoder = {
+          .alloc = irda_encoder_sirc_alloc,
+          .encode = irda_encoder_sirc_encode,
+          .reset = irda_encoder_sirc_reset,
+          .free = irda_encoder_sirc_free},
+      .get_protocol_spec = irda_sirc_get_spec,
+    },
 };
 };
 
 
+
+static int irda_find_index_by_protocol(IrdaProtocol protocol);
+static const IrdaProtocolSpecification* irda_get_spec_by_protocol(IrdaProtocol protocol);
+
 const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration) {
 const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration) {
     furi_assert(handler);
     furi_assert(handler);
 
 
@@ -121,6 +140,7 @@ IrdaDecoderHandler* irda_alloc_decoder(void) {
             handler->ctx[i] = irda_encoder_decoder[i].decoder.alloc();
             handler->ctx[i] = irda_encoder_decoder[i].decoder.alloc();
     }
     }
 
 
+    irda_reset_decoder(handler);
     return handler;
     return handler;
 }
 }
 
 
@@ -144,6 +164,25 @@ void irda_reset_decoder(IrdaDecoderHandler* handler) {
     }
     }
 }
 }
 
 
+const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler) {
+    furi_assert(handler);
+
+    IrdaMessage* message = NULL;
+    IrdaMessage* result = NULL;
+
+    for (int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) {
+        if (irda_encoder_decoder[i].decoder.check_ready) {
+            message = irda_encoder_decoder[i].decoder.check_ready(handler->ctx[i]);
+            if (!result && message) {
+                result = message;
+            }
+        }
+    }
+
+    return result;
+}
+
+
 IrdaEncoderHandler* irda_alloc_encoder(void) {
 IrdaEncoderHandler* irda_alloc_encoder(void) {
     IrdaEncoderHandler* handler = furi_alloc(sizeof(IrdaEncoderHandler));
     IrdaEncoderHandler* handler = furi_alloc(sizeof(IrdaEncoderHandler));
     handler->handler = NULL;
     handler->handler = NULL;

+ 23 - 5
lib/irda/encoder_decoder/irda.h

@@ -15,11 +15,9 @@ extern "C" {
 #define IRDA_RAW_RX_TIMING_DELAY_US        150000
 #define IRDA_RAW_RX_TIMING_DELAY_US        150000
 #define IRDA_RAW_TX_TIMING_DELAY_US        180000
 #define IRDA_RAW_TX_TIMING_DELAY_US        180000
 
 
-
 typedef struct IrdaDecoderHandler IrdaDecoderHandler;
 typedef struct IrdaDecoderHandler IrdaDecoderHandler;
 typedef struct IrdaEncoderHandler IrdaEncoderHandler;
 typedef struct IrdaEncoderHandler IrdaEncoderHandler;
 
 
-// Do not change protocol order, as it can be saved into memory and fw update can be performed!
 typedef enum {
 typedef enum {
     IrdaProtocolUnknown = -1,
     IrdaProtocolUnknown = -1,
     IrdaProtocolNEC = 0,
     IrdaProtocolNEC = 0,
@@ -28,6 +26,9 @@ typedef enum {
     IrdaProtocolRC6 = 3,
     IrdaProtocolRC6 = 3,
     IrdaProtocolRC5 = 4,
     IrdaProtocolRC5 = 4,
     IrdaProtocolRC5X = 5,
     IrdaProtocolRC5X = 5,
+    IrdaProtocolSIRC = 6,
+    IrdaProtocolSIRC15 = 7,
+    IrdaProtocolSIRC20 = 8,
     IrdaProtocolMAX,
     IrdaProtocolMAX,
 } IrdaProtocol;
 } IrdaProtocol;
 
 
@@ -62,10 +63,27 @@ IrdaDecoderHandler* irda_alloc_decoder(void);
  * \param[in]   duration    - duration of steady high/low input signal.
  * \param[in]   duration    - duration of steady high/low input signal.
  * \return      if message is ready, returns pointer to decoded message, returns NULL.
  * \return      if message is ready, returns pointer to decoded message, returns NULL.
  *              Note: ownership of returned ptr belongs to handler. So pointer is valid
  *              Note: ownership of returned ptr belongs to handler. So pointer is valid
- *              up to next irda_free_decoder(), irda_reset_decoder(), irda_decode() calls.
+ *              up to next irda_free_decoder(), irda_reset_decoder(),
+ *              irda_decode(), irda_check_decoder_ready() calls.
  */
  */
 const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration);
 const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration);
 
 
+/**
+ * Check whether decoder is ready.
+ * Functionality is quite similar to irda_decode(), but with no timing providing.
+ * Some protocols (e.g. Sony SIRC) has variable payload length, which means we
+ * can't recognize end of message right after receiving last bit. That's why
+ * application should call to irda_check_decoder_ready() after some timeout to
+ * retrieve decoded message, if so.
+ *
+ * \param[in]   handler     - handler to IRDA decoders. Should be acquired with \c irda_alloc_decoder().
+ * \return      if message is ready, returns pointer to decoded message, returns NULL.
+ *              Note: ownership of returned ptr belongs to handler. So pointer is valid
+ *              up to next irda_free_decoder(), irda_reset_decoder(),
+ *              irda_decode(), irda_check_decoder_ready() calls.
+ */
+const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler);
+
 /**
 /**
  * Deinitialize decoder and free allocated memory.
  * Deinitialize decoder and free allocated memory.
  *
  *
@@ -100,7 +118,7 @@ IrdaProtocol irda_get_protocol_by_name(const char* protocol_name);
  * Get address length by protocol enum.
  * Get address length by protocol enum.
  *
  *
  * \param[in]   protocol    - protocol identifier.
  * \param[in]   protocol    - protocol identifier.
- * \return      length of address in nibbles.
+ * \return      length of address in bits.
  */
  */
 uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
 uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
 
 
@@ -108,7 +126,7 @@ uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
  * Get command length by protocol enum.
  * Get command length by protocol enum.
  *
  *
  * \param[in]   protocol    - protocol identifier.
  * \param[in]   protocol    - protocol identifier.
- * \return      length of command in nibbles.
+ * \return      length of command in bits.
  */
  */
 uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
 uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
 
 

+ 6 - 3
lib/irda/encoder_decoder/irda_i.h

@@ -1,6 +1,7 @@
 #pragma once
 #pragma once
 #include "irda.h"
 #include "irda.h"
 #include <stddef.h>
 #include <stddef.h>
+#include <stdint.h>
 
 
 typedef struct {
 typedef struct {
     uint32_t silence_time;
     uint32_t silence_time;
@@ -10,7 +11,7 @@ typedef struct {
     uint16_t bit1_space;
     uint16_t bit1_space;
     uint16_t bit0_mark;
     uint16_t bit0_mark;
     uint16_t bit0_space;
     uint16_t bit0_space;
-    float    preamble_tolerance;
+    uint32_t preamble_tolerance;
     uint32_t bit_tolerance;
     uint32_t bit_tolerance;
 } IrdaTimings;
 } IrdaTimings;
 
 
@@ -25,10 +26,12 @@ typedef struct {
 typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec) (IrdaProtocol protocol);
 typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec) (IrdaProtocol protocol);
 
 
 typedef void* (*IrdaAlloc) (void);
 typedef void* (*IrdaAlloc) (void);
-typedef IrdaMessage* (*IrdaDecode) (void* ctx, bool level, uint32_t duration);
-typedef void (*IrdaReset) (void*);
 typedef void (*IrdaFree) (void*);
 typedef void (*IrdaFree) (void*);
 
 
+typedef void (*IrdaDecoderReset) (void*);
+typedef IrdaMessage* (*IrdaDecode) (void* ctx, bool level, uint32_t duration);
+typedef IrdaMessage* (*IrdaDecoderCheckReady) (void*);
+
 typedef void (*IrdaEncoderReset)(void* encoder, const IrdaMessage* message);
 typedef void (*IrdaEncoderReset)(void* encoder, const IrdaMessage* message);
 typedef IrdaStatus (*IrdaEncode)(void* encoder, uint32_t* out, bool* polarity);
 typedef IrdaStatus (*IrdaEncode)(void* encoder, uint32_t* out, bool* polarity);
 
 

+ 71 - 19
lib/irda/encoder_decoder/irda_protocol_defs_i.h

@@ -11,29 +11,28 @@
 *   https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1
 *   https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1
 ****************************************************************************************************
 ****************************************************************************************************
 *     Preamble   Preamble      Pulse Distance/Width          Pause       Preamble   Preamble  Stop
 *     Preamble   Preamble      Pulse Distance/Width          Pause       Preamble   Preamble  Stop
-*       mark      space            Modulation                             repeat     repeat    bit
+*       mark      space            Modulation             up to period    repeat     repeat    bit
 *                                                                          mark       space
 *                                                                          mark       space
 *
 *
-*        9000      4500         32 bit + stop bit         40000/100000     9000       2250
+*        9000      4500         32 bit + stop bit         ...110000         9000       2250
 *     __________          _ _ _ _  _  _  _ _ _  _  _ _ _                ___________            _
 *     __________          _ _ _ _  _  _  _ _ _  _  _ _ _                ___________            _
 * ____          __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________           ____________ ___
 * ____          __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________           ____________ ___
 *
 *
 ***************************************************************************************************/
 ***************************************************************************************************/
 
 
-#define IRDA_NEC_PREAMBULE_MARK         9000
-#define IRDA_NEC_PREAMBULE_SPACE        4500
+#define IRDA_NEC_PREAMBLE_MARK          9000
+#define IRDA_NEC_PREAMBLE_SPACE         4500
 #define IRDA_NEC_BIT1_MARK              560
 #define IRDA_NEC_BIT1_MARK              560
 #define IRDA_NEC_BIT1_SPACE             1600
 #define IRDA_NEC_BIT1_SPACE             1600
 #define IRDA_NEC_BIT0_MARK              560
 #define IRDA_NEC_BIT0_MARK              560
 #define IRDA_NEC_BIT0_SPACE             560
 #define IRDA_NEC_BIT0_SPACE             560
+#define IRDA_NEC_REPEAT_PERIOD          110000
+#define IRDA_NEC_SILENCE                IRDA_NEC_REPEAT_PERIOD
 #define IRDA_NEC_REPEAT_PAUSE_MIN       30000
 #define IRDA_NEC_REPEAT_PAUSE_MIN       30000
-#define IRDA_NEC_REPEAT_PAUSE1          46000
-#define IRDA_NEC_REPEAT_PAUSE2          97000
-#define IRDA_NEC_SILENCE                IRDA_NEC_REPEAT_PAUSE2
 #define IRDA_NEC_REPEAT_PAUSE_MAX       150000
 #define IRDA_NEC_REPEAT_PAUSE_MAX       150000
 #define IRDA_NEC_REPEAT_MARK            9000
 #define IRDA_NEC_REPEAT_MARK            9000
 #define IRDA_NEC_REPEAT_SPACE           2250
 #define IRDA_NEC_REPEAT_SPACE           2250
-#define IRDA_NEC_PREAMBLE_TOLERANCE     0.07    // percents
+#define IRDA_NEC_PREAMBLE_TOLERANCE     200     // us
 #define IRDA_NEC_BIT_TOLERANCE          120     // us
 #define IRDA_NEC_BIT_TOLERANCE          120     // us
 
 
 void* irda_decoder_nec_alloc(void);
 void* irda_decoder_nec_alloc(void);
@@ -66,8 +65,8 @@ extern const IrdaCommonProtocolSpec protocol_nec;
 *
 *
 ***************************************************************************************************/
 ***************************************************************************************************/
 
 
-#define IRDA_SAMSUNG_PREAMBULE_MARK         4500
-#define IRDA_SAMSUNG_PREAMBULE_SPACE        4500
+#define IRDA_SAMSUNG_PREAMBLE_MARK          4500
+#define IRDA_SAMSUNG_PREAMBLE_SPACE         4500
 #define IRDA_SAMSUNG_BIT1_MARK              550
 #define IRDA_SAMSUNG_BIT1_MARK              550
 #define IRDA_SAMSUNG_BIT1_SPACE             1650
 #define IRDA_SAMSUNG_BIT1_SPACE             1650
 #define IRDA_SAMSUNG_BIT0_MARK              550
 #define IRDA_SAMSUNG_BIT0_MARK              550
@@ -84,7 +83,7 @@ extern const IrdaCommonProtocolSpec protocol_nec;
 #define IRDA_SAMSUNG_REPEAT_PAUSE_MAX       140000
 #define IRDA_SAMSUNG_REPEAT_PAUSE_MAX       140000
 #define IRDA_SAMSUNG_REPEAT_MARK            4500
 #define IRDA_SAMSUNG_REPEAT_MARK            4500
 #define IRDA_SAMSUNG_REPEAT_SPACE           4500
 #define IRDA_SAMSUNG_REPEAT_SPACE           4500
-#define IRDA_SAMSUNG_PREAMBLE_TOLERANCE     0.07    // percents
+#define IRDA_SAMSUNG_PREAMBLE_TOLERANCE     200     // us
 #define IRDA_SAMSUNG_BIT_TOLERANCE          120     // us
 #define IRDA_SAMSUNG_BIT_TOLERANCE          120     // us
 
 
 void* irda_decoder_samsung32_alloc(void);
 void* irda_decoder_samsung32_alloc(void);
@@ -127,10 +126,10 @@ extern const IrdaCommonProtocolSpec protocol_samsung32;
 #define IRDA_RC6_CARRIER_FREQUENCY          36000
 #define IRDA_RC6_CARRIER_FREQUENCY          36000
 #define IRDA_RC6_DUTY_CYCLE                 0.33
 #define IRDA_RC6_DUTY_CYCLE                 0.33
 
 
-#define IRDA_RC6_PREAMBULE_MARK             2666
-#define IRDA_RC6_PREAMBULE_SPACE            889
+#define IRDA_RC6_PREAMBLE_MARK              2666
+#define IRDA_RC6_PREAMBLE_SPACE             889
 #define IRDA_RC6_BIT                        444     // half of time-quant for 1 bit
 #define IRDA_RC6_BIT                        444     // half of time-quant for 1 bit
-#define IRDA_RC6_PREAMBLE_TOLERANCE         0.07    // percents
+#define IRDA_RC6_PREAMBLE_TOLERANCE         200     // us
 #define IRDA_RC6_BIT_TOLERANCE              120     // us
 #define IRDA_RC6_BIT_TOLERANCE              120     // us
 /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
 /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
 #define IRDA_RC6_SILENCE                    (2700 * 10)
 #define IRDA_RC6_SILENCE                    (2700 * 10)
@@ -169,17 +168,17 @@ extern const IrdaCommonProtocolSpec protocol_rc6;
 *    s - start bit (always 1)
 *    s - start bit (always 1)
 *    si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0)
 *    si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0)
 *    T - toggle bit, change it's value every button press
 *    T - toggle bit, change it's value every button press
-*    address - 8 bit
-*    command - 8 bit
+*    address - 5 bit
+*    command - 6/7 bit
 ***************************************************************************************************/
 ***************************************************************************************************/
 
 
 #define IRDA_RC5_CARRIER_FREQUENCY          36000
 #define IRDA_RC5_CARRIER_FREQUENCY          36000
 #define IRDA_RC5_DUTY_CYCLE                 0.33
 #define IRDA_RC5_DUTY_CYCLE                 0.33
 
 
-#define IRDA_RC5_PREAMBULE_MARK             0
-#define IRDA_RC5_PREAMBULE_SPACE            0
+#define IRDA_RC5_PREAMBLE_MARK              0
+#define IRDA_RC5_PREAMBLE_SPACE             0
 #define IRDA_RC5_BIT                        888     // half of time-quant for 1 bit
 #define IRDA_RC5_BIT                        888     // half of time-quant for 1 bit
-#define IRDA_RC5_PREAMBLE_TOLERANCE         0.07    // percents
+#define IRDA_RC5_PREAMBLE_TOLERANCE         200     // us
 #define IRDA_RC5_BIT_TOLERANCE              120     // us
 #define IRDA_RC5_BIT_TOLERANCE              120     // us
 /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
 /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
 #define IRDA_RC5_SILENCE                    (2700 * 10)
 #define IRDA_RC5_SILENCE                    (2700 * 10)
@@ -197,3 +196,56 @@ const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol);
 
 
 extern const IrdaCommonProtocolSpec protocol_rc5;
 extern const IrdaCommonProtocolSpec protocol_rc5;
 
 
+
+/***************************************************************************************************
+*   Sony SIRC protocol description
+*   https://www.sbprojects.net/knowledge/ir/sirc.php
+*   http://picprojects.org.uk/
+****************************************************************************************************
+*      Preamble  Preamble     Pulse Width Modulation           Pause             Entirely repeat
+*        mark     space                                     up to period             message..
+*
+*        2400      600      12/15/20 bits (600,1200)         ...45000          2400      600
+*     __________          _ _ _ _  _  _  _ _ _  _  _ _ _                    __________          _ _
+* ____          __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________          __________ _
+*                        |    command    |   address    |
+*                 SIRC   |     7b LSB    |    5b LSB    |
+*                 SIRC15 |     7b LSB    |    8b LSB    |
+*                 SIRC20 |     7b LSB    |    13b LSB   |
+*
+* No way to determine either next message is repeat or not,
+* so recognize only fact message received. Sony remotes always send at least 3 messages.
+* Assume 8 last extended bits for SIRC20 are address bits.
+***************************************************************************************************/
+
+#define IRDA_SIRC_CARRIER_FREQUENCY            40000
+#define IRDA_SIRC_DUTY_CYCLE                   0.33
+#define IRDA_SIRC_PREAMBLE_MARK                2400
+#define IRDA_SIRC_PREAMBLE_SPACE               600
+#define IRDA_SIRC_BIT1_MARK                    1200
+#define IRDA_SIRC_BIT1_SPACE                   600
+#define IRDA_SIRC_BIT0_MARK                    600
+#define IRDA_SIRC_BIT0_SPACE                   600
+#define IRDA_SIRC_PREAMBLE_TOLERANCE           200     // us
+#define IRDA_SIRC_BIT_TOLERANCE                120     // us
+#define IRDA_SIRC_SILENCE                      10000
+#define IRDA_SIRC_MIN_SILENCE                  (IRDA_SIRC_SILENCE - 1000)
+#define IRDA_SIRC_REPEAT_PERIOD                45000
+
+
+void* irda_decoder_sirc_alloc(void);
+void irda_decoder_sirc_reset(void* decoder);
+IrdaMessage* irda_decoder_sirc_check_ready(void* decoder);
+uint32_t irda_decoder_sirc_get_timeout(void* decoder);
+void irda_decoder_sirc_free(void* decoder);
+IrdaMessage* irda_decoder_sirc_decode(void* decoder, bool level, uint32_t duration);
+void* irda_encoder_sirc_alloc(void);
+void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message);
+void irda_encoder_sirc_free(void* decoder);
+IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
+bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder);
+const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol);
+IrdaStatus irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level);
+
+extern const IrdaCommonProtocolSpec protocol_sirc;
+

+ 3 - 3
lib/irda/encoder_decoder/nec/irda_decoder_nec.c

@@ -43,9 +43,9 @@ IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder) {
 
 
     if((decoder->timings[0] > IRDA_NEC_REPEAT_PAUSE_MIN) &&
     if((decoder->timings[0] > IRDA_NEC_REPEAT_PAUSE_MIN) &&
        (decoder->timings[0] < IRDA_NEC_REPEAT_PAUSE_MAX) &&
        (decoder->timings[0] < IRDA_NEC_REPEAT_PAUSE_MAX) &&
-       MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_NEC_REPEAT_MARK, preamble_tolerance) &&
-       MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_NEC_REPEAT_SPACE, preamble_tolerance) &&
-       MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
+       MATCH_TIMING(decoder->timings[1], IRDA_NEC_REPEAT_MARK, preamble_tolerance) &&
+       MATCH_TIMING(decoder->timings[2], IRDA_NEC_REPEAT_SPACE, preamble_tolerance) &&
+       MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
         status = IrdaStatusReady;
         status = IrdaStatusReady;
         decoder->timings_cnt = 0;
         decoder->timings_cnt = 0;
     } else {
     } else {

+ 5 - 4
lib/irda/encoder_decoder/nec/irda_encoder_nec.c

@@ -7,7 +7,7 @@
 #include <furi.h>
 #include <furi.h>
 
 
 static const uint32_t repeat_timings[] = {
 static const uint32_t repeat_timings[] = {
-    IRDA_NEC_REPEAT_PAUSE2,
+    IRDA_NEC_REPEAT_PERIOD - IRDA_NEC_REPEAT_MARK - IRDA_NEC_REPEAT_SPACE - IRDA_NEC_BIT1_MARK,
     IRDA_NEC_REPEAT_MARK,
     IRDA_NEC_REPEAT_MARK,
     IRDA_NEC_REPEAT_SPACE,
     IRDA_NEC_REPEAT_SPACE,
     IRDA_NEC_BIT1_MARK,
     IRDA_NEC_BIT1_MARK,
@@ -44,10 +44,11 @@ IrdaStatus irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t*
 
 
     furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
     furi_assert(encoder->timings_encoded >= timings_encoded_up_to_repeat);
 
 
-    if (repeat_cnt > 0)
+    if (repeat_cnt > 0) {
         *duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
         *duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)];
-    else
-        *duration = IRDA_NEC_REPEAT_PAUSE1;
+    } else {
+        *duration = IRDA_NEC_REPEAT_PERIOD - encoder->timings_sum;
+    }
 
 
     *level = repeat_cnt % 2;
     *level = repeat_cnt % 2;
     ++encoder->timings_encoded;
     ++encoder->timings_encoded;

+ 4 - 4
lib/irda/encoder_decoder/nec/irda_nec_spec.c

@@ -3,16 +3,16 @@
 
 
 static const IrdaProtocolSpecification irda_nec_protocol_specification = {
 static const IrdaProtocolSpecification irda_nec_protocol_specification = {
       .name = "NEC",
       .name = "NEC",
-      .address_length = 2,
-      .command_length = 2,
+      .address_length = 8,
+      .command_length = 8,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
 };
 };
 
 
 static const IrdaProtocolSpecification irda_necext_protocol_specification = {
 static const IrdaProtocolSpecification irda_necext_protocol_specification = {
       .name = "NECext",
       .name = "NECext",
-      .address_length = 4,
-      .command_length = 2,
+      .address_length = 16,
+      .command_length = 8,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
 };
 };

+ 1 - 1
lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c

@@ -57,7 +57,7 @@ void* irda_decoder_rc5_alloc(void) {
     IrdaRc5Decoder* decoder = furi_alloc(sizeof(IrdaRc5Decoder));
     IrdaRc5Decoder* decoder = furi_alloc(sizeof(IrdaRc5Decoder));
     decoder->toggle = false;
     decoder->toggle = false;
     decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc5);
     decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc5);
-    irda_common_decoder_set_context(decoder->common_decoder, decoder);
+    decoder->common_decoder->context = decoder;
     return decoder;
     return decoder;
 }
 }
 
 

+ 4 - 4
lib/irda/encoder_decoder/rc5/irda_rc5_spec.c

@@ -3,16 +3,16 @@
 
 
 static const IrdaProtocolSpecification irda_rc5_protocol_specification = {
 static const IrdaProtocolSpecification irda_rc5_protocol_specification = {
       .name = "RC5",
       .name = "RC5",
-      .address_length = 2,
-      .command_length = 2,
+      .address_length = 5,
+      .command_length = 6,
       .frequency = IRDA_RC5_CARRIER_FREQUENCY,
       .frequency = IRDA_RC5_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_RC5_DUTY_CYCLE,
       .duty_cycle = IRDA_RC5_DUTY_CYCLE,
 };
 };
 
 
 static const IrdaProtocolSpecification irda_rc5x_protocol_specification = {
 static const IrdaProtocolSpecification irda_rc5x_protocol_specification = {
       .name = "RC5X",
       .name = "RC5X",
-      .address_length = 2,
-      .command_length = 2,
+      .address_length = 5,
+      .command_length = 7,
       .frequency = IRDA_RC5_CARRIER_FREQUENCY,
       .frequency = IRDA_RC5_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_RC5_DUTY_CYCLE,
       .duty_cycle = IRDA_RC5_DUTY_CYCLE,
 };
 };

+ 4 - 4
lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c

@@ -57,9 +57,9 @@ IrdaStatus irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder) {
     uint16_t tolerance = decoder->protocol->timings.bit_tolerance;
     uint16_t tolerance = decoder->protocol->timings.bit_tolerance;
     uint16_t timing = decoder->timings[0];
     uint16_t timing = decoder->timings[0];
 
 
-    bool single_timing = MATCH_BIT_TIMING(timing, bit, tolerance);
-    bool double_timing = MATCH_BIT_TIMING(timing, 2*bit, tolerance);
-    bool triple_timing = MATCH_BIT_TIMING(timing, 3*bit, tolerance);
+    bool single_timing = MATCH_TIMING(timing, bit, tolerance);
+    bool double_timing = MATCH_TIMING(timing, 2*bit, tolerance);
+    bool triple_timing = MATCH_TIMING(timing, 3*bit, tolerance);
 
 
     if (decoder->databit_cnt == 4) {
     if (decoder->databit_cnt == 4) {
         furi_assert(decoder->timings_cnt == 1);
         furi_assert(decoder->timings_cnt == 1);
@@ -92,7 +92,7 @@ void* irda_decoder_rc6_alloc(void) {
     IrdaRc6Decoder* decoder = furi_alloc(sizeof(IrdaRc6Decoder));
     IrdaRc6Decoder* decoder = furi_alloc(sizeof(IrdaRc6Decoder));
     decoder->toggle = false;
     decoder->toggle = false;
     decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc6);
     decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc6);
-    irda_common_decoder_set_context(decoder->common_decoder, decoder);
+    decoder->common_decoder->context = decoder;
     return decoder;
     return decoder;
 }
 }
 
 

+ 2 - 2
lib/irda/encoder_decoder/rc6/irda_rc6_spec.c

@@ -3,8 +3,8 @@
 
 
 static const IrdaProtocolSpecification irda_rc6_protocol_specification = {
 static const IrdaProtocolSpecification irda_rc6_protocol_specification = {
       .name = "RC6",
       .name = "RC6",
-      .address_length = 2,
-      .command_length = 2,
+      .address_length = 8,
+      .command_length = 8,
       .frequency = IRDA_RC6_CARRIER_FREQUENCY,
       .frequency = IRDA_RC6_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_RC6_DUTY_CYCLE,
       .duty_cycle = IRDA_RC6_DUTY_CYCLE,
 };
 };

+ 5 - 5
lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c

@@ -39,11 +39,11 @@ IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder) {
 
 
     if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
     if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
         && (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
         && (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
-        && MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
-        && MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
-        && MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
-        && MATCH_BIT_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
-        && MATCH_BIT_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
+        && MATCH_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
+        && MATCH_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
+        && MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
+        && MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
+        && MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
         ) {
         ) {
         status = IrdaStatusReady;
         status = IrdaStatusReady;
         decoder->timings_cnt = 0;
         decoder->timings_cnt = 0;

+ 2 - 2
lib/irda/encoder_decoder/samsung/irda_samsung_spec.c

@@ -3,8 +3,8 @@
 
 
 static const IrdaProtocolSpecification irda_samsung32_protocol_specification = {
 static const IrdaProtocolSpecification irda_samsung32_protocol_specification = {
       .name = "Samsung32",
       .name = "Samsung32",
-      .address_length = 2,
-      .command_length = 2,
+      .address_length = 8,
+      .command_length = 8,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .frequency = IRDA_COMMON_CARRIER_FREQUENCY,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
       .duty_cycle = IRDA_COMMON_DUTY_CYCLE,
 };
 };

+ 92 - 0
lib/irda/encoder_decoder/sirc/irda_decoder_sirc.c

@@ -0,0 +1,92 @@
+#include "common/irda_common_i.h"
+#include "irda.h"
+#include "irda_protocol_defs_i.h"
+#include <stdbool.h>
+#include <stdint.h>
+#include <furi.h>
+#include "../irda_i.h"
+
+
+IrdaMessage* irda_decoder_sirc_check_ready(void* ctx) {
+    IrdaMessage* message = NULL;
+    IrdaCommonDecoder* decoder = ctx;
+
+    if (irda_decoder_sirc_interpret(decoder)) {
+        message = &decoder->message;
+        decoder->timings_cnt = 0;
+        decoder->databit_cnt = 0;
+    }
+
+    return message;
+}
+
+bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder) {
+    furi_assert(decoder);
+
+    uint32_t* data = (void*) &decoder->data[0];
+    uint16_t address = 0;
+    uint8_t command = 0;
+    IrdaProtocol protocol = IrdaProtocolUnknown;
+
+    if (decoder->databit_cnt == 12) {
+        address = (*data >> 7)  & 0x1F;
+        command = *data & 0x7F;
+        protocol = IrdaProtocolSIRC;
+    } else if (decoder->databit_cnt == 15) {
+        address = (*data >> 7)  & 0xFF;
+        command = *data & 0x7F;
+        protocol = IrdaProtocolSIRC15;
+    } else if (decoder->databit_cnt == 20) {
+        address = (*data >> 7)  & 0x1FFF;
+        command = *data & 0x7F;
+        protocol = IrdaProtocolSIRC20;
+    } else {
+        return false;
+    }
+
+    decoder->message.protocol = protocol;
+    decoder->message.address = address;
+    decoder->message.command = command;
+    /* SIRC doesn't specify repeat detection */
+    decoder->message.repeat = false;
+
+    return true;
+}
+
+void* irda_decoder_sirc_alloc(void) {
+    return irda_common_decoder_alloc(&protocol_sirc);
+}
+
+IrdaMessage* irda_decoder_sirc_decode(void* context, bool level, uint32_t duration) {
+    IrdaCommonDecoder* decoder = context;
+    IrdaMessage* message = NULL;
+
+    if ((decoder->databit_cnt == 12) || (decoder->databit_cnt == 15)) {
+        if (!level && (duration >= IRDA_SIRC_MIN_SILENCE)) {
+            if (irda_decoder_sirc_interpret(decoder)) {
+                message = &decoder->message;
+                decoder->timings_cnt = 0;
+                decoder->databit_cnt = 0;
+            }
+        }
+    }
+
+    if (!message) {
+        message = irda_common_decode(decoder, level, duration);
+        if (message) {  /* 20 bit */
+            decoder->timings_cnt = 0;
+            decoder->databit_cnt = 0;
+        }
+    }
+
+    return message;
+}
+
+void irda_decoder_sirc_free(void* decoder) {
+    irda_common_decoder_free(decoder);
+}
+
+void irda_decoder_sirc_reset(void* decoder) {
+    irda_common_decoder_reset(decoder);
+}
+

+ 89 - 0
lib/irda/encoder_decoder/sirc/irda_encoder_sirc.c

@@ -0,0 +1,89 @@
+#include "furi/check.h"
+#include "irda.h"
+#include "common/irda_common_i.h"
+#include <stdint.h>
+#include "../irda_i.h"
+#include "irda_protocol_defs_i.h"
+#include <furi.h>
+
+
+typedef struct {
+    IrdaCommonEncoder* common_encoder;
+    uint8_t databits;
+} IrdaSircEncoder;
+
+
+void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) {
+    furi_assert(encoder_ptr);
+    furi_assert(message);
+
+    IrdaCommonEncoder* encoder = encoder_ptr;
+    IrdaSircEncoder* encoder_sirc = encoder->context;
+    irda_common_encoder_reset(encoder);
+
+    uint32_t* data = (void*) encoder->data;
+
+    if (message->protocol == IrdaProtocolSIRC) {
+        encoder_sirc->databits = 12;
+        *data = (message->command & 0x7F);
+        *data |= (message->address & 0x1F) << 7;
+    } else if (message->protocol == IrdaProtocolSIRC15) {
+        encoder_sirc->databits = 15;
+        *data = (message->command & 0x7F);
+        *data |= (message->address & 0xFF) << 7;
+    } else if (message->protocol == IrdaProtocolSIRC20) {
+        encoder_sirc->databits = 20;
+        *data = (message->command & 0x7F);
+        *data |= (message->address & 0x1FFF) << 7;
+    } else {
+        furi_assert(0);
+    }
+}
+
+IrdaStatus irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) {
+    furi_assert(encoder);
+
+    IrdaSircEncoder* encoder_sirc = encoder->context;
+
+    uint32_t timings_in_message = 1 + 2 + encoder_sirc->databits * 2;
+    furi_assert(encoder->timings_encoded == timings_in_message);
+
+    furi_assert(encoder->timings_sum < IRDA_SIRC_REPEAT_PERIOD);
+    *duration = IRDA_SIRC_REPEAT_PERIOD - encoder->timings_sum;
+    *level = false;
+
+    encoder->timings_sum = 0;
+    encoder->timings_encoded = 1;
+    encoder->bits_encoded = 0;
+    encoder->state = IrdaCommonEncoderStatePreamble;
+
+    return IrdaStatusOk;
+}
+
+void* irda_encoder_sirc_alloc(void) {
+    IrdaCommonEncoder* encoder_common = irda_common_encoder_alloc(&protocol_sirc);
+    IrdaSircEncoder* encoder_sirc = furi_alloc(sizeof(IrdaSircEncoder));
+    encoder_sirc->common_encoder = encoder_common;
+    encoder_common->context = encoder_sirc;
+    return encoder_common;
+}
+
+void irda_encoder_sirc_free(void* encoder_ptr) {
+    IrdaCommonEncoder* encoder = encoder_ptr;
+    free(encoder->context);
+    irda_common_encoder_free(encoder);
+}
+
+IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
+    IrdaCommonEncoder* encoder_common = encoder_ptr;
+    IrdaSircEncoder* encoder_sirc = encoder_common->context;
+
+    IrdaStatus status = irda_common_encode(encoder_ptr, duration, level);
+    if ((status == IrdaStatusOk) && (encoder_common->bits_encoded == encoder_sirc->databits)) {
+        furi_assert(!*level);
+        status = IrdaStatusDone;
+        encoder_common->state = IrdaCommonEncoderStateEncodeRepeat;
+    }
+    return status;
+}
+

+ 38 - 0
lib/irda/encoder_decoder/sirc/irda_sirc_spec.c

@@ -0,0 +1,38 @@
+#include "../irda_i.h"
+#include "irda_protocol_defs_i.h"
+
+static const IrdaProtocolSpecification irda_sirc_protocol_specification = {
+      .name = "SIRC",
+      .address_length = 5,
+      .command_length = 7,
+      .frequency = IRDA_SIRC_CARRIER_FREQUENCY,
+      .duty_cycle = IRDA_SIRC_DUTY_CYCLE,
+};
+
+static const IrdaProtocolSpecification irda_sirc15_protocol_specification = {
+      .name = "SIRC15",
+      .address_length = 8,
+      .command_length = 7,
+      .frequency = IRDA_SIRC_CARRIER_FREQUENCY,
+      .duty_cycle = IRDA_SIRC_DUTY_CYCLE,
+};
+
+static const IrdaProtocolSpecification irda_sirc20_protocol_specification = {
+      .name = "SIRC20",
+      .address_length = 13,
+      .command_length = 7,
+      .frequency = IRDA_SIRC_CARRIER_FREQUENCY,
+      .duty_cycle = IRDA_SIRC_DUTY_CYCLE,
+};
+
+const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol) {
+    if (protocol == IrdaProtocolSIRC)
+        return &irda_sirc_protocol_specification;
+    else if (protocol == IrdaProtocolSIRC15)
+        return &irda_sirc15_protocol_specification;
+    else if (protocol == IrdaProtocolSIRC20)
+        return &irda_sirc20_protocol_specification;
+    else
+        return NULL;
+}
+

+ 10 - 2
lib/irda/worker/irda_worker.c

@@ -118,7 +118,14 @@ static void irda_worker_process_timeout(IrdaWorker* instance) {
     if (instance->signal.timings_cnt < 2)
     if (instance->signal.timings_cnt < 2)
         return;
         return;
 
 
-    instance->signal.decoded = false;
+    const IrdaMessage* message_decoded = irda_check_decoder_ready(instance->irda_decoder);
+    if (message_decoded) {
+        instance->signal.message = *message_decoded;
+        instance->signal.timings_cnt = 0;
+        instance->signal.decoded = true;
+    } else {
+        instance->signal.decoded = false;
+    }
     if (instance->rx.received_signal_callback)
     if (instance->rx.received_signal_callback)
         instance->rx.received_signal_callback(instance->rx.received_signal_context, &instance->signal);
         instance->rx.received_signal_callback(instance->rx.received_signal_context, &instance->signal);
 }
 }
@@ -132,7 +139,7 @@ static void irda_worker_process_timings(IrdaWorker* instance, uint32_t duration,
         if (instance->rx.received_signal_callback)
         if (instance->rx.received_signal_callback)
             instance->rx.received_signal_callback(instance->rx.received_signal_context, &instance->signal);
             instance->rx.received_signal_callback(instance->rx.received_signal_context, &instance->signal);
     } else {
     } else {
-        /* Skip first timing if it's starts from Space */
+        /* Skip first timing if it starts from Space */
         if ((instance->signal.timings_cnt == 0) && !level) {
         if ((instance->signal.timings_cnt == 0) && !level) {
             return;
             return;
         }
         }
@@ -253,6 +260,7 @@ void irda_worker_rx_start(IrdaWorker* instance) {
     furi_hal_irda_async_rx_start();
     furi_hal_irda_async_rx_start();
     furi_hal_irda_async_rx_set_timeout(IRDA_WORKER_RX_TIMEOUT);
     furi_hal_irda_async_rx_set_timeout(IRDA_WORKER_RX_TIMEOUT);
 
 
+    instance->rx.overrun = false;
     instance->state = IrdaWorkerStateRunRx;
     instance->state = IrdaWorkerStateRunRx;
 }
 }