[FL-1931, FL-2005] SubGhz: migration in flipper file format (#807)
* SubGhz: add save key in flipper file format * [FL-2005] SubGhz: fix stored signals cannot be deleted * SubGhz: add load key in flipper file format * SubGhz: fix syntax * SubGhz: fix bad file upload * Storage: add function to get the next free filename * SubGhz: add save RAW in flipper file format * SubGhz: add load RAW in flipper file format * SubGhz: refactoring protocol * SubGhz: refactoring scene * SubGhz: fix SubGhzNotificationState define * Makefile: proper comapre for FORCE Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		| @@ -11,33 +11,33 @@ void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* co | ||||
|  | ||||
| void subghz_scene_delete_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|  | ||||
|     char buffer_str[16]; | ||||
|     snprintf( | ||||
|         buffer_str, | ||||
|         sizeof(buffer_str), | ||||
|         "%03ld.%02ld", | ||||
|         subghz->txrx->frequency / 1000000 % 1000, | ||||
|         subghz->txrx->frequency / 10000 % 100); | ||||
|     widget_add_string_element( | ||||
|         subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, buffer_str); | ||||
|     if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|        subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|         snprintf(buffer_str, sizeof(buffer_str), "AM"); | ||||
|     } else if( | ||||
|         subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|         subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|         snprintf(buffer_str, sizeof(buffer_str), "FM"); | ||||
|     } else { | ||||
|         furi_crash(NULL); | ||||
|     } | ||||
|     widget_add_string_element( | ||||
|         subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str); | ||||
|     string_t frequency_str; | ||||
|     string_t modulation_str; | ||||
|     string_t text; | ||||
|  | ||||
|     string_init(frequency_str); | ||||
|     string_init(modulation_str); | ||||
|     string_init(text); | ||||
|  | ||||
|     subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); | ||||
|     widget_add_string_element( | ||||
|         subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(frequency_str)); | ||||
|  | ||||
|     widget_add_string_element( | ||||
|         subghz->widget, | ||||
|         113, | ||||
|         0, | ||||
|         AlignLeft, | ||||
|         AlignTop, | ||||
|         FontSecondary, | ||||
|         string_get_cstr(modulation_str)); | ||||
|  | ||||
|     subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text); | ||||
|     widget_add_string_multiline_element( | ||||
|         subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text)); | ||||
|  | ||||
|     string_clear(frequency_str); | ||||
|     string_clear(modulation_str); | ||||
|     string_clear(text); | ||||
|  | ||||
|     widget_add_button_element( | ||||
| @@ -50,7 +50,7 @@ bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) { | ||||
|     SubGhz* subghz = context; | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == SubghzCustomEventSceneDelete) { | ||||
|             memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name)); | ||||
|             memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name) + 1); | ||||
|             if(subghz_delete_file(subghz)) { | ||||
|                 scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess); | ||||
|             } else { | ||||
|   | ||||
| @@ -6,27 +6,19 @@ | ||||
| static void subghz_scene_read_raw_update_statusbar(void* context) { | ||||
|     furi_assert(context); | ||||
|     SubGhz* subghz = context; | ||||
|     char frequency_str[20]; | ||||
|     char preset_str[10]; | ||||
|  | ||||
|     snprintf( | ||||
|         frequency_str, | ||||
|         sizeof(frequency_str), | ||||
|         "%03ld.%02ld", | ||||
|         subghz->txrx->frequency / 1000000 % 1000, | ||||
|         subghz->txrx->frequency / 10000 % 100); | ||||
|     if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|        subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|         snprintf(preset_str, sizeof(preset_str), "AM"); | ||||
|     } else if( | ||||
|         subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|         subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|         snprintf(preset_str, sizeof(preset_str), "FM"); | ||||
|     } else { | ||||
|         furi_crash(NULL); | ||||
|     } | ||||
|     string_t frequency_str; | ||||
|     string_t modulation_str; | ||||
|  | ||||
|     subghz_read_raw_add_data_statusbar(subghz->subghz_read_raw, frequency_str, preset_str); | ||||
|     string_init(frequency_str); | ||||
|     string_init(modulation_str); | ||||
|  | ||||
|     subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); | ||||
|     subghz_read_raw_add_data_statusbar( | ||||
|         subghz->subghz_read_raw, string_get_cstr(frequency_str), string_get_cstr(modulation_str)); | ||||
|  | ||||
|     string_clear(frequency_str); | ||||
|     string_clear(modulation_str); | ||||
| } | ||||
|  | ||||
| void subghz_scene_read_raw_callback(SubghzCustomEvent event, void* context) { | ||||
| @@ -70,7 +62,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|             subghz->txrx->preset = FuriHalSubGhzPresetOok650Async; | ||||
|             subghz_protocol_raw_save_to_file_stop( | ||||
|                 (SubGhzProtocolRAW*)subghz->txrx->protocol_result); | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|  | ||||
|             if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { | ||||
|                 subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; | ||||
| @@ -95,7 +87,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|             }; | ||||
|             subghz_protocol_raw_save_to_file_stop( | ||||
|                 (SubGhzProtocolRAW*)subghz->txrx->protocol_result); | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|  | ||||
|             subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; | ||||
|  | ||||
| @@ -106,17 +98,18 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|             if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { | ||||
|                 scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); | ||||
|             } else { | ||||
|                 subghz_get_preset_name(subghz, subghz->error_str); | ||||
|                 if(subghz_protocol_raw_save_to_file_init( | ||||
|                        (SubGhzProtocolRAW*)subghz->txrx->protocol_result, | ||||
|                        "Raw_temp", | ||||
|                        subghz->txrx->frequency, | ||||
|                        subghz->txrx->preset)) { | ||||
|                        string_get_cstr(subghz->error_str))) { | ||||
|                     if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) || | ||||
|                        (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { | ||||
|                         subghz_begin(subghz, subghz->txrx->preset); | ||||
|                         subghz_rx(subghz, subghz->txrx->frequency); | ||||
|                     } | ||||
|                     subghz->state_notifications = NOTIFICATION_RX_STATE; | ||||
|                     subghz->state_notifications = SubGhzNotificationStateRX; | ||||
|                 } else { | ||||
|                     string_set(subghz->error_str, "No SD card"); | ||||
|                     scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); | ||||
| @@ -127,14 +120,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|             break; | ||||
|         case SubghzCustomEventViewReadRAWMore: | ||||
|             if(strcmp( | ||||
|                    subghz_protocol_get_last_file_name( | ||||
|                    subghz_protocol_raw_get_last_file_name( | ||||
|                        (SubGhzProtocolRAW*)subghz->txrx->protocol_result), | ||||
|                    "")) { | ||||
|                 strlcpy( | ||||
|                     subghz->file_name, | ||||
|                     subghz_protocol_get_last_file_name( | ||||
|                     subghz_protocol_raw_get_last_file_name( | ||||
|                         (SubGhzProtocolRAW*)subghz->txrx->protocol_result), | ||||
|                     strlen(subghz_protocol_get_last_file_name( | ||||
|                     strlen(subghz_protocol_raw_get_last_file_name( | ||||
|                         (SubGhzProtocolRAW*)subghz->txrx->protocol_result)) + | ||||
|                         1); | ||||
|                 //set the path to read the file | ||||
| @@ -145,7 +138,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|                     SUBGHZ_APP_PATH_FOLDER, | ||||
|                     subghz->file_name, | ||||
|                     SUBGHZ_APP_EXTENSION); | ||||
|                 subghz_protocol_set_last_file_name( | ||||
|                 subghz_protocol_raw_set_last_file_name( | ||||
|                     (SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str)); | ||||
|                 string_clear(temp_str); | ||||
|  | ||||
| @@ -159,7 +152,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { | ||||
|         } | ||||
|     } else if(event.type == SceneManagerEventTypeTick) { | ||||
|         switch(subghz->state_notifications) { | ||||
|         case NOTIFICATION_RX_STATE: | ||||
|         case SubGhzNotificationStateRX: | ||||
|             notification_message(subghz->notifications, &sequence_blink_blue_10); | ||||
|             subghz_read_raw_update_sample_write( | ||||
|                 subghz->subghz_read_raw, | ||||
| @@ -182,7 +175,7 @@ void subghz_scene_read_raw_on_exit(void* context) { | ||||
|         subghz_rx_end(subghz); | ||||
|         subghz_sleep(subghz); | ||||
|     }; | ||||
|     subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|     subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|  | ||||
|     //Сallback restoration | ||||
|     subghz_worker_set_pair_callback( | ||||
|   | ||||
| @@ -3,33 +3,29 @@ | ||||
|  | ||||
| static void subghz_scene_receiver_update_statusbar(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     char frequency_str[20]; | ||||
|     char preset_str[10]; | ||||
|     string_t history_stat_str; | ||||
|     string_init(history_stat_str); | ||||
|     if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) { | ||||
|         snprintf( | ||||
|             frequency_str, | ||||
|             sizeof(frequency_str), | ||||
|             "%03ld.%02ld", | ||||
|             subghz->txrx->frequency / 1000000 % 1000, | ||||
|             subghz->txrx->frequency / 10000 % 100); | ||||
|         if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|            subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|             snprintf(preset_str, sizeof(preset_str), "AM"); | ||||
|         } else if( | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|             snprintf(preset_str, sizeof(preset_str), "FM"); | ||||
|         } else { | ||||
|             furi_crash(NULL); | ||||
|         } | ||||
|         string_t frequency_str; | ||||
|         string_t modulation_str; | ||||
|  | ||||
|         string_init(frequency_str); | ||||
|         string_init(modulation_str); | ||||
|  | ||||
|         subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); | ||||
|  | ||||
|         subghz_receiver_add_data_statusbar( | ||||
|             subghz->subghz_receiver, frequency_str, preset_str, string_get_cstr(history_stat_str)); | ||||
|             subghz->subghz_receiver, | ||||
|             string_get_cstr(frequency_str), | ||||
|             string_get_cstr(modulation_str), | ||||
|             string_get_cstr(history_stat_str)); | ||||
|  | ||||
|         string_clear(frequency_str); | ||||
|         string_clear(modulation_str); | ||||
|     } else { | ||||
|         subghz_receiver_add_data_statusbar( | ||||
|             subghz->subghz_receiver, string_get_cstr(history_stat_str), "", ""); | ||||
|         subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|         subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|     } | ||||
|     string_clear(history_stat_str); | ||||
| } | ||||
| @@ -83,7 +79,7 @@ void subghz_scene_receiver_on_enter(void* context) { | ||||
|     subghz_receiver_set_callback(subghz->subghz_receiver, subghz_scene_receiver_callback, subghz); | ||||
|     subghz_parser_enable_dump(subghz->txrx->parser, subghz_scene_add_to_history_callback, subghz); | ||||
|  | ||||
|     subghz->state_notifications = NOTIFICATION_RX_STATE; | ||||
|     subghz->state_notifications = SubGhzNotificationStateRX; | ||||
|     if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { | ||||
|         subghz_rx_end(subghz); | ||||
|     }; | ||||
| @@ -104,7 +100,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { | ||||
|         switch(event.event) { | ||||
|         case SubghzCustomEventViewReceverBack: | ||||
|             // Stop CC1101 Rx | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { | ||||
|                 subghz_rx_end(subghz); | ||||
|                 subghz_sleep(subghz); | ||||
| @@ -125,7 +121,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { | ||||
|             return true; | ||||
|             break; | ||||
|         case SubghzCustomEventViewReceverConfig: | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver); | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); | ||||
|             return true; | ||||
| @@ -140,7 +136,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { | ||||
|         } | ||||
|  | ||||
|         switch(subghz->state_notifications) { | ||||
|         case NOTIFICATION_RX_STATE: | ||||
|         case SubGhzNotificationStateRX: | ||||
|             notification_message(subghz->notifications, &sequence_blink_blue_10); | ||||
|             break; | ||||
|         default: | ||||
|   | ||||
| @@ -40,35 +40,42 @@ void subghz_scene_receiver_info_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|  | ||||
|     if(subghz_scene_receiver_info_update_parser(subghz)) { | ||||
|         char buffer_str[16]; | ||||
|         snprintf( | ||||
|             buffer_str, | ||||
|             sizeof(buffer_str), | ||||
|             "%03ld.%02ld", | ||||
|             subghz->txrx->frequency / 1000000 % 1000, | ||||
|             subghz->txrx->frequency / 10000 % 100); | ||||
|         widget_add_string_element( | ||||
|             subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, buffer_str); | ||||
|         if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|            subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|             snprintf(buffer_str, sizeof(buffer_str), "AM"); | ||||
|         } else if( | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|             snprintf(buffer_str, sizeof(buffer_str), "FM"); | ||||
|         } else { | ||||
|             furi_crash(NULL); | ||||
|         } | ||||
|         widget_add_string_element( | ||||
|             subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str); | ||||
|         string_t frequency_str; | ||||
|         string_t modulation_str; | ||||
|         string_t text; | ||||
|  | ||||
|         string_init(frequency_str); | ||||
|         string_init(modulation_str); | ||||
|         string_init(text); | ||||
|  | ||||
|         subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); | ||||
|         widget_add_string_element( | ||||
|             subghz->widget, | ||||
|             78, | ||||
|             0, | ||||
|             AlignLeft, | ||||
|             AlignTop, | ||||
|             FontSecondary, | ||||
|             string_get_cstr(frequency_str)); | ||||
|  | ||||
|         widget_add_string_element( | ||||
|             subghz->widget, | ||||
|             113, | ||||
|             0, | ||||
|             AlignLeft, | ||||
|             AlignTop, | ||||
|             FontSecondary, | ||||
|             string_get_cstr(modulation_str)); | ||||
|  | ||||
|         subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text); | ||||
|         widget_add_string_multiline_element( | ||||
|             subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text)); | ||||
|  | ||||
|         string_clear(frequency_str); | ||||
|         string_clear(modulation_str); | ||||
|         string_clear(text); | ||||
|  | ||||
|         if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string && | ||||
|         if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file && | ||||
|            strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) { | ||||
|             widget_add_button_element( | ||||
|                 subghz->widget, | ||||
| @@ -112,13 +119,13 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) | ||||
|                 if(!subghz_tx_start(subghz)) { | ||||
|                     scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); | ||||
|                 } else { | ||||
|                     subghz->state_notifications = NOTIFICATION_TX_STATE; | ||||
|                     subghz->state_notifications = SubGhzNotificationStateTX; | ||||
|                 } | ||||
|             } | ||||
|             return true; | ||||
|         } else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) { | ||||
|             //CC1101 Stop Tx -> Start RX | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { | ||||
|                 subghz_tx_stop(subghz); | ||||
|             } | ||||
| @@ -129,11 +136,11 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) | ||||
|             if(subghz->txrx->hopper_state == SubGhzHopperStatePause) { | ||||
|                 subghz->txrx->hopper_state = SubGhzHopperStateRunnig; | ||||
|             } | ||||
|             subghz->state_notifications = NOTIFICATION_RX_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateRX; | ||||
|             return true; | ||||
|         } else if(event.event == SubghzCustomEventSceneReceiverInfoSave) { | ||||
|             //CC1101 Stop RX -> Save | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) { | ||||
|                 subghz->txrx->hopper_state = SubGhzHopperStateOFF; | ||||
|             } | ||||
| @@ -144,7 +151,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) | ||||
|             if(!subghz_scene_receiver_info_update_parser(subghz)) { | ||||
|                 return false; | ||||
|             } | ||||
|             if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string && | ||||
|             if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file && | ||||
|                strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) { | ||||
|                 subghz_file_name_clear(subghz); | ||||
|                 scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); | ||||
| @@ -156,10 +163,10 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) | ||||
|             subghz_hopper_update(subghz); | ||||
|         } | ||||
|         switch(subghz->state_notifications) { | ||||
|         case NOTIFICATION_TX_STATE: | ||||
|         case SubGhzNotificationStateTX: | ||||
|             notification_message(subghz->notifications, &sequence_blink_red_10); | ||||
|             break; | ||||
|         case NOTIFICATION_RX_STATE: | ||||
|         case SubGhzNotificationStateRX: | ||||
|             notification_message(subghz->notifications, &sequence_blink_blue_10); | ||||
|             break; | ||||
|         default: | ||||
|   | ||||
| @@ -19,7 +19,7 @@ void subghz_scene_save_name_on_enter(void* context) { | ||||
|         set_random_name(subghz->file_name, sizeof(subghz->file_name)); | ||||
|         dev_name_empty = true; | ||||
|     } else { | ||||
|         memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name)); | ||||
|         memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name) + 1); | ||||
|         if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAWMenu) == | ||||
|            SubghzCustomEventManagerSet) { | ||||
|             subghz_get_next_name_file(subghz); | ||||
|   | ||||
| @@ -16,8 +16,8 @@ void subghz_scene_start_submenu_callback(void* context, uint32_t index) { | ||||
|  | ||||
| void subghz_scene_start_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     if(subghz->state_notifications == NOTIFICATION_STARTING_STATE) { | ||||
|         subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|     if(subghz->state_notifications == SubGhzNotificationStateStarting) { | ||||
|         subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|     } | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); | ||||
|   | ||||
| @@ -13,9 +13,12 @@ bool subghz_scene_transmitter_update_data_show(void* context) { | ||||
|  | ||||
|     if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->get_upload_protocol) { | ||||
|         string_t key_str; | ||||
|         string_t frequency_str; | ||||
|         string_t modulation_str; | ||||
|  | ||||
|         string_init(key_str); | ||||
|         char frequency_str[10]; | ||||
|         char preset_str[6]; | ||||
|         string_init(frequency_str); | ||||
|         string_init(modulation_str); | ||||
|         uint8_t show_button = 0; | ||||
|         subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, key_str); | ||||
|  | ||||
| @@ -27,29 +30,17 @@ bool subghz_scene_transmitter_update_data_show(void* context) { | ||||
|         } else { | ||||
|             show_button = 1; | ||||
|         } | ||||
|         snprintf( | ||||
|             frequency_str, | ||||
|             sizeof(frequency_str), | ||||
|             "%03ld.%02ld", | ||||
|             subghz->txrx->frequency / 1000000 % 1000, | ||||
|             subghz->txrx->frequency / 10000 % 100); | ||||
|         if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|            subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|             snprintf(preset_str, sizeof(preset_str), "AM"); | ||||
|         } else if( | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|             snprintf(preset_str, sizeof(preset_str), "FM"); | ||||
|         } else { | ||||
|             furi_crash(NULL); | ||||
|         } | ||||
|  | ||||
|         subghz_get_frequency_modulation(subghz, frequency_str, modulation_str); | ||||
|         subghz_transmitter_add_data_to_show( | ||||
|             subghz->subghz_transmitter, | ||||
|             string_get_cstr(key_str), | ||||
|             frequency_str, | ||||
|             preset_str, | ||||
|             string_get_cstr(frequency_str), | ||||
|             string_get_cstr(modulation_str), | ||||
|             show_button); | ||||
|  | ||||
|         string_clear(frequency_str); | ||||
|         string_clear(modulation_str); | ||||
|         string_clear(key_str); | ||||
|  | ||||
|         return true; | ||||
| @@ -67,7 +58,7 @@ void subghz_scene_transmitter_on_enter(void* context) { | ||||
|     subghz_transmitter_set_callback( | ||||
|         subghz->subghz_transmitter, subghz_scene_transmitter_callback, subghz); | ||||
|  | ||||
|     subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|     subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|     view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTransmitter); | ||||
| } | ||||
|  | ||||
| @@ -75,7 +66,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { | ||||
|     SubGhz* subghz = context; | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == SubghzCustomEventViewTransmitterSendStart) { | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) { | ||||
|                 subghz_rx_end(subghz); | ||||
|             } | ||||
| @@ -84,20 +75,20 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { | ||||
|                 if(!subghz_tx_start(subghz)) { | ||||
|                     scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); | ||||
|                 } else { | ||||
|                     subghz->state_notifications = NOTIFICATION_TX_STATE; | ||||
|                     subghz->state_notifications = SubGhzNotificationStateTX; | ||||
|                     subghz_scene_transmitter_update_data_show(subghz); | ||||
|                 } | ||||
|             } | ||||
|             return true; | ||||
|         } else if(event.event == SubghzCustomEventViewTransmitterSendStop) { | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) { | ||||
|                 subghz_tx_stop(subghz); | ||||
|                 subghz_sleep(subghz); | ||||
|             } | ||||
|             return true; | ||||
|         } else if(event.event == SubghzCustomEventViewTransmitterBack) { | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
|             scene_manager_search_and_switch_to_previous_scene( | ||||
|                 subghz->scene_manager, SubGhzSceneStart); | ||||
|             return true; | ||||
| @@ -106,7 +97,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); | ||||
|         } | ||||
|     } else if(event.type == SceneManagerEventTypeTick) { | ||||
|         if(subghz->state_notifications == NOTIFICATION_TX_STATE) { | ||||
|         if(subghz->state_notifications == SubGhzNotificationStateTX) { | ||||
|             notification_message(subghz->notifications, &sequence_blink_red_10); | ||||
|         } | ||||
|         return true; | ||||
| @@ -117,5 +108,5 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { | ||||
| void subghz_scene_transmitter_on_exit(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|  | ||||
|     subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|     subghz->state_notifications = SubGhzNotificationStateIDLE; | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| #include "subghz_i.h" | ||||
| #include <lib/toolbox/path.h> | ||||
|  | ||||
| const char* const subghz_frequencies_text[] = { | ||||
|     "300.00", | ||||
| @@ -119,6 +120,9 @@ SubGhz* subghz_alloc() { | ||||
|     view_dispatcher_add_view( | ||||
|         subghz->view_dispatcher, SubGhzViewWidget, widget_get_view(subghz->widget)); | ||||
|  | ||||
|     //Dialog | ||||
|     subghz->dialogs = furi_record_open("dialogs"); | ||||
|  | ||||
|     // Transmitter | ||||
|     subghz->subghz_transmitter = subghz_transmitter_alloc(); | ||||
|     view_dispatcher_add_view( | ||||
| @@ -224,6 +228,9 @@ void subghz_free(SubGhz* subghz) { | ||||
|     view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewWidget); | ||||
|     widget_free(subghz->widget); | ||||
|  | ||||
|     //Dialog | ||||
|     furi_record_close("dialogs"); | ||||
|  | ||||
|     // Transmitter | ||||
|     view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTransmitter); | ||||
|     subghz_transmitter_free(subghz->subghz_transmitter); | ||||
| @@ -280,6 +287,12 @@ int32_t subghz_app(void* p) { | ||||
|  | ||||
|     // Check argument and run corresponding scene | ||||
|     if(p && subghz_key_load(subghz, p)) { | ||||
|         string_t filename; | ||||
|         path_extract_filename_no_ext(p, filename); | ||||
|         strlcpy( | ||||
|             subghz->file_name, string_get_cstr(filename), strlen(string_get_cstr(filename)) + 1); | ||||
|         string_clear(filename); | ||||
|  | ||||
|         scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter); | ||||
|     } else { | ||||
|         scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart); | ||||
|   | ||||
| @@ -6,10 +6,74 @@ | ||||
| #include <input/input.h> | ||||
| #include <gui/elements.h> | ||||
| #include <notification/notification-messages.h> | ||||
| #include "file-worker.h" | ||||
| #include <lib/flipper_file/flipper_file.h> | ||||
| #include "../notification/notification.h" | ||||
| #include "views/subghz_receiver.h" | ||||
|  | ||||
| bool subghz_set_pteset(SubGhz* subghz, const char* preset) { | ||||
|     if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) { | ||||
|         subghz->txrx->preset = FuriHalSubGhzPresetOok270Async; | ||||
|     } else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) { | ||||
|         subghz->txrx->preset = FuriHalSubGhzPresetOok650Async; | ||||
|     } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) { | ||||
|         subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev238Async; | ||||
|     } else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) { | ||||
|         subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev476Async; | ||||
|     } else { | ||||
|         FURI_LOG_E(SUBGHZ_KEY_TAG, "Unknown preset"); | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| bool subghz_get_preset_name(SubGhz* subghz, string_t preset) { | ||||
|     const char* preset_name; | ||||
|     switch(subghz->txrx->preset) { | ||||
|     case FuriHalSubGhzPresetOok270Async: | ||||
|         preset_name = "FuriHalSubGhzPresetOok270Async"; | ||||
|         break; | ||||
|     case FuriHalSubGhzPresetOok650Async: | ||||
|         preset_name = "FuriHalSubGhzPresetOok650Async"; | ||||
|         break; | ||||
|     case FuriHalSubGhzPreset2FSKDev238Async: | ||||
|         preset_name = "FuriHalSubGhzPreset2FSKDev238Async"; | ||||
|         break; | ||||
|     case FuriHalSubGhzPreset2FSKDev476Async: | ||||
|         preset_name = "FuriHalSubGhzPreset2FSKDev476Async"; | ||||
|         break; | ||||
|         FURI_LOG_E(SUBGHZ_KEY_TAG, "Unknown preset"); | ||||
|     default: | ||||
|         return false; | ||||
|         break; | ||||
|     } | ||||
|     string_set(preset, preset_name); | ||||
|     return true; | ||||
| } | ||||
|  | ||||
| void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation) { | ||||
|     furi_assert(subghz); | ||||
|     if(frequency != NULL) { | ||||
|         string_printf( | ||||
|             frequency, | ||||
|             "%03ld.%02ld", | ||||
|             subghz->txrx->frequency / 1000000 % 1000, | ||||
|             subghz->txrx->frequency / 10000 % 100); | ||||
|     } | ||||
|  | ||||
|     if(modulation != NULL) { | ||||
|         if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async || | ||||
|            subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) { | ||||
|             string_set(modulation, "AM"); | ||||
|         } else if( | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async || | ||||
|             subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) { | ||||
|             string_set(modulation, "FM"); | ||||
|         } else { | ||||
|             furi_crash(NULL); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) { | ||||
|     furi_assert(subghz); | ||||
|     furi_hal_subghz_reset(); | ||||
| @@ -79,17 +143,6 @@ void subghz_sleep(SubGhz* subghz) { | ||||
|     subghz->txrx->txrx_state = SubGhzTxRxStateSleep; | ||||
| } | ||||
|  | ||||
| static void subghz_frequency_preset_to_str(SubGhz* subghz, string_t output) { | ||||
|     furi_assert(subghz); | ||||
|  | ||||
|     string_cat_printf( | ||||
|         output, | ||||
|         "Frequency: %d\n" | ||||
|         "Preset: %d\n", | ||||
|         (int)subghz->txrx->frequency, | ||||
|         (int)subghz->txrx->preset); | ||||
| } | ||||
|  | ||||
| bool subghz_tx_start(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
|  | ||||
| @@ -144,66 +197,77 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { | ||||
|     furi_assert(subghz); | ||||
|     furi_assert(file_path); | ||||
|  | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     Storage* storage = furi_record_open("storage"); | ||||
|     FlipperFile* flipper_file = flipper_file_alloc(storage); | ||||
|  | ||||
|     // Load device data | ||||
|     bool loaded = false; | ||||
|     string_t path; | ||||
|     string_init_set_str(path, file_path); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
|     uint32_t version; | ||||
|  | ||||
|     do { | ||||
|         if(!file_worker_open(file_worker, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|         if(!flipper_file_open_existing(flipper_file, string_get_cstr(path))) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to open file for read: %s", string_get_cstr(path)); | ||||
|             break; | ||||
|         } | ||||
|         if(!flipper_file_read_header(flipper_file, temp_str, &version)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing or incorrect header"); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         // Read and parse frequency from 1st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|         if(((!strcmp(string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) || | ||||
|             (!strcmp(string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) && | ||||
|            version == SUBGHZ_KEY_FILE_VERSION) { | ||||
|         } else { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Type or version mismatch"); | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Frequency: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         subghz->txrx->frequency = (uint32_t)data; | ||||
|  | ||||
|         // Read and parse preset from 2st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|         if(!flipper_file_read_uint32( | ||||
|                flipper_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Frequency"); | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Preset: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         subghz->txrx->preset = (FuriHalSubGhzPreset)data; | ||||
|  | ||||
|         // Read and parse name protocol from 2st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|         if(!flipper_file_read_string(flipper_file, "Preset", temp_str)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Preset"); | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Protocol: ") = 10 | ||||
|         string_right(temp_str, 10); | ||||
|         if(!subghz_set_pteset(subghz, string_get_cstr(temp_str))) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         if(!flipper_file_read_string(flipper_file, "Protocol", temp_str)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Protocol"); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         subghz->txrx->protocol_result = | ||||
|             subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str)); | ||||
|         if(subghz->txrx->protocol_result == NULL) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "This type of protocol was not found"); | ||||
|             break; | ||||
|         } | ||||
|         if(!subghz->txrx->protocol_result->to_load_protocol_from_file( | ||||
|                file_worker, subghz->txrx->protocol_result, string_get_cstr(path))) { | ||||
|                flipper_file, subghz->txrx->protocol_result, string_get_cstr(path))) { | ||||
|             break; | ||||
|         } | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
|  | ||||
|     if(!loaded) { | ||||
|         file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|         dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile"); | ||||
|     } | ||||
|     string_clear(temp_str); | ||||
|     string_clear(path); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|  | ||||
|     flipper_file_close(flipper_file); | ||||
|     flipper_file_free(flipper_file); | ||||
|  | ||||
|     furi_record_close("storage"); | ||||
|  | ||||
|     return loaded; | ||||
| } | ||||
| @@ -211,23 +275,22 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { | ||||
| bool subghz_get_next_name_file(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
|  | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     Storage* storage = furi_record_open("storage"); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     bool res = false; | ||||
|  | ||||
|     if(strcmp(subghz->file_name, "")) { | ||||
|         //get the name of the next free file | ||||
|         file_worker_get_next_filename( | ||||
|             file_worker, SUBGHZ_RAW_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION, temp_str); | ||||
|         storage_get_next_filename( | ||||
|             storage, SUBGHZ_RAW_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION, temp_str); | ||||
|  | ||||
|         memcpy(subghz->file_name, string_get_cstr(temp_str), strlen(string_get_cstr(temp_str))); | ||||
|         res = true; | ||||
|     } | ||||
|  | ||||
|     string_clear(temp_str); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     furi_record_close("storage"); | ||||
|  | ||||
|     return res; | ||||
| } | ||||
| @@ -236,7 +299,8 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { | ||||
|     furi_assert(subghz); | ||||
|     furi_assert(subghz->txrx->protocol_result); | ||||
|  | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     Storage* storage = furi_record_open("storage"); | ||||
|     FlipperFile* flipper_file = flipper_file_alloc(storage); | ||||
|     string_t dev_file_name; | ||||
|     string_init(dev_file_name); | ||||
|     string_t temp_str; | ||||
| @@ -244,43 +308,71 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { | ||||
|     bool saved = false; | ||||
|  | ||||
|     do { | ||||
|         // Checking that this type of people can be saved | ||||
|         if(subghz->txrx->protocol_result->to_save_file == NULL) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "No saving of this type of keys"); | ||||
|             break; | ||||
|         } | ||||
|         // Create subghz folder directory if necessary | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_FOLDER)) { | ||||
|         if(!storage_simply_mkdir(storage, SUBGHZ_APP_FOLDER)) { | ||||
|             dialog_message_show_storage_error(subghz->dialogs, "Cannot create\nfolder"); | ||||
|             break; | ||||
|         } | ||||
|         // Create saved directory if necessary | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_PATH_FOLDER)) { | ||||
|         if(!storage_simply_mkdir(storage, SUBGHZ_APP_FOLDER)) { | ||||
|             dialog_message_show_storage_error(subghz->dialogs, "Cannot create\nfolder"); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         // First remove subghz device file if it was saved | ||||
|         string_printf( | ||||
|             dev_file_name, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, dev_name, SUBGHZ_APP_EXTENSION); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(dev_file_name))) { | ||||
|  | ||||
|         if(!storage_simply_remove(storage, string_get_cstr(dev_file_name))) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         // Open file | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { | ||||
|         if(!flipper_file_open_always(flipper_file, string_get_cstr(dev_file_name))) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to open file for write: %s", dev_file_name); | ||||
|             break; | ||||
|         } | ||||
|         //Get string frequency preset protocol | ||||
|         subghz_frequency_preset_to_str(subghz, temp_str); | ||||
|         if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|  | ||||
|         if(!flipper_file_write_header_cstr( | ||||
|                flipper_file, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add header"); | ||||
|             break; | ||||
|         } | ||||
|         //Get string save | ||||
|         subghz->txrx->protocol_result->to_save_string(subghz->txrx->protocol_result, temp_str); | ||||
|         // Prepare and write data to file | ||||
|         if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|  | ||||
|         if(!flipper_file_write_uint32( | ||||
|                flipper_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Frequency"); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         if(!subghz_get_preset_name(subghz, temp_str)) { | ||||
|             break; | ||||
|         } | ||||
|         if(!flipper_file_write_string_cstr(flipper_file, "Preset", string_get_cstr(temp_str))) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Preset"); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         if(!subghz->txrx->protocol_result->to_save_file( | ||||
|                subghz->txrx->protocol_result, flipper_file)) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         saved = true; | ||||
|     } while(0); | ||||
|  | ||||
|     string_clear(temp_str); | ||||
|     string_clear(dev_file_name); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|  | ||||
|     flipper_file_close(flipper_file); | ||||
|     flipper_file_free(flipper_file); | ||||
|  | ||||
|     furi_record_close("storage"); | ||||
|  | ||||
|     return saved; | ||||
| } | ||||
| @@ -288,17 +380,12 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) { | ||||
| bool subghz_load_protocol_from_file(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
|  | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t protocol_file_name; | ||||
|     string_init(protocol_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int sscanf_res = 0; | ||||
|     int data = 0; | ||||
|     string_t file_name; | ||||
|     string_init(file_name); | ||||
|  | ||||
|     // Input events and views are managed by file_select | ||||
|     bool res = file_worker_file_select( | ||||
|         file_worker, | ||||
|     bool res = dialog_file_select_show( | ||||
|         subghz->dialogs, | ||||
|         SUBGHZ_APP_PATH_FOLDER, | ||||
|         SUBGHZ_APP_EXTENSION, | ||||
|         subghz->file_name, | ||||
| @@ -306,87 +393,24 @@ bool subghz_load_protocol_from_file(SubGhz* subghz) { | ||||
|         NULL); | ||||
|  | ||||
|     if(res) { | ||||
|         // Get key file path | ||||
|         string_printf( | ||||
|             protocol_file_name, | ||||
|             "%s/%s%s", | ||||
|             SUBGHZ_APP_PATH_FOLDER, | ||||
|             subghz->file_name, | ||||
|             SUBGHZ_APP_EXTENSION); | ||||
|     } else { | ||||
|         string_clear(temp_str); | ||||
|         string_clear(protocol_file_name); | ||||
|             file_name, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION); | ||||
|  | ||||
|         file_worker_close(file_worker); | ||||
|         file_worker_free(file_worker); | ||||
|         return res; | ||||
|     } | ||||
|     res = false; | ||||
|     do { | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(protocol_file_name), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|             return res; | ||||
|         } | ||||
|         // Read and parse frequency from 1st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         sscanf_res = sscanf(string_get_cstr(temp_str), "Frequency: %d\n", &data); | ||||
|         if(sscanf_res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         subghz->txrx->frequency = (uint32_t)data; | ||||
|  | ||||
|         // Read and parse preset from 2st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         sscanf_res = sscanf(string_get_cstr(temp_str), "Preset: %d\n", &data); | ||||
|         if(sscanf_res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         subghz->txrx->preset = (FuriHalSubGhzPreset)data; | ||||
|  | ||||
|         // Read and parse name protocol from 3st line | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Protocol: ") = 10 | ||||
|         string_right(temp_str, 10); | ||||
|         subghz->txrx->protocol_result = | ||||
|             subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str)); | ||||
|         if(subghz->txrx->protocol_result == NULL) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         if(subghz->txrx->protocol_result->to_load_protocol_from_file == NULL || | ||||
|            !subghz->txrx->protocol_result->to_load_protocol_from_file( | ||||
|                file_worker, subghz->txrx->protocol_result, string_get_cstr(protocol_file_name))) { | ||||
|             break; | ||||
|         } | ||||
|         res = true; | ||||
|     } while(0); | ||||
|  | ||||
|     if(!res) { | ||||
|         file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|         res = subghz_key_load(subghz, string_get_cstr(file_name)); | ||||
|     } | ||||
|  | ||||
|     string_clear(temp_str); | ||||
|     string_clear(protocol_file_name); | ||||
|  | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     string_clear(file_name); | ||||
|  | ||||
|     return res; | ||||
| } | ||||
|  | ||||
| bool subghz_rename_file(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
|     bool ret = false; | ||||
|     bool ret = true; | ||||
|     string_t old_path; | ||||
|     string_t new_path; | ||||
|  | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     Storage* storage = furi_record_open("storage"); | ||||
|  | ||||
|     string_init_printf( | ||||
|         old_path, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name_tmp, SUBGHZ_APP_EXTENSION); | ||||
| @@ -394,39 +418,33 @@ bool subghz_rename_file(SubGhz* subghz) { | ||||
|     string_init_printf( | ||||
|         new_path, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION); | ||||
|  | ||||
|     ret = file_worker_rename(file_worker, string_get_cstr(old_path), string_get_cstr(new_path)); | ||||
|     FS_Error fs_result = | ||||
|         storage_common_rename(storage, string_get_cstr(old_path), string_get_cstr(new_path)); | ||||
|  | ||||
|     if(fs_result != FSE_OK && fs_result != FSE_EXIST) { | ||||
|         dialog_message_show_storage_error(subghz->dialogs, "Cannot rename\n file/directory"); | ||||
|         ret = false; | ||||
|     } | ||||
|  | ||||
|     string_clear(old_path); | ||||
|     string_clear(new_path); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     furi_record_close("storage"); | ||||
|  | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| bool subghz_delete_file(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
|  | ||||
|     bool result = true; | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     Storage* storage = furi_record_open("storage"); | ||||
|     string_t file_path; | ||||
|     string_init_printf( | ||||
|         file_path, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, subghz->file_name_tmp, SUBGHZ_APP_EXTENSION); | ||||
|     bool result = storage_simply_remove(storage, string_get_cstr(file_path)); | ||||
|     furi_record_close("storage"); | ||||
|  | ||||
|     do { | ||||
|         // Get key file path | ||||
|         string_init_printf( | ||||
|             file_path, | ||||
|             "%s/%s%s", | ||||
|             SUBGHZ_APP_PATH_FOLDER, | ||||
|             subghz->file_name_tmp, | ||||
|             SUBGHZ_APP_EXTENSION); | ||||
|         // Delete original file | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(file_path))) { | ||||
|             result = false; | ||||
|             break; | ||||
|         } | ||||
|     } while(0); | ||||
|     subghz_file_name_clear(subghz); | ||||
|  | ||||
|     string_clear(file_path); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     return result; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ | ||||
| #include <furi.h> | ||||
| #include <furi-hal.h> | ||||
| #include <gui/gui.h> | ||||
| #include <dialogs/dialogs.h> | ||||
| #include <gui/scene_manager.h> | ||||
| #include <notification/notification-messages.h> | ||||
| #include <gui/view_dispatcher.h> | ||||
| @@ -33,11 +34,6 @@ | ||||
|  | ||||
| #define SUBGHZ_TEXT_STORE_SIZE 40 | ||||
|  | ||||
| #define NOTIFICATION_STARTING_STATE 0u | ||||
| #define NOTIFICATION_IDLE_STATE 1u | ||||
| #define NOTIFICATION_TX_STATE 2u | ||||
| #define NOTIFICATION_RX_STATE 3u | ||||
|  | ||||
| extern const char* const subghz_frequencies_text[]; | ||||
| extern const uint32_t subghz_frequencies[]; | ||||
| extern const uint32_t subghz_hopper_frequencies[]; | ||||
| @@ -45,6 +41,14 @@ extern const uint32_t subghz_frequencies_count; | ||||
| extern const uint32_t subghz_hopper_frequencies_count; | ||||
| extern const uint32_t subghz_frequencies_433_92; | ||||
|  | ||||
| /** SubGhzNotification state */ | ||||
| typedef enum { | ||||
|     SubGhzNotificationStateStarting, | ||||
|     SubGhzNotificationStateIDLE, | ||||
|     SubGhzNotificationStateTX, | ||||
|     SubGhzNotificationStateRX, | ||||
| } SubGhzNotificationState; | ||||
|  | ||||
| /** SubGhzTxRx state */ | ||||
| typedef enum { | ||||
|     SubGhzTxRxStateIDLE, | ||||
| @@ -101,9 +105,10 @@ struct SubGhz { | ||||
|     Popup* popup; | ||||
|     TextInput* text_input; | ||||
|     Widget* widget; | ||||
|     DialogsApp* dialogs; | ||||
|     char file_name[SUBGHZ_TEXT_STORE_SIZE + 1]; | ||||
|     char file_name_tmp[SUBGHZ_TEXT_STORE_SIZE + 1]; | ||||
|     uint8_t state_notifications; | ||||
|     SubGhzNotificationState state_notifications; | ||||
|  | ||||
|     SubghzReceiver* subghz_receiver; | ||||
|     SubghzTransmitter* subghz_transmitter; | ||||
| @@ -133,6 +138,9 @@ typedef enum { | ||||
|     SubGhzViewTestPacket, | ||||
| } SubGhzView; | ||||
|  | ||||
| bool subghz_set_pteset(SubGhz* subghz, const char* preset); | ||||
| bool subghz_get_preset_name(SubGhz* subghz, string_t preset); | ||||
| void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation); | ||||
| void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset); | ||||
| uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency); | ||||
| void subghz_rx_end(SubGhz* subghz); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user