久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2184|回復: 0
打印 上一主題 下一主題
收起左側

LoRa官方驅動程序 SX12xxDrivers

[復制鏈接]
跳轉到指定樓層
樓主
ID:342496 發表于 2019-10-7 19:04 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
官方驅動源程序如下:
  1. /*!
  2. * \file       main.c
  3. * \brief      Ping-Pong example application on how to use Semtech's Radio
  4. *             drivers.
  5. *
  6. * \version    2.0
  7. * \date       Nov 21 2012
  8. * \author     Miguel Luis
  9. */
  10. #include <string.h>
  11. #include <stdint.h>
  12. #include <stdbool.h>
  13. #include "platform.h"
  14. #include "led.h"

  15. #if USE_UART
  16. #include "uart.h"
  17. #endif

  18. #include "radio.h"


  19. #define BUFFER_SIZE                                 9 // Define the payload size here


  20. static uint16_t BufferSize = BUFFER_SIZE;                        // RF buffer size
  21. static uint8_t Buffer[BUFFER_SIZE];                                        // RF buffer

  22. static uint8_t EnableMaster = true;                                 // Master/Slave selection

  23. tRadioDriver *Radio = NULL;

  24. const uint8_t PingMsg[] = "PING";
  25. const uint8_t PongMsg[] = "PONG";

  26. /*
  27. * Manages the master operation
  28. */
  29. void OnMaster( void )
  30. {
  31.     uint8_t i;
  32.    
  33.     switch( Radio->Process( ) )
  34.     {
  35.     case RF_RX_TIMEOUT:
  36.         // Send the next PING frame
  37.         Buffer[0] = 'P';
  38.         Buffer[1] = 'I';
  39.         Buffer[2] = 'N';
  40.         Buffer[3] = 'G';
  41.         for( i = 4; i < BufferSize; i++ )
  42.         {
  43.             Buffer[i] = i - 4;
  44.         }
  45.         Radio->SetTxPacket( Buffer, BufferSize );
  46.         break;
  47.     case RF_RX_DONE:
  48.         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
  49.    
  50.         if( BufferSize > 0 )
  51.         {
  52.             if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
  53.             {
  54.                 // Indicates on a LED that the received frame is a PONG
  55.                 LedToggle( LED_GREEN );

  56.                 // Send the next PING frame            
  57.                 Buffer[0] = 'P';
  58.                 Buffer[1] = 'I';
  59.                 Buffer[2] = 'N';
  60.                 Buffer[3] = 'G';
  61.                 // We fill the buffer with numbers for the payload
  62.                 for( i = 4; i < BufferSize; i++ )
  63.                 {
  64.                     Buffer[i] = i - 4;
  65.                 }
  66.                 Radio->SetTxPacket( Buffer, BufferSize );
  67.             }
  68.             else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  69.             { // A master already exists then become a slave
  70.                 EnableMaster = false;
  71.                 LedOff( LED_RED );
  72.             }
  73.         }            
  74.         break;
  75.     case RF_TX_DONE:
  76.         // Indicates on a LED that we have sent a PING
  77.         LedToggle( LED_RED );
  78.         Radio->StartRx( );
  79.         break;
  80.     default:
  81.         break;
  82.     }
  83. }

  84. /*
  85. * Manages the slave operation
  86. */
  87. void OnSlave( void )
  88. {
  89.     uint8_t i;

  90.     switch( Radio->Process( ) )
  91.     {
  92.     case RF_RX_DONE:
  93.         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
  94.    
  95.         if( BufferSize > 0 )
  96.         {
  97.             if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  98.             {
  99.                 // Indicates on a LED that the received frame is a PING
  100.                 LedToggle( LED_GREEN );

  101.                // Send the reply to the PONG string
  102.                 Buffer[0] = 'P';
  103.                 Buffer[1] = 'O';
  104.                 Buffer[2] = 'N';
  105.                 Buffer[3] = 'G';
  106.                 // We fill the buffer with numbers for the payload
  107.                 for( i = 4; i < BufferSize; i++ )
  108.                 {
  109.                     Buffer[i] = i - 4;
  110.                 }

  111.                 Radio->SetTxPacket( Buffer, BufferSize );
  112.             }
  113.         }
  114.         break;
  115.     case RF_TX_DONE:
  116.         // Indicates on a LED that we have sent a PONG
  117.         LedToggle( LED_RED );
  118.         Radio->StartRx( );
  119.         break;
  120.     default:
  121.         break;
  122.     }
  123. }


  124. /*
  125. * Main application entry point.
  126. */
  127. int main( void )
  128. {
  129.     BoardInit( );
  130.    
  131.     Radio = RadioDriverInit( );
  132.    
  133.     Radio->Init( );

  134.     Radio->StartRx( );
  135.    
  136.     while( 1 )
  137.     {
  138.         if( EnableMaster == true )
  139.         {
  140.             OnMaster( );
  141.         }
  142.         else
  143.         {
  144.             OnSlave( );
  145.         }   
  146. #if( PLATFORM == SX12xxEiger ) && ( USE_UART == 1 )

  147.         UartProcess( );
  148.         
  149.         {
  150.             uint8_t data = 0;
  151.             if( UartGetChar( &data ) == UART_OK )
  152.             {
  153.                 UartPutChar( data );
  154.             }
  155.         }
  156. #endif        
  157.     }
  158. #ifdef __GNUC__
  159.     return 0;
  160. #endif
  161. }
復制代碼

所有資料51hei提供下載:
SX12xxDrivers-V2.1.0.7z (820.95 KB, 下載次數: 46)



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品一区二区在线看 | 91人人在线| 九九热这里只有精品6 | 日韩视频在线免费观看 | 99re在线视频免费观看 | 国产69精品久久99不卡免费版 | 国产不卡在线播放 | 2021天天躁夜夜看 | 国产精品久久久久久久三级 | 日韩中文在线 | 综合精品在线 | 精品国产91乱码一区二区三区 | 一区二区三区中文字幕 | 亚洲电影第三页 | 亚洲欧美日韩国产综合 | www.五月天婷婷 | 国产人成在线观看 | 亚洲一区二区精品视频 | 国产欧美一区二区三区在线看 | 欧美日韩在线播放 | 天天射网站 | 一区二区三区视频在线免费观看 | 欧美一区二区三区一在线观看 | h片在线看 | 97精品超碰一区二区三区 | 成人美女免费网站视频 | 国产欧美精品 | 免费毛片网站 | 中文字幕在线欧美 | 亚洲精品一区在线观看 | 国产福利91精品一区二区三区 | 九九伊人sl水蜜桃色推荐 | 中国一级特黄真人毛片免费观看 | 毛片入口 | 久久国产美女视频 | 色婷婷国产精品综合在线观看 | 久久久久久免费毛片精品 | 天天色图| 91亚洲国产成人久久精品网站 | 欧美精品网站 | 亚洲va欧美va天堂v国产综合 |