Radnoumane Mossabely
/
Serre_auto_p2p_master
Peer to peer connection to switch on a led on slave
Revision 1:3ad74105ea9a, committed 2018-03-21
- Comitter:
- radnoumane
- Date:
- Wed Mar 21 13:43:48 2018 +0000
- Parent:
- 0:eba1236b9395
- Commit message:
- code master ok;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r eba1236b9395 -r 3ad74105ea9a main.cpp --- a/main.cpp Wed Mar 21 13:16:28 2018 +0000 +++ b/main.cpp Wed Mar 21 13:43:48 2018 +0000 @@ -73,7 +73,7 @@ CAD_DONE } AppStates_t; -volatile AppStates_t State = RX; +volatile AppStates_t State = LOWPOWER; /*! * Radio events function pointer @@ -168,103 +168,74 @@ Radio.Rx( RX_TIMEOUT_VALUE ); while( 1 ) { + switch( State ) { case RX: - if( BufferSize > 0 ) { - if( strncmp( ( const char* )Buffer, ( const char* )Coucou, 6 ) == 0 ) { - debug("LED ON"); - for(i=10;i<10;i++){ - led = 1; // LED is ON - led = 0; - wait(0.2); // 200 ms - led = 0; // LED is OFF - led= 1; - wait(0.2); // 1 sec - } - - // envoi de la réponse - strcpy( ( char* )Buffer, ( char* )Loulou ); - // We fill the buffer with numbers for the payload - for( i = 6; i < BufferSize; i++ ) { - Buffer[i] = i - 6; - } - wait_ms( 10 ); - Radio.Send( Buffer, BufferSize ); + debug("RX ?"); + if( BufferSize > 0 ) { //buffer contient des données + if( strncmp( ( const char* )Buffer, ( const char* )Loulou, 6 ) == 0 ) { + debug("LED OK \r\n..."); + } + } State = LOWPOWER; break; case TX: - debug("state = TX\r\n"); + + //debug("state = TX\r\n"); //led = !led; + if (mybutton == 0) { + debug("Coucou\r\n"); + debug("TX \r\n"); + strcpy( ( char* )Buffer, ( char* )Coucou ); + for( i = 6; i < BufferSize; i++ ) { + Buffer[i] = i - 6; + } + wait_ms( 10 ); + Radio.Send( Buffer, BufferSize ); + //debug(State); + } Radio.Rx( RX_TIMEOUT_VALUE ); State = LOWPOWER; break; case RX_TIMEOUT: debug("state = RX_TIMEOUT\r\n"); - /* 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 ); - Radio.Send( Buffer, BufferSize ); - } - else - { - Radio.Rx( RX_TIMEOUT_VALUE ); - }*/ + if (mybutton == 0) { + debug("\r\n"); + debug("allumage Led \r\n"); + strcpy( ( char* )Buffer, ( char* )Coucou ); + for( i = 6; i < BufferSize; i++ ) { + Buffer[i] = i - 6; + } + wait_ms( 10 ); + Radio.Send( Buffer, BufferSize ); + //debug(State); + } else { + Radio.Rx( RX_TIMEOUT_VALUE ); + } State = LOWPOWER; break; case RX_ERROR: debug("state = RX_ERROR\r\n"); - // 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 ); - 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: debug("state = TX_TIMEOUT\r\n"); Radio.Rx( RX_TIMEOUT_VALUE ); - State = RX; + State = LOWPOWER; break; case LOWPOWER: // debug("state = LOWPOWER\r\n"); - //State = RX; + //State = TX; break; default: debug("default\r\n"); - State = RX; + State = LOWPOWER; break; } - } - - } void OnTxDone( void )