Skip to content

Commit

Permalink
[FL-2787] SubGhz: add protocol Clemsa, fix decoder BETT (flipperdevic…
Browse files Browse the repository at this point in the history
…es#1696)

* SubGhz: add protocol Clemsa
* SubGhz: fix decoder BETT protocol

Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
Skorpionm and skotopes committed Sep 3, 2022
1 parent e314741 commit 5e40696
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 20 deletions.
17 changes: 16 additions & 1 deletion applications/unit_tests/subghz/subghz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo")
#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
#define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub")
#define TEST_RANDOM_COUNT_PARSE 208
#define TEST_RANDOM_COUNT_PARSE 232
#define TEST_TIMEOUT 10000

static SubGhzEnvironment* environment_handler;
Expand Down Expand Up @@ -427,6 +427,13 @@ MU_TEST(subghz_decoder_intertechno_v3_test) {
"Test decoder " SUBGHZ_PROTOCOL_INTERTECHNO_V3_NAME " error\r\n");
}

MU_TEST(subghz_decoder_clemsa_test) {
mu_assert(
subghz_decoder_test(
EXT_PATH("unit_tests/subghz/clemsa_raw.sub"), SUBGHZ_PROTOCOL_CLEMSA_NAME),
"Test decoder " SUBGHZ_PROTOCOL_CLEMSA_NAME " error\r\n");
}

//test encoders
MU_TEST(subghz_encoder_princeton_test) {
mu_assert(
Expand Down Expand Up @@ -542,6 +549,12 @@ MU_TEST(subghz_encoder_intertechno_v3_test) {
"Test encoder " SUBGHZ_PROTOCOL_INTERTECHNO_V3_NAME " error\r\n");
}

MU_TEST(subghz_encoder_clemsa_test) {
mu_assert(
subghz_encoder_test(EXT_PATH("unit_tests/subghz/clemsa.sub")),
"Test encoder " SUBGHZ_PROTOCOL_CLEMSA_NAME " error\r\n");
}

MU_TEST(subghz_random_test) {
mu_assert(subghz_decode_random_test(TEST_RANDOM_DIR_NAME), "Random test error\r\n");
}
Expand Down Expand Up @@ -581,6 +594,7 @@ MU_TEST_SUITE(subghz) {
MU_RUN_TEST(subghz_decoder_honeywell_wdb_test);
MU_RUN_TEST(subghz_decoder_magellen_test);
MU_RUN_TEST(subghz_decoder_intertechno_v3_test);
MU_RUN_TEST(subghz_decoder_clemsa_test);

MU_RUN_TEST(subghz_encoder_princeton_test);
MU_RUN_TEST(subghz_encoder_came_test);
Expand All @@ -601,6 +615,7 @@ MU_TEST_SUITE(subghz) {
MU_RUN_TEST(subghz_encoder_honeywell_wdb_test);
MU_RUN_TEST(subghz_encoder_magellen_test);
MU_RUN_TEST(subghz_encoder_intertechno_v3_test);
MU_RUN_TEST(subghz_encoder_clemsa_test);

MU_RUN_TEST(subghz_random_test);
subghz_test_deinit();
Expand Down
7 changes: 7 additions & 0 deletions assets/unit_tests/subghz/clemsa.sub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Filetype: Flipper SubGhz Key File
Version: 1
Frequency: 433920000
Preset: FuriHalSubGhzPresetOok650Async
Protocol: Clemsa
Bit: 18
Key: 00 00 00 00 00 02 FC AA
14 changes: 14 additions & 0 deletions assets/unit_tests/subghz/clemsa_raw.sub

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions assets/unit_tests/subghz/test_random_raw.sub

Large diffs are not rendered by default.

24 changes: 5 additions & 19 deletions lib/subghz/protocols/bett.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void* subghz_protocol_encoder_bett_alloc(SubGhzEnvironment* environment) {
instance->generic.protocol_name = instance->base.protocol->name;

instance->encoder.repeat = 10;
instance->encoder.size_upload = 52; //max 24bit*2 + 2 (start, stop)
instance->encoder.size_upload = 52;
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
Expand Down Expand Up @@ -233,7 +233,8 @@ void subghz_protocol_decoder_bett_feed(void* context, bool level, uint32_t durat
case BETTDecoderStepReset:
if((!level) && (DURATION_DIFF(duration, subghz_protocol_bett_const.te_short * 44) <
(subghz_protocol_bett_const.te_delta * 15))) {
//Found Preambula
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = BETTDecoderStepCheckDuration;
}
break;
Expand Down Expand Up @@ -288,20 +289,6 @@ void subghz_protocol_decoder_bett_feed(void* context, bool level, uint32_t durat
}
}

/**
* Analysis of received data
* @param instance Pointer to a SubGhzBlockGeneric* instance
*/
static void subghz_protocol_bett_check_remote_controller(SubGhzBlockGeneric* instance) {
uint32_t code_found_reverse =
subghz_protocol_blocks_reverse_key(instance->data, instance->data_count_bit);

instance->serial = (code_found_reverse & 0xFF) << 12 |
((code_found_reverse >> 8) & 0xFF) << 4 |
((code_found_reverse >> 20) & 0x0F);
instance->btn = ((code_found_reverse >> 16) & 0x0F);
}

uint8_t subghz_protocol_decoder_bett_get_hash_data(void* context) {
furi_assert(context);
SubGhzProtocolDecoderBETT* instance = context;
Expand Down Expand Up @@ -339,8 +326,7 @@ bool subghz_protocol_decoder_bett_deserialize(void* context, FlipperFormat* flip
void subghz_protocol_decoder_bett_get_string(void* context, string_t output) {
furi_assert(context);
SubGhzProtocolDecoderBETT* instance = context;
subghz_protocol_bett_check_remote_controller(&instance->generic);
uint32_t data = (uint32_t)(instance->generic.data & 0xFFFFFF);
uint32_t data = (uint32_t)(instance->generic.data & 0x3FFFF);
string_cat_printf(
output,
"%s %dbit\r\n"
Expand All @@ -350,7 +336,7 @@ void subghz_protocol_decoder_bett_get_string(void* context, string_t output) {
" -: " DIP_PATTERN "\r\n",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint32_t)(instance->generic.data & 0xFFFFFF),
data,
SHOW_DIP_P(data, DIP_P),
SHOW_DIP_P(data, DIP_O),
SHOW_DIP_P(data, DIP_N));
Expand Down

0 comments on commit 5e40696

Please sign in to comment.