Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SerialDisplay.cpp
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 (C)2015 Semtech 00008 00009 Description: VT100 serial display management 00010 00011 License: Revised BSD License, see LICENSE.TXT file include in the project 00012 00013 Maintainer: Miguel Luis and Gregory Cristian 00014 */ 00015 #include "board.h" 00016 #include "vt100.h" 00017 #include "SerialDisplay.h" 00018 00019 VT100 vt( USBTX, USBRX ); 00020 00021 void SerialPrintCheckBox( bool activated, uint8_t color ) 00022 { 00023 if( activated == true ) 00024 { 00025 vt.SetAttribute( VT100::ATTR_OFF, color, color ); 00026 } 00027 else 00028 { 00029 vt.SetAttribute( VT100::ATTR_OFF ); 00030 } 00031 vt.printf( " " ); 00032 vt.SetAttribute( VT100::ATTR_OFF ); 00033 } 00034 00035 void SerialDisplayUpdateActivationMode( bool otaa ) 00036 { 00037 vt.SetCursorPos( 4, 17 ); 00038 SerialPrintCheckBox( otaa, VT100::WHITE ); 00039 vt.SetCursorPos( 9, 17 ); 00040 SerialPrintCheckBox( !otaa, VT100::WHITE ); 00041 } 00042 00043 void SerialDisplayUpdateEui( uint8_t line, uint8_t *eui ) 00044 { 00045 vt.SetCursorPos( line, 27 ); 00046 for( uint8_t i = 0; i < 8; i++ ) 00047 { 00048 vt.printf( "%02X ", eui[i] ); 00049 } 00050 vt.SetCursorPos( line, 50 ); 00051 vt.printf( "]" ); 00052 } 00053 00054 void SerialDisplayUpdateKey( uint8_t line, uint8_t *key ) 00055 { 00056 vt.SetCursorPos( line, 27 ); 00057 for( uint8_t i = 0; i < 16; i++ ) 00058 { 00059 vt.printf( "%02X ", key[i] ); 00060 } 00061 vt.SetCursorPos( line, 74 ); 00062 vt.printf( "]" ); 00063 } 00064 00065 void SerialDisplayUpdateNwkId( uint8_t id ) 00066 { 00067 vt.SetCursorPos( 10, 27 ); 00068 vt.printf( "%03d", id ); 00069 } 00070 00071 void SerialDisplayUpdateDevAddr( uint32_t addr ) 00072 { 00073 vt.SetCursorPos( 11, 27 ); 00074 vt.printf( "%02X %02X %02X %02X", ( addr >> 24 ) & 0xFF, ( addr >> 16 ) & 0xFF, ( addr >> 8 ) & 0xFF, addr & 0xFF ); 00075 } 00076 00077 void SerialDisplayUpdateFrameType( bool confirmed ) 00078 { 00079 vt.SetCursorPos( 15, 17 ); 00080 SerialPrintCheckBox( confirmed, VT100::WHITE ); 00081 vt.SetCursorPos( 15, 32 ); 00082 SerialPrintCheckBox( !confirmed, VT100::WHITE ); 00083 } 00084 00085 void SerialDisplayUpdateAdr( bool adr ) 00086 { 00087 vt.SetCursorPos( 16, 27 ); 00088 if( adr == true ) 00089 { 00090 vt.printf( " ON" ); 00091 } 00092 else 00093 { 00094 vt.printf( "OFF" ); 00095 } 00096 } 00097 00098 void SerialDisplayUpdateDutyCycle( bool dutyCycle ) 00099 { 00100 vt.SetCursorPos( 17, 27 ); 00101 if( dutyCycle == true ) 00102 { 00103 vt.printf( " ON" ); 00104 } 00105 else 00106 { 00107 vt.printf( "OFF" ); 00108 } 00109 } 00110 00111 void SerialDisplayPrintDebugLine( char* str, uint8_t size ) 00112 { 00113 vt.SetCursorPos( 17, 27 ); 00114 vt.printf("DEBUG LINE: "); 00115 for (int i = 0; i < size; i++) { 00116 vt.printf( "%c", str[i] ); 00117 } 00118 00119 00120 } 00121 00122 void SerialDisplayPrintDebugNumber( int n, bool overwrite ) 00123 { 00124 if ( overwrite == true) { 00125 vt.SetCursorPos( 17, 27 ); 00126 vt.printf("DEBUG NUMBER: "); 00127 } 00128 vt.printf( " %d", n ); 00129 00130 } 00131 00132 void SerialDisplayPrintDebugStatus( uint16_t status ) 00133 { 00134 vt.SetCursorPos( 17, 27 ); 00135 vt.printf("DEBUG STATUS: "); 00136 vt.printf( "%d", status ); 00137 00138 } 00139 00140 void SerialDisplayUpdatePublicNetwork( bool network ) 00141 { 00142 vt.SetCursorPos( 19, 17 ); 00143 SerialPrintCheckBox( network, VT100::WHITE ); 00144 vt.SetCursorPos( 19, 30 ); 00145 SerialPrintCheckBox( !network, VT100::WHITE ); 00146 } 00147 00148 void SerialDisplayUpdateNetworkIsJoined( bool state ) 00149 { 00150 vt.SetCursorPos( 20, 17 ); 00151 SerialPrintCheckBox( !state, VT100::RED ); 00152 vt.SetCursorPos( 20, 30 ); 00153 SerialPrintCheckBox( state, VT100::GREEN ); 00154 } 00155 00156 void SerialDisplayUpdateLedState( uint8_t id, uint8_t state ) 00157 { 00158 switch( id ) 00159 { 00160 case 1: 00161 vt.SetCursorPos( 22, 17 ); 00162 SerialPrintCheckBox( state, VT100::RED ); 00163 break; 00164 case 2: 00165 vt.SetCursorPos( 22, 31 ); 00166 SerialPrintCheckBox( state, VT100::GREEN ); 00167 break; 00168 case 3: 00169 vt.SetCursorPos( 22, 45 ); 00170 SerialPrintCheckBox( state, VT100::BLUE ); 00171 break; 00172 } 00173 } 00174 00175 void SerialDisplayUpdateData( uint8_t line, uint8_t *buffer, uint8_t size ) 00176 { 00177 if( size != 0 ) 00178 { 00179 vt.SetCursorPos( line, 27 ); 00180 for( uint8_t i = 0; i < size; i++ ) 00181 { 00182 vt.printf( "%02X ", buffer[i] ); 00183 if( ( ( i + 1 ) % 16 ) == 0 ) 00184 { 00185 line++; 00186 vt.SetCursorPos( line, 27 ); 00187 } 00188 } 00189 for( uint8_t i = size; i < 64; i++ ) 00190 { 00191 vt.printf( "__ " ); 00192 if( ( ( i + 1 ) % 16 ) == 0 ) 00193 { 00194 line++; 00195 vt.SetCursorPos( line, 27 ); 00196 } 00197 } 00198 vt.SetCursorPos( line - 1, 74 ); 00199 vt.printf( "]" ); 00200 } 00201 else 00202 { 00203 vt.SetCursorPos( line, 27 ); 00204 for( uint8_t i = 0; i < 64; i++ ) 00205 { 00206 vt.printf( "__ " ); 00207 if( ( ( i + 1 ) % 16 ) == 0 ) 00208 { 00209 line++; 00210 vt.SetCursorPos( line, 27 ); 00211 } 00212 } 00213 vt.SetCursorPos( line - 1, 74 ); 00214 vt.printf( "]" ); 00215 } 00216 } 00217 00218 void SerialDisplayUpdateUplinkAcked( bool state ) 00219 { 00220 vt.SetCursorPos( 24, 36 ); 00221 SerialPrintCheckBox( state, VT100::GREEN ); 00222 } 00223 00224 void SerialDisplayUpdateUplink( bool acked, uint8_t datarate, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize ) 00225 { 00226 // Acked 00227 SerialDisplayUpdateUplinkAcked( acked ); 00228 // Datarate 00229 vt.SetCursorPos( 25, 33 ); 00230 vt.printf( "DR%d", datarate ); 00231 // Counter 00232 vt.SetCursorPos( 26, 27 ); 00233 vt.printf( "%10d", counter ); 00234 // Port 00235 vt.SetCursorPos( 27, 34 ); 00236 vt.printf( "%3d", port ); 00237 // Data 00238 SerialDisplayUpdateData( 28, buffer, bufferSize ); 00239 // Help message 00240 vt.SetCursorPos( 42, 1 ); 00241 vt.printf( "To refresh screen please hit 'r' key." ); 00242 } 00243 00244 void SerialDisplayUpdateDonwlinkRxData( bool state ) 00245 { 00246 vt.SetCursorPos( 34, 4 ); 00247 SerialPrintCheckBox( state, VT100::GREEN ); 00248 } 00249 00250 void SerialDisplayUpdateDownlink( bool rxData, int16_t rssi, int8_t snr, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize ) 00251 { 00252 // Rx data 00253 SerialDisplayUpdateDonwlinkRxData( rxData ); 00254 // RSSI 00255 vt.SetCursorPos( 33, 32 ); 00256 vt.printf( "%5d", rssi ); 00257 // SNR 00258 vt.SetCursorPos( 34, 32 ); 00259 vt.printf( "%5d", snr ); 00260 // Counter 00261 vt.SetCursorPos( 35, 27 ); 00262 vt.printf( "%10d", counter ); 00263 if( rxData == true ) 00264 { 00265 // Port 00266 vt.SetCursorPos( 36, 34 ); 00267 vt.printf( "%3d", port ); 00268 // Data 00269 SerialDisplayUpdateData( 37, buffer, bufferSize ); 00270 } 00271 else 00272 { 00273 // Port 00274 vt.SetCursorPos( 36, 34 ); 00275 vt.printf( " " ); 00276 // Data 00277 SerialDisplayUpdateData( 37, NULL, 0 ); 00278 } 00279 } 00280 00281 void SerialDisplayDrawFirstLine( void ) 00282 { 00283 vt.PutBoxDrawingChar( 'l' ); 00284 for( int8_t i = 0; i <= 77; i++ ) 00285 { 00286 vt.PutBoxDrawingChar( 'q' ); 00287 } 00288 vt.PutBoxDrawingChar( 'k' ); 00289 vt.printf( "\r\n" ); 00290 } 00291 00292 void SerialDisplayDrawTitle( const char* title ) 00293 { 00294 vt.PutBoxDrawingChar( 'x' ); 00295 vt.printf( "%s", title ); 00296 vt.PutBoxDrawingChar( 'x' ); 00297 vt.printf( "\r\n" ); 00298 } 00299 void SerialDisplayDrawTopSeparator( void ) 00300 { 00301 vt.PutBoxDrawingChar( 't' ); 00302 for( int8_t i = 0; i <= 11; i++ ) 00303 { 00304 vt.PutBoxDrawingChar( 'q' ); 00305 } 00306 vt.PutBoxDrawingChar( 'w' ); 00307 for( int8_t i = 0; i <= 64; i++ ) 00308 { 00309 vt.PutBoxDrawingChar( 'q' ); 00310 } 00311 vt.PutBoxDrawingChar( 'u' ); 00312 vt.printf( "\r\n" ); 00313 } 00314 00315 void SerialDisplayDrawColSeparator( void ) 00316 { 00317 vt.PutBoxDrawingChar( 'x' ); 00318 for( int8_t i = 0; i <= 11; i++ ) 00319 { 00320 vt.PutBoxDrawingChar( ' ' ); 00321 } 00322 vt.PutBoxDrawingChar( 't' ); 00323 for( int8_t i = 0; i <= 64; i++ ) 00324 { 00325 vt.PutBoxDrawingChar( 'q' ); 00326 } 00327 vt.PutBoxDrawingChar( 'u' ); 00328 vt.printf( "\r\n" ); 00329 } 00330 00331 void SerialDisplayDrawSeparator( void ) 00332 { 00333 vt.PutBoxDrawingChar( 't' ); 00334 for( int8_t i = 0; i <= 11; i++ ) 00335 { 00336 vt.PutBoxDrawingChar( 'q' ); 00337 } 00338 vt.PutBoxDrawingChar( 'n' ); 00339 for( int8_t i = 0; i <= 64; i++ ) 00340 { 00341 vt.PutBoxDrawingChar( 'q' ); 00342 } 00343 vt.PutBoxDrawingChar( 'u' ); 00344 vt.printf( "\r\n" ); 00345 } 00346 00347 void SerialDisplayDrawLine( const char* firstCol, const char* secondCol ) 00348 { 00349 vt.PutBoxDrawingChar( 'x' ); 00350 vt.printf( "%s", firstCol ); 00351 vt.PutBoxDrawingChar( 'x' ); 00352 vt.printf( "%s", secondCol ); 00353 vt.PutBoxDrawingChar( 'x' ); 00354 vt.printf( "\r\n" ); 00355 } 00356 00357 void SerialDisplayDrawBottomLine( void ) 00358 { 00359 vt.PutBoxDrawingChar( 'm' ); 00360 for( int8_t i = 0; i <= 11; i++ ) 00361 { 00362 vt.PutBoxDrawingChar( 'q' ); 00363 } 00364 vt.PutBoxDrawingChar( 'v' ); 00365 for( int8_t i = 0; i <= 64; i++ ) 00366 { 00367 vt.PutBoxDrawingChar( 'q' ); 00368 } 00369 vt.PutBoxDrawingChar( 'j' ); 00370 vt.printf( "\r\n" ); 00371 } 00372 00373 void SerialDisplayInit( void ) 00374 { 00375 vt.ClearScreen( 2 ); 00376 vt.SetCursorMode( false ); 00377 vt.SetCursorPos( 0, 0 ); 00378 00379 // "+-----------------------------------------------------------------------------+" ); 00380 SerialDisplayDrawFirstLine( ); 00381 // "¦ LoRaWAN Demonstration Application ¦" ); 00382 SerialDisplayDrawTitle( " LoRaWAN Demonstration Application " ); 00383 // "+------------+----------------------------------------------------------------¦" ); 00384 SerialDisplayDrawTopSeparator( ); 00385 // "¦ Activation ¦ [ ]Over The Air ¦" ); 00386 SerialDisplayDrawLine( " Activation ", " [ ]Over The Air " ); 00387 // "¦ ¦ DevEui [__ __ __ __ __ __ __ __] ¦" ); 00388 SerialDisplayDrawLine( " ", " DevEui [__ __ __ __ __ __ __ __] " ); 00389 // "¦ ¦ AppEui [__ __ __ __ __ __ __ __] ¦" ); 00390 SerialDisplayDrawLine( " ", " AppEui [__ __ __ __ __ __ __ __] " ); 00391 // "¦ ¦ AppKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" ); 00392 SerialDisplayDrawLine( " ", " AppKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " ); 00393 // "¦ +----------------------------------------------------------------¦" ); 00394 SerialDisplayDrawColSeparator( ); 00395 // "¦ ¦ [x]Personalisation ¦" ); 00396 SerialDisplayDrawLine( " ", " [ ]Personalisation " ); 00397 // "¦ ¦ NwkId [___] ¦" ); 00398 SerialDisplayDrawLine( " ", " NwkId [___] " ); 00399 // "¦ ¦ DevAddr [__ __ __ __] ¦" ); 00400 SerialDisplayDrawLine( " ", " DevAddr [__ __ __ __] " ); 00401 // "¦ ¦ NwkSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" ); 00402 SerialDisplayDrawLine( " ", " NwkSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " ); 00403 // "¦ ¦ AppSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" ); 00404 SerialDisplayDrawLine( " ", " AppSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " ); 00405 // "+------------+----------------------------------------------------------------¦" ); 00406 SerialDisplayDrawSeparator( ); 00407 // "¦ MAC params ¦ [ ]Confirmed / [ ]Unconfirmed ¦" ); 00408 SerialDisplayDrawLine( " MAC params ", " [ ]Confirmed / [ ]Unconfirmed " ); 00409 // "¦ ¦ ADR [ ] ¦" ); 00410 SerialDisplayDrawLine( " ", " ADR [ ] " ); 00411 // "¦ ¦ Duty cycle[ ] ¦" ); 00412 SerialDisplayDrawLine( " ", " Duty cycle[ ] " ); 00413 // "+------------+----------------------------------------------------------------¦" ); 00414 SerialDisplayDrawSeparator( ); 00415 // "¦ Network ¦ [ ]Public / [ ]Private ¦" ); 00416 SerialDisplayDrawLine( " Network ", " [ ]Public / [ ]Private " ); 00417 // "¦ ¦ [ ]Joining / [ ]Joined ¦" ); 00418 SerialDisplayDrawLine( " ", " [ ]Joining / [ ]Joined " ); 00419 // "+------------+----------------------------------------------------------------¦" ); 00420 SerialDisplayDrawSeparator( ); 00421 // "¦ LED status ¦ [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App) ¦" ); 00422 SerialDisplayDrawLine( " LED status ", " [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App) " ); 00423 // "+------------+----------------------------------------------------------------¦" ); 00424 SerialDisplayDrawSeparator( ); 00425 // "¦ Uplink ¦ Acked [ ] ¦" ); 00426 SerialDisplayDrawLine( " Uplink ", " Acked [ ] " ); 00427 // "¦ ¦ Datarate [ ] ¦" ); 00428 SerialDisplayDrawLine( " ", " Datarate [ ] " ); 00429 // "¦ ¦ Counter [ ] ¦" ); 00430 SerialDisplayDrawLine( " ", " Counter [ ] " ); 00431 // "¦ ¦ Port [ ] ¦" ); 00432 SerialDisplayDrawLine( " ", " Port [ ] " ); 00433 // "¦ ¦ Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00434 SerialDisplayDrawLine( " ", " Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00435 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00436 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00437 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00438 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00439 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00440 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00441 // "+------------+----------------------------------------------------------------¦" ); 00442 SerialDisplayDrawSeparator( ); 00443 // "¦ Downlink ¦ RSSI [ ] dBm ¦" ); 00444 SerialDisplayDrawLine( " Downlink ", " RSSI [ ] dBm " ); 00445 // "¦ [ ]Data ¦ SNR [ ] dB ¦" ); 00446 SerialDisplayDrawLine( " [ ]Data ", " SNR [ ] dB " ); 00447 // "¦ ¦ Counter [ ] ¦" ); 00448 // "¦ ¦ Counter [ ] ¦" ); 00449 SerialDisplayDrawLine( " ", " Counter [ ] " ); 00450 // "¦ ¦ Port [ ] ¦" ); 00451 SerialDisplayDrawLine( " ", " Port [ ] " ); 00452 // "¦ ¦ Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00453 SerialDisplayDrawLine( " ", " Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00454 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00455 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00456 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00457 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00458 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); 00459 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); 00460 // "+------------+----------------------------------------------------------------+" ); 00461 SerialDisplayDrawBottomLine( ); 00462 vt.printf( "To refresh screen please hit 'r' key.\r\n" ); 00463 } 00464 00465 bool SerialDisplayReadable( void ) 00466 { 00467 return vt.Readable( ); 00468 } 00469 00470 uint8_t SerialDisplayGetChar( void ) 00471 { 00472 return vt.GetChar( ); 00473 }
Generated on Thu Jul 14 2022 04:57:38 by
1.7.2