SubGhz: refactoring

This commit is contained in:
gid9798 2023-05-09 18:24:25 +03:00
parent a2fbe7fab8
commit 8ae2cb1d32
8 changed files with 75 additions and 52 deletions

View File

@ -125,14 +125,14 @@ bool subghz_scene_decode_raw_start(SubGhz* subghz) {
bool subghz_scene_decode_raw_next(SubGhz* subghz) {
LevelDuration level_duration;
SubGhzReceiver* receiver = subghz_txrx_get_receiver(subghz->txrx);
for(uint32_t read = SAMPLES_TO_READ_PER_TICK; read > 0; --read) {
level_duration =
subghz_file_encoder_worker_get_level_duration(subghz->decode_raw_file_worker_encoder);
if(!level_duration_is_reset(level_duration)) {
bool level = level_duration_get_level(level_duration);
uint32_t duration = level_duration_get_duration(level_duration);
subghz_receiver_decode(subghz->txrx->receiver, level, duration);
subghz_receiver_decode(receiver, level, duration);
} else {
subghz->decode_raw_state = SubGhzDecodeRawStateLoaded;
subghz->state_notifications = SubGhzNotificationStateIDLE;
@ -167,8 +167,7 @@ void subghz_scene_decode_raw_on_enter(void* context) {
subghz_view_receiver_set_callback(
subghz->subghz_receiver, subghz_scene_decode_raw_callback, subghz);
subghz_receiver_set_rx_callback(
subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz);
subghz_txrx_receiver_set_filter(subghz->txrx, SubGhzProtocolFlag_Decodable);
@ -214,7 +213,7 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) {
subghz->in_decoder_scene = false;
subghz->in_decoder_scene_skip = false;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz);
if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) {
subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder);

View File

@ -228,11 +228,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
DOLPHIN_DEED(DolphinDeedSubGhzSend);
}
// set callback end tx
subghz_protocol_raw_file_encoder_worker_set_callback_end(
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(
subghz->txrx->transmitter),
subghz_scene_read_raw_callback_end_tx,
subghz);
subghz_txrx_set_raw_file_encoder_worker_set_callback_end(
subghz->txrx, subghz_scene_read_raw_callback_end_tx, subghz);
subghz->state_notifications = SubGhzNotificationStateTx;
}
} else {

View File

@ -153,32 +153,31 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz_scene_receiver_update_statusbar(subghz);
subghz_view_receiver_set_callback(
subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
subghz_receiver_set_rx_callback(
subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz);
// TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here
// Needs to be done after subghz refactoring merge!!!
if(subghz->ignore_starline == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Star Line")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver);
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}
if(subghz->ignore_auto_alarms == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "KIA Seed")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver);
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Scher-Khan")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver);
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}
if(subghz->ignore_magellan == true) {
if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Magellan")) {
subghz_protocol_decoder_base_set_decoder_callback(
subghz_txrx_get_decoder(subghz->txrx), NULL, subghz->txrx->receiver);
subghz_txrx_get_decoder(subghz->txrx), NULL, NULL);
}
}
@ -205,7 +204,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz_txrx_stop(subghz->txrx);
subghz_hopper_set_state(subghz->txrx, SubGhzHopperStateOFF);
subghz->idx_menu_chosen = 0;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz);
if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateAddKey) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateExit);

View File

@ -57,15 +57,16 @@ void subghz_scene_save_name_on_enter(void* context) {
if(!subghz_path_is_file(subghz->file_path)) {
char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0};
if(furi_hal_subghz_get_timestamp_file_names()) {
if(subghz->txrx->decoder_result != 0x0) {
if(subghz->txrx->decoder_result != NULL) {
if(strlen(subghz->txrx->decoder_result->protocol->name) != 0) {
SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx);
if(decoder_result != 0x0) {
if(decoder_result != NULL) {
if(strlen(decoder_result->protocol->name) != 0) {
if(scene_manager_has_previous_scene(
subghz->scene_manager, SubGhzSceneSetType)) {
subghz_scene_save_name_get_timefilename(file_name, "S", true);
} else {
subghz_scene_save_name_get_timefilename(
file_name, subghz->txrx->decoder_result->protocol->name, false);
file_name, decoder_result->protocol->name, false);
}
} else {
@ -155,8 +156,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
} else {
subghz_save_protocol_to_file(
subghz,
subghz_history_get_raw_data(
subghz->history, subghz->idx_menu_chosen),
subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen),
furi_string_get_cstr(subghz->file_path));
}
}

View File

@ -40,7 +40,7 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event)
} else {
subghz->decode_raw_state = SubGhzDecodeRawStateStart;
subghz->idx_menu_chosen = 0;
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
subghz_txrx_set_rx_calback(subghz->txrx, NULL, subghz);
if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) {
subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder);

View File

@ -368,7 +368,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) {
subghz->gui = NULL;
if(!alloc_for_tx_only) {
subghz_last_settings_free(subghz->last_settings);
subghz_last_settings_free(subghz->last_settings); //TODO always allocated
}
// threshold rssi

View File

@ -3,6 +3,33 @@
#define TAG "SubGhz"
struct SubGhzTxRx {
SubGhzWorker* worker;
SubGhzEnvironment* environment;
SubGhzReceiver* receiver;
SubGhzTransmitter* transmitter;
SubGhzProtocolDecoderBase* decoder_result;
FlipperFormat* fff_data;
SubGhzRadioPreset* preset;
SubGhzSetting* setting;
uint8_t hopper_timeout;
uint8_t hopper_idx_frequency;
bool load_database;
SubGhzHopperState hopper_state;
SubGhzTxRxState txrx_state;
SubGhzSpeakerState speaker_state;
SubGhzTxRxNeedSaveCallback need_save_callback;
void* need_save_context;
bool debug_pin_state;
};
SubGhzTxRx* subghz_txrx_alloc() {
SubGhzTxRx* txrx = malloc(sizeof(SubGhzTxRx));
txrx->setting = subghz_setting_alloc();
@ -541,6 +568,25 @@ void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter
subghz_receiver_set_filter(txrx->receiver, filter);
}
void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context) {
subghz_receiver_set_rx_callback(txrx->receiver, callback, context);
}
void subghz_txrx_set_raw_file_encoder_worker_set_callback_end(
SubGhzTxRx* txrx,
SubGhzProtocolEncoderRAWCallbackEnd callback,
void* context) {
subghz_protocol_raw_file_encoder_worker_set_callback_end(
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(txrx->transmitter),
callback,
context);
}
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx) {
furi_assert(txrx);
return txrx->receiver;
}
//#############Create new Key##############
#include <lib/subghz/protocols/protocol_items.h>
#include <lib/subghz/protocols/keeloq.h>

View File

@ -5,38 +5,12 @@
#include <lib/subghz/subghz_setting.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/transmitter.h>
#include <lib/subghz/protocols/raw.h>
#include "subghz_history.h"
typedef void (*SubGhzTxRxNeedSaveCallback)(void* context);
struct SubGhzTxRx {
SubGhzWorker* worker;
SubGhzEnvironment* environment;
SubGhzReceiver* receiver;
SubGhzTransmitter* transmitter;
SubGhzProtocolDecoderBase* decoder_result;
FlipperFormat* fff_data;
SubGhzRadioPreset* preset;
SubGhzSetting* setting;
uint8_t hopper_timeout;
uint8_t hopper_idx_frequency;
bool load_database;
SubGhzHopperState hopper_state;
SubGhzTxRxState txrx_state;
SubGhzSpeakerState speaker_state;
SubGhzTxRxNeedSaveCallback need_save_callback;
void* need_save_context;
bool debug_pin_state;
};
typedef struct SubGhzTxRx SubGhzTxRx;
SubGhzTxRx* subghz_txrx_alloc();
@ -96,6 +70,14 @@ bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type);
void subghz_txrx_receiver_set_filter(SubGhzTxRx* txrx, SubGhzProtocolFlag filter);
void subghz_txrx_set_rx_calback(SubGhzTxRx* txrx, SubGhzReceiverCallback callback, void* context);
void subghz_txrx_set_raw_file_encoder_worker_set_callback_end(
SubGhzTxRx* txrx,
SubGhzProtocolEncoderRAWCallbackEnd callback,
void* context);
SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* txrx); // TODO use only in DecodeRaw
//#############Create new Key##############
bool subghz_gen_data_protocol(
void* context,