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.

Committer:
dudmuck
Date:
Thu Sep 16 21:57:23 2021 +0000
Revision:
14:14b9e1c08bfc
Parent:
13:8ce61a1897ab
BufferedSerial flush printf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 1:0817a150122b 1 #include "sx12xx.h"
Wayne Roberts 1:0817a150122b 2
Wayne Roberts 1:0817a150122b 3 #ifdef SX127x_H
Wayne Roberts 1:0817a150122b 4 #include "sx127x_lora.h"
Wayne Roberts 1:0817a150122b 5 #include "sx127x_fsk.h"
Wayne Roberts 1:0817a150122b 6 #endif /* SX127x_H */
Wayne Roberts 1:0817a150122b 7
Wayne Roberts 9:295e37c38fb3 8 #define FIRST_CHIP_MENU_ROW 3
Wayne Roberts 9:295e37c38fb3 9 #define LAST_CHIP_MENU_ROW (MAX_MENU_ROWS-5)
Wayne Roberts 9:295e37c38fb3 10
Wayne Roberts 9:295e37c38fb3 11 #if defined(SX128x_H)
Wayne Roberts 9:295e37c38fb3 12 #define MAX_MENU_ROWS 16
Wayne Roberts 9:295e37c38fb3 13 #define MAX_MENU_COLUMNS 6
Wayne Roberts 9:295e37c38fb3 14 #elif defined(SX127x_H)
Wayne Roberts 9:295e37c38fb3 15 #define MAX_MENU_ROWS 16
Wayne Roberts 9:295e37c38fb3 16 #define MAX_MENU_COLUMNS 6
Wayne Roberts 9:295e37c38fb3 17 #elif defined(SX126x_H)
Wayne Roberts 9:295e37c38fb3 18 //#define MEMSCAN
Wayne Roberts 9:295e37c38fb3 19 #define MAX_MENU_ROWS 17
Wayne Roberts 9:295e37c38fb3 20 #define MAX_MENU_COLUMNS 6
Wayne Roberts 9:295e37c38fb3 21 #elif defined(SX1265_H)
Wayne Roberts 9:295e37c38fb3 22 #define MAX_MENU_ROWS 23
Wayne Roberts 9:295e37c38fb3 23 #define MAX_MENU_COLUMNS 14
Wayne Roberts 9:295e37c38fb3 24 #endif
Wayne Roberts 9:295e37c38fb3 25
Wayne Roberts 4:fa31fdf4ec8d 26 #define PA_OFF_DBM -127
Wayne Roberts 1:0817a150122b 27
Wayne Roberts 1:0817a150122b 28 typedef enum {
Wayne Roberts 1:0817a150122b 29 _READ_,
Wayne Roberts 1:0817a150122b 30 _WRITE_
Wayne Roberts 1:0817a150122b 31 } action_e;
Wayne Roberts 1:0817a150122b 32
Wayne Roberts 1:0817a150122b 33 typedef struct {
Wayne Roberts 1:0817a150122b 34 uint8_t row;
Wayne Roberts 1:0817a150122b 35 uint8_t col;
Wayne Roberts 1:0817a150122b 36 } pos_t;
Wayne Roberts 1:0817a150122b 37
Wayne Roberts 1:0817a150122b 38 #define _ITEM_VALUE 0xbb
Wayne Roberts 1:0817a150122b 39 #define _ITEM_DROPDOWN 0xaa
Wayne Roberts 1:0817a150122b 40 #define _ITEM_BUTTON 0xcc
Wayne Roberts 1:0817a150122b 41 #define _ITEM_TOGGLE 0xdd
Wayne Roberts 1:0817a150122b 42
Wayne Roberts 1:0817a150122b 43 typedef enum {
Wayne Roberts 1:0817a150122b 44 MENUMODE_NONE = 0,
Wayne Roberts 1:0817a150122b 45 MENUMODE_ENTRY,
Wayne Roberts 1:0817a150122b 46 MENUMODE_DROPDOWN,
Wayne Roberts 1:0817a150122b 47 MENUMODE_REDRAW,
Wayne Roberts 1:0817a150122b 48 MENUMODE_REINIT_MENU,
Wayne Roberts 1:0817a150122b 49 } menuMode_e;
Wayne Roberts 1:0817a150122b 50
Wayne Roberts 1:0817a150122b 51 typedef struct {
Wayne Roberts 1:0817a150122b 52 uint8_t itemType;
Wayne Roberts 1:0817a150122b 53
Wayne Roberts 1:0817a150122b 54 const char* const * printed_strs; // displayed values index from read callback return
Wayne Roberts 1:0817a150122b 55 const char* const * selectable_strs; // choices
Wayne Roberts 1:0817a150122b 56
Wayne Roberts 1:0817a150122b 57 unsigned (*const read)(bool forWriting);
Wayne Roberts 1:0817a150122b 58 menuMode_e (*const write)(unsigned);
Wayne Roberts 1:0817a150122b 59 } dropdown_item_t;
Wayne Roberts 1:0817a150122b 60
Wayne Roberts 1:0817a150122b 61 typedef struct {
Wayne Roberts 1:0817a150122b 62 uint8_t itemType;
Wayne Roberts 1:0817a150122b 63
Wayne Roberts 1:0817a150122b 64 unsigned width; // num columns printed
Wayne Roberts 1:0817a150122b 65
Wayne Roberts 1:0817a150122b 66 void (*const print)(void);
Wayne Roberts 1:0817a150122b 67 bool (*const write)(const char*); // NULL for read-only. return true: redraw menu
Wayne Roberts 1:0817a150122b 68 } value_item_t;
Wayne Roberts 1:0817a150122b 69
Wayne Roberts 1:0817a150122b 70 typedef struct {
Wayne Roberts 1:0817a150122b 71 uint8_t itemType;
Wayne Roberts 1:0817a150122b 72
Wayne Roberts 1:0817a150122b 73 const char * const label;
Wayne Roberts 1:0817a150122b 74 void (*const push)(void);
Wayne Roberts 1:0817a150122b 75 } button_item_t;
Wayne Roberts 1:0817a150122b 76
Wayne Roberts 1:0817a150122b 77 typedef struct {
Wayne Roberts 1:0817a150122b 78 uint8_t itemType;
Wayne Roberts 1:0817a150122b 79
Wayne Roberts 1:0817a150122b 80 const char * const label0;
Wayne Roberts 1:0817a150122b 81 const char * const label1;
Wayne Roberts 1:0817a150122b 82 bool (*const read)(void);
Wayne Roberts 1:0817a150122b 83 bool (*const push)(void);
Wayne Roberts 1:0817a150122b 84 } toggle_item_t;
Wayne Roberts 1:0817a150122b 85
Wayne Roberts 1:0817a150122b 86 #define FLAG_MSGTYPE_ALL 0x07
Wayne Roberts 1:0817a150122b 87 #define FLAG_MSGTYPE_PKT 0x01
Wayne Roberts 1:0817a150122b 88 #define FLAG_MSGTYPE_PER 0x02
Wayne Roberts 1:0817a150122b 89 #define FLAG_MSGTYPE_PING 0x04
Wayne Roberts 1:0817a150122b 90
Wayne Roberts 1:0817a150122b 91 typedef struct {
Wayne Roberts 1:0817a150122b 92 pos_t pos; // on screen position, both row & col with 1 starting value
Wayne Roberts 1:0817a150122b 93 const char* const label;
Wayne Roberts 1:0817a150122b 94
Wayne Roberts 1:0817a150122b 95 const void* const itemPtr;
Wayne Roberts 1:0817a150122b 96
Wayne Roberts 1:0817a150122b 97 uint8_t flags;
Wayne Roberts 1:0817a150122b 98
Wayne Roberts 9:295e37c38fb3 99 const void* refreshReadItem; /* other item to be read after activation */
Wayne Roberts 1:0817a150122b 100 } menu_t;
Wayne Roberts 1:0817a150122b 101
Wayne Roberts 1:0817a150122b 102
Wayne Roberts 1:0817a150122b 103 typedef struct {
Wayne Roberts 1:0817a150122b 104 menuMode_e mode;
Wayne Roberts 1:0817a150122b 105 uint8_t sel_idx;
Wayne Roberts 1:0817a150122b 106 const menu_t* sm;
Wayne Roberts 1:0817a150122b 107 uint8_t dropdown_col;
Wayne Roberts 1:0817a150122b 108 } menuState_t;
Wayne Roberts 1:0817a150122b 109
Wayne Roberts 1:0817a150122b 110 extern menuState_t menuState;
Wayne Roberts 1:0817a150122b 111 extern menu_t* menu[][MAX_MENU_COLUMNS];
Wayne Roberts 1:0817a150122b 112 extern int8_t StopMenuCols[];
Wayne Roberts 1:0817a150122b 113
Wayne Roberts 1:0817a150122b 114 extern uint8_t entry_buf_idx;
Wayne Roberts 1:0817a150122b 115 extern char entry_buf[];
Wayne Roberts 1:0817a150122b 116
Wayne Roberts 1:0817a150122b 117 void log_printf(const char* format, ...);
Wayne Roberts 1:0817a150122b 118
Wayne Roberts 9:295e37c38fb3 119 typedef struct {
Wayne Roberts 9:295e37c38fb3 120 unsigned hz;
Wayne Roberts 9:295e37c38fb3 121 uint8_t bwf;
Wayne Roberts 9:295e37c38fb3 122 } rxbw_t;
Wayne Roberts 9:295e37c38fb3 123
Wayne Roberts 1:0817a150122b 124 typedef struct
Wayne Roberts 1:0817a150122b 125 {
Wayne Roberts 1:0817a150122b 126 void (*const TxDone_botHalf)(void); // read irqAt for timestamp of interrupt
Wayne Roberts 1:0817a150122b 127 void (*const RxDone)(uint8_t size, float rssi, float snr); // read radio.rx_buf for payload, irqAt for timestamp of interrupt
Wayne Roberts 1:0817a150122b 128 } RadioEvents_t;
Wayne Roberts 1:0817a150122b 129
Wayne Roberts 9:295e37c38fb3 130 void printRxPkt(uint8_t size);
Wayne Roberts 9:295e37c38fb3 131
Wayne Roberts 1:0817a150122b 132 class Radio {
Wayne Roberts 1:0817a150122b 133 public:
Wayne Roberts 1:0817a150122b 134 static const char* const chipNum_str;
Wayne Roberts 1:0817a150122b 135
Wayne Roberts 1:0817a150122b 136 static void boardInit(const RadioEvents_t* e);
Wayne Roberts 1:0817a150122b 137 static void hw_reset(void);
Wayne Roberts 1:0817a150122b 138 static void clearIrqFlags(void);
Wayne Roberts 1:0817a150122b 139 static void readChip(void);
Wayne Roberts 1:0817a150122b 140 static void tx_carrier(void);
Wayne Roberts 1:0817a150122b 141 static void tx_preamble(void);
Wayne Roberts 1:0817a150122b 142 static void txPkt(void);
Wayne Roberts 1:0817a150122b 143 static void Rx(void);
Wayne Roberts 1:0817a150122b 144 static void setFS(void);
Wayne Roberts 1:0817a150122b 145
Wayne Roberts 1:0817a150122b 146 static const value_item_t tx_dbm_item;
Wayne Roberts 1:0817a150122b 147
Wayne Roberts 1:0817a150122b 148 static const menu_t* get_modem_menu(void);
Wayne Roberts 1:0817a150122b 149 static const menu_t* get_modem_sub_menu(void);
Wayne Roberts 1:0817a150122b 150
Wayne Roberts 2:ea9245bb1c53 151 static unsigned pktType_read(bool);
Wayne Roberts 2:ea9245bb1c53 152 static menuMode_e pktType_write(unsigned);
Wayne Roberts 1:0817a150122b 153 static const char* const pktType_strs[];
Wayne Roberts 1:0817a150122b 154
Wayne Roberts 1:0817a150122b 155 static void tx_dbm_print(void);
Wayne Roberts 1:0817a150122b 156 static bool tx_dbm_write(const char*);
Wayne Roberts 1:0817a150122b 157
Wayne Roberts 2:ea9245bb1c53 158 static unsigned tx_ramp_read(bool);
Wayne Roberts 2:ea9245bb1c53 159 static menuMode_e tx_ramp_write(unsigned);
Wayne Roberts 1:0817a150122b 160 static const char* tx_ramp_strs[];
Wayne Roberts 1:0817a150122b 161
Wayne Roberts 1:0817a150122b 162 static const char* const opmode_status_strs[];
Wayne Roberts 1:0817a150122b 163 static const char* const opmode_select_strs[];
Wayne Roberts 2:ea9245bb1c53 164 static unsigned opmode_read(bool);
Wayne Roberts 2:ea9245bb1c53 165 static menuMode_e opmode_write(unsigned);
Wayne Roberts 1:0817a150122b 166
Wayne Roberts 1:0817a150122b 167 static uint8_t get_payload_length(void);
Wayne Roberts 1:0817a150122b 168 static void set_payload_length(uint8_t);
Wayne Roberts 1:0817a150122b 169
Wayne Roberts 1:0817a150122b 170 static void tx_payload_length_print(void);
Wayne Roberts 1:0817a150122b 171 static bool tx_payload_length_write(const char*);
Wayne Roberts 1:0817a150122b 172 #ifdef SX127x_H
Wayne Roberts 1:0817a150122b 173 static SX127x radio;
Wayne Roberts 1:0817a150122b 174 static SX127x_lora lora;
Wayne Roberts 1:0817a150122b 175 static SX127x_fsk fsk;
Wayne Roberts 1:0817a150122b 176 static void rfsw_callback(void);
Wayne Roberts 1:0817a150122b 177 static void ocp(uint8_t ma);
Wayne Roberts 1:0817a150122b 178 static InterruptIn dio0;
Wayne Roberts 1:0817a150122b 179 static InterruptIn dio1;
Wayne Roberts 1:0817a150122b 180 #elif defined(SX126x_H)
Wayne Roberts 1:0817a150122b 181 static SX126x radio;
Wayne Roberts 1:0817a150122b 182 static ModulationParams_t mpFSK, mpLORA;
Wayne Roberts 1:0817a150122b 183 static PacketParams_t ppFSK, ppLORA;
Wayne Roberts 1:0817a150122b 184 #elif defined(SX128x_H)
Wayne Roberts 1:0817a150122b 185 static SX128x radio;
Wayne Roberts 1:0817a150122b 186 static uint8_t tx_param_buf[];
Wayne Roberts 1:0817a150122b 187 static ModulationParams_t mpFLRC, mpBLE_GFSK, mpLORA;
Wayne Roberts 1:0817a150122b 188 static PacketParams_t ppGFSK, ppFLRC, ppLORA, ppBLE;
Wayne Roberts 9:295e37c38fb3 189 #elif defined(SX1265_H)
Wayne Roberts 9:295e37c38fb3 190 static SX1265 radio;
Wayne Roberts 9:295e37c38fb3 191 static uint8_t tx_param_buf[];
Wayne Roberts 9:295e37c38fb3 192 static uint8_t pa_config_buf[];
Wayne Roberts 9:295e37c38fb3 193 static irq_t memRegRead(uint32_t addr, uint16_t len_dwords, uint8_t *dest);
Wayne Roberts 9:295e37c38fb3 194 static uint32_t from_big_endian32(const uint8_t *in);
Wayne Roberts 9:295e37c38fb3 195 static void print_stat(stat_t stat);
Wayne Roberts 9:295e37c38fb3 196 static uint8_t gfsk_pp_buf[];
Wayne Roberts 9:295e37c38fb3 197 static uint8_t gfsk_mp_buf[];
Wayne Roberts 9:295e37c38fb3 198 static uint8_t lora_pp_buf[];
Wayne Roberts 9:295e37c38fb3 199 static uint8_t lora_mp_buf[];
Wayne Roberts 1:0817a150122b 200 #else
Wayne Roberts 1:0817a150122b 201 #error import radio driver library
Wayne Roberts 1:0817a150122b 202 #endif
Wayne Roberts 1:0817a150122b 203 static bool service(int8_t);
Wayne Roberts 1:0817a150122b 204 static const menu_t common_menu[];
Wayne Roberts 1:0817a150122b 205
Wayne Roberts 1:0817a150122b 206 static void test(void);
Wayne Roberts 1:0817a150122b 207
Wayne Roberts 4:fa31fdf4ec8d 208 static unsigned read_register(unsigned);
Wayne Roberts 4:fa31fdf4ec8d 209 static void write_register(unsigned, unsigned);
Wayne Roberts 4:fa31fdf4ec8d 210
Wayne Roberts 1:0817a150122b 211 private:
Wayne Roberts 1:0817a150122b 212 static const RadioEvents_t* RadioEvents;
Wayne Roberts 1:0817a150122b 213
Wayne Roberts 1:0817a150122b 214 static void txDoneBottom(void);
Wayne Roberts 9:295e37c38fb3 215 static void cadDone(bool);
Wayne Roberts 1:0817a150122b 216
Wayne Roberts 1:0817a150122b 217 static const menu_t lora_menu[];
Wayne Roberts 1:0817a150122b 218
Wayne Roberts 1:0817a150122b 219 static LowPowerTimer lpt;
Wayne Roberts 1:0817a150122b 220 #if defined(SX128x_H)
Wayne Roberts 1:0817a150122b 221 #include "radio_sx128x_private.h"
Wayne Roberts 1:0817a150122b 222 #elif defined(SX127x_H)
Wayne Roberts 1:0817a150122b 223 #include "radio_sx127x_private.h"
Wayne Roberts 1:0817a150122b 224 #elif defined(SX126x_H)
Wayne Roberts 1:0817a150122b 225 #include "radio_sx126x_private.h"
Wayne Roberts 9:295e37c38fb3 226 #elif defined(SX1265_H)
Wayne Roberts 9:295e37c38fb3 227 #include "radio_lr1110_private.h"
Wayne Roberts 1:0817a150122b 228 #endif
Wayne Roberts 1:0817a150122b 229 };
Wayne Roberts 1:0817a150122b 230