|
| 1 | +#include "subghz_i.h" |
| 2 | + |
| 3 | +//#include "assets_icons.h" |
| 4 | +//#include "subghz/types.h" |
| 5 | +#include <math.h> |
| 6 | +#include <furi.h> |
| 7 | +#include <furi_hal.h> |
| 8 | +#include <input/input.h> |
| 9 | +#include <gui/elements.h> |
| 10 | +#include <notification/notification.h> |
| 11 | +#include <notification/notification_messages.h> |
| 12 | +#include <flipper_format/flipper_format.h> |
| 13 | +//#include "views/receiver.h" |
| 14 | + |
| 15 | +#include <flipper_format/flipper_format_i.h> |
| 16 | +#include <lib/toolbox/stream/stream.h> |
| 17 | +#include <lib/subghz/protocols/raw.h> |
| 18 | + |
| 19 | +#define TAG "SubGhz" |
| 20 | +/* |
| 21 | +void subghz_set_default_preset(SubGhz* subghz) { |
| 22 | + furi_assert(subghz); |
| 23 | + subghz_txrx_set_preset( |
| 24 | + subghz->txrx, |
| 25 | + "AM650", |
| 26 | + subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), |
| 27 | + NULL, |
| 28 | + 0); |
| 29 | +}*/ |
| 30 | + |
| 31 | +/*void subghz_blink_start(SubGhz* subghz) { |
| 32 | + furi_assert(subghz); |
| 33 | + notification_message(subghz->notifications, &sequence_blink_stop); |
| 34 | + notification_message(subghz->notifications, &sequence_blink_start_magenta); |
| 35 | +}*/ |
| 36 | + |
| 37 | +/*void subghz_blink_stop(SubGhz* subghz) { |
| 38 | + furi_assert(subghz); |
| 39 | + notification_message(subghz->notifications, &sequence_blink_stop); |
| 40 | +}*/ |
| 41 | + |
| 42 | +/*bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { |
| 43 | + switch(subghz_txrx_tx_start(subghz->txrx, flipper_format)) { |
| 44 | + case SubGhzTxRxStartTxStateErrorParserOthers: |
| 45 | + dialog_message_show_storage_error( |
| 46 | + subghz->dialogs, "Error in protocol\nparameters\ndescription"); |
| 47 | + break; |
| 48 | + case SubGhzTxRxStartTxStateErrorOnlyRx: |
| 49 | + FURI_LOG_D(TAG, 'Cannot send, only RX possible'); |
| 50 | + break; |
| 51 | +
|
| 52 | + default: |
| 53 | + return true; |
| 54 | + break; |
| 55 | + } |
| 56 | + return false; |
| 57 | +}*/ |
| 58 | + |
| 59 | +/*bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { |
| 60 | + furi_assert(subghz); |
| 61 | + furi_assert(file_path); |
| 62 | +
|
| 63 | + Storage* storage = furi_record_open(RECORD_STORAGE); |
| 64 | + FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); |
| 65 | + Stream* fff_data_stream = |
| 66 | + flipper_format_get_raw_stream(subghz_txrx_get_fff_data(subghz->txrx)); |
| 67 | +
|
| 68 | + SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr; |
| 69 | + FuriString* temp_str = furi_string_alloc(); |
| 70 | + uint32_t temp_data32; |
| 71 | +
|
| 72 | + do { |
| 73 | + stream_clean(fff_data_stream); |
| 74 | + if(!flipper_format_file_open_existing(fff_data_file, file_path)) { |
| 75 | + FURI_LOG_E(TAG, "Error open file %s", file_path); |
| 76 | + break; |
| 77 | + } |
| 78 | +
|
| 79 | + if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) { |
| 80 | + FURI_LOG_E(TAG, "Missing or incorrect header"); |
| 81 | + break; |
| 82 | + } |
| 83 | +
|
| 84 | + if(((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) || |
| 85 | + (!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) && |
| 86 | + temp_data32 == SUBGHZ_KEY_FILE_VERSION) { |
| 87 | + } else { |
| 88 | + FURI_LOG_E(TAG, "Type or version mismatch"); |
| 89 | + break; |
| 90 | + } |
| 91 | +
|
| 92 | + //Load frequency |
| 93 | + if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) { |
| 94 | + FURI_LOG_E(TAG, "Missing Frequency"); |
| 95 | + break; |
| 96 | + } |
| 97 | +
|
| 98 | + if(!subghz_txrx_radio_device_is_frequecy_valid(subghz->txrx, temp_data32)) { |
| 99 | + FURI_LOG_E(TAG, "Frequency not supported"); |
| 100 | + break; |
| 101 | + } |
| 102 | +
|
| 103 | + //Load preset |
| 104 | + if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) { |
| 105 | + FURI_LOG_E(TAG, "Missing Preset"); |
| 106 | + break; |
| 107 | + } |
| 108 | +
|
| 109 | + furi_string_set_str( |
| 110 | + temp_str, subghz_txrx_get_preset_name(subghz->txrx, furi_string_get_cstr(temp_str))); |
| 111 | + if(!strcmp(furi_string_get_cstr(temp_str), "")) { |
| 112 | + break; |
| 113 | + } |
| 114 | + SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); |
| 115 | +
|
| 116 | + if(!strcmp(furi_string_get_cstr(temp_str), "CUSTOM")) { |
| 117 | + //TODO FL-3551: add Custom_preset_module |
| 118 | + //delete preset if it already exists |
| 119 | + subghz_setting_delete_custom_preset(setting, furi_string_get_cstr(temp_str)); |
| 120 | + //load custom preset from file |
| 121 | + if(!subghz_setting_load_custom_preset( |
| 122 | + setting, furi_string_get_cstr(temp_str), fff_data_file)) { |
| 123 | + FURI_LOG_E(TAG, "Missing Custom preset"); |
| 124 | + break; |
| 125 | + } |
| 126 | + } |
| 127 | + size_t preset_index = |
| 128 | + subghz_setting_get_inx_preset_by_name(setting, furi_string_get_cstr(temp_str)); |
| 129 | + subghz_txrx_set_preset( |
| 130 | + subghz->txrx, |
| 131 | + furi_string_get_cstr(temp_str), |
| 132 | + temp_data32, |
| 133 | + subghz_setting_get_preset_data(setting, preset_index), |
| 134 | + subghz_setting_get_preset_data_size(setting, preset_index)); |
| 135 | +
|
| 136 | + //Load protocol |
| 137 | + if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) { |
| 138 | + FURI_LOG_E(TAG, "Missing Protocol"); |
| 139 | + break; |
| 140 | + } |
| 141 | +
|
| 142 | + FlipperFormat* fff_data = subghz_txrx_get_fff_data(subghz->txrx); |
| 143 | + if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { |
| 144 | + //if RAW |
| 145 | + subghz->load_type_file = SubGhzLoadTypeFileRaw; |
| 146 | + subghz_protocol_raw_gen_fff_data( |
| 147 | + fff_data, file_path, subghz_txrx_radio_device_get_name(subghz->txrx)); |
| 148 | + } else { |
| 149 | + subghz->load_type_file = SubGhzLoadTypeFileKey; |
| 150 | + stream_copy_full( |
| 151 | + flipper_format_get_raw_stream(fff_data_file), |
| 152 | + flipper_format_get_raw_stream(fff_data)); |
| 153 | + } |
| 154 | +
|
| 155 | + if(subghz_txrx_load_decoder_by_name_protocol( |
| 156 | + subghz->txrx, furi_string_get_cstr(temp_str))) { |
| 157 | + //SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize( |
| 158 | + // subghz_txrx_get_decoder(subghz->txrx), fff_data); |
| 159 | + //if(status != SubGhzProtocolStatusOk) { |
| 160 | + // load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr; |
| 161 | + // break; |
| 162 | + //} |
| 163 | + } else { |
| 164 | + FURI_LOG_E(TAG, "Protocol not found"); |
| 165 | + break; |
| 166 | + } |
| 167 | +
|
| 168 | + load_key_state = SubGhzLoadKeyStateOK; |
| 169 | + } while(0); |
| 170 | +
|
| 171 | + furi_string_free(temp_str); |
| 172 | + flipper_format_free(fff_data_file); |
| 173 | + furi_record_close(RECORD_STORAGE); |
| 174 | +
|
| 175 | + switch(load_key_state) { |
| 176 | + case SubGhzLoadKeyStateParseErr: |
| 177 | + if(show_dialog) { |
| 178 | + dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile"); |
| 179 | + } |
| 180 | + return false; |
| 181 | + case SubGhzLoadKeyStateProtocolDescriptionErr: |
| 182 | + if(show_dialog) { |
| 183 | + dialog_message_show_storage_error( |
| 184 | + subghz->dialogs, "Error in protocol\nparameters\ndescription"); |
| 185 | + } |
| 186 | + return false; |
| 187 | +
|
| 188 | + case SubGhzLoadKeyStateOK: |
| 189 | + return true; |
| 190 | +
|
| 191 | + default: |
| 192 | + furi_crash("SubGhz: Unknown load_key_state."); |
| 193 | + return false; |
| 194 | + } |
| 195 | +}*/ |
| 196 | + |
| 197 | +/*SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz) { |
| 198 | + furi_assert(subghz); |
| 199 | + return subghz->load_type_file; |
| 200 | +}*/ |
| 201 | + |
| 202 | +/*bool subghz_load_protocol_from_file(SubGhz* subghz) { |
| 203 | + furi_assert(subghz); |
| 204 | +
|
| 205 | + FuriString* file_path = furi_string_alloc(); |
| 206 | +
|
| 207 | + DialogsFileBrowserOptions browser_options; |
| 208 | + dialog_file_browser_set_basic_options( |
| 209 | + &browser_options, SUBGHZ_APP_FILENAME_EXTENSION, &I_sub1_10px); |
| 210 | + browser_options.base_path = SUBGHZ_APP_FOLDER; |
| 211 | +
|
| 212 | + // Input events and views are managed by file_select |
| 213 | + bool res = dialog_file_browser_show( |
| 214 | + subghz->dialogs, subghz->file_path, subghz->file_path, &browser_options); |
| 215 | +
|
| 216 | + if(res) { |
| 217 | + res = subghz_key_load(subghz, furi_string_get_cstr(subghz->file_path), true); |
| 218 | + } |
| 219 | +
|
| 220 | + furi_string_free(file_path); |
| 221 | +
|
| 222 | + return res; |
| 223 | +}*/ |
| 224 | + |
| 225 | +/*bool subghz_file_available(SubGhz* subghz) { |
| 226 | + furi_assert(subghz); |
| 227 | + bool ret = true; |
| 228 | + Storage* storage = furi_record_open(RECORD_STORAGE); |
| 229 | +
|
| 230 | + FS_Error fs_result = |
| 231 | + storage_common_stat(storage, furi_string_get_cstr(subghz->file_path), NULL); |
| 232 | +
|
| 233 | + if(fs_result != FSE_OK) { |
| 234 | + dialog_message_show_storage_error(subghz->dialogs, "File not available\n file/directory"); |
| 235 | + ret = false; |
| 236 | + } |
| 237 | +
|
| 238 | + furi_record_close(RECORD_STORAGE); |
| 239 | + return ret; |
| 240 | +}*/ |
| 241 | + |
| 242 | +/*bool subghz_path_is_file(FuriString* path) { |
| 243 | + return furi_string_end_with(path, SUBGHZ_APP_FILENAME_EXTENSION); |
| 244 | +}*/ |
| 245 | + |
| 246 | +/*void subghz_lock(SubGhz* subghz) { |
| 247 | + furi_assert(subghz); |
| 248 | + subghz->lock = SubGhzLockOn; |
| 249 | +}*/ |
| 250 | + |
| 251 | +/*void subghz_unlock(SubGhz* subghz) { |
| 252 | + furi_assert(subghz); |
| 253 | + subghz->lock = SubGhzLockOff; |
| 254 | +}*/ |
| 255 | + |
| 256 | +/*bool subghz_is_locked(SubGhz* subghz) { |
| 257 | + furi_assert(subghz); |
| 258 | + return (subghz->lock == SubGhzLockOn); |
| 259 | +}*/ |
| 260 | + |
| 261 | +/*void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state) { |
| 262 | + furi_assert(subghz); |
| 263 | + subghz->rx_key_state = state; |
| 264 | +}*/ |
| 265 | + |
| 266 | +/*SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz) { |
| 267 | + furi_assert(subghz); |
| 268 | + return subghz->rx_key_state; |
| 269 | +}*/ |
0 commit comments