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:
Wed Aug 22 09:50:32 2018 -0700
Revision:
2:ea9245bb1c53
Parent:
1:0817a150122b
Child:
4:fa31fdf4ec8d
add LoRa CAD function

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 1:0817a150122b 8
Wayne Roberts 1:0817a150122b 9 typedef enum {
Wayne Roberts 1:0817a150122b 10 _READ_,
Wayne Roberts 1:0817a150122b 11 _WRITE_
Wayne Roberts 1:0817a150122b 12 } action_e;
Wayne Roberts 1:0817a150122b 13
Wayne Roberts 1:0817a150122b 14 typedef struct {
Wayne Roberts 1:0817a150122b 15 uint8_t row;
Wayne Roberts 1:0817a150122b 16 uint8_t col;
Wayne Roberts 1:0817a150122b 17 } pos_t;
Wayne Roberts 1:0817a150122b 18
Wayne Roberts 1:0817a150122b 19 #define _ITEM_VALUE 0xbb
Wayne Roberts 1:0817a150122b 20 #define _ITEM_DROPDOWN 0xaa
Wayne Roberts 1:0817a150122b 21 #define _ITEM_BUTTON 0xcc
Wayne Roberts 1:0817a150122b 22 #define _ITEM_TOGGLE 0xdd
Wayne Roberts 1:0817a150122b 23
Wayne Roberts 1:0817a150122b 24 typedef enum {
Wayne Roberts 1:0817a150122b 25 MENUMODE_NONE = 0,
Wayne Roberts 1:0817a150122b 26 MENUMODE_ENTRY,
Wayne Roberts 1:0817a150122b 27 MENUMODE_DROPDOWN,
Wayne Roberts 1:0817a150122b 28 MENUMODE_REDRAW,
Wayne Roberts 1:0817a150122b 29 MENUMODE_REINIT_MENU,
Wayne Roberts 1:0817a150122b 30 } menuMode_e;
Wayne Roberts 1:0817a150122b 31
Wayne Roberts 1:0817a150122b 32 typedef struct {
Wayne Roberts 1:0817a150122b 33 uint8_t itemType;
Wayne Roberts 1:0817a150122b 34
Wayne Roberts 1:0817a150122b 35 const char* const * printed_strs; // displayed values index from read callback return
Wayne Roberts 1:0817a150122b 36 const char* const * selectable_strs; // choices
Wayne Roberts 1:0817a150122b 37
Wayne Roberts 1:0817a150122b 38 unsigned (*const read)(bool forWriting);
Wayne Roberts 1:0817a150122b 39 menuMode_e (*const write)(unsigned);
Wayne Roberts 1:0817a150122b 40 } dropdown_item_t;
Wayne Roberts 1:0817a150122b 41
Wayne Roberts 1:0817a150122b 42 typedef struct {
Wayne Roberts 1:0817a150122b 43 uint8_t itemType;
Wayne Roberts 1:0817a150122b 44
Wayne Roberts 1:0817a150122b 45 unsigned width; // num columns printed
Wayne Roberts 1:0817a150122b 46
Wayne Roberts 1:0817a150122b 47 void (*const print)(void);
Wayne Roberts 1:0817a150122b 48 bool (*const write)(const char*); // NULL for read-only. return true: redraw menu
Wayne Roberts 1:0817a150122b 49 } value_item_t;
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 label;
Wayne Roberts 1:0817a150122b 55 void (*const push)(void);
Wayne Roberts 1:0817a150122b 56 } button_item_t;
Wayne Roberts 1:0817a150122b 57
Wayne Roberts 1:0817a150122b 58 typedef struct {
Wayne Roberts 1:0817a150122b 59 uint8_t itemType;
Wayne Roberts 1:0817a150122b 60
Wayne Roberts 1:0817a150122b 61 const char * const label0;
Wayne Roberts 1:0817a150122b 62 const char * const label1;
Wayne Roberts 1:0817a150122b 63 bool (*const read)(void);
Wayne Roberts 1:0817a150122b 64 bool (*const push)(void);
Wayne Roberts 1:0817a150122b 65 } toggle_item_t;
Wayne Roberts 1:0817a150122b 66
Wayne Roberts 1:0817a150122b 67 #define FLAG_MSGTYPE_ALL 0x07
Wayne Roberts 1:0817a150122b 68 #define FLAG_MSGTYPE_PKT 0x01
Wayne Roberts 1:0817a150122b 69 #define FLAG_MSGTYPE_PER 0x02
Wayne Roberts 1:0817a150122b 70 #define FLAG_MSGTYPE_PING 0x04
Wayne Roberts 1:0817a150122b 71
Wayne Roberts 1:0817a150122b 72 typedef struct {
Wayne Roberts 1:0817a150122b 73 pos_t pos; // on screen position, both row & col with 1 starting value
Wayne Roberts 1:0817a150122b 74 const char* const label;
Wayne Roberts 1:0817a150122b 75
Wayne Roberts 1:0817a150122b 76 const void* const itemPtr;
Wayne Roberts 1:0817a150122b 77
Wayne Roberts 1:0817a150122b 78 uint8_t flags;
Wayne Roberts 1:0817a150122b 79
Wayne Roberts 1:0817a150122b 80 const void* refreshReadItem;
Wayne Roberts 1:0817a150122b 81 } menu_t;
Wayne Roberts 1:0817a150122b 82 #define FIRST_CHIP_MENU_ROW 3
Wayne Roberts 1:0817a150122b 83
Wayne Roberts 1:0817a150122b 84
Wayne Roberts 1:0817a150122b 85 typedef struct {
Wayne Roberts 1:0817a150122b 86 menuMode_e mode;
Wayne Roberts 1:0817a150122b 87 uint8_t sel_idx;
Wayne Roberts 1:0817a150122b 88 const menu_t* sm;
Wayne Roberts 1:0817a150122b 89 uint8_t dropdown_col;
Wayne Roberts 1:0817a150122b 90 } menuState_t;
Wayne Roberts 1:0817a150122b 91
Wayne Roberts 1:0817a150122b 92 extern menuState_t menuState;
Wayne Roberts 1:0817a150122b 93 #define MAX_MENU_COLUMNS 6
Wayne Roberts 1:0817a150122b 94 extern menu_t* menu[][MAX_MENU_COLUMNS];
Wayne Roberts 1:0817a150122b 95 extern int8_t StopMenuCols[];
Wayne Roberts 1:0817a150122b 96
Wayne Roberts 1:0817a150122b 97 extern uint8_t entry_buf_idx;
Wayne Roberts 1:0817a150122b 98 extern char entry_buf[];
Wayne Roberts 1:0817a150122b 99
Wayne Roberts 1:0817a150122b 100 void log_printf(const char* format, ...);
Wayne Roberts 1:0817a150122b 101
Wayne Roberts 1:0817a150122b 102 typedef struct
Wayne Roberts 1:0817a150122b 103 {
Wayne Roberts 1:0817a150122b 104 void (*const TxDone_botHalf)(void); // read irqAt for timestamp of interrupt
Wayne Roberts 1:0817a150122b 105 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 106 } RadioEvents_t;
Wayne Roberts 1:0817a150122b 107
Wayne Roberts 1:0817a150122b 108 class Radio {
Wayne Roberts 1:0817a150122b 109 public:
Wayne Roberts 1:0817a150122b 110 static const char* const chipNum_str;
Wayne Roberts 1:0817a150122b 111
Wayne Roberts 1:0817a150122b 112 static void boardInit(const RadioEvents_t* e);
Wayne Roberts 1:0817a150122b 113 static void hw_reset(void);
Wayne Roberts 1:0817a150122b 114 static void clearIrqFlags(void);
Wayne Roberts 1:0817a150122b 115 static void readChip(void);
Wayne Roberts 1:0817a150122b 116 static void set_tx_dbm(int8_t dbm);
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 1:0817a150122b 174 private:
Wayne Roberts 1:0817a150122b 175 static const RadioEvents_t* RadioEvents;
Wayne Roberts 1:0817a150122b 176
Wayne Roberts 1:0817a150122b 177 static void txDoneBottom(void);
Wayne Roberts 1:0817a150122b 178
Wayne Roberts 1:0817a150122b 179 static const menu_t lora_menu[];
Wayne Roberts 1:0817a150122b 180
Wayne Roberts 1:0817a150122b 181 static LowPowerTimer lpt;
Wayne Roberts 1:0817a150122b 182
Wayne Roberts 1:0817a150122b 183 #if defined(SX128x_H)
Wayne Roberts 1:0817a150122b 184 #include "radio_sx128x_private.h"
Wayne Roberts 1:0817a150122b 185 #elif defined(SX127x_H)
Wayne Roberts 1:0817a150122b 186 #include "radio_sx127x_private.h"
Wayne Roberts 1:0817a150122b 187 #elif defined(SX126x_H)
Wayne Roberts 1:0817a150122b 188 #include "radio_sx126x_private.h"
Wayne Roberts 1:0817a150122b 189 #endif
Wayne Roberts 1:0817a150122b 190 };
Wayne Roberts 1:0817a150122b 191
Wayne Roberts 1:0817a150122b 192 extern RawSerial pc;
Wayne Roberts 1:0817a150122b 193