From 980bc6ab78c77af0f6353c339959ab3bbfd5a52d Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 10 Mar 2024 19:30:47 +0100 Subject: WIP: Implement LoRa TX via Zephyr shell TODO: Can only be TX or RX depending on async rx command --- src/main.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 511f9f4..48d6371 100644 --- a/src/main.c +++ b/src/main.c @@ -1,16 +1,36 @@ +#include #include #include #include +#include #include #define DEFAULT_RADIO_NODE DT_ALIAS(lora0) BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay), "Board has no LoRa modem"); +const struct device *const lora_dev = DEVICE_DT_GET(DEFAULT_RADIO_NODE); #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL #include LOG_MODULE_REGISTER(lora); +void lora_tx_cb(const struct shell *sh, size_t argc, char *argv[]) +{ + if (argc != 2) { + LOG_ERR("lora_tx requires exactly one argument"); + return; + } + + int ret = lora_send(lora_dev, argv[1], strlen(argv[1])); + if (ret < 0) { + LOG_ERR("LoRa send failed"); + return; + } + + LOG_INF("tx: %s", argv[1]); +} +SHELL_CMD_ARG_REGISTER(tx, NULL, "send via LoRa", lora_tx_cb, 2, 0); + void lora_rx_cb(const struct device *dev, uint8_t *data, uint16_t size, int16_t rssi, int8_t snr) { @@ -22,7 +42,6 @@ void lora_rx_cb(const struct device *dev, uint8_t *data, uint16_t size, int main(void) { - const struct device *const lora_dev = DEVICE_DT_GET(DEFAULT_RADIO_NODE); struct lora_modem_config config; int ret; @@ -38,8 +57,8 @@ int main(void) config.coding_rate = CR_4_5; config.iq_inverted = false; config.public_network = false; - config.tx_power = 14; - config.tx = false; + config.tx_power = 4; + config.tx = true; ret = lora_config(lora_dev, &config); if (ret < 0) { @@ -47,7 +66,7 @@ int main(void) return 0; } - lora_recv_async(lora_dev, lora_rx_cb); +// lora_recv_async(lora_dev, lora_rx_cb); k_sleep(K_FOREVER); return 0; } -- cgit v1.2.3-70-g09d2