| 
 | 
	
    
 
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册  
 
x
 
自带收发功能,支持SX1272/1276/1278; J: E' t0 C1 @1 b# z( a& M 
 
* `/ I. C4 {; @$ D% g$ f8 y- #include <string.h>
 - #include <stdint.h>
 - #include <stdbool.h>
 - #include "platform.h"
 - #include "led.h"
 - #if USE_UART
 - #include "uart.h"
 - #endif
 - #include "radio.h"
 - #define BUFFER_SIZE                                 9 // Define the payload size here
 - static uint16_t BufferSize = BUFFER_SIZE;                        // RF buffer size
 - static uint8_t Buffer[BUFFER_SIZE];                                        // RF buffer
 - static uint8_t EnableMaster = true;                                 // Master/Slave selection
 - tRadioDriver *Radio = NULL;
 - const uint8_t PingMsg[] = "PING";
 - const uint8_t PongMsg[] = "PONG";
 - /*
 -  * Manages the master operation
 -  */
 - void OnMaster( void )
 - {
 -     uint8_t i;
 -     switch( Radio->Process( ) )
 -     {
 -     case RF_RX_TIMEOUT:
 -         // Send the next PING frame
 -         Buffer[0] = 'P';
 -         Buffer[1] = 'I';
 -         Buffer[2] = 'N';
 -         Buffer[3] = 'G';
 -         for( i = 4; i < BufferSize; i++ )
 -         {
 -             Buffer = i - 4;
-         }
 -         Radio->SetTxPacket( Buffer, BufferSize );
 -         break;
 -     case RF_RX_DONE:
 -         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
 -         if( BufferSize > 0 )
 -         {
 -             if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
 -             {
 -                 // Indicates on a LED that the received frame is a PONG
 -                 LedToggle( LED_GREEN );
 -                 // Send the next PING frame
 -                 Buffer[0] = 'P';
 -                 Buffer[1] = 'I';
 -                 Buffer[2] = 'N';
 -                 Buffer[3] = 'G';
 -                 // We fill the buffer with numbers for the payload
 -                 for( i = 4; i < BufferSize; i++ )
 -                 {
 -                     Buffer = i - 4;
-                 }
 -                 Radio->SetTxPacket( Buffer, BufferSize );
 -             }
 -             else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
 -             { // A master already exists then become a slave
 -                 EnableMaster = false;
 -                 LedOff( LED_RED );
 -             }
 -         }
 -         break;
 -     case RF_TX_DONE:
 -         // Indicates on a LED that we have sent a PING
 -         LedToggle( LED_RED );
 -         Radio->StartRx( );
 -         break;
 -     default:
 -         break;
 -     }
 - }
 - /*
 -  * Manages the slave operation
 -  */
 - void OnSlave( void )
 - {
 -     uint8_t i;
 -     switch( Radio->Process( ) )
 -     {
 -     case RF_RX_DONE:
 -         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
 -         if( BufferSize > 0 )
 -         {
 -             if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
 -             {
 -                 // Indicates on a LED that the received frame is a PING
 -                 LedToggle( LED_GREEN );
 -                // Send the reply to the PONG string
 -                 Buffer[0] = 'P';
 -                 Buffer[1] = 'O';
 -                 Buffer[2] = 'N';
 -                 Buffer[3] = 'G';
 -                 // We fill the buffer with numbers for the payload
 -                 for( i = 4; i < BufferSize; i++ )
 -                 {
 -                     Buffer = i - 4;
-                 }
 -                 Radio->SetTxPacket( Buffer, BufferSize );
 -             }
 -         }
 -         break;
 -     case RF_TX_DONE:
 -         // Indicates on a LED that we have sent a PONG
 -         LedToggle( LED_RED );
 -         Radio->StartRx( );
 -         break;
 -     default:
 -         break;
 -     }
 - }
 - /*
 -  * Main application entry point.
 -  */
 - int main( void )
 - {
 -     BoardInit( );
 -     Radio = RadioDriverInit( );
 -     Radio->Init( );
 -     Radio->StartRx( );
 -     while( 1 )
 -     {
 -         if( EnableMaster == true )
 -         {
 -             OnMaster( );
 -         }
 -         else
 -         {
 -             OnSlave( );
 -         }
 - #if( PLATFORM == SX12xxEiger ) && ( USE_UART == 1 )
 -         UartProcess( );
 -         {
 -             uint8_t data = 0;
 -             if( UartGetChar( &data ) == UART_OK )
 -             {
 -                 UartPutChar( data );
 -             }
 -         }
 - #endif
 -     }
 - #ifdef __GNUC__
 -     return 0;
 - #endif
 - }
 
8 `9 `# J: O4 p. @     ) F7 x0 Y, D9 _ 
 
3 R" A# u. s. W" a9 W 
8 e, E2 e) G9 {! R3 A, w% u; ] |   
 
 
 
 |