[FL-2230] SubGhz: protocol API refactoring (#969)
* SubGhz: protocols library refactoring * SubGhz: new architecture and refactoring * SubGhz: simplify protocol structure, remove unused types * SubGhz: rename Subghz to SubGhz * SubGhz: add environment concept Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_read_raw.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol_raw.h>
|
||||
#include <lib/subghz/subghz_parser.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
#define RAW_FILE_NAME "Raw_signal_"
|
||||
#define TAG "SubGhzSceneReadRAW"
|
||||
|
||||
bool subghz_scene_read_raw_update_filename(SubGhz* subghz) {
|
||||
bool ret = false;
|
||||
//set the path to read the file
|
||||
if(strcmp(
|
||||
subghz_protocol_raw_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result),
|
||||
"")) {
|
||||
string_t temp_str;
|
||||
string_init_printf(
|
||||
temp_str,
|
||||
"%s",
|
||||
subghz_protocol_raw_get_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
do {
|
||||
if(!flipper_format_rewind(subghz->txrx->fff_data)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(subghz->txrx->fff_data, "File_name", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing File_name");
|
||||
break;
|
||||
}
|
||||
|
||||
path_extract_filename_no_ext(string_get_cstr(temp_str), temp_str);
|
||||
strcpy(subghz->file_name, string_get_cstr(temp_str));
|
||||
string_printf(
|
||||
temp_str, "%s/%s%s", SUBGHZ_APP_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION);
|
||||
|
||||
subghz_protocol_raw_set_last_file_name(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
ret = true;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
string_clear(temp_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ static void subghz_scene_read_raw_update_statusbar(void* context) {
|
||||
string_clear(modulation_str);
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_callback(SubghzCustomEvent event, void* context) {
|
||||
void subghz_scene_read_raw_callback(SubGhzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
@@ -61,7 +61,7 @@ void subghz_scene_read_raw_callback_end_tx(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubghzCustomEventViewReadRAWSendStop);
|
||||
subghz->view_dispatcher, SubGhzCustomEventViewReadRAWSendStop);
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_on_enter(void* context) {
|
||||
@@ -69,46 +69,43 @@ void subghz_scene_read_raw_on_enter(void* context) {
|
||||
|
||||
switch(subghz->txrx->rx_key_state) {
|
||||
case SubGhzRxKeyStateBack:
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusIDLE, "");
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "");
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWLoad:
|
||||
subghz_read_raw_set_status(
|
||||
subghz->subghz_read_raw, SubghzReadRAWStatusLoadKeyTX, subghz->file_name);
|
||||
subghz->subghz_read_raw, SubGhzReadRAWStatusLoadKeyTX, subghz->file_name);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWSave:
|
||||
subghz_read_raw_set_status(
|
||||
subghz->subghz_read_raw, SubghzReadRAWStatusSaveKey, subghz->file_name);
|
||||
subghz->subghz_read_raw, SubGhzReadRAWStatusSaveKey, subghz->file_name);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
default:
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusStart, "");
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubGhzReadRAWStatusStart, "");
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
}
|
||||
|
||||
subghz_scene_read_raw_update_statusbar(subghz);
|
||||
|
||||
//set callback view raw
|
||||
subghz_read_raw_set_callback(subghz->subghz_read_raw, subghz_scene_read_raw_callback, subghz);
|
||||
|
||||
subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, "RAW");
|
||||
furi_assert(subghz->txrx->protocol_result);
|
||||
subghz->txrx->decoder_result =
|
||||
subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, "RAW");
|
||||
furi_assert(subghz->txrx->decoder_result);
|
||||
|
||||
subghz_worker_set_pair_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_raw_parse);
|
||||
|
||||
subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result,
|
||||
subghz_scene_read_raw_callback_end_tx,
|
||||
subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReadRAW);
|
||||
//set filter RAW feed
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_RAW);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
|
||||
}
|
||||
|
||||
bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubghzCustomEventViewReadRAWBack:
|
||||
case SubGhzCustomEventViewReadRAWBack:
|
||||
//Stop TX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
@@ -121,7 +118,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
};
|
||||
//Stop save file
|
||||
subghz_protocol_raw_save_to_file_stop(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result);
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
//needed save?
|
||||
if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) ||
|
||||
@@ -144,7 +141,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWTXRXStop:
|
||||
case SubGhzCustomEventViewReadRAWTXRXStop:
|
||||
//Stop TX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
@@ -159,27 +156,27 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWConfig:
|
||||
case SubGhzCustomEventViewReadRAWConfig:
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet);
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWErase:
|
||||
case SubGhzCustomEventViewReadRAWErase:
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWVibro:
|
||||
case SubGhzCustomEventViewReadRAWVibro:
|
||||
notification_message(subghz->notifications, &sequence_single_vibro);
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWMore:
|
||||
case SubGhzCustomEventViewReadRAWMore:
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSet);
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
|
||||
return true;
|
||||
@@ -188,7 +185,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWSendStart:
|
||||
case SubGhzCustomEventViewReadRAWSendStart:
|
||||
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
//start send
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
@@ -197,10 +195,17 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
if(!subghz_tx_start(subghz)) {
|
||||
//ToDo FIX
|
||||
|
||||
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
} else {
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzSend);
|
||||
// set callback end tx
|
||||
subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
||||
(SubGhzProtocolEncoderRAW*)subghz->txrx->transmitter->protocol_instance,
|
||||
subghz_scene_read_raw_callback_end_tx,
|
||||
subghz);
|
||||
subghz->state_notifications = SubGhzNotificationStateTX;
|
||||
}
|
||||
}
|
||||
@@ -208,7 +213,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWSendStop:
|
||||
case SubGhzCustomEventViewReadRAWSendStop:
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
@@ -218,13 +223,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWIDLE:
|
||||
case SubGhzCustomEventViewReadRAWIDLE:
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz_protocol_raw_save_to_file_stop(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result);
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
|
||||
subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, RAW_FILE_NAME);
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
@@ -232,16 +238,16 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWREC:
|
||||
case SubGhzCustomEventViewReadRAWREC:
|
||||
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
subghz_get_preset_name(subghz, subghz->error_str);
|
||||
//subghz_get_preset_name(subghz, subghz->error_str);
|
||||
if(subghz_protocol_raw_save_to_file_init(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result,
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result,
|
||||
RAW_FILE_NAME,
|
||||
subghz->txrx->frequency,
|
||||
string_get_cstr(subghz->error_str))) {
|
||||
subghz->txrx->preset)) {
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzRawRec);
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
@@ -258,10 +264,10 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SubghzCustomEventViewReadRAWSave:
|
||||
case SubGhzCustomEventViewReadRAWSave:
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerSetRAW);
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
}
|
||||
@@ -278,7 +284,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
subghz_read_raw_update_sample_write(
|
||||
subghz->subghz_read_raw,
|
||||
subghz_protocol_raw_get_sample_write(
|
||||
(SubGhzProtocolRAW*)subghz->txrx->protocol_result));
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result));
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, furi_hal_subghz_get_rssi());
|
||||
break;
|
||||
case SubGhzNotificationStateTX:
|
||||
@@ -302,7 +308,6 @@ void subghz_scene_read_raw_on_exit(void* context) {
|
||||
};
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
|
||||
//Сallback restoration
|
||||
subghz_worker_set_pair_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_parse);
|
||||
//filter restoration
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
}
|
||||
|
Reference in New Issue
Block a user