From f64a1bd5ea68563f52e834cd9de7f28a47d7c036 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 20 Mar 2024 21:05:21 +0100 Subject: WIP: Unknown --- src/main.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index 7a35245..0280998 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,15 @@ static struct lora_modem_config modem_config = { .tx = true }; +void lora_rx_cb(const struct device *dev, uint8_t *data, uint16_t size, + int16_t rssi, int8_t snr) +{ + ARG_UNUSED(dev); + ARG_UNUSED(size); + + LOG_INF("rx: %s (RSSI: %d dBm, SNR: %d dBm)", data, rssi, snr); +} + void lora_tx_cb(const struct shell *sh, size_t argc, char *argv[]) { if (argc != 2) { @@ -33,24 +42,30 @@ void lora_tx_cb(const struct shell *sh, size_t argc, char *argv[]) return; } - int ret = lora_send(lora_dev, argv[1], strlen(argv[1])); + modem_config.tx = true; + int ret = lora_config(lora_dev, &modem_config); if (ret < 0) { - LOG_ERR("LoRa send failed"); + shell_error(sh, "LoRa config to TX mode failed"); return; } + lora_recv_async(lora_dev, NULL); + 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) -{ - ARG_UNUSED(dev); - ARG_UNUSED(size); - LOG_INF("rx: %s (RSSI: %d dBm, SNR: %d dBm)", data, rssi, snr); + modem_config.tx = false; + ret = lora_config(lora_dev, &modem_config); + if (ret < 0) { + shell_error(sh, "LoRa config to RX mode failed"); + return; + } + lora_recv_async(lora_dev, lora_rx_cb); } +SHELL_CMD_ARG_REGISTER(tx, NULL, "send via LoRa", lora_tx_cb, 2, 0); int main(void) { @@ -65,7 +80,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