[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
148
applications/main/subghz/helpers/subghz_chat.c
Normal file
148
applications/main/subghz/helpers/subghz_chat.c
Normal file
@@ -0,0 +1,148 @@
|
||||
#include "subghz_chat.h"
|
||||
#include <lib/subghz/subghz_tx_rx_worker.h>
|
||||
|
||||
#define TAG "SubGhzChat"
|
||||
#define SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES 500
|
||||
|
||||
struct SubGhzChatWorker {
|
||||
FuriThread* thread;
|
||||
SubGhzTxRxWorker* subghz_txrx;
|
||||
|
||||
volatile bool worker_running;
|
||||
volatile bool worker_stoping;
|
||||
FuriMessageQueue* event_queue;
|
||||
uint32_t last_time_rx_data;
|
||||
|
||||
Cli* cli;
|
||||
};
|
||||
|
||||
/** Worker thread
|
||||
*
|
||||
* @param context
|
||||
* @return exit code
|
||||
*/
|
||||
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;
|
||||
furi_message_queue_put(instance->event_queue, &event, 0);
|
||||
while(instance->worker_running) {
|
||||
if(cli_read_timeout(instance->cli, (uint8_t*)&c, 1, 1000) == 1) {
|
||||
event.event = SubGhzChatEventInputData;
|
||||
event.c = c;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Worker stop");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void subghz_chat_worker_update_rx_event_chat(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzChatWorker* instance = context;
|
||||
SubGhzChatEvent event;
|
||||
if((furi_get_tick() - instance->last_time_rx_data) >
|
||||
SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) {
|
||||
event.event = SubGhzChatEventNewMessage;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
instance->last_time_rx_data = furi_get_tick();
|
||||
event.event = SubGhzChatEventRXData;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli) {
|
||||
SubGhzChatWorker* instance = malloc(sizeof(SubGhzChatWorker));
|
||||
|
||||
instance->cli = cli;
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
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 = furi_message_queue_alloc(80, sizeof(SubGhzChatEvent));
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_chat_worker_free(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
furi_message_queue_free(instance->event_queue);
|
||||
subghz_tx_rx_worker_free(instance->subghz_txrx);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, frequency)) {
|
||||
furi_message_queue_reset(instance->event_queue);
|
||||
subghz_tx_rx_worker_set_callback_have_read(
|
||||
instance->subghz_txrx, subghz_chat_worker_update_rx_event_chat, instance);
|
||||
|
||||
instance->worker_running = true;
|
||||
instance->last_time_rx_data = 0;
|
||||
|
||||
furi_thread_start(instance->thread);
|
||||
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_chat_worker_stop(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->worker_running);
|
||||
if(subghz_tx_rx_worker_is_running(instance->subghz_txrx)) {
|
||||
subghz_tx_rx_worker_stop(instance->subghz_txrx);
|
||||
}
|
||||
|
||||
instance->worker_running = false;
|
||||
|
||||
furi_thread_join(instance->thread);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->worker_running;
|
||||
}
|
||||
|
||||
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
SubGhzChatEvent event;
|
||||
if(furi_message_queue_get(instance->event_queue, &event, FuriWaitForever) == FuriStatusOk) {
|
||||
return event;
|
||||
} else {
|
||||
event.event = SubGhzChatEventNoEvent;
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event) {
|
||||
furi_assert(instance);
|
||||
furi_message_queue_put(instance->event_queue, event, FuriWaitForever);
|
||||
}
|
||||
|
||||
size_t subghz_chat_worker_available(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_available(instance->subghz_txrx);
|
||||
}
|
||||
|
||||
size_t subghz_chat_worker_read(SubGhzChatWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_read(instance->subghz_txrx, data, size);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_write(SubGhzChatWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_write(instance->subghz_txrx, data, size);
|
||||
}
|
30
applications/main/subghz/helpers/subghz_chat.h
Normal file
30
applications/main/subghz/helpers/subghz_chat.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
#include <cli/cli.h>
|
||||
|
||||
typedef struct SubGhzChatWorker SubGhzChatWorker;
|
||||
|
||||
typedef enum {
|
||||
SubGhzChatEventNoEvent,
|
||||
SubGhzChatEventUserEntrance,
|
||||
SubGhzChatEventUserExit,
|
||||
SubGhzChatEventInputData,
|
||||
SubGhzChatEventRXData,
|
||||
SubGhzChatEventNewMessage,
|
||||
} SubGhzChatEventType;
|
||||
|
||||
typedef struct {
|
||||
SubGhzChatEventType event;
|
||||
char c;
|
||||
} SubGhzChatEvent;
|
||||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli);
|
||||
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);
|
||||
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);
|
75
applications/main/subghz/helpers/subghz_custom_event.h
Normal file
75
applications/main/subghz/helpers/subghz_custom_event.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
SubGhzCustomEventManagerNoSet = 0,
|
||||
SubGhzCustomEventManagerSet,
|
||||
SubGhzCustomEventManagerSetRAW,
|
||||
|
||||
//SubmenuIndex
|
||||
SubmenuIndexPricenton,
|
||||
SubmenuIndexNiceFlo12bit,
|
||||
SubmenuIndexNiceFlo24bit,
|
||||
SubmenuIndexCAME12bit,
|
||||
SubmenuIndexCAME24bit,
|
||||
SubmenuIndexCAMETwee,
|
||||
SubmenuIndexNeroSketch,
|
||||
SubmenuIndexNeroRadio,
|
||||
SubmenuIndexGateTX,
|
||||
SubmenuIndexDoorHan_315_00,
|
||||
SubmenuIndexDoorHan_433_92,
|
||||
SubmenuIndexLinear_300_00,
|
||||
SubmenuIndexLiftMaster_315_00,
|
||||
SubmenuIndexLiftMaster_390_00,
|
||||
SubmenuIndexSecPlus_v2_310_00,
|
||||
SubmenuIndexSecPlus_v2_315_00,
|
||||
SubmenuIndexSecPlus_v2_390_00,
|
||||
|
||||
//SubGhzCustomEvent
|
||||
SubGhzCustomEventSceneDeleteSuccess = 100,
|
||||
SubGhzCustomEventSceneDelete,
|
||||
SubGhzCustomEventSceneDeleteRAW,
|
||||
SubGhzCustomEventSceneDeleteRAWBack,
|
||||
|
||||
SubGhzCustomEventSceneReceiverInfoTxStart,
|
||||
SubGhzCustomEventSceneReceiverInfoTxStop,
|
||||
SubGhzCustomEventSceneReceiverInfoSave,
|
||||
SubGhzCustomEventSceneSaveName,
|
||||
SubGhzCustomEventSceneSaveSuccess,
|
||||
SubGhzCustomEventSceneShowErrorBack,
|
||||
SubGhzCustomEventSceneShowErrorOk,
|
||||
SubGhzCustomEventSceneShowErrorSub,
|
||||
SubGhzCustomEventSceneShowOnlyRX,
|
||||
SubGhzCustomEventSceneAnalyzerLock,
|
||||
SubGhzCustomEventSceneAnalyzerUnlock,
|
||||
SubGhzCustomEventSceneSettingLock,
|
||||
|
||||
SubGhzCustomEventSceneExit,
|
||||
SubGhzCustomEventSceneStay,
|
||||
|
||||
SubGhzCustomEventSceneRpcLoad,
|
||||
SubGhzCustomEventSceneRpcButtonPress,
|
||||
SubGhzCustomEventSceneRpcButtonRelease,
|
||||
SubGhzCustomEventSceneRpcSessionClose,
|
||||
|
||||
SubGhzCustomEventViewReceiverOK,
|
||||
SubGhzCustomEventViewReceiverConfig,
|
||||
SubGhzCustomEventViewReceiverBack,
|
||||
SubGhzCustomEventViewReceiverOffDisplay,
|
||||
SubGhzCustomEventViewReceiverUnlock,
|
||||
|
||||
SubGhzCustomEventViewReadRAWBack,
|
||||
SubGhzCustomEventViewReadRAWIDLE,
|
||||
SubGhzCustomEventViewReadRAWREC,
|
||||
SubGhzCustomEventViewReadRAWConfig,
|
||||
SubGhzCustomEventViewReadRAWErase,
|
||||
SubGhzCustomEventViewReadRAWSendStart,
|
||||
SubGhzCustomEventViewReadRAWSendStop,
|
||||
SubGhzCustomEventViewReadRAWSave,
|
||||
SubGhzCustomEventViewReadRAWTXRXStop,
|
||||
SubGhzCustomEventViewReadRAWMore,
|
||||
|
||||
SubGhzCustomEventViewTransmitterBack,
|
||||
SubGhzCustomEventViewTransmitterSendStart,
|
||||
SubGhzCustomEventViewTransmitterSendStop,
|
||||
SubGhzCustomEventViewTransmitterError,
|
||||
} SubGhzCustomEvent;
|
@@ -0,0 +1,299 @@
|
||||
#include "subghz_frequency_analyzer_worker.h"
|
||||
#include <lib/drivers/cc1101.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "SubghzFrequencyAnalyzerWorker"
|
||||
|
||||
#define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -95.0f
|
||||
|
||||
static const uint8_t subghz_preset_ook_58khz[][2] = {
|
||||
{CC1101_MDMCFG4, 0b11110111}, // Rx BW filter is 58.035714kHz
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t subghz_preset_ook_650khz[][2] = {
|
||||
{CC1101_MDMCFG4, 0b00010111}, // Rx BW filter is 650.000kHz
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
struct SubGhzFrequencyAnalyzerWorker {
|
||||
FuriThread* thread;
|
||||
|
||||
volatile bool worker_running;
|
||||
uint8_t sample_hold_counter;
|
||||
FrequencyRSSI frequency_rssi_buf;
|
||||
SubGhzSetting* setting;
|
||||
|
||||
float filVal;
|
||||
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback pair_callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
static void subghz_frequency_analyzer_worker_load_registers(const uint8_t data[][2]) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
size_t i = 0;
|
||||
while(data[i][0]) {
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, data[i][0], data[i][1]);
|
||||
i++;
|
||||
}
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
// running average with adaptive coefficient
|
||||
static uint32_t subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
uint32_t newVal) {
|
||||
float k;
|
||||
float newValFloat = newVal;
|
||||
// the sharpness of the filter depends on the absolute value of the difference
|
||||
if(fabs(newValFloat - instance->filVal) > 500000)
|
||||
k = 0.9;
|
||||
else
|
||||
k = 0.03;
|
||||
|
||||
instance->filVal += (newValFloat - instance->filVal) * k;
|
||||
return (uint32_t)instance->filVal;
|
||||
}
|
||||
|
||||
/** Worker thread
|
||||
*
|
||||
* @param context
|
||||
* @return exit code
|
||||
*/
|
||||
static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
||||
SubGhzFrequencyAnalyzerWorker* instance = context;
|
||||
|
||||
FrequencyRSSI frequency_rssi = {
|
||||
.frequency_coarse = 0, .rssi_coarse = 0, .frequency_fine = 0, .rssi_fine = 0};
|
||||
float rssi = 0;
|
||||
uint32_t frequency = 0;
|
||||
CC1101Status status;
|
||||
|
||||
//Start CC1101
|
||||
furi_hal_subghz_reset();
|
||||
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_MDMCFG3,
|
||||
0b01111111); // symbol rate
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL2,
|
||||
0b00000111); // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAGN_TARGET 42 dB
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL1,
|
||||
0b00001000); // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 1000 - Absolute carrier sense threshold disabled
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL0,
|
||||
0b00110000); // 00 - No hysteresis, medium asymmetric dead zone, medium gain ; 11 - 64 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
|
||||
while(instance->worker_running) {
|
||||
furi_delay_ms(10);
|
||||
|
||||
float rssi_min = 26.0f;
|
||||
float rssi_avg = 0;
|
||||
size_t rssi_avg_samples = 0;
|
||||
|
||||
frequency_rssi.rssi_coarse = -127.0f;
|
||||
frequency_rssi.rssi_fine = -127.0f;
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_650khz);
|
||||
|
||||
// First stage: coarse scan
|
||||
for(size_t i = 0; i < subghz_setting_get_frequency_count(instance->setting); i++) {
|
||||
if(furi_hal_subghz_is_frequency_valid(
|
||||
subghz_setting_get_frequency(instance->setting, i))) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency = cc1101_set_frequency(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
subghz_setting_get_frequency(instance->setting, i));
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
rssi_avg += rssi;
|
||||
rssi_avg_samples++;
|
||||
|
||||
if(rssi < rssi_min) rssi_min = rssi;
|
||||
|
||||
if(frequency_rssi.rssi_coarse < rssi) {
|
||||
frequency_rssi.rssi_coarse = rssi;
|
||||
frequency_rssi.frequency_coarse = frequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_T(
|
||||
TAG,
|
||||
"RSSI: avg %f, max %f at %u, min %f",
|
||||
(double)(rssi_avg / rssi_avg_samples),
|
||||
(double)frequency_rssi.rssi_coarse,
|
||||
frequency_rssi.frequency_coarse,
|
||||
(double)rssi_min);
|
||||
|
||||
// Second stage: fine scan
|
||||
if(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_58khz);
|
||||
//for example -0.3 ... 433.92 ... +0.3 step 20KHz
|
||||
for(uint32_t i = frequency_rssi.frequency_coarse - 300000;
|
||||
i < frequency_rssi.frequency_coarse + 300000;
|
||||
i += 20000) {
|
||||
if(furi_hal_subghz_is_frequency_valid(i)) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, i);
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
FURI_LOG_T(TAG, "#:%u:%f", frequency, (double)rssi);
|
||||
|
||||
if(frequency_rssi.rssi_fine < rssi) {
|
||||
frequency_rssi.rssi_fine = rssi;
|
||||
frequency_rssi.frequency_fine = frequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deliver results fine
|
||||
if(frequency_rssi.rssi_fine > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
|
||||
FURI_LOG_D(
|
||||
TAG, "=:%u:%f", frequency_rssi.frequency_fine, (double)frequency_rssi.rssi_fine);
|
||||
|
||||
instance->sample_hold_counter = 20;
|
||||
if(instance->filVal) {
|
||||
frequency_rssi.frequency_fine =
|
||||
subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
instance, frequency_rssi.frequency_fine);
|
||||
}
|
||||
// Deliver callback
|
||||
if(instance->pair_callback) {
|
||||
instance->pair_callback(
|
||||
instance->context, frequency_rssi.frequency_fine, frequency_rssi.rssi_fine);
|
||||
}
|
||||
} else if( // Deliver results coarse
|
||||
(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) &&
|
||||
(instance->sample_hold_counter < 10)) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"~:%u:%f",
|
||||
frequency_rssi.frequency_coarse,
|
||||
(double)frequency_rssi.rssi_coarse);
|
||||
|
||||
instance->sample_hold_counter = 20;
|
||||
if(instance->filVal) {
|
||||
frequency_rssi.frequency_coarse =
|
||||
subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
instance, frequency_rssi.frequency_coarse);
|
||||
}
|
||||
// Deliver callback
|
||||
if(instance->pair_callback) {
|
||||
instance->pair_callback(
|
||||
instance->context,
|
||||
frequency_rssi.frequency_coarse,
|
||||
frequency_rssi.rssi_coarse);
|
||||
}
|
||||
} else {
|
||||
if(instance->sample_hold_counter > 0) {
|
||||
instance->sample_hold_counter--;
|
||||
} else {
|
||||
instance->filVal = 0;
|
||||
if(instance->pair_callback) instance->pair_callback(instance->context, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Stop CC1101
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzFrequencyAnalyzerWorker* instance = malloc(sizeof(SubGhzFrequencyAnalyzerWorker));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
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);
|
||||
|
||||
SubGhz* subghz = context;
|
||||
instance->setting = subghz->setting;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
furi_thread_free(instance->thread);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_set_pair_callback(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
|
||||
void* context) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
instance->pair_callback = callback;
|
||||
instance->context = context;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
instance->worker_running = true;
|
||||
|
||||
furi_thread_start(instance->thread);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->worker_running);
|
||||
|
||||
instance->worker_running = false;
|
||||
|
||||
furi_thread_join(instance->thread);
|
||||
}
|
||||
|
||||
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->worker_running;
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include "../subghz_i.h"
|
||||
|
||||
typedef struct SubGhzFrequencyAnalyzerWorker SubGhzFrequencyAnalyzerWorker;
|
||||
|
||||
typedef void (
|
||||
*SubGhzFrequencyAnalyzerWorkerPairCallback)(void* context, uint32_t frequency, float rssi);
|
||||
|
||||
typedef struct {
|
||||
uint32_t frequency_coarse;
|
||||
float rssi_coarse;
|
||||
uint32_t frequency_fine;
|
||||
float rssi_fine;
|
||||
} FrequencyRSSI;
|
||||
|
||||
/** Allocate SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param context SubGhz* context
|
||||
* @return SubGhzFrequencyAnalyzerWorker*
|
||||
*/
|
||||
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context);
|
||||
|
||||
/** Free SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Pair callback SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
* @param callback SubGhzFrequencyAnalyzerWorkerOverrunCallback callback
|
||||
* @param context
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_set_pair_callback(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
|
||||
void* context);
|
||||
|
||||
/** Start SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Stop SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Check if worker is running
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
* @return bool - true if running
|
||||
*/
|
||||
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance);
|
38
applications/main/subghz/helpers/subghz_testing.c
Normal file
38
applications/main/subghz/helpers/subghz_testing.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "subghz_testing.h"
|
||||
|
||||
const uint32_t subghz_frequencies_testing[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
304500000,
|
||||
310000000,
|
||||
312025000,
|
||||
313250000,
|
||||
313625000,
|
||||
315000000,
|
||||
315225000,
|
||||
321950000,
|
||||
348000000,
|
||||
/* 387 - 464 */
|
||||
387000000,
|
||||
433075000, /* LPD433 first */
|
||||
433825000,
|
||||
433920000, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
464000000,
|
||||
/* 779 - 928 */
|
||||
779000000,
|
||||
868150000,
|
||||
868350000,
|
||||
868550000,
|
||||
915000000,
|
||||
925000000,
|
||||
926500000,
|
||||
927950000,
|
||||
928000000,
|
||||
};
|
||||
|
||||
const uint32_t subghz_frequencies_count_testing =
|
||||
sizeof(subghz_frequencies_testing) / sizeof(uint32_t);
|
||||
const uint32_t subghz_frequencies_433_92_testing = 13;
|
6
applications/main/subghz/helpers/subghz_testing.h
Normal file
6
applications/main/subghz/helpers/subghz_testing.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
|
||||
extern const uint32_t subghz_frequencies_testing[];
|
||||
extern const uint32_t subghz_frequencies_count_testing;
|
||||
extern const uint32_t subghz_frequencies_433_92_testing;
|
82
applications/main/subghz/helpers/subghz_types.h
Normal file
82
applications/main/subghz/helpers/subghz_types.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
/** SubGhzNotification state */
|
||||
typedef enum {
|
||||
SubGhzNotificationStateStarting,
|
||||
SubGhzNotificationStateIDLE,
|
||||
SubGhzNotificationStateTx,
|
||||
SubGhzNotificationStateRx,
|
||||
SubGhzNotificationStateRxDone,
|
||||
} SubGhzNotificationState;
|
||||
|
||||
/** SubGhzTxRx state */
|
||||
typedef enum {
|
||||
SubGhzTxRxStateIDLE,
|
||||
SubGhzTxRxStateRx,
|
||||
SubGhzTxRxStateTx,
|
||||
SubGhzTxRxStateSleep,
|
||||
} SubGhzTxRxState;
|
||||
|
||||
/** SubGhzHopperState state */
|
||||
typedef enum {
|
||||
SubGhzHopperStateOFF,
|
||||
SubGhzHopperStateRunnig,
|
||||
SubGhzHopperStatePause,
|
||||
SubGhzHopperStateRSSITimeOut,
|
||||
} SubGhzHopperState;
|
||||
|
||||
/** SubGhzRxKeyState state */
|
||||
typedef enum {
|
||||
SubGhzRxKeyStateIDLE,
|
||||
SubGhzRxKeyStateNoSave,
|
||||
SubGhzRxKeyStateNeedSave,
|
||||
SubGhzRxKeyStateBack,
|
||||
SubGhzRxKeyStateStart,
|
||||
SubGhzRxKeyStateAddKey,
|
||||
SubGhzRxKeyStateExit,
|
||||
SubGhzRxKeyStateRAWLoad,
|
||||
SubGhzRxKeyStateRAWSave,
|
||||
} SubGhzRxKeyState;
|
||||
|
||||
/** SubGhzLoadKeyState state */
|
||||
typedef enum {
|
||||
SubGhzLoadKeyStateUnknown,
|
||||
SubGhzLoadKeyStateOK,
|
||||
SubGhzLoadKeyStateParseErr,
|
||||
SubGhzLoadKeyStateOnlyRx,
|
||||
} SubGhzLoadKeyState;
|
||||
|
||||
/** SubGhzLock */
|
||||
typedef enum {
|
||||
SubGhzLockOff,
|
||||
SubGhzLockOn,
|
||||
} SubGhzLock;
|
||||
|
||||
typedef enum {
|
||||
SubGhzViewIdMenu,
|
||||
SubGhzViewIdReceiver,
|
||||
SubGhzViewIdPopup,
|
||||
SubGhzViewIdTextInput,
|
||||
SubGhzViewIdWidget,
|
||||
SubGhzViewIdTransmitter,
|
||||
SubGhzViewIdVariableItemList,
|
||||
SubGhzViewIdFrequencyAnalyzer,
|
||||
SubGhzViewIdReadRAW,
|
||||
|
||||
SubGhzViewIdStatic,
|
||||
SubGhzViewIdTestCarrier,
|
||||
SubGhzViewIdTestPacket,
|
||||
} SubGhzViewId;
|
||||
|
||||
struct SubGhzPresetDefinition {
|
||||
string_t name;
|
||||
uint32_t frequency;
|
||||
uint8_t* data;
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
typedef struct SubGhzPresetDefinition SubGhzPresetDefinition;
|
Reference in New Issue
Block a user