/**
|
******************************************************************************
|
* @file : KWireLess.h
|
* @brief : Header for KWireLess.c file.
|
* This file contains the common defines of the application.
|
******************************************************************************
|
*/
|
#include "KMachine.h"
|
#include <stdint.h>
|
#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;
|
|
#define STORE_KWCONFIG_BASE (FLASH_BASE + 0x0000F000) //50k K //and
|
//#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K
|
#define STORE_KWCONFIG_PAGES 1 //use 1 pages
|
|
enum enWLWorkMode
|
{
|
WLWorkModeNone, //
|
WLWorkModeUni, // 一对一
|
WLWorkModeMul, // 一对多
|
WLWorkModeThr, // 透传
|
|
};
|
|
typedef struct tagWLConfig
|
{
|
uint32_t RF_T_Freq; //Hz
|
uint32_t RF_R_Freq; //Hz
|
uint16_t nChnSpacing; //kHz
|
uchar workMode; //0: FSK, 1: LoRa
|
uchar Tx_Power; // dBm 5 - 22 dBm
|
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, 4: 4/8 ]
|
uint8_t NetWorkAddr;
|
uint16_t DeviceAddr;
|
uchar bEnableAddr;
|
uchar bEnableEncrypt;
|
uchar bEnableRelay;
|
uchar LoRaPreambleLen; // 2 - 12
|
uchar bAutoReSend; //自动重发
|
|
|
// uchar ; //
|
// uchar
|
|
}stWLConfig, *pstWLConfig;
|
|
typedef struct tagStoredWLConfig
|
{
|
unsigned short BlockSign;
|
unsigned char BlockType;
|
unsigned char nSeq;
|
unsigned short nSize;
|
unsigned short nCRC16;
|
stWLConfig WLConfig;
|
}stStoredWLConfig, *pstStoredWLConfig;
|
|
|
typedef enum tag_runstep{
|
RS_IDEL,
|
RS_SENDING,
|
RS_RECVING,
|
}enRunStep;
|
|
#pragma anon_unions
|
typedef struct tagWLStat
|
{
|
union {
|
uint32_t Status; //状态
|
struct {
|
uint32_t bMasterSent:1;
|
uint32_t bMasterRecved:1;
|
};
|
};
|
uint16_t curStat; //当前状态
|
uint16_t runStep; //工作步骤
|
|
uint16_t RunStat; //运行状态
|
uint16_t ErrStat; //错误状态
|
|
uint32_t RF_Freq; //运行频率
|
uint16_t nTimeOnAir;
|
uint16_t DeviceAddr;
|
|
uint8_t NetWorkAddr;
|
|
uchar Tx_Power; // dBm 5 - 22 dBm
|
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, 4: 4/8 ]
|
|
uchar LoRaPreambleLen; // 2 - 12
|
|
uchar bEnableAddr;
|
uchar bEnableEncrypt;
|
uchar bEnableRelay;
|
uchar bAutoReSend; //自动重发
|
|
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; //循环时间
|
uint16_t LostPackets; //丢包计数
|
uint16_t CtnLstPkts; //连续丢包计数
|
uint16_t MaxCtnLstPkts; //最大连续丢包计数
|
uint16_t TXErr; //发送错误计数
|
uint16_t RXErr; //接收错误计数
|
uint16_t CRCErr; //CRC错误计数
|
uint16_t ChnErr; //频道错误
|
uint16_t PktErr; //包错误
|
uint16_t CADDoneCount; //CAD 完成次数
|
uint16_t StepErr1; //步骤错误1
|
uint16_t StepErr2; //步骤错误2
|
uint16_t Err1Count; //微闪报警次数
|
uint16_t Err2Count; //大闪报警次数
|
uint16_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 tagKLPacket
|
{
|
uchar STSign;
|
uchar DstAddr;
|
uchar Func;
|
uchar Stat;
|
uchar Data[1];
|
|
}stKLPacket, *pstKLPacket;
|
|
int LoadKwConfig(void);
|
int SaveKwConfig(void);
|
|
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 stWLConfig WLCfg ;
|
extern stWLRunStat KwRunStat;
|
|
|
#endif ///* __KBUS_H__ */
|