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.
Fork of SX1272PingPong by
Revision 15:f48a416da6a8, committed 2017-07-21
- Comitter:
- franc_unina
- Date:
- Fri Jul 21 19:44:45 2017 +0000
- Parent:
- 14:ab6eecd44b7a
- Commit message:
- LoRa_Tx
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 24 09:29:13 2017 +0000 +++ b/main.cpp Fri Jul 21 19:44:45 2017 +0000 @@ -86,8 +86,9 @@ */ SX1272MB2xAS Radio( NULL ); -const uint8_t PingMsg[] = "PING"; -const uint8_t PongMsg[] = "PONG"; +const uint8_t PingMsg[] = "LOR1"; +const uint8_t PongMs2[] = "LOR2"; +const uint8_t PongMs3[] = "LOR3"; uint16_t BufferSize = BUFFER_SIZE; uint8_t Buffer[BUFFER_SIZE]; @@ -98,7 +99,7 @@ int main( void ) { uint8_t i; - bool isMaster = true; + debug( "\n\n\r SX1272 Ping Pong Demo Application \n\n\r" ); @@ -161,147 +162,23 @@ led = 0; - Radio.Rx( RX_TIMEOUT_VALUE ); + //Radio.Rx( RX_TIMEOUT_VALUE ); while( 1 ) { - switch( State ) - { - case RX: - if( isMaster == true ) - { - if( BufferSize > 0 ) - { - if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 ) - { - led = !led; - debug( "...Pong\r\n" ); - // Send the next PING frame - strcpy( ( char* )Buffer, ( char* )PingMsg ); - // We fill the buffer with numbers for the payload - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); - } - else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) - { // A master already exists then become a slave - debug( "...Ping\r\n" ); - led = !led; - isMaster = false; - // Send the next PONG frame - strcpy( ( char* )Buffer, ( char* )PongMsg ); - // We fill the buffer with numbers for the payload - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); - } - else // valid reception but neither a PING or a PONG message - { // Set device as master ans start again - isMaster = true; - Radio.Rx( RX_TIMEOUT_VALUE ); - } - } - } - else - { - if( BufferSize > 0 ) - { - if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 ) - { - led = !led; - debug( "...Ping\r\n" ); - // Send the reply to the PING string - strcpy( ( char* )Buffer, ( char* )PongMsg ); - // We fill the buffer with numbers for the payload - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); - } - else // valid reception but not a PING as expected - { // Set device as master and start again - isMaster = true; - Radio.Rx( RX_TIMEOUT_VALUE ); - } - } - } - State = LOWPOWER; - break; - case TX: + led = !led; - if( isMaster == true ) - { - debug( "Ping...\r\n" ); - } - else - { - debug( "Pong...\r\n" ); - } - Radio.Rx( RX_TIMEOUT_VALUE ); - State = LOWPOWER; - break; - case RX_TIMEOUT: - if( isMaster == true ) - { - // Send the next PING frame + + debug( "LOR1...\r\n" ); + strcpy( ( char* )Buffer, ( char* )PingMsg ); for( i = 4; i < BufferSize; i++ ) { Buffer[i] = i - 4; } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); - } - else - { - Radio.Rx( RX_TIMEOUT_VALUE ); - } - State = LOWPOWER; - break; - case RX_ERROR: - // We have received a Packet with a CRC error, send reply as if packet was correct - if( isMaster == true ) - { - // Send the next PING frame - strcpy( ( char* )Buffer, ( char* )PingMsg ); - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); + wait_ms( 1000 ); Radio.Send( Buffer, BufferSize ); - } - else - { - // Send the next PONG frame - strcpy( ( char* )Buffer, ( char* )PongMsg ); - for( i = 4; i < BufferSize; i++ ) - { - Buffer[i] = i - 4; - } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); - } - State = LOWPOWER; - break; - case TX_TIMEOUT: - Radio.Rx( RX_TIMEOUT_VALUE ); - State = LOWPOWER; - break; - case LOWPOWER: - break; - default: - State = LOWPOWER; - break; - } + } } @@ -314,6 +191,7 @@ void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { + Radio.Sleep( ); BufferSize = size; memcpy( Buffer, payload, BufferSize ); @@ -321,6 +199,7 @@ SnrValue = snr; State = RX; debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" ); + } void OnTxTimeout( void ) @@ -332,15 +211,19 @@ void OnRxTimeout( void ) { + Radio.Sleep( ); Buffer[BufferSize] = 0; State = RX_TIMEOUT; debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" ); + } void OnRxError( void ) { + Radio.Sleep( ); State = RX_ERROR; debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" ); + }