diff options
author | xengineering <me@xengineering.eu> | 2024-03-20 21:05:21 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-03-20 21:05:21 +0100 |
commit | f64a1bd5ea68563f52e834cd9de7f28a47d7c036 (patch) | |
tree | 6c639d7a82822868072a307e707a8febc5251f89 | |
parent | 14ae2e7d28d2d3f39a7067f7111257f119eef3e1 (diff) | |
download | radio-gateway-tx.tar radio-gateway-tx.tar.zst radio-gateway-tx.zip |
WIP: Unknowntx
-rw-r--r-- | src/main.c | 39 |
1 files changed, 27 insertions, 12 deletions
@@ -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; } |