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:
Wayne Roberts
Date:
Thu Apr 04 11:14:05 2019 -0700
Revision:
7:ea73b63b9eb1
Parent:
4:fa31fdf4ec8d
Child:
9:295e37c38fb3
remove unused set_tx_dbm() in sx127x arduino form-factor

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