[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:
		
							parent
							
								
									5209701add
								
							
						
					
					
						commit
						ac8b1457f2
					
				
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							| @ -49,14 +49,14 @@ firmware_clean: | ||||
| 
 | ||||
| .PHONY: bootloader_flash | ||||
| bootloader_flash: | ||||
| ifeq ($(FORCE), '1') | ||||
| ifeq ($(FORCE), 1) | ||||
| 	rm $(PROJECT_ROOT)/bootloader/.obj/f*/flash || true | ||||
| endif | ||||
| 	$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) flash | ||||
| 
 | ||||
| .PHONY: firmware_flash | ||||
| firmware_flash: | ||||
| ifeq ($(FORCE), '1') | ||||
| ifeq ($(FORCE), 1) | ||||
| 	rm $(PROJECT_ROOT)/firmware/.obj/f*/flash || true | ||||
| endif | ||||
| 	$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) flash | ||||
|  | ||||
| @ -463,3 +463,28 @@ bool storage_simply_mkdir(Storage* storage, const char* path) { | ||||
|     result = storage_common_mkdir(storage, path); | ||||
|     return result == FSE_OK || result == FSE_EXIST; | ||||
| } | ||||
| 
 | ||||
| void storage_get_next_filename( | ||||
|     Storage* storage, | ||||
|     const char* dirname, | ||||
|     const char* filename, | ||||
|     const char* fileextension, | ||||
|     string_t nextfilename) { | ||||
|     string_t temp_str; | ||||
|     uint16_t num = 0; | ||||
| 
 | ||||
|     string_init_printf(temp_str, "%s/%s%s", dirname, filename, fileextension); | ||||
| 
 | ||||
|     while(storage_common_stat(storage, string_get_cstr(temp_str), NULL) == FSE_OK) { | ||||
|         num++; | ||||
|         string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension); | ||||
|     } | ||||
| 
 | ||||
|     if(num) { | ||||
|         string_printf(nextfilename, "%s%d", filename, num); | ||||
|     } else { | ||||
|         string_printf(nextfilename, "%s", filename); | ||||
|     } | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| } | ||||
|  | ||||
| @ -262,6 +262,22 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path); | ||||
|  */ | ||||
| bool storage_simply_mkdir(Storage* storage, const char* path); | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief Get next free filename. | ||||
|  *  | ||||
|  * @param storage | ||||
|  * @param dirname  | ||||
|  * @param filename  | ||||
|  * @param fileextension  | ||||
|  * @param nextfilename return name | ||||
|  */ | ||||
| void storage_get_next_filename( | ||||
|     Storage* storage, | ||||
|     const char* dirname, | ||||
|     const char* filename, | ||||
|     const char* fileextension, | ||||
|     string_t nextfilename); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -28,8 +28,8 @@ SubGhzProtocolCame* subghz_protocol_came_alloc() { | ||||
|     instance->common.te_delta = 150; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_came_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_came_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -88,8 +88,6 @@ void subghz_protocol_came_parse(SubGhzProtocolCame* instance, bool level, uint32 | ||||
|                         instance->common.te_delta * 51)) { //Need protocol 36 te_short
 | ||||
|             //Found header CAME
 | ||||
|             instance->common.parser_step = CameDecoderStepFoundStartBit; | ||||
|         } else { | ||||
|             instance->common.parser_step = CameDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case CameDecoderStepFoundStartBit: | ||||
| @ -169,55 +167,16 @@ void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output) | ||||
|         code_found_reverse_lo); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_came_to_save_str(SubGhzProtocolCame* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found & 0x00000000ffffffff)); | ||||
| bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_came_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolCame* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         uint32_t temp_key = 0; | ||||
|         res = sscanf(string_get_cstr(temp_str), "Key: %08lX\n", &temp_key); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_found = (uint64_t)temp_key; | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_came_to_load_protocol(SubGhzProtocolCame* instance, void* context) { | ||||
|  | ||||
| @ -45,22 +45,23 @@ void subghz_protocol_came_parse(SubGhzProtocolCame* instance, bool level, uint32 | ||||
|  */ | ||||
| void subghz_protocol_came_to_str(SubGhzProtocolCame* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolCame instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_came_to_save_str(SubGhzProtocolCame* instance, string_t output); | ||||
| bool subghz_protocol_came_to_save_file(SubGhzProtocolCame* instance, FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolCame instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_came_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolCame* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -177,8 +177,6 @@ void subghz_protocol_came_atomo_parse( | ||||
|                 ManchesterEventShortLow, | ||||
|                 &instance->manchester_saved_state, | ||||
|                 NULL); | ||||
|         } else { | ||||
|             instance->common.parser_step = CameAtomoDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case CameAtomoDecoderStepDecoderData: | ||||
|  | ||||
| @ -36,8 +36,8 @@ SubGhzProtocolCameTwee* subghz_protocol_came_twee_alloc() { | ||||
|     instance->common.te_delta = 250; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_twee_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_came_twee_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_came_twee_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_came_twee_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -247,8 +247,6 @@ void subghz_protocol_came_twee_parse( | ||||
|                 ManchesterEventShortLow, | ||||
|                 &instance->manchester_saved_state, | ||||
|                 NULL); | ||||
|         } else { | ||||
|             instance->common.parser_step = CameTweeDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case CameTweeDecoderStepDecoderData: | ||||
| @ -327,62 +325,22 @@ void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t | ||||
|         CNT_TO_DIP(instance->common.cnt)); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_came_twee_to_save_str(SubGhzProtocolCameTwee* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX%08lX\r\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found >> 32), | ||||
|         (uint32_t)(instance->common.code_last_found & 0xFFFFFFFF)); | ||||
| bool subghz_protocol_came_twee_to_save_file( | ||||
|     SubGhzProtocolCameTwee* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_came_twee_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolCameTwee* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Key: ") = 5
 | ||||
|         string_right(temp_str, 5); | ||||
| 
 | ||||
|         uint8_t buf_key[8] = {0}; | ||||
|         if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         for(uint8_t i = 0; i < 8; i++) { | ||||
|             instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i]; | ||||
|         } | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     subghz_protocol_came_twee_remote_controller(instance); | ||||
|     return loaded; | ||||
|     if(subghz_protocol_common_to_load_protocol_from_file( | ||||
|            (SubGhzProtocolCommon*)instance, flipper_file)) { | ||||
|         subghz_protocol_came_twee_remote_controller(instance); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_came_twee_to_load_protocol(SubGhzProtocolCameTwee* instance, void* context) { | ||||
|  | ||||
| @ -48,22 +48,25 @@ void subghz_protocol_came_twee_parse( | ||||
|  */ | ||||
| void subghz_protocol_came_twee_to_str(SubGhzProtocolCameTwee* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolCameTwee instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_came_twee_to_save_str(SubGhzProtocolCameTwee* instance, string_t output); | ||||
| bool subghz_protocol_came_twee_to_save_file( | ||||
|     SubGhzProtocolCameTwee* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolCameTwee instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_came_twee_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolCameTwee* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -168,3 +168,67 @@ bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len) | ||||
|     } | ||||
|     return parsed; | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file) { | ||||
|     furi_assert(instance); | ||||
|     furi_assert(flipper_file); | ||||
|     bool res = false; | ||||
|     do { | ||||
|         if(!flipper_file_write_string_cstr(flipper_file, "Protocol", instance->name)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Protocol"); | ||||
|             break; | ||||
|         } | ||||
|         if(!flipper_file_write_uint32( | ||||
|                flipper_file, "Bit", (uint32_t*)&instance->code_last_count_bit, 1)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Bit"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         uint8_t key_data[sizeof(uint64_t)] = {0}; | ||||
|         for(size_t i = 0; i < sizeof(uint64_t); i++) { | ||||
|             key_data[sizeof(uint64_t) - i - 1] = (instance->code_last_found >> i * 8) & 0xFF; | ||||
|         } | ||||
| 
 | ||||
|         if(!flipper_file_write_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Key"); | ||||
|             break; | ||||
|         } | ||||
|         res = true; | ||||
|     } while(false); | ||||
| 
 | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_common_to_load_protocol_from_file( | ||||
|     SubGhzProtocolCommon* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     furi_assert(instance); | ||||
|     furi_assert(flipper_file); | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     uint32_t temp_data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         if(!flipper_file_read_uint32(flipper_file, "Bit", (uint32_t*)&temp_data, 1)) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Bit"); | ||||
|             break; | ||||
|         } | ||||
|         instance->code_last_count_bit = (uint8_t)temp_data; | ||||
| 
 | ||||
|         uint8_t key_data[sizeof(uint64_t)] = {0}; | ||||
|         if(!flipper_file_read_hex(flipper_file, "Key", key_data, sizeof(uint64_t))) { | ||||
|             FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing Key"); | ||||
|             break; | ||||
|         } | ||||
|         for(uint8_t i = 0; i < sizeof(uint64_t); i++) { | ||||
|             instance->code_last_found = instance->code_last_found << 8 | key_data[i]; | ||||
|         } | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
| } | ||||
|  | ||||
| @ -3,7 +3,7 @@ | ||||
| #include <m-string.h> | ||||
| #include <furi-hal.h> | ||||
| #include <stdint.h> | ||||
| #include "file-worker.h" | ||||
| #include <lib/flipper_file/flipper_file.h> | ||||
| 
 | ||||
| #define bit_read(value, bit) (((value) >> (bit)) & 0x01) | ||||
| #define bit_set(value, bit) ((value) |= (1UL << (bit))) | ||||
| @ -21,6 +21,15 @@ | ||||
| #define SUBGHZ_APP_EXTENSION ".sub" | ||||
| #define SUBGHZ_ENCODER_UPLOAD_MAX_SIZE 2048 | ||||
| 
 | ||||
| #define SUBGHZ_KEY_TAG "SubGhzParser" | ||||
| #define SUBGHZ_KEY_FILE_VERSION 1 | ||||
| #define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File" | ||||
| 
 | ||||
| #define SUBGHZ_RAW_TAG "SubGhzRAW" | ||||
| #define SUBGHZ_RAW_FILE_VERSION 1 | ||||
| #define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File" | ||||
| 
 | ||||
| 
 | ||||
| typedef enum { | ||||
|     SubGhzProtocolCommonTypeUnknown, | ||||
|     SubGhzProtocolCommonTypeStatic, | ||||
| @ -37,11 +46,14 @@ typedef void (*SubGhzProtocolCommonCallback)(SubGhzProtocolCommon* parser, void* | ||||
| typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string_t output); | ||||
| 
 | ||||
| //Get string to save
 | ||||
| typedef void (*SubGhzProtocolCommonGetStrSave)(SubGhzProtocolCommon* instance, string_t output); | ||||
| typedef bool ( | ||||
|     *SubGhzProtocolCommonSaveFile)(SubGhzProtocolCommon* instance, FlipperFile* flipper_file); | ||||
| 
 | ||||
| //Load protocol from file
 | ||||
| typedef bool ( | ||||
|     *SubGhzProtocolCommonLoadFromFile)(FileWorker* file_worker, SubGhzProtocolCommon* instance, const char* file_path); | ||||
| typedef bool (*SubGhzProtocolCommonLoadFromFile)( | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolCommon* instance, | ||||
|     const char* file_path); | ||||
| //Load protocol
 | ||||
| typedef void (*SubGhzProtocolCommonLoadFromRAW)(SubGhzProtocolCommon* instance, void* context); | ||||
| //Get upload encoder protocol
 | ||||
| @ -77,7 +89,7 @@ struct SubGhzProtocolCommon { | ||||
|     /* Dump To String */ | ||||
|     SubGhzProtocolCommonToStr to_string; | ||||
|     /* Get string to save */ | ||||
|     SubGhzProtocolCommonGetStrSave to_save_string; | ||||
|     SubGhzProtocolCommonSaveFile to_save_file; | ||||
|     /* Load protocol from file */ | ||||
|     SubGhzProtocolCommonLoadFromFile to_load_protocol_from_file; | ||||
|     /* Load protocol from RAW data */ | ||||
| @ -196,3 +208,21 @@ void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t outp | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_common_read_hex(string_t str, uint8_t* buff, uint16_t len); | ||||
| 
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolCommon instance | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_common_to_save_file(SubGhzProtocolCommon* instance, FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolCommon instance | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_common_to_load_protocol_from_file( | ||||
|     SubGhzProtocolCommon* instance, | ||||
|     FlipperFile* flipper_file); | ||||
|  | ||||
| @ -95,8 +95,6 @@ void subghz_protocol_faac_slh_parse(SubGhzProtocolFaacSLH* instance, bool level, | ||||
|         if((level) && (DURATION_DIFF(duration, instance->common.te_long * 2) < | ||||
|                        instance->common.te_delta * 3)) { | ||||
|             instance->common.parser_step = FaacSLHDecoderStepFoundPreambula; | ||||
|         } else { | ||||
|             instance->common.parser_step = FaacSLHDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case FaacSLHDecoderStepFoundPreambula: | ||||
|  | ||||
| @ -21,8 +21,8 @@ SubGhzProtocolGateTX* subghz_protocol_gate_tx_alloc(void) { | ||||
|     instance->common.te_delta = 100; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_gate_tx_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_gate_tx_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_gate_tx_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_gate_tx_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -94,8 +94,6 @@ void subghz_protocol_gate_tx_parse(SubGhzProtocolGateTX* instance, bool level, u | ||||
|                         instance->common.te_delta * 47)) { | ||||
|             //Found Preambula
 | ||||
|             instance->common.parser_step = GateTXDecoderStepFoundStartBit; | ||||
|         } else { | ||||
|             instance->common.parser_step = GateTXDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case GateTXDecoderStepFoundStartBit: | ||||
| @ -169,56 +167,22 @@ void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t out | ||||
|         instance->common.btn); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_gate_tx_to_save_str(SubGhzProtocolGateTX* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found & 0x00000000ffffffff)); | ||||
| bool subghz_protocol_gate_tx_to_save_file( | ||||
|     SubGhzProtocolGateTX* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_gate_tx_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolGateTX* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         uint32_t temp_key = 0; | ||||
|         res = sscanf(string_get_cstr(temp_str), "Key: %08lX\n", &temp_key); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_found = (uint64_t)temp_key; | ||||
|     if(subghz_protocol_common_to_load_protocol_from_file( | ||||
|            (SubGhzProtocolCommon*)instance, flipper_file)) { | ||||
|         subghz_protocol_gate_tx_check_remote_controller(instance); | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_gate_tx_to_load_protocol(SubGhzProtocolGateTX* instance, void* context) { | ||||
|  | ||||
| @ -45,22 +45,25 @@ void subghz_protocol_gate_tx_parse(SubGhzProtocolGateTX* instance, bool level, u | ||||
|  */ | ||||
| void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolGateTX instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_gate_tx_to_save_str(SubGhzProtocolGateTX* instance, string_t output); | ||||
| bool subghz_protocol_gate_tx_to_save_file( | ||||
|     SubGhzProtocolGateTX* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolGateTX instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_gate_tx_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolGateTX* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -24,8 +24,8 @@ SubGhzProtocolHormann* subghz_protocol_hormann_alloc() { | ||||
|     instance->common.te_delta = 200; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_hormann_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_hormann_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_hormann_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_hormann_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -94,8 +94,6 @@ void subghz_protocol_hormann_parse(SubGhzProtocolHormann* instance, bool level, | ||||
|         if((level) && (DURATION_DIFF(duration, instance->common.te_short * 64) < | ||||
|                        instance->common.te_delta * 64)) { | ||||
|             instance->common.parser_step = HormannDecoderStepFoundStartHeader; | ||||
|         } else { | ||||
|             instance->common.parser_step = HormannDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case HormannDecoderStepFoundStartHeader: | ||||
| @ -188,61 +186,18 @@ void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t ou | ||||
|         instance->common.btn); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_hormann_to_save_str(SubGhzProtocolHormann* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX%08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found >> 32), | ||||
|         (uint32_t)(instance->common.code_last_found & 0x00000000ffffffff)); | ||||
| bool subghz_protocol_hormann_to_save_file( | ||||
|     SubGhzProtocolHormann* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_hormann_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolHormann* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Key: ") = 5
 | ||||
|         string_right(temp_str, 5); | ||||
| 
 | ||||
|         uint8_t buf_key[8] = {0}; | ||||
|         if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         for(uint8_t i = 0; i < 8; i++) { | ||||
|             instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i]; | ||||
|         } | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_hormann_to_load_protocol(SubGhzProtocolHormann* instance, void* context) { | ||||
|  | ||||
| @ -45,22 +45,25 @@ void subghz_protocol_hormann_parse(SubGhzProtocolHormann* instance, bool level, | ||||
|  */ | ||||
| void subghz_protocol_hormann_to_str(SubGhzProtocolHormann* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolHormann instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_hormann_to_save_str(SubGhzProtocolHormann* instance, string_t output); | ||||
| bool subghz_protocol_hormann_to_save_file( | ||||
|     SubGhzProtocolHormann* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolHormann instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_hormann_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolHormann* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -94,8 +94,6 @@ void subghz_protocol_ido_parse(SubGhzProtocolIDo* instance, bool level, uint32_t | ||||
|         if((level) && (DURATION_DIFF(duration, instance->common.te_short * 10) < | ||||
|                        instance->common.te_delta * 5)) { | ||||
|             instance->common.parser_step = IDoDecoderStepFoundPreambula; | ||||
|         } else { | ||||
|             instance->common.parser_step = IDoDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case IDoDecoderStepFoundPreambula: | ||||
|  | ||||
| @ -32,8 +32,8 @@ SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc(SubGhzKeystore* keystore) { | ||||
|     instance->common.te_delta = 140; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeDynamic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_keeloq_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_keeloq_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_keeloq_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_keeloq_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -314,10 +314,7 @@ void subghz_protocol_keeloq_parse(SubGhzProtocolKeeloq* instance, bool level, ui | ||||
|            DURATION_DIFF(duration, instance->common.te_short) < instance->common.te_delta) { | ||||
|             instance->common.parser_step = KeeloqDecoderStepCheckPreambula; | ||||
|             instance->common.header_count++; | ||||
|         } else { | ||||
|             instance->common.parser_step = KeeloqDecoderStepReset; | ||||
|         } | ||||
| 
 | ||||
|         break; | ||||
|     case KeeloqDecoderStepCheckPreambula: | ||||
|         if((!level) && | ||||
| @ -422,59 +419,16 @@ void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t outp | ||||
|         instance->common.serial); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_keeloq_to_save_str(SubGhzProtocolKeeloq* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX%08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found >> 32), | ||||
|         (uint32_t)(instance->common.code_last_found & 0xFFFFFFFF)); | ||||
| bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_keeloq_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolKeeloq* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Key: ") = 5
 | ||||
|         string_right(temp_str, 5); | ||||
| 
 | ||||
|         uint8_t buf_key[8] = {0}; | ||||
|         if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         for(uint8_t i = 0; i < 8; i++) { | ||||
|             instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i]; | ||||
|         } | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_keeloq_to_load_protocol(SubGhzProtocolKeeloq* instance, void* context) { | ||||
|  | ||||
| @ -76,22 +76,23 @@ void subghz_protocol_keeloq_parse(SubGhzProtocolKeeloq* instance, bool level, ui | ||||
|  */ | ||||
| void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolKeeloq instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_keeloq_to_save_str(SubGhzProtocolKeeloq* instance, string_t output); | ||||
| bool subghz_protocol_keeloq_to_save_file(SubGhzProtocolKeeloq* instance, FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|   * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolKeeloq instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_keeloq_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolKeeloq* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -78,8 +78,6 @@ void subghz_protocol_kia_parse(SubGhzProtocolKIA* instance, bool level, uint32_t | ||||
|             instance->common.parser_step = KIADecoderStepCheckPreambula; | ||||
|             instance->common.te_last = duration; | ||||
|             instance->common.header_count = 0; | ||||
|         } else { | ||||
|             instance->common.parser_step = KIADecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case KIADecoderStepCheckPreambula: | ||||
|  | ||||
| @ -21,8 +21,8 @@ SubGhzProtocolNeroRadio* subghz_protocol_nero_radio_alloc(void) { | ||||
|     instance->common.te_delta = 80; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_nero_radio_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_nero_radio_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_nero_radio_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_nero_radio_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -84,23 +84,6 @@ void subghz_protocol_nero_radio_reset(SubGhzProtocolNeroRadio* instance) { | ||||
|     instance->common.parser_step = NeroRadioDecoderStepReset; | ||||
| } | ||||
| 
 | ||||
| /** Analysis of received data
 | ||||
|  *  | ||||
|  * @param instance SubGhzProtocolNeroRadio instance | ||||
|  */ | ||||
| // void subghz_protocol_nero_radio_check_remote_controller(SubGhzProtocolNeroRadio* instance) {
 | ||||
| //     //пока не понятно с серийником, но код статический
 | ||||
| //     // uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
 | ||||
| //     // uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
 | ||||
| //     // //uint32_t code_hop = (code_found_reverse >> 24) & 0xFFFFF;
 | ||||
| 
 | ||||
| //     // instance->common.serial = code_fix & 0xFFFFFFF;
 | ||||
| //     // instance->common.btn = (code_fix >> 28) & 0x0F;
 | ||||
| 
 | ||||
| //     //if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
 | ||||
| 
 | ||||
| // }
 | ||||
| 
 | ||||
| void subghz_protocol_nero_radio_parse( | ||||
|     SubGhzProtocolNeroRadio* instance, | ||||
|     bool level, | ||||
| @ -112,8 +95,6 @@ void subghz_protocol_nero_radio_parse( | ||||
|             instance->common.parser_step = NeroRadioDecoderStepCheckPreambula; | ||||
|             instance->common.te_last = duration; | ||||
|             instance->common.header_count = 0; | ||||
|         } else { | ||||
|             instance->common.parser_step = NeroRadioDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case NeroRadioDecoderStepCheckPreambula: | ||||
| @ -228,64 +209,18 @@ void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string | ||||
|         code_found_reverse_lo); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_nero_radio_to_save_str(SubGhzProtocolNeroRadio* instance, string_t output) { | ||||
|     uint32_t code_found_hi = instance->common.code_last_found >> 32; | ||||
|     uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff; | ||||
| 
 | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX%08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         code_found_hi, | ||||
|         code_found_lo); | ||||
| bool subghz_protocol_nero_radio_to_save_file( | ||||
|     SubGhzProtocolNeroRadio* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_nero_radio_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNeroRadio* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Key: ") = 5
 | ||||
|         string_right(temp_str, 5); | ||||
| 
 | ||||
|         uint8_t buf_key[8] = {0}; | ||||
|         if(!subghz_protocol_common_read_hex(temp_str, buf_key, 8)) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         for(uint8_t i = 0; i < 8; i++) { | ||||
|             instance->common.code_last_found = instance->common.code_last_found << 8 | buf_key[i]; | ||||
|         } | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_nero_radio_to_load_protocol(SubGhzProtocolNeroRadio* instance, void* context) { | ||||
|  | ||||
| @ -54,22 +54,25 @@ void subghz_protocol_nero_radio_parse( | ||||
|  */ | ||||
| void subghz_protocol_nero_radio_to_str(SubGhzProtocolNeroRadio* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolNeroRadio instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_nero_radio_to_save_str(SubGhzProtocolNeroRadio* instance, string_t output); | ||||
| bool subghz_protocol_nero_radio_to_save_file( | ||||
|     SubGhzProtocolNeroRadio* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile | ||||
|  * @param instance - SubGhzProtocolNeroRadio instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_nero_radio_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNeroRadio* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -21,8 +21,8 @@ SubGhzProtocolNeroSketch* subghz_protocol_nero_sketch_alloc(void) { | ||||
|     instance->common.te_delta = 150; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_nero_sketch_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_nero_sketch_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_nero_sketch_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_nero_sketch_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -85,23 +85,6 @@ void subghz_protocol_nero_sketch_reset(SubGhzProtocolNeroSketch* instance) { | ||||
|     instance->common.parser_step = NeroSketchDecoderStepReset; | ||||
| } | ||||
| 
 | ||||
| /** Analysis of received data
 | ||||
|  *  | ||||
|  * @param instance SubGhzProtocolNeroSketch instance | ||||
|  */ | ||||
| // void subghz_protocol_nero_sketch_check_remote_controller(SubGhzProtocolNeroSketch* instance) {
 | ||||
| //     //пока не понятно с серийником, но код статический
 | ||||
| //     // uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
 | ||||
| //     // uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
 | ||||
| //     // //uint32_t code_hop = (code_found_reverse >> 24) & 0xFFFFF;
 | ||||
| 
 | ||||
| //     // instance->common.serial = code_fix & 0xFFFFFFF;
 | ||||
| //     // instance->common.btn = (code_fix >> 28) & 0x0F;
 | ||||
| 
 | ||||
| //     //if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
 | ||||
| 
 | ||||
| // }
 | ||||
| 
 | ||||
| void subghz_protocol_nero_sketch_parse( | ||||
|     SubGhzProtocolNeroSketch* instance, | ||||
|     bool level, | ||||
| @ -113,8 +96,6 @@ void subghz_protocol_nero_sketch_parse( | ||||
|             instance->common.parser_step = NeroSketchDecoderStepCheckPreambula; | ||||
|             instance->common.te_last = duration; | ||||
|             instance->common.header_count = 0; | ||||
|         } else { | ||||
|             instance->common.parser_step = NeroSketchDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case NeroSketchDecoderStepCheckPreambula: | ||||
| @ -221,60 +202,18 @@ void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, stri | ||||
|         code_found_reverse_lo); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_nero_sketch_to_save_str(SubGhzProtocolNeroSketch* instance, string_t output) { | ||||
|     uint32_t code_found_hi = instance->common.code_last_found >> 32; | ||||
|     uint32_t code_found_lo = instance->common.code_last_found & 0x00000000ffffffff; | ||||
| 
 | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX%08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         code_found_hi, | ||||
|         code_found_lo); | ||||
| bool subghz_protocol_nero_sketch_to_save_file( | ||||
|     SubGhzProtocolNeroSketch* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_nero_sketch_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNeroSketch* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         uint32_t temp_key_hi = 0; | ||||
|         uint32_t temp_key_lo = 0; | ||||
|         res = sscanf(string_get_cstr(temp_str), "Key: %08lX%08lX\n", &temp_key_hi, &temp_key_lo); | ||||
|         if(res != 2) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_found = (uint64_t)temp_key_hi << 32 | temp_key_lo; | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_nero_sketch_to_load_protocol(SubGhzProtocolNeroSketch* instance, void* context) { | ||||
|  | ||||
| @ -54,22 +54,25 @@ void subghz_protocol_nero_sketch_parse( | ||||
|  */ | ||||
| void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolNeroSketch instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_nero_sketch_to_save_str(SubGhzProtocolNeroSketch* instance, string_t output); | ||||
| bool subghz_protocol_nero_sketch_to_save_file( | ||||
|     SubGhzProtocolNeroSketch* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile | ||||
|  * @param instance - SubGhzProtocolNeroSketch instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_nero_sketch_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNeroSketch* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -27,8 +27,8 @@ SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc() { | ||||
|     instance->common.te_delta = 200; | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_nice_flo_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_protocol_nice_flo_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_protocol_nice_flo_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_protocol_nice_flo_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -86,8 +86,6 @@ void subghz_protocol_nice_flo_parse(SubGhzProtocolNiceFlo* instance, bool level, | ||||
|                         instance->common.te_delta * 36)) { | ||||
|             //Found header Nice Flo
 | ||||
|             instance->common.parser_step = NiceFloDecoderStepFoundStartBit; | ||||
|         } else { | ||||
|             instance->common.parser_step = NiceFloDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case NiceFloDecoderStepFoundStartBit: | ||||
| @ -166,55 +164,18 @@ void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t o | ||||
|         code_found_reverse_lo); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_nice_flo_to_save_str(SubGhzProtocolNiceFlo* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Key: %08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         (uint32_t)(instance->common.code_last_found & 0x00000000ffffffff)); | ||||
| bool subghz_protocol_nice_flo_to_save_file( | ||||
|     SubGhzProtocolNiceFlo* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     return subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_nice_flo_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNiceFlo* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         uint32_t temp_key = 0; | ||||
|         res = sscanf(string_get_cstr(temp_str), "Key: %08lX\n", &temp_key); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_found = (uint64_t)temp_key; | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     return loaded; | ||||
|     return subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_nice_flo_to_load_protocol(SubGhzProtocolNiceFlo* instance, void* context) { | ||||
|  | ||||
| @ -45,22 +45,25 @@ void subghz_protocol_nice_flo_parse(SubGhzProtocolNiceFlo* instance, bool level, | ||||
|  */ | ||||
| void subghz_protocol_nice_flo_to_str(SubGhzProtocolNiceFlo* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzProtocolNiceFlo instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_protocol_nice_flo_to_save_str(SubGhzProtocolNiceFlo* instance, string_t output); | ||||
| bool subghz_protocol_nice_flo_to_save_file( | ||||
|     SubGhzProtocolNiceFlo* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @param instance - SubGhzProtocolNiceFlo instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_protocol_nice_flo_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolNiceFlo* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -166,8 +166,6 @@ void subghz_protocol_nice_flor_s_parse( | ||||
|                         instance->common.te_delta * 38)) { | ||||
|             //Found start header Nice Flor-S
 | ||||
|             instance->common.parser_step = NiceFlorSDecoderStepCheckHeader; | ||||
|         } else { | ||||
|             instance->common.parser_step = NiceFlorSDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case NiceFlorSDecoderStepCheckHeader: | ||||
|  | ||||
| @ -141,8 +141,8 @@ SubGhzDecoderPrinceton* subghz_decoder_princeton_alloc(void) { | ||||
|     instance->common.te_delta = 250; //50;
 | ||||
|     instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; | ||||
|     instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_decoder_princeton_to_str; | ||||
|     instance->common.to_save_string = | ||||
|         (SubGhzProtocolCommonGetStrSave)subghz_decoder_princeton_to_save_str; | ||||
|     instance->common.to_save_file = | ||||
|         (SubGhzProtocolCommonSaveFile)subghz_decoder_princeton_to_save_file; | ||||
|     instance->common.to_load_protocol_from_file = | ||||
|         (SubGhzProtocolCommonLoadFromFile)subghz_decoder_princeton_to_load_protocol_from_file; | ||||
|     instance->common.to_load_protocol = | ||||
| @ -210,8 +210,6 @@ void subghz_decoder_princeton_parse( | ||||
|             instance->common.code_found = 0; | ||||
|             instance->common.code_count_bit = 0; | ||||
|             instance->te = 0; | ||||
|         } else { | ||||
|             instance->common.parser_step = PrincetonDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case PrincetonDecoderStepSaveDuration: | ||||
| @ -293,68 +291,27 @@ void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t | ||||
|         instance->te); | ||||
| } | ||||
| 
 | ||||
| void subghz_decoder_princeton_to_save_str(SubGhzDecoderPrinceton* instance, string_t output) { | ||||
|     string_printf( | ||||
|         output, | ||||
|         "Protocol: %s\n" | ||||
|         "Bit: %d\n" | ||||
|         "Te: %d\n" | ||||
|         "Key: %08lX\n", | ||||
|         instance->common.name, | ||||
|         instance->common.code_last_count_bit, | ||||
|         instance->te, | ||||
|         (uint32_t)(instance->common.code_last_found & 0x00000000ffffffff)); | ||||
| bool subghz_decoder_princeton_to_save_file( | ||||
|     SubGhzDecoderPrinceton* instance, | ||||
|     FlipperFile* flipper_file) { | ||||
|     bool res = subghz_protocol_common_to_save_file((SubGhzProtocolCommon*)instance, flipper_file); | ||||
|     if(res) { | ||||
|         res = flipper_file_write_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1); | ||||
|         if(!res) FURI_LOG_E(SUBGHZ_KEY_TAG, "Unable to add Te"); | ||||
|     } | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| bool subghz_decoder_princeton_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzDecoderPrinceton* instance, | ||||
|     const char* file_path) { | ||||
|     bool loaded = false; | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     int res = 0; | ||||
|     int data = 0; | ||||
| 
 | ||||
|     do { | ||||
|         // Read and parse bit data from 2nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Bit: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_count_bit = (uint8_t)data; | ||||
| 
 | ||||
|         // Read and parse te data from 3nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         res = sscanf(string_get_cstr(temp_str), "Te: %d\n", &data); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->te = (uint16_t)data; | ||||
| 
 | ||||
|         // Read and parse key data from 4nd line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         uint32_t temp_key = 0; | ||||
|         res = sscanf(string_get_cstr(temp_str), "Key: %08lX\n", &temp_key); | ||||
|         if(res != 1) { | ||||
|             break; | ||||
|         } | ||||
|         instance->common.code_last_found = (uint64_t)temp_key; | ||||
|         instance->common.serial = instance->common.code_last_found >> 4; | ||||
|         instance->common.btn = (uint8_t)instance->common.code_last_found & 0x00000F; | ||||
| 
 | ||||
|         loaded = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
| 
 | ||||
|     bool loaded = subghz_protocol_common_to_load_protocol_from_file( | ||||
|         (SubGhzProtocolCommon*)instance, flipper_file); | ||||
|     if(loaded) { | ||||
|         loaded = flipper_file_read_uint32(flipper_file, "TE", (uint32_t*)&instance->te, 1); | ||||
|         if(!loaded) FURI_LOG_E(SUBGHZ_KEY_TAG, "Missing TE"); | ||||
|     } | ||||
|     return loaded; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -100,22 +100,25 @@ void subghz_decoder_princeton_parse( | ||||
|  */ | ||||
| void subghz_decoder_princeton_to_str(SubGhzDecoderPrinceton* instance, string_t output); | ||||
| 
 | ||||
| /** Get a string to save the protocol
 | ||||
| /** Adding data to a file
 | ||||
|  *  | ||||
|  * @param instance  - SubGhzDecoderPrinceton instance | ||||
|  * @param output    - the resulting string | ||||
|  * @param flipper_file - FlipperFile  | ||||
|  * @return bool | ||||
|  */ | ||||
| void subghz_decoder_princeton_to_save_str(SubGhzDecoderPrinceton* instance, string_t output); | ||||
| bool subghz_decoder_princeton_to_save_file( | ||||
|     SubGhzDecoderPrinceton* instance, | ||||
|     FlipperFile* flipper_file); | ||||
| 
 | ||||
| /** Loading protocol from file
 | ||||
|  *  | ||||
|  * @param file_worker - FileWorker file_worker | ||||
|  * @param flipper_file - FlipperFile | ||||
|  * @param instance - SubGhzDecoderPrinceton instance | ||||
|  * @param file_path - file path | ||||
|  * @return bool | ||||
|  */ | ||||
| bool subghz_decoder_princeton_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzDecoderPrinceton* instance, | ||||
|     const char* file_path); | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,4 @@ | ||||
| #include "subghz_protocol_raw.h" | ||||
| #include "file-worker.h" | ||||
| #include "../subghz_file_encoder_worker.h" | ||||
| 
 | ||||
| #define SUBGHZ_DOWNLOAD_MAX_SIZE 512 | ||||
| @ -7,9 +6,10 @@ | ||||
| struct SubGhzProtocolRAW { | ||||
|     SubGhzProtocolCommon common; | ||||
| 
 | ||||
|     int16_t* upload_raw; | ||||
|     int32_t* upload_raw; | ||||
|     uint16_t ind_write; | ||||
|     FileWorker* file_worker; | ||||
|     Storage* storage; | ||||
|     FlipperFile* flipper_file; | ||||
|     SubGhzFileEncoderWorker* file_worker_encoder; | ||||
|     uint32_t file_is_open; | ||||
|     string_t file_name; | ||||
| @ -31,7 +31,8 @@ SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) { | ||||
| 
 | ||||
|     instance->last_level = false; | ||||
| 
 | ||||
|     instance->file_worker = file_worker_alloc(false); | ||||
|     instance->storage = furi_record_open("storage"); | ||||
|     instance->flipper_file = flipper_file_alloc(instance->storage); | ||||
|     instance->file_is_open = RAWFileIsOpenClose; | ||||
|     string_init(instance->file_name); | ||||
| 
 | ||||
| @ -55,7 +56,10 @@ SubGhzProtocolRAW* subghz_protocol_raw_alloc(void) { | ||||
| void subghz_protocol_raw_free(SubGhzProtocolRAW* instance) { | ||||
|     furi_assert(instance); | ||||
|     string_clear(instance->file_name); | ||||
|     file_worker_free(instance->file_worker); | ||||
| 
 | ||||
|     flipper_file_free(instance->flipper_file); | ||||
|     furi_record_close("storage"); | ||||
| 
 | ||||
|     free(instance); | ||||
| } | ||||
| 
 | ||||
| @ -120,11 +124,11 @@ void subghz_protocol_raw_to_str(SubGhzProtocolRAW* instance, string_t output) { | ||||
|     string_cat_printf(output, "RAW Date"); | ||||
| } | ||||
| 
 | ||||
| const char* subghz_protocol_get_last_file_name(SubGhzProtocolRAW* instance) { | ||||
| const char* subghz_protocol_raw_get_last_file_name(SubGhzProtocolRAW* instance) { | ||||
|     return string_get_cstr(instance->file_name); | ||||
| } | ||||
| 
 | ||||
| void subghz_protocol_set_last_file_name(SubGhzProtocolRAW* instance, const char* name) { | ||||
| void subghz_protocol_raw_set_last_file_name(SubGhzProtocolRAW* instance, const char* name) { | ||||
|     string_printf(instance->file_name, "%s", name); | ||||
| } | ||||
| 
 | ||||
| @ -132,22 +136,21 @@ bool subghz_protocol_raw_save_to_file_init( | ||||
|     SubGhzProtocolRAW* instance, | ||||
|     const char* dev_name, | ||||
|     uint32_t frequency, | ||||
|     FuriHalSubGhzPreset preset) { | ||||
|     const char* preset) { | ||||
|     furi_assert(instance); | ||||
| 
 | ||||
|     //instance->flipper_file = flipper_file_alloc(instance->storage);
 | ||||
|     string_t dev_file_name; | ||||
|     string_init(dev_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     bool init = false; | ||||
| 
 | ||||
|     do { | ||||
|         // Create subghz folder directory if necessary
 | ||||
|         if(!file_worker_mkdir(instance->file_worker, SUBGHZ_RAW_FOLDER)) { | ||||
|         if(!storage_simply_mkdir(instance->storage, SUBGHZ_RAW_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
|         // Create saved directory if necessary
 | ||||
|         if(!file_worker_mkdir(instance->file_worker, SUBGHZ_RAW_PATH_FOLDER)) { | ||||
|         if(!storage_simply_mkdir(instance->storage, SUBGHZ_RAW_PATH_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
| @ -155,61 +158,44 @@ bool subghz_protocol_raw_save_to_file_init( | ||||
|         // 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(instance->file_worker, string_get_cstr(dev_file_name))) { | ||||
| 
 | ||||
|         if(!storage_simply_remove(instance->storage, string_get_cstr(dev_file_name))) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         // Open file
 | ||||
|         if(!file_worker_open( | ||||
|                instance->file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { | ||||
|         if(!flipper_file_open_always(instance->flipper_file, string_get_cstr(dev_file_name))) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to open file for write: %s", dev_file_name); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         // //get the name of the next free file
 | ||||
|         // file_worker_get_next_filename(
 | ||||
|         //     instance->file_worker,
 | ||||
|         //     SUBGHZ_RAW_PATH_FOLDER,
 | ||||
|         //     dev_name,
 | ||||
|         //     SUBGHZ_APP_EXTENSION,
 | ||||
|         //     temp_str);
 | ||||
| 
 | ||||
|         // string_set(instance->file_name, temp_str);
 | ||||
| 
 | ||||
|         // string_printf(
 | ||||
|         //     dev_file_name,
 | ||||
|         //     "%s/%s%s",
 | ||||
|         //     SUBGHZ_RAW_PATH_FOLDER,
 | ||||
|         //     string_get_cstr(temp_str),
 | ||||
|         //     SUBGHZ_APP_EXTENSION);
 | ||||
|         // // Open file
 | ||||
|         // if(!file_worker_open(
 | ||||
|         //        instance->file_worker,
 | ||||
|         //        string_get_cstr(dev_file_name),
 | ||||
|         //        FSAM_WRITE,
 | ||||
|         //        FSOM_CREATE_ALWAYS)) {
 | ||||
|         //     break;
 | ||||
|         // }
 | ||||
| 
 | ||||
|         //Get string frequency preset protocol
 | ||||
|         string_printf( | ||||
|             temp_str, | ||||
|             "Frequency: %d\n" | ||||
|             "Preset: %d\n" | ||||
|             "Protocol: RAW\n", | ||||
|             (int)frequency, | ||||
|             (int)preset); | ||||
| 
 | ||||
|         if(!file_worker_write( | ||||
|                instance->file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|         if(!flipper_file_write_header_cstr( | ||||
|                instance->flipper_file, SUBGHZ_RAW_FILE_TYPE, SUBGHZ_RAW_FILE_VERSION)) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add header"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         instance->upload_raw = furi_alloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(uint16_t)); | ||||
|         if(!flipper_file_write_uint32(instance->flipper_file, "Frequency", (uint32_t*)&frequency, 1)) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Frequency"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(!flipper_file_write_string_cstr(instance->flipper_file, "Preset", preset)) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Preset"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(!flipper_file_write_string_cstr(instance->flipper_file, "Protocol", instance->common.name)) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add Protocol"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         instance->upload_raw = furi_alloc(SUBGHZ_DOWNLOAD_MAX_SIZE * sizeof(int32_t)); | ||||
|         instance->file_is_open = RAWFileIsOpenWrite; | ||||
|         instance->sample_write = 0; | ||||
|         init = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
|     string_clear(dev_file_name); | ||||
| 
 | ||||
|     return init; | ||||
| @ -225,44 +211,23 @@ void subghz_protocol_raw_save_to_file_stop(SubGhzProtocolRAW* instance) { | ||||
|         instance->upload_raw = NULL; | ||||
|     } | ||||
| 
 | ||||
|     file_worker_close(instance->file_worker); | ||||
|     flipper_file_close(instance->flipper_file); | ||||
|     instance->file_is_open = RAWFileIsOpenClose; | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance) { | ||||
|     furi_assert(instance); | ||||
| 
 | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     bool is_write = false; | ||||
|     if(instance->file_is_open == RAWFileIsOpenWrite) { | ||||
|         do { | ||||
|             string_printf(temp_str, "RAW_Data: "); | ||||
| 
 | ||||
|             if(!file_worker_write( | ||||
|                    instance->file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|                 break; | ||||
|             } | ||||
| 
 | ||||
|             for(size_t i = 0; i < instance->ind_write - 1; i++) { | ||||
|                 string_printf(temp_str, "%d, ", instance->upload_raw[i]); | ||||
|                 if(!file_worker_write( | ||||
|                        instance->file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             string_printf(temp_str, "%d\n", instance->upload_raw[instance->ind_write - 1]); | ||||
|             if(!file_worker_write( | ||||
|                    instance->file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|                 break; | ||||
|             } | ||||
| 
 | ||||
|         if(!flipper_file_write_int32( | ||||
|                instance->flipper_file, "RAW_Data", instance->upload_raw, instance->ind_write)) { | ||||
|             FURI_LOG_E(SUBGHZ_RAW_TAG, "Unable to add RAW_Data"); | ||||
|         } else { | ||||
|             instance->sample_write += instance->ind_write; | ||||
|             instance->ind_write = 0; | ||||
|             is_write = true; | ||||
|         } while(0); | ||||
|         string_clear(temp_str); | ||||
|         } | ||||
|     } | ||||
|     return is_write; | ||||
| } | ||||
| @ -272,9 +237,10 @@ size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance) { | ||||
| } | ||||
| 
 | ||||
| bool subghz_protocol_raw_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolRAW* instance, | ||||
|     const char* file_path) { | ||||
|     subghz_protocol_set_last_file_name(instance, file_path); | ||||
|     furi_assert(file_path); | ||||
|     subghz_protocol_raw_set_last_file_name(instance, file_path); | ||||
|     return true; | ||||
| } | ||||
| @ -45,20 +45,20 @@ void subghz_protocol_raw_parse(SubGhzProtocolRAW* instance, bool level, uint32_t | ||||
|  */ | ||||
| void subghz_protocol_raw_to_str(SubGhzProtocolRAW* instance, string_t output); | ||||
| 
 | ||||
| const char* subghz_protocol_get_last_file_name(SubGhzProtocolRAW* instance); | ||||
| const char* subghz_protocol_raw_get_last_file_name(SubGhzProtocolRAW* instance); | ||||
| 
 | ||||
| void subghz_protocol_set_last_file_name(SubGhzProtocolRAW* instance, const char* name); | ||||
| void subghz_protocol_raw_set_last_file_name(SubGhzProtocolRAW* instance, const char* name); | ||||
| 
 | ||||
| bool subghz_protocol_raw_save_to_file_init( | ||||
|     SubGhzProtocolRAW* instance, | ||||
|     const char* dev_name, | ||||
|     uint32_t frequency, | ||||
|     FuriHalSubGhzPreset preset); | ||||
|     const char* preset); | ||||
| void subghz_protocol_raw_save_to_file_stop(SubGhzProtocolRAW* instance); | ||||
| bool subghz_protocol_raw_save_to_file_write(SubGhzProtocolRAW* instance); | ||||
| size_t subghz_protocol_raw_get_sample_write(SubGhzProtocolRAW* instance); | ||||
| 
 | ||||
| bool subghz_protocol_raw_to_load_protocol_from_file( | ||||
|     FileWorker* file_worker, | ||||
|     FlipperFile* flipper_file, | ||||
|     SubGhzProtocolRAW* instance, | ||||
|     const char* file_path); | ||||
| @ -130,8 +130,6 @@ void subghz_protocol_scher_khan_parse( | ||||
|             instance->common.parser_step = ScherKhanDecoderStepCheckPreambula; | ||||
|             instance->common.te_last = duration; | ||||
|             instance->common.header_count = 0; | ||||
|         } else { | ||||
|             instance->common.parser_step = ScherKhanDecoderStepReset; | ||||
|         } | ||||
|         break; | ||||
|     case ScherKhanDecoderStepCheckPreambula: | ||||
|  | ||||
| @ -238,7 +238,6 @@ void subghz_protocol_star_line_parse( | ||||
|                 instance->common.parser_step = StarLineDecoderStepCheckDuration; | ||||
|             } | ||||
|         } else { | ||||
|             instance->common.parser_step = StarLineDecoderStepReset; | ||||
|             instance->common.header_count = 0; | ||||
|         } | ||||
|         break; | ||||
|  | ||||
| @ -1,25 +1,28 @@ | ||||
| #include "subghz_file_encoder_worker.h" | ||||
| #include <stream_buffer.h> | ||||
| 
 | ||||
| #include "file-worker.h" | ||||
| #include <lib/flipper_file/flipper_file.h> | ||||
| #include <lib/flipper_file/file_helper.h> | ||||
| 
 | ||||
| #define SUBGHZ_FILE_ENCODER_LOAD 512 | ||||
| 
 | ||||
| struct SubGhzFileEncoderWorker { | ||||
|     FuriThread* thread; | ||||
|     StreamBufferHandle_t stream; | ||||
|     FileWorker* file_worker; | ||||
| 
 | ||||
|     Storage* storage; | ||||
|     FlipperFile* flipper_file; | ||||
| 
 | ||||
|     volatile bool worker_running; | ||||
|     bool level; | ||||
|     int16_t duration; | ||||
|     int32_t duration; | ||||
|     string_t str_data; | ||||
|     string_t file_path; | ||||
| }; | ||||
| 
 | ||||
| void subghz_file_encoder_worker_add_livel_duration( | ||||
|     SubGhzFileEncoderWorker* instance, | ||||
|     int16_t duration) { | ||||
|     int32_t duration) { | ||||
|     bool res = true; | ||||
|     if(duration < 0 && !instance->level) { | ||||
|         instance->duration += duration; | ||||
| @ -34,7 +37,7 @@ void subghz_file_encoder_worker_add_livel_duration( | ||||
|     if(res) { | ||||
|         instance->level = !instance->level; | ||||
|         instance->duration += duration; | ||||
|         xStreamBufferSend(instance->stream, &instance->duration, sizeof(int16_t), 10); | ||||
|         xStreamBufferSend(instance->stream, &instance->duration, sizeof(int32_t), 10); | ||||
|         instance->duration = 0; | ||||
|     } | ||||
| } | ||||
| @ -53,14 +56,13 @@ bool subghz_file_encoder_worker_data_parse( | ||||
|         str1 = strchr( | ||||
|             str1, | ||||
|             ' '); //if found, shift the pointer by 1 element per line "RAW_Data: -1, 2, -2..."
 | ||||
|         subghz_file_encoder_worker_add_livel_duration(instance, atoi(str1)); | ||||
|         while( | ||||
|             strchr(str1, ',') != NULL && | ||||
|             strchr(str1, ' ') != NULL && | ||||
|             ((size_t)str1 < | ||||
|              (len + | ||||
|               ind_start))) { //check that there is still an element in the line and that it has not gone beyond the line
 | ||||
|             str1 = strchr(str1, ','); | ||||
|             str1 += 2; //if found, shift the pointer by next element per line
 | ||||
|             str1 = strchr(str1, ' '); | ||||
|             str1 += 1; //if found, shift the pointer by next element per line
 | ||||
|             subghz_file_encoder_worker_add_livel_duration(instance, atoi(str1)); | ||||
|         } | ||||
|         res = true; | ||||
| @ -71,12 +73,12 @@ bool subghz_file_encoder_worker_data_parse( | ||||
| LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) { | ||||
|     furi_assert(context); | ||||
|     SubGhzFileEncoderWorker* instance = context; | ||||
|     int16_t duration; | ||||
|     int32_t duration; | ||||
|     BaseType_t xHigherPriorityTaskWoken = pdFALSE; | ||||
|     int ret = xStreamBufferReceiveFromISR( | ||||
|         instance->stream, &duration, sizeof(int16_t), &xHigherPriorityTaskWoken); | ||||
|         instance->stream, &duration, sizeof(int32_t), &xHigherPriorityTaskWoken); | ||||
|     portYIELD_FROM_ISR(xHigherPriorityTaskWoken); | ||||
|     if(ret == sizeof(int16_t)) { | ||||
|     if(ret == sizeof(int32_t)) { | ||||
|         LevelDuration level_duration = {.level = LEVEL_DURATION_RESET}; | ||||
|         if(duration < 0) { | ||||
|             level_duration = level_duration_make(false, duration * -1); | ||||
| @ -102,32 +104,33 @@ static int32_t subghz_file_encoder_worker_thread(void* context) { | ||||
|     SubGhzFileEncoderWorker* instance = context; | ||||
|     FURI_LOG_I("SubGhzFileEncoderWorker", "Worker start"); | ||||
|     bool res = false; | ||||
|     File* file = flipper_file_get_file(instance->flipper_file); | ||||
|     do { | ||||
|         if(!file_worker_open( | ||||
|                instance->file_worker, | ||||
|                string_get_cstr(instance->file_path), | ||||
|                FSAM_READ, | ||||
|                FSOM_OPEN_EXISTING)) { | ||||
|         if(!flipper_file_open_existing( | ||||
|                instance->flipper_file, string_get_cstr(instance->file_path))) { | ||||
|             FURI_LOG_E( | ||||
|                 "SubGhzFileEncoderWorker", | ||||
|                 "Unable to open file for read: %s", | ||||
|                 string_get_cstr(instance->file_path)); | ||||
|             break; | ||||
|         } | ||||
|         //todo skips 3 lines file header
 | ||||
|         if(!file_worker_read_until(instance->file_worker, instance->str_data, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         if(!file_worker_read_until(instance->file_worker, instance->str_data, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         if(!file_worker_read_until(instance->file_worker, instance->str_data, '\n')) { | ||||
|         if(!flipper_file_read_string(instance->flipper_file, "Protocol", instance->str_data)) { | ||||
|             FURI_LOG_E("SubGhzFileEncoderWorker", "Missing Protocol"); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         //skip the end of the previous line "\n"
 | ||||
|         storage_file_seek(file, 1, false); | ||||
|         res = true; | ||||
|         FURI_LOG_I("SubGhzFileEncoderWorker", "Start transmission"); | ||||
|     } while(0); | ||||
| 
 | ||||
|     while(res && instance->worker_running) { | ||||
|         size_t stream_free_byte = xStreamBufferSpacesAvailable(instance->stream); | ||||
|         if((stream_free_byte / sizeof(int16_t)) >= SUBGHZ_FILE_ENCODER_LOAD) { | ||||
|             if(file_worker_read_until(instance->file_worker, instance->str_data, '\n')) { | ||||
|         if((stream_free_byte / sizeof(int32_t)) >= SUBGHZ_FILE_ENCODER_LOAD) { | ||||
|             if(file_helper_read_line(file, instance->str_data)) { | ||||
|                 //skip the end of the previous line "\n"
 | ||||
|                 storage_file_seek(file, 1, false); | ||||
|                 if(!subghz_file_encoder_worker_data_parse( | ||||
|                        instance, | ||||
|                        string_get_cstr(instance->str_data), | ||||
| @ -146,10 +149,12 @@ static int32_t subghz_file_encoder_worker_thread(void* context) { | ||||
|         } | ||||
|     } | ||||
|     //waiting for the end of the transfer
 | ||||
|     FURI_LOG_I("SubGhzFileEncoderWorker", "End read file"); | ||||
|     while(instance->worker_running) { | ||||
|         osDelay(50); | ||||
|     } | ||||
|     file_worker_close(instance->file_worker); | ||||
|     flipper_file_close(instance->flipper_file); | ||||
| 
 | ||||
|     FURI_LOG_I("SubGhzFileEncoderWorker", "Worker stop"); | ||||
|     return 0; | ||||
| } | ||||
| @ -162,9 +167,11 @@ SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() { | ||||
|     furi_thread_set_stack_size(instance->thread, 2048); | ||||
|     furi_thread_set_context(instance->thread, instance); | ||||
|     furi_thread_set_callback(instance->thread, subghz_file_encoder_worker_thread); | ||||
|     instance->stream = xStreamBufferCreate(sizeof(int16_t) * 4096, sizeof(int16_t)); | ||||
|     instance->stream = xStreamBufferCreate(sizeof(int32_t) * 2048, sizeof(int32_t)); | ||||
| 
 | ||||
|     instance->storage = furi_record_open("storage"); | ||||
|     instance->flipper_file = flipper_file_alloc(instance->storage); | ||||
| 
 | ||||
|     instance->file_worker = file_worker_alloc(false); | ||||
|     string_init(instance->str_data); | ||||
|     string_init(instance->file_path); | ||||
|     instance->level = false; | ||||
| @ -180,7 +187,9 @@ void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) { | ||||
| 
 | ||||
|     string_clear(instance->str_data); | ||||
|     string_clear(instance->file_path); | ||||
|     file_worker_free(instance->file_worker); | ||||
| 
 | ||||
|     flipper_file_free(instance->flipper_file); | ||||
|     furi_record_close("storage"); | ||||
| 
 | ||||
|     free(instance); | ||||
| } | ||||
|  | ||||
| @ -54,7 +54,7 @@ static int32_t subghz_worker_thread_callback(void* context) { | ||||
|             xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10); | ||||
|         if(ret == sizeof(LevelDuration)) { | ||||
|             if(level_duration_is_reset(level_duration)) { | ||||
|                 printf("."); | ||||
|                 FURI_LOG_E("SubGhzWorker", "Overrun buffer");; | ||||
|                 if(instance->overrun_callback) instance->overrun_callback(instance->context); | ||||
|             } else { | ||||
|                 bool level = level_duration_get_level(level_duration); | ||||
| @ -95,7 +95,7 @@ SubGhzWorker* subghz_worker_alloc() { | ||||
|     furi_thread_set_context(instance->thread, instance); | ||||
|     furi_thread_set_callback(instance->thread, subghz_worker_thread_callback); | ||||
| 
 | ||||
|     instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration)); | ||||
|     instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 2048, sizeof(LevelDuration)); | ||||
| 
 | ||||
|     //setting filter
 | ||||
|     instance->filter_running = true; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Skorpionm
						Skorpionm