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.

Revision:
3:56fc764dee0a
Parent:
2:ea9245bb1c53
Child:
4:fa31fdf4ec8d
--- a/radio_sx126x.cpp	Wed Aug 22 09:50:32 2018 -0700
+++ b/radio_sx126x.cpp	Thu Nov 01 13:02:38 2018 -0700
@@ -45,6 +45,7 @@
 uint8_t Radio::pktType;
 uint8_t Radio::bw_idx;
 uint8_t Radio::cadParams[7];
+uint16_t Radio::ppg;
 
 const char* opModes[] = {
     "SLEEP    ", // 0
@@ -602,7 +603,7 @@
 
 const toggle_item_t Radio::deviceSel_item = { _ITEM_TOGGLE, "SX1262", "SX1261", deviceSel_read, deviceSel_push};
 
-static const char* paDutyCycles[] = {
+static const char* const paDutyCycles[] = {
     "0",
     "1",
     "2",
@@ -631,7 +632,7 @@
 
 const dropdown_item_t Radio::paDutyCycle_item = { _ITEM_DROPDOWN, paDutyCycles, paDutyCycles, paDutyCycle_read, paDutyCycle_write};
 
-static const char* hpMaxs[] = {
+static const char* const hpMaxs[] = {
     "0",
     "1",
     "2",
@@ -694,7 +695,7 @@
     LORA_BW_500
 };
 
-static const char* lora_bwstrs[] = {
+static const char* const lora_bwstrs[] = {
     " 7.81KHz", "10.42KHz", "15.63KHz",
     "20.83KHz", "31.25KHz", "41.67KHz",
     " 62.5KHz", "  125KHz", "  250KHz",
@@ -747,7 +748,7 @@
 
 const value_item_t Radio::lora_sf_item = { _ITEM_VALUE, 3, lora_sf_print, lora_sf_write };
 
-static const char* lora_crs[] = {
+static const char* const lora_crs[] = {
     "4/5   ",
     "4/6   ",
     "4/7   ",
@@ -877,6 +878,30 @@
 
 const toggle_item_t Radio::lora_inviq_item = { _ITEM_TOGGLE, "InvertIQ", NULL, lora_inviq_read, lora_inviq_push};
 
+void Radio::lora_ppg_print()
+{
+    uint8_t val;
+    ppg = radio.readReg(REG_ADDR_LORA_SYNC, 2);
+
+    val = (ppg >> 8) & 0xf0;
+    val |= (ppg & 0xf0) >> 4;
+    pc.printf("%02x", val);
+}
+
+bool Radio::lora_ppg_write(const char* txt)
+{
+    unsigned val;
+    if (sscanf(txt, "%x", &val) == 1) {
+        ppg &= 0x0707;
+        ppg |= (val & 0xf0) << 8;
+        ppg |= (val & 0x0f) << 4;
+        radio.writeReg(REG_ADDR_LORA_SYNC, ppg, 2);
+    }
+    return false;
+}
+
+const value_item_t Radio::lora_ppg_item = { _ITEM_VALUE, 4, lora_ppg_print, lora_ppg_write};
+
 void Radio::cad_push()
 {
     {
@@ -904,7 +929,7 @@
 
 const button_item_t Radio::lora_cad_item = { _ITEM_BUTTON, "CAD", cad_push };
 
-static const char* lora_cadsymbs[] = {
+static const char* const lora_cadsymbs[] = {
     " 1",
     " 2",
     " 4",
@@ -1022,6 +1047,7 @@
     { {FIRST_CHIP_MENU_ROW+2, 22},              NULL, &lora_headerType_item, FLAG_MSGTYPE_ALL },
     { {FIRST_CHIP_MENU_ROW+2, 32},              NULL, &lora_crcon_item, FLAG_MSGTYPE_ALL },
     { {FIRST_CHIP_MENU_ROW+2, 39},              NULL, &lora_inviq_item, FLAG_MSGTYPE_ALL },
+    { {FIRST_CHIP_MENU_ROW+2, 49},            "ppg:", &lora_ppg_item, FLAG_MSGTYPE_ALL },
 
     { {FIRST_CHIP_MENU_ROW+3,  1},          NULL,        &lora_cad_item, FLAG_MSGTYPE_ALL },
     { {FIRST_CHIP_MENU_ROW+3,  5},    "symbols:",   &lora_cadsymbs_item, FLAG_MSGTYPE_ALL },
@@ -1070,7 +1096,7 @@
 
 const value_item_t Radio::gfsk_bitrate_item = { _ITEM_VALUE, 8, gfsk_bitrate_print, gfsk_bitrate_write};
 
-static const char* gfsk_bts[] = {
+static const char* const gfsk_bts[] = {
     "off", // 0
     "0.3", // 1
     "0.5", // 2
@@ -1114,7 +1140,7 @@
     GFSK_RX_BW_467000
 };
 
-static const char* rxbw_str[] = {
+static const char* const rxbw_str[] = {
     "  4.8KHz", "  5.8KHz", "  7.3KHz", "  9.7KHz",
     " 11.7KHz", " 14.6KHz", " 19.5KHz", " 23.4KHz",
     " 29.3KHz", " 39.0KHz", " 46.9KHz", " 58.6KHz",
@@ -1189,7 +1215,7 @@
 
 const value_item_t Radio::gfsk_pblLen_item = { _ITEM_VALUE, 5, gfsk_pblLen_print, gfsk_pblLen_write};
 
-static const char* fsk_detlens[] = {
+static const char* const fsk_detlens[] = {
     " off  ",
     " 8bits",
     "16bits",
@@ -1307,7 +1333,7 @@
 };
 
 
-static const char* addrcomps[] = {
+static const char* const addrcomps[] = {
     "          off        ",
     "NodeAddress          ",
     "NodeAddress+broadcast",