From 4392349b649164f2b498ca5157ecd141631ea96f Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期三, 01 二月 2023 18:18:47 +0800 Subject: [PATCH] KBus fix project name --- Src/KWireLess.c | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Src/KWireLess.c b/Src/KWireLess.c index 061e5d1..91bc065 100644 --- a/Src/KWireLess.c +++ b/Src/KWireLess.c @@ -12,9 +12,9 @@ /************************************************************************************************************************************** -Demo 程序流程 RadioEnableMaster=true 为主机端,主机端发送一个"PING"数据后切换到接收,等待从机返回的应答"PONG"数据LED闪烁 +Demo 绋嬪簭娴佺▼ RadioEnableMaster=true 涓轰富鏈虹锛屼富鏈虹鍙戦�佷竴涓�"PING"鏁版嵁鍚庡垏鎹㈠埌鎺ユ敹锛岀瓑寰呬粠鏈鸿繑鍥炵殑搴旂瓟"PONG"鏁版嵁LED闂儊 - RadioEnableMaster=false 为从机端,从机端接收到主机端发过来的"PING"数据后LED闪烁并发送一个"PONG"数据作为应答 + RadioEnableMaster=false 涓轰粠鏈虹锛屼粠鏈虹鎺ユ敹鍒颁富鏈虹鍙戣繃鏉ョ殑"PING"鏁版嵁鍚嶭ED闂儊骞跺彂閫佷竴涓�"PONG"鏁版嵁浣滀负搴旂瓟 ***************************************************************************************************************************************/ //#define USE_MODEM_LORA @@ -32,7 +32,7 @@ #elif defined( REGION_CN779 ) -#define RF_FREQUENCY 433100000 // Hz +#define RF_FREQUENCY 433000000 // Hz #elif defined( REGION_EU868 ) @@ -60,12 +60,13 @@ #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 @@ -132,14 +133,14 @@ 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; @@ -152,7 +153,8 @@ 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); @@ -204,7 +206,7 @@ - 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); @@ -234,7 +236,7 @@ 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); @@ -250,7 +252,7 @@ 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); @@ -259,7 +261,7 @@ 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; @@ -285,7 +287,7 @@ { 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]; } @@ -295,10 +297,13 @@ { 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 { -- Gitblit v1.9.1