diff options
author | Skorpionm <85568270+Skorpionm@users.noreply.github.com> | 2021-08-29 16:05:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-29 16:05:15 +0300 |
commit | 663dbbfe9f8e7c868310e3500be136e4f51d3979 (patch) | |
tree | 2afc2aecb9d61168fa429bc5d3c3d137a226d8f1 /applications/subghz/views | |
parent | 0a8a944e100c79432773ef3b6e749ab065e46cd1 (diff) |
SubGhz: frequency hopping mode (#671)
* SubGhz: fix assert on worker double stop.
* SubGhz: add hopping mode (315.00, 433.92, 868.00)
* SubGhz: add support for new alarms on the keelog protocol
* SubGhz: update te in princeton protocol
* SubGhz: move static to tests, rename sniffer to hopper/auto, remove delay from timer thread, optimize locking strategy.
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Diffstat (limited to 'applications/subghz/views')
-rw-r--r-- | applications/subghz/views/subghz_receiver.c | 111 | ||||
-rw-r--r-- | applications/subghz/views/subghz_receiver.h | 5 | ||||
-rw-r--r-- | applications/subghz/views/subghz_static.h | 11 | ||||
-rw-r--r-- | applications/subghz/views/subghz_test_static.c (renamed from applications/subghz/views/subghz_static.c) | 77 | ||||
-rw-r--r-- | applications/subghz/views/subghz_test_static.h | 11 |
5 files changed, 151 insertions, 64 deletions
diff --git a/applications/subghz/views/subghz_receiver.c b/applications/subghz/views/subghz_receiver.c index 147811dc..aa894deb 100644 --- a/applications/subghz/views/subghz_receiver.c +++ b/applications/subghz/views/subghz_receiver.c @@ -14,6 +14,16 @@ #define MAX_LEN_PX 100 #define MENU_ITEMS 4 +#define COUNT_FREQUNCY_SCANER 3 +const uint32_t subghz_frequencies_scanner[] = { + /* 300 - 348 */ + 315000000, + /* 387 - 464 */ + 433920000, /* LPD433 mid */ + /* 779 - 928 */ + 868350000, +}; + typedef enum { ReceiverSceneStart, ReceiverSceneMain, @@ -21,6 +31,12 @@ typedef enum { ReceiverSceneInfo, } SubghzReceiverScene; +typedef enum { + SubGhzHopperStateOFF, + SubGhzHopperStatePause, + SubGhzHopperStateRunnig, +} SubGhzHopperState; + static const Icon* ReceiverItemIcons[] = { [TYPE_PROTOCOL_UNKNOWN] = &I_quest_7x8, [TYPE_PROTOCOL_STATIC] = &I_unlock_7x8, @@ -33,6 +49,8 @@ struct SubghzReceiver { void* context; SubGhzWorker* worker; SubGhzProtocol* protocol; + osTimerId timer; + SubGhzHopperState hopper_state; }; typedef struct { @@ -188,13 +206,18 @@ void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) { break; case ReceiverSceneConfig: - snprintf( - buffer, - sizeof(buffer), - "Frequency: < %03ld.%03ldMHz >", - model->real_frequency / 1000000 % 1000, - model->real_frequency / 1000 % 1000); - canvas_draw_str(canvas, 0, 8, buffer); + if(model->frequency < subghz_frequencies_count) { + snprintf( + buffer, + sizeof(buffer), + "Frequency: < %03ld.%03ldMHz >", + model->real_frequency / 1000000 % 1000, + model->real_frequency / 1000 % 1000); + canvas_draw_str(canvas, 0, 8, buffer); + } else { + canvas_draw_str(canvas, 0, 8, "Frequency: <auto>"); + } + elements_button_center(canvas, "Save"); break; @@ -255,6 +278,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { return true; }); } else if(event->key == InputKeyLeft) { + subghz_receiver->hopper_state = SubGhzHopperStatePause; with_view_model( subghz_receiver->view, (SubghzReceiverModel * model) { model->scene = ReceiverSceneConfig; @@ -295,6 +319,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { subghz_rx_end(subghz_receiver->worker); model->real_frequency = subghz_rx(subghz_receiver->worker, subghz_frequencies[model->frequency]); + subghz_receiver->hopper_state = SubGhzHopperStateRunnig; model->scene = ReceiverSceneMain; return true; }); @@ -303,6 +328,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { subghz_receiver->callback(SubghzReceverEventSave, subghz_receiver->context); return false; } else if(can_be_saved && event->key == InputKeyOk && event->type == InputTypePress) { + subghz_receiver->hopper_state = SubGhzHopperStatePause; subghz_rx_end(subghz_receiver->worker); subghz_receiver->callback(SubghzReceverEventSendStart, subghz_receiver->context); return true; @@ -318,6 +344,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { subghz_receiver->view, (SubghzReceiverModel * model) { model->frequency = model->temp_frequency; model->real_frequency = subghz_frequencies[model->frequency]; + subghz_receiver->hopper_state = SubGhzHopperStateRunnig; if(subghz_history_get_item(model->history) == 0) { model->scene = ReceiverSceneStart; } else { @@ -329,9 +356,16 @@ bool subghz_receiver_input(InputEvent* event, void* context) { } else if(event->key == InputKeyOk) { with_view_model( subghz_receiver->view, (SubghzReceiverModel * model) { - subghz_rx_end(subghz_receiver->worker); - model->real_frequency = - subghz_rx(subghz_receiver->worker, subghz_frequencies[model->frequency]); + if(model->frequency < subghz_frequencies_count) { + subghz_rx_end(subghz_receiver->worker); + model->real_frequency = subghz_rx( + subghz_receiver->worker, subghz_frequencies[model->frequency]); + subghz_receiver->hopper_state = SubGhzHopperStateOFF; + } else { + osTimerStart(subghz_receiver->timer, 1024 / 10); + subghz_receiver->hopper_state = SubGhzHopperStateRunnig; + } + if(subghz_history_get_item(model->history) == 0) { model->scene = ReceiverSceneStart; } else { @@ -349,7 +383,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { if(model->frequency > 0) model->frequency--; model_updated = true; } else if(event->key == InputKeyRight) { - if(model->frequency < subghz_frequencies_count - 1) model->frequency++; + if(model->frequency < subghz_frequencies_count) model->frequency++; model_updated = true; } if(model_updated) { @@ -364,6 +398,7 @@ bool subghz_receiver_input(InputEvent* event, void* context) { if(event->key == InputKeyBack) { return false; } else if(event->key == InputKeyLeft) { + subghz_receiver->hopper_state = SubGhzHopperStatePause; with_view_model( subghz_receiver->view, (SubghzReceiverModel * model) { model->temp_frequency = model->frequency; @@ -416,6 +451,52 @@ void subghz_receiver_protocol_callback(SubGhzProtocolCommon* parser, void* conte subghz_receiver_update_offset(subghz_receiver); } +static void subghz_receiver_timer_callback(void* context) { + furi_assert(context); + SubghzReceiver* subghz_receiver = context; + + switch(subghz_receiver->hopper_state) { + case SubGhzHopperStateOFF: + return; + break; + case SubGhzHopperStatePause: + osTimerStart(subghz_receiver->timer, 1024 / 10); + return; + break; + default: + break; + } + float rssi = -127.0f; + with_view_model( + subghz_receiver->view, (SubghzReceiverModel * model) { + // See RSSI Calculation timings in CC1101 17.3 RSSI + rssi = furi_hal_subghz_get_rssi(); + + // Stay if RSSI is high enough + if(rssi > -90.0f) { + osTimerStart(subghz_receiver->timer, 1024 / 4); + return false; + } else { + osTimerStart(subghz_receiver->timer, 1024 / 10); + } + + // Select next frequency + if(model->frequency < COUNT_FREQUNCY_SCANER - 1) { + model->frequency++; + } else { + model->frequency = 0; + } + + // Restart radio + subghz_rx_end(subghz_receiver->worker); + subghz_protocol_reset(subghz_receiver->protocol); + model->real_frequency = + subghz_rx(subghz_receiver->worker, subghz_frequencies_scanner[model->frequency]); + + return true; + }); +} + void subghz_receiver_enter(void* context) { furi_assert(context); SubghzReceiver* subghz_receiver = context; @@ -441,6 +522,7 @@ void subghz_receiver_enter(void* context) { void subghz_receiver_exit(void* context) { furi_assert(context); SubghzReceiver* subghz_receiver = context; + osTimerStop(subghz_receiver->timer); with_view_model( subghz_receiver->view, (SubghzReceiverModel * model) { string_clean(model->text); @@ -469,6 +551,10 @@ SubghzReceiver* subghz_receiver_alloc() { model->history = subghz_history_alloc(); return true; }); + + subghz_receiver->timer = + osTimerNew(subghz_receiver_timer_callback, osTimerOnce, subghz_receiver, NULL); + subghz_receiver->hopper_state = SubGhzHopperStateOFF; return subghz_receiver; } @@ -481,6 +567,7 @@ void subghz_receiver_free(SubghzReceiver* subghz_receiver) { subghz_history_free(model->history); return false; }); + osTimerDelete(subghz_receiver->timer); view_free(subghz_receiver->view); free(subghz_receiver); } @@ -529,4 +616,4 @@ void subghz_receiver_frequency_preset_to_str(SubghzReceiver* subghz_receiver, st "Preset: %d\n", (int)frequency, (int)preset); -}
\ No newline at end of file +} diff --git a/applications/subghz/views/subghz_receiver.h b/applications/subghz/views/subghz_receiver.h index b4aa7bbc..400b5c13 100644 --- a/applications/subghz/views/subghz_receiver.h +++ b/applications/subghz/views/subghz_receiver.h @@ -36,8 +36,13 @@ void subghz_receiver_set_protocol( SubghzReceiver* subghz_receiver, SubGhzProtocolCommon* protocol_result, SubGhzProtocol* protocol); + SubGhzProtocolCommon* subghz_receiver_get_protocol(SubghzReceiver* subghz_receiver); + void subghz_receiver_set_worker(SubghzReceiver* subghz_receiver, SubGhzWorker* worker); + uint32_t subghz_receiver_get_frequency(SubghzReceiver* subghz_receiver); + FuriHalSubGhzPreset subghz_receiver_get_preset(SubghzReceiver* subghz_receiver); + void subghz_receiver_frequency_preset_to_str(SubghzReceiver* subghz_receiver, string_t output); diff --git a/applications/subghz/views/subghz_static.h b/applications/subghz/views/subghz_static.h deleted file mode 100644 index f80f8735..00000000 --- a/applications/subghz/views/subghz_static.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include <gui/view.h> - -typedef struct SubghzStatic SubghzStatic; - -SubghzStatic* subghz_static_alloc(); - -void subghz_static_free(SubghzStatic* subghz_static); - -View* subghz_static_get_view(SubghzStatic* subghz_static); diff --git a/applications/subghz/views/subghz_static.c b/applications/subghz/views/subghz_test_static.c index bdb11753..240dc215 100644 --- a/applications/subghz/views/subghz_static.c +++ b/applications/subghz/views/subghz_test_static.c @@ -1,4 +1,4 @@ -#include "subghz_static.h" +#include "subghz_test_static.h" #include "../subghz_i.h" #include <math.h> @@ -8,30 +8,30 @@ #include <notification/notification-messages.h> #include <lib/subghz/protocols/subghz_protocol_princeton.h> -static const uint32_t subghz_static_keys[] = { +static const uint32_t subghz_test_static_keys[] = { 0x0074BADE, 0x0074BADD, 0x0074BADB, 0x00E34A4E, }; -struct SubghzStatic { +struct SubghzTestStatic { View* view; SubGhzEncoderPrinceton* encoder; }; typedef enum { - SubghzStaticStatusRx, - SubghzStaticStatusTx, -} SubghzStaticStatus; + SubghzTestStaticStatusRx, + SubghzTestStaticStatusTx, +} SubghzTestStaticStatus; typedef struct { uint8_t frequency; uint32_t real_frequency; uint8_t button; -} SubghzStaticModel; +} SubghzTestStaticModel; -void subghz_static_draw(Canvas* canvas, SubghzStaticModel* model) { +void subghz_test_static_draw(Canvas* canvas, SubghzTestStaticModel* model) { char buffer[64]; canvas_set_color(canvas, ColorBlack); @@ -52,24 +52,21 @@ void subghz_static_draw(Canvas* canvas, SubghzStaticModel* model) { canvas_draw_str(canvas, 0, 31, buffer); } -bool subghz_static_input(InputEvent* event, void* context) { +bool subghz_test_static_input(InputEvent* event, void* context) { furi_assert(context); - SubghzStatic* instance = context; + SubghzTestStatic* instance = context; if(event->key == InputKeyBack) { return false; } with_view_model( - instance->view, (SubghzStaticModel * model) { - bool reconfigure = false; + instance->view, (SubghzTestStaticModel * model) { if(event->type == InputTypeShort) { if(event->key == InputKeyLeft) { if(model->frequency > 0) model->frequency--; - reconfigure = true; } else if(event->key == InputKeyRight) { if(model->frequency < subghz_frequencies_count - 1) model->frequency++; - reconfigure = true; } else if(event->key == InputKeyDown) { if(model->button > 0) model->button--; } else if(event->key == InputKeyUp) { @@ -77,28 +74,29 @@ bool subghz_static_input(InputEvent* event, void* context) { } } - if(reconfigure) { - furi_hal_subghz_idle(); - model->real_frequency = - furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]); - furi_hal_subghz_tx(); - } + model->real_frequency = subghz_frequencies[model->frequency]; if(event->key == InputKeyOk) { + NotificationApp* notification = furi_record_open("notification"); if(event->type == InputTypePress) { - NotificationApp* notification = furi_record_open("notification"); notification_message_block(notification, &sequence_set_red_255); + FURI_LOG_I("SubghzTestStatic", "TX Start"); + furi_hal_subghz_idle(); + furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]); + subghz_encoder_princeton_set( - instance->encoder, subghz_static_keys[model->button], 20); + instance->encoder, subghz_test_static_keys[model->button], 10000); + furi_hal_subghz_start_async_tx( subghz_encoder_princeton_yield, instance->encoder); - while(!furi_hal_subghz_is_async_tx_complete()) osDelay(33); + } else if(event->type == InputTypeRelease) { + FURI_LOG_I("SubghzTestStatic", "TX Stop"); furi_hal_subghz_stop_async_tx(); notification_message(notification, &sequence_reset_red); - furi_record_close("notification"); } + furi_record_close("notification"); } return true; @@ -107,9 +105,9 @@ bool subghz_static_input(InputEvent* event, void* context) { return true; } -void subghz_static_enter(void* context) { +void subghz_test_static_enter(void* context) { furi_assert(context); - SubghzStatic* instance = context; + SubghzTestStatic* instance = context; furi_hal_subghz_reset(); furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async); @@ -118,47 +116,44 @@ void subghz_static_enter(void* context) { hal_gpio_write(&gpio_cc1101_g0, false); with_view_model( - instance->view, (SubghzStaticModel * model) { + instance->view, (SubghzTestStaticModel * model) { model->frequency = subghz_frequencies_433_92; - model->real_frequency = - furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]); + model->real_frequency = subghz_frequencies[model->frequency]; model->button = 0; return true; }); - - furi_hal_subghz_tx(); } -void subghz_static_exit(void* context) { +void subghz_test_static_exit(void* context) { furi_assert(context); furi_hal_subghz_sleep(); } -SubghzStatic* subghz_static_alloc() { - SubghzStatic* instance = furi_alloc(sizeof(SubghzStatic)); +SubghzTestStatic* subghz_test_static_alloc() { + SubghzTestStatic* instance = furi_alloc(sizeof(SubghzTestStatic)); // View allocation and configuration instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzStaticModel)); + view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubghzTestStaticModel)); view_set_context(instance->view, instance); - view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_static_draw); - view_set_input_callback(instance->view, subghz_static_input); - view_set_enter_callback(instance->view, subghz_static_enter); - view_set_exit_callback(instance->view, subghz_static_exit); + 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(); return instance; } -void subghz_static_free(SubghzStatic* instance) { +void subghz_test_static_free(SubghzTestStatic* instance) { furi_assert(instance); subghz_encoder_princeton_free(instance->encoder); view_free(instance->view); free(instance); } -View* subghz_static_get_view(SubghzStatic* instance) { +View* subghz_test_static_get_view(SubghzTestStatic* instance) { furi_assert(instance); return instance->view; } diff --git a/applications/subghz/views/subghz_test_static.h b/applications/subghz/views/subghz_test_static.h new file mode 100644 index 00000000..ddcd8315 --- /dev/null +++ b/applications/subghz/views/subghz_test_static.h @@ -0,0 +1,11 @@ +#pragma once + +#include <gui/view.h> + +typedef struct SubghzTestStatic SubghzTestStatic; + +SubghzTestStatic* subghz_test_static_alloc(); + +void subghz_test_static_free(SubghzTestStatic* subghz_static); + +View* subghz_test_static_get_view(SubghzTestStatic* subghz_static); |