SubGhz: sending / receiving messages via subghz (#851)
* SubGhz: add worker subghz_txrx * SubGhz: added support for transferring Russian characters and support for backspace in CLI subghz_txrx * SubGhz: refactoring subghz_txrx_worker, added a callback for accepting data in an empty one RX buffer * SubGhz: fix conflict * SubGhz: fix syntax errors * Cli: document string_move usage and its behavior * FuriHal: update subghz api and documentation. Subghz: move chat to subghz cli subcommand. * Subghz: update text in chat cli Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -113,7 +113,9 @@ void cli_prompt(Cli* cli) {
|
||||
}
|
||||
|
||||
void cli_reset(Cli* cli) {
|
||||
// cli->last_line is cleared and cli->line's buffer moved to cli->last_line
|
||||
string_move(cli->last_line, cli->line);
|
||||
// Reiniting cli->line
|
||||
string_init(cli->line);
|
||||
cli->cursor_position = 0;
|
||||
}
|
||||
@@ -129,7 +131,11 @@ static void cli_handle_backspace(Cli* cli) {
|
||||
string_reserve(temp, string_size(cli->line) - 1);
|
||||
string_set_strn(temp, string_get_cstr(cli->line), cli->cursor_position - 1);
|
||||
string_cat_str(temp, string_get_cstr(cli->line) + cli->cursor_position);
|
||||
|
||||
// cli->line is cleared and temp's buffer moved to cli->line
|
||||
string_move(cli->line, temp);
|
||||
// NO MEMORY LEAK, STOP REPORTING IT
|
||||
|
||||
cli->cursor_position--;
|
||||
} else {
|
||||
cli_putc(CliSymbolAsciiBell);
|
||||
@@ -332,7 +338,11 @@ void cli_process_input(Cli* cli) {
|
||||
string_set_strn(temp, string_get_cstr(cli->line), cli->cursor_position);
|
||||
string_push_back(temp, c);
|
||||
string_cat_str(temp, string_get_cstr(cli->line) + cli->cursor_position);
|
||||
|
||||
// cli->line is cleared and temp's buffer moved to cli->line
|
||||
string_move(cli->line, temp);
|
||||
// NO MEMORY LEAK, STOP REPORTING IT
|
||||
|
||||
// Print character in replace mode
|
||||
printf("\e[4h%c\e[4l", c);
|
||||
fflush(stdout);
|
||||
|
@@ -9,11 +9,12 @@
|
||||
#include <lib/subghz/subghz_keystore.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol_common.h>
|
||||
#include <lib/subghz/protocols/subghz_protocol_princeton.h>
|
||||
#include <lib/subghz/subghz_tx_rx_worker.h>
|
||||
|
||||
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
||||
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
||||
static void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
@@ -56,7 +57,7 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
||||
static void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
@@ -96,7 +97,7 @@ void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
||||
static void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t key = 0x0074BADE;
|
||||
size_t repeat = 10;
|
||||
@@ -187,7 +188,7 @@ static void subghz_cli_command_rx_text_callback(string_t text, void* context) {
|
||||
printf("%s", string_get_cstr(text));
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
static void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
@@ -260,7 +261,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_cli_command_print_usage() {
|
||||
static void subghz_cli_command_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("subghz <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
@@ -268,9 +269,10 @@ void subghz_cli_command_print_usage() {
|
||||
"\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");
|
||||
printf("\tchat <frequency:in Herz>\t - Chat with other Flippers\r\n");
|
||||
}
|
||||
|
||||
void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
|
||||
static void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
|
||||
uint8_t iv[16];
|
||||
|
||||
string_t source;
|
||||
@@ -312,7 +314,7 @@ void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
|
||||
string_clear(source);
|
||||
}
|
||||
|
||||
void subghz_cli_command_encrypt_raw(Cli* cli, string_t args) {
|
||||
static void subghz_cli_command_encrypt_raw(Cli* cli, string_t args) {
|
||||
uint8_t iv[16];
|
||||
|
||||
string_t source;
|
||||
@@ -348,7 +350,110 @@ void subghz_cli_command_encrypt_raw(Cli* cli, string_t args) {
|
||||
string_clear(source);
|
||||
}
|
||||
|
||||
void subghz_cli_command(Cli* cli, string_t args, void* context) {
|
||||
static void subghz_cli_command_chat(Cli* cli, string_t args) {
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
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_txrx", "<Frequency in HZ>", 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;
|
||||
}
|
||||
}
|
||||
if(!furi_hal_subghz_is_tx_allowed(frequency)) {
|
||||
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;
|
||||
}
|
||||
|
||||
SubGhzTxRxWorker* subghz_txrx = subghz_tx_rx_worker_alloc();
|
||||
subghz_tx_rx_worker_start(subghz_txrx, frequency);
|
||||
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
size_t message_max_len = 64;
|
||||
uint8_t message[64] = {0};
|
||||
string_t input;
|
||||
string_init(input);
|
||||
string_t name;
|
||||
string_init(name);
|
||||
char c;
|
||||
bool exit = false;
|
||||
|
||||
string_printf(name, "\033[0;33m%s\033[0m: ", furi_hal_version_get_name_ptr());
|
||||
string_set(input, name);
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
|
||||
while(!exit) {
|
||||
if(furi_hal_vcp_rx_with_timeout((uint8_t*)&c, 1, 0) == 1) {
|
||||
if(c == CliSymbolAsciiETX) {
|
||||
printf("\r\n");
|
||||
exit = true;
|
||||
break;
|
||||
} else if((c >= 0x20 && c < 0x7F) || (c >= 0x80 && c < 0xF0)) {
|
||||
putc(c, stdout);
|
||||
fflush(stdout);
|
||||
string_push_back(input, c);
|
||||
} else if(c == CliSymbolAsciiBackspace) {
|
||||
size_t len = string_size(input);
|
||||
if(len > string_size(name)) {
|
||||
string_set_strn(input, string_get_cstr(input), len - 1);
|
||||
printf("\r");
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("\r%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
}
|
||||
} else if(c == CliSymbolAsciiCR) {
|
||||
printf("\r\n");
|
||||
subghz_tx_rx_worker_write(
|
||||
subghz_txrx, (uint8_t*)string_get_cstr(input), strlen(string_get_cstr(input)));
|
||||
string_printf(input, "%s", string_get_cstr(name));
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
if(subghz_tx_rx_worker_available(subghz_txrx)) {
|
||||
memset(message, 0x00, message_max_len);
|
||||
subghz_tx_rx_worker_read(subghz_txrx, message, message_max_len);
|
||||
printf("\r");
|
||||
for(uint8_t i = 0; i < 80; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf("\r %s\r\n", message);
|
||||
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\r\nExit chat\r\n");
|
||||
string_clear(input);
|
||||
string_clear(name);
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
if(subghz_tx_rx_worker_is_running(subghz_txrx)) {
|
||||
subghz_tx_rx_worker_stop(subghz_txrx);
|
||||
subghz_tx_rx_worker_free(subghz_txrx);
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_cli_command(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
@@ -368,6 +473,11 @@ void subghz_cli_command(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "chat") == 0) {
|
||||
subghz_cli_command_chat(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
subghz_cli_command_print_usage();
|
||||
} while(false);
|
||||
|
||||
|
Reference in New Issue
Block a user