Просмотр исходного кода

Seems to be sending, but doesn't close nicely

David Lee 2 лет назад
Родитель
Сommit
49cfa7f322

+ 5 - 2
helpers/subghz/subghz.c

@@ -1,7 +1,7 @@
 /* Reduced variant of the Flipper Zero SubGhz Class */
 
 #include "subghz_i.h"
-#include "../meal_pager_storage.h"
+//#include "../meal_pager_storage.h"
 
 static SubGhz* subghz_alloc() {
     SubGhz* subghz = malloc(sizeof(SubGhz));
@@ -28,6 +28,8 @@ void subghz_send(void* context) {
     UNUSED(context);
     SubGhz* subghz = subghz_alloc();
 
+    subghz_load_protocol_from_file(subghz);
+
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* ff = flipper_format_file_alloc(storage);
 
@@ -38,7 +40,8 @@ void subghz_send(void* context) {
         return;
     }
 
-    subghz_txrx_tx_start(subghz->txrx, ff);
+    //subghz_txrx_tx_start(subghz->txrx, ff);
+    subghz_txrx_tx_start(subghz->txrx, subghz_txrx_get_fff_data(subghz->txrx)); //Seems like it must be done this way
 
     flipper_format_rewind(ff);
     flipper_format_file_close(ff);

+ 1 - 1
helpers/subghz/subghz.h

@@ -2,6 +2,6 @@
 
 #include "subghz_i.h"
 
-typedef struct SubGhz SubGhz;
+//typedef struct SubGhz SubGhz;
 
 void subghz_send(void* context);

+ 31 - 27
helpers/subghz/subghz_i.c

@@ -1,7 +1,7 @@
 #include "subghz_i.h"
 
 //#include "assets_icons.h"
-//#include "subghz/types.h"
+#include "subghz/types.h"
 #include <math.h>
 #include <furi.h>
 #include <furi_hal.h>
@@ -16,7 +16,7 @@
 #include <lib/toolbox/stream/stream.h>
 #include <lib/subghz/protocols/raw.h>
 
-#define TAG "SubGhz"
+//#define TAG "SubGhz"
 /*
 void subghz_set_default_preset(SubGhz* subghz) {
     furi_assert(subghz);
@@ -45,10 +45,10 @@ void subghz_set_default_preset(SubGhz* subghz) {
     return false;
 }*/
 
-/*bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
+bool subghz_key_load(SubGhz* subghz, const char* file_path) { //, bool show_dialog) {
     furi_assert(subghz);
     furi_assert(file_path);
-
+    
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
     Stream* fff_data_stream =
@@ -57,7 +57,7 @@ void subghz_set_default_preset(SubGhz* subghz) {
     SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr;
     FuriString* temp_str = furi_string_alloc();
     uint32_t temp_data32;
-
+    
     do {
         stream_clean(fff_data_stream);
         if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
@@ -143,12 +143,12 @@ void subghz_set_default_preset(SubGhz* subghz) {
 
         if(subghz_txrx_load_decoder_by_name_protocol(
                subghz->txrx, furi_string_get_cstr(temp_str))) {
-            //SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(
-            //    subghz_txrx_get_decoder(subghz->txrx), fff_data);
-            //if(status != SubGhzProtocolStatusOk) {
-            //    load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr;
-            //    break;
-            //}
+            SubGhzProtocolStatus status = subghz_protocol_decoder_base_deserialize(
+                subghz_txrx_get_decoder(subghz->txrx), fff_data);
+            if(status != SubGhzProtocolStatusOk) {
+                load_key_state = SubGhzLoadKeyStateProtocolDescriptionErr;
+                break;
+            }
         } else {
             FURI_LOG_E(TAG, "Protocol not found");
             break;
@@ -163,15 +163,15 @@ void subghz_set_default_preset(SubGhz* subghz) {
 
     switch(load_key_state) {
     case SubGhzLoadKeyStateParseErr:
-        if(show_dialog) {
-            dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
-        }
+        //if(show_dialog) {
+        //    dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
+        //}
         return false;
     case SubGhzLoadKeyStateProtocolDescriptionErr:
-        if(show_dialog) {
-            dialog_message_show_storage_error(
-                subghz->dialogs, "Error in protocol\nparameters\ndescription");
-        }
+        //if(show_dialog) {
+        //    dialog_message_show_storage_error(
+        //        subghz->dialogs, "Error in protocol\nparameters\ndescription");
+        //}
         return false;
 
     case SubGhzLoadKeyStateOK:
@@ -181,19 +181,22 @@ void subghz_set_default_preset(SubGhz* subghz) {
         furi_crash("SubGhz: Unknown load_key_state.");
         return false;
     }
-}*/
+    return false;
+}
 
 /*SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz) {
     furi_assert(subghz);
     return subghz->load_type_file;
 }*/
 
-/*bool subghz_load_protocol_from_file(SubGhz* subghz) {
+bool subghz_load_protocol_from_file(SubGhz* subghz) {
     furi_assert(subghz);
 
-    FuriString* file_path = furi_string_alloc();
+    //FuriString* file_path = furi_string_alloc();
+
+    bool res = false;
 
-    DialogsFileBrowserOptions browser_options;
+    /*DialogsFileBrowserOptions browser_options;
     dialog_file_browser_set_basic_options(
         &browser_options, SUBGHZ_APP_FILENAME_EXTENSION, &I_sub1_10px);
     browser_options.base_path = SUBGHZ_APP_FOLDER;
@@ -202,14 +205,15 @@ void subghz_set_default_preset(SubGhz* subghz) {
     bool res = dialog_file_browser_show(
         subghz->dialogs, subghz->file_path, subghz->file_path, &browser_options);
 
-    if(res) {
-        res = subghz_key_load(subghz, furi_string_get_cstr(subghz->file_path), true);
-    }
+    if(res) {*/
+        //res = subghz_key_load(subghz, furi_string_get_cstr(subghz->file_path), true);
+       res = subghz_key_load(subghz, MEAL_PAGER_TMP_FILE); //, true);
+    //}
 
-    furi_string_free(file_path);
+    //furi_string_free(file_path);
 
     return res;
-}*/
+}
 
 /*bool subghz_file_available(SubGhz* subghz) {
     furi_assert(subghz);

+ 6 - 3
helpers/subghz/subghz_i.h

@@ -4,6 +4,7 @@
 #include "subghz_error_type.h"
 #include <lib/subghz/types.h>
 #include "subghz.h"
+#include "../meal_pager_storage.h"
 
 /*#include "views/receiver.h"
 #include "views/transmitter.h"
@@ -38,6 +39,8 @@
 
 #define SUBGHZ_MAX_LEN_NAME 64
 
+typedef struct SubGhz SubGhz;
+
 struct SubGhz {
     SubGhzTxRx* txrx;
     FuriString* file_path;
@@ -57,7 +60,7 @@ struct SubGhz {
     //SubGhzThresholdRssi* threshold_rssi;
     //SubGhzRxKeyState rx_key_state;
     //SubGhzHistory* history;
-    //SubGhzLoadTypeFile load_type_file;
+    SubGhzLoadTypeFile load_type_file;
     //void* rpc_ctx;
 };
 
@@ -68,8 +71,8 @@ struct SubGhz {
 //bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
 //void subghz_dialog_message_show_only_rx(SubGhz* subghz);
 
-//bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog);
-//bool subghz_load_protocol_from_file(SubGhz* subghz);
+bool subghz_key_load(SubGhz* subghz, const char* file_path); //, bool show_dialog);
+bool subghz_load_protocol_from_file(SubGhz* subghz);
 //bool subghz_file_available(SubGhz* subghz);
 //SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz);
 

+ 28 - 17
helpers/subghz/subghz_txrx.c

@@ -43,7 +43,7 @@ SubGhzTxRx* subghz_txrx_alloc() {
     subghz_txrx_speaker_set_state(instance, SubGhzSpeakerStateDisable);
 
     instance->worker = subghz_worker_alloc();
-/*    instance->fff_data = flipper_format_string_alloc(); */
+    instance->fff_data = flipper_format_string_alloc(); 
 
     instance->environment = subghz_environment_alloc();
     instance->is_database_loaded =
@@ -90,7 +90,7 @@ void subghz_txrx_free(SubGhzTxRx* instance) {
     subghz_worker_free(instance->worker);
     subghz_receiver_free(instance->receiver);
     subghz_environment_free(instance->environment);
-    /*flipper_format_free(instance->fff_data);*/
+    flipper_format_free(instance->fff_data);
     furi_string_free(instance->preset->name);
     subghz_setting_free(instance->setting);
 
@@ -117,7 +117,7 @@ void subghz_txrx_set_preset(
     preset->data_size = preset_data_size;
 }
 
-/*const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) {
+const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset) {
     UNUSED(instance);
     const char* preset_name = "";
     if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
@@ -134,7 +134,7 @@ void subghz_txrx_set_preset(
         FURI_LOG_E(TAG, "Unknown preset");
     }
     return preset_name;
-}*/
+}
 
 /*SubGhzRadioPreset subghz_txrx_get_preset(SubGhzTxRx* instance) {
     furi_assert(instance);
@@ -244,6 +244,7 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
     
     FURI_LOG_D(TAG, "starting loop in subghz_txrx_tx_start");
     do {
+        FURI_LOG_D(TAG, "looping");
         if(!flipper_format_rewind(flipper_format)) {
             FURI_LOG_E(TAG, "Rewind error");
             break;
@@ -256,6 +257,7 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
             FURI_LOG_E(TAG, "Unable Repeat");
             break;
         }
+        //FURI_LOG_D(TAG, "File loaded");
         ret = SubGhzTxRxStartTxStateOk;
         
         SubGhzRadioPreset* preset = instance->preset;
@@ -263,18 +265,24 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
             subghz_transmitter_alloc_init(instance->environment, furi_string_get_cstr(temp_str));
 
         if(instance->transmitter) {
+            FURI_LOG_D(TAG, "transmitter found");
             if(subghz_transmitter_deserialize(instance->transmitter, flipper_format) ==
                SubGhzProtocolStatusOk) {
+            //if (false) {
+                FURI_LOG_D(TAG, "deserialization");
                 if(strcmp(furi_string_get_cstr(preset->name), "") != 0) {
+                    FURI_LOG_D(TAG, "got preset name");
                     subghz_txrx_begin(
                         instance,
                         subghz_setting_get_preset_data_by_name(
                             instance->setting, furi_string_get_cstr(preset->name))); 
+                    FURI_LOG_D(TAG, "loaded preset by name");
                     if(preset->frequency) {
                         if(!subghz_txrx_tx(instance, preset->frequency)) {
                             FURI_LOG_E(TAG, "Only Rx");
                             ret = SubGhzTxRxStartTxStateErrorOnlyRx;
                         }
+                        FURI_LOG_D(TAG, "got frequency");
                     } else {
                         ret = SubGhzTxRxStartTxStateErrorParserOthers;
                     }
@@ -287,17 +295,20 @@ SubGhzTxRxStartTxState subghz_txrx_tx_start(SubGhzTxRx* instance, FlipperFormat*
                 
                 if(ret == SubGhzTxRxStartTxStateOk) {
                     //Start TX
+                    FURI_LOG_D(TAG, "starting Async TX");
                     subghz_devices_start_async_tx(
                         instance->radio_device, subghz_transmitter_yield, instance->transmitter);
                 }
             } else {
+                FURI_LOG_D(TAG, "no deserialization");
                 ret = SubGhzTxRxStartTxStateErrorParserOthers;
             }
         } else {
             ret = SubGhzTxRxStartTxStateErrorParserOthers;
         }
         if(ret != SubGhzTxRxStartTxStateOk) {
-            subghz_transmitter_free(instance->transmitter);
+            FURI_LOG_D(TAG, "state not ok");
+            //subghz_transmitter_free(instance->transmitter); // Crashes here
             if(instance->txrx_state != SubGhzTxRxStateIDLE) {
                 subghz_txrx_idle(instance);
             }
@@ -344,15 +355,15 @@ static void subghz_txrx_tx_stop(SubGhzTxRx* instance) {
     subghz_txrx_speaker_off(instance);
 }
 
-/*FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
+FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance) {
     furi_assert(instance);
     return instance->fff_data;
-}*/
+}
 
-/*SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) {
+SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance) {
     furi_assert(instance);
     return instance->setting;
-}*/
+}
 
 void subghz_txrx_stop(SubGhzTxRx* instance) {
     furi_assert(instance);
@@ -496,7 +507,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
     return instance->speaker_state;
 }*/
 
-/*bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) {
+bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol) {
     furi_assert(instance);
     furi_assert(name_protocol);
     bool res = false;
@@ -506,12 +517,12 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
         res = true;
     }
     return res;
-}*/
+}
 
-/*SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) {
+SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) {
     furi_assert(instance);
     return instance->decoder_result;
-}*/
+}
 
 /*bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance) {
     furi_assert(instance);
@@ -608,12 +619,12 @@ SubGhzRadioDeviceType
     return subghz_devices_get_rssi(instance->radio_device);
 }*/
 
-/*const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
+const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) {
     furi_assert(instance);
     return subghz_devices_get_name(instance->radio_device);
-}*/
+}
 
-/*bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
+bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) {
     furi_assert(instance);
     return subghz_devices_is_frequency_valid(instance->radio_device, frequency);
-}*/
+}

+ 7 - 7
helpers/subghz/subghz_txrx.h

@@ -64,7 +64,7 @@ void subghz_txrx_set_preset(
  * @param preset String of preset 
  * @return const char*  Name of preset
  */
-//const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset);
+const char* subghz_txrx_get_preset_name(SubGhzTxRx* instance, const char* preset);
 
 /**
  * Get of preset
@@ -204,7 +204,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
  * @param name_protocol Name protocol
  * @return bool True if the decoder is loaded 
  */
-//bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol);
+bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* name_protocol);
 
 /**
  * Get decoder
@@ -212,7 +212,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
  * @param instance Pointer to a SubGhzTxRx
  * @return SubGhzProtocolDecoderBase* Pointer to a SubGhzProtocolDecoderBase
  */
-//SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance);
+SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance);
 
 /**
  * Set callback for save data
@@ -232,7 +232,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
  * @param instance Pointer to a SubGhzTxRx
  * @return FlipperFormat* 
  */
-//FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance);
+FlipperFormat* subghz_txrx_get_fff_data(SubGhzTxRx* instance);
 
 /**
  * Get pointer to a SugGhzSetting
@@ -240,7 +240,7 @@ void subghz_txrx_speaker_set_state(SubGhzTxRx* instance, SubGhzSpeakerState stat
  * @param instance Pointer to a SubGhzTxRx
  * @return SubGhzSetting* 
  */
-//SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance);
+SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* instance);
 
 /**
  * Is it possible to save this protocol
@@ -326,11 +326,11 @@ SubGhzRadioDeviceType
 * @param instance Pointer to a SubGhzTxRx
 * @return const char* Name of installed radio device
 */
-//const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
+const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance);
 
 /* Get get intelligence whether frequency the selected radio device to use
 *
 * @param instance Pointer to a SubGhzTxRx
 * @return bool True if the frequency is valid
 */
-//bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);
+bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency);

+ 4 - 4
helpers/subghz/subghz_txrx_i.h

@@ -8,9 +8,9 @@ struct SubGhzTxRx {
     SubGhzEnvironment* environment;
     SubGhzReceiver* receiver;
     SubGhzTransmitter* transmitter;
-    /*SubGhzProtocolDecoderBase* decoder_result;
+    SubGhzProtocolDecoderBase* decoder_result;
     FlipperFormat* fff_data;
-*/
+
     SubGhzRadioPreset* preset;
     SubGhzSetting* setting;
 
@@ -24,6 +24,6 @@ struct SubGhzTxRx {
     const SubGhzDevice* radio_device;
     SubGhzRadioDeviceType radio_device_type;
 
-    /*SubGhzTxRxNeedSaveCallback need_save_callback;
-    void* need_save_context;*/
+    SubGhzTxRxNeedSaveCallback need_save_callback;
+    void* need_save_context;
 };