163be139eb
* SubGhz: add protocol DataRAW (binarization of data quantized by the minimum correlated duration) * SubGhz: fix name history * SubGhz: add encoder Data_RAW protocol * SubGhz: decreasing the size of the LevelDuration structure * SubGhz: history, added check that there is free RAM * SubGhz: checking for free memory, support to pass without gap * SubGhz: add running average to average the result, auto cut noise at the end of a burst * SubGhz: support for repeating sequences * SubGhz: fix secplus_v2 decoder * SubGhz: bin_RAW fix add history * SubGhz: add debug * SubGhz: debug refactoring * FURI_LOG: add FURI_LOG_RAW_x formatted string output like printf * SubGhz: fix new FURI_LOG metod * FURI_LOG: fix unit test * SubGhz: add enable/disable BinRAW protocol decoding * SubGhz: fix PVS * SubGhz: forcibly turn off the speaker when exiting SubGhz * SubGhz: adaptive adjustment to the noise level Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
246 lines
9.0 KiB
C
246 lines
9.0 KiB
C
#include "../subghz_i.h"
|
|
#include "../views/receiver.h"
|
|
#include <dolphin/dolphin.h>
|
|
#include <lib/subghz/protocols/bin_raw.h>
|
|
|
|
static const NotificationSequence subghs_sequence_rx = {
|
|
&message_green_255,
|
|
|
|
&message_vibro_on,
|
|
&message_note_c6,
|
|
&message_delay_50,
|
|
&message_sound_off,
|
|
&message_vibro_off,
|
|
|
|
&message_delay_50,
|
|
NULL,
|
|
};
|
|
|
|
static const NotificationSequence subghs_sequence_rx_locked = {
|
|
&message_green_255,
|
|
|
|
&message_display_backlight_on,
|
|
|
|
&message_vibro_on,
|
|
&message_note_c6,
|
|
&message_delay_50,
|
|
&message_sound_off,
|
|
&message_vibro_off,
|
|
|
|
&message_delay_500,
|
|
|
|
&message_display_backlight_off,
|
|
NULL,
|
|
};
|
|
|
|
static void subghz_scene_receiver_update_statusbar(void* context) {
|
|
SubGhz* subghz = context;
|
|
FuriString* history_stat_str;
|
|
history_stat_str = furi_string_alloc();
|
|
if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) {
|
|
FuriString* frequency_str;
|
|
FuriString* modulation_str;
|
|
|
|
frequency_str = furi_string_alloc();
|
|
modulation_str = furi_string_alloc();
|
|
|
|
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
|
|
|
subghz_view_receiver_add_data_statusbar(
|
|
subghz->subghz_receiver,
|
|
furi_string_get_cstr(frequency_str),
|
|
furi_string_get_cstr(modulation_str),
|
|
furi_string_get_cstr(history_stat_str));
|
|
|
|
furi_string_free(frequency_str);
|
|
furi_string_free(modulation_str);
|
|
} else {
|
|
subghz_view_receiver_add_data_statusbar(
|
|
subghz->subghz_receiver, furi_string_get_cstr(history_stat_str), "", "");
|
|
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
|
}
|
|
furi_string_free(history_stat_str);
|
|
}
|
|
|
|
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
|
|
furi_assert(context);
|
|
SubGhz* subghz = context;
|
|
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
|
}
|
|
|
|
static void subghz_scene_add_to_history_callback(
|
|
SubGhzReceiver* receiver,
|
|
SubGhzProtocolDecoderBase* decoder_base,
|
|
void* context) {
|
|
furi_assert(context);
|
|
SubGhz* subghz = context;
|
|
FuriString* str_buff;
|
|
str_buff = furi_string_alloc();
|
|
|
|
if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) {
|
|
furi_string_reset(str_buff);
|
|
|
|
subghz->state_notifications = SubGhzNotificationStateRxDone;
|
|
|
|
subghz_history_get_text_item_menu(
|
|
subghz->txrx->history, str_buff, subghz_history_get_item(subghz->txrx->history) - 1);
|
|
subghz_view_receiver_add_item_to_menu(
|
|
subghz->subghz_receiver,
|
|
furi_string_get_cstr(str_buff),
|
|
subghz_history_get_type_protocol(
|
|
subghz->txrx->history, subghz_history_get_item(subghz->txrx->history) - 1));
|
|
|
|
subghz_scene_receiver_update_statusbar(subghz);
|
|
}
|
|
subghz_receiver_reset(receiver);
|
|
furi_string_free(str_buff);
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
|
}
|
|
|
|
void subghz_scene_receiver_on_enter(void* context) {
|
|
SubGhz* subghz = context;
|
|
|
|
FuriString* str_buff;
|
|
str_buff = furi_string_alloc();
|
|
|
|
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
|
|
subghz_preset_init(
|
|
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
|
subghz_history_reset(subghz->txrx->history);
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
|
|
}
|
|
|
|
subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz->lock);
|
|
|
|
//Load history to receiver
|
|
subghz_view_receiver_exit(subghz->subghz_receiver);
|
|
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
|
|
furi_string_reset(str_buff);
|
|
subghz_history_get_text_item_menu(subghz->txrx->history, str_buff, i);
|
|
subghz_view_receiver_add_item_to_menu(
|
|
subghz->subghz_receiver,
|
|
furi_string_get_cstr(str_buff),
|
|
subghz_history_get_type_protocol(subghz->txrx->history, i));
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
|
}
|
|
furi_string_free(str_buff);
|
|
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->state_notifications = SubGhzNotificationStateRx;
|
|
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
|
subghz_rx_end(subghz);
|
|
};
|
|
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
|
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
|
subghz_begin(
|
|
subghz,
|
|
subghz_setting_get_preset_data_by_name(
|
|
subghz->setting, furi_string_get_cstr(subghz->txrx->preset->name)));
|
|
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
|
}
|
|
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
|
|
|
|
//to use a universal decoder, we are looking for a link to it
|
|
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
|
subghz->txrx->receiver, SUBGHZ_PROTOCOL_BIN_RAW_NAME);
|
|
furi_assert(subghz->txrx->decoder_result);
|
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
|
|
}
|
|
|
|
bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
|
SubGhz* subghz = context;
|
|
bool consumed = false;
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
switch(event.event) {
|
|
case SubGhzCustomEventViewReceiverBack:
|
|
// Stop CC1101 Rx
|
|
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
|
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
|
subghz_rx_end(subghz);
|
|
subghz_sleep(subghz);
|
|
};
|
|
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
|
subghz->txrx->idx_menu_chosen = 0;
|
|
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
|
|
|
|
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
|
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
|
} else {
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
|
subghz_preset_init(
|
|
subghz,
|
|
"AM650",
|
|
subghz_setting_get_default_frequency(subghz->setting),
|
|
NULL,
|
|
0);
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
subghz->scene_manager, SubGhzSceneStart);
|
|
}
|
|
consumed = true;
|
|
break;
|
|
case SubGhzCustomEventViewReceiverOK:
|
|
subghz->txrx->idx_menu_chosen =
|
|
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
|
|
DOLPHIN_DEED(DolphinDeedSubGhzReceiverInfo);
|
|
consumed = true;
|
|
break;
|
|
case SubGhzCustomEventViewReceiverConfig:
|
|
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
|
subghz->txrx->idx_menu_chosen =
|
|
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
|
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
|
consumed = true;
|
|
break;
|
|
case SubGhzCustomEventViewReceiverOffDisplay:
|
|
notification_message(subghz->notifications, &sequence_display_backlight_off);
|
|
consumed = true;
|
|
break;
|
|
case SubGhzCustomEventViewReceiverUnlock:
|
|
subghz->lock = SubGhzLockOff;
|
|
consumed = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} else if(event.type == SceneManagerEventTypeTick) {
|
|
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
|
subghz_hopper_update(subghz);
|
|
subghz_scene_receiver_update_statusbar(subghz);
|
|
}
|
|
|
|
//get RSSI
|
|
float rssi = furi_hal_subghz_get_rssi();
|
|
subghz_receiver_rssi(subghz->subghz_receiver, rssi);
|
|
subghz_protocol_decoder_bin_raw_data_input_rssi(
|
|
(SubGhzProtocolDecoderBinRAW*)subghz->txrx->decoder_result, rssi);
|
|
|
|
switch(subghz->state_notifications) {
|
|
case SubGhzNotificationStateRx:
|
|
notification_message(subghz->notifications, &sequence_blink_cyan_10);
|
|
break;
|
|
case SubGhzNotificationStateRxDone:
|
|
if(subghz->lock != SubGhzLockOn) {
|
|
notification_message(subghz->notifications, &subghs_sequence_rx);
|
|
} else {
|
|
notification_message(subghz->notifications, &subghs_sequence_rx_locked);
|
|
}
|
|
subghz->state_notifications = SubGhzNotificationStateRx;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return consumed;
|
|
}
|
|
|
|
void subghz_scene_receiver_on_exit(void* context) {
|
|
UNUSED(context);
|
|
}
|