Text menu driven ANSI/VT100 console test utility for LoRa transceivers

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
if you're using LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

This is VT100 text-based menu driven test program for SX12xx transceiver devices.
Serial console is divided into horizontally into top half and bottom half.
The bottom half serves as scrolling area to log activity.
The top half serves as menu, to configure the radio.
For all devices, the serial console operates at 115200 8N1, and requires terminal with ANSI-VT100 capability, such as putty/teraterm/minicom etc.
Use program only with keyboard up/down/left/right keys. Enter to change an item, or number for value item. Some items are single bit, requiring only enter key to toggle. Others with fixed choices give a drop-down menu.

Files at this revision

API Documentation at this revision

Comitter:
dudmuck
Date:
Mon Aug 05 20:07:16 2024 +0000
Parent:
14:14b9e1c08bfc
Commit message:
add reading of RSSI

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
radio.h Show annotated file Show diff for this revision Revisions of this file
radio_lr1110.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx126x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx127x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx128x.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 14b9e1c08bfc -r 703ca340d0fb main.cpp
--- a/main.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/main.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -3,6 +3,13 @@
 
 //#define MENU_DEBUG
 
+#ifdef TARGET_NUCLEO_L073RZ
+BufferedSerial logpc(PC_10, PC_11, 115200);
+#else
+    //#error log_uart_for_target
+#endif
+void logpc_printf(const char* format, ...);
+
 static BufferedSerial pc(USBTX, USBRX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 namespace mbed {
 	FileHandle *mbed_override_console(int fd) {
@@ -284,6 +291,12 @@
 }
 const button_item_t tx_preamble_item = { _ITEM_BUTTON, "TX_PREAMBLE", tx_preamble_push };
 
+void get_rssi_push()
+{
+    Radio::get_rssi();
+}
+const button_item_t get_rssi_item = { _ITEM_BUTTON, "GET_RSSI", get_rssi_push };
+
 const value_item_t sweep_start_item = { _ITEM_VALUE, 5, sweep_start_print, sweep_start_write};
 const value_item_t sweep_step_item = { _ITEM_VALUE, 5, sweep_step_print, sweep_step_write};
 const value_item_t sweep_stop_item = { _ITEM_VALUE, 5, sweep_stop_print, sweep_stop_write};
@@ -299,6 +312,7 @@
     { {LAST_CHIP_MENU_ROW+3, 10},                 NULL,            &rx_pkt_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+3, 20},                 NULL,        &tx_carrier_item, FLAG_MSGTYPE_PKT, &opmode_item },
     { {LAST_CHIP_MENU_ROW+3, 45},                 NULL,       &tx_preamble_item, FLAG_MSGTYPE_PKT, &opmode_item },
+    { {LAST_CHIP_MENU_ROW+3, 58},                 NULL,          &get_rssi_item, FLAG_MSGTYPE_PKT, &opmode_item },
     { {LAST_CHIP_MENU_ROW+4,  1},    "cf sweep start:",       &sweep_start_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+4, 28},              "step:",        &sweep_step_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+4, 45},              "stop:",        &sweep_stop_item, FLAG_MSGTYPE_PKT },
@@ -803,6 +817,7 @@
 
 void navigate_menu(uint8_t ch)
 {
+    //logpc_printf("navigate_menu %c\r\n", ch);
     read_menu_item(menu_table[curpos.row][curpos.tableCol], false);
 
     switch (ch) {
@@ -1415,6 +1430,8 @@
     curpos.tableCol = 0;
 
     tx_ipd_ms = 100;
+
+    logpc_printf("\r\nRESET\r\n");
     
     for (;;) {
         if (pc.readable()) {
@@ -1490,3 +1507,17 @@
     pc.sync();
 }
 
+void logpc_printf(const char* format, ...)  /* printing on 2nd uart */
+{
+    int len;
+    va_list arglist;
+
+    va_start(arglist, format);
+    len = vsprintf(strbuf, format, arglist);
+    va_end(arglist);
+
+    //logpc.write(strbuf, len);
+    
+    fflush(stdout);
+    pc.sync();
+}
diff -r 14b9e1c08bfc -r 703ca340d0fb radio.h
--- a/radio.h	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio.h	Mon Aug 05 20:07:16 2024 +0000
@@ -139,6 +139,7 @@
         static void readChip(void);
         static void tx_carrier(void);
         static void tx_preamble(void);
+        static void get_rssi(void);
         static void txPkt(void);
         static void Rx(void);
         static void setFS(void);
diff -r 14b9e1c08bfc -r 703ca340d0fb radio_lr1110.cpp
--- a/radio_lr1110.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_lr1110.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -488,6 +488,15 @@
     print_stat(stat);
 }
 
+void Radio::get_rssi()
+{
+    stat_t stat;
+    uint8_t buf;
+    stat.word = radio.xfer(OPCODE_GET_RSSI_INST, 0, 0, NULL);
+    stat.word = radio.xfer(0x0000, 0, 1, &buf); 
+    log_printf("-%0.1f dBm\r\n", buf/2.0);   
+}
+
 void Radio::print_stat(stat_t stat)
 {
     char out[96];
diff -r 14b9e1c08bfc -r 703ca340d0fb radio_sx126x.cpp
--- a/radio_sx126x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx126x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -328,6 +328,13 @@
     radio.xfer(OPCODE_SET_TX_PREAMBLE, 0, 0, NULL);
 }
 
+void Radio::get_rssi()
+{
+    uint8_t buf[3];
+    radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+}
+
 void Radio::txPkt()
 {
     uint8_t txlen = get_payload_length();
diff -r 14b9e1c08bfc -r 703ca340d0fb radio_sx127x.cpp
--- a/radio_sx127x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx127x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -181,6 +181,20 @@
     }
 }
 
+void Radio::get_rssi()
+{
+    //uint8_t buf[3];
+    //radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    //log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+    if (radio.RegOpMode.bits.LongRangeMode) {
+        log_printf("lora rssi %d dBm", lora.get_current_rssi());
+        //REG_LR_RSSIVALUE
+    } else {
+        uint8_t v = radio.read_reg(REG_FSK_RSSIVALUE);
+        log_printf("-%0.1f dBm\r\n", v/2.0);
+    }
+}
+
 bool Radio::service(int8_t statusRow)
 {
     bool ret = false;
@@ -697,7 +711,7 @@
 
 void Radio::fsk_ook_bps_print(void)
 {
-    printf("%lu", fsk.get_bitrate());
+    printf("%u", fsk.get_bitrate());
 }
 
 bool Radio::fsk_ook_bps_write(const char* txt)
@@ -714,7 +728,7 @@
 
 void Radio::gfsk_fdev_print(void)
 {
-    printf("%lu", fsk.get_tx_fdev_hz());
+    printf("%u", fsk.get_tx_fdev_hz());
 
 }
 
diff -r 14b9e1c08bfc -r 703ca340d0fb radio_sx128x.cpp
--- a/radio_sx128x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx128x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -561,6 +561,14 @@
     chipModeChange();
 }
 
+void Radio::get_rssi()
+{
+    uint8_t buf[3];
+    radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+}
+
+
 void Radio::rngTx()
 {
     IrqFlags_t irqEnable;