[FL-3502] SubGhz: fix Protocol not found error message

This commit is contained in:
SkorP 2023-08-16 10:46:08 +04:00
parent 9d7396ee63
commit 0ecec8a711
4 changed files with 44 additions and 46 deletions

View File

@ -13,7 +13,7 @@
#define TAG "SubGhzCreateProtocolKey"
bool subghz_txrx_gen_data_protocol(
SubGhzProtocolStatus subghz_txrx_gen_data_protocol(
void* context,
const char* preset_name,
uint32_t frequency,
@ -23,30 +23,29 @@ bool subghz_txrx_gen_data_protocol(
furi_assert(context);
SubGhzTxRx* instance = context;
bool res = false;
SubGhzProtocolStatus ret = SubGhzProtocolStatusOk;
subghz_txrx_set_preset(instance, preset_name, frequency, NULL, 0);
instance->decoder_result =
subghz_receiver_search_decoder_base_by_name(instance->receiver, protocol_name);
if(instance->decoder_result == NULL) {
//TODO: Error
// furi_string_set(error_str, "Protocol not\nfound!");
// scene_manager_next_scene(scene_manager, SubGhzSceneShowErrorSub);
FURI_LOG_E(TAG, "Protocol not found!");
return false;
ret = SubGhzProtocolStatusErrorProtocolNotFound;
return ret;
}
do {
Stream* fff_data_stream = flipper_format_get_raw_stream(instance->fff_data);
stream_clean(fff_data_stream);
if(subghz_protocol_decoder_base_serialize(
instance->decoder_result, instance->fff_data, instance->preset) !=
SubGhzProtocolStatusOk) {
ret = subghz_protocol_decoder_base_serialize(
instance->decoder_result, instance->fff_data, instance->preset);
if(ret != SubGhzProtocolStatusOk) {
FURI_LOG_E(TAG, "Unable to serialize");
break;
}
if(!flipper_format_update_uint32(instance->fff_data, "Bit", &bit, 1)) {
ret = SubGhzProtocolStatusErrorParserOthers;
FURI_LOG_E(TAG, "Unable to update Bit");
break;
}
@ -56,15 +55,15 @@ bool subghz_txrx_gen_data_protocol(
key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF;
}
if(!flipper_format_update_hex(instance->fff_data, "Key", key_data, sizeof(uint64_t))) {
ret = SubGhzProtocolStatusErrorParserOthers;
FURI_LOG_E(TAG, "Unable to update Key");
break;
}
res = true;
} while(false);
return res;
return ret;
}
bool subghz_txrx_gen_data_protocol_and_te(
SubGhzProtocolStatus subghz_txrx_gen_data_protocol_and_te(
SubGhzTxRx* instance,
const char* preset_name,
uint32_t frequency,
@ -73,18 +72,18 @@ bool subghz_txrx_gen_data_protocol_and_te(
uint32_t bit,
uint32_t te) {
furi_assert(instance);
bool ret = false;
if(subghz_txrx_gen_data_protocol(instance, preset_name, frequency, protocol_name, key, bit)) {
SubGhzProtocolStatus ret =
subghz_txrx_gen_data_protocol(instance, preset_name, frequency, protocol_name, key, bit);
if(ret == SubGhzProtocolStatusOk) {
if(!flipper_format_update_uint32(instance->fff_data, "TE", (uint32_t*)&te, 1)) {
ret = SubGhzProtocolStatusErrorParserOthers;
FURI_LOG_E(TAG, "Unable to update Te");
} else {
ret = true;
}
}
return ret;
}
bool subghz_txrx_gen_keeloq_protocol(
SubGhzProtocolStatus subghz_txrx_gen_keeloq_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency,
@ -94,7 +93,7 @@ bool subghz_txrx_gen_keeloq_protocol(
uint16_t cnt) {
furi_assert(instance);
bool ret = false;
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
serial &= 0x0FFFFFFF;
instance->transmitter =
subghz_transmitter_alloc_init(instance->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
@ -108,13 +107,13 @@ bool subghz_txrx_gen_keeloq_protocol(
cnt,
name_sysmem,
instance->preset);
ret = true;
ret = SubGhzProtocolStatusOk;
}
subghz_transmitter_free(instance->transmitter);
return ret;
}
bool subghz_txrx_gen_secplus_v2_protocol(
SubGhzProtocolStatus subghz_txrx_gen_secplus_v2_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency,
@ -123,10 +122,11 @@ bool subghz_txrx_gen_secplus_v2_protocol(
uint32_t cnt) {
furi_assert(instance);
bool ret = false;
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
instance->transmitter =
subghz_transmitter_alloc_init(instance->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
subghz_txrx_set_preset(instance, name_preset, frequency, NULL, 0);
if(instance->transmitter) {
subghz_protocol_secplus_v2_create_data(
subghz_transmitter_get_protocol_instance(instance->transmitter),
@ -135,30 +135,27 @@ bool subghz_txrx_gen_secplus_v2_protocol(
btn,
cnt,
instance->preset);
ret = true;
ret = SubGhzProtocolStatusOk;
}
return ret;
}
bool subghz_txrx_gen_secplus_v1_protocol(
SubGhzProtocolStatus subghz_txrx_gen_secplus_v1_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency) {
furi_assert(instance);
bool ret = false;
uint32_t serial = (uint32_t)rand();
while(!subghz_protocol_secplus_v1_check_fixed(serial)) {
serial = (uint32_t)rand();
}
if(subghz_txrx_gen_data_protocol(
return subghz_txrx_gen_data_protocol(
instance,
name_preset,
frequency,
SUBGHZ_PROTOCOL_SECPLUS_V1_NAME,
(uint64_t)serial << 32 | 0xE6000000,
42)) {
ret = true;
}
return ret;
42);
}

View File

@ -11,9 +11,9 @@
* @param protocol_name Name of protocol
* @param key Key
* @param bit Bit
* @return bool True if success
* @return SubGhzProtocolStatus
*/
bool subghz_txrx_gen_data_protocol(
SubGhzProtocolStatus subghz_txrx_gen_data_protocol(
void* context,
const char* preset_name,
uint32_t frequency,
@ -31,9 +31,9 @@ bool subghz_txrx_gen_data_protocol(
* @param key Key
* @param bit Bit
* @param te Te
* @return bool True if success
* @return SubGhzProtocolStatus
*/
bool subghz_txrx_gen_data_protocol_and_te(
SubGhzProtocolStatus subghz_txrx_gen_data_protocol_and_te(
SubGhzTxRx* instance,
const char* preset_name,
uint32_t frequency,
@ -52,9 +52,9 @@ bool subghz_txrx_gen_data_protocol_and_te(
* @param serial Serial number
* @param btn Button
* @param cnt Counter
* @return bool True if success
* @return SubGhzProtocolStatus
*/
bool subghz_txrx_gen_keeloq_protocol(
SubGhzProtocolStatus subghz_txrx_gen_keeloq_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency,
@ -72,9 +72,9 @@ bool subghz_txrx_gen_keeloq_protocol(
* @param serial Serial number
* @param btn Button
* @param cnt Counter
* @return bool True if success
* @return SubGhzProtocolStatus
*/
bool subghz_txrx_gen_secplus_v2_protocol(
SubGhzProtocolStatus subghz_txrx_gen_secplus_v2_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency,
@ -88,9 +88,9 @@ bool subghz_txrx_gen_secplus_v2_protocol(
* @param instance Pointer to a SubGhzTxRx
* @param name_preset Name of preset
* @param frequency Frequency in Hz
* @return bool True if success
* @return SubGhzProtocolStatus
*/
bool subghz_txrx_gen_secplus_v1_protocol(
SubGhzProtocolStatus subghz_txrx_gen_secplus_v1_protocol(
SubGhzTxRx* instance,
const char* name_preset,
uint32_t frequency);

View File

@ -118,7 +118,7 @@ void subghz_scene_set_type_on_enter(void* context) {
bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
bool generated_protocol = false;
SubGhzProtocolStatus generated_protocol = SubGhzProtocolStatusError;
if(event.type == SceneManagerEventTypeCustom) {
uint32_t key = (uint32_t)rand();
@ -216,7 +216,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSetType, event.event);
if(generated_protocol) {
if(generated_protocol == SubGhzProtocolStatusOk) {
subghz_file_name_clear(subghz);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
return true;

View File

@ -57,6 +57,7 @@ typedef enum {
// Encoder issue
SubGhzProtocolStatusErrorEncoderGetUpload = (-12), ///< Payload encoder failure
// Special Values
SubGhzProtocolStatusErrorProtocolNotFound = (-13), ///< Protocol not found
SubGhzProtocolStatusReserved = 0x7FFFFFFF, ///< Prevents enum down-size compiler optimization.
} SubGhzProtocolStatus;