diff options
author | xengineering <me@xengineering.eu> | 2024-03-10 19:30:47 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-03-10 19:45:11 +0100 |
commit | 980bc6ab78c77af0f6353c339959ab3bbfd5a52d (patch) | |
tree | ab74c0855c4631554e624d8274b6b04acca22dfa | |
parent | afa66ca4430deecb98a1283233fd95d4f21dce6c (diff) | |
download | radio-gateway-980bc6ab78c77af0f6353c339959ab3bbfd5a52d.tar radio-gateway-980bc6ab78c77af0f6353c339959ab3bbfd5a52d.tar.zst radio-gateway-980bc6ab78c77af0f6353c339959ab3bbfd5a52d.zip |
WIP: Implement LoRa TX via Zephyr shell
TODO: Can only be TX or RX depending on async rx command
-rw-r--r-- | src/main.c | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -1,16 +1,36 @@ +#include <string.h> #include <zephyr/device.h> #include <zephyr/drivers/lora.h> #include <zephyr/kernel.h> +#include <zephyr/shell/shell.h> #include <zephyr/sys/util.h> #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 <zephyr/logging/log.h> 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; } |