Skip to content

Commit

Permalink
some subghz cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Nov 1, 2024
1 parent 9180364 commit 2d60165
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
24 changes: 17 additions & 7 deletions lib/subghz/protocols/alutech_at_4n.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,22 @@ bool subghz_protocol_alutech_at_4n_create_data(
instance->generic.serial = serial;
instance->generic.cnt = cnt;
instance->generic.data_count_bit = 72;
bool res = subghz_protocol_alutech_at_4n_gen_data(instance, btn);
if(res) {
if(subghz_protocol_alutech_at_4n_gen_data(instance, btn)) {
if((subghz_block_generic_serialize(&instance->generic, flipper_format, preset) !=
SubGhzProtocolStatusOk) ||
!flipper_format_write_uint32(flipper_format, "CRC", &instance->crc, 1)) {
SubGhzProtocolStatusOk)) {
FURI_LOG_E(TAG, "Serialize error");
return false;
}
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
return false;
}
if(!flipper_format_insert_or_update_uint32(flipper_format, "CRC", &instance->crc, 1)) {
FURI_LOG_E(TAG, "Unable to add CRC");
res = false;
return false;
}
}
return res;
return true;
}

/**
Expand Down Expand Up @@ -665,8 +671,12 @@ SubGhzProtocolStatus subghz_protocol_decoder_alutech_at_4n_serialize(
SubGhzProtocolDecoderAlutech_at_4n* instance = context;
SubGhzProtocolStatus res =
subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
res = SubGhzProtocolStatusErrorParserOthers;
}
if((res == SubGhzProtocolStatusOk) &&
!flipper_format_write_uint32(flipper_format, "CRC", &instance->crc, 1)) {
!flipper_format_insert_or_update_uint32(flipper_format, "CRC", &instance->crc, 1)) {
FURI_LOG_E(TAG, "Unable to add CRC");
res = SubGhzProtocolStatusErrorParserOthers;
}
Expand Down
22 changes: 11 additions & 11 deletions lib/subghz/protocols/keeloq.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ bool subghz_protocol_keeloq_create_data(
instance->generic.cnt = cnt;
instance->manufacture_name = manufacture_name;
instance->generic.data_count_bit = 64;
bool res = subghz_protocol_keeloq_gen_data(instance, btn, false);
if(res) {
return SubGhzProtocolStatusOk ==
subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
if(subghz_protocol_keeloq_gen_data(instance, btn, false)) {
return (
subghz_block_generic_serialize(&instance->generic, flipper_format, preset) ==
SubGhzProtocolStatusOk);
}
return res;
return false;
}

bool subghz_protocol_keeloq_bft_create_data(
Expand All @@ -380,13 +380,13 @@ bool subghz_protocol_keeloq_bft_create_data(
instance->generic.seed = seed;
instance->manufacture_name = manufacture_name;
instance->generic.data_count_bit = 64;
// roguuemaster don't steal.!!!!
bool res = subghz_protocol_keeloq_gen_data(instance, btn, false);
if(res) {
return SubGhzProtocolStatusOk ==
subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
// hehehehe
if(subghz_protocol_keeloq_gen_data(instance, btn, false)) {
return (
subghz_block_generic_serialize(&instance->generic, flipper_format, preset) ==
SubGhzProtocolStatusOk);
}
return res;
return false;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/subghz/protocols/kinggates_stylo_4k.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ SubGhzProtocolStatus subghz_protocol_encoder_kinggates_stylo_4k_deserialize(
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data_2 >> i * 8) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");
FURI_LOG_E(TAG, "Unable to update Data");
break;
}

Expand Down Expand Up @@ -522,8 +522,13 @@ SubGhzProtocolStatus subghz_protocol_decoder_kinggates_stylo_4k_serialize(
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data_2 >> (i * 8)) & 0xFF;
}

if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
ret = SubGhzProtocolStatusErrorParserOthers;
}

if((ret == SubGhzProtocolStatusOk) &&
!flipper_format_write_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
!flipper_format_insert_or_update_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Data");
ret = SubGhzProtocolStatusErrorParserOthers;
}
Expand Down
11 changes: 8 additions & 3 deletions lib/subghz/protocols/nice_flor_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ SubGhzProtocolStatus
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");
FURI_LOG_E(TAG, "Unable to update Key");
break;
}

Expand All @@ -278,7 +278,7 @@ SubGhzProtocolStatus
}
uint32_t temp = (instance->generic.data_2 >> 4) & 0xFFFFF;
if(!flipper_format_update_uint32(flipper_format, "Data", &temp, 1)) {
FURI_LOG_E(TAG, "Unable to add Data");
FURI_LOG_E(TAG, "Unable to update Data");
}
}

Expand Down Expand Up @@ -707,8 +707,13 @@ SubGhzProtocolStatus subghz_protocol_decoder_nice_flor_s_serialize(
SubGhzProtocolStatus ret =
subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
if(instance->generic.data_count_bit == NICE_ONE_COUNT_BIT) {
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
ret = SubGhzProtocolStatusErrorParserOthers;
}
if((ret == SubGhzProtocolStatusOk) &&
!flipper_format_write_uint32(flipper_format, "Data", (uint32_t*)&instance->data, 1)) {
!flipper_format_insert_or_update_uint32(
flipper_format, "Data", (uint32_t*)&instance->data, 1)) {
FURI_LOG_E(TAG, "Unable to add Data");
ret = SubGhzProtocolStatusErrorParserOthers;
}
Expand Down

0 comments on commit 2d60165

Please sign in to comment.