| | |
| | |
|
| | |
|
| | | /**************************************************************************************************************************************
|
| | | Demo 程序流程 RadioEnableMaster=true 为主机端,主机端发送一个"PING"数据后切换到接收,等待从机返回的应答"PONG"数据LED闪烁
|
| | | Demo 程序流程 RadioEnableMaster=true 为主机端,主机端发送一个"PING"数据后切换到接收,等待从机返回的应答"PONG"数据LED闪烁
|
| | |
|
| | | RadioEnableMaster=false 为从机端,从机端接收到主机端发过来的"PING"数据后LED闪烁并发送一个"PONG"数据作为应答
|
| | | RadioEnableMaster=false 为从机端,从机端接收到主机端发过来的"PING"数据后LED闪烁并发送一个"PONG"数据作为应答
|
| | | ***************************************************************************************************************************************/
|
| | |
|
| | | //#define USE_MODEM_LORA
|
| | |
| | |
|
| | | #elif defined( REGION_CN779 )
|
| | |
|
| | | #define RF_FREQUENCY 433100000 // Hz
|
| | | #define RF_FREQUENCY 433000000 // Hz
|
| | |
|
| | | #elif defined( REGION_EU868 )
|
| | |
|
| | |
| | |
|
| | | #endif
|
| | |
|
| | | #define nChannelBandwidth 100000 // Hz
|
| | | #define TX_OUTPUT_POWER 22 // 22 dBm
|
| | |
|
| | | extern bool IrqFired;
|
| | |
|
| | | bool RadioEnableMaster=true;//主从选择
|
| | |
|
| | | bool RadioEnableMaster=true;//主从选择
|
| | | uint32_t nRadioChannel=0;
|
| | | uint16_t crc_value;
|
| | | /*!
|
| | | * Radio events function pointer
|
| | |
| | |
|
| | | void LedToggle(void)
|
| | | {
|
| | | // GPIO_WriteBit( LED1_PORT, LED1_PIN,Bit_RESET);//LED闪烁
|
| | | // GPIO_WriteBit( LED1_PORT, LED1_PIN,Bit_RESET);//LED闪烁
|
| | | // HAL_Delay_nMS(10);
|
| | | // GPIO_WriteBit( LED1_PORT, LED1_PIN,Bit_SET);
|
| | |
|
| | | LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_13);
|
| | | }
|
| | |
|
| | | int KWireLessInit(bool bRadioEnableMaster)
|
| | | int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn)
|
| | | {
|
| | |
|
| | | RadioEnableMaster = bRadioEnableMaster;
|
| | |
| | |
|
| | |
|
| | | Radio.Init( &RadioEvents );
|
| | | Radio.SetChannel( RF_FREQUENCY );
|
| | | nRadioChannel = nChn;
|
| | | Radio.SetChannel( RF_FREQUENCY + nRadioChannel * nChannelBandwidth );
|
| | |
|
| | | // Radio.WriteBuffer(0x06C0,data,2);
|
| | | // Radio.ReadBuffer(0x06C0,test,2);
|
| | |
| | |
|
| | |
|
| | |
|
| | | crc_value=RadioComputeCRC(TX_Buffer,8,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | crc_value=RadioComputeCRC(TX_Buffer,8,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | TX_Buffer[8]=crc_value>>8;
|
| | | TX_Buffer[9]=crc_value;
|
| | | Radio.Send( TX_Buffer, 10);
|
| | |
| | | TX_Buffer[6] = KMem.WY[2]>>8;
|
| | | TX_Buffer[7] = KMem.WY[2];
|
| | |
|
| | | crc_value=RadioComputeCRC(TX_Buffer,len1,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | crc_value=RadioComputeCRC(TX_Buffer,len1,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | TX_Buffer[len1]=crc_value>>8;
|
| | | TX_Buffer[len1+1]=crc_value;
|
| | | Radio.Send( TX_Buffer, len1+2);
|
| | |
| | | TX_Buffer[6] = KMem.WX[1]>>8;
|
| | | TX_Buffer[7] = KMem.WX[1];
|
| | |
|
| | | crc_value=RadioComputeCRC(TX_Buffer,len1,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | crc_value=RadioComputeCRC(TX_Buffer,len1,CRC_TYPE_IBM);//计算得出要发送数据包CRC值
|
| | | TX_Buffer[len1]=crc_value>>8;
|
| | | TX_Buffer[len1+1]=crc_value;
|
| | | Radio.Send( TX_Buffer, len1+2);
|
| | |
| | | void OnTxDone( void )
|
| | | {
|
| | | Radio.Standby();
|
| | | Radio.Rx( RX_TIMEOUT_VALUE ); //进入接收
|
| | | Radio.Rx( RX_TIMEOUT_VALUE ); //进入接收
|
| | | LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_14);
|
| | | int us2=GetuS();
|
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime;
|
| | |
| | | {
|
| | | if(memcmp(RX_Buffer,PongMsg,4)==0)
|
| | | {
|
| | | LedToggle();//LED闪烁
|
| | | LedToggle();//LED闪烁
|
| | | KMem.WX[1]=(RX_Buffer[4]<<8) + RX_Buffer[5];
|
| | | KMem.WX[2]=(RX_Buffer[6]<<8) + RX_Buffer[7];
|
| | | }
|
| | |
| | | {
|
| | | if(memcmp(RX_Buffer,PingMsg,4)==0)
|
| | | {
|
| | | LedToggle();//LED闪烁
|
| | | LedToggle();//LED闪烁
|
| | | SendPongMsg(size-2);
|
| | | KMem.WY[0]=(RX_Buffer[4]<<8) + RX_Buffer[5];
|
| | | KMem.WY[1]=(RX_Buffer[6]<<8) + RX_Buffer[7]; |
| | | KMem.WX[1]=(RX_Buffer[4]<<8) + RX_Buffer[5];
|
| | | KMem.WX[2]=(RX_Buffer[6]<<8) + RX_Buffer[7]; |
| | | |
| | | // KMem.WY[0]=(RX_Buffer[4]<<8) + RX_Buffer[5];
|
| | | // KMem.WY[1]=(RX_Buffer[6]<<8) + RX_Buffer[7]; |
| | | }
|
| | | else
|
| | | {
|