[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:
Skorpionm
2022-03-03 13:48:56 +04:00
committed by GitHub
parent 052237f8c9
commit 3164184bbc
173 changed files with 9836 additions and 8486 deletions
+12 -12
View File
@@ -23,12 +23,12 @@ static int32_t subghz_chat_worker_thread(void* context) {
SubGhzChatWorker* instance = context;
FURI_LOG_I(TAG, "Worker start");
char c;
SubghzChatEvent event;
event.event = SubghzChatEventUserEntrance;
SubGhzChatEvent event;
event.event = SubGhzChatEventUserEntrance;
osMessageQueuePut(instance->event_queue, &event, 0, 0);
while(instance->worker_running) {
if(furi_hal_vcp_rx_with_timeout((uint8_t*)&c, 1, 1000) == 1) {
event.event = SubghzChatEventInputData;
event.event = SubGhzChatEventInputData;
event.c = c;
osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);
}
@@ -41,13 +41,13 @@ static int32_t subghz_chat_worker_thread(void* context) {
static void subghz_chat_worker_update_rx_event_chat(void* context) {
furi_assert(context);
SubGhzChatWorker* instance = context;
SubghzChatEvent event;
SubGhzChatEvent event;
if((millis() - instance->last_time_rx_data) > SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) {
event.event = SubghzChatEventNewMessage;
event.event = SubGhzChatEventNewMessage;
osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);
}
instance->last_time_rx_data = millis();
event.event = SubghzChatEventRXData;
event.event = SubGhzChatEventRXData;
osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);
}
@@ -55,12 +55,12 @@ SubGhzChatWorker* subghz_chat_worker_alloc() {
SubGhzChatWorker* instance = malloc(sizeof(SubGhzChatWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzChat");
furi_thread_set_name(instance->thread, "SubGhzChat");
furi_thread_set_stack_size(instance->thread, 2048);
furi_thread_set_context(instance->thread, instance);
furi_thread_set_callback(instance->thread, subghz_chat_worker_thread);
instance->subghz_txrx = subghz_tx_rx_worker_alloc();
instance->event_queue = osMessageQueueNew(80, sizeof(SubghzChatEvent), NULL);
instance->event_queue = osMessageQueueNew(80, sizeof(SubGhzChatEvent), NULL);
return instance;
}
@@ -109,18 +109,18 @@ bool subghz_chat_worker_is_running(SubGhzChatWorker* instance) {
return instance->worker_running;
}
SubghzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) {
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) {
furi_assert(instance);
SubghzChatEvent event;
SubGhzChatEvent event;
if(osMessageQueueGet(instance->event_queue, &event, NULL, osWaitForever) == osOK) {
return event;
} else {
event.event = SubghzChatEventNoEvent;
event.event = SubGhzChatEventNoEvent;
return event;
}
}
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubghzChatEvent* event) {
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event) {
furi_assert(instance);
osMessageQueuePut(instance->event_queue, event, 0, osWaitForever);
}
+11 -11
View File
@@ -4,26 +4,26 @@
typedef struct SubGhzChatWorker SubGhzChatWorker;
typedef enum {
SubghzChatEventNoEvent,
SubghzChatEventUserEntrance,
SubghzChatEventUserExit,
SubghzChatEventInputData,
SubghzChatEventRXData,
SubghzChatEventNewMessage,
} SubghzChatEventType;
SubGhzChatEventNoEvent,
SubGhzChatEventUserEntrance,
SubGhzChatEventUserExit,
SubGhzChatEventInputData,
SubGhzChatEventRXData,
SubGhzChatEventNewMessage,
} SubGhzChatEventType;
typedef struct {
SubghzChatEventType event;
SubGhzChatEventType event;
char c;
} SubghzChatEvent;
} SubGhzChatEvent;
SubGhzChatWorker* subghz_chat_worker_alloc();
void subghz_chat_worker_free(SubGhzChatWorker* instance);
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency);
void subghz_chat_worker_stop(SubGhzChatWorker* instance);
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance);
SubghzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance);
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubghzChatEvent* event);
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance);
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event);
size_t subghz_chat_worker_available(SubGhzChatWorker* instance);
size_t subghz_chat_worker_read(SubGhzChatWorker* instance, uint8_t* data, size_t size);
bool subghz_chat_worker_write(SubGhzChatWorker* instance, uint8_t* data, size_t size);
@@ -1,46 +1,46 @@
#pragma once
typedef enum {
SubghzCustomEventManagerNoSet = 0,
SubghzCustomEventManagerSet,
SubghzCustomEventManagerSetRAW,
SubGhzCustomEventManagerNoSet = 0,
SubGhzCustomEventManagerSet,
SubGhzCustomEventManagerSetRAW,
SubghzCustomEventSceneDeleteSuccess = 100,
SubghzCustomEventSceneDelete,
SubghzCustomEventSceneDeleteRAW,
SubghzCustomEventSceneDeleteRAWBack,
SubGhzCustomEventSceneDeleteSuccess = 100,
SubGhzCustomEventSceneDelete,
SubGhzCustomEventSceneDeleteRAW,
SubGhzCustomEventSceneDeleteRAWBack,
SubghzCustomEventSceneReceiverInfoTxStart,
SubghzCustomEventSceneReceiverInfoTxStop,
SubghzCustomEventSceneReceiverInfoSave,
SubghzCustomEventSceneSaveName,
SubghzCustomEventSceneSaveSuccess,
SubghzCustomEventSceneShowErrorBack,
SubghzCustomEventSceneShowErrorOk,
SubghzCustomEventSceneShowErrorSub,
SubghzCustomEventSceneShowOnlyRX,
SubGhzCustomEventSceneReceiverInfoTxStart,
SubGhzCustomEventSceneReceiverInfoTxStop,
SubGhzCustomEventSceneReceiverInfoSave,
SubGhzCustomEventSceneSaveName,
SubGhzCustomEventSceneSaveSuccess,
SubGhzCustomEventSceneShowErrorBack,
SubGhzCustomEventSceneShowErrorOk,
SubGhzCustomEventSceneShowErrorSub,
SubGhzCustomEventSceneShowOnlyRX,
SubghzCustomEventSceneExit,
SubghzCustomEventSceneStay,
SubGhzCustomEventSceneExit,
SubGhzCustomEventSceneStay,
SubghzCustomEventViewReceverOK,
SubghzCustomEventViewReceverConfig,
SubghzCustomEventViewReceverBack,
SubGhzCustomEventViewReceverOK,
SubGhzCustomEventViewReceverConfig,
SubGhzCustomEventViewReceverBack,
SubghzCustomEventViewReadRAWBack,
SubghzCustomEventViewReadRAWIDLE,
SubghzCustomEventViewReadRAWREC,
SubghzCustomEventViewReadRAWConfig,
SubghzCustomEventViewReadRAWErase,
SubghzCustomEventViewReadRAWSendStart,
SubghzCustomEventViewReadRAWSendStop,
SubghzCustomEventViewReadRAWSave,
SubghzCustomEventViewReadRAWVibro,
SubghzCustomEventViewReadRAWTXRXStop,
SubghzCustomEventViewReadRAWMore,
SubGhzCustomEventViewReadRAWBack,
SubGhzCustomEventViewReadRAWIDLE,
SubGhzCustomEventViewReadRAWREC,
SubGhzCustomEventViewReadRAWConfig,
SubGhzCustomEventViewReadRAWErase,
SubGhzCustomEventViewReadRAWSendStart,
SubGhzCustomEventViewReadRAWSendStop,
SubGhzCustomEventViewReadRAWSave,
SubGhzCustomEventViewReadRAWVibro,
SubGhzCustomEventViewReadRAWTXRXStop,
SubGhzCustomEventViewReadRAWMore,
SubghzCustomEventViewTransmitterBack,
SubghzCustomEventViewTransmitterSendStart,
SubghzCustomEventViewTransmitterSendStop,
SubghzCustomEventViewTransmitterError,
} SubghzCustomEvent;
SubGhzCustomEventViewTransmitterBack,
SubGhzCustomEventViewTransmitterSendStart,
SubGhzCustomEventViewTransmitterSendStop,
SubGhzCustomEventViewTransmitterError,
} SubGhzCustomEvent;
@@ -145,7 +145,7 @@ SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc() {
SubGhzFrequencyAnalyzerWorker* instance = malloc(sizeof(SubGhzFrequencyAnalyzerWorker));
instance->thread = furi_thread_alloc();
furi_thread_set_name(instance->thread, "SubghzFAWorker");
furi_thread_set_name(instance->thread, "SubGhzFAWorker");
furi_thread_set_stack_size(instance->thread, 2048);
furi_thread_set_context(instance->thread, instance);
furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread);
@@ -5,7 +5,7 @@ void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* co
furi_assert(context);
SubGhz* subghz = context;
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneDelete);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneDelete);
}
}
@@ -31,8 +31,7 @@ void subghz_scene_delete_on_enter(void* context) {
AlignTop,
FontSecondary,
string_get_cstr(modulation_str));
subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text);
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text);
widget_add_string_multiline_element(
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
@@ -43,13 +42,13 @@ void subghz_scene_delete_on_enter(void* context) {
widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDelete) {
if(event.event == SubGhzCustomEventSceneDelete) {
strcpy(subghz->file_name_tmp, subghz->file_name);
if(subghz_delete_file(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
@@ -6,10 +6,10 @@ void subghz_scene_delete_raw_callback(GuiButtonType result, InputType type, void
SubGhz* subghz = context;
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteRAW);
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteRAW);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteRAWBack);
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteRAWBack);
}
}
@@ -49,13 +49,13 @@ void subghz_scene_delete_raw_on_enter(void* context) {
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_delete_raw_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
bool subghz_scene_delete_raw_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDeleteRAW) {
if(event.event == SubGhzCustomEventSceneDeleteRAW) {
strcpy(subghz->file_name_tmp, subghz->file_name);
if(subghz_delete_file(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
@@ -64,7 +64,7 @@ bool subghz_scene_delete_raw_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.event == SubghzCustomEventSceneDeleteRAWBack) {
} else if(event.event == SubGhzCustomEventSceneDeleteRAWBack) {
return scene_manager_previous_scene(subghz->scene_manager);
}
}
@@ -4,7 +4,7 @@
void subghz_scene_delete_success_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteSuccess);
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteSuccess);
}
void subghz_scene_delete_success_on_enter(void* context) {
@@ -18,14 +18,14 @@ void subghz_scene_delete_success_on_enter(void* context) {
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_delete_success_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
}
bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneDeleteSuccess) {
if(event.event == SubGhzCustomEventSceneDeleteSuccess) {
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneSaved)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
@@ -2,7 +2,7 @@
#include "../views/subghz_frequency_analyzer.h"
#include <dolphin/dolphin.h>
void subghz_scene_frequency_analyzer_callback(SubghzCustomEvent event, void* context) {
void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
@@ -13,7 +13,7 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {
DOLPHIN_DEED(DolphinDeedSubGhzFrequencyAnalyzer);
subghz_frequency_analyzer_set_callback(
subghz->subghz_frequency_analyzer, subghz_scene_frequency_analyzer_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer);
}
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
@@ -30,7 +30,7 @@ void subghz_scene_more_raw_on_enter(void* context) {
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneMoreRAW));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
}
bool subghz_scene_more_raw_on_event(void* context, SceneManagerEvent event) {
@@ -39,7 +39,7 @@ bool subghz_scene_more_raw_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexDelete) {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerNoSet);
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneMoreRAW, SubmenuIndexDelete);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteRAW);
@@ -6,9 +6,9 @@ void subghz_scene_need_saving_callback(GuiButtonType result, InputType type, voi
SubGhz* subghz = context;
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneStay);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneStay);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneExit);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneExit);
}
}
@@ -31,7 +31,7 @@ void subghz_scene_need_saving_on_enter(void* context) {
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Exit", subghz_scene_need_saving_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
@@ -41,11 +41,11 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
scene_manager_previous_scene(subghz->scene_manager);
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneStay) {
if(event.event == SubGhzCustomEventSceneStay) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
scene_manager_previous_scene(subghz->scene_manager);
return true;
} else if(event.event == SubghzCustomEventSceneExit) {
} else if(event.event == SubGhzCustomEventSceneExit) {
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
scene_manager_search_and_switch_to_previous_scene(
@@ -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);
}
@@ -1,5 +1,5 @@
#include "../subghz_i.h"
#include "../views/subghz_receiver.h"
#include "../views/receiver.h"
static void subghz_scene_receiver_update_statusbar(void* context) {
SubGhz* subghz = context;
@@ -14,7 +14,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
subghz_receiver_add_data_statusbar(
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver,
string_get_cstr(frequency_str),
string_get_cstr(modulation_str),
@@ -23,36 +23,41 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
string_clear(frequency_str);
string_clear(modulation_str);
} else {
subghz_receiver_add_data_statusbar(
subghz_view_receiver_add_data_statusbar(
subghz->subghz_receiver, string_get_cstr(history_stat_str), "", "");
subghz->state_notifications = SubGhzNotificationStateIDLE;
}
string_clear(history_stat_str);
}
void subghz_scene_receiver_callback(SubghzCustomEvent event, void* context) {
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
void subghz_scene_add_to_history_callback(SubGhzProtocolCommon* parser, void* context) {
static void subghz_scene_add_to_history_callback(
SubGhzReceiver* receiver,
SubGhzProtocolDecoderBase* decoder_base,
void* context) {
furi_assert(context);
SubGhz* subghz = context;
string_t str_buff;
string_init(str_buff);
if(subghz_history_add_to_history(
subghz->txrx->history, parser, subghz->txrx->frequency, subghz->txrx->preset)) {
subghz_parser_reset(subghz->txrx->parser);
subghz->txrx->history, decoder_base, subghz->txrx->frequency, subghz->txrx->preset)) {
subghz_receiver_reset(receiver);
string_reset(str_buff);
subghz_history_get_text_item_menu(
subghz->txrx->history, str_buff, subghz_history_get_item(subghz->txrx->history) - 1);
subghz_receiver_add_item_to_menu(
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
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);
}
string_clear(str_buff);
@@ -70,11 +75,11 @@ void subghz_scene_receiver_on_enter(void* context) {
}
//Load history to receiver
subghz_receiver_exit(subghz->subghz_receiver);
subghz_view_receiver_exit(subghz->subghz_receiver);
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
string_reset(str_buff);
subghz_history_get_text_item_menu(subghz->txrx->history, str_buff, i);
subghz_receiver_add_item_to_menu(
subghz_view_receiver_add_item_to_menu(
subghz->subghz_receiver,
string_get_cstr(str_buff),
subghz_history_get_type_protocol(subghz->txrx->history, i));
@@ -82,8 +87,10 @@ void subghz_scene_receiver_on_enter(void* context) {
}
string_clear(str_buff);
subghz_scene_receiver_update_statusbar(subghz);
subghz_receiver_set_callback(subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
subghz_parser_enable_dump(subghz->txrx->parser, subghz_scene_add_to_history_callback, 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) {
@@ -94,9 +101,9 @@ void subghz_scene_receiver_on_enter(void* context) {
subghz_begin(subghz, subghz->txrx->preset);
subghz_rx(subghz, subghz->txrx->frequency);
}
subghz_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewReceiver);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
}
bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
@@ -104,7 +111,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubghzCustomEventViewReceverBack:
case SubGhzCustomEventViewReceverBack:
// Stop CC1101 Rx
subghz->state_notifications = SubGhzNotificationStateIDLE;
@@ -116,7 +123,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
subghz->txrx->idx_menu_chosen = 0;
subghz_parser_enable_dump(subghz->txrx->parser, NULL, subghz);
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
@@ -127,14 +134,16 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
}
return true;
break;
case SubghzCustomEventViewReceverOK:
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
case SubGhzCustomEventViewReceverOK:
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
return true;
break;
case SubghzCustomEventViewReceverConfig:
case SubGhzCustomEventViewReceverConfig:
subghz->state_notifications = SubGhzNotificationStateIDLE;
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
subghz->txrx->idx_menu_chosen =
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
return true;
break;
@@ -127,7 +127,7 @@ void subghz_scene_receiver_config_on_enter(void* context) {
variable_item_set_current_value_text(item, subghz_frequencies_text[value_index]);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubghzCustomEventManagerSet) {
SubGhzCustomEventManagerSet) {
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
@@ -151,7 +151,7 @@ void subghz_scene_receiver_config_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, preset_text[value_index]);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewVariableItemList);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
}
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
@@ -163,5 +163,5 @@ void subghz_scene_receiver_config_on_exit(void* context) {
SubGhz* subghz = context;
variable_item_list_reset(subghz->variable_item_list);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerNoSet);
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
}
@@ -8,25 +8,24 @@ void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, v
if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStart);
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStart);
} else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStop);
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStop);
} else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoSave);
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSave);
}
}
static bool subghz_scene_receiver_info_update_parser(void* context) {
SubGhz* subghz = context;
subghz->txrx->protocol_result = subghz_parser_get_by_name(
subghz->txrx->parser,
subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
subghz->txrx->protocol_result->to_load_protocol(
subghz->txrx->protocol_result,
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver,
subghz_history_get_protocol_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
if(subghz->txrx->decoder_result) {
subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result,
subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
subghz->txrx->frequency =
subghz_history_get_frequency(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
@@ -68,8 +67,7 @@ void subghz_scene_receiver_info_on_enter(void* context) {
AlignTop,
FontSecondary,
string_get_cstr(modulation_str));
subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text);
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text);
widget_add_string_multiline_element(
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
@@ -77,14 +75,19 @@ void subghz_scene_receiver_info_on_enter(void* context) {
string_clear(modulation_str);
string_clear(text);
if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file &&
strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) ==
SubGhzProtocolFlag_Save) {
widget_add_button_element(
subghz->widget,
GuiButtonTypeRight,
"Save",
subghz_scene_receiver_info_callback,
subghz);
}
if(((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) ==
SubGhzProtocolFlag_Send) &&
subghz->txrx->decoder_result->protocol->encoder->deserialize &&
subghz->txrx->decoder_result->protocol->type == SubGhzProtocolTypeStatic) {
widget_add_button_element(
subghz->widget,
GuiButtonTypeCenter,
@@ -92,20 +95,19 @@ void subghz_scene_receiver_info_on_enter(void* context) {
subghz_scene_receiver_info_callback,
subghz);
}
} else {
widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51);
widget_add_string_element(
subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
}
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) {
//CC1101 Stop RX -> Start TX
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
subghz->txrx->hopper_state = SubGhzHopperStatePause;
@@ -118,14 +120,17 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
}
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE ||
subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
if(!subghz_tx_start(subghz)) {
if(!subghz_tx_start(
subghz,
subghz_history_get_raw_data(
subghz->txrx->history, subghz->txrx->idx_menu_chosen))) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
subghz->state_notifications = SubGhzNotificationStateTX;
}
}
return true;
} else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
} else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) {
//CC1101 Stop Tx -> Start RX
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
@@ -140,7 +145,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
}
subghz->state_notifications = SubGhzNotificationStateRX;
return true;
} else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
//CC1101 Stop RX -> Save
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
@@ -153,8 +158,9 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
if(!subghz_scene_receiver_info_update_parser(subghz)) {
return false;
}
if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file &&
strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) ==
SubGhzProtocolFlag_Save) {
subghz_file_name_clear(subghz);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
}
@@ -1,13 +1,13 @@
#include "../subghz_i.h"
#include <lib/toolbox/random_name.h>
#include "../helpers/subghz_custom_event.h"
#include <lib/subghz/protocols/subghz_protocol_raw.h>
#include <lib/subghz/protocols/raw.h>
#include <gui/modules/validators.h>
void subghz_scene_save_name_text_input_callback(void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneSaveName);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveName);
}
void subghz_scene_save_name_on_enter(void* context) {
@@ -24,10 +24,10 @@ void subghz_scene_save_name_on_enter(void* context) {
} else {
strcpy(subghz->file_name_tmp, subghz->file_name);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubghzCustomEventManagerNoSet) {
SubGhzCustomEventManagerNoSet) {
subghz_get_next_name_file(subghz);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) ==
SubghzCustomEventManagerSetRAW) {
SubGhzCustomEventManagerSetRAW) {
dev_name_empty = true;
}
}
@@ -46,7 +46,7 @@ void subghz_scene_save_name_on_enter(void* context) {
validator_is_file_alloc_init(SUBGHZ_APP_FOLDER, SUBGHZ_APP_EXTENSION);
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTextInput);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
}
bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
@@ -56,22 +56,35 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
scene_manager_previous_scene(subghz->scene_manager);
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneSaveName) {
if(event.event == SubGhzCustomEventSceneSaveName) {
if(strcmp(subghz->file_name, "")) {
if(strcmp(subghz->file_name_tmp, "")) {
if(!subghz_rename_file(subghz)) {
return false;
}
} else {
subghz_save_protocol_to_file(subghz, subghz->file_name);
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType) !=
SubGhzCustomEventManagerNoSet) {
subghz_save_protocol_to_file(
subghz, subghz->txrx->fff_data, subghz->file_name);
scene_manager_set_scene_state(
subghz->scene_manager,
SubGhzSceneSetType,
SubGhzCustomEventManagerNoSet);
} else {
subghz_save_protocol_to_file(
subghz,
subghz_history_get_raw_data(
subghz->txrx->history, subghz->txrx->idx_menu_chosen),
subghz->file_name);
}
}
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
SubghzCustomEventManagerNoSet) {
subghz_protocol_raw_set_last_file_name(
(SubGhzProtocolRAW*)subghz->txrx->protocol_result, subghz->file_name);
SubGhzCustomEventManagerNoSet) {
subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, subghz->file_name);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubghzCustomEventManagerNoSet);
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
} else {
subghz_file_name_clear(subghz);
}
@@ -5,7 +5,7 @@
void subghz_scene_save_success_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneSaveSuccess);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveSuccess);
}
void subghz_scene_save_success_on_enter(void* context) {
@@ -20,13 +20,13 @@ void subghz_scene_save_success_on_enter(void* context) {
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_save_success_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
}
bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneSaveSuccess) {
if(event.event == SubGhzCustomEventSceneSaveSuccess) {
if(!scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneReceiver)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWSave;
@@ -4,7 +4,7 @@ void subghz_scene_saved_on_enter(void* context) {
SubGhz* subghz = context;
if(subghz_load_protocol_from_file(subghz)) {
if((!strcmp(subghz->txrx->protocol_result->name, "RAW"))) {
if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
} else {
@@ -38,7 +38,7 @@ void subghz_scene_saved_menu_on_enter(void* context) {
subghz->submenu,
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSavedMenu));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
}
bool subghz_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
@@ -1,6 +1,11 @@
#include "../subghz_i.h"
#include "../lib/subghz/protocols/subghz_protocol_keeloq.h"
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/blocks/math.h>
#include <dolphin/dolphin.h>
#include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/stream.h>
#define TAG "SubGhzSetType"
enum SubmenuIndex {
SubmenuIndexPricenton,
@@ -15,15 +20,52 @@ enum SubmenuIndex {
SubmenuIndexDoorHan,
};
bool subghz_scene_set_type_submenu_to_find_protocol(void* context, const char* protocol_name) {
bool subghz_scene_set_type_submenu_gen_data_protocol(
void* context,
const char* protocol_name,
uint64_t key,
uint32_t bit) {
furi_assert(context);
SubGhz* subghz = context;
subghz->txrx->protocol_result = subghz_parser_get_by_name(subghz->txrx->parser, protocol_name);
if(subghz->txrx->protocol_result == NULL) {
bool res = false;
subghz->txrx->decoder_result =
subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name);
if(subghz->txrx->decoder_result == NULL) {
string_set(subghz->error_str, "Protocol not found");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
return false;
}
return true;
do {
Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data);
stream_clean(fff_data_stream);
if(!subghz_protocol_decoder_base_serialize(
subghz->txrx->decoder_result,
subghz->txrx->fff_data,
subghz_frequencies[subghz_frequencies_433_92],
FuriHalSubGhzPresetOok650Async)) {
FURI_LOG_E(TAG, "Unable to serialize");
break;
}
if(!flipper_format_update_uint32(subghz->txrx->fff_data, "Bit", &bit, 1)) {
FURI_LOG_E(TAG, "Unable to update Bit");
break;
}
uint8_t key_data[sizeof(uint64_t)] = {0};
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (key >> i * 8) & 0xFF;
}
if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to update Key");
break;
}
res = true;
} while(false);
return res;
}
void subghz_scene_set_type_submenu_callback(void* context, uint32_t index) {
@@ -90,7 +132,7 @@ void subghz_scene_set_type_on_enter(void* context) {
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
}
bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
@@ -98,54 +140,45 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
bool generated_protocol = false;
if(event.type == SceneManagerEventTypeCustom) {
//ToDo Fix
uint32_t key = subghz_random_serial();
switch(event.event) {
case SubmenuIndexPricenton:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Princeton")) {
subghz->txrx->protocol_result->code_last_count_bit = 24;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
subghz->txrx->protocol_result->code_last_found = key;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "Princeton", key, 24)) {
uint32_t te = 400;
flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1);
generated_protocol = true;
}
break;
case SubmenuIndexNiceFlo12bit:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Nice FLO")) {
subghz->txrx->protocol_result->code_last_count_bit = 12;
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
subghz->txrx->protocol_result->code_last_found = key;
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "Nice FLO", key, 12)) {
generated_protocol = true;
}
break;
case SubmenuIndexNiceFlo24bit:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Nice FLO")) {
subghz->txrx->protocol_result->code_last_count_bit = 24;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
subghz->txrx->protocol_result->code_last_found = key;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "Nice FLO", key, 24)) {
generated_protocol = true;
}
break;
case SubmenuIndexCAME12bit:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME")) {
subghz->txrx->protocol_result->code_last_count_bit = 12;
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
subghz->txrx->protocol_result->code_last_found = key;
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "CAME", key, 12)) {
generated_protocol = true;
}
break;
case SubmenuIndexCAME24bit:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME")) {
subghz->txrx->protocol_result->code_last_count_bit = 24;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
subghz->txrx->protocol_result->code_last_found = key;
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "CAME", key, 24)) {
generated_protocol = true;
}
break;
case SubmenuIndexCAMETwee:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME TWEE")) {
subghz->txrx->protocol_result->code_last_count_bit = 54;
key = (key & 0x0FFFFFF0);
subghz->txrx->protocol_result->code_last_found = 0x003FFF7200000000 |
(key ^ 0xE0E0E0EE);
key = (key & 0x0FFFFFF0);
key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE);
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "CAME TWEE", key, 54)) {
generated_protocol = true;
}
break;
@@ -156,32 +189,34 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
// /* code */
// break;
case SubmenuIndexGateTX:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "GateTX")) {
subghz->txrx->protocol_result->code_last_count_bit = 24;
key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?)
subghz->txrx->protocol_result->code_last_found =
subghz_protocol_common_reverse_key(
key, subghz->txrx->protocol_result->code_last_count_bit);
key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?)
uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24);
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "GateTX", rev_key, 24)) {
generated_protocol = true;
}
break;
case SubmenuIndexDoorHan:
if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "KeeLoq")) {
subghz->txrx->protocol_result->code_last_count_bit = 64;
subghz->txrx->protocol_result->serial = key & 0x0FFFFFFF;
subghz->txrx->protocol_result->btn = 0x2; //btn 0x1, 0x2, 0x4, 0x8
subghz->txrx->protocol_result->cnt = 0x0003;
if(subghz_protocol_keeloq_set_manufacture_name(
subghz->txrx->protocol_result, "DoorHan")) {
subghz->txrx->protocol_result->code_last_found =
subghz_protocol_keeloq_gen_key(subghz->txrx->protocol_result);
generated_protocol = true;
} else {
generated_protocol = false;
string_set(
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
subghz->txrx->transmitter =
subghz_transmitter_alloc_init(subghz->txrx->environment, "KeeLoq");
if(subghz->txrx->transmitter) {
subghz_protocol_keeloq_create_data(
subghz->txrx->transmitter->protocol_instance,
subghz->txrx->fff_data,
key & 0x0FFFFFFF,
0x2,
0x0003,
"DoorHan",
subghz_frequencies[subghz_frequencies_433_92],
FuriHalSubGhzPresetOok650Async);
generated_protocol = true;
} else {
generated_protocol = false;
}
subghz_transmitter_free(subghz->txrx->transmitter);
if(!generated_protocol) {
string_set(
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
break;
default:
@@ -190,10 +225,10 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
}
if(generated_protocol) {
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
subghz->txrx->preset = FuriHalSubGhzPresetOok650Async;
subghz_file_name_clear(subghz);
DOLPHIN_DEED(DolphinDeedSubGhzAddManually);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneSetType, SubGhzCustomEventManagerSet);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
return true;
}
@@ -7,10 +7,10 @@ void subghz_scene_show_error_callback(GuiButtonType result, InputType type, void
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneShowErrorOk);
subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorOk);
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneShowErrorBack);
subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorBack);
}
}
@@ -28,7 +28,7 @@ void subghz_scene_show_error_on_enter(void* context) {
FontSecondary,
string_get_cstr(subghz->error_str));
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
SubGhzCustomEventManagerSet) {
widget_add_button_element(
subghz->widget, GuiButtonTypeRight, "Ok", subghz_scene_show_error_callback, subghz);
}
@@ -36,14 +36,14 @@ void subghz_scene_show_error_on_enter(void* context) {
widget_add_button_element(
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_show_error_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
}
bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeBack) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
SubGhzCustomEventManagerSet) {
return false;
} else {
scene_manager_search_and_switch_to_previous_scene(
@@ -51,15 +51,15 @@ bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
}
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowErrorOk) {
if(event.event == SubGhzCustomEventSceneShowErrorOk) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
SubGhzCustomEventManagerSet) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
}
return true;
} else if(event.event == SubghzCustomEventSceneShowErrorBack) {
} else if(event.event == SubGhzCustomEventSceneShowErrorBack) {
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
SubghzCustomEventManagerSet) {
SubGhzCustomEventManagerSet) {
//exit app
if(!scene_manager_previous_scene(subghz->scene_manager)) {
scene_manager_stop(subghz->scene_manager);
@@ -78,7 +78,7 @@ bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
void subghz_scene_show_error_on_exit(void* context) {
SubGhz* subghz = context;
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneShowError, SubghzCustomEventManagerNoSet);
subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerNoSet);
widget_reset(subghz->widget);
string_reset(subghz->error_str);
}
@@ -3,7 +3,7 @@
void subghz_scene_show_error_sub_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowErrorSub);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorSub);
}
void subghz_scene_show_error_sub_on_enter(void* context) {
@@ -17,13 +17,13 @@ void subghz_scene_show_error_sub_on_enter(void* context) {
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_show_error_sub_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
}
bool subghz_scene_show_error_sub_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowErrorSub) {
if(event.event == SubGhzCustomEventSceneShowErrorSub) {
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
return true;
@@ -3,7 +3,7 @@
void subghz_scene_show_only_rx_popup_callback(void* context) {
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneShowOnlyRX);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneShowOnlyRX);
}
void subghz_scene_show_only_rx_on_enter(void* context) {
@@ -23,13 +23,13 @@ void subghz_scene_show_only_rx_on_enter(void* context) {
popup_set_context(popup, subghz);
popup_set_callback(popup, subghz_scene_show_only_rx_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewPopup);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
}
const bool subghz_scene_show_only_rx_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventSceneShowOnlyRX) {
if(event.event == SubGhzCustomEventSceneShowOnlyRX) {
scene_manager_previous_scene(subghz->scene_manager);
return true;
}
@@ -48,7 +48,7 @@ void subghz_scene_start_on_enter(void* context) {
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
}
bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
@@ -28,7 +28,7 @@ void subghz_scene_test_on_enter(void* context) {
submenu_set_selected_item(
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneTest));
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
}
bool subghz_scene_test_on_event(void* context, SceneManagerEvent event) {
@@ -1,7 +1,7 @@
#include "../subghz_i.h"
#include "../views/subghz_test_carrier.h"
void subghz_scene_test_carrier_callback(SubghzTestCarrierEvent event, void* context) {
void subghz_scene_test_carrier_callback(SubGhzTestCarrierEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
@@ -11,13 +11,13 @@ void subghz_scene_test_carrier_on_enter(void* context) {
SubGhz* subghz = context;
subghz_test_carrier_set_callback(
subghz->subghz_test_carrier, subghz_scene_test_carrier_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTestCarrier);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
}
bool subghz_scene_test_carrier_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzTestCarrierEventOnlyRx) {
if(event.event == SubGhzTestCarrierEventOnlyRx) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
return true;
}
@@ -1,7 +1,7 @@
#include "../subghz_i.h"
#include "../views/subghz_test_packet.h"
void subghz_scene_test_packet_callback(SubghzTestPacketEvent event, void* context) {
void subghz_scene_test_packet_callback(SubGhzTestPacketEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
@@ -11,13 +11,13 @@ void subghz_scene_test_packet_on_enter(void* context) {
SubGhz* subghz = context;
subghz_test_packet_set_callback(
subghz->subghz_test_packet, subghz_scene_test_packet_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTestPacket);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTestPacket);
}
bool subghz_scene_test_packet_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzTestPacketEventOnlyRx) {
if(event.event == SubGhzTestPacketEventOnlyRx) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
return true;
}
@@ -1,7 +1,7 @@
#include "../subghz_i.h"
#include "../views/subghz_test_static.h"
void subghz_scene_test_static_callback(SubghzTestStaticEvent event, void* context) {
void subghz_scene_test_static_callback(SubGhzTestStaticEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
@@ -11,13 +11,13 @@ void subghz_scene_test_static_on_enter(void* context) {
SubGhz* subghz = context;
subghz_test_static_set_callback(
subghz->subghz_test_static, subghz_scene_test_static_callback, subghz);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewStatic);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdStatic);
}
bool subghz_scene_test_static_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzTestStaticEventOnlyRx) {
if(event.event == SubGhzTestStaticEventOnlyRx) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
return true;
}
@@ -1,18 +1,18 @@
#include "../subghz_i.h"
#include "../views/subghz_transmitter.h"
#include <lib/subghz/protocols/subghz_protocol_keeloq.h>
#include "../views/transmitter.h"
#include <dolphin/dolphin.h>
void subghz_scene_transmitter_callback(SubghzCustomEvent event, void* context) {
void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}
bool subghz_scene_transmitter_update_data_show(void* context) {
//ToDo Fix
SubGhz* subghz = context;
if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->get_upload_protocol) {
if(subghz->txrx->decoder_result) {
string_t key_str;
string_t frequency_str;
string_t modulation_str;
@@ -21,19 +21,18 @@ bool subghz_scene_transmitter_update_data_show(void* context) {
string_init(frequency_str);
string_init(modulation_str);
uint8_t show_button = 0;
subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, key_str);
if((!strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) &&
(!strcmp(
subghz_protocol_keeloq_get_manufacture_name(subghz->txrx->protocol_result),
"Unknown"))) {
show_button = 0;
} else {
subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data);
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, key_str);
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) ==
SubGhzProtocolFlag_Send) {
show_button = 1;
}
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
subghz_transmitter_add_data_to_show(
subghz_view_transmitter_add_data_to_show(
subghz->subghz_transmitter,
string_get_cstr(key_str),
string_get_cstr(frequency_str),
@@ -54,27 +53,27 @@ void subghz_scene_transmitter_on_enter(void* context) {
DOLPHIN_DEED(DolphinDeedSubGhzSend);
if(!subghz_scene_transmitter_update_data_show(subghz)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventViewTransmitterError);
subghz->view_dispatcher, SubGhzCustomEventViewTransmitterError);
}
subghz_transmitter_set_callback(
subghz_view_transmitter_set_callback(
subghz->subghz_transmitter, subghz_scene_transmitter_callback, subghz);
subghz->state_notifications = SubGhzNotificationStateIDLE;
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTransmitter);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
}
bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzCustomEventViewTransmitterSendStart) {
if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
}
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
if(!subghz_tx_start(subghz)) {
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
subghz->state_notifications = SubGhzNotificationStateTX;
@@ -82,19 +81,19 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
}
}
return true;
} else if(event.event == SubghzCustomEventViewTransmitterSendStop) {
} else if(event.event == SubGhzCustomEventViewTransmitterSendStop) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
subghz_tx_stop(subghz);
subghz_sleep(subghz);
}
return true;
} else if(event.event == SubghzCustomEventViewTransmitterBack) {
} else if(event.event == SubGhzCustomEventViewTransmitterBack) {
subghz->state_notifications = SubGhzNotificationStateIDLE;
scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
return true;
} else if(event.event == SubghzCustomEventViewTransmitterError) {
} else if(event.event == SubGhzCustomEventViewTransmitterError) {
string_set(subghz->error_str, "Protocol not found");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
}
+52 -44
View File
@@ -85,80 +85,80 @@ SubGhz* subghz_alloc() {
// SubMenu
subghz->submenu = submenu_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewMenu, submenu_get_view(subghz->submenu));
subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu));
// Receiver
subghz->subghz_receiver = subghz_receiver_alloc();
subghz->subghz_receiver = subghz_view_receiver_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewReceiver,
subghz_receiver_get_view(subghz->subghz_receiver));
SubGhzViewIdReceiver,
subghz_view_receiver_get_view(subghz->subghz_receiver));
// Popup
subghz->popup = popup_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewPopup, popup_get_view(subghz->popup));
subghz->view_dispatcher, SubGhzViewIdPopup, popup_get_view(subghz->popup));
// Text Input
subghz->text_input = text_input_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewTextInput, text_input_get_view(subghz->text_input));
subghz->view_dispatcher, SubGhzViewIdTextInput, text_input_get_view(subghz->text_input));
// Custom Widget
subghz->widget = widget_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher, SubGhzViewWidget, widget_get_view(subghz->widget));
subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget));
//Dialog
subghz->dialogs = furi_record_open("dialogs");
// Transmitter
subghz->subghz_transmitter = subghz_transmitter_alloc();
subghz->subghz_transmitter = subghz_view_transmitter_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTransmitter,
subghz_transmitter_get_view(subghz->subghz_transmitter));
SubGhzViewIdTransmitter,
subghz_view_transmitter_get_view(subghz->subghz_transmitter));
// Variable Item List
subghz->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewVariableItemList,
SubGhzViewIdVariableItemList,
variable_item_list_get_view(subghz->variable_item_list));
// Frequency Analyzer
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewFrequencyAnalyzer,
SubGhzViewIdFrequencyAnalyzer,
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
// Read RAW
subghz->subghz_read_raw = subghz_read_raw_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewReadRAW,
SubGhzViewIdReadRAW,
subghz_read_raw_get_view(subghz->subghz_read_raw));
// Carrier Test Module
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTestCarrier,
SubGhzViewIdTestCarrier,
subghz_test_carrier_get_view(subghz->subghz_test_carrier));
// Packet Test
subghz->subghz_test_packet = subghz_test_packet_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewTestPacket,
SubGhzViewIdTestPacket,
subghz_test_packet_get_view(subghz->subghz_test_packet));
// Static send
subghz->subghz_test_static = subghz_test_static_alloc();
view_dispatcher_add_view(
subghz->view_dispatcher,
SubGhzViewStatic,
SubGhzViewIdStatic,
subghz_test_static_get_view(subghz->subghz_test_static));
//init Worker & Protocol & History
@@ -170,12 +170,21 @@ SubGhz* subghz_alloc() {
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
subghz->txrx->history = subghz_history_alloc();
subghz->txrx->worker = subghz_worker_alloc();
subghz->txrx->parser = subghz_parser_alloc();
subghz->txrx->fff_data = flipper_format_string_alloc();
subghz->txrx->environment = subghz_environment_alloc();
subghz_environment_set_came_atomo_rainbow_table_file_name(
subghz->txrx->environment, "/ext/subghz/assets/came_atomo");
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
subghz->txrx->environment, "/ext/subghz/assets/nice_flor_s");
subghz->txrx->receiver = subghz_receiver_alloc(subghz->txrx->environment);
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
subghz_worker_set_overrun_callback(
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_parser_reset);
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
subghz_worker_set_pair_callback(
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_parser_parse);
subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->parser);
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver);
//Init Error_str
string_init(subghz->error_str);
@@ -187,54 +196,54 @@ void subghz_free(SubGhz* subghz) {
furi_assert(subghz);
// Packet Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestPacket);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestPacket);
subghz_test_packet_free(subghz->subghz_test_packet);
// Carrier Test
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTestCarrier);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
subghz_test_carrier_free(subghz->subghz_test_carrier);
// Static
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewStatic);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic);
subghz_test_static_free(subghz->subghz_test_static);
// Receiver
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewReceiver);
subghz_receiver_free(subghz->subghz_receiver);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
subghz_view_receiver_free(subghz->subghz_receiver);
// TextInput
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTextInput);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
text_input_free(subghz->text_input);
// Custom Widget
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewWidget);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget);
widget_free(subghz->widget);
//Dialog
furi_record_close("dialogs");
// Transmitter
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewTransmitter);
subghz_transmitter_free(subghz->subghz_transmitter);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
subghz_view_transmitter_free(subghz->subghz_transmitter);
// Variable Item List
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewVariableItemList);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
variable_item_list_free(subghz->variable_item_list);
// Frequency Analyzer
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewFrequencyAnalyzer);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer);
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
// Read RAW
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewReadRAW);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
subghz_read_raw_free(subghz->subghz_read_raw);
// Submenu
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewMenu);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu);
submenu_free(subghz->submenu);
// Popup
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewPopup);
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdPopup);
popup_free(subghz->popup);
// Scene manager
@@ -248,8 +257,10 @@ void subghz_free(SubGhz* subghz) {
subghz->gui = NULL;
//Worker & Protocol & History
subghz_parser_free(subghz->txrx->parser);
subghz_receiver_free(subghz->txrx->receiver);
subghz_environment_free(subghz->txrx->environment);
subghz_worker_free(subghz->txrx->worker);
flipper_format_free(subghz->txrx->fff_data);
subghz_history_free(subghz->txrx->history);
free(subghz->txrx);
@@ -268,12 +279,10 @@ int32_t subghz_app(void* p) {
SubGhz* subghz = subghz_alloc();
//Load database
bool load_database =
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/assets/keeloq_mfcodes");
subghz_parser_load_keeloq_file(subghz->txrx->parser, "/ext/subghz/assets/keeloq_mfcodes_user");
subghz_parser_load_nice_flor_s_file(subghz->txrx->parser, "/ext/subghz/assets/nice_flor_s_rx");
subghz_parser_load_came_atomo_file(subghz->txrx->parser, "/ext/subghz/assets/came_atomo");
bool load_database = subghz_environment_load_keystore(
subghz->txrx->environment, "/ext/subghz/assets/keeloq_mfcodes");
subghz_environment_load_keystore(
subghz->txrx->environment, "/ext/subghz/assets/keeloq_mfcodes_user");
// Check argument and run corresponding scene
if(p && subghz_key_load(subghz, p)) {
string_t filename;
@@ -282,8 +291,7 @@ int32_t subghz_app(void* p) {
path_extract_filename_no_ext(p, filename);
strcpy(subghz->file_name, string_get_cstr(filename));
string_clear(filename);
if((!strcmp(subghz->txrx->protocol_result->name, "RAW"))) {
if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) {
//Load Raw TX
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
@@ -296,7 +304,7 @@ int32_t subghz_app(void* p) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
} else {
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneShowError, SubghzCustomEventManagerSet);
subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerSet);
string_set(
subghz->error_str,
"No SD card or\ndatabase found.\nSome app function\nmay be reduced.");
+61 -31
View File
@@ -5,14 +5,15 @@
#include <stream_buffer.h>
#include <lib/toolbox/args.h>
#include <lib/subghz/subghz_parser.h>
#include <lib/subghz/subghz_keystore.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/transmitter.h>
#include "helpers/subghz_chat.h"
#include <notification/notification_messages.h>
#include <flipper_format/flipper_format_i.h>
#define SUBGHZ_FREQUENCY_RANGE_STR \
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
@@ -134,21 +135,35 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
key,
repeat);
SubGhzDecoderPrinceton* protocol = subghz_decoder_princeton_alloc();
protocol->common.code_last_found = key;
protocol->common.code_last_count_bit = 24;
string_t flipper_format_string;
string_init_printf(
flipper_format_string,
"Protocol: Princeton\n"
"Bit: 24\n"
"Key: 00 00 00 00 00 %X %X %X\n"
"TE: 403\n"
"Repeat: %d\n",
(uint8_t)((key >> 16) & 0xFF),
(uint8_t)((key >> 8) & 0xFF),
(uint8_t)(key & 0xFF),
repeat);
FlipperFormat* flipper_format = flipper_format_string_alloc();
Stream* stream = flipper_format_get_raw_stream(flipper_format);
stream_clean(stream);
stream_write_cstring(stream, string_get_cstr(flipper_format_string));
SubGhzProtocolCommonEncoder* encoder = subghz_protocol_encoder_common_alloc();
encoder->repeat = repeat;
SubGhzEnvironment* environment = subghz_environment_alloc();
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
subghz_transmitter_deserialize(transmitter, flipper_format);
subghz_protocol_princeton_send_key(protocol, encoder);
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
furi_hal_power_suppress_charge_enter();
furi_hal_subghz_start_async_tx(subghz_protocol_encoder_common_yield, encoder);
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter);
while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) {
printf(".");
@@ -160,8 +175,9 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
furi_hal_power_suppress_charge_exit();
subghz_decoder_princeton_free(protocol);
subghz_protocol_encoder_common_free(encoder);
flipper_format_free(flipper_format);
subghz_transmitter_free(transmitter);
subghz_environment_free(environment);
}
typedef struct {
@@ -170,7 +186,7 @@ typedef struct {
size_t packet_count;
} SubGhzCliCommandRx;
static void subghz_cli_command_rx_callback(bool level, uint32_t duration, void* context) {
static void subghz_cli_command_rx_capture_callback(bool level, uint32_t duration, void* context) {
SubGhzCliCommandRx* instance = context;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
@@ -185,10 +201,19 @@ static void subghz_cli_command_rx_callback(bool level, uint32_t duration, void*
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
static void subghz_cli_command_rx_text_callback(string_t text, void* context) {
static void subghz_cli_command_rx_callback(
SubGhzReceiver* receiver,
SubGhzProtocolDecoderBase* decoder_base,
void* context) {
SubGhzCliCommandRx* instance = context;
instance->packet_count++;
string_t text;
string_init(text);
subghz_protocol_decoder_base_get_string(decoder_base, text);
subghz_receiver_reset(receiver);
printf("%s", string_get_cstr(text));
string_clear(text);
}
void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
@@ -214,12 +239,16 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
furi_check(instance->stream);
SubGhzParser* parser = subghz_parser_alloc();
subghz_parser_load_keeloq_file(parser, "/ext/subghz/assets/keeloq_mfcodes");
subghz_parser_load_keeloq_file(parser, "/ext/subghz/assets/keeloq_mfcodes_user");
subghz_parser_load_nice_flor_s_file(parser, "/ext/subghz/assets/nice_flor_s_rx");
subghz_parser_load_came_atomo_file(parser, "/ext/subghz/assets/came_atomo");
subghz_parser_enable_dump_text(parser, subghz_cli_command_rx_text_callback, instance);
SubGhzEnvironment* environment = subghz_environment_alloc();
subghz_environment_load_keystore(environment, "/ext/subghz/assets/keeloq_mfcodes");
subghz_environment_set_came_atomo_rainbow_table_file_name(
environment, "/ext/subghz/assets/came_atomo");
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
environment, "/ext/subghz/assets/nice_flor_s");
SubGhzReceiver* receiver = subghz_receiver_alloc(environment);
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
// Configure radio
furi_hal_subghz_reset();
@@ -230,7 +259,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
furi_hal_power_suppress_charge_enter();
// Prepare and start RX
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_callback, instance);
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_capture_callback, instance);
// Wait for packets to arrive
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
@@ -241,11 +270,11 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
if(ret == sizeof(LevelDuration)) {
if(level_duration_is_reset(level_duration)) {
printf(".");
subghz_parser_reset(parser);
subghz_receiver_reset(receiver);
} else {
bool level = level_duration_get_level(level_duration);
uint32_t duration = level_duration_get_duration(level_duration);
subghz_parser_parse(parser, level, duration);
subghz_receiver_decode(receiver, level, duration);
}
}
}
@@ -259,7 +288,8 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
printf("\r\nPackets recieved %u\r\n", instance->packet_count);
// Cleanup
subghz_parser_free(parser);
subghz_receiver_free(receiver);
subghz_environment_free(environment);
vStreamBufferDelete(instance->stream);
free(instance);
}
@@ -416,7 +446,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
string_t sysmsg;
string_init(sysmsg);
bool exit = false;
SubghzChatEvent chat_event;
SubGhzChatEvent chat_event;
NotificationApp* notification = furi_record_open("notification");
@@ -428,10 +458,10 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
while(!exit) {
chat_event = subghz_chat_worker_get_event_chat(subghz_chat);
switch(chat_event.event) {
case SubghzChatEventInputData:
case SubGhzChatEventInputData:
if(chat_event.c == CliSymbolAsciiETX) {
printf("\r\n");
chat_event.event = SubghzChatEventUserExit;
chat_event.event = SubGhzChatEventUserExit;
subghz_chat_worker_put_event_chat(subghz_chat, &chat_event);
break;
} else if(
@@ -478,7 +508,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
fflush(stdout);
string_push_back(input, chat_event.c);
break;
case SubghzChatEventRXData:
case SubGhzChatEventRXData:
do {
memset(message, 0x00, message_max_len);
size_t len = subghz_chat_worker_read(subghz_chat, message, message_max_len);
@@ -497,10 +527,10 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
}
} while(subghz_chat_worker_available(subghz_chat));
break;
case SubghzChatEventNewMessage:
case SubGhzChatEventNewMessage:
notification_message(notification, &sequence_single_vibro);
break;
case SubghzChatEventUserEntrance:
case SubGhzChatEventUserEntrance:
string_printf(
sysmsg,
"\033[0;34m%s joined chat.\033[0m\r\n",
@@ -510,7 +540,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
(uint8_t*)string_get_cstr(sysmsg),
strlen(string_get_cstr(sysmsg)));
break;
case SubghzChatEventUserExit:
case SubGhzChatEventUserExit:
string_printf(
sysmsg, "\033[0;31m%s left chat.\033[0m\r\n", furi_hal_version_get_name_ptr());
subghz_chat_worker_write(
+133 -91
View File
@@ -1,70 +1,83 @@
#include "subghz_history.h"
#include <lib/subghz/protocols/subghz_protocol_keeloq.h>
#include <lib/subghz/protocols/subghz_protocol_star_line.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <lib/subghz/protocols/subghz_protocol_somfy_keytis.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/protocols/came.h>
#include <furi.h>
#include <m-string.h>
#define SUBGHZ_HISTORY_MAX 50
#define TAG "SubGhzHistory"
typedef struct SubGhzHistoryStruct SubGhzHistoryStruct;
struct SubGhzHistoryStruct {
const char* name;
const char* manufacture_name;
uint8_t type_protocol;
uint8_t code_count_bit;
uint64_t code_found;
uint32_t data1;
typedef struct {
string_t item_str;
FlipperFormat* flipper_string;
uint8_t type;
FuriHalSubGhzPreset preset;
uint32_t real_frequency;
};
uint32_t frequency;
} SubGhzHistoryItem;
ARRAY_DEF(SubGhzHistoryItemArray, SubGhzHistoryItem, M_POD_OPLIST)
#define M_OPL_SubGhzHistoryItemArray_t() ARRAY_OPLIST(SubGhzHistoryItemArray, M_POD_OPLIST)
typedef struct {
SubGhzHistoryItemArray_t data;
} SubGhzHistoryStruct;
struct SubGhzHistory {
uint32_t last_update_timestamp;
uint16_t last_index_write;
uint64_t code_last_found;
SubGhzHistoryStruct history[SUBGHZ_HISTORY_MAX];
SubGhzProtocolCommonLoad data;
uint8_t code_last_hash_data;
string_t tmp_string;
SubGhzHistoryStruct* history;
};
SubGhzHistory* subghz_history_alloc(void) {
SubGhzHistory* instance = malloc(sizeof(SubGhzHistory));
string_init(instance->tmp_string);
instance->history = malloc(sizeof(SubGhzHistoryStruct));
SubGhzHistoryItemArray_init(instance->history->data);
return instance;
}
void subghz_history_free(SubGhzHistory* instance) {
furi_assert(instance);
string_clear(instance->tmp_string);
for
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
string_clear(item->item_str);
flipper_format_free(item->flipper_string);
item->type = 0;
}
SubGhzHistoryItemArray_clear(instance->history->data);
free(instance->history);
free(instance);
}
void subghz_history_set_frequency_preset(
SubGhzHistory* instance,
uint16_t idx,
uint32_t frequency,
FuriHalSubGhzPreset preset) {
furi_assert(instance);
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return;
instance->history[idx].preset = preset;
instance->history[idx].real_frequency = frequency;
}
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].real_frequency;
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
return item->frequency;
}
FuriHalSubGhzPreset subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].preset;
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
return item->preset;
}
void subghz_history_reset(SubGhzHistory* instance) {
furi_assert(instance);
string_reset(instance->tmp_string);
for
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
string_clear(item->item_str);
flipper_format_free(item->flipper_string);
item->type = 0;
}
SubGhzHistoryItemArray_reset(instance->history->data);
instance->last_index_write = 0;
instance->code_last_found = 0;
instance->code_last_hash_data = 0;
}
uint16_t subghz_history_get_item(SubGhzHistory* instance) {
@@ -74,20 +87,29 @@ uint16_t subghz_history_get_item(SubGhzHistory* instance) {
uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].type_protocol;
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
return item->type;
}
const char* subghz_history_get_name(SubGhzHistory* instance, uint16_t idx) {
const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
return instance->history[idx].name;
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
flipper_format_rewind(item->flipper_string);
if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) {
FURI_LOG_E(TAG, "Missing Protocol");
string_reset(instance->tmp_string);
}
return string_get_cstr(instance->tmp_string);
}
SubGhzProtocolCommonLoad* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) {
FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
instance->data.code_found = instance->history[idx].code_found;
instance->data.code_count_bit = instance->history[idx].code_count_bit;
instance->data.param1 = instance->history[idx].data1;
return &instance->data;
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
if(item->flipper_string) {
return item->flipper_string;
} else {
return NULL;
}
}
bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output) {
furi_assert(instance);
@@ -99,34 +121,10 @@ bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output
string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX);
return false;
}
void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output, uint16_t idx) {
if(instance->history[idx].code_count_bit < 33) {
string_printf(
output,
"%s %lX",
instance->history[idx].name,
(uint32_t)(instance->history[idx].code_found & 0xFFFFFFFF));
} else {
string_t str_buff;
string_init(str_buff);
if(strcmp(instance->history[idx].name, "KeeLoq") == 0) {
string_set(str_buff, "KL ");
string_cat(str_buff, instance->history[idx].manufacture_name);
} else if(strcmp(instance->history[idx].name, "Star Line") == 0) {
string_set(str_buff, "SL ");
string_cat(str_buff, instance->history[idx].manufacture_name);
} else {
string_set(str_buff, instance->history[idx].name);
}
string_printf(
output,
"%s %lX%08lX",
string_get_cstr(str_buff),
(uint32_t)(instance->history[idx].code_found >> 32),
(uint32_t)(instance->history[idx].code_found & 0xFFFFFFFF));
string_clear(str_buff);
}
void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output, uint16_t idx) {
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
string_set(output, item->item_str);
}
bool subghz_history_add_to_history(
@@ -136,41 +134,85 @@ bool subghz_history_add_to_history(
FuriHalSubGhzPreset preset) {
furi_assert(instance);
furi_assert(context);
SubGhzProtocolCommon* protocol = context;
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return false;
if((instance->code_last_found == (protocol->code_last_found & 0xFFFF0FFFFFFFFFFF)) &&
SubGhzProtocolDecoderBase* decoder_base = context;
if((instance->code_last_hash_data ==
subghz_protocol_decoder_base_get_hash_data(decoder_base)) &&
((millis() - instance->last_update_timestamp) < 500)) {
instance->last_update_timestamp = millis();
return false;
}
instance->code_last_found = protocol->code_last_found & 0xFFFF0FFFFFFFFFFF;
instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base);
instance->last_update_timestamp = millis();
instance->history[instance->last_index_write].real_frequency = frequency;
instance->history[instance->last_index_write].preset = preset;
instance->history[instance->last_index_write].data1 = 0;
instance->history[instance->last_index_write].manufacture_name = NULL;
instance->history[instance->last_index_write].name = protocol->name;
instance->history[instance->last_index_write].code_count_bit = protocol->code_last_count_bit;
instance->history[instance->last_index_write].code_found = protocol->code_last_found;
if(strcmp(protocol->name, "KeeLoq") == 0) {
instance->history[instance->last_index_write].manufacture_name =
subghz_protocol_keeloq_find_and_get_manufacture_name(protocol);
} else if(strcmp(protocol->name, "Star Line") == 0) {
instance->history[instance->last_index_write].manufacture_name =
subghz_protocol_star_line_find_and_get_manufacture_name(protocol);
} else if(strcmp(protocol->name, "Princeton") == 0) {
instance->history[instance->last_index_write].data1 =
subghz_protocol_princeton_get_te(protocol);
} else if(strcmp(protocol->name, "Somfy Keytis") == 0) {
instance->history[instance->last_index_write].data1 =
subghz_protocol_somfy_keytis_get_press_duration(protocol);
}
string_t text;
string_init(text);
SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data);
item->type = decoder_base->protocol->type;
item->frequency = frequency;
item->preset = preset;
instance->history[instance->last_index_write].type_protocol = protocol->type_protocol;
string_init(item->item_str);
item->flipper_string = flipper_format_string_alloc();
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, frequency, preset);
do {
if(!flipper_format_rewind(item->flipper_string)) {
FURI_LOG_E(TAG, "Rewind error");
break;
}
if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) {
string_set(instance->tmp_string, "KL ");
if(!flipper_format_read_string(item->flipper_string, "Manufacture", text)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
string_cat(instance->tmp_string, text);
} else if(!strcmp(string_get_cstr(instance->tmp_string), "Star Line")) {
string_set(instance->tmp_string, "SL ");
if(!flipper_format_read_string(item->flipper_string, "Manufacture", text)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
string_cat(instance->tmp_string, text);
}
if(!flipper_format_rewind(item->flipper_string)) {
FURI_LOG_E(TAG, "Rewind error");
break;
}
uint8_t key_data[sizeof(uint64_t)] = {0};
if(!flipper_format_read_hex(item->flipper_string, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Missing Key");
break;
}
uint64_t data = 0;
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
data = (data << 8) | key_data[i];
}
if(!(uint32_t)(data >> 32)) {
string_printf(
item->item_str,
"%s %lX",
string_get_cstr(instance->tmp_string),
(uint32_t)(data & 0xFFFFFFFF));
} else {
string_printf(
item->item_str,
"%s %lX%08lX",
string_get_cstr(instance->tmp_string),
(uint32_t)(data >> 32),
(uint32_t)(data & 0xFFFFFFFF));
}
} while(false);
string_clear(text);
instance->last_index_write++;
return true;
}
+6 -16
View File
@@ -1,7 +1,10 @@
#pragma once
#include <lib/subghz/protocols/subghz_protocol_common.h>
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
#include <lib/flipper_format/flipper_format.h>
typedef struct SubGhzHistory SubGhzHistory;
@@ -23,19 +26,6 @@ void subghz_history_free(SubGhzHistory* instance);
*/
void subghz_history_reset(SubGhzHistory* instance);
/** Set frequency and preset to history[idx]
*
* @param instance - SubGhzHistory instance
* @param idx - record index
* @param frequency - frequency Hz
* @param preset - FuriHalSubGhzPreset preset
*/
void subghz_history_set_frequency_preset(
SubGhzHistory* instance,
uint16_t idx,
uint32_t frequency,
FuriHalSubGhzPreset preset);
/** Get frequency to history[idx]
*
* @param instance - SubGhzHistory instance
@@ -73,7 +63,7 @@ uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx);
* @param idx - record index
* @return name - const char* name protocol
*/
const char* subghz_history_get_name(SubGhzHistory* instance, uint16_t idx);
const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx);
/** Get string item menu to history[idx]
*
@@ -111,4 +101,4 @@ bool subghz_history_add_to_history(
* @param idx - record index
* @return SubGhzProtocolCommonLoad*
*/
SubGhzProtocolCommonLoad* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx);
FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx);
+116 -133
View File
@@ -8,9 +8,16 @@
#include <notification/notification_messages.h>
#include <flipper_format/flipper_format.h>
#include "../notification/notification.h"
#include "views/subghz_receiver.h"
#include "views/receiver.h"
bool subghz_set_pteset(SubGhz* subghz, const char* preset) {
#include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/stream.h>
#include <lib/subghz/protocols/raw.h>
#include <lib/toolbox/path.h>
#define TAG "SubGhz"
bool subghz_set_preset(SubGhz* subghz, const char* preset) {
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
subghz->txrx->preset = FuriHalSubGhzPresetOok270Async;
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
@@ -20,36 +27,12 @@ bool subghz_set_pteset(SubGhz* subghz, const char* preset) {
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
subghz->txrx->preset = FuriHalSubGhzPreset2FSKDev476Async;
} else {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unknown preset");
FURI_LOG_E(TAG, "Unknown preset");
return false;
}
return true;
}
bool subghz_get_preset_name(SubGhz* subghz, string_t preset) {
const char* preset_name;
switch(subghz->txrx->preset) {
case FuriHalSubGhzPresetOok270Async:
preset_name = "FuriHalSubGhzPresetOok270Async";
break;
case FuriHalSubGhzPresetOok650Async:
preset_name = "FuriHalSubGhzPresetOok650Async";
break;
case FuriHalSubGhzPreset2FSKDev238Async:
preset_name = "FuriHalSubGhzPreset2FSKDev238Async";
break;
case FuriHalSubGhzPreset2FSKDev476Async:
preset_name = "FuriHalSubGhzPreset2FSKDev476Async";
break;
default:
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unknown preset");
return false;
break;
}
string_set(preset, preset_name);
return true;
}
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation) {
furi_assert(subghz);
if(frequency != NULL) {
@@ -143,38 +126,57 @@ void subghz_sleep(SubGhz* subghz) {
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
}
bool subghz_tx_start(SubGhz* subghz) {
bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
furi_assert(subghz);
bool ret = false;
subghz->txrx->encoder = subghz_protocol_encoder_common_alloc();
subghz->txrx->encoder->repeat = 200; //max repeat with the button held down
//get upload
if(subghz->txrx->protocol_result->get_upload_protocol) {
if(subghz->txrx->protocol_result->get_upload_protocol(
subghz->txrx->protocol_result, subghz->txrx->encoder)) {
if(subghz->txrx->preset) {
subghz_begin(subghz, subghz->txrx->preset);
} else {
subghz_begin(subghz, FuriHalSubGhzPresetOok270Async);
}
if(subghz->txrx->frequency) {
ret = subghz_tx(subghz, subghz->txrx->frequency);
} else {
ret = subghz_tx(subghz, 433920000);
}
string_t temp_str;
string_init(temp_str);
uint32_t repeat = 200;
do {
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
break;
}
if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
//ToDo FIX
if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) {
FURI_LOG_E(TAG, "Unable Repeat");
break;
}
if(ret) {
//Start TX
furi_hal_subghz_start_async_tx(
subghz_protocol_encoder_common_yield, subghz->txrx->encoder);
subghz->txrx->transmitter =
subghz_transmitter_alloc_init(subghz->txrx->environment, string_get_cstr(temp_str));
if(subghz->txrx->transmitter) {
if(subghz_transmitter_deserialize(subghz->txrx->transmitter, flipper_format)) {
if(subghz->txrx->preset) {
subghz_begin(subghz, subghz->txrx->preset);
} else {
subghz_begin(subghz, FuriHalSubGhzPresetOok270Async);
}
if(subghz->txrx->frequency) {
ret = subghz_tx(subghz, subghz->txrx->frequency);
} else {
ret = subghz_tx(subghz, 433920000);
}
if(ret) {
//Start TX
furi_hal_subghz_start_async_tx(
subghz_transmitter_yield, subghz->txrx->transmitter);
}
}
}
}
if(!ret) {
subghz_protocol_encoder_common_free(subghz->txrx->encoder);
subghz_idle(subghz);
}
if(!ret) {
subghz_transmitter_free(subghz->txrx->transmitter);
subghz_idle(subghz);
}
} while(false);
string_clear(temp_str);
return ret;
}
@@ -183,13 +185,15 @@ void subghz_tx_stop(SubGhz* subghz) {
furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateTx);
//Stop TX
furi_hal_subghz_stop_async_tx();
subghz_protocol_encoder_common_free(subghz->txrx->encoder);
subghz_idle(subghz);
subghz_transmitter_stop(subghz->txrx->transmitter);
subghz_transmitter_free(subghz->txrx->transmitter);
//if protocol dynamic then we save the last upload
if((subghz->txrx->protocol_result->type_protocol == SubGhzProtocolCommonTypeDynamic) &&
if((subghz->txrx->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) &&
(strcmp(subghz->file_name, ""))) {
subghz_save_protocol_to_file(subghz, subghz->file_name);
subghz_save_protocol_to_file(subghz, subghz->txrx->fff_data, subghz->file_name);
}
subghz_idle(subghz);
notification_message(subghz->notifications, &sequence_reset_red);
}
@@ -198,24 +202,23 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
furi_assert(file_path);
Storage* storage = furi_record_open("storage");
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data);
// Load device data
bool loaded = false;
string_t path;
string_init_set_str(path, file_path);
string_t temp_str;
string_init(temp_str);
uint32_t version;
do {
if(!flipper_format_file_open_existing(flipper_format, string_get_cstr(path))) {
FURI_LOG_E(
SUBGHZ_PARSER_TAG, "Unable to open file for read: %s", string_get_cstr(path));
stream_clean(fff_data_stream);
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
FURI_LOG_E(TAG, "Error open file %s", file_path);
break;
}
if(!flipper_format_read_header(flipper_format, temp_str, &version)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing or incorrect header");
if(!flipper_format_read_header(fff_data_file, temp_str, &version)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
@@ -223,50 +226,59 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) {
(!strcmp(string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) &&
version == SUBGHZ_KEY_FILE_VERSION) {
} else {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Type or version mismatch");
FURI_LOG_E(TAG, "Type or version mismatch");
break;
}
if(!flipper_format_read_uint32(
flipper_format, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Frequency");
fff_data_file, "Frequency", (uint32_t*)&subghz->txrx->frequency, 1)) {
FURI_LOG_E(TAG, "Missing Frequency");
break;
}
if(!flipper_format_read_string(flipper_format, "Preset", temp_str)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Preset");
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
FURI_LOG_E(TAG, "Missing Preset");
break;
}
if(!subghz_set_pteset(subghz, string_get_cstr(temp_str))) {
if(!subghz_set_preset(subghz, string_get_cstr(temp_str))) {
break;
}
if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Missing Protocol");
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
FURI_LOG_E(TAG, "Missing Protocol");
break;
}
if(!strcmp(string_get_cstr(temp_str), "RAW")) {
//if RAW
string_t file_name;
string_init(file_name);
path_extract_filename_no_ext(file_path, file_name);
subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, string_get_cstr(file_name));
string_clear(file_name);
} else {
stream_copy_full(
flipper_format_get_raw_stream(fff_data_file),
flipper_format_get_raw_stream(subghz->txrx->fff_data));
}
subghz->txrx->protocol_result =
subghz_parser_get_by_name(subghz->txrx->parser, string_get_cstr(temp_str));
if(subghz->txrx->protocol_result == NULL) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "This type of protocol was not found");
break;
}
if(!subghz->txrx->protocol_result->to_load_protocol_from_file(
flipper_format, subghz->txrx->protocol_result, string_get_cstr(path))) {
break;
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, string_get_cstr(temp_str));
if(subghz->txrx->decoder_result) {
subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data);
}
loaded = true;
} while(0);
if(!loaded) {
dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
}
string_clear(temp_str);
string_clear(path);
flipper_format_free(flipper_format);
//string_clear(path);
flipper_format_free(fff_data_file);
furi_record_close("storage");
return loaded;
@@ -295,24 +307,26 @@ bool subghz_get_next_name_file(SubGhz* subghz) {
return res;
}
bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
bool subghz_save_protocol_to_file(
SubGhz* subghz,
FlipperFormat* flipper_format,
const char* dev_name) {
furi_assert(subghz);
furi_assert(subghz->txrx->protocol_result);
furi_assert(flipper_format);
furi_assert(dev_name);
Storage* storage = furi_record_open("storage");
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
Stream* flipper_format_stream = flipper_format_get_raw_stream(flipper_format);
string_t dev_file_name;
string_init(dev_file_name);
string_t temp_str;
string_init(temp_str);
bool saved = false;
do {
// Checking that this type of people can be saved
if(subghz->txrx->protocol_result->to_save_file == NULL) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "No saving of this type of keys");
break;
}
//removing additional fields
flipper_format_delete_key(flipper_format, "Repeat");
flipper_format_delete_key(flipper_format, "Manufacture");
// Create subghz folder directory if necessary
if(!storage_simply_mkdir(storage, SUBGHZ_APP_FOLDER)) {
dialog_message_show_storage_error(subghz->dialogs, "Cannot create\nfolder");
@@ -325,47 +339,16 @@ bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name) {
if(!storage_simply_remove(storage, string_get_cstr(dev_file_name))) {
break;
}
// Open file
if(!flipper_format_file_open_always(flipper_format, string_get_cstr(dev_file_name))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to open file for write: %s", dev_file_name);
break;
}
if(!flipper_format_write_header_cstr(
flipper_format, SUBGHZ_KEY_FILE_TYPE, SUBGHZ_KEY_FILE_VERSION)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add header");
break;
}
if(!flipper_format_write_uint32(flipper_format, "Frequency", &subghz->txrx->frequency, 1)) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Frequency");
break;
}
if(!subghz_get_preset_name(subghz, temp_str)) {
break;
}
if(!flipper_format_write_string_cstr(flipper_format, "Preset", string_get_cstr(temp_str))) {
FURI_LOG_E(SUBGHZ_PARSER_TAG, "Unable to add Preset");
break;
}
if(!subghz->txrx->protocol_result->to_save_file(
subghz->txrx->protocol_result, flipper_format)) {
break;
}
//ToDo check Write
stream_seek(flipper_format_stream, 0, StreamOffsetFromStart);
stream_save_to_file(
flipper_format_stream, storage, string_get_cstr(dev_file_name), FSOM_CREATE_ALWAYS);
saved = true;
} while(0);
string_clear(temp_str);
string_clear(dev_file_name);
flipper_format_free(flipper_format);
furi_record_close("storage");
return saved;
}
@@ -501,7 +484,7 @@ void subghz_hopper_update(SubGhz* subghz) {
subghz_rx_end(subghz);
};
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
subghz_parser_reset(subghz->txrx->parser);
subghz_receiver_reset(subghz->txrx->receiver);
subghz->txrx->frequency = subghz_hopper_frequencies[subghz->txrx->hopper_idx_frequency];
subghz_rx(subghz, subghz->txrx->frequency);
}
+38 -31
View File
@@ -1,8 +1,8 @@
#pragma once
#include "subghz.h"
#include "views/subghz_receiver.h"
#include "views/subghz_transmitter.h"
#include "views/receiver.h"
#include "views/transmitter.h"
#include "views/subghz_frequency_analyzer.h"
#include "views/subghz_read_raw.h"
@@ -26,8 +26,9 @@
#include <lib/subghz/subghz_worker.h>
#include <lib/subghz/subghz_parser.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
#include <lib/subghz/receiver.h>
#include <lib/subghz/transmitter.h>
#include "subghz_history.h"
#include <gui/modules/variable_item_list.h>
@@ -79,9 +80,13 @@ typedef enum {
struct SubGhzTxRx {
SubGhzWorker* worker;
SubGhzParser* parser;
SubGhzProtocolCommon* protocol_result;
SubGhzProtocolCommonEncoder* encoder;
SubGhzEnvironment* environment;
SubGhzReceiver* receiver;
SubGhzTransmitter* transmitter;
SubGhzProtocolDecoderBase* decoder_result;
FlipperFormat* fff_data;
uint32_t frequency;
FuriHalSubGhzPreset preset;
SubGhzHistory* history;
@@ -113,46 +118,48 @@ struct SubGhz {
char file_name_tmp[SUBGHZ_TEXT_STORE_SIZE + 1];
SubGhzNotificationState state_notifications;
SubghzReceiver* subghz_receiver;
SubghzTransmitter* subghz_transmitter;
SubGhzViewReceiver* subghz_receiver;
SubGhzViewTransmitter* subghz_transmitter;
VariableItemList* variable_item_list;
SubghzFrequencyAnalyzer* subghz_frequency_analyzer;
SubghzReadRAW* subghz_read_raw;
SubghzTestStatic* subghz_test_static;
SubghzTestCarrier* subghz_test_carrier;
SubghzTestPacket* subghz_test_packet;
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer;
SubGhzReadRAW* subghz_read_raw;
SubGhzTestStatic* subghz_test_static;
SubGhzTestCarrier* subghz_test_carrier;
SubGhzTestPacket* subghz_test_packet;
string_t error_str;
};
typedef enum {
SubGhzViewMenu,
SubGhzViewIdMenu,
SubGhzViewIdReceiver,
SubGhzViewIdPopup,
SubGhzViewIdTextInput,
SubGhzViewIdWidget,
SubGhzViewIdTransmitter,
SubGhzViewIdVariableItemList,
SubGhzViewIdFrequencyAnalyzer,
SubGhzViewIdReadRAW,
SubGhzViewReceiver,
SubGhzViewPopup,
SubGhzViewTextInput,
SubGhzViewWidget,
SubGhzViewTransmitter,
SubGhzViewVariableItemList,
SubGhzViewFrequencyAnalyzer,
SubGhzViewReadRAW,
SubGhzViewStatic,
SubGhzViewTestCarrier,
SubGhzViewTestPacket,
} SubGhzView;
SubGhzViewIdStatic,
SubGhzViewIdTestCarrier,
SubGhzViewIdTestPacket,
} SubGhzViewId;
bool subghz_set_pteset(SubGhz* subghz, const char* preset);
bool subghz_get_preset_name(SubGhz* subghz, string_t preset);
bool subghz_set_preset(SubGhz* subghz, const char* preset);
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation);
void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset);
uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency);
void subghz_rx_end(SubGhz* subghz);
void subghz_sleep(SubGhz* subghz);
bool subghz_tx_start(SubGhz* subghz);
bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
void subghz_tx_stop(SubGhz* subghz);
bool subghz_key_load(SubGhz* subghz, const char* file_path);
bool subghz_get_next_name_file(SubGhz* subghz);
bool subghz_save_protocol_to_file(SubGhz* subghz, const char* dev_name);
bool subghz_save_protocol_to_file(
SubGhz* subghz,
FlipperFormat* flipper_format,
const char* dev_name);
bool subghz_load_protocol_from_file(SubGhz* subghz);
bool subghz_rename_file(SubGhz* subghz);
bool subghz_delete_file(SubGhz* subghz);
@@ -1,4 +1,4 @@
#include "subghz_receiver.h"
#include "receiver.h"
#include "../subghz_i.h"
#include <math.h>
@@ -29,14 +29,14 @@ struct SubGhzReceiverHistory {
typedef struct SubGhzReceiverHistory SubGhzReceiverHistory;
static const Icon* ReceiverItemIcons[] = {
[SubGhzProtocolCommonTypeUnknown] = &I_Quest_7x8,
[SubGhzProtocolCommonTypeStatic] = &I_Unlock_7x8,
[SubGhzProtocolCommonTypeDynamic] = &I_Lock_7x8,
[SubGhzProtocolTypeUnknown] = &I_Quest_7x8,
[SubGhzProtocolTypeStatic] = &I_Unlock_7x8,
[SubGhzProtocolTypeDynamic] = &I_Lock_7x8,
};
struct SubghzReceiver {
struct SubGhzViewReceiver {
View* view;
SubghzReceiverCallback callback;
SubGhzViewReceiverCallback callback;
void* context;
};
@@ -48,11 +48,11 @@ typedef struct {
uint16_t idx;
uint16_t list_offset;
uint16_t history_item;
} SubghzReceiverModel;
} SubGhzViewReceiverModel;
void subghz_receiver_set_callback(
SubghzReceiver* subghz_receiver,
SubghzReceiverCallback callback,
void subghz_view_receiver_set_callback(
SubGhzViewReceiver* subghz_receiver,
SubGhzViewReceiverCallback callback,
void* context) {
furi_assert(subghz_receiver);
furi_assert(callback);
@@ -60,11 +60,11 @@ void subghz_receiver_set_callback(
subghz_receiver->context = context;
}
static void subghz_receiver_update_offset(SubghzReceiver* subghz_receiver) {
static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
size_t history_item = model->history_item;
uint16_t bounds = history_item > 3 ? 2 : history_item;
@@ -79,13 +79,13 @@ static void subghz_receiver_update_offset(SubghzReceiver* subghz_receiver) {
});
}
void subghz_receiver_add_item_to_menu(
SubghzReceiver* subghz_receiver,
void subghz_view_receiver_add_item_to_menu(
SubGhzViewReceiver* subghz_receiver,
const char* name,
uint8_t type) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
SubGhzReceiverMenuItem* item_menu =
SubGhzReceiverMenuItemArray_push_raw(model->history->data);
string_init_set_str(item_menu->item_str, name);
@@ -99,17 +99,17 @@ void subghz_receiver_add_item_to_menu(
return true;
});
subghz_receiver_update_offset(subghz_receiver);
subghz_view_receiver_update_offset(subghz_receiver);
}
void subghz_receiver_add_data_statusbar(
SubghzReceiver* subghz_receiver,
void subghz_view_receiver_add_data_statusbar(
SubGhzViewReceiver* subghz_receiver,
const char* frequency_str,
const char* preset_str,
const char* history_stat_str) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
string_set(model->frequency_str, frequency_str);
string_set(model->preset_str, preset_str);
string_set(model->history_stat_str, history_stat_str);
@@ -117,7 +117,7 @@ void subghz_receiver_add_data_statusbar(
});
}
static void subghz_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
canvas_set_color(canvas, ColorBlack);
canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT);
@@ -131,7 +131,7 @@ static void subghz_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scroll
canvas_draw_dot(canvas, scrollbar ? 121 : 126, (0 + idx * FRAME_HEIGHT) + 11);
}
void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) {
void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
@@ -162,7 +162,7 @@ void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) {
string_set(str_buff, item_menu->item_str);
elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX);
if(model->idx == idx) {
subghz_receiver_draw_frame(canvas, i, scrollbar);
subghz_view_receiver_draw_frame(canvas, i, scrollbar);
} else {
canvas_set_color(canvas, ColorBlack);
}
@@ -176,17 +176,17 @@ void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) {
string_clear(str_buff);
}
bool subghz_receiver_input(InputEvent* event, void* context) {
bool subghz_view_receiver_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
SubGhzViewReceiver* subghz_receiver = context;
if(event->key == InputKeyBack && event->type == InputTypeShort) {
subghz_receiver->callback(SubghzCustomEventViewReceverBack, subghz_receiver->context);
subghz_receiver->callback(SubGhzCustomEventViewReceverBack, subghz_receiver->context);
} else if(
event->key == InputKeyUp &&
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
if(model->idx != 0) model->idx--;
return true;
});
@@ -194,38 +194,38 @@ bool subghz_receiver_input(InputEvent* event, void* context) {
event->key == InputKeyDown &&
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
if(model->idx != model->history_item - 1) model->idx++;
return true;
});
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
subghz_receiver->callback(SubghzCustomEventViewReceverConfig, subghz_receiver->context);
subghz_receiver->callback(SubGhzCustomEventViewReceverConfig, subghz_receiver->context);
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
if(model->history_item != 0) {
subghz_receiver->callback(
SubghzCustomEventViewReceverOK, subghz_receiver->context);
SubGhzCustomEventViewReceverOK, subghz_receiver->context);
}
return false;
});
}
subghz_receiver_update_offset(subghz_receiver);
subghz_view_receiver_update_offset(subghz_receiver);
return true;
}
void subghz_receiver_enter(void* context) {
void subghz_view_receiver_enter(void* context) {
furi_assert(context);
//SubghzReceiver* subghz_receiver = context;
//SubGhzViewReceiver* subghz_receiver = context;
}
void subghz_receiver_exit(void* context) {
void subghz_view_receiver_exit(void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
SubGhzViewReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
string_reset(model->frequency_str);
string_reset(model->preset_str);
string_reset(model->history_stat_str);
@@ -242,20 +242,21 @@ void subghz_receiver_exit(void* context) {
});
}
SubghzReceiver* subghz_receiver_alloc() {
SubghzReceiver* subghz_receiver = malloc(sizeof(SubghzReceiver));
SubGhzViewReceiver* subghz_view_receiver_alloc() {
SubGhzViewReceiver* subghz_receiver = malloc(sizeof(SubGhzViewReceiver));
// View allocation and configuration
subghz_receiver->view = view_alloc();
view_allocate_model(subghz_receiver->view, ViewModelTypeLocking, sizeof(SubghzReceiverModel));
view_allocate_model(
subghz_receiver->view, ViewModelTypeLocking, sizeof(SubGhzViewReceiverModel));
view_set_context(subghz_receiver->view, subghz_receiver);
view_set_draw_callback(subghz_receiver->view, (ViewDrawCallback)subghz_receiver_draw);
view_set_input_callback(subghz_receiver->view, subghz_receiver_input);
view_set_enter_callback(subghz_receiver->view, subghz_receiver_enter);
view_set_exit_callback(subghz_receiver->view, subghz_receiver_exit);
view_set_draw_callback(subghz_receiver->view, (ViewDrawCallback)subghz_view_receiver_draw);
view_set_input_callback(subghz_receiver->view, subghz_view_receiver_input);
view_set_enter_callback(subghz_receiver->view, subghz_view_receiver_enter);
view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
string_init(model->frequency_str);
string_init(model->preset_str);
string_init(model->history_stat_str);
@@ -267,11 +268,11 @@ SubghzReceiver* subghz_receiver_alloc() {
return subghz_receiver;
}
void subghz_receiver_free(SubghzReceiver* subghz_receiver) {
void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
string_clear(model->frequency_str);
string_clear(model->preset_str);
string_clear(model->history_stat_str);
@@ -288,29 +289,29 @@ void subghz_receiver_free(SubghzReceiver* subghz_receiver) {
free(subghz_receiver);
}
View* subghz_receiver_get_view(SubghzReceiver* subghz_receiver) {
View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
return subghz_receiver->view;
}
uint16_t subghz_receiver_get_idx_menu(SubghzReceiver* subghz_receiver) {
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
uint32_t idx = 0;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
idx = model->idx;
return false;
});
return idx;
}
void subghz_receiver_set_idx_menu(SubghzReceiver* subghz_receiver, uint16_t idx) {
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
model->idx = idx;
if(model->idx > 2) model->list_offset = idx - 2;
return true;
});
subghz_receiver_update_offset(subghz_receiver);
subghz_view_receiver_update_offset(subghz_receiver);
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubGhzViewReceiver SubGhzViewReceiver;
typedef void (*SubGhzViewReceiverCallback)(SubGhzCustomEvent event, void* context);
void subghz_view_receiver_set_callback(
SubGhzViewReceiver* subghz_receiver,
SubGhzViewReceiverCallback callback,
void* context);
SubGhzViewReceiver* subghz_view_receiver_alloc();
void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver);
View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver);
void subghz_view_receiver_add_data_statusbar(
SubGhzViewReceiver* subghz_receiver,
const char* frequency_str,
const char* preset_str,
const char* history_stat_str);
void subghz_view_receiver_add_item_to_menu(
SubGhzViewReceiver* subghz_receiver,
const char* name,
uint8_t type);
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver);
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx);
void subghz_view_receiver_exit(void* context);
@@ -6,30 +6,29 @@
#include <furi_hal.h>
#include <input/input.h>
#include <notification/notification_messages.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include "../helpers/subghz_frequency_analyzer_worker.h"
#include <assets_icons.h>
typedef enum {
SubghzFrequencyAnalyzerStatusIDLE,
} SubghzFrequencyAnalyzerStatus;
SubGhzFrequencyAnalyzerStatusIDLE,
} SubGhzFrequencyAnalyzerStatus;
struct SubghzFrequencyAnalyzer {
struct SubGhzFrequencyAnalyzer {
View* view;
SubGhzFrequencyAnalyzerWorker* worker;
SubghzFrequencyAnalyzerCallback callback;
SubGhzFrequencyAnalyzerCallback callback;
void* context;
};
typedef struct {
uint32_t frequency;
float rssi;
} SubghzFrequencyAnalyzerModel;
} SubGhzFrequencyAnalyzerModel;
void subghz_frequency_analyzer_set_callback(
SubghzFrequencyAnalyzer* subghz_frequency_analyzer,
SubghzFrequencyAnalyzerCallback callback,
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
SubGhzFrequencyAnalyzerCallback callback,
void* context) {
furi_assert(subghz_frequency_analyzer);
furi_assert(callback);
@@ -53,7 +52,7 @@ void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, float rssi) {
}
}
void subghz_frequency_analyzer_draw(Canvas* canvas, SubghzFrequencyAnalyzerModel* model) {
void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -77,7 +76,6 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubghzFrequencyAnalyzerModel
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
furi_assert(context);
//SubghzFrequencyAnalyzer* instance = context;
if(event->key == InputKeyBack) {
return false;
@@ -87,9 +85,9 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
}
void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency, float rssi) {
SubghzFrequencyAnalyzer* instance = context;
SubGhzFrequencyAnalyzer* instance = context;
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
model->rssi = rssi;
model->frequency = frequency;
return true;
@@ -98,7 +96,7 @@ void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency,
void subghz_frequency_analyzer_enter(void* context) {
furi_assert(context);
SubghzFrequencyAnalyzer* instance = context;
SubGhzFrequencyAnalyzer* instance = context;
//Start worker
instance->worker = subghz_frequency_analyzer_worker_alloc();
@@ -111,7 +109,7 @@ void subghz_frequency_analyzer_enter(void* context) {
subghz_frequency_analyzer_worker_start(instance->worker);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
model->rssi = 0;
model->frequency = 0;
return true;
@@ -120,7 +118,7 @@ void subghz_frequency_analyzer_enter(void* context) {
void subghz_frequency_analyzer_exit(void* context) {
furi_assert(context);
SubghzFrequencyAnalyzer* instance = context;
SubGhzFrequencyAnalyzer* instance = context;
//Stop worker
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
@@ -129,19 +127,19 @@ void subghz_frequency_analyzer_exit(void* context) {
subghz_frequency_analyzer_worker_free(instance->worker);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
model->rssi = 0;
return true;
});
}
SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
SubghzFrequencyAnalyzer* instance = malloc(sizeof(SubghzFrequencyAnalyzer));
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
// View allocation and configuration
instance->view = view_alloc();
view_allocate_model(
instance->view, ViewModelTypeLocking, sizeof(SubghzFrequencyAnalyzerModel));
instance->view, ViewModelTypeLocking, sizeof(SubGhzFrequencyAnalyzerModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_frequency_analyzer_draw);
view_set_input_callback(instance->view, subghz_frequency_analyzer_input);
@@ -149,7 +147,7 @@ SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
with_view_model(
instance->view, (SubghzFrequencyAnalyzerModel * model) {
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
model->rssi = 0;
return true;
});
@@ -157,14 +155,14 @@ SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
return instance;
}
void subghz_frequency_analyzer_free(SubghzFrequencyAnalyzer* instance) {
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* instance) {
furi_assert(instance);
view_free(instance->view);
free(instance);
}
View* subghz_frequency_analyzer_get_view(SubghzFrequencyAnalyzer* instance) {
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) {
furi_assert(instance);
return instance->view;
}
@@ -3,17 +3,17 @@
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubghzFrequencyAnalyzer SubghzFrequencyAnalyzer;
typedef struct SubGhzFrequencyAnalyzer SubGhzFrequencyAnalyzer;
typedef void (*SubghzFrequencyAnalyzerCallback)(SubghzCustomEvent event, void* context);
typedef void (*SubGhzFrequencyAnalyzerCallback)(SubGhzCustomEvent event, void* context);
void subghz_frequency_analyzer_set_callback(
SubghzFrequencyAnalyzer* subghz_frequency_analyzer,
SubghzFrequencyAnalyzerCallback callback,
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
SubGhzFrequencyAnalyzerCallback callback,
void* context);
SubghzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
void subghz_frequency_analyzer_free(SubghzFrequencyAnalyzer* subghz_static);
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static);
View* subghz_frequency_analyzer_get_view(SubghzFrequencyAnalyzer* subghz_static);
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* subghz_static);
+116 -118
View File
@@ -6,15 +6,14 @@
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <assets_icons.h>
#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100
#define TAG "SubghzReadRAW"
#define TAG "SubGhzReadRAW"
struct SubghzReadRAW {
struct SubGhzReadRAW {
View* view;
SubghzReadRAWCallback callback;
SubGhzReadRAWCallback callback;
void* context;
};
@@ -27,12 +26,12 @@ typedef struct {
bool rssi_history_end;
uint8_t ind_write;
uint8_t ind_sin;
SubghzReadRAWStatus satus;
} SubghzReadRAWModel;
SubGhzReadRAWStatus satus;
} SubGhzReadRAWModel;
void subghz_read_raw_set_callback(
SubghzReadRAW* subghz_read_raw,
SubghzReadRAWCallback callback,
SubGhzReadRAW* subghz_read_raw,
SubGhzReadRAWCallback callback,
void* context) {
furi_assert(subghz_read_raw);
furi_assert(callback);
@@ -41,19 +40,19 @@ void subghz_read_raw_set_callback(
}
void subghz_read_raw_add_data_statusbar(
SubghzReadRAW* instance,
SubGhzReadRAW* instance,
const char* frequency_str,
const char* preset_str) {
furi_assert(instance);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
string_set(model->frequency_str, frequency_str);
string_set(model->preset_str, preset_str);
return true;
});
}
void subghz_read_raw_add_data_rssi(SubghzReadRAW* instance, float rssi) {
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
furi_assert(instance);
uint8_t u_rssi = 0;
@@ -62,10 +61,9 @@ void subghz_read_raw_add_data_rssi(SubghzReadRAW* instance, float rssi) {
} else {
u_rssi = (uint8_t)((rssi + 90) / 2.7);
}
//if(u_rssi > 34) u_rssi = 34;
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
model->rssi_history[model->ind_write++] = u_rssi;
if(model->ind_write > SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE) {
model->rssi_history_end = true;
@@ -75,46 +73,46 @@ void subghz_read_raw_add_data_rssi(SubghzReadRAW* instance, float rssi) {
});
}
void subghz_read_raw_update_sample_write(SubghzReadRAW* instance, size_t sample) {
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) {
furi_assert(instance);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
string_printf(model->sample_write, "%d spl.", sample);
return false;
});
}
void subghz_read_raw_stop_send(SubghzReadRAW* instance) {
void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
furi_assert(instance);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
switch(model->satus) {
case SubghzReadRAWStatusTXRepeat:
case SubghzReadRAWStatusLoadKeyTXRepeat:
instance->callback(SubghzCustomEventViewReadRAWSendStart, instance->context);
case SubGhzReadRAWStatusTXRepeat:
case SubGhzReadRAWStatusLoadKeyTXRepeat:
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
break;
case SubghzReadRAWStatusTX:
model->satus = SubghzReadRAWStatusIDLE;
case SubGhzReadRAWStatusTX:
model->satus = SubGhzReadRAWStatusIDLE;
break;
case SubghzReadRAWStatusLoadKeyTX:
model->satus = SubghzReadRAWStatusLoadKeyIDLE;
case SubGhzReadRAWStatusLoadKeyTX:
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
break;
default:
FURI_LOG_W(TAG, "unknown status");
model->satus = SubghzReadRAWStatusIDLE;
model->satus = SubGhzReadRAWStatusIDLE;
break;
}
return true;
});
}
void subghz_read_raw_update_sin(SubghzReadRAW* instance) {
void subghz_read_raw_update_sin(SubGhzReadRAW* instance) {
furi_assert(instance);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
if(model->ind_sin++ > 62) {
model->ind_sin = 0;
}
@@ -134,7 +132,7 @@ static int8_t subghz_read_raw_tab_sin(uint8_t x) {
return r;
}
void subghz_read_raw_draw_sin(Canvas* canvas, SubghzReadRAWModel* model) {
void subghz_read_raw_draw_sin(Canvas* canvas, SubGhzReadRAWModel* model) {
#define SUBGHZ_RAW_SIN_AMPLITUDE 11
for(int i = 113; i > 0; i--) {
canvas_draw_line(
@@ -154,7 +152,7 @@ void subghz_read_raw_draw_sin(Canvas* canvas, SubghzReadRAWModel* model) {
}
}
void subghz_read_raw_draw_scale(Canvas* canvas, SubghzReadRAWModel* model) {
void subghz_read_raw_draw_scale(Canvas* canvas, SubGhzReadRAWModel* model) {
#define SUBGHZ_RAW_TOP_SCALE 14
#define SUBGHZ_RAW_END_SCALE 115
@@ -178,7 +176,7 @@ void subghz_read_raw_draw_scale(Canvas* canvas, SubghzReadRAWModel* model) {
}
}
void subghz_read_raw_draw_rssi(Canvas* canvas, SubghzReadRAWModel* model) {
void subghz_read_raw_draw_rssi(Canvas* canvas, SubGhzReadRAWModel* model) {
int ind = 0;
int base = 0;
if(model->rssi_history_end == false) {
@@ -214,7 +212,7 @@ void subghz_read_raw_draw_rssi(Canvas* canvas, SubghzReadRAWModel* model) {
}
}
void subghz_read_raw_draw(Canvas* canvas, SubghzReadRAWModel* model) {
void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
uint8_t graphics_mode = 1;
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
@@ -228,12 +226,12 @@ void subghz_read_raw_draw(Canvas* canvas, SubghzReadRAWModel* model) {
canvas_draw_line(canvas, 115, 14, 115, 48);
switch(model->satus) {
case SubghzReadRAWStatusIDLE:
case SubGhzReadRAWStatusIDLE:
elements_button_left(canvas, "Erase");
elements_button_center(canvas, "Send");
elements_button_right(canvas, "Save");
break;
case SubghzReadRAWStatusLoadKeyIDLE:
case SubGhzReadRAWStatusLoadKeyIDLE:
elements_button_left(canvas, "New");
elements_button_center(canvas, "Send");
elements_button_right(canvas, "More");
@@ -241,15 +239,15 @@ void subghz_read_raw_draw(Canvas* canvas, SubghzReadRAWModel* model) {
canvas, 4, 12, 110, 44, AlignCenter, AlignCenter, string_get_cstr(model->file_name));
break;
case SubghzReadRAWStatusTX:
case SubghzReadRAWStatusTXRepeat:
case SubghzReadRAWStatusLoadKeyTX:
case SubghzReadRAWStatusLoadKeyTXRepeat:
case SubGhzReadRAWStatusTX:
case SubGhzReadRAWStatusTXRepeat:
case SubGhzReadRAWStatusLoadKeyTX:
case SubGhzReadRAWStatusLoadKeyTXRepeat:
graphics_mode = 0;
elements_button_center(canvas, "Send");
break;
case SubghzReadRAWStatusStart:
case SubGhzReadRAWStatusStart:
elements_button_left(canvas, "Config");
elements_button_center(canvas, "REC");
break;
@@ -272,7 +270,7 @@ void subghz_read_raw_draw(Canvas* canvas, SubghzReadRAWModel* model) {
bool subghz_read_raw_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzReadRAW* instance = context;
SubGhzReadRAW* instance = context;
if((event->key == InputKeyOk) &&
(event->type == InputTypeLong || event->type == InputTypeRepeat)) {
@@ -281,30 +279,30 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
return false;
} else if(event->key == InputKeyOk && event->type == InputTypePress) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
uint8_t ret = false;
switch(model->satus) {
case SubghzReadRAWStatusIDLE:
case SubGhzReadRAWStatusIDLE:
// Start TX
instance->callback(SubghzCustomEventViewReadRAWSendStart, instance->context);
instance->callback(SubghzCustomEventViewReadRAWVibro, instance->context);
model->satus = SubghzReadRAWStatusTXRepeat;
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWVibro, instance->context);
model->satus = SubGhzReadRAWStatusTXRepeat;
ret = true;
break;
case SubghzReadRAWStatusTX:
case SubGhzReadRAWStatusTX:
// Start TXRepeat
model->satus = SubghzReadRAWStatusTXRepeat;
model->satus = SubGhzReadRAWStatusTXRepeat;
break;
case SubghzReadRAWStatusLoadKeyIDLE:
case SubGhzReadRAWStatusLoadKeyIDLE:
// Start Load Key TX
instance->callback(SubghzCustomEventViewReadRAWSendStart, instance->context);
instance->callback(SubghzCustomEventViewReadRAWVibro, instance->context);
model->satus = SubghzReadRAWStatusLoadKeyTXRepeat;
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWVibro, instance->context);
model->satus = SubGhzReadRAWStatusLoadKeyTXRepeat;
ret = true;
break;
case SubghzReadRAWStatusLoadKeyTX:
case SubGhzReadRAWStatusLoadKeyTX:
// Start Load Key TXRepeat
model->satus = SubghzReadRAWStatusLoadKeyTXRepeat;
model->satus = SubGhzReadRAWStatusLoadKeyTXRepeat;
break;
default:
@@ -314,91 +312,91 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
});
} else if(event->key == InputKeyOk && event->type == InputTypeRelease) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
if(model->satus == SubghzReadRAWStatusTXRepeat) {
instance->view, (SubGhzReadRAWModel * model) {
if(model->satus == SubGhzReadRAWStatusTXRepeat) {
// Stop repeat TX
model->satus = SubghzReadRAWStatusTX;
} else if(model->satus == SubghzReadRAWStatusLoadKeyTXRepeat) {
model->satus = SubGhzReadRAWStatusTX;
} else if(model->satus == SubGhzReadRAWStatusLoadKeyTXRepeat) {
// Stop repeat TX
model->satus = SubghzReadRAWStatusLoadKeyTX;
model->satus = SubGhzReadRAWStatusLoadKeyTX;
}
return false;
});
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
switch(model->satus) {
case SubghzReadRAWStatusREC:
case SubGhzReadRAWStatusREC:
//Stop REC
instance->callback(SubghzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubghzReadRAWStatusIDLE;
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubGhzReadRAWStatusIDLE;
break;
case SubghzReadRAWStatusLoadKeyTX:
case SubGhzReadRAWStatusLoadKeyTX:
//Stop TxRx
instance->callback(SubghzCustomEventViewReadRAWTXRXStop, instance->context);
model->satus = SubghzReadRAWStatusLoadKeyIDLE;
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
break;
case SubghzReadRAWStatusTX:
case SubGhzReadRAWStatusTX:
//Stop TxRx
instance->callback(SubghzCustomEventViewReadRAWTXRXStop, instance->context);
model->satus = SubghzReadRAWStatusIDLE;
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
model->satus = SubGhzReadRAWStatusIDLE;
break;
case SubghzReadRAWStatusLoadKeyIDLE:
case SubGhzReadRAWStatusLoadKeyIDLE:
//Exit
instance->callback(SubghzCustomEventViewReadRAWBack, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
break;
default:
//Exit
instance->callback(SubghzCustomEventViewReadRAWBack, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
break;
}
return true;
});
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
if(model->satus == SubghzReadRAWStatusStart) {
instance->view, (SubGhzReadRAWModel * model) {
if(model->satus == SubGhzReadRAWStatusStart) {
//Config
instance->callback(SubghzCustomEventViewReadRAWConfig, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context);
} else if(
(model->satus == SubghzReadRAWStatusIDLE) ||
(model->satus == SubghzReadRAWStatusLoadKeyIDLE)) {
(model->satus == SubGhzReadRAWStatusIDLE) ||
(model->satus == SubGhzReadRAWStatusLoadKeyIDLE)) {
//Erase
model->satus = SubghzReadRAWStatusStart;
model->satus = SubGhzReadRAWStatusStart;
model->rssi_history_end = false;
model->ind_write = 0;
string_set(model->sample_write, "0 spl.");
string_reset(model->file_name);
instance->callback(SubghzCustomEventViewReadRAWErase, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context);
}
return true;
});
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
if(model->satus == SubghzReadRAWStatusIDLE) {
instance->view, (SubGhzReadRAWModel * model) {
if(model->satus == SubGhzReadRAWStatusIDLE) {
//Save
instance->callback(SubghzCustomEventViewReadRAWSave, instance->context);
} else if(model->satus == SubghzReadRAWStatusLoadKeyIDLE) {
instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context);
} else if(model->satus == SubGhzReadRAWStatusLoadKeyIDLE) {
//More
instance->callback(SubghzCustomEventViewReadRAWMore, instance->context);
instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context);
}
return true;
});
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
if(model->satus == SubghzReadRAWStatusStart) {
instance->view, (SubGhzReadRAWModel * model) {
if(model->satus == SubGhzReadRAWStatusStart) {
//Record
instance->callback(SubghzCustomEventViewReadRAWREC, instance->context);
model->satus = SubghzReadRAWStatusREC;
instance->callback(SubGhzCustomEventViewReadRAWREC, instance->context);
model->satus = SubGhzReadRAWStatusREC;
model->ind_write = 0;
model->rssi_history_end = false;
} else if(model->satus == SubghzReadRAWStatusREC) {
} else if(model->satus == SubGhzReadRAWStatusREC) {
//Stop
instance->callback(SubghzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubghzReadRAWStatusIDLE;
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubGhzReadRAWStatusIDLE;
}
return true;
});
@@ -407,16 +405,16 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
}
void subghz_read_raw_set_status(
SubghzReadRAW* instance,
SubghzReadRAWStatus satus,
SubGhzReadRAW* instance,
SubGhzReadRAWStatus satus,
const char* file_name) {
furi_assert(instance);
switch(satus) {
case SubghzReadRAWStatusStart:
case SubGhzReadRAWStatusStart:
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
model->satus = SubghzReadRAWStatusStart;
instance->view, (SubGhzReadRAWModel * model) {
model->satus = SubGhzReadRAWStatusStart;
model->rssi_history_end = false;
model->ind_write = 0;
string_reset(model->file_name);
@@ -424,17 +422,17 @@ void subghz_read_raw_set_status(
return true;
});
break;
case SubghzReadRAWStatusIDLE:
case SubGhzReadRAWStatusIDLE:
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
model->satus = SubghzReadRAWStatusIDLE;
instance->view, (SubGhzReadRAWModel * model) {
model->satus = SubGhzReadRAWStatusIDLE;
return true;
});
break;
case SubghzReadRAWStatusLoadKeyTX:
case SubGhzReadRAWStatusLoadKeyTX:
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
model->satus = SubghzReadRAWStatusLoadKeyIDLE;
instance->view, (SubGhzReadRAWModel * model) {
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
model->rssi_history_end = false;
model->ind_write = 0;
string_set(model->file_name, file_name);
@@ -442,10 +440,10 @@ void subghz_read_raw_set_status(
return true;
});
break;
case SubghzReadRAWStatusSaveKey:
case SubGhzReadRAWStatusSaveKey:
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
model->satus = SubghzReadRAWStatusLoadKeyIDLE;
instance->view, (SubGhzReadRAWModel * model) {
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
if(!model->ind_write) {
string_set(model->file_name, file_name);
string_set(model->sample_write, "RAW");
@@ -464,31 +462,31 @@ void subghz_read_raw_set_status(
void subghz_read_raw_enter(void* context) {
furi_assert(context);
//SubghzReadRAW* instance = context;
//SubGhzReadRAW* instance = context;
}
void subghz_read_raw_exit(void* context) {
furi_assert(context);
SubghzReadRAW* instance = context;
SubGhzReadRAW* instance = context;
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
if(model->satus != SubghzReadRAWStatusIDLE &&
model->satus != SubghzReadRAWStatusStart &&
model->satus != SubghzReadRAWStatusLoadKeyIDLE) {
instance->callback(SubghzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubghzReadRAWStatusStart;
instance->view, (SubGhzReadRAWModel * model) {
if(model->satus != SubGhzReadRAWStatusIDLE &&
model->satus != SubGhzReadRAWStatusStart &&
model->satus != SubGhzReadRAWStatusLoadKeyIDLE) {
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
model->satus = SubGhzReadRAWStatusStart;
}
return true;
});
}
SubghzReadRAW* subghz_read_raw_alloc() {
SubghzReadRAW* instance = malloc(sizeof(SubghzReadRAW));
SubGhzReadRAW* subghz_read_raw_alloc() {
SubGhzReadRAW* instance = malloc(sizeof(SubGhzReadRAW));
// View allocation and configuration
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzReadRAWModel));
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzReadRAWModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_read_raw_draw);
view_set_input_callback(instance->view, subghz_read_raw_input);
@@ -496,7 +494,7 @@ SubghzReadRAW* subghz_read_raw_alloc() {
view_set_exit_callback(instance->view, subghz_read_raw_exit);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
string_init(model->frequency_str);
string_init(model->preset_str);
string_init(model->sample_write);
@@ -508,11 +506,11 @@ SubghzReadRAW* subghz_read_raw_alloc() {
return instance;
}
void subghz_read_raw_free(SubghzReadRAW* instance) {
void subghz_read_raw_free(SubGhzReadRAW* instance) {
furi_assert(instance);
with_view_model(
instance->view, (SubghzReadRAWModel * model) {
instance->view, (SubGhzReadRAWModel * model) {
string_clear(model->frequency_str);
string_clear(model->preset_str);
string_clear(model->sample_write);
@@ -524,7 +522,7 @@ void subghz_read_raw_free(SubghzReadRAW* instance) {
free(instance);
}
View* subghz_read_raw_get_view(SubghzReadRAW* instance) {
View* subghz_read_raw_get_view(SubGhzReadRAW* instance) {
furi_assert(instance);
return instance->view;
}
+24 -24
View File
@@ -3,48 +3,48 @@
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubghzReadRAW SubghzReadRAW;
typedef struct SubGhzReadRAW SubGhzReadRAW;
typedef void (*SubghzReadRAWCallback)(SubghzCustomEvent event, void* context);
typedef void (*SubGhzReadRAWCallback)(SubGhzCustomEvent event, void* context);
typedef enum {
SubghzReadRAWStatusStart,
SubghzReadRAWStatusIDLE,
SubghzReadRAWStatusREC,
SubghzReadRAWStatusTX,
SubghzReadRAWStatusTXRepeat,
SubGhzReadRAWStatusStart,
SubGhzReadRAWStatusIDLE,
SubGhzReadRAWStatusREC,
SubGhzReadRAWStatusTX,
SubGhzReadRAWStatusTXRepeat,
SubghzReadRAWStatusLoadKeyIDLE,
SubghzReadRAWStatusLoadKeyTX,
SubghzReadRAWStatusLoadKeyTXRepeat,
SubghzReadRAWStatusSaveKey,
} SubghzReadRAWStatus;
SubGhzReadRAWStatusLoadKeyIDLE,
SubGhzReadRAWStatusLoadKeyTX,
SubGhzReadRAWStatusLoadKeyTXRepeat,
SubGhzReadRAWStatusSaveKey,
} SubGhzReadRAWStatus;
void subghz_read_raw_set_callback(
SubghzReadRAW* subghz_read_raw,
SubghzReadRAWCallback callback,
SubGhzReadRAW* subghz_read_raw,
SubGhzReadRAWCallback callback,
void* context);
SubghzReadRAW* subghz_read_raw_alloc();
SubGhzReadRAW* subghz_read_raw_alloc();
void subghz_read_raw_free(SubghzReadRAW* subghz_static);
void subghz_read_raw_free(SubGhzReadRAW* subghz_static);
void subghz_read_raw_add_data_statusbar(
SubghzReadRAW* instance,
SubGhzReadRAW* instance,
const char* frequency_str,
const char* preset_str);
void subghz_read_raw_update_sample_write(SubghzReadRAW* instance, size_t sample);
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample);
void subghz_read_raw_stop_send(SubghzReadRAW* instance);
void subghz_read_raw_stop_send(SubGhzReadRAW* instance);
void subghz_read_raw_update_sin(SubghzReadRAW* instance);
void subghz_read_raw_update_sin(SubGhzReadRAW* instance);
void subghz_read_raw_add_data_rssi(SubghzReadRAW* instance, float rssi);
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi);
void subghz_read_raw_set_status(
SubghzReadRAW* instance,
SubghzReadRAWStatus satus,
SubGhzReadRAW* instance,
SubGhzReadRAWStatus satus,
const char* file_name);
View* subghz_read_raw_get_view(SubghzReadRAW* subghz_static);
View* subghz_read_raw_get_view(SubGhzReadRAW* subghz_static);
@@ -1,36 +0,0 @@
#pragma once
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubghzReceiver SubghzReceiver;
typedef void (*SubghzReceiverCallback)(SubghzCustomEvent event, void* context);
void subghz_receiver_set_callback(
SubghzReceiver* subghz_receiver,
SubghzReceiverCallback callback,
void* context);
SubghzReceiver* subghz_receiver_alloc();
void subghz_receiver_free(SubghzReceiver* subghz_receiver);
View* subghz_receiver_get_view(SubghzReceiver* subghz_receiver);
void subghz_receiver_add_data_statusbar(
SubghzReceiver* subghz_receiver,
const char* frequency_str,
const char* preset_str,
const char* history_stat_str);
void subghz_receiver_add_item_to_menu(
SubghzReceiver* subghz_receiver,
const char* name,
uint8_t type);
uint16_t subghz_receiver_get_idx_menu(SubghzReceiver* subghz_receiver);
void subghz_receiver_set_idx_menu(SubghzReceiver* subghz_receiver, uint16_t idx);
void subghz_receiver_exit(void* context);
+30 -30
View File
@@ -7,29 +7,29 @@
#include <furi_hal.h>
#include <input/input.h>
struct SubghzTestCarrier {
struct SubGhzTestCarrier {
View* view;
osTimerId_t timer;
SubghzTestCarrierCallback callback;
SubGhzTestCarrierCallback callback;
void* context;
};
typedef enum {
SubghzTestCarrierModelStatusRx,
SubghzTestCarrierModelStatusTx,
} SubghzTestCarrierModelStatus;
SubGhzTestCarrierModelStatusRx,
SubGhzTestCarrierModelStatusTx,
} SubGhzTestCarrierModelStatus;
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
FuriHalSubGhzPath path;
float rssi;
SubghzTestCarrierModelStatus status;
} SubghzTestCarrierModel;
SubGhzTestCarrierModelStatus status;
} SubGhzTestCarrierModel;
void subghz_test_carrier_set_callback(
SubghzTestCarrier* subghz_test_carrier,
SubghzTestCarrierCallback callback,
SubGhzTestCarrier* subghz_test_carrier,
SubGhzTestCarrierCallback callback,
void* context) {
furi_assert(subghz_test_carrier);
furi_assert(callback);
@@ -37,7 +37,7 @@ void subghz_test_carrier_set_callback(
subghz_test_carrier->context = context;
}
void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -67,7 +67,7 @@ void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
}
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
canvas_draw_str(canvas, 0, 31, buffer);
if(model->status == SubghzTestCarrierModelStatusRx) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
snprintf(
buffer,
sizeof(buffer),
@@ -82,14 +82,14 @@ void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
if(event->key == InputKeyBack || event->type != InputTypeShort) {
return false;
}
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
furi_hal_subghz_idle();
if(event->key == InputKeyLeft) {
@@ -101,10 +101,10 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
if(model->path < FuriHalSubGhzPath868) model->path++;
} else if(event->key == InputKeyOk) {
if(model->status == SubghzTestCarrierModelStatusTx) {
model->status = SubghzTestCarrierModelStatusRx;
if(model->status == SubGhzTestCarrierModelStatusTx) {
model->status = SubGhzTestCarrierModelStatusRx;
} else {
model->status = SubghzTestCarrierModelStatusTx;
model->status = SubGhzTestCarrierModelStatusTx;
}
}
@@ -112,7 +112,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
furi_hal_subghz_set_path(model->path);
if(model->status == SubghzTestCarrierModelStatusRx) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
} else {
@@ -121,7 +121,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
if(!furi_hal_subghz_tx()) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_test_carrier->callback(
SubghzTestCarrierEventOnlyRx, subghz_test_carrier->context);
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
}
}
@@ -133,7 +133,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
void subghz_test_carrier_enter(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
@@ -141,13 +141,13 @@ void subghz_test_carrier_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
model->frequency = subghz_frequencies_433_92_testing; // 433
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubghzTestCarrierModelStatusRx;
model->status = SubGhzTestCarrierModelStatusRx;
return true;
});
@@ -158,7 +158,7 @@ void subghz_test_carrier_enter(void* context) {
void subghz_test_carrier_exit(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
osTimerStop(subghz_test_carrier->timer);
@@ -168,11 +168,11 @@ void subghz_test_carrier_exit(void* context) {
void subghz_test_carrier_rssi_timer_callback(void* context) {
furi_assert(context);
SubghzTestCarrier* subghz_test_carrier = context;
SubGhzTestCarrier* subghz_test_carrier = context;
with_view_model(
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
if(model->status == SubghzTestCarrierModelStatusRx) {
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
if(model->status == SubGhzTestCarrierModelStatusRx) {
model->rssi = furi_hal_subghz_get_rssi();
return true;
}
@@ -180,13 +180,13 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
});
}
SubghzTestCarrier* subghz_test_carrier_alloc() {
SubghzTestCarrier* subghz_test_carrier = malloc(sizeof(SubghzTestCarrier));
SubGhzTestCarrier* subghz_test_carrier_alloc() {
SubGhzTestCarrier* subghz_test_carrier = malloc(sizeof(SubGhzTestCarrier));
// View allocation and configuration
subghz_test_carrier->view = view_alloc();
view_allocate_model(
subghz_test_carrier->view, ViewModelTypeLocking, sizeof(SubghzTestCarrierModel));
subghz_test_carrier->view, ViewModelTypeLocking, sizeof(SubGhzTestCarrierModel));
view_set_context(subghz_test_carrier->view, subghz_test_carrier);
view_set_draw_callback(subghz_test_carrier->view, (ViewDrawCallback)subghz_test_carrier_draw);
view_set_input_callback(subghz_test_carrier->view, subghz_test_carrier_input);
@@ -199,14 +199,14 @@ SubghzTestCarrier* subghz_test_carrier_alloc() {
return subghz_test_carrier;
}
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier) {
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
osTimerDelete(subghz_test_carrier->timer);
view_free(subghz_test_carrier->view);
free(subghz_test_carrier);
}
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier) {
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
return subghz_test_carrier->view;
}
@@ -3,20 +3,20 @@
#include <gui/view.h>
typedef enum {
SubghzTestCarrierEventOnlyRx,
} SubghzTestCarrierEvent;
SubGhzTestCarrierEventOnlyRx,
} SubGhzTestCarrierEvent;
typedef struct SubghzTestCarrier SubghzTestCarrier;
typedef struct SubGhzTestCarrier SubGhzTestCarrier;
typedef void (*SubghzTestCarrierCallback)(SubghzTestCarrierEvent event, void* context);
typedef void (*SubGhzTestCarrierCallback)(SubGhzTestCarrierEvent event, void* context);
void subghz_test_carrier_set_callback(
SubghzTestCarrier* subghz_test_carrier,
SubghzTestCarrierCallback callback,
SubGhzTestCarrier* subghz_test_carrier,
SubGhzTestCarrierCallback callback,
void* context);
SubghzTestCarrier* subghz_test_carrier_alloc();
SubGhzTestCarrier* subghz_test_carrier_alloc();
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier);
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier);
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier);
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier);
+57 -55
View File
@@ -7,26 +7,26 @@
#include <furi_hal.h>
#include <input/input.h>
#include <toolbox/level_duration.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <lib/subghz/protocols/princeton_for_testing.h>
#define SUBGHZ_TEST_PACKET_COUNT 500
struct SubghzTestPacket {
struct SubGhzTestPacket {
View* view;
osTimerId_t timer;
SubGhzDecoderPrinceton* decoder;
SubGhzEncoderPrinceton* encoder;
volatile size_t packet_rx;
SubghzTestPacketCallback callback;
SubGhzTestPacketCallback callback;
void* context;
};
typedef enum {
SubghzTestPacketModelStatusRx,
SubghzTestPacketModelStatusOnlyRx,
SubghzTestPacketModelStatusTx,
} SubghzTestPacketModelStatus;
SubGhzTestPacketModelStatusRx,
SubGhzTestPacketModelStatusOnlyRx,
SubGhzTestPacketModelStatusTx,
} SubGhzTestPacketModelStatus;
typedef struct {
uint8_t frequency;
@@ -34,14 +34,14 @@ typedef struct {
FuriHalSubGhzPath path;
float rssi;
size_t packets;
SubghzTestPacketModelStatus status;
} SubghzTestPacketModel;
SubGhzTestPacketModelStatus status;
} SubGhzTestPacketModel;
volatile bool subghz_test_packet_overrun = false;
void subghz_test_packet_set_callback(
SubghzTestPacket* subghz_test_packet,
SubghzTestPacketCallback callback,
SubGhzTestPacket* subghz_test_packet,
SubGhzTestPacketCallback callback,
void* context) {
furi_assert(subghz_test_packet);
furi_assert(callback);
@@ -51,34 +51,36 @@ void subghz_test_packet_set_callback(
static void subghz_test_packet_rx_callback(bool level, uint32_t duration, void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
subghz_decoder_princeton_parse(instance->decoder, level, duration);
SubGhzTestPacket* instance = context;
subghz_decoder_princeton_for_testing_parse(instance->decoder, level, duration);
}
static void subghz_test_packet_rx_pt_callback(SubGhzProtocolCommon* parser, void* context) {
//todo
static void subghz_test_packet_rx_pt_callback(SubGhzDecoderPrinceton* parser, void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
SubGhzTestPacket* instance = context;
instance->packet_rx++;
}
static void subghz_test_packet_rssi_timer_callback(void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
SubGhzTestPacket* instance = context;
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
if(model->status == SubghzTestPacketModelStatusRx) {
instance->view, (SubGhzTestPacketModel * model) {
if(model->status == SubGhzTestPacketModelStatusRx) {
model->rssi = furi_hal_subghz_get_rssi();
model->packets = instance->packet_rx;
} else if(model->status == SubghzTestPacketModelStatusTx) {
model->packets = SUBGHZ_TEST_PACKET_COUNT -
subghz_encoder_princeton_get_repeat_left(instance->encoder);
} else if(model->status == SubGhzTestPacketModelStatusTx) {
model->packets =
SUBGHZ_TEST_PACKET_COUNT -
subghz_encoder_princeton_for_testing_get_repeat_left(instance->encoder);
}
return true;
});
}
static void subghz_test_packet_draw(Canvas* canvas, SubghzTestPacketModel* model) {
static void subghz_test_packet_draw(Canvas* canvas, SubGhzTestPacketModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -112,7 +114,7 @@ static void subghz_test_packet_draw(Canvas* canvas, SubghzTestPacketModel* model
snprintf(buffer, sizeof(buffer), "Packets: %d", model->packets);
canvas_draw_str(canvas, 0, 42, buffer);
if(model->status == SubghzTestPacketModelStatusRx) {
if(model->status == SubGhzTestPacketModelStatusRx) {
snprintf(
buffer,
sizeof(buffer),
@@ -127,18 +129,18 @@ static void subghz_test_packet_draw(Canvas* canvas, SubghzTestPacketModel* model
static bool subghz_test_packet_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
SubGhzTestPacket* instance = context;
if(event->key == InputKeyBack || event->type != InputTypeShort) {
return false;
}
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
if(model->status == SubghzTestPacketModelStatusRx) {
instance->view, (SubGhzTestPacketModel * model) {
if(model->status == SubGhzTestPacketModelStatusRx) {
furi_hal_subghz_stop_async_rx();
} else if(model->status == SubghzTestPacketModelStatusTx) {
subghz_encoder_princeton_stop(instance->encoder, millis());
} else if(model->status == SubGhzTestPacketModelStatusTx) {
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
furi_hal_subghz_stop_async_tx();
}
@@ -151,10 +153,10 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
if(model->path < FuriHalSubGhzPath868) model->path++;
} else if(event->key == InputKeyOk) {
if(model->status == SubghzTestPacketModelStatusRx) {
model->status = SubghzTestPacketModelStatusTx;
if(model->status == SubGhzTestPacketModelStatusRx) {
model->status = SubGhzTestPacketModelStatusTx;
} else {
model->status = SubghzTestPacketModelStatusRx;
model->status = SubGhzTestPacketModelStatusRx;
}
}
@@ -162,18 +164,18 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
furi_hal_subghz_set_path(model->path);
if(model->status == SubghzTestPacketModelStatusRx) {
if(model->status == SubGhzTestPacketModelStatusRx) {
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
} else {
subghz_encoder_princeton_set(
subghz_encoder_princeton_for_testing_set(
instance->encoder,
0x00AABBCC,
SUBGHZ_TEST_PACKET_COUNT,
subghz_frequencies_testing[model->frequency]);
if(!furi_hal_subghz_start_async_tx(
subghz_encoder_princeton_yield, instance->encoder)) {
model->status = SubghzTestPacketModelStatusOnlyRx;
instance->callback(SubghzTestPacketEventOnlyRx, instance->context);
subghz_encoder_princeton_for_testing_yield, instance->encoder)) {
model->status = SubGhzTestPacketModelStatusOnlyRx;
instance->callback(SubGhzTestPacketEventOnlyRx, instance->context);
}
}
@@ -185,19 +187,19 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
void subghz_test_packet_enter(void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
SubGhzTestPacket* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
instance->view, (SubGhzTestPacketModel * model) {
model->frequency = subghz_frequencies_433_92_testing;
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubghzTestPacketModelStatusRx;
model->status = SubGhzTestPacketModelStatusRx;
return true;
});
@@ -208,17 +210,17 @@ void subghz_test_packet_enter(void* context) {
void subghz_test_packet_exit(void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
SubGhzTestPacket* instance = context;
osTimerStop(instance->timer);
// Reinitialize IC to default state
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
if(model->status == SubghzTestPacketModelStatusRx) {
instance->view, (SubGhzTestPacketModel * model) {
if(model->status == SubGhzTestPacketModelStatusRx) {
furi_hal_subghz_stop_async_rx();
} else if(model->status == SubghzTestPacketModelStatusTx) {
subghz_encoder_princeton_stop(instance->encoder, millis());
} else if(model->status == SubGhzTestPacketModelStatusTx) {
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
furi_hal_subghz_stop_async_tx();
}
return true;
@@ -226,12 +228,12 @@ void subghz_test_packet_exit(void* context) {
furi_hal_subghz_sleep();
}
SubghzTestPacket* subghz_test_packet_alloc() {
SubghzTestPacket* instance = malloc(sizeof(SubghzTestPacket));
SubGhzTestPacket* subghz_test_packet_alloc() {
SubGhzTestPacket* instance = malloc(sizeof(SubGhzTestPacket));
// View allocation and configuration
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzTestPacketModel));
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzTestPacketModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_test_packet_draw);
view_set_input_callback(instance->view, subghz_test_packet_input);
@@ -241,26 +243,26 @@ SubghzTestPacket* subghz_test_packet_alloc() {
instance->timer =
osTimerNew(subghz_test_packet_rssi_timer_callback, osTimerPeriodic, instance, NULL);
instance->decoder = subghz_decoder_princeton_alloc();
subghz_protocol_common_set_callback(
(SubGhzProtocolCommon*)instance->decoder, subghz_test_packet_rx_pt_callback, instance);
instance->encoder = subghz_encoder_princeton_alloc();
instance->decoder = subghz_decoder_princeton_for_testing_alloc();
subghz_decoder_princeton_for_testing_set_callback(
instance->decoder, subghz_test_packet_rx_pt_callback, instance);
instance->encoder = subghz_encoder_princeton_for_testing_alloc();
return instance;
}
void subghz_test_packet_free(SubghzTestPacket* instance) {
void subghz_test_packet_free(SubGhzTestPacket* instance) {
furi_assert(instance);
subghz_decoder_princeton_free(instance->decoder);
subghz_encoder_princeton_free(instance->encoder);
subghz_decoder_princeton_for_testing_free(instance->decoder);
subghz_encoder_princeton_for_testing_free(instance->encoder);
osTimerDelete(instance->timer);
view_free(instance->view);
free(instance);
}
View* subghz_test_packet_get_view(SubghzTestPacket* instance) {
View* subghz_test_packet_get_view(SubGhzTestPacket* instance) {
furi_assert(instance);
return instance->view;
}
@@ -3,20 +3,20 @@
#include <gui/view.h>
typedef enum {
SubghzTestPacketEventOnlyRx,
} SubghzTestPacketEvent;
SubGhzTestPacketEventOnlyRx,
} SubGhzTestPacketEvent;
typedef struct SubghzTestPacket SubghzTestPacket;
typedef struct SubGhzTestPacket SubGhzTestPacket;
typedef void (*SubghzTestPacketCallback)(SubghzTestPacketEvent event, void* context);
typedef void (*SubGhzTestPacketCallback)(SubGhzTestPacketEvent event, void* context);
void subghz_test_packet_set_callback(
SubghzTestPacket* subghz_test_packet,
SubghzTestPacketCallback callback,
SubGhzTestPacket* subghz_test_packet,
SubGhzTestPacketCallback callback,
void* context);
SubghzTestPacket* subghz_test_packet_alloc();
SubGhzTestPacket* subghz_test_packet_alloc();
void subghz_test_packet_free(SubghzTestPacket* subghz_test_packet);
void subghz_test_packet_free(SubGhzTestPacket* subghz_test_packet);
View* subghz_test_packet_get_view(SubghzTestPacket* subghz_test_packet);
View* subghz_test_packet_get_view(SubGhzTestPacket* subghz_test_packet);
+31 -31
View File
@@ -7,14 +7,14 @@
#include <furi_hal.h>
#include <input/input.h>
#include <notification/notification_messages.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
#include <lib/subghz/protocols/princeton_for_testing.h>
#define TAG "SubGhzTestStatic"
typedef enum {
SubghzTestStaticStatusIDLE,
SubghzTestStaticStatusTX,
} SubghzTestStaticStatus;
SubGhzTestStaticStatusIDLE,
SubGhzTestStaticStatusTX,
} SubGhzTestStaticStatus;
static const uint32_t subghz_test_static_keys[] = {
0x0074BADE,
@@ -23,11 +23,11 @@ static const uint32_t subghz_test_static_keys[] = {
0x00E34A4E,
};
struct SubghzTestStatic {
struct SubGhzTestStatic {
View* view;
SubghzTestStaticStatus satus_tx;
SubGhzTestStaticStatus satus_tx;
SubGhzEncoderPrinceton* encoder;
SubghzTestStaticCallback callback;
SubGhzTestStaticCallback callback;
void* context;
};
@@ -35,11 +35,11 @@ typedef struct {
uint8_t frequency;
uint32_t real_frequency;
uint8_t button;
} SubghzTestStaticModel;
} SubGhzTestStaticModel;
void subghz_test_static_set_callback(
SubghzTestStatic* subghz_test_static,
SubghzTestStaticCallback callback,
SubGhzTestStatic* subghz_test_static,
SubGhzTestStaticCallback callback,
void* context) {
furi_assert(subghz_test_static);
furi_assert(callback);
@@ -47,7 +47,7 @@ void subghz_test_static_set_callback(
subghz_test_static->context = context;
}
void subghz_test_static_draw(Canvas* canvas, SubghzTestStaticModel* model) {
void subghz_test_static_draw(Canvas* canvas, SubGhzTestStaticModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -70,14 +70,14 @@ void subghz_test_static_draw(Canvas* canvas, SubghzTestStaticModel* model) {
bool subghz_test_static_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestStatic* instance = context;
SubGhzTestStatic* instance = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
instance->view, (SubghzTestStaticModel * model) {
instance->view, (SubGhzTestStaticModel * model) {
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
@@ -99,31 +99,31 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
furi_hal_subghz_set_frequency_and_path(
subghz_frequencies_testing[model->frequency]);
if(!furi_hal_subghz_tx()) {
instance->callback(SubghzTestStaticEventOnlyRx, instance->context);
instance->callback(SubGhzTestStaticEventOnlyRx, instance->context);
} else {
notification_message_block(notification, &sequence_set_red_255);
FURI_LOG_I(TAG, "TX Start");
subghz_encoder_princeton_set(
subghz_encoder_princeton_for_testing_set(
instance->encoder,
subghz_test_static_keys[model->button],
10000,
subghz_frequencies_testing[model->frequency]);
furi_hal_subghz_start_async_tx(
subghz_encoder_princeton_yield, instance->encoder);
instance->satus_tx = SubghzTestStaticStatusTX;
subghz_encoder_princeton_for_testing_yield, instance->encoder);
instance->satus_tx = SubGhzTestStaticStatusTX;
}
} else if(event->type == InputTypeRelease) {
if(instance->satus_tx == SubghzTestStaticStatusTX) {
if(instance->satus_tx == SubGhzTestStaticStatusTX) {
FURI_LOG_I(TAG, "TX Stop");
subghz_encoder_princeton_stop(instance->encoder, millis());
subghz_encoder_princeton_print_log(instance->encoder);
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
subghz_encoder_princeton_for_testing_print_log(instance->encoder);
furi_hal_subghz_stop_async_tx();
notification_message(notification, &sequence_reset_red);
}
instance->satus_tx = SubghzTestStaticStatusIDLE;
instance->satus_tx = SubGhzTestStaticStatusIDLE;
}
furi_record_close("notification");
}
@@ -136,17 +136,17 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
void subghz_test_static_enter(void* context) {
furi_assert(context);
SubghzTestStatic* instance = context;
SubGhzTestStatic* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, false);
instance->satus_tx = SubghzTestStaticStatusIDLE;
instance->satus_tx = SubGhzTestStaticStatusIDLE;
with_view_model(
instance->view, (SubghzTestStaticModel * model) {
instance->view, (SubGhzTestStaticModel * model) {
model->frequency = subghz_frequencies_433_92_testing;
model->real_frequency = subghz_frequencies_testing[model->frequency];
model->button = 0;
@@ -160,31 +160,31 @@ void subghz_test_static_exit(void* context) {
furi_hal_subghz_sleep();
}
SubghzTestStatic* subghz_test_static_alloc() {
SubghzTestStatic* instance = malloc(sizeof(SubghzTestStatic));
SubGhzTestStatic* subghz_test_static_alloc() {
SubGhzTestStatic* instance = malloc(sizeof(SubGhzTestStatic));
// View allocation and configuration
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzTestStaticModel));
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzTestStaticModel));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_test_static_draw);
view_set_input_callback(instance->view, subghz_test_static_input);
view_set_enter_callback(instance->view, subghz_test_static_enter);
view_set_exit_callback(instance->view, subghz_test_static_exit);
instance->encoder = subghz_encoder_princeton_alloc();
instance->encoder = subghz_encoder_princeton_for_testing_alloc();
return instance;
}
void subghz_test_static_free(SubghzTestStatic* instance) {
void subghz_test_static_free(SubGhzTestStatic* instance) {
furi_assert(instance);
subghz_encoder_princeton_free(instance->encoder);
subghz_encoder_princeton_for_testing_free(instance->encoder);
view_free(instance->view);
free(instance);
}
View* subghz_test_static_get_view(SubghzTestStatic* instance) {
View* subghz_test_static_get_view(SubGhzTestStatic* instance) {
furi_assert(instance);
return instance->view;
}
@@ -3,20 +3,20 @@
#include <gui/view.h>
typedef enum {
SubghzTestStaticEventOnlyRx,
} SubghzTestStaticEvent;
SubGhzTestStaticEventOnlyRx,
} SubGhzTestStaticEvent;
typedef struct SubghzTestStatic SubghzTestStatic;
typedef struct SubGhzTestStatic SubGhzTestStatic;
typedef void (*SubghzTestStaticCallback)(SubghzTestStaticEvent event, void* context);
typedef void (*SubGhzTestStaticCallback)(SubGhzTestStaticEvent event, void* context);
void subghz_test_static_set_callback(
SubghzTestStatic* subghz_test_static,
SubghzTestStaticCallback callback,
SubGhzTestStatic* subghz_test_static,
SubGhzTestStaticCallback callback,
void* context);
SubghzTestStatic* subghz_test_static_alloc();
SubGhzTestStatic* subghz_test_static_alloc();
void subghz_test_static_free(SubghzTestStatic* subghz_static);
void subghz_test_static_free(SubGhzTestStatic* subghz_static);
View* subghz_test_static_get_view(SubghzTestStatic* subghz_static);
View* subghz_test_static_get_view(SubGhzTestStatic* subghz_static);
@@ -1,26 +0,0 @@
#pragma once
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubghzTransmitter SubghzTransmitter;
typedef void (*SubghzTransmitterCallback)(SubghzCustomEvent event, void* context);
void subghz_transmitter_set_callback(
SubghzTransmitter* subghz_transmitter,
SubghzTransmitterCallback callback,
void* context);
SubghzTransmitter* subghz_transmitter_alloc();
void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter);
View* subghz_transmitter_get_view(SubghzTransmitter* subghz_transmitter);
void subghz_transmitter_add_data_to_show(
SubghzTransmitter* subghz_transmitter,
const char* key_str,
const char* frequency_str,
const char* preset_str,
uint8_t show_button);
@@ -1,12 +1,12 @@
#include "subghz_transmitter.h"
#include "transmitter.h"
#include "../subghz_i.h"
#include <input/input.h>
#include <gui/elements.h>
struct SubghzTransmitter {
struct SubGhzViewTransmitter {
View* view;
SubghzTransmitterCallback callback;
SubGhzViewTransmitterCallback callback;
void* context;
};
@@ -15,11 +15,11 @@ typedef struct {
string_t preset_str;
string_t key_str;
uint8_t show_button;
} SubghzTransmitterModel;
} SubGhzViewTransmitterModel;
void subghz_transmitter_set_callback(
SubghzTransmitter* subghz_transmitter,
SubghzTransmitterCallback callback,
void subghz_view_transmitter_set_callback(
SubGhzViewTransmitter* subghz_transmitter,
SubGhzViewTransmitterCallback callback,
void* context) {
furi_assert(subghz_transmitter);
@@ -27,15 +27,15 @@ void subghz_transmitter_set_callback(
subghz_transmitter->context = context;
}
void subghz_transmitter_add_data_to_show(
SubghzTransmitter* subghz_transmitter,
void subghz_view_transmitter_add_data_to_show(
SubGhzViewTransmitter* subghz_transmitter,
const char* key_str,
const char* frequency_str,
const char* preset_str,
uint8_t show_button) {
furi_assert(subghz_transmitter);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
string_set(model->key_str, key_str);
string_set(model->frequency_str, frequency_str);
string_set(model->preset_str, preset_str);
@@ -44,7 +44,7 @@ void subghz_transmitter_add_data_to_show(
});
}
static void subghz_transmitter_button_right(Canvas* canvas, const char* str) {
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
const uint8_t button_height = 13;
const uint8_t vertical_offset = 3;
const uint8_t horizontal_offset = 1;
@@ -75,24 +75,24 @@ static void subghz_transmitter_button_right(Canvas* canvas, const char* str) {
canvas_invert_color(canvas);
}
void subghz_transmitter_draw(Canvas* canvas, SubghzTransmitterModel* model) {
void subghz_view_transmitter_draw(Canvas* canvas, SubGhzViewTransmitterModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 8, string_get_cstr(model->key_str));
canvas_draw_str(canvas, 78, 8, string_get_cstr(model->frequency_str));
canvas_draw_str(canvas, 113, 8, string_get_cstr(model->preset_str));
if(model->show_button) subghz_transmitter_button_right(canvas, "Send");
if(model->show_button) subghz_view_transmitter_button_right(canvas, "Send");
}
bool subghz_transmitter_input(InputEvent* event, void* context) {
bool subghz_view_transmitter_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
SubGhzViewTransmitter* subghz_transmitter = context;
bool can_be_sent = false;
if(event->key == InputKeyBack && event->type == InputTypeShort) {
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
string_reset(model->frequency_str);
string_reset(model->preset_str);
string_reset(model->key_str);
@@ -103,7 +103,7 @@ bool subghz_transmitter_input(InputEvent* event, void* context) {
}
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
if(model->show_button) {
can_be_sent = true;
}
@@ -112,42 +112,41 @@ bool subghz_transmitter_input(InputEvent* event, void* context) {
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
subghz_transmitter->callback(
SubghzCustomEventViewTransmitterSendStart, subghz_transmitter->context);
SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context);
return true;
} else if(can_be_sent && event->key == InputKeyOk && event->type == InputTypeRelease) {
subghz_transmitter->callback(
SubghzCustomEventViewTransmitterSendStop, subghz_transmitter->context);
SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context);
return true;
}
return true;
}
void subghz_transmitter_enter(void* context) {
void subghz_view_transmitter_enter(void* context) {
furi_assert(context);
// SubghzTransmitter* subghz_transmitter = context;
}
void subghz_transmitter_exit(void* context) {
void subghz_view_transmitter_exit(void* context) {
furi_assert(context);
// SubghzTransmitter* subghz_transmitter = context;
}
SubghzTransmitter* subghz_transmitter_alloc() {
SubghzTransmitter* subghz_transmitter = malloc(sizeof(SubghzTransmitter));
SubGhzViewTransmitter* subghz_view_transmitter_alloc() {
SubGhzViewTransmitter* subghz_transmitter = malloc(sizeof(SubGhzViewTransmitter));
// View allocation and configuration
subghz_transmitter->view = view_alloc();
view_allocate_model(
subghz_transmitter->view, ViewModelTypeLocking, sizeof(SubghzTransmitterModel));
subghz_transmitter->view, ViewModelTypeLocking, sizeof(SubGhzViewTransmitterModel));
view_set_context(subghz_transmitter->view, subghz_transmitter);
view_set_draw_callback(subghz_transmitter->view, (ViewDrawCallback)subghz_transmitter_draw);
view_set_input_callback(subghz_transmitter->view, subghz_transmitter_input);
view_set_enter_callback(subghz_transmitter->view, subghz_transmitter_enter);
view_set_exit_callback(subghz_transmitter->view, subghz_transmitter_exit);
view_set_draw_callback(
subghz_transmitter->view, (ViewDrawCallback)subghz_view_transmitter_draw);
view_set_input_callback(subghz_transmitter->view, subghz_view_transmitter_input);
view_set_enter_callback(subghz_transmitter->view, subghz_view_transmitter_enter);
view_set_exit_callback(subghz_transmitter->view, subghz_view_transmitter_exit);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
string_init(model->frequency_str);
string_init(model->preset_str);
string_init(model->key_str);
@@ -156,11 +155,11 @@ SubghzTransmitter* subghz_transmitter_alloc() {
return subghz_transmitter;
}
void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter) {
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
string_clear(model->frequency_str);
string_clear(model->preset_str);
string_clear(model->key_str);
@@ -170,7 +169,7 @@ void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter) {
free(subghz_transmitter);
}
View* subghz_transmitter_get_view(SubghzTransmitter* subghz_transmitter) {
View* subghz_view_transmitter_get_view(SubGhzViewTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
return subghz_transmitter->view;
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include <gui/view.h>
#include "../helpers/subghz_custom_event.h"
typedef struct SubGhzViewTransmitter SubGhzViewTransmitter;
typedef void (*SubGhzViewTransmitterCallback)(SubGhzCustomEvent event, void* context);
void subghz_view_transmitter_set_callback(
SubGhzViewTransmitter* subghz_transmitter,
SubGhzViewTransmitterCallback callback,
void* context);
SubGhzViewTransmitter* subghz_view_transmitter_alloc();
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter);
View* subghz_view_transmitter_get_view(SubGhzViewTransmitter* subghz_transmitter);
void subghz_view_transmitter_add_data_to_show(
SubGhzViewTransmitter* subghz_transmitter,
const char* key_str,
const char* frequency_str,
const char* preset_str,
uint8_t show_button);