Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgornekich <n.gorbadey@gmail.com>2021-06-08 12:51:16 +0300
committerGitHub <noreply@github.com>2021-06-08 12:51:16 +0300
commit498ffe8d2c7bcc2a107db3d5624fb4f612aac34c (patch)
tree0fde1713d51cc3c252fc1444484d015faa6e2a52 /applications/subghz/subghz_cli.c
parent216f8b4fb86ec8a29b061b0ac1ab50b63157397c (diff)
Subghz packet test (#512)
* subghz: add cli support for packet tx rx * api-hal-subghz: add comments * subghz_cli: fix typo Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/subghz/subghz_cli.c')
-rwxr-xr-x[-rw-r--r--]applications/subghz/subghz_cli.c126
1 files changed, 120 insertions, 6 deletions
diff --git a/applications/subghz/subghz_cli.c b/applications/subghz/subghz_cli.c
index 61bbcdea..419da1b6 100644..100755
--- a/applications/subghz/subghz_cli.c
+++ b/applications/subghz/subghz_cli.c
@@ -2,6 +2,13 @@
#include <furi.h>
#include <api-hal.h>
+static const uint8_t subghz_test_packet_data[] = {
+ 0x30, // 48bytes to transmit
+ 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
+};
+
void subghz_cli_init() {
Cli* cli = furi_record_open("cli");
@@ -32,9 +39,9 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
frequency = api_hal_subghz_set_frequency(frequency);
printf("Transmitting at frequency %lu Hz\r\n", frequency);
printf("Press CTRL+C to stop\r\n");
- if(frequency < 400) {
+ if(frequency < 400000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath315);
- } else if(frequency < 500) {
+ } else if(frequency < 500000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath433);
} else {
api_hal_subghz_set_path(ApiHalSubGhzPath868);
@@ -73,9 +80,9 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
frequency = api_hal_subghz_set_frequency(frequency);
printf("Receiving at frequency %lu Hz\r\n", frequency);
printf("Press CTRL+C to stop\r\n");
- if(frequency < 400) {
+ if(frequency < 400000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath315);
- } else if(frequency < 500) {
+ } else if(frequency < 500000000) {
api_hal_subghz_set_path(ApiHalSubGhzPath433);
} else {
api_hal_subghz_set_path(ApiHalSubGhzPath868);
@@ -96,9 +103,116 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
}
void subghz_cli_command_tx_pt(Cli* cli, string_t args, void* context) {
- printf("Not implemented\r\n");
+ uint32_t frequency;
+ uint32_t pattern;
+ uint32_t count;
+
+ int ret = sscanf(string_get_cstr(args), "%lu %lu %lu", &frequency, &pattern, &count);
+ if(ret != 3) {
+ printf(
+ "sscanf returned %d, frequency: %lu; pattern: %lu; count: %lu\r\n",
+ ret,
+ frequency,
+ pattern,
+ count);
+ cli_print_usage(
+ "subghz_tx_pt", "<Frequency in HZ> <Pattern> <Count>", string_get_cstr(args));
+ return;
+ }
+
+ if(frequency < 300000000 || frequency > 925000000) {
+ printf("Frequency must be in 300000000...925000000 range, not %lu\r\n", frequency);
+ return;
+ }
+ if(pattern > 1) {
+ printf("Pattern must be 1, not %lu\r\n", pattern);
+ }
+
+ api_hal_subghz_reset();
+ api_hal_subghz_idle();
+
+ api_hal_subghz_load_preset(ApiHalSubGhzPreset2FskPacket);
+
+ frequency = api_hal_subghz_set_frequency(frequency);
+ if(frequency < 400000000) {
+ api_hal_subghz_set_path(ApiHalSubGhzPath315);
+ } else if(frequency < 500000000) {
+ api_hal_subghz_set_path(ApiHalSubGhzPath433);
+ } else {
+ api_hal_subghz_set_path(ApiHalSubGhzPath868);
+ }
+ hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
+
+ uint8_t status = api_hal_subghz_get_status();
+ FURI_LOG_D("SUBGHZ CLI", "Status: %02X", status);
+
+ while(!cli_cmd_interrupt_received(cli) && count) {
+ api_hal_subghz_idle();
+ api_hal_subghz_write_packet(subghz_test_packet_data, sizeof(subghz_test_packet_data));
+ api_hal_subghz_tx();
+ while(!hal_gpio_read(&gpio_cc1101_g0))
+ ; // Wait for sync
+ while(hal_gpio_read(&gpio_cc1101_g0))
+ ; // Wait end of transaction
+ count--;
+ }
+
+ api_hal_subghz_reset();
+ api_hal_subghz_set_path(ApiHalSubGhzPathIsolate);
+ hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
void subghz_cli_command_rx_pt(Cli* cli, string_t args, void* context) {
- printf("Not implemented\r\n");
+ uint32_t frequency;
+
+ 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_pt", "<Frequency in HZ>", string_get_cstr(args));
+ return;
+ }
+
+ if(frequency < 300000000 || frequency > 925000000) {
+ printf("Frequency must be in 300000000...925000000 range, not %lu\r\n", frequency);
+ return;
+ }
+
+ api_hal_subghz_reset();
+ api_hal_subghz_idle();
+ api_hal_subghz_load_preset(ApiHalSubGhzPreset2FskPacket);
+
+ frequency = api_hal_subghz_set_frequency(frequency);
+ if(frequency < 400000000) {
+ api_hal_subghz_set_path(ApiHalSubGhzPath315);
+ } else if(frequency < 500000000) {
+ api_hal_subghz_set_path(ApiHalSubGhzPath433);
+ } else {
+ api_hal_subghz_set_path(ApiHalSubGhzPath868);
+ }
+ hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
+
+ uint8_t status = api_hal_subghz_get_status();
+ FURI_LOG_D("SUBGHZ CLI", "Status: %02X", status);
+ printf("Start receiving packets. Press CTRL+C to stop\r\n");
+
+ api_hal_subghz_flush_rx();
+ api_hal_subghz_rx();
+ uint32_t packet_cnt = 0;
+
+ while(!cli_cmd_interrupt_received(cli)) {
+ if(hal_gpio_read(&gpio_cc1101_g0)) {
+ while(hal_gpio_read(&gpio_cc1101_g0))
+ ; // Wait reception
+ packet_cnt++;
+ api_hal_subghz_idle();
+ api_hal_subghz_flush_rx();
+ api_hal_subghz_rx();
+ }
+ }
+
+ printf("Received %lu packets", packet_cnt);
+
+ api_hal_subghz_reset();
+ api_hal_subghz_set_path(ApiHalSubGhzPathIsolate);
+ hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}