/** ****************************************************************************** * @file : KWireLess.h * @brief : Header for KWireLess.c file. * This file contains the common defines of the application. ****************************************************************************** */ #include "KMachine.h" #include #include "user.h" #include "radio/inc/sx126x-board.h" #ifndef __KWIRELESS_H__ #define __KWIRELESS_H__ typedef unsigned char uchar; /************************************************************************************************************************************** Demo 程序流程 RadioEnableMaster=true 为主机端,主机端发送一个"PING"数据后切换到接收,等待从机返回的应答"PONG"数据LED闪烁 RadioEnableMaster=false 为从机端,从机端接收到主机端发过来的"PING"数据后LED闪烁并发送一个"PONG"数据作为应答 ***************************************************************************************************************************************/ typedef enum tag_KWStates { KW_PON, KW_UNINIT, KW_INITED, KW_UNCONFIGED, KW_CONFIGING, KW_CONFIGED, KW_READY, KW_STARTING, KW_OPERATION, KW_ERROR1, KW_ERROR2, KW_ERROR3, }KWStates; typedef enum tag_runstep{ RS_IDEL, RS_SENDING, RS_RECVING, }enRunStep; typedef struct tagWLStat { uint32_t Stat; //状态 uint32_t curStat; //当前状态 uint32_t runStep; //工作步骤 uint32_t sentCount; //发送计数 uint32_t recvCount; //接收计数 uint32_t lastSendtime; //上次发送时间 uint32_t lastSenttime; //上次发完时间 uint32_t lastRecvtime; //上次启动接收时间 uint32_t lastRecvdtime; //上次收到时间 uint32_t lastActTime; //上次动作时间 uint32_t lastAckTime; //上次应答时间 uint32_t lastErrTime; //上次错误时间 uint32_t latancy; //延迟 uint32_t cycleTime; //循环时间 uint32_t LostPackets; //丢包计数 uint32_t CtnLstPkts; //连续丢包计数 uint32_t MaxCtnLstPkts; //最大连续丢包计数 uint32_t TXErr; //发送错误计数 uint32_t RXErr; //接收错误计数 uint32_t CRCErr; //CRC错误计数 uint32_t CADDoneCount; //CAD 完成次数 uint32_t StepErr1; //步骤错误1 uint32_t StepErr2; //步骤错误2 uint32_t Err1Count; //微闪报警次数 uint32_t Err2Count; //大闪报警次数 uint32_t Err3Count; //严重丢失信号次数 int8_t RSSI; //信号强度 int8_t SNR; //信噪比 int8_t tRSSI; //对方信号强度 int8_t tSNR; //对方信噪比 uint32_t targetSentCount; //对方发送数量 uint32_t targetRecvdCount; //对方接受数量 }stWLRunStat,*pstWLRunStat; enum { enReqSign = 0x55, enRplySign = 0xAA, }; typedef struct tagWLConfig { uint32_t RF_Freq; uint32_t ChannelSpacing; uchar Tx_Power; uchar workMode; //0: FSK, 1: LoRa uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] uchar LoRaFactor; // [SF5 .. SF 12] uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7 uchar LoRaPreamble_Len; // 2 - 12 // uchar ; // // uchar }stWLConfig; typedef struct tagKLPacket { uchar STSign; uchar DstAddr; uchar Func; uchar Stat; uchar Data[1]; }stKLPacket, *pstKLPacket; int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn); int KWireLessStart(void); void OnTxDone( void ); void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); void OnTxTimeout( void ); void OnRxTimeout( void ); void OnRxError( void ); void OnCadDone( bool channelActivityDetected); void LedToggle(void); int KWL_Process(int nChn); int KWLMasterProc(int nChn); int KWLSlaveProc(int nChn); int KWLMasterParsePkt(int nChn, int nSize); int KWLSlaveParsePkt(int nChn, int nSize); int KWLMasterSendReqPkt(int nChn); int KWLSlaveSendRplyPkt(int nChn); int KWMasterProc(void); int KWSlaveProc(void); int MkKwPkg(void* pPkg, int len); int KWSendPkg(void* pPkg, int len); int KWProcPkg(void); extern uchar nRadioChannel; extern uchar nRadioAddr; extern stWLRunStat KwRunStat; #endif ///* __KBUS_H__ */