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>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-11-01 20:35:54 +00:00
|
|
|
|
2021-11-01 13:11:25 +00:00
|
|
|
#include <lib/toolbox/args.h>
|
|
|
|
#include <lib/subghz/subghz_keystore.h>
|
2022-03-03 09:48:56 +00:00
|
|
|
|
|
|
|
#include <lib/subghz/receiver.h>
|
|
|
|
#include <lib/subghz/transmitter.h>
|
2022-04-14 12:49:29 +00:00
|
|
|
#include <lib/subghz/subghz_file_encoder_worker.h>
|
2022-10-19 17:27:26 +00:00
|
|
|
#include <lib/subghz/protocols/protocol_items.h>
|
2023-06-30 14:03:36 +00:00
|
|
|
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
|
|
|
|
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
|
|
|
|
#include <lib/subghz/devices/devices.h>
|
|
|
|
#include <lib/subghz/devices/cc1101_configs.h>
|
2021-12-08 13:42:01 +00:00
|
|
|
|
|
|
|
#include "helpers/subghz_chat.h"
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <notification/notification_messages.h>
|
2022-03-03 09:48:56 +00:00
|
|
|
#include <flipper_format/flipper_format_i.h>
|
2021-12-04 13:40:17 +00:00
|
|
|
|
2022-08-11 09:21:56 +00:00
|
|
|
#include <flipper.pb.h>
|
|
|
|
#include <pb_decode.h>
|
|
|
|
|
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
|
|
|
|
2022-08-11 09:21:56 +00:00
|
|
|
#define SUBGHZ_REGION_FILENAME "/int/.region_data"
|
|
|
|
|
2023-09-04 05:10:07 +00:00
|
|
|
#define TAG "SubGhzCli"
|
2023-07-12 09:41:46 +00:00
|
|
|
|
2023-06-30 14:03:36 +00:00
|
|
|
static void subghz_cli_radio_device_power_on() {
|
2023-07-12 09:41:46 +00:00
|
|
|
uint8_t attempts = 5;
|
|
|
|
while(--attempts > 0) {
|
|
|
|
if(furi_hal_power_enable_otg()) break;
|
|
|
|
}
|
|
|
|
if(attempts == 0) {
|
|
|
|
if(furi_hal_power_get_usb_voltage() < 4.5f) {
|
|
|
|
FURI_LOG_E(
|
|
|
|
"TAG",
|
|
|
|
"Error power otg enable. BQ2589 check otg fault = %d",
|
|
|
|
furi_hal_power_check_otg_fault() ? 1 : 0);
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subghz_cli_radio_device_power_off() {
|
|
|
|
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-07-18 18:09:00 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
|
|
|
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
2021-07-18 18:09:00 +00:00
|
|
|
if(ret != 1) {
|
|
|
|
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
2022-10-05 15:15:23 +00:00
|
|
|
cli_print_usage("subghz tx_carrier", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
2021-07-18 18:09:00 +00:00
|
|
|
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();
|
2023-06-30 14:03:36 +00:00
|
|
|
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
2021-08-08 18:03:25 +00:00
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2022-03-30 15:23:40 +00:00
|
|
|
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
|
|
|
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2021-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_enter();
|
|
|
|
|
2021-09-28 00:05:40 +00:00
|
|
|
if(furi_hal_subghz_tx()) {
|
|
|
|
printf("Transmitting at frequency %lu Hz\r\n", frequency);
|
|
|
|
printf("Press CTRL+C to stop\r\n");
|
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(250);
|
2021-09-28 00:05:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("This frequency can only be used for RX in your region\r\n");
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 18:03:25 +00:00
|
|
|
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
|
|
|
furi_hal_subghz_sleep();
|
2021-10-04 07:01:41 +00:00
|
|
|
|
|
|
|
furi_hal_power_suppress_charge_exit();
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_cli_command_rx_carrier(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-07-18 18:09:00 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2021-05-25 10:19:07 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
|
|
|
int ret = sscanf(furi_string_get_cstr(args), "%lu", &frequency);
|
2021-07-18 18:09:00 +00:00
|
|
|
if(ret != 1) {
|
|
|
|
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
2022-10-05 15:15:23 +00:00
|
|
|
cli_print_usage("subghz rx_carrier", "<Frequency: in Hz>", furi_string_get_cstr(args));
|
2021-07-18 18:09:00 +00:00
|
|
|
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();
|
2023-06-30 14:03:36 +00:00
|
|
|
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
|
2021-08-08 18:03:25 +00:00
|
|
|
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-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_enter();
|
|
|
|
|
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)) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(250);
|
2022-05-11 09:45:01 +00:00
|
|
|
printf("RSSI: %03.1fdbm\r", (double)furi_hal_subghz_get_rssi());
|
2021-05-25 10:19:07 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2021-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-12 09:41:46 +00:00
|
|
|
static const SubGhzDevice* subghz_cli_command_get_device(uint32_t* device_ind) {
|
2023-06-30 14:03:36 +00:00
|
|
|
const SubGhzDevice* device = NULL;
|
2023-07-12 09:41:46 +00:00
|
|
|
switch(*device_ind) {
|
2023-06-30 14:03:36 +00:00
|
|
|
case 1:
|
|
|
|
subghz_cli_radio_device_power_on();
|
|
|
|
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
|
|
|
break;
|
|
|
|
}
|
2023-07-12 09:41:46 +00:00
|
|
|
//check if the device is connected
|
|
|
|
if(!subghz_devices_is_connect(device)) {
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
|
|
|
|
*device_ind = 0;
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-07-15 13:54:11 +00:00
|
|
|
uint32_t frequency = 433920000;
|
|
|
|
uint32_t key = 0x0074BADE;
|
2021-12-05 11:47:02 +00:00
|
|
|
uint32_t repeat = 10;
|
2022-08-30 15:22:24 +00:00
|
|
|
uint32_t te = 403;
|
2023-06-30 14:03:36 +00:00
|
|
|
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
2023-06-30 14:03:36 +00:00
|
|
|
int ret = sscanf(
|
|
|
|
furi_string_get_cstr(args),
|
|
|
|
"%lx %lu %lu %lu %lu",
|
|
|
|
&key,
|
|
|
|
&frequency,
|
|
|
|
&te,
|
|
|
|
&repeat,
|
|
|
|
&device_ind);
|
|
|
|
if(ret != 5) {
|
2021-07-15 13:54:11 +00:00
|
|
|
printf(
|
2023-06-30 14:03:36 +00:00
|
|
|
"sscanf returned %d, key: %lx, frequency: %lu, te: %lu, repeat: %lu, device: %lu\r\n ",
|
2021-07-15 13:54:11 +00:00
|
|
|
ret,
|
|
|
|
key,
|
|
|
|
frequency,
|
2022-08-30 15:22:24 +00:00
|
|
|
te,
|
2023-06-30 14:03:36 +00:00
|
|
|
repeat,
|
|
|
|
device_ind);
|
2021-07-15 13:54:11 +00:00
|
|
|
cli_print_usage(
|
2021-12-25 13:19:30 +00:00
|
|
|
"subghz tx",
|
2023-06-30 14:03:36 +00:00
|
|
|
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(args));
|
2021-07-15 13:54:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_init();
|
2023-07-12 09:41:46 +00:00
|
|
|
const SubGhzDevice* device = subghz_cli_command_get_device(&device_ind);
|
2023-06-30 14:03:36 +00:00
|
|
|
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
|
|
|
printf(
|
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-18 18:09:00 +00:00
|
|
|
printf(
|
2023-06-30 14:03:36 +00:00
|
|
|
"Transmitting at %lu, key %lx, te %lu, repeat %lu device %lu. Press CTRL+C to stop\r\n",
|
2021-07-18 18:09:00 +00:00
|
|
|
frequency,
|
|
|
|
key,
|
2022-08-30 15:22:24 +00:00
|
|
|
te,
|
2023-06-30 14:03:36 +00:00
|
|
|
repeat,
|
|
|
|
device_ind);
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* flipper_format_string = furi_string_alloc_printf(
|
2022-03-03 09:48:56 +00:00
|
|
|
"Protocol: Princeton\n"
|
|
|
|
"Bit: 24\n"
|
2022-08-30 15:22:24 +00:00
|
|
|
"Key: 00 00 00 00 00 %02X %02X %02X\n"
|
2022-12-26 12:13:30 +00:00
|
|
|
"TE: %lu\n"
|
|
|
|
"Repeat: %lu\n",
|
|
|
|
(uint8_t)((key >> 16) & 0xFFU),
|
|
|
|
(uint8_t)((key >> 8) & 0xFFU),
|
|
|
|
(uint8_t)(key & 0xFFU),
|
2022-08-30 15:22:24 +00:00
|
|
|
te,
|
2022-03-03 09:48:56 +00:00
|
|
|
repeat);
|
|
|
|
FlipperFormat* flipper_format = flipper_format_string_alloc();
|
|
|
|
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
|
|
|
stream_clean(stream);
|
2022-10-05 15:15:23 +00:00
|
|
|
stream_write_cstring(stream, furi_string_get_cstr(flipper_format_string));
|
2022-03-03 09:48:56 +00:00
|
|
|
|
|
|
|
SubGhzEnvironment* environment = subghz_environment_alloc();
|
2022-10-19 17:27:26 +00:00
|
|
|
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
[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>
2021-08-12 14:42:56 +00:00
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
|
|
|
|
subghz_transmitter_deserialize(transmitter, flipper_format);
|
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646)
* SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited
* SubGhz: Fix displaying Nice FlorS in the Raed scene
* SubGhz: Fix displaying Faac SLH in the Raed scene
* SubGhz: Fix displaying iDo in the Raed scene
* SubGhz: Fix displaying Star Line in the Raed scene
* SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control)
* SubGhz: subghz_beginadded common encoder upload signal
* SubGhz: add Came encoder
* SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder
* SubGhz: add nice flo encoder, need testing no remote control
* SubGhz: add gate_tx encoder
* SubGhz: add nero_sketch encoder
* SubGhz: add keelog encoder
* SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions)
* SubGhz: fix max upload
* SubGhz: Fix structure subghz add encoder
* SubGhz: add generating and sending a dynamic keelog key, refactoring the code
* SubGhz: add notifications
* SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan)
* SubGhz: Fix load file, fix scene start
* Subghz: Fix show key
* SubGhz: Fix subghz_cli
* SubGhz: Fix furi-hal-subghz
* Format sources
* SubGhz: standard notification scheme, fix broken assert in DMA.
* SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup.
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 19:56:23 +00:00
|
|
|
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_begin(device);
|
|
|
|
subghz_devices_reset(device);
|
|
|
|
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
|
|
|
frequency = subghz_devices_set_frequency(device, frequency);
|
2021-10-04 07:01:41 +00:00
|
|
|
|
|
|
|
furi_hal_power_suppress_charge_enter();
|
2023-06-30 14:03:36 +00:00
|
|
|
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
|
|
|
|
while(!(subghz_devices_is_async_complete_tx(device) || cli_cmd_interrupt_received(cli))) {
|
2023-05-31 12:59:12 +00:00
|
|
|
printf(".");
|
|
|
|
fflush(stdout);
|
|
|
|
furi_delay_ms(333);
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_stop_async_tx(device);
|
2021-07-15 13:54:11 +00:00
|
|
|
|
2023-05-31 12:59:12 +00:00
|
|
|
} else {
|
|
|
|
printf("Transmission on this frequency is restricted in your region\r\n");
|
[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>
2021-08-12 14:42:56 +00:00
|
|
|
}
|
SubGhz: read and save static remotes. Create new static and dynamic remotes. (#646)
* SubGhz: the functions of saving loading KeeLog have been modified, saving KeeLog is prohibited
* SubGhz: Fix displaying Nice FlorS in the Raed scene
* SubGhz: Fix displaying Faac SLH in the Raed scene
* SubGhz: Fix displaying iDo in the Raed scene
* SubGhz: Fix displaying Star Line in the Raed scene
* SubGhz: Fix displaying Nice Flo in the Raed scene, added save and load functions. (testing needed, no remote control)
* SubGhz: subghz_beginadded common encoder upload signal
* SubGhz: add Came encoder
* SubGhz: modified pricenton encoder, fix view transmitter hide the "Send" button if there is no encoder
* SubGhz: add nice flo encoder, need testing no remote control
* SubGhz: add gate_tx encoder
* SubGhz: add nero_sketch encoder
* SubGhz: add keelog encoder
* SubGhz: add long upload upload while the button is pressed while releasing the transfer is over, with a check for sticking (maximum 200 upload repetitions)
* SubGhz: fix max upload
* SubGhz: Fix structure subghz add encoder
* SubGhz: add generating and sending a dynamic keelog key, refactoring the code
* SubGhz: add notifications
* SubGhz: add creating a new remote control (Pricenton, Nice Flo 12bit, Nice Flo 24bit, CAME 12bit, CAME 24bit, Gate TX, DoorHan)
* SubGhz: Fix load file, fix scene start
* Subghz: Fix show key
* SubGhz: Fix subghz_cli
* SubGhz: Fix furi-hal-subghz
* Format sources
* SubGhz: standard notification scheme, fix broken assert in DMA.
* SubGhz: move level alignment logic to furi-hal-subghz, fix spelling, cleanup.
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-16 19:56:23 +00:00
|
|
|
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_sleep(device);
|
|
|
|
subghz_devices_end(device);
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
|
2021-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
flipper_format_free(flipper_format);
|
|
|
|
subghz_transmitter_free(transmitter);
|
|
|
|
subghz_environment_free(environment);
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
typedef struct {
|
|
|
|
volatile bool overrun;
|
2022-10-07 12:27:11 +00:00
|
|
|
FuriStreamBuffer* stream;
|
2021-07-18 18:09:00 +00:00
|
|
|
size_t packet_count;
|
|
|
|
} SubGhzCliCommandRx;
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
static void subghz_cli_command_rx_capture_callback(bool level, uint32_t duration, void* context) {
|
2021-07-18 18:09:00 +00:00
|
|
|
SubGhzCliCommandRx* instance = context;
|
2021-06-29 21:19:20 +00:00
|
|
|
|
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
|
|
|
}
|
2022-10-07 12:27:11 +00:00
|
|
|
size_t ret =
|
|
|
|
furi_stream_buffer_send(instance->stream, &level_duration, sizeof(LevelDuration), 0);
|
2021-07-18 18:09:00 +00:00
|
|
|
if(sizeof(LevelDuration) != ret) instance->overrun = true;
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
static void subghz_cli_command_rx_callback(
|
|
|
|
SubGhzReceiver* receiver,
|
|
|
|
SubGhzProtocolDecoderBase* decoder_base,
|
|
|
|
void* context) {
|
2021-07-18 18:09:00 +00:00
|
|
|
SubGhzCliCommandRx* instance = context;
|
|
|
|
instance->packet_count++;
|
2022-03-03 09:48:56 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* text;
|
|
|
|
text = furi_string_alloc();
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_protocol_decoder_base_get_string(decoder_base, text);
|
|
|
|
subghz_receiver_reset(receiver);
|
2022-10-05 15:15:23 +00:00
|
|
|
printf("%s", furi_string_get_cstr(text));
|
|
|
|
furi_string_free(text);
|
2021-07-18 18:09:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-06-29 21:19:20 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2023-06-30 14:03:36 +00:00
|
|
|
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
2023-06-30 14:03:36 +00:00
|
|
|
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
|
|
|
if(ret != 2) {
|
2021-06-29 21:19:20 +00:00
|
|
|
printf(
|
2023-06-30 14:03:36 +00:00
|
|
|
"sscanf returned %d, frequency: %lu device: %lu\r\n", ret, frequency, device_ind);
|
|
|
|
cli_print_usage(
|
|
|
|
"subghz rx",
|
|
|
|
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
|
|
|
furi_string_get_cstr(args));
|
2021-06-29 21:19:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_init();
|
2023-07-12 09:41:46 +00:00
|
|
|
const SubGhzDevice* device = subghz_cli_command_get_device(&device_ind);
|
2023-06-30 14:03:36 +00:00
|
|
|
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
|
|
|
printf(
|
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
return;
|
|
|
|
}
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Allocate context and buffers
|
2022-02-18 19:53:46 +00:00
|
|
|
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
2022-10-07 12:27:11 +00:00
|
|
|
instance->stream =
|
|
|
|
furi_stream_buffer_alloc(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
2021-07-18 18:09:00 +00:00
|
|
|
furi_check(instance->stream);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzEnvironment* environment = subghz_environment_alloc();
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
|
|
|
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
2023-02-08 16:59:49 +00:00
|
|
|
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
2022-10-19 17:27:26 +00:00
|
|
|
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
2022-03-03 09:48:56 +00:00
|
|
|
|
2022-03-16 09:18:48 +00:00
|
|
|
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
|
|
|
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Configure radio
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_begin(device);
|
|
|
|
subghz_devices_reset(device);
|
|
|
|
subghz_devices_load_preset(device, FuriHalSubGhzPresetOok650Async, NULL);
|
|
|
|
frequency = subghz_devices_set_frequency(device, frequency);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_enter();
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Prepare and start RX
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_start_async_rx(device, subghz_cli_command_rx_capture_callback, instance);
|
2021-06-29 21:19:20 +00:00
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Wait for packets to arrive
|
2023-06-30 14:03:36 +00:00
|
|
|
printf(
|
|
|
|
"Listening at frequency: %lu device: %lu. Press CTRL+C to stop\r\n",
|
|
|
|
frequency,
|
|
|
|
device_ind);
|
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)) {
|
2022-10-07 12:27:11 +00:00
|
|
|
int ret = furi_stream_buffer_receive(
|
|
|
|
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(".");
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_receiver_reset(receiver);
|
2021-06-29 21:19:20 +00:00
|
|
|
} 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);
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_receiver_decode(receiver, level, duration);
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
// Shutdown radio
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_stop_async_rx(device);
|
|
|
|
subghz_devices_sleep(device);
|
|
|
|
subghz_devices_end(device);
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
2021-07-18 18:09:00 +00:00
|
|
|
|
2021-10-04 07:01:41 +00:00
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
2022-12-26 12:13:30 +00:00
|
|
|
printf("\r\nPackets received %zu\r\n", instance->packet_count);
|
2021-07-18 18:09:00 +00:00
|
|
|
|
|
|
|
// Cleanup
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_receiver_free(receiver);
|
|
|
|
subghz_environment_free(environment);
|
2022-10-07 12:27:11 +00:00
|
|
|
furi_stream_buffer_free(instance->stream);
|
2021-07-18 18:09:00 +00:00
|
|
|
free(instance);
|
2021-06-29 21:19:20 +00:00
|
|
|
}
|
2021-11-01 13:11:25 +00:00
|
|
|
|
2023-02-08 13:20:42 +00:00
|
|
|
void subghz_cli_command_rx_raw(Cli* cli, FuriString* args, void* context) {
|
|
|
|
UNUSED(context);
|
|
|
|
uint32_t frequency = 433920000;
|
|
|
|
|
|
|
|
if(furi_string_size(args)) {
|
|
|
|
int ret = sscanf(furi_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>", furi_string_get_cstr(args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
|
|
|
printf(
|
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate context and buffers
|
|
|
|
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
|
|
|
instance->stream =
|
|
|
|
furi_stream_buffer_alloc(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
|
|
|
furi_check(instance->stream);
|
|
|
|
|
|
|
|
// Configure radio
|
|
|
|
furi_hal_subghz_reset();
|
2023-06-30 14:03:36 +00:00
|
|
|
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_270khz_async_regs);
|
2023-02-08 13:20:42 +00:00
|
|
|
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
|
|
|
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
|
|
|
|
|
|
|
furi_hal_power_suppress_charge_enter();
|
|
|
|
|
|
|
|
// Prepare and start RX
|
|
|
|
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_capture_callback, instance);
|
|
|
|
|
|
|
|
// Wait for packets to arrive
|
|
|
|
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
|
|
|
LevelDuration level_duration;
|
|
|
|
size_t counter = 0;
|
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
|
|
|
int ret = furi_stream_buffer_receive(
|
|
|
|
instance->stream, &level_duration, sizeof(LevelDuration), 10);
|
|
|
|
if(ret == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(ret != sizeof(LevelDuration)) {
|
|
|
|
puts("stream corrupt");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(level_duration_is_reset(level_duration)) {
|
|
|
|
puts(". ");
|
|
|
|
} else {
|
|
|
|
bool level = level_duration_get_level(level_duration);
|
|
|
|
uint32_t duration = level_duration_get_duration(level_duration);
|
|
|
|
printf("%c%lu ", level ? '+' : '-', duration);
|
|
|
|
}
|
|
|
|
furi_thread_stdout_flush();
|
|
|
|
counter++;
|
|
|
|
if(counter > 255) {
|
|
|
|
puts("\r\n");
|
|
|
|
counter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown radio
|
|
|
|
furi_hal_subghz_stop_async_rx();
|
|
|
|
furi_hal_subghz_sleep();
|
|
|
|
|
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
furi_stream_buffer_free(instance->stream);
|
|
|
|
free(instance);
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* file_name;
|
|
|
|
file_name = furi_string_alloc();
|
|
|
|
furi_string_set(file_name, ANY_PATH("subghz/test.sub"));
|
2022-04-14 12:49:29 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-04-14 12:49:29 +00:00
|
|
|
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* temp_str;
|
|
|
|
temp_str = furi_string_alloc();
|
2022-04-14 12:49:29 +00:00
|
|
|
uint32_t temp_data32;
|
|
|
|
bool check_file = false;
|
|
|
|
|
|
|
|
do {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
2022-04-14 12:49:29 +00:00
|
|
|
if(!args_read_string_and_trim(args, file_name)) {
|
|
|
|
cli_print_usage(
|
2022-10-05 15:15:23 +00:00
|
|
|
"subghz decode_raw", "<file_name: path_RAW_file>", furi_string_get_cstr(args));
|
2022-04-14 12:49:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
2022-04-14 12:49:29 +00:00
|
|
|
printf(
|
|
|
|
"subghz decode_raw \033[0;31mError open file\033[0m %s\r\n",
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(file_name));
|
2022-04-14 12:49:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
|
|
|
printf("subghz decode_raw \033[0;31mMissing or incorrect header\033[0m\r\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE) &&
|
2022-04-14 12:49:29 +00:00
|
|
|
temp_data32 == SUBGHZ_KEY_FILE_VERSION) {
|
|
|
|
} else {
|
|
|
|
printf("subghz decode_raw \033[0;31mType or version mismatch\033[0m\r\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_file = true;
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(temp_str);
|
2022-04-14 12:49:29 +00:00
|
|
|
flipper_format_free(fff_data_file);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-04-14 12:49:29 +00:00
|
|
|
|
|
|
|
if(check_file) {
|
|
|
|
// Allocate context
|
|
|
|
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
|
|
|
|
|
|
|
SubGhzEnvironment* environment = subghz_environment_alloc();
|
2023-06-30 14:03:36 +00:00
|
|
|
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
|
[FL-2658, FL-2657] SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode) (#1404)
* Subghz: fix cli no load keeloq_mfcodes_user
* SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode)
* SubGhz: fix syntax
* SubGhz: fix error build
Co-authored-by: あく <alleteam@gmail.com>
2022-07-17 09:45:21 +00:00
|
|
|
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
2022-04-14 12:49:29 +00:00
|
|
|
} else {
|
[FL-2658, FL-2657] SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode) (#1404)
* Subghz: fix cli no load keeloq_mfcodes_user
* SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode)
* SubGhz: fix syntax
* SubGhz: fix error build
Co-authored-by: あく <alleteam@gmail.com>
2022-07-17 09:45:21 +00:00
|
|
|
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
|
[FL-2658, FL-2657] SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode) (#1404)
* Subghz: fix cli no load keeloq_mfcodes_user
* SubGhz: add new protocol (IronLogic, Comunello, Sommer(fsk476), Normstahl, KEY, EcoStar, Gibidi, Mutancode)
* SubGhz: fix syntax
* SubGhz: fix error build
Co-authored-by: あく <alleteam@gmail.com>
2022-07-17 09:45:21 +00:00
|
|
|
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
|
|
|
} else {
|
|
|
|
printf(
|
|
|
|
"SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;31mERROR\033[0m\r\n");
|
2022-04-14 12:49:29 +00:00
|
|
|
}
|
|
|
|
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_CAME_ATOMO_DIR_NAME);
|
2023-02-08 16:59:49 +00:00
|
|
|
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
2022-04-14 12:49:29 +00:00
|
|
|
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
2023-06-30 14:03:36 +00:00
|
|
|
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
2022-10-19 17:27:26 +00:00
|
|
|
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
2022-04-14 12:49:29 +00:00
|
|
|
|
|
|
|
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
|
|
|
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
|
|
|
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
|
|
|
|
|
|
|
SubGhzFileEncoderWorker* file_worker_encoder = subghz_file_encoder_worker_alloc();
|
2023-06-30 14:03:36 +00:00
|
|
|
if(subghz_file_encoder_worker_start(
|
|
|
|
file_worker_encoder, furi_string_get_cstr(file_name), NULL)) {
|
2022-04-14 12:49:29 +00:00
|
|
|
//the worker needs a file in order to open and read part of the file
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(100);
|
2022-04-14 12:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(
|
|
|
|
"Listening at \033[0;33m%s\033[0m.\r\n\r\nPress CTRL+C to stop\r\n\r\n",
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(file_name));
|
2022-04-14 12:49:29 +00:00
|
|
|
|
|
|
|
LevelDuration level_duration;
|
|
|
|
while(!cli_cmd_interrupt_received(cli)) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_us(500); //you need to have time to read from the file from the SD card
|
2022-04-14 12:49:29 +00:00
|
|
|
level_duration = subghz_file_encoder_worker_get_level_duration(file_worker_encoder);
|
|
|
|
if(!level_duration_is_reset(level_duration)) {
|
|
|
|
bool level = level_duration_get_level(level_duration);
|
|
|
|
uint32_t duration = level_duration_get_duration(level_duration);
|
|
|
|
subghz_receiver_decode(receiver, level, duration);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-12 16:34:30 +00:00
|
|
|
printf("\r\nPackets received \033[0;32m%zu\033[0m\r\n", instance->packet_count);
|
2022-04-14 12:49:29 +00:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
subghz_receiver_free(receiver);
|
|
|
|
subghz_environment_free(environment);
|
|
|
|
|
|
|
|
if(subghz_file_encoder_worker_is_running(file_worker_encoder)) {
|
|
|
|
subghz_file_encoder_worker_stop(file_worker_encoder);
|
|
|
|
}
|
|
|
|
subghz_file_encoder_worker_free(file_worker_encoder);
|
|
|
|
free(instance);
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(file_name);
|
2022-04-14 12:49:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 15:44:39 +00:00
|
|
|
static void subghz_cli_command_print_usage() {
|
2021-11-01 13:11:25 +00:00
|
|
|
printf("Usage:\r\n");
|
2021-11-03 16:41:07 +00:00
|
|
|
printf("subghz <cmd> <args>\r\n");
|
2021-11-01 13:11:25 +00:00
|
|
|
printf("Cmd list:\r\n");
|
2021-12-25 13:19:30 +00:00
|
|
|
|
2021-11-01 13:11:25 +00:00
|
|
|
printf(
|
2023-06-30 14:03:36 +00:00
|
|
|
"\tchat <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Chat with other Flippers\r\n");
|
|
|
|
printf(
|
|
|
|
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Transmitting key\r\n");
|
|
|
|
printf("\trx <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Receive\r\n");
|
2023-02-08 13:20:42 +00:00
|
|
|
printf("\trx_raw <frequency:in Hz>\t - Receive RAW\r\n");
|
2022-04-14 12:49:29 +00:00
|
|
|
printf("\tdecode_raw <file_name: path_RAW_file>\t - Testing\r\n");
|
2021-12-25 13:19:30 +00:00
|
|
|
|
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
|
|
|
printf("\r\n");
|
|
|
|
printf(" debug cmd:\r\n");
|
|
|
|
printf("\ttx_carrier <frequency:in Hz>\t - Transmit carrier\r\n");
|
2022-11-23 13:23:11 +00:00
|
|
|
printf("\trx_carrier <frequency:in Hz>\t - Receive carrier\r\n");
|
2021-12-25 13:19:30 +00:00
|
|
|
printf(
|
|
|
|
"\tencrypt_keeloq <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt keeloq manufacture keys\r\n");
|
|
|
|
printf(
|
|
|
|
"\tencrypt_raw <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt RAW data\r\n");
|
|
|
|
}
|
2021-11-01 13:11:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static void subghz_cli_command_encrypt_keeloq(Cli* cli, FuriString* args) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(cli);
|
2021-11-01 13:11:25 +00:00
|
|
|
uint8_t iv[16];
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* source;
|
|
|
|
FuriString* destination;
|
|
|
|
source = furi_string_alloc();
|
|
|
|
destination = furi_string_alloc();
|
2021-11-01 13:11:25 +00:00
|
|
|
|
|
|
|
SubGhzKeystore* keystore = subghz_keystore_alloc();
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!args_read_string_and_trim(args, source)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args_read_string_and_trim(args, destination)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args_read_hex_bytes(args, iv, 16)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!subghz_keystore_load(keystore, furi_string_get_cstr(source))) {
|
2021-11-01 13:11:25 +00:00
|
|
|
printf("Failed to load Keystore");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!subghz_keystore_save(keystore, furi_string_get_cstr(destination), iv)) {
|
2021-11-01 13:11:25 +00:00
|
|
|
printf("Failed to save Keystore");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
subghz_keystore_free(keystore);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(destination);
|
|
|
|
furi_string_free(source);
|
2021-11-01 13:11:25 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static void subghz_cli_command_encrypt_raw(Cli* cli, FuriString* args) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(cli);
|
2021-11-03 16:41:07 +00:00
|
|
|
uint8_t iv[16];
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* source;
|
|
|
|
FuriString* destination;
|
|
|
|
source = furi_string_alloc();
|
|
|
|
destination = furi_string_alloc();
|
2021-11-03 16:41:07 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if(!args_read_string_and_trim(args, source)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args_read_string_and_trim(args, destination)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!args_read_hex_bytes(args, iv, 16)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!subghz_keystore_raw_encrypted_save(
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(source), furi_string_get_cstr(destination), iv)) {
|
2021-11-03 16:41:07 +00:00
|
|
|
printf("Failed to save Keystore");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(destination);
|
|
|
|
furi_string_free(source);
|
2021-11-03 16:41:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static void subghz_cli_command_chat(Cli* cli, FuriString* args) {
|
2021-12-01 15:44:39 +00:00
|
|
|
uint32_t frequency = 433920000;
|
2023-06-30 14:03:36 +00:00
|
|
|
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
2021-12-01 15:44:39 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(args)) {
|
2023-06-30 14:03:36 +00:00
|
|
|
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &frequency, &device_ind);
|
|
|
|
if(ret != 2) {
|
|
|
|
printf("sscanf returned %d, Frequency: %lu\r\n", ret, frequency);
|
|
|
|
printf("sscanf returned %d, Device: %lu\r\n", ret, device_ind);
|
|
|
|
cli_print_usage(
|
|
|
|
"subghz chat",
|
|
|
|
"<Frequency: in Hz> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
|
|
|
furi_string_get_cstr(args));
|
2021-12-01 15:44:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 14:03:36 +00:00
|
|
|
subghz_devices_init();
|
2023-07-12 09:41:46 +00:00
|
|
|
const SubGhzDevice* device = subghz_cli_command_get_device(&device_ind);
|
2023-06-30 14:03:36 +00:00
|
|
|
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
|
|
|
printf(
|
|
|
|
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n", frequency);
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
return;
|
|
|
|
}
|
2022-08-11 09:21:56 +00:00
|
|
|
if(!furi_hal_region_is_frequency_allowed(frequency)) {
|
2021-12-01 15:44:39 +00:00
|
|
|
printf(
|
|
|
|
"In your region, only reception on this frequency (%lu) is allowed,\r\n"
|
|
|
|
"the actual operation of the application is not possible\r\n ",
|
|
|
|
frequency);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-29 12:02:17 +00:00
|
|
|
SubGhzChatWorker* subghz_chat = subghz_chat_worker_alloc(cli);
|
2023-06-30 14:03:36 +00:00
|
|
|
|
|
|
|
if(!subghz_chat_worker_start(subghz_chat, device, frequency)) {
|
2021-12-08 13:42:01 +00:00
|
|
|
printf("Startup error SubGhzChatWorker\r\n");
|
|
|
|
|
|
|
|
if(subghz_chat_worker_is_running(subghz_chat)) {
|
|
|
|
subghz_chat_worker_stop(subghz_chat);
|
|
|
|
subghz_chat_worker_free(subghz_chat);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-12-01 15:44:39 +00:00
|
|
|
|
|
|
|
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
|
|
|
printf("Press CTRL+C to stop\r\n");
|
|
|
|
|
|
|
|
furi_hal_power_suppress_charge_enter();
|
2021-12-08 13:42:01 +00:00
|
|
|
|
2021-12-01 15:44:39 +00:00
|
|
|
size_t message_max_len = 64;
|
|
|
|
uint8_t message[64] = {0};
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* input;
|
|
|
|
input = furi_string_alloc();
|
|
|
|
FuriString* name;
|
|
|
|
name = furi_string_alloc();
|
|
|
|
FuriString* output;
|
|
|
|
output = furi_string_alloc();
|
|
|
|
FuriString* sysmsg;
|
|
|
|
sysmsg = furi_string_alloc();
|
2021-12-01 15:44:39 +00:00
|
|
|
bool exit = false;
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzChatEvent chat_event;
|
2021-12-01 15:44:39 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
2021-12-04 13:40:17 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(name, "\033[0;33m%s\033[0m: ", furi_hal_version_get_name_ptr());
|
|
|
|
furi_string_set(input, name);
|
|
|
|
printf("%s", furi_string_get_cstr(input));
|
2021-12-01 15:44:39 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
while(!exit) {
|
2021-12-08 13:42:01 +00:00
|
|
|
chat_event = subghz_chat_worker_get_event_chat(subghz_chat);
|
|
|
|
switch(chat_event.event) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzChatEventInputData:
|
2021-12-08 13:42:01 +00:00
|
|
|
if(chat_event.c == CliSymbolAsciiETX) {
|
2021-12-01 15:44:39 +00:00
|
|
|
printf("\r\n");
|
2022-03-03 09:48:56 +00:00
|
|
|
chat_event.event = SubGhzChatEventUserExit;
|
2021-12-08 13:42:01 +00:00
|
|
|
subghz_chat_worker_put_event_chat(subghz_chat, &chat_event);
|
2021-12-01 15:44:39 +00:00
|
|
|
break;
|
2021-12-08 13:42:01 +00:00
|
|
|
} else if(
|
|
|
|
(chat_event.c == CliSymbolAsciiBackspace) || (chat_event.c == CliSymbolAsciiDel)) {
|
2022-10-05 15:15:23 +00:00
|
|
|
size_t len = furi_string_utf8_length(input);
|
|
|
|
if(len > furi_string_utf8_length(name)) {
|
2021-12-02 11:19:47 +00:00
|
|
|
printf("%s", "\e[D\e[1P");
|
2021-12-01 15:44:39 +00:00
|
|
|
fflush(stdout);
|
2021-12-08 13:42:01 +00:00
|
|
|
//delete 1 char UTF
|
2022-10-05 15:15:23 +00:00
|
|
|
const char* str = furi_string_get_cstr(input);
|
2021-12-08 13:42:01 +00:00
|
|
|
size_t size = 0;
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriStringUTF8State s = FuriStringUTF8StateStarting;
|
|
|
|
FuriStringUnicodeValue u = 0;
|
|
|
|
furi_string_reset(sysmsg);
|
2021-12-08 13:42:01 +00:00
|
|
|
while(*str) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_utf8_decode(*str, &s, &u);
|
|
|
|
if((s == FuriStringUTF8StateError) || s == FuriStringUTF8StateStarting) {
|
|
|
|
furi_string_utf8_push(sysmsg, u);
|
2021-12-08 13:42:01 +00:00
|
|
|
if(++size >= len - 1) break;
|
2022-10-05 15:15:23 +00:00
|
|
|
s = FuriStringUTF8StateStarting;
|
2021-12-08 13:42:01 +00:00
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(input, sysmsg);
|
2021-12-01 15:44:39 +00:00
|
|
|
}
|
2021-12-08 13:42:01 +00:00
|
|
|
} else if(chat_event.c == CliSymbolAsciiCR) {
|
2021-12-01 15:44:39 +00:00
|
|
|
printf("\r\n");
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_push_back(input, '\r');
|
|
|
|
furi_string_push_back(input, '\n');
|
2021-12-08 13:42:01 +00:00
|
|
|
while(!subghz_chat_worker_write(
|
|
|
|
subghz_chat,
|
2022-10-05 15:15:23 +00:00
|
|
|
(uint8_t*)furi_string_get_cstr(input),
|
|
|
|
strlen(furi_string_get_cstr(input)))) {
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(10);
|
2021-12-08 13:42:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(input, "%s", furi_string_get_cstr(name));
|
|
|
|
printf("%s", furi_string_get_cstr(input));
|
2021-12-01 15:44:39 +00:00
|
|
|
fflush(stdout);
|
2021-12-08 13:42:01 +00:00
|
|
|
} else if(chat_event.c == CliSymbolAsciiLF) {
|
|
|
|
//cut out the symbol \n
|
|
|
|
} else {
|
|
|
|
putc(chat_event.c, stdout);
|
|
|
|
fflush(stdout);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_push_back(input, chat_event.c);
|
2021-12-08 13:42:01 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzChatEventRXData:
|
2021-12-08 13:42:01 +00:00
|
|
|
do {
|
|
|
|
memset(message, 0x00, message_max_len);
|
|
|
|
size_t len = subghz_chat_worker_read(subghz_chat, message, message_max_len);
|
|
|
|
for(size_t i = 0; i < len; i++) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_push_back(output, message[i]);
|
2021-12-08 13:42:01 +00:00
|
|
|
if(message[i] == '\n') {
|
|
|
|
printf("\r");
|
|
|
|
for(uint8_t i = 0; i < 80; i++) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
printf("\r %s", furi_string_get_cstr(output));
|
|
|
|
printf("%s", furi_string_get_cstr(input));
|
2021-12-08 13:42:01 +00:00
|
|
|
fflush(stdout);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(output);
|
2021-12-08 13:42:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(subghz_chat_worker_available(subghz_chat));
|
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzChatEventNewMessage:
|
2021-12-08 13:42:01 +00:00
|
|
|
notification_message(notification, &sequence_single_vibro);
|
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzChatEventUserEntrance:
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(
|
2021-12-08 13:42:01 +00:00
|
|
|
sysmsg,
|
|
|
|
"\033[0;34m%s joined chat.\033[0m\r\n",
|
|
|
|
furi_hal_version_get_name_ptr());
|
|
|
|
subghz_chat_worker_write(
|
|
|
|
subghz_chat,
|
2022-10-05 15:15:23 +00:00
|
|
|
(uint8_t*)furi_string_get_cstr(sysmsg),
|
|
|
|
strlen(furi_string_get_cstr(sysmsg)));
|
2021-12-08 13:42:01 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzChatEventUserExit:
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(
|
2021-12-08 13:42:01 +00:00
|
|
|
sysmsg, "\033[0;31m%s left chat.\033[0m\r\n", furi_hal_version_get_name_ptr());
|
|
|
|
subghz_chat_worker_write(
|
|
|
|
subghz_chat,
|
2022-10-05 15:15:23 +00:00
|
|
|
(uint8_t*)furi_string_get_cstr(sysmsg),
|
|
|
|
strlen(furi_string_get_cstr(sysmsg)));
|
2022-07-20 10:56:33 +00:00
|
|
|
furi_delay_ms(10);
|
2021-12-08 13:42:01 +00:00
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FURI_LOG_W("SubGhzChat", "Error event");
|
|
|
|
break;
|
2021-12-01 15:44:39 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-25 11:48:06 +00:00
|
|
|
if(!cli_is_connected(cli)) {
|
2022-07-23 03:35:14 +00:00
|
|
|
printf("\r\n");
|
|
|
|
chat_event.event = SubGhzChatEventUserExit;
|
|
|
|
subghz_chat_worker_put_event_chat(subghz_chat, &chat_event);
|
|
|
|
}
|
2021-12-01 15:44:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(input);
|
|
|
|
furi_string_free(name);
|
|
|
|
furi_string_free(output);
|
|
|
|
furi_string_free(sysmsg);
|
2023-06-30 14:03:36 +00:00
|
|
|
|
|
|
|
subghz_devices_deinit();
|
|
|
|
subghz_cli_radio_device_power_off();
|
|
|
|
|
2021-12-01 15:44:39 +00:00
|
|
|
furi_hal_power_suppress_charge_exit();
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
2021-12-01 15:44:39 +00:00
|
|
|
|
2021-12-08 13:42:01 +00:00
|
|
|
if(subghz_chat_worker_is_running(subghz_chat)) {
|
|
|
|
subghz_chat_worker_stop(subghz_chat);
|
|
|
|
subghz_chat_worker_free(subghz_chat);
|
2021-12-01 15:44:39 +00:00
|
|
|
}
|
2021-12-08 13:42:01 +00:00
|
|
|
printf("\r\nExit chat\r\n");
|
2021-12-01 15:44:39 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static void subghz_cli_command(Cli* cli, FuriString* args, void* context) {
|
|
|
|
FuriString* cmd;
|
|
|
|
cmd = furi_string_alloc();
|
2021-11-01 13:11:25 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if(!args_read_string_and_trim(args, cmd)) {
|
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "chat") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_chat(cli, args);
|
2021-11-01 13:11:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "tx") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_tx(cli, args, context);
|
2021-11-03 16:41:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "rx") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_rx(cli, args, context);
|
2021-12-01 15:44:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-04-14 12:49:29 +00:00
|
|
|
|
2023-02-08 13:20:42 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "rx_raw") == 0) {
|
|
|
|
subghz_cli_command_rx_raw(cli, args, context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "decode_raw") == 0) {
|
2022-04-14 12:49:29 +00:00
|
|
|
subghz_cli_command_decode_raw(cli, args, context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-25 13:19:30 +00:00
|
|
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "encrypt_keeloq") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_encrypt_keeloq(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "encrypt_raw") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_encrypt_raw(cli, args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "tx_carrier") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_tx_carrier(cli, args, context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_cmp_str(cmd, "rx_carrier") == 0) {
|
2021-12-25 13:19:30 +00:00
|
|
|
subghz_cli_command_rx_carrier(cli, args, context);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 15:44:39 +00:00
|
|
|
|
2021-11-01 13:11:25 +00:00
|
|
|
subghz_cli_command_print_usage();
|
|
|
|
} while(false);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(cmd);
|
2021-11-01 13:11:25 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 09:21:56 +00:00
|
|
|
static bool
|
|
|
|
subghz_on_system_start_istream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
|
|
|
File* file = istream->state;
|
|
|
|
uint16_t ret = storage_file_read(file, buf, count);
|
|
|
|
return (count == ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool subghz_on_system_start_istream_decode_band(
|
|
|
|
pb_istream_t* stream,
|
|
|
|
const pb_field_t* field,
|
|
|
|
void** arg) {
|
|
|
|
(void)field;
|
|
|
|
FuriHalRegion* region = *arg;
|
|
|
|
|
|
|
|
PB_Region_Band band = {0};
|
|
|
|
if(!pb_decode(stream, PB_Region_Band_fields, &band)) {
|
|
|
|
FURI_LOG_E("SubGhzOnStart", "PB Region band decode error: %s", PB_GET_ERROR(stream));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
region->bands_count += 1;
|
2022-12-26 12:13:30 +00:00
|
|
|
region = realloc( //-V701
|
|
|
|
region,
|
|
|
|
sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count);
|
2022-08-11 09:21:56 +00:00
|
|
|
size_t pos = region->bands_count - 1;
|
|
|
|
region->bands[pos].start = band.start;
|
|
|
|
region->bands[pos].end = band.end;
|
|
|
|
region->bands[pos].power_limit = band.power_limit;
|
|
|
|
region->bands[pos].duty_cycle = band.duty_cycle;
|
|
|
|
*arg = region;
|
|
|
|
|
|
|
|
FURI_LOG_I(
|
|
|
|
"SubGhzOnStart",
|
2022-12-26 12:13:30 +00:00
|
|
|
"Add allowed band: start %luHz, stop %luHz, power_limit %ddBm, duty_cycle %u%%",
|
2022-08-11 09:21:56 +00:00
|
|
|
band.start,
|
|
|
|
band.end,
|
|
|
|
band.power_limit,
|
|
|
|
band.duty_cycle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-24 18:47:48 +00:00
|
|
|
void subghz_on_system_start() {
|
|
|
|
#ifdef SRV_CLI
|
2022-07-26 12:21:51 +00:00
|
|
|
Cli* cli = furi_record_open(RECORD_CLI);
|
2021-11-01 13:11:25 +00:00
|
|
|
|
|
|
|
cli_add_command(cli, "subghz", CliCommandFlagDefault, subghz_cli_command, NULL);
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_CLI);
|
2022-04-13 20:50:25 +00:00
|
|
|
#else
|
|
|
|
UNUSED(subghz_cli_command);
|
2021-12-24 18:47:48 +00:00
|
|
|
#endif
|
2022-08-11 09:21:56 +00:00
|
|
|
|
|
|
|
#ifdef SRV_STORAGE
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
File* file = storage_file_alloc(storage);
|
|
|
|
FileInfo fileinfo = {0};
|
|
|
|
PB_Region pb_region = {0};
|
|
|
|
pb_region.bands.funcs.decode = subghz_on_system_start_istream_decode_band;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(storage_common_stat(storage, SUBGHZ_REGION_FILENAME, &fileinfo) != FSE_OK ||
|
|
|
|
fileinfo.size == 0) {
|
|
|
|
FURI_LOG_W("SubGhzOnStart", "Region data is missing or empty");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!storage_file_open(file, SUBGHZ_REGION_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
|
FURI_LOG_E("SubGhzOnStart", "Unable to open region data");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pb_istream_t istream = {
|
|
|
|
.callback = subghz_on_system_start_istream_read,
|
|
|
|
.state = file,
|
|
|
|
.errmsg = NULL,
|
|
|
|
.bytes_left = fileinfo.size,
|
|
|
|
};
|
|
|
|
|
|
|
|
pb_region.bands.arg = malloc(sizeof(FuriHalRegion));
|
|
|
|
if(!pb_decode(&istream, PB_Region_fields, &pb_region)) {
|
|
|
|
FURI_LOG_E("SubGhzOnStart", "Invalid region data");
|
|
|
|
free(pb_region.bands.arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuriHalRegion* region = pb_region.bands.arg;
|
|
|
|
memcpy(
|
|
|
|
region->country_code,
|
|
|
|
pb_region.country_code->bytes,
|
|
|
|
pb_region.country_code->size < 4 ? pb_region.country_code->size : 3);
|
|
|
|
furi_hal_region_set(region);
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
pb_release(PB_Region_fields, &pb_region);
|
|
|
|
storage_file_free(file);
|
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
#else
|
|
|
|
UNUSED(subghz_cli_command);
|
2022-09-14 16:11:38 +00:00
|
|
|
UNUSED(subghz_on_system_start_istream_decode_band);
|
|
|
|
UNUSED(subghz_on_system_start_istream_read);
|
2022-08-11 09:21:56 +00:00
|
|
|
#endif
|
2021-11-01 13:11:25 +00:00
|
|
|
}
|