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:
Thu Sep 16 21:57:23 2021 +0000
Parent:
13:8ce61a1897ab
Commit message:
BufferedSerial flush printf

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
radio_ff_arduino_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
--- a/main.cpp	Tue Aug 24 16:21:28 2021 -0700
+++ b/main.cpp	Thu Sep 16 21:57:23 2021 +0000
@@ -3,14 +3,10 @@
 
 //#define MENU_DEBUG
 
-BufferedSerial *_pc;
-namespace mbed
-{
-	FileHandle *mbed_override_console(int fd)
-	{
-	    static BufferedSerial console(USBTX, USBRX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
-        _pc = &console;
-		return &console;
+static BufferedSerial pc(USBTX, USBRX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
+namespace mbed {
+	FileHandle *mbed_override_console(int fd) {
+		return &pc;
 	}
 }
 
@@ -689,6 +685,7 @@
                 printf("\e[0m");
         }
     }
+    
 } // ..read_menu_item()
 
 void draw_menu()
@@ -703,7 +700,9 @@
     } // ..table row iterator
 
     read_menu_item(menu_table[curpos.row][curpos.tableCol], true);
-
+    
+	fflush(stdout);
+	pc.sync();    
 } // ..draw_menu()
 
 typedef struct {
@@ -749,8 +748,9 @@
 #endif /* MENU_DEBUG */
     }
 #ifdef MENU_DEBUG
+	char ch;
     printf("hit key:");
-    _pc->getc();
+    pc.read(&ch, 1);
 #endif /* MENU_DEBUG */
 
 }
@@ -1169,10 +1169,9 @@
 {
     char serial_write_buf[4];
     unsigned char serial_write_buf_idx = 0;
-    //char ch = pc.getc();
     char ch;
-    _pc->read(&ch, 1);
-
+	pc.read(&ch, 1);
+	
     switch (uart_rx_state) {
         case URX_STATE_NONE:
             if (ch == 0x1b) {
@@ -1248,10 +1247,14 @@
             //printf("\e[18;1f");  // set (force) cursor to row;column
             break;
     } // ..switch (uart_rx_state)
+    
+    fflush(stdout);
 
     if (serial_write_buf_idx > 0) {
-        _pc->write(serial_write_buf, serial_write_buf_idx);
+        pc.write(serial_write_buf, serial_write_buf_idx);
     }
+    
+    pc.sync();
 }
 
 void txDone()
@@ -1412,9 +1415,9 @@
     curpos.tableCol = 0;
 
     tx_ipd_ms = 100;
-
+    
     for (;;) {
-        if (_pc->readable()) {
+        if (pc.readable()) {
             serial_callback();
         }
 
@@ -1482,5 +1485,8 @@
     va_end(arglist);
 
     printf("%s", strbuf);
+    
+    fflush(stdout);
+    pc.sync();
 }
 
--- a/radio_ff_arduino_sx127x.cpp	Tue Aug 24 16:21:28 2021 -0700
+++ b/radio_ff_arduino_sx127x.cpp	Thu Sep 16 21:57:23 2021 +0000
@@ -1,5 +1,5 @@
 /* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */
-#if defined(TARGET_FF_ARDUINO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
+#if defined(TARGET_FF_ARDUINO) || defined(TARGET_FF_ARDUINO_UNO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
 #include "radio.h"
 #ifdef SX127x_H 
 
@@ -85,7 +85,7 @@
     } else {
         dbm = PA_OFF_DBM;
     }
-    pc.printf("%d", dbm);
+    printf("%d", dbm);
 }
 
 bool Radio::tx_dbm_write(const char* str)
--- a/radio_sx128x.cpp	Tue Aug 24 16:21:28 2021 -0700
+++ b/radio_sx128x.cpp	Thu Sep 16 21:57:23 2021 +0000
@@ -2,8 +2,9 @@
 #ifdef SX128x_H 
 
 #include <float.h>
+using namespace std::chrono;
 
-#ifdef TARGET_FF_ARDUINO    /* pins of SX126xDVK1xAS board */
+#if defined(TARGET_FF_ARDUINO) || defined(TARGET_FF_ARDUINO_UNO)    /* pins of SX126xDVK1xAS board */
     #define NRST_PIN        A0
     SPI spi(D11, D12, D13); // mosi, miso, sclk
     //           spi, nss, busy, dio1
@@ -1890,12 +1891,13 @@
     static IrqFlags_t prevIrqFlags;
     IrqFlags_t irqFlags;
     bool ret = false;
-    static us_timestamp_t prev_now;
-    us_timestamp_t now = lpt.read_us();
+    static long prev_now_ms;
+    auto now_tp = time_point_cast<milliseconds>(Kernel::Clock::now());
+    long now_ms = now_tp.time_since_epoch().count();    
 
     radio.service();
 
-    if (statusRow > 0 && now-prev_now > 50000) {
+    if (statusRow > 0 && now_ms-prev_now_ms > 50) {
         int cmp = 0;
         pktStatus_t pktStatus;
         uint8_t buf[6];
@@ -2012,7 +2014,7 @@
             }
         } // ..if change
 
-        prev_now = now;
+        prev_now_ms = now_ms;
     }
 
     return ret;