2021-05-25 10:19:07 +00:00
|
|
|
#include "subghz_cli.h"
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-05-25 10:19:07 +00:00
|
|
|
#include <furi.h>
|
2021-08-08 18:03:25 +00:00
|
|
|
#include <furi-hal.h>
|
2021-06-29 21:19:20 +00:00
|
|
|
#include <stream_buffer.h>
|
2021-07-18 18:09:00 +00:00
|
|
|
#include <lib/subghz/protocols/subghz_protocol.h>
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-27 11:47:45 +00:00
|
|
|
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
|
|
|
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-05-25 10:19:07 +00:00
|
|
|
void subghz_cli_init() {
|
|
|
|
Cli* cli = furi_record_open("cli");
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
cli_add_command(
|
|
|
|
cli, "subghz_tx_carrier", CliCommandFlagDefault, subghz_cli_command_tx_carrier, NULL);
|
|
|
|
cli_add_command(
|
|
|
|
cli, "subghz_rx_carrier", CliCommandFlagDefault, subghz_cli_command_rx_carrier, NULL);
|
|
|
|
cli_add_command(cli, "subghz_tx", CliCommandFlagDefault, subghz_cli_command_tx, NULL);
|
|
|
|
cli_add_command(cli, "subghz_rx", CliCommandFlagDefault, subghz_cli_command_rx, NULL);
|
2021-05-25 10:19:07 +00:00
|
|
|
|
|
|
|
furi_record_close("cli");
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
2021-07-18 18:09:00 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
if(string_size(args)) {
|
|
|
|
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
|
|
|
if(ret != 1) {
|
|
|
|
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
|
|
|
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
|
|
|
return;
|
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
2021-07-18 18:09:00 +00:00
|
|
|
printf(
|
2021-07-27 11:47:45 +00:00
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
2021-07-18 18:09:00 +00:00
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_reset();
|
|
|
|
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
|
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
2021-05-25 10:19:07 +00:00
|
|
|
|
|
|
|
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
2021-07-18 18:09:00 +00:00
|
|
|
hal_gpio_write(&gpio_cc1101_g0, true);
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_tx();
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
printf("Transmitting at frequency %lu Hz\r\n", frequency);
|
|
|
|
printf("Press CTRL+C to stop\r\n");
|
2021-05-25 10:19:07 +00:00
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
|
|
|
osDelay(250);
|
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
|
|
furi_hal_subghz_sleep();
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
2021-07-18 18:09:00 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
if(string_size(args)) {
|
|
|
|
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
|
|
|
if(ret != 1) {
|
|
|
|
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
|
|
|
cli_print_usage("subghz_tx_carrier", "<Frequency in HZ>", string_get_cstr(args));
|
|
|
|
return;
|
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
2021-07-18 18:09:00 +00:00
|
|
|
printf(
|
2021-07-27 11:47:45 +00:00
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
2021-07-18 18:09:00 +00:00
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_reset();
|
|
|
|
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
|
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
2021-05-25 10:19:07 +00:00
|
|
|
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
|
|
|
printf("Press CTRL+C to stop\r\n");
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_rx();
|
2021-05-25 10:19:07 +00:00
|
|
|
|
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
|
|
|
osDelay(250);
|
2021-08-08 18:03:25 +00:00
|
|
|
printf("RSSI: %03.1fdbm\r", furi_hal_subghz_get_rssi());
|
2021-05-25 10:19:07 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
|
|
furi_hal_subghz_sleep();
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
#define SUBGHZ_PT_SHORT 376
|
2021-07-15 13:54:11 +00:00
|
|
|
#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3)
|
2021-07-18 18:09:00 +00:00
|
|
|
#define SUBGHZ_PT_GUARD 10600
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-06-29 21:19:20 +00:00
|
|
|
void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
2021-07-15 13:54:11 +00:00
|
|
|
uint32_t frequency = 433920000;
|
|
|
|
size_t repeat = 10;
|
|
|
|
uint32_t key = 0x0074BADE;
|
|
|
|
|
|
|
|
if(string_size(args)) {
|
|
|
|
int ret = sscanf(string_get_cstr(args), "%lx %lu %u", &key, &frequency, &repeat);
|
|
|
|
if(ret != 3) {
|
|
|
|
printf(
|
|
|
|
"sscanf returned %d, key: %lx, frequency: %lu, repeat: %u\r\n",
|
|
|
|
ret,
|
|
|
|
key,
|
|
|
|
frequency,
|
|
|
|
repeat);
|
|
|
|
cli_print_usage(
|
|
|
|
"subghz_rx",
|
|
|
|
"<3 Byte Key in hex> <Frequency in HZ> <Repeat count>",
|
|
|
|
string_get_cstr(args));
|
|
|
|
return;
|
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
2021-07-15 13:54:11 +00:00
|
|
|
printf(
|
2021-07-27 11:47:45 +00:00
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
2021-07-15 13:54:11 +00:00
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t subghz_test_data_size = 25 * 2 * sizeof(uint32_t);
|
|
|
|
uint32_t* subghz_test_data = furi_alloc(subghz_test_data_size);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_LONG;
|
|
|
|
} else {
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_LONG;
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_SHORT;
|
|
|
|
subghz_test_data[pos++] = SUBGHZ_PT_SHORT + SUBGHZ_PT_GUARD;
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
printf(
|
|
|
|
"Transmitting at %lu, key %lx, repeat %u. Press CTRL+C to stop\r\n",
|
|
|
|
frequency,
|
|
|
|
key,
|
|
|
|
repeat);
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_reset();
|
|
|
|
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
|
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_start_async_tx(subghz_test_data, subghz_test_data_size, repeat);
|
|
|
|
furi_hal_subghz_wait_async_tx();
|
|
|
|
furi_hal_subghz_stop_async_tx();
|
2021-07-15 13:54:11 +00:00
|
|
|
|
|
|
|
free(subghz_test_data);
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_sleep();
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
typedef struct {
|
|
|
|
volatile bool overrun;
|
|
|
|
StreamBufferHandle_t stream;
|
|
|
|
size_t packet_count;
|
|
|
|
} SubGhzCliCommandRx;
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
static void subghz_cli_command_rx_callback(bool level, uint32_t duration, void* context) {
|
|
|
|
SubGhzCliCommandRx* instance = context;
|
2021-06-29 21:19:20 +00:00
|
|
|
|
|
|
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
2021-07-07 19:49:45 +00:00
|
|
|
LevelDuration level_duration = level_duration_make(level, duration);
|
2021-07-18 18:09:00 +00:00
|
|
|
if(instance->overrun) {
|
|
|
|
instance->overrun = false;
|
2021-07-07 19:49:45 +00:00
|
|
|
level_duration = level_duration_reset();
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
2021-07-07 19:49:45 +00:00
|
|
|
size_t ret = xStreamBufferSendFromISR(
|
2021-07-18 18:09:00 +00:00
|
|
|
instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
|
|
|
|
if(sizeof(LevelDuration) != ret) instance->overrun = true;
|
2021-06-29 21:19:20 +00:00
|
|
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
static void subghz_cli_command_rx_text_callback(string_t text, void* context) {
|
|
|
|
SubGhzCliCommandRx* instance = context;
|
|
|
|
instance->packet_count++;
|
|
|
|
printf(string_get_cstr(text));
|
|
|
|
}
|
|
|
|
|
2021-06-29 21:19:20 +00:00
|
|
|
void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
|
|
|
uint32_t frequency = 433920000;
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2021-06-29 21:19:20 +00:00
|
|
|
if(string_size(args)) {
|
|
|
|
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
|
|
|
if(ret != 1) {
|
|
|
|
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
|
|
|
cli_print_usage("subghz_rx", "<Frequency in HZ>", string_get_cstr(args));
|
|
|
|
return;
|
|
|
|
}
|
2021-08-08 18:03:25 +00:00
|
|
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
2021-06-29 21:19:20 +00:00
|
|
|
printf(
|
2021-07-27 11:47:45 +00:00
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
2021-06-29 21:19:20 +00:00
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Allocate context and buffers
|
|
|
|
SubGhzCliCommandRx* instance = furi_alloc(sizeof(SubGhzCliCommandRx));
|
|
|
|
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
|
|
|
furi_check(instance->stream);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
|
|
|
SubGhzProtocol* protocol = subghz_protocol_alloc();
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 12:20:19 +00:00
|
|
|
subghz_protocol_load_keeloq_file(protocol, "/ext/assets/subghz/keeloq_mfcodes");
|
|
|
|
subghz_protocol_load_nice_flor_s_file(protocol, "/ext/assets/subghz/nice_floor_s_rx");
|
2021-07-18 18:09:00 +00:00
|
|
|
subghz_protocol_enable_dump_text(protocol, subghz_cli_command_rx_text_callback, instance);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Configure radio
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_reset();
|
|
|
|
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync);
|
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
2021-07-18 18:09:00 +00:00
|
|
|
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Prepare and start RX
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_set_async_rx_callback(subghz_cli_command_rx_callback, instance);
|
|
|
|
furi_hal_subghz_start_async_rx();
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Wait for packets to arrive
|
2021-06-29 21:19:20 +00:00
|
|
|
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
2021-07-07 19:49:45 +00:00
|
|
|
LevelDuration level_duration;
|
2021-06-29 21:19:20 +00:00
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
2021-07-18 18:09:00 +00:00
|
|
|
int ret =
|
|
|
|
xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10);
|
2021-07-07 19:49:45 +00:00
|
|
|
if(ret == sizeof(LevelDuration)) {
|
|
|
|
if(level_duration_is_reset(level_duration)) {
|
2021-06-29 21:19:20 +00:00
|
|
|
printf(".");
|
|
|
|
subghz_protocol_reset(protocol);
|
|
|
|
} else {
|
2021-07-07 19:49:45 +00:00
|
|
|
bool level = level_duration_get_level(level_duration);
|
|
|
|
uint32_t duration = level_duration_get_duration(level_duration);
|
|
|
|
subghz_protocol_parse(protocol, level, duration);
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Shutdown radio
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_stop_async_rx();
|
|
|
|
furi_hal_subghz_sleep();
|
2021-07-18 18:09:00 +00:00
|
|
|
|
|
|
|
printf("\r\nPackets recieved %u\r\n", instance->packet_count);
|
|
|
|
|
|
|
|
// Cleanup
|
2021-06-29 21:19:20 +00:00
|
|
|
subghz_protocol_free(protocol);
|
2021-07-18 18:09:00 +00:00
|
|
|
vStreamBufferDelete(instance->stream);
|
|
|
|
free(instance);
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|