A very easy to understand LoRaWAN-node code.
Dependencies: LoRaWAN-lib SX1272Lib X_NUCLEO_IKS01A1 mbed
Important parameters:
• In comissioning.h: DevEUI, AppEUI, AppKEY, DevADR, NwksKEY, AppsKEY, OTAA and public network. Frequency and channel block to use, confirmed or unconfirmed messages, app port, app data size and OTAA and Tx duty cycles.
• In LoRaMac.h: Maximum payload and MAC commands length, receive delays, max FCNT, adr ack limit, timeout and delay, max ack retries, rssi threshold and sync words.
• In LoRaMac.cpp: Maximum payload, MAC commands and FRMpayload length.
• In LoRaMac-board.h: Tx power, data rates and band settings.
NOTE: Please refer to LoRaWAN regional parameters (page 12 for US band) to know which parameters you can modify.
Code/vt100.h@0:60ff878b27b8, 2018-04-03 (annotated)
- Committer:
- dgabino
- Date:
- Tue Apr 03 17:09:34 2018 +0000
- Revision:
- 0:60ff878b27b8
A simpler way to customize your LoRaWAN payload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dgabino | 0:60ff878b27b8 | 1 | /* |
dgabino | 0:60ff878b27b8 | 2 | / _____) _ | | |
dgabino | 0:60ff878b27b8 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
dgabino | 0:60ff878b27b8 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
dgabino | 0:60ff878b27b8 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
dgabino | 0:60ff878b27b8 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
dgabino | 0:60ff878b27b8 | 7 | (C)2015 Semtech |
dgabino | 0:60ff878b27b8 | 8 | |
dgabino | 0:60ff878b27b8 | 9 | Description: VT100 terminal support class |
dgabino | 0:60ff878b27b8 | 10 | |
dgabino | 0:60ff878b27b8 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
dgabino | 0:60ff878b27b8 | 12 | |
dgabino | 0:60ff878b27b8 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
dgabino | 0:60ff878b27b8 | 14 | */ |
dgabino | 0:60ff878b27b8 | 15 | #ifndef __VT100_H__ |
dgabino | 0:60ff878b27b8 | 16 | #define __VT100_H__ |
dgabino | 0:60ff878b27b8 | 17 | |
dgabino | 0:60ff878b27b8 | 18 | #ifndef STRING_STACK_LIMIT |
dgabino | 0:60ff878b27b8 | 19 | #define STRING_STACK_LIMIT 120 |
dgabino | 0:60ff878b27b8 | 20 | #endif |
dgabino | 0:60ff878b27b8 | 21 | |
dgabino | 0:60ff878b27b8 | 22 | /** |
dgabino | 0:60ff878b27b8 | 23 | * Implements VT100 terminal commands support. |
dgabino | 0:60ff878b27b8 | 24 | * Implments also the same behaviour has RawSerial class. The only difference |
dgabino | 0:60ff878b27b8 | 25 | * is located in putc fucntion where writeable check is made befor sending the character. |
dgabino | 0:60ff878b27b8 | 26 | */ |
dgabino | 0:60ff878b27b8 | 27 | class VT100 : public SerialBase |
dgabino | 0:60ff878b27b8 | 28 | { |
dgabino | 0:60ff878b27b8 | 29 | public: |
dgabino | 0:60ff878b27b8 | 30 | enum TextAttributes |
dgabino | 0:60ff878b27b8 | 31 | { |
dgabino | 0:60ff878b27b8 | 32 | ATTR_OFF = 0, |
dgabino | 0:60ff878b27b8 | 33 | BOLD = 1, |
dgabino | 0:60ff878b27b8 | 34 | USCORE = 4, |
dgabino | 0:60ff878b27b8 | 35 | BLINK = 5, |
dgabino | 0:60ff878b27b8 | 36 | REVERSE = 7, |
dgabino | 0:60ff878b27b8 | 37 | BOLD_OFF = 21, |
dgabino | 0:60ff878b27b8 | 38 | USCORE_OFF = 24, |
dgabino | 0:60ff878b27b8 | 39 | BLINK_OFF = 25, |
dgabino | 0:60ff878b27b8 | 40 | REVERSE_OFF = 27, |
dgabino | 0:60ff878b27b8 | 41 | }; |
dgabino | 0:60ff878b27b8 | 42 | |
dgabino | 0:60ff878b27b8 | 43 | enum Colors |
dgabino | 0:60ff878b27b8 | 44 | { |
dgabino | 0:60ff878b27b8 | 45 | BLACK = 0, |
dgabino | 0:60ff878b27b8 | 46 | RED = 1, |
dgabino | 0:60ff878b27b8 | 47 | GREEN = 2, |
dgabino | 0:60ff878b27b8 | 48 | BROWN = 3, |
dgabino | 0:60ff878b27b8 | 49 | BLUE = 4, |
dgabino | 0:60ff878b27b8 | 50 | MAGENTA = 5, |
dgabino | 0:60ff878b27b8 | 51 | CYAN = 6, |
dgabino | 0:60ff878b27b8 | 52 | WHITE = 7, |
dgabino | 0:60ff878b27b8 | 53 | }; |
dgabino | 0:60ff878b27b8 | 54 | |
dgabino | 0:60ff878b27b8 | 55 | VT100( PinName tx, PinName rx ): SerialBase( tx, rx ) |
dgabino | 0:60ff878b27b8 | 56 | { |
dgabino | 0:60ff878b27b8 | 57 | this->baud( 115200 ); |
dgabino | 0:60ff878b27b8 | 58 | // initializes terminal to "power-on" settings |
dgabino | 0:60ff878b27b8 | 59 | // ESC c |
dgabino | 0:60ff878b27b8 | 60 | this->printf( "\x1B\x63" ); |
dgabino | 0:60ff878b27b8 | 61 | } |
dgabino | 0:60ff878b27b8 | 62 | |
dgabino | 0:60ff878b27b8 | 63 | void ClearScreen( uint8_t param ) |
dgabino | 0:60ff878b27b8 | 64 | { |
dgabino | 0:60ff878b27b8 | 65 | // ESC [ Ps J |
dgabino | 0:60ff878b27b8 | 66 | // 0 Clear screen from cursor down |
dgabino | 0:60ff878b27b8 | 67 | // 1 Clear screen from cursor up |
dgabino | 0:60ff878b27b8 | 68 | // 2 Clear entire screen |
dgabino | 0:60ff878b27b8 | 69 | this->printf( "\x1B[%dJ", param ); |
dgabino | 0:60ff878b27b8 | 70 | } |
dgabino | 0:60ff878b27b8 | 71 | |
dgabino | 0:60ff878b27b8 | 72 | void ClearLine( uint8_t param ) |
dgabino | 0:60ff878b27b8 | 73 | { |
dgabino | 0:60ff878b27b8 | 74 | // ESC [ Ps K |
dgabino | 0:60ff878b27b8 | 75 | // 0 Erase from the active position to the end of the line, inclusive (default) |
dgabino | 0:60ff878b27b8 | 76 | // 1 Erase from the start of the screen to the active position, inclusive |
dgabino | 0:60ff878b27b8 | 77 | // 2 Erase all of the line, inclusive |
dgabino | 0:60ff878b27b8 | 78 | this->printf( "\x1B[%dK", param ); |
dgabino | 0:60ff878b27b8 | 79 | } |
dgabino | 0:60ff878b27b8 | 80 | |
dgabino | 0:60ff878b27b8 | 81 | void SetAttribute( uint8_t attr ) |
dgabino | 0:60ff878b27b8 | 82 | { |
dgabino | 0:60ff878b27b8 | 83 | // ESC [ Ps;...;Ps m |
dgabino | 0:60ff878b27b8 | 84 | this->printf( "\x1B[%dm", attr ); |
dgabino | 0:60ff878b27b8 | 85 | } |
dgabino | 0:60ff878b27b8 | 86 | |
dgabino | 0:60ff878b27b8 | 87 | void SetAttribute( uint8_t attr, uint8_t fgcolor, uint8_t bgcolor ) |
dgabino | 0:60ff878b27b8 | 88 | { |
dgabino | 0:60ff878b27b8 | 89 | // ESC [ Ps;...;Ps m |
dgabino | 0:60ff878b27b8 | 90 | this->printf( "\x1B[%d;%d;%dm", attr, fgcolor + 30, bgcolor + 40 ); |
dgabino | 0:60ff878b27b8 | 91 | } |
dgabino | 0:60ff878b27b8 | 92 | |
dgabino | 0:60ff878b27b8 | 93 | void SetCursorMode( uint8_t visible ) |
dgabino | 0:60ff878b27b8 | 94 | { |
dgabino | 0:60ff878b27b8 | 95 | if( visible == true ) |
dgabino | 0:60ff878b27b8 | 96 | { |
dgabino | 0:60ff878b27b8 | 97 | // ESC [ ? 25 h |
dgabino | 0:60ff878b27b8 | 98 | this->printf( "\x1B[?25h" ); |
dgabino | 0:60ff878b27b8 | 99 | } |
dgabino | 0:60ff878b27b8 | 100 | else |
dgabino | 0:60ff878b27b8 | 101 | { |
dgabino | 0:60ff878b27b8 | 102 | // ESC [ ? 25 l |
dgabino | 0:60ff878b27b8 | 103 | this->printf( "\x1B[?25l" ); |
dgabino | 0:60ff878b27b8 | 104 | } |
dgabino | 0:60ff878b27b8 | 105 | } |
dgabino | 0:60ff878b27b8 | 106 | |
dgabino | 0:60ff878b27b8 | 107 | void SetCursorPos( uint8_t line, uint8_t col ) |
dgabino | 0:60ff878b27b8 | 108 | { |
dgabino | 0:60ff878b27b8 | 109 | // ESC [ Pl ; Pc H |
dgabino | 0:60ff878b27b8 | 110 | this->printf( "\x1B[%d;%dH", line, col ); |
dgabino | 0:60ff878b27b8 | 111 | } |
dgabino | 0:60ff878b27b8 | 112 | |
dgabino | 0:60ff878b27b8 | 113 | void PutStringAt( uint8_t line, uint8_t col, const char *s ) |
dgabino | 0:60ff878b27b8 | 114 | { |
dgabino | 0:60ff878b27b8 | 115 | this->SetCursorPos( line, col ); |
dgabino | 0:60ff878b27b8 | 116 | this->printf( "%s", s ); |
dgabino | 0:60ff878b27b8 | 117 | } |
dgabino | 0:60ff878b27b8 | 118 | |
dgabino | 0:60ff878b27b8 | 119 | void PutCharAt( uint8_t line, uint8_t col, uint8_t c ) |
dgabino | 0:60ff878b27b8 | 120 | { |
dgabino | 0:60ff878b27b8 | 121 | this->SetCursorPos( line, col ); |
dgabino | 0:60ff878b27b8 | 122 | this->printf( "%c", c ); |
dgabino | 0:60ff878b27b8 | 123 | } |
dgabino | 0:60ff878b27b8 | 124 | |
dgabino | 0:60ff878b27b8 | 125 | void PutHexAt( uint8_t line, uint8_t col, uint16_t n ) |
dgabino | 0:60ff878b27b8 | 126 | { |
dgabino | 0:60ff878b27b8 | 127 | this->SetCursorPos( line, col ); |
dgabino | 0:60ff878b27b8 | 128 | this->printf( "%X", n ); |
dgabino | 0:60ff878b27b8 | 129 | } |
dgabino | 0:60ff878b27b8 | 130 | |
dgabino | 0:60ff878b27b8 | 131 | void PutBoxDrawingChar( uint8_t c ) |
dgabino | 0:60ff878b27b8 | 132 | { |
dgabino | 0:60ff878b27b8 | 133 | this->printf( "\x1B(0%c\x1b(B", c ); |
dgabino | 0:60ff878b27b8 | 134 | } |
dgabino | 0:60ff878b27b8 | 135 | |
dgabino | 0:60ff878b27b8 | 136 | bool Readable( void ) |
dgabino | 0:60ff878b27b8 | 137 | { |
dgabino | 0:60ff878b27b8 | 138 | return this->readable( ); |
dgabino | 0:60ff878b27b8 | 139 | } |
dgabino | 0:60ff878b27b8 | 140 | |
dgabino | 0:60ff878b27b8 | 141 | uint8_t GetChar( void ) |
dgabino | 0:60ff878b27b8 | 142 | { |
dgabino | 0:60ff878b27b8 | 143 | return this->getc( ); |
dgabino | 0:60ff878b27b8 | 144 | } |
dgabino | 0:60ff878b27b8 | 145 | |
dgabino | 0:60ff878b27b8 | 146 | /* |
dgabino | 0:60ff878b27b8 | 147 | * RawSerial class implmentation copy. |
dgabino | 0:60ff878b27b8 | 148 | */ |
dgabino | 0:60ff878b27b8 | 149 | /** Read a char from the serial port |
dgabino | 0:60ff878b27b8 | 150 | * |
dgabino | 0:60ff878b27b8 | 151 | * @returns The char read from the serial port |
dgabino | 0:60ff878b27b8 | 152 | */ |
dgabino | 0:60ff878b27b8 | 153 | int getc( ) |
dgabino | 0:60ff878b27b8 | 154 | { |
dgabino | 0:60ff878b27b8 | 155 | return _base_getc(); |
dgabino | 0:60ff878b27b8 | 156 | } |
dgabino | 0:60ff878b27b8 | 157 | |
dgabino | 0:60ff878b27b8 | 158 | /** Write a char to the serial port |
dgabino | 0:60ff878b27b8 | 159 | * |
dgabino | 0:60ff878b27b8 | 160 | * @param c The char to write |
dgabino | 0:60ff878b27b8 | 161 | * |
dgabino | 0:60ff878b27b8 | 162 | * @returns The written char or -1 if an error occured |
dgabino | 0:60ff878b27b8 | 163 | */ |
dgabino | 0:60ff878b27b8 | 164 | int putc( int c ) |
dgabino | 0:60ff878b27b8 | 165 | { |
dgabino | 0:60ff878b27b8 | 166 | while( this->writeable( ) != 1 ); |
dgabino | 0:60ff878b27b8 | 167 | return _base_putc( c ); |
dgabino | 0:60ff878b27b8 | 168 | } |
dgabino | 0:60ff878b27b8 | 169 | |
dgabino | 0:60ff878b27b8 | 170 | /** Write a string to the serial port |
dgabino | 0:60ff878b27b8 | 171 | * |
dgabino | 0:60ff878b27b8 | 172 | * @param str The string to write |
dgabino | 0:60ff878b27b8 | 173 | * |
dgabino | 0:60ff878b27b8 | 174 | * @returns 0 if the write succeeds, EOF for error |
dgabino | 0:60ff878b27b8 | 175 | */ |
dgabino | 0:60ff878b27b8 | 176 | int puts( const char *str ) |
dgabino | 0:60ff878b27b8 | 177 | { |
dgabino | 0:60ff878b27b8 | 178 | while( *str ) |
dgabino | 0:60ff878b27b8 | 179 | putc( *str++ ); |
dgabino | 0:60ff878b27b8 | 180 | return 0; |
dgabino | 0:60ff878b27b8 | 181 | } |
dgabino | 0:60ff878b27b8 | 182 | |
dgabino | 0:60ff878b27b8 | 183 | // Experimental support for printf in RawSerial. No Stream inheritance |
dgabino | 0:60ff878b27b8 | 184 | // means we can't call printf() directly, so we use sprintf() instead. |
dgabino | 0:60ff878b27b8 | 185 | // We only call malloc() for the sprintf() buffer if the buffer |
dgabino | 0:60ff878b27b8 | 186 | // length is above a certain threshold, otherwise we use just the stack. |
dgabino | 0:60ff878b27b8 | 187 | int printf( const char *format, ... ) |
dgabino | 0:60ff878b27b8 | 188 | { |
dgabino | 0:60ff878b27b8 | 189 | std::va_list arg; |
dgabino | 0:60ff878b27b8 | 190 | va_start( arg, format ); |
dgabino | 0:60ff878b27b8 | 191 | int len = vsnprintf( NULL, 0, format, arg ); |
dgabino | 0:60ff878b27b8 | 192 | if( len < STRING_STACK_LIMIT ) |
dgabino | 0:60ff878b27b8 | 193 | { |
dgabino | 0:60ff878b27b8 | 194 | char temp[STRING_STACK_LIMIT]; |
dgabino | 0:60ff878b27b8 | 195 | vsprintf( temp, format, arg ); |
dgabino | 0:60ff878b27b8 | 196 | puts( temp ); |
dgabino | 0:60ff878b27b8 | 197 | } |
dgabino | 0:60ff878b27b8 | 198 | else |
dgabino | 0:60ff878b27b8 | 199 | { |
dgabino | 0:60ff878b27b8 | 200 | char *temp = new char[len + 1]; |
dgabino | 0:60ff878b27b8 | 201 | vsprintf( temp, format, arg ); |
dgabino | 0:60ff878b27b8 | 202 | puts( temp ); |
dgabino | 0:60ff878b27b8 | 203 | delete[] temp; |
dgabino | 0:60ff878b27b8 | 204 | } |
dgabino | 0:60ff878b27b8 | 205 | va_end( arg ); |
dgabino | 0:60ff878b27b8 | 206 | return len; |
dgabino | 0:60ff878b27b8 | 207 | } |
dgabino | 0:60ff878b27b8 | 208 | |
dgabino | 0:60ff878b27b8 | 209 | private: |
dgabino | 0:60ff878b27b8 | 210 | |
dgabino | 0:60ff878b27b8 | 211 | }; |
dgabino | 0:60ff878b27b8 | 212 | |
dgabino | 0:60ff878b27b8 | 213 | #endif // __VT100_H__ |