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:
Sun Nov 25 15:34:40 2018 -0800
Revision:
4:fa31fdf4ec8d
Parent:
2:ea9245bb1c53
Child:
7:ea73b63b9eb1
add PA-off and xtal trim

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 set_tx_dbm(int8_t dbm);
Wayne Roberts 1:0817a150122b 118 static void tx_carrier(void);
Wayne Roberts 1:0817a150122b 119 static void tx_preamble(void);
Wayne Roberts 1:0817a150122b 120 static void txPkt(void);
Wayne Roberts 1:0817a150122b 121 static void Rx(void);
Wayne Roberts 1:0817a150122b 122 static void setFS(void);
Wayne Roberts 1:0817a150122b 123
Wayne Roberts 1:0817a150122b 124 static const value_item_t tx_dbm_item;
Wayne Roberts 1:0817a150122b 125
Wayne Roberts 1:0817a150122b 126 static const menu_t* get_modem_menu(void);
Wayne Roberts 1:0817a150122b 127 static const menu_t* get_modem_sub_menu(void);
Wayne Roberts 1:0817a150122b 128
Wayne Roberts 2:ea9245bb1c53 129 static unsigned pktType_read(bool);
Wayne Roberts 2:ea9245bb1c53 130 static menuMode_e pktType_write(unsigned);
Wayne Roberts 1:0817a150122b 131 static const char* const pktType_strs[];
Wayne Roberts 1:0817a150122b 132
Wayne Roberts 1:0817a150122b 133 static void tx_dbm_print(void);
Wayne Roberts 1:0817a150122b 134 static bool tx_dbm_write(const char*);
Wayne Roberts 1:0817a150122b 135
Wayne Roberts 2:ea9245bb1c53 136 static unsigned tx_ramp_read(bool);
Wayne Roberts 2:ea9245bb1c53 137 static menuMode_e tx_ramp_write(unsigned);
Wayne Roberts 1:0817a150122b 138 static const char* tx_ramp_strs[];
Wayne Roberts 1:0817a150122b 139
Wayne Roberts 1:0817a150122b 140 static const char* const opmode_status_strs[];
Wayne Roberts 1:0817a150122b 141 static const char* const opmode_select_strs[];
Wayne Roberts 2:ea9245bb1c53 142 static unsigned opmode_read(bool);
Wayne Roberts 2:ea9245bb1c53 143 static menuMode_e opmode_write(unsigned);
Wayne Roberts 1:0817a150122b 144
Wayne Roberts 1:0817a150122b 145 static uint8_t get_payload_length(void);
Wayne Roberts 1:0817a150122b 146 static void set_payload_length(uint8_t);
Wayne Roberts 1:0817a150122b 147
Wayne Roberts 1:0817a150122b 148 static void tx_payload_length_print(void);
Wayne Roberts 1:0817a150122b 149 static bool tx_payload_length_write(const char*);
Wayne Roberts 1:0817a150122b 150 #ifdef SX127x_H
Wayne Roberts 1:0817a150122b 151 static SX127x radio;
Wayne Roberts 1:0817a150122b 152 static SX127x_lora lora;
Wayne Roberts 1:0817a150122b 153 static SX127x_fsk fsk;
Wayne Roberts 1:0817a150122b 154 static void rfsw_callback(void);
Wayne Roberts 1:0817a150122b 155 static void ocp(uint8_t ma);
Wayne Roberts 1:0817a150122b 156 static InterruptIn dio0;
Wayne Roberts 1:0817a150122b 157 static InterruptIn dio1;
Wayne Roberts 1:0817a150122b 158 #elif defined(SX126x_H)
Wayne Roberts 1:0817a150122b 159 static SX126x radio;
Wayne Roberts 1:0817a150122b 160 static ModulationParams_t mpFSK, mpLORA;
Wayne Roberts 1:0817a150122b 161 static PacketParams_t ppFSK, ppLORA;
Wayne Roberts 1:0817a150122b 162 #elif defined(SX128x_H)
Wayne Roberts 1:0817a150122b 163 static SX128x radio;
Wayne Roberts 1:0817a150122b 164 static uint8_t tx_param_buf[];
Wayne Roberts 1:0817a150122b 165 static ModulationParams_t mpFLRC, mpBLE_GFSK, mpLORA;
Wayne Roberts 1:0817a150122b 166 static PacketParams_t ppGFSK, ppFLRC, ppLORA, ppBLE;
Wayne Roberts 1:0817a150122b 167 #else
Wayne Roberts 1:0817a150122b 168 #error import radio driver library
Wayne Roberts 1:0817a150122b 169 #endif
Wayne Roberts 1:0817a150122b 170 static bool service(int8_t);
Wayne Roberts 1:0817a150122b 171 static const menu_t common_menu[];
Wayne Roberts 1:0817a150122b 172
Wayne Roberts 1:0817a150122b 173 static void test(void);
Wayne Roberts 1:0817a150122b 174
Wayne Roberts 4:fa31fdf4ec8d 175 static unsigned read_register(unsigned);
Wayne Roberts 4:fa31fdf4ec8d 176 static void write_register(unsigned, unsigned);
Wayne Roberts 4:fa31fdf4ec8d 177
Wayne Roberts 1:0817a150122b 178 private:
Wayne Roberts 1:0817a150122b 179 static const RadioEvents_t* RadioEvents;
Wayne Roberts 1:0817a150122b 180
Wayne Roberts 1:0817a150122b 181 static void txDoneBottom(void);
Wayne Roberts 1:0817a150122b 182
Wayne Roberts 1:0817a150122b 183 static const menu_t lora_menu[];
Wayne Roberts 1:0817a150122b 184
Wayne Roberts 1:0817a150122b 185 static LowPowerTimer lpt;
Wayne Roberts 1:0817a150122b 186
Wayne Roberts 1:0817a150122b 187 #if defined(SX128x_H)
Wayne Roberts 1:0817a150122b 188 #include "radio_sx128x_private.h"
Wayne Roberts 1:0817a150122b 189 #elif defined(SX127x_H)
Wayne Roberts 1:0817a150122b 190 #include "radio_sx127x_private.h"
Wayne Roberts 1:0817a150122b 191 #elif defined(SX126x_H)
Wayne Roberts 1:0817a150122b 192 #include "radio_sx126x_private.h"
Wayne Roberts 1:0817a150122b 193 #endif
Wayne Roberts 1:0817a150122b 194 };
Wayne Roberts 1:0817a150122b 195
Wayne Roberts 1:0817a150122b 196 extern RawSerial pc;
Wayne Roberts 1:0817a150122b 197