mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-11 23:38:11 -07:00
prt2
This commit is contained in:
@@ -40,6 +40,7 @@ struct SubGhzProtocolEncoderRAW {
|
||||
|
||||
bool is_running;
|
||||
FuriString* file_name;
|
||||
FuriString* radio_device_name;
|
||||
SubGhzFileEncoderWorker* file_worker_encoder;
|
||||
};
|
||||
|
||||
@@ -282,6 +283,7 @@ void* subghz_protocol_encoder_raw_alloc(SubGhzEnvironment* environment) {
|
||||
|
||||
instance->base.protocol = &subghz_protocol_raw;
|
||||
instance->file_name = furi_string_alloc();
|
||||
instance->radio_device_name = furi_string_alloc();
|
||||
instance->is_running = false;
|
||||
return instance;
|
||||
}
|
||||
@@ -300,6 +302,7 @@ void subghz_protocol_encoder_raw_free(void* context) {
|
||||
SubGhzProtocolEncoderRAW* instance = context;
|
||||
subghz_protocol_encoder_raw_stop(instance);
|
||||
furi_string_free(instance->file_name);
|
||||
furi_string_free(instance->radio_device_name);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
@@ -318,7 +321,9 @@ static bool subghz_protocol_encoder_raw_worker_init(SubGhzProtocolEncoderRAW* in
|
||||
|
||||
instance->file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(
|
||||
instance->file_worker_encoder, furi_string_get_cstr(instance->file_name))) {
|
||||
instance->file_worker_encoder,
|
||||
furi_string_get_cstr(instance->file_name),
|
||||
furi_string_get_cstr(instance->radio_device_name))) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
instance->is_running = true;
|
||||
@@ -328,7 +333,10 @@ static bool subghz_protocol_encoder_raw_worker_init(SubGhzProtocolEncoderRAW* in
|
||||
return instance->is_running;
|
||||
}
|
||||
|
||||
void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char* file_path) {
|
||||
void subghz_protocol_raw_gen_fff_data(
|
||||
FlipperFormat* flipper_format,
|
||||
const char* file_path,
|
||||
const char* radio_device_name) {
|
||||
do {
|
||||
stream_clean(flipper_format_get_raw_stream(flipper_format));
|
||||
if(!flipper_format_write_string_cstr(flipper_format, "Protocol", "RAW")) {
|
||||
@@ -340,6 +348,12 @@ void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char*
|
||||
FURI_LOG_E(TAG, "Unable to add File_name");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_write_string_cstr(
|
||||
flipper_format, "Radio_device_name", radio_device_name)) {
|
||||
FURI_LOG_E(TAG, "Unable to add Radio_device_name");
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
|
||||
@@ -364,6 +378,13 @@ SubGhzProtocolStatus
|
||||
}
|
||||
furi_string_set(instance->file_name, temp_str);
|
||||
|
||||
if(!flipper_format_read_string(flipper_format, "Radio_device_name", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Radio_device_name");
|
||||
res = SubGhzProtocolStatusErrorParserOthers;
|
||||
break;
|
||||
}
|
||||
furi_string_set(instance->radio_device_name, temp_str);
|
||||
|
||||
if(!subghz_protocol_encoder_raw_worker_init(instance)) {
|
||||
res = SubGhzProtocolStatusErrorEncoderGetUpload;
|
||||
break;
|
||||
|
||||
@@ -126,8 +126,12 @@ void subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
||||
* File generation for RAW work.
|
||||
* @param flipper_format Pointer to a FlipperFormat instance
|
||||
* @param file_path File path
|
||||
* @param radio_dev_name Radio device name
|
||||
*/
|
||||
void subghz_protocol_raw_gen_fff_data(FlipperFormat* flipper_format, const char* file_path);
|
||||
void subghz_protocol_raw_gen_fff_data(
|
||||
FlipperFormat* flipper_format,
|
||||
const char* file_path,
|
||||
const char* radio_dev_name);
|
||||
|
||||
/**
|
||||
* Deserialize and generating an upload to send.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
|
||||
#define TAG "SubGhzFileEncoderWorker"
|
||||
|
||||
@@ -21,6 +22,7 @@ struct SubGhzFileEncoderWorker {
|
||||
bool is_storage_slow;
|
||||
FuriString* str_data;
|
||||
FuriString* file_path;
|
||||
const SubGhzDevice* device;
|
||||
|
||||
SubGhzFileEncoderWorkerCallbackEnd callback_end;
|
||||
void* context_end;
|
||||
@@ -180,10 +182,13 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
||||
if(instance->is_storage_slow) {
|
||||
FURI_LOG_E(TAG, "Storage is slow");
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "End read file");
|
||||
while(!furi_hal_subghz_is_async_tx_complete() && instance->worker_running) {
|
||||
while(instance->device && !subghz_devices_is_async_complete_tx(instance->device) &&
|
||||
instance->worker_running) {
|
||||
furi_delay_ms(5);
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "End transmission");
|
||||
while(instance->worker_running) {
|
||||
if(instance->worker_stopping) {
|
||||
@@ -230,12 +235,16 @@ void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) {
|
||||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const char* file_path) {
|
||||
bool subghz_file_encoder_worker_start(
|
||||
SubGhzFileEncoderWorker* instance,
|
||||
const char* file_path,
|
||||
const char* radio_device_name) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
furi_stream_buffer_reset(instance->stream);
|
||||
furi_string_set(instance->file_path, file_path);
|
||||
instance->device = subghz_devices_get_by_name(radio_device_name);
|
||||
instance->worker_running = true;
|
||||
furi_thread_start(instance->thread);
|
||||
|
||||
|
||||
@@ -47,9 +47,14 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context);
|
||||
/**
|
||||
* Start SubGhzFileEncoderWorker.
|
||||
* @param instance Pointer to a SubGhzFileEncoderWorker instance
|
||||
* @param file_path File path
|
||||
* @param radio_device_name Radio device name
|
||||
* @return bool - true if ok
|
||||
*/
|
||||
bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const char* file_path);
|
||||
bool subghz_file_encoder_worker_start(
|
||||
SubGhzFileEncoderWorker* instance,
|
||||
const char* file_path,
|
||||
const char* radio_device_name);
|
||||
|
||||
/**
|
||||
* Stop SubGhzFileEncoderWorker
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-list.h>
|
||||
#include <furi_hal_subghz_configs.h>
|
||||
#include <lib/subghz/devices/cc1101_configs.h>
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
@@ -195,23 +195,23 @@ static void subghz_setting_load_default_region(
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM270",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
(uint8_t*)subghz_device_cc1101_preset_ook_270khz_async_regs,
|
||||
subghz_device_cc1101_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM650",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
(uint8_t*)subghz_device_cc1101_preset_ook_650khz_async_regs,
|
||||
subghz_device_cc1101_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM238",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
(uint8_t*)subghz_device_cc1101_preset_2fsk_dev2_38khz_async_regs,
|
||||
subghz_device_cc1101_preset_2fsk_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM476",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
(uint8_t*)subghz_device_cc1101_preset_2fsk_dev47_6khz_async_regs,
|
||||
subghz_device_cc1101_preset_2fsk_async_patable);
|
||||
}
|
||||
|
||||
// Region check removed
|
||||
@@ -270,6 +270,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
//Todo: add a frequency support check depending on the selected radio device
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->frequencies, temp_data32);
|
||||
|
||||
@@ -21,6 +21,8 @@ struct SubGhzTxRxWorker {
|
||||
SubGhzTxRxWorkerStatus status;
|
||||
|
||||
uint32_t frequency;
|
||||
const SubGhzDevice* device;
|
||||
const GpioPin* device_data_gpio;
|
||||
|
||||
SubGhzTxRxWorkerCallbackHaveRead callback_have_read;
|
||||
void* context_have_read;
|
||||
@@ -65,33 +67,33 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
|
||||
uint8_t timeout = 100;
|
||||
bool ret = false;
|
||||
if(instance->status != SubGhzTxRxWorkerStatusRx) {
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_set_rx(instance->device);
|
||||
instance->status = SubGhzTxRxWorkerStatusRx;
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
//waiting for reception to complete
|
||||
while(furi_hal_gpio_read(furi_hal_subghz.cc1101_g0_pin)) {
|
||||
while(furi_hal_gpio_read(instance->device_data_gpio)) {
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "RX cc1101_g0 timeout");
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
subghz_devices_set_rx(instance->device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(furi_hal_subghz_rx_pipe_not_empty()) {
|
||||
if(subghz_devices_rx_pipe_not_empty(instance->device)) {
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"RSSI: %03.1fdbm LQI: %d",
|
||||
(double)furi_hal_subghz_get_rssi(),
|
||||
furi_hal_subghz_get_lqi());
|
||||
if(furi_hal_subghz_is_rx_data_crc_valid()) {
|
||||
furi_hal_subghz_read_packet(data, size);
|
||||
(double)subghz_devices_get_rssi(instance->device),
|
||||
subghz_devices_get_lqi(instance->device));
|
||||
if(subghz_devices_is_rx_data_crc_valid(instance->device)) {
|
||||
subghz_devices_read_packet(instance->device, data, size);
|
||||
ret = true;
|
||||
}
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
subghz_devices_set_rx(instance->device);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -99,13 +101,13 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
|
||||
void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t size) {
|
||||
uint8_t timeout = 200;
|
||||
if(instance->status != SubGhzTxRxWorkerStatusIDLE) {
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->device);
|
||||
}
|
||||
furi_hal_subghz_write_packet(data, size);
|
||||
furi_hal_subghz_tx(); //start send
|
||||
subghz_devices_write_packet(instance->device, data, size);
|
||||
subghz_devices_set_tx(instance->device); //start send
|
||||
instance->status = SubGhzTxRxWorkerStatusTx;
|
||||
while(!furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
instance->device_data_gpio)) { // Wait for GDO0 to be set -> sync transmitted
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX !cc1101_g0 timeout");
|
||||
@@ -113,14 +115,14 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
|
||||
}
|
||||
}
|
||||
while(furi_hal_gpio_read(
|
||||
furi_hal_subghz.cc1101_g0_pin)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
instance->device_data_gpio)) { // Wait for GDO0 to be cleared -> end of packet
|
||||
furi_delay_tick(1);
|
||||
if(!--timeout) {
|
||||
FURI_LOG_W(TAG, "TX cc1101_g0 timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz_devices_idle(instance->device);
|
||||
instance->status = SubGhzTxRxWorkerStatusIDLE;
|
||||
}
|
||||
/** Worker thread
|
||||
@@ -130,16 +132,19 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
|
||||
*/
|
||||
static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
SubGhzTxRxWorker* instance = context;
|
||||
furi_assert(instance->device);
|
||||
FURI_LOG_I(TAG, "Worker start");
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
|
||||
//furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
|
||||
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_devices_begin(instance->device);
|
||||
instance->device_data_gpio = subghz_devices_get_data_gpio(instance->device);
|
||||
subghz_devices_reset(instance->device);
|
||||
subghz_devices_idle(instance->device);
|
||||
subghz_devices_load_preset(instance->device, FuriHalSubGhzPresetGFSK9_99KbAsync, NULL);
|
||||
|
||||
furi_hal_subghz_set_frequency_and_path(instance->frequency);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_gpio_init(instance->device_data_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
subghz_devices_set_frequency(instance->device, instance->frequency);
|
||||
subghz_devices_flush_rx(instance->device);
|
||||
|
||||
uint8_t data[SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE + 1] = {0};
|
||||
size_t size_tx = 0;
|
||||
@@ -193,8 +198,8 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz_devices_sleep(instance->device);
|
||||
subghz_devices_end(instance->device);
|
||||
|
||||
FURI_LOG_I(TAG, "Worker stop");
|
||||
return 0;
|
||||
@@ -226,7 +231,10 @@ void subghz_tx_rx_worker_free(SubGhzTxRxWorker* instance) {
|
||||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency) {
|
||||
bool subghz_tx_rx_worker_start(
|
||||
SubGhzTxRxWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
@@ -237,6 +245,7 @@ bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency) {
|
||||
|
||||
if(furi_hal_subghz_is_tx_allowed(frequency)) {
|
||||
instance->frequency = frequency;
|
||||
instance->device = device;
|
||||
res = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <devices/devices.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -67,9 +68,13 @@ void subghz_tx_rx_worker_free(SubGhzTxRxWorker* instance);
|
||||
/**
|
||||
* Start SubGhzTxRxWorker
|
||||
* @param instance Pointer to a SubGhzTxRxWorker instance
|
||||
* @param device Pointer to a SubGhzDevice instance
|
||||
* @return bool - true if ok
|
||||
*/
|
||||
bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency);
|
||||
bool subghz_tx_rx_worker_start(
|
||||
SubGhzTxRxWorker* instance,
|
||||
const SubGhzDevice* device,
|
||||
uint32_t frequency);
|
||||
|
||||
/**
|
||||
* Stop SubGhzTxRxWorker
|
||||
|
||||
Reference in New Issue
Block a user