[FL-1610] SubGhz: scene based application, PT save and replay (#630)

* SubGhz: scene based application
* SubGhz: encoder/decoder separation, DMA streaming, update app and cli.
* SubGhz: 2 stage async tx complete, minor cleanup
* SubGhz: 2 stage async tx complete, FIX state pin end transmit
* SubGhz: Pricenton, receive TE signal
* SubGhz: Pricenton, add save data, add load data
* SubGhz: Add Read scene, Fix pricenton save, load funtion
* SubGhz: Add Read, Receiver, SaveName scene
* SubGhz: Read and Save (pricenton)
* SubGhz: add Load scence
* SubGhz: Fix select file scene, add load scene, add transmitter view, add send tx pricenton
* SubGhz: Fix pricenton encoder, fix transmitter send
* SubGhz: modified Pricenton Encoder (added guard time at the beginning), modified CC1101 config, code refactoring
* SubGhz: Fix pricenton encoder defalut TE
* Archive: Fix path and name SubGhz
* Archive: Fix name app SubGhz
* GubGhz: Came: add Save, Load key
* GubGhz: GateTX: add Save, Load key
* GubGhz: NeroSketch: add Save, Load key
* Github: better linters triggers
* SubGhz: adding fast loading keys Archive -> Run in app
* GubGhz: KeeLog: add Save, Load key, key generation from the serial number of the meter and the button
* SubGhz: format sources and fix compilation
* FuriHal: add subghz configuration description for AGC section
* SubGhz: save only protocols that can be saved. Cleanup.
* Github: lint on pull requests

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Skorpionm
2021-08-12 18:42:56 +04:00
committed by GitHub
parent 37d7870e52
commit 1cfa857f98
51 changed files with 2466 additions and 671 deletions

View File

@@ -1,4 +1,4 @@
#include "subghz_capture.h"
#include "subghz_analyze.h"
#include "../subghz_i.h"
#include <math.h>
@@ -13,7 +13,7 @@
#include <assets_icons.h>
struct SubghzCapture {
struct SubghzAnalyze {
View* view;
SubGhzWorker* worker;
SubGhzProtocol* protocol;
@@ -26,11 +26,11 @@ typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon parser;
} SubghzCaptureModel;
} SubghzAnalyzeModel;
static const char subghz_symbols[] = {'-', '\\', '|', '/'};
void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
void subghz_analyze_draw(Canvas* canvas, SubghzAnalyzeModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -39,7 +39,7 @@ void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
snprintf(
buffer,
sizeof(buffer),
"Capture: %03ld.%03ldMHz %c",
"Analyze: %03ld.%03ldMHz %c",
model->real_frequency / 1000000 % 1000,
model->real_frequency / 1000 % 1000,
subghz_symbols[model->counter % 4]);
@@ -63,46 +63,47 @@ void subghz_capture_draw(Canvas* canvas, SubghzCaptureModel* model) {
}
}
bool subghz_capture_input(InputEvent* event, void* context) {
bool subghz_analyze_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
if(event->type != InputTypeShort) return false;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
bool reconfigure = false;
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;
}
subghz_analyze->view, (SubghzAnalyzeModel * model) {
bool model_updated = false;
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
model_updated = true;
} else if(event->key == InputKeyRight) {
if(model->frequency < subghz_frequencies_count - 1) model->frequency++;
model_updated = true;
}
if(reconfigure) {
if(model_updated) {
furi_hal_subghz_idle();
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
furi_hal_subghz_rx();
}
return reconfigure;
return model_updated;
});
return true;
}
void subghz_capture_text_callback(string_t text, void* context) {
void subghz_analyze_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->counter++;
string_set(model->text, text);
model->scene = 0;
@@ -110,9 +111,9 @@ void subghz_capture_text_callback(string_t text, void* context) {
});
}
void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
void subghz_analyze_protocol_callback(SubGhzProtocolCommon* parser, void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
char buffer[64];
snprintf(
buffer,
@@ -128,7 +129,7 @@ void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* contex
parser->btn);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->counter++;
model->parser = *parser;
string_set(model->text, buffer);
@@ -137,16 +138,16 @@ void subghz_capture_protocol_callback(SubGhzProtocolCommon* parser, void* contex
});
}
void subghz_capture_enter(void* context) {
void subghz_analyze_enter(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
model->frequency = subghz_frequencies_433_92;
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
@@ -156,83 +157,77 @@ void subghz_capture_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_set_async_rx_callback(subghz_worker_rx_callback, subghz_capture->worker);
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz_analyze->worker);
subghz_worker_start(subghz_capture->worker);
subghz_worker_start(subghz_analyze->worker);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
}
void subghz_capture_exit(void* context) {
void subghz_analyze_exit(void* context) {
furi_assert(context);
SubghzCapture* subghz_capture = context;
SubghzAnalyze* subghz_analyze = context;
subghz_worker_stop(subghz_capture->worker);
subghz_worker_stop(subghz_analyze->worker);
furi_hal_subghz_stop_async_rx();
furi_hal_subghz_sleep();
}
uint32_t subghz_capture_back(void* context) {
return SubGhzViewMenu;
}
SubghzCapture* subghz_capture_alloc() {
SubghzCapture* subghz_capture = furi_alloc(sizeof(SubghzCapture));
SubghzAnalyze* subghz_analyze_alloc() {
SubghzAnalyze* subghz_analyze = furi_alloc(sizeof(SubghzAnalyze));
// View allocation and configuration
subghz_capture->view = view_alloc();
view_allocate_model(subghz_capture->view, ViewModelTypeLocking, sizeof(SubghzCaptureModel));
view_set_context(subghz_capture->view, subghz_capture);
view_set_draw_callback(subghz_capture->view, (ViewDrawCallback)subghz_capture_draw);
view_set_input_callback(subghz_capture->view, subghz_capture_input);
view_set_enter_callback(subghz_capture->view, subghz_capture_enter);
view_set_exit_callback(subghz_capture->view, subghz_capture_exit);
view_set_previous_callback(subghz_capture->view, subghz_capture_back);
subghz_analyze->view = view_alloc();
view_allocate_model(subghz_analyze->view, ViewModelTypeLocking, sizeof(SubghzAnalyzeModel));
view_set_context(subghz_analyze->view, subghz_analyze);
view_set_draw_callback(subghz_analyze->view, (ViewDrawCallback)subghz_analyze_draw);
view_set_input_callback(subghz_analyze->view, subghz_analyze_input);
view_set_enter_callback(subghz_analyze->view, subghz_analyze_enter);
view_set_exit_callback(subghz_analyze->view, subghz_analyze_exit);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
string_init(model->text);
return true;
});
subghz_capture->worker = subghz_worker_alloc();
subghz_capture->protocol = subghz_protocol_alloc();
subghz_analyze->worker = subghz_worker_alloc();
subghz_analyze->protocol = subghz_protocol_alloc();
subghz_worker_set_overrun_callback(
subghz_capture->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_analyze->worker, (SubGhzWorkerOverrunCallback)subghz_protocol_reset);
subghz_worker_set_pair_callback(
subghz_capture->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz_capture->worker, subghz_capture->protocol);
subghz_analyze->worker, (SubGhzWorkerPairCallback)subghz_protocol_parse);
subghz_worker_set_context(subghz_analyze->worker, subghz_analyze->protocol);
subghz_protocol_load_keeloq_file(
subghz_capture->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_analyze->protocol, "/ext/assets/subghz/keeloq_mfcodes");
subghz_protocol_load_nice_flor_s_file(
subghz_capture->protocol, "/ext/assets/subghz/nice_floor_s_rx");
subghz_analyze->protocol, "/ext/assets/subghz/nice_floor_s_rx");
subghz_protocol_enable_dump_text(
subghz_capture->protocol, subghz_capture_text_callback, subghz_capture);
subghz_analyze->protocol, subghz_analyze_text_callback, subghz_analyze);
return subghz_capture;
return subghz_analyze;
}
void subghz_capture_free(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
void subghz_analyze_free(SubghzAnalyze* subghz_analyze) {
furi_assert(subghz_analyze);
subghz_protocol_free(subghz_capture->protocol);
subghz_worker_free(subghz_capture->worker);
subghz_protocol_free(subghz_analyze->protocol);
subghz_worker_free(subghz_analyze->worker);
with_view_model(
subghz_capture->view, (SubghzCaptureModel * model) {
subghz_analyze->view, (SubghzAnalyzeModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_capture->view);
free(subghz_capture);
view_free(subghz_analyze->view);
free(subghz_analyze);
}
View* subghz_capture_get_view(SubghzCapture* subghz_capture) {
furi_assert(subghz_capture);
return subghz_capture->view;
View* subghz_analyze_get_view(SubghzAnalyze* subghz_analyze) {
furi_assert(subghz_analyze);
return subghz_analyze->view;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzAnalyze SubghzAnalyze;
SubghzAnalyze* subghz_analyze_alloc();
void subghz_analyze_free(SubghzAnalyze* subghz_analyze);
View* subghz_analyze_get_view(SubghzAnalyze* subghz_analyze);

View File

@@ -1,11 +0,0 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzCapture SubghzCapture;
SubghzCapture* subghz_capture_alloc();
void subghz_capture_free(SubghzCapture* subghz_capture);
View* subghz_capture_get_view(SubghzCapture* subghz_capture);

View File

@@ -0,0 +1,146 @@
#include "subghz_receiver.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include <assets_icons.h>
struct SubghzReceiver {
View* view;
SubghzReceiverCallback callback;
void* context;
};
typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon* protocol;
} SubghzReceiverModel;
void subghz_receiver_set_callback(
SubghzReceiver* subghz_receiver,
SubghzReceiverCallback callback,
void* context) {
furi_assert(subghz_receiver);
furi_assert(callback);
subghz_receiver->callback = callback;
subghz_receiver->context = context;
}
void subghz_receiver_set_protocol(SubghzReceiver* subghz_receiver, SubGhzProtocolCommon* protocol) {
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
model->protocol = protocol;
return true;
});
}
void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text));
elements_button_left(canvas, "Back");
if(model->protocol && model->protocol->to_save_string) {
elements_button_right(canvas, "Save");
}
}
bool subghz_receiver_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
if(event->type != InputTypeShort) return false;
bool can_be_saved = false;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
can_be_saved = (model->protocol && model->protocol->to_save_string);
return false;
});
if(event->key == InputKeyBack) {
return false;
} else if(event->key == InputKeyLeft) {
subghz_receiver->callback(SubghzReceverEventBack, subghz_receiver->context);
} else if(can_be_saved && event->key == InputKeyRight) {
subghz_receiver->callback(SubghzReceverEventSave, subghz_receiver->context);
}
return true;
}
void subghz_receiver_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_set(model->text, text);
model->scene = 0;
return true;
});
}
void subghz_receiver_enter(void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
model->protocol->to_string(model->protocol, model->text);
return true;
});
}
void subghz_receiver_exit(void* context) {
furi_assert(context);
SubghzReceiver* subghz_receiver = context;
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_clean(model->text);
return true;
});
}
SubghzReceiver* subghz_receiver_alloc() {
SubghzReceiver* subghz_receiver = furi_alloc(sizeof(SubghzReceiver));
// View allocation and configuration
subghz_receiver->view = view_alloc();
view_allocate_model(subghz_receiver->view, ViewModelTypeLocking, sizeof(SubghzReceiverModel));
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);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_init(model->text);
return true;
});
return subghz_receiver;
}
void subghz_receiver_free(SubghzReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
with_view_model(
subghz_receiver->view, (SubghzReceiverModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_receiver->view);
free(subghz_receiver);
}
View* subghz_receiver_get_view(SubghzReceiver* subghz_receiver) {
furi_assert(subghz_receiver);
return subghz_receiver->view;
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <gui/view.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
typedef enum {
SubghzReceverEventSave,
SubghzReceverEventBack,
} SubghzReceverEvent;
typedef struct SubghzReceiver SubghzReceiver;
typedef void (*SubghzReceiverCallback)(SubghzReceverEvent 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_set_protocol(SubghzReceiver* subghz_receiver, SubGhzProtocolCommon* protocol);

View File

@@ -6,20 +6,18 @@
#include <furi-hal.h>
#include <input/input.h>
#include <notification/notification-messages.h>
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
static const uint8_t subghz_static_keys[][4] = {
{0x74, 0xBA, 0xDE},
{0x74, 0xBA, 0xDD},
{0x74, 0xBA, 0xDB},
{0xE3, 0x4A, 0x4E},
static const uint32_t subghz_static_keys[] = {
0x0074BADE,
0x0074BADD,
0x0074BADB,
0x00E34A4E,
};
#define SUBGHZ_PT_SHORT 376
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
#define SUBGHZ_PT_GUARD 10600
struct SubghzStatic {
View* view;
SubGhzEncoderPrinceton* encoder;
};
typedef enum {
@@ -56,14 +54,14 @@ void subghz_static_draw(Canvas* canvas, SubghzStaticModel* model) {
bool subghz_static_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzStatic* subghz_static = context;
SubghzStatic* instance = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_static->view, (SubghzStaticModel * model) {
instance->view, (SubghzStaticModel * model) {
bool reconfigure = false;
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
@@ -88,31 +86,16 @@ bool subghz_static_input(InputEvent* event, void* context) {
if(event->key == InputKeyOk) {
if(event->type == InputTypePress) {
const uint8_t* key = subghz_static_keys[model->button];
NotificationApp* notification = furi_record_open("notification");
notification_message_block(notification, &sequence_set_red_255);
__disable_irq();
for(uint8_t r = 0; r < 20; r++) {
//Payload
for(uint8_t i = 0; i < 24; i++) {
uint8_t byte = i / 8;
uint8_t bit = i % 8;
bool value = (key[byte] >> (7 - bit)) & 1;
// Payload send
hal_gpio_write(&gpio_cc1101_g0, true);
delay_us(value ? SUBGHZ_PT_SHORT : SUBGHZ_PT_LONG);
hal_gpio_write(&gpio_cc1101_g0, false);
delay_us(value ? SUBGHZ_PT_LONG : SUBGHZ_PT_SHORT);
}
// Last bit
hal_gpio_write(&gpio_cc1101_g0, true);
delay_us(SUBGHZ_PT_SHORT);
hal_gpio_write(&gpio_cc1101_g0, false);
// Guard time
delay_us(10600);
}
__enable_irq();
subghz_encoder_princeton_reset(
instance->encoder, subghz_static_keys[model->button], 20);
furi_hal_subghz_start_async_tx(
subghz_encoder_princeton_yield, instance->encoder);
while(!furi_hal_subghz_is_async_tx_complete()) osDelay(33);
furi_hal_subghz_stop_async_tx();
notification_message(notification, &sequence_reset_red);
furi_record_close("notification");
}
@@ -126,7 +109,7 @@ bool subghz_static_input(InputEvent* event, void* context) {
void subghz_static_enter(void* context) {
furi_assert(context);
SubghzStatic* subghz_static = context;
SubghzStatic* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
@@ -135,7 +118,7 @@ void subghz_static_enter(void* context) {
hal_gpio_write(&gpio_cc1101_g0, false);
with_view_model(
subghz_static->view, (SubghzStaticModel * model) {
instance->view, (SubghzStaticModel * model) {
model->frequency = subghz_frequencies_433_92;
model->real_frequency =
furi_hal_subghz_set_frequency_and_path(subghz_frequencies[model->frequency]);
@@ -148,39 +131,34 @@ void subghz_static_enter(void* context) {
void subghz_static_exit(void* context) {
furi_assert(context);
// SubghzStatic* subghz_static = context;
// Reinitialize IC to default state
furi_hal_subghz_sleep();
}
uint32_t subghz_static_back(void* context) {
return SubGhzViewMenu;
}
SubghzStatic* subghz_static_alloc() {
SubghzStatic* subghz_static = furi_alloc(sizeof(SubghzStatic));
SubghzStatic* instance = furi_alloc(sizeof(SubghzStatic));
// View allocation and configuration
subghz_static->view = view_alloc();
view_allocate_model(subghz_static->view, ViewModelTypeLockFree, sizeof(SubghzStaticModel));
view_set_context(subghz_static->view, subghz_static);
view_set_draw_callback(subghz_static->view, (ViewDrawCallback)subghz_static_draw);
view_set_input_callback(subghz_static->view, subghz_static_input);
view_set_enter_callback(subghz_static->view, subghz_static_enter);
view_set_exit_callback(subghz_static->view, subghz_static_exit);
view_set_previous_callback(subghz_static->view, subghz_static_back);
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLockFree, sizeof(SubghzStaticModel));
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);
return subghz_static;
instance->encoder = subghz_encoder_princeton_alloc();
return instance;
}
void subghz_static_free(SubghzStatic* subghz_static) {
furi_assert(subghz_static);
view_free(subghz_static->view);
free(subghz_static);
void subghz_static_free(SubghzStatic* instance) {
furi_assert(instance);
subghz_encoder_princeton_free(instance->encoder);
view_free(instance->view);
free(instance);
}
View* subghz_static_get_view(SubghzStatic* subghz_static) {
furi_assert(subghz_static);
return subghz_static->view;
View* subghz_static_get_view(SubghzStatic* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzTestBasic SubghzTestBasic;
SubghzTestBasic* subghz_test_basic_alloc();
void subghz_test_basic_free(SubghzTestBasic* subghz_test_basic);
View* subghz_test_basic_get_view(SubghzTestBasic* subghz_test_basic);

View File

@@ -1,4 +1,4 @@
#include "subghz_test_basic.h"
#include "subghz_test_carrier.h"
#include "../subghz_i.h"
#include <math.h>
@@ -6,25 +6,25 @@
#include <furi-hal.h>
#include <input/input.h>
struct SubghzTestBasic {
struct SubghzTestCarrier {
View* view;
osTimerId timer;
};
typedef enum {
SubghzTestBasicModelStatusRx,
SubghzTestBasicModelStatusTx,
} SubghzTestBasicModelStatus;
SubghzTestCarrierModelStatusRx,
SubghzTestCarrierModelStatusTx,
} SubghzTestCarrierModelStatus;
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
FuriHalSubGhzPath path;
float rssi;
SubghzTestBasicModelStatus status;
} SubghzTestBasicModel;
SubghzTestCarrierModelStatus status;
} SubghzTestCarrierModel;
void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
void subghz_test_carrier_draw(Canvas* canvas, SubghzTestCarrierModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
@@ -54,7 +54,7 @@ void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
}
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
canvas_draw_str(canvas, 0, 31, buffer);
if(model->status == SubghzTestBasicModelStatusRx) {
if(model->status == SubghzTestCarrierModelStatusRx) {
snprintf(
buffer,
sizeof(buffer),
@@ -67,17 +67,17 @@ void subghz_test_basic_draw(Canvas* canvas, SubghzTestBasicModel* model) {
}
}
bool subghz_test_basic_input(InputEvent* event, void* context) {
bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
osTimerStop(subghz_test_basic->timer);
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
osTimerStop(subghz_test_carrier->timer);
furi_hal_subghz_idle();
if(event->type == InputTypeShort) {
@@ -90,10 +90,10 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
if(model->path < FuriHalSubGhzPath868) model->path++;
} else if(event->key == InputKeyOk) {
if(model->status == SubghzTestBasicModelStatusTx) {
model->status = SubghzTestBasicModelStatusRx;
if(model->status == SubghzTestCarrierModelStatusTx) {
model->status = SubghzTestCarrierModelStatusRx;
} else {
model->status = SubghzTestBasicModelStatusTx;
model->status = SubghzTestCarrierModelStatusTx;
}
}
@@ -102,10 +102,10 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
furi_hal_subghz_set_path(model->path);
}
if(model->status == SubghzTestBasicModelStatusRx) {
if(model->status == SubghzTestCarrierModelStatusRx) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
osTimerStart(subghz_test_basic->timer, 1024 / 4);
osTimerStart(subghz_test_carrier->timer, 1024 / 4);
} else {
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
@@ -118,9 +118,9 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
return true;
}
void subghz_test_basic_enter(void* context) {
void subghz_test_carrier_enter(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
@@ -128,74 +128,69 @@ void subghz_test_basic_enter(void* context) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
model->frequency = subghz_frequencies_433_92; // 433
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubghzTestBasicModelStatusRx;
model->status = SubghzTestCarrierModelStatusRx;
return true;
});
furi_hal_subghz_rx();
osTimerStart(subghz_test_basic->timer, 1024 / 4);
osTimerStart(subghz_test_carrier->timer, 1024 / 4);
}
void subghz_test_basic_exit(void* context) {
void subghz_test_carrier_exit(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
osTimerStop(subghz_test_basic->timer);
osTimerStop(subghz_test_carrier->timer);
// Reinitialize IC to default state
furi_hal_subghz_sleep();
}
void subghz_test_basic_rssi_timer_callback(void* context) {
void subghz_test_carrier_rssi_timer_callback(void* context) {
furi_assert(context);
SubghzTestBasic* subghz_test_basic = context;
SubghzTestCarrier* subghz_test_carrier = context;
with_view_model(
subghz_test_basic->view, (SubghzTestBasicModel * model) {
subghz_test_carrier->view, (SubghzTestCarrierModel * model) {
model->rssi = furi_hal_subghz_get_rssi();
return true;
});
}
uint32_t subghz_test_basic_back(void* context) {
return SubGhzViewMenu;
}
SubghzTestBasic* subghz_test_basic_alloc() {
SubghzTestBasic* subghz_test_basic = furi_alloc(sizeof(SubghzTestBasic));
SubghzTestCarrier* subghz_test_carrier_alloc() {
SubghzTestCarrier* subghz_test_carrier = furi_alloc(sizeof(SubghzTestCarrier));
// View allocation and configuration
subghz_test_basic->view = view_alloc();
subghz_test_carrier->view = view_alloc();
view_allocate_model(
subghz_test_basic->view, ViewModelTypeLockFree, sizeof(SubghzTestBasicModel));
view_set_context(subghz_test_basic->view, subghz_test_basic);
view_set_draw_callback(subghz_test_basic->view, (ViewDrawCallback)subghz_test_basic_draw);
view_set_input_callback(subghz_test_basic->view, subghz_test_basic_input);
view_set_enter_callback(subghz_test_basic->view, subghz_test_basic_enter);
view_set_exit_callback(subghz_test_basic->view, subghz_test_basic_exit);
view_set_previous_callback(subghz_test_basic->view, subghz_test_basic_back);
subghz_test_carrier->view, ViewModelTypeLockFree, 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);
view_set_enter_callback(subghz_test_carrier->view, subghz_test_carrier_enter);
view_set_exit_callback(subghz_test_carrier->view, subghz_test_carrier_exit);
subghz_test_basic->timer = osTimerNew(
subghz_test_basic_rssi_timer_callback, osTimerPeriodic, subghz_test_basic, NULL);
subghz_test_carrier->timer = osTimerNew(
subghz_test_carrier_rssi_timer_callback, osTimerPeriodic, subghz_test_carrier, NULL);
return subghz_test_basic;
return subghz_test_carrier;
}
void subghz_test_basic_free(SubghzTestBasic* subghz_test_basic) {
furi_assert(subghz_test_basic);
osTimerDelete(subghz_test_basic->timer);
view_free(subghz_test_basic->view);
free(subghz_test_basic);
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_basic_get_view(SubghzTestBasic* subghz_test_basic) {
furi_assert(subghz_test_basic);
return subghz_test_basic->view;
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
return subghz_test_carrier->view;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct SubghzTestCarrier SubghzTestCarrier;
SubghzTestCarrier* subghz_test_carrier_alloc();
void subghz_test_carrier_free(SubghzTestCarrier* subghz_test_carrier);
View* subghz_test_carrier_get_view(SubghzTestCarrier* subghz_test_carrier);

View File

@@ -10,16 +10,12 @@
#define SUBGHZ_TEST_PACKET_COUNT 1000
#define SUBGHZ_PT_SHORT 376
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
#define SUBGHZ_PT_GUARD 10600
struct SubghzTestPacket {
View* view;
osTimerId timer;
size_t tx_buffer_size;
uint32_t* tx_buffer;
SubGhzProtocolPrinceton* princeton;
SubGhzDecoderPrinceton* decoder;
SubGhzEncoderPrinceton* encoder;
volatile size_t packet_rx;
};
@@ -43,7 +39,7 @@ volatile bool subghz_test_packet_overrun = false;
static void subghz_test_packet_rx_callback(bool level, uint32_t duration, void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
subghz_protocol_princeton_parse(instance->princeton, level, duration);
subghz_decoder_princeton_parse(instance->decoder, level, duration);
}
static void subghz_test_packet_rx_pt_callback(SubGhzProtocolCommon* parser, void* context) {
@@ -62,8 +58,8 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
model->rssi = furi_hal_subghz_get_rssi();
model->packets = instance->packet_rx;
} else {
model->packets =
SUBGHZ_TEST_PACKET_COUNT - furi_hal_subghz_get_async_tx_repeat_left();
model->packets = SUBGHZ_TEST_PACKET_COUNT -
subghz_encoder_princeton_get_repeat_left(instance->encoder);
}
return true;
});
@@ -155,10 +151,10 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
}
if(model->status == SubghzTestPacketModelStatusRx) {
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
} else {
furi_hal_subghz_start_async_tx(
instance->tx_buffer, instance->tx_buffer_size, SUBGHZ_TEST_PACKET_COUNT);
subghz_encoder_princeton_reset(instance->encoder, 0x00AABBCC, 1000);
furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, instance->encoder);
}
return true;
@@ -171,30 +167,8 @@ void subghz_test_packet_enter(void* context) {
furi_assert(context);
SubghzTestPacket* instance = context;
instance->tx_buffer_size = 25 * 2 * sizeof(uint32_t);
instance->tx_buffer = furi_alloc(instance->tx_buffer_size);
const uint32_t key = 0x00ABCDEF;
size_t pos = 0;
for(uint8_t i = 0; i < 24; i++) {
uint8_t byte = i / 8;
uint8_t bit = i % 8;
bool value = (((uint8_t*)&key)[2 - byte] >> (7 - bit)) & 1;
if(value) {
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
instance->tx_buffer[pos++] = SUBGHZ_PT_LONG;
} else {
instance->tx_buffer[pos++] = SUBGHZ_PT_LONG;
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
}
}
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT;
instance->tx_buffer[pos++] = SUBGHZ_PT_SHORT + SUBGHZ_PT_GUARD;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
furi_hal_subghz_set_async_rx_callback(subghz_test_packet_rx_callback, instance);
with_view_model(
instance->view, (SubghzTestPacketModel * model) {
@@ -207,7 +181,7 @@ void subghz_test_packet_enter(void* context) {
return true;
});
furi_hal_subghz_start_async_rx();
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
osTimerStart(instance->timer, 1024 / 4);
}
@@ -228,14 +202,9 @@ void subghz_test_packet_exit(void* context) {
}
return true;
});
furi_hal_subghz_set_async_rx_callback(NULL, NULL);
furi_hal_subghz_sleep();
}
uint32_t subghz_test_packet_back(void* context) {
return SubGhzViewMenu;
}
SubghzTestPacket* subghz_test_packet_alloc() {
SubghzTestPacket* instance = furi_alloc(sizeof(SubghzTestPacket));
@@ -247,14 +216,14 @@ SubghzTestPacket* subghz_test_packet_alloc() {
view_set_input_callback(instance->view, subghz_test_packet_input);
view_set_enter_callback(instance->view, subghz_test_packet_enter);
view_set_exit_callback(instance->view, subghz_test_packet_exit);
view_set_previous_callback(instance->view, subghz_test_packet_back);
instance->timer =
osTimerNew(subghz_test_packet_rssi_timer_callback, osTimerPeriodic, instance, NULL);
instance->princeton = subghz_protocol_princeton_alloc();
instance->decoder = subghz_decoder_princeton_alloc();
subghz_protocol_common_set_callback(
(SubGhzProtocolCommon*)instance->princeton, subghz_test_packet_rx_pt_callback, instance);
(SubGhzProtocolCommon*)instance->decoder, subghz_test_packet_rx_pt_callback, instance);
instance->encoder = subghz_encoder_princeton_alloc();
return instance;
}
@@ -262,7 +231,9 @@ SubghzTestPacket* subghz_test_packet_alloc() {
void subghz_test_packet_free(SubghzTestPacket* instance) {
furi_assert(instance);
subghz_protocol_princeton_free(instance->princeton);
subghz_decoder_princeton_free(instance->decoder);
subghz_encoder_princeton_free(instance->encoder);
osTimerDelete(instance->timer);
view_free(instance->view);
free(instance);

View File

@@ -0,0 +1,138 @@
#include "subghz_transmitter.h"
#include "../subghz_i.h"
#include <math.h>
#include <furi.h>
#include <furi-hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <notification/notification-messages.h>
#include <assets_icons.h>
struct SubghzTransmitter {
View* view;
SubghzTransmitterCallback callback;
void* context;
};
typedef struct {
string_t text;
uint16_t scene;
SubGhzProtocolCommon* protocol;
} SubghzTransmitterModel;
void subghz_transmitter_set_callback(
SubghzTransmitter* subghz_transmitter,
SubghzTransmitterCallback callback,
void* context) {
furi_assert(subghz_transmitter);
subghz_transmitter->callback = callback;
subghz_transmitter->context = context;
}
void subghz_transmitter_set_protocol(
SubghzTransmitter* subghz_transmitter,
SubGhzProtocolCommon* protocol) {
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
model->protocol = protocol;
return true;
});
}
void subghz_transmitter_draw(Canvas* canvas, SubghzTransmitterModel* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text));
elements_button_center(canvas, "Send");
}
bool subghz_transmitter_input(InputEvent* event, void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
if(event->type != InputTypeShort) return false;
if(event->key == InputKeyBack) {
return false;
} else if(event->key == InputKeyOk) {
subghz_transmitter->callback(SubghzTransmitterEventSend, subghz_transmitter->context);
return true;
}
return true;
}
void subghz_transmitter_text_callback(string_t text, void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_set(model->text, text);
model->scene = 0;
return true;
});
}
void subghz_transmitter_enter(void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
model->protocol->to_string(model->protocol, model->text);
return true;
});
}
void subghz_transmitter_exit(void* context) {
furi_assert(context);
SubghzTransmitter* subghz_transmitter = context;
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_clean(model->text);
return true;
});
}
SubghzTransmitter* subghz_transmitter_alloc() {
SubghzTransmitter* subghz_transmitter = furi_alloc(sizeof(SubghzTransmitter));
// View allocation and configuration
subghz_transmitter->view = view_alloc();
view_allocate_model(
subghz_transmitter->view, ViewModelTypeLocking, sizeof(SubghzTransmitterModel));
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);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_init(model->text);
return true;
});
return subghz_transmitter;
}
void subghz_transmitter_free(SubghzTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
with_view_model(
subghz_transmitter->view, (SubghzTransmitterModel * model) {
string_clear(model->text);
return true;
});
view_free(subghz_transmitter->view);
free(subghz_transmitter);
}
View* subghz_transmitter_get_view(SubghzTransmitter* subghz_transmitter) {
furi_assert(subghz_transmitter);
return subghz_transmitter->view;
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <gui/view.h>
#include <lib/subghz/protocols/subghz_protocol_common.h>
typedef enum {
SubghzTransmitterEventSend,
SubghzTransmitterEventBack,
} SubghzTransmitterEvent;
typedef struct SubghzTransmitter SubghzTransmitter;
typedef void (*SubghzTransmitterCallback)(SubghzTransmitterEvent 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_set_protocol(
SubghzTransmitter* subghz_transmitter,
SubGhzProtocolCommon* protocol);