提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : KWireLess.h |
|
4 |
* @brief : Header for KWireLess.c file. |
|
5 |
* This file contains the common defines of the application. |
|
6 |
****************************************************************************** |
|
7 |
*/ |
|
8 |
#include "KMachine.h" |
|
9 |
#include <stdint.h> |
|
10 |
#include "user.h" |
|
11 |
|
|
12 |
#include "radio/inc/sx126x-board.h" |
|
13 |
|
|
14 |
|
|
15 |
#ifndef __KWIRELESS_H__ |
|
16 |
#define __KWIRELESS_H__ |
|
17 |
typedef unsigned char uchar; |
|
18 |
|
|
19 |
|
|
20 |
/************************************************************************************************************************************** |
|
21 |
Demo 程序流程 RadioEnableMaster=true 为主机端,主机端发送一个"PING"数据后切换到接收,等待从机返回的应答"PONG"数据LED闪烁 |
|
22 |
|
|
23 |
RadioEnableMaster=false 为从机端,从机端接收到主机端发过来的"PING"数据后LED闪烁并发送一个"PONG"数据作为应答 |
|
24 |
***************************************************************************************************************************************/ |
|
25 |
typedef enum tag_KWStates |
|
26 |
{ |
|
27 |
KW_PON, |
|
28 |
KW_UNINIT, |
|
29 |
KW_INITED, |
|
30 |
KW_UNCONFIGED, |
|
31 |
KW_CONFIGING, |
|
32 |
KW_CONFIGED, |
|
33 |
KW_READY, |
|
34 |
KW_STARTING, |
|
35 |
KW_OPERATION, |
|
36 |
KW_ERROR1, |
|
37 |
KW_ERROR2, |
|
38 |
KW_ERROR3, |
|
39 |
}KWStates; |
|
40 |
|
|
41 |
typedef enum tag_runstep{ |
|
42 |
RS_IDEL, |
|
43 |
RS_SENDING, |
|
44 |
RS_RECVING, |
|
45 |
}enRunStep; |
8b51c7
|
46 |
|
483170
|
47 |
typedef struct tagWLStat |
Q |
48 |
{ |
|
49 |
uint32_t Stat; //状态 |
|
50 |
uint32_t curStat; //当前状态 |
|
51 |
uint32_t runStep; //工作步骤 |
|
52 |
uint32_t sentCount; //发送计数 |
|
53 |
uint32_t recvCount; //接收计数 |
|
54 |
uint32_t lastSendtime; //上次发送时间 |
eaf5d5
|
55 |
uint32_t lastSenttime; //上次发完时间 |
483170
|
56 |
uint32_t lastRecvtime; //上次启动接收时间 |
eaf5d5
|
57 |
uint32_t lastRecvdtime; //上次收到时间 |
483170
|
58 |
uint32_t lastActTime; //上次动作时间 |
Q |
59 |
uint32_t lastAckTime; //上次应答时间 |
eaf5d5
|
60 |
uint32_t lastErrTime; //上次错误时间 |
483170
|
61 |
uint32_t latancy; //延迟 |
Q |
62 |
uint32_t cycleTime; //循环时间 |
|
63 |
uint32_t LostPackets; //丢包计数 |
|
64 |
uint32_t CtnLstPkts; //连续丢包计数 |
|
65 |
uint32_t MaxCtnLstPkts; //最大连续丢包计数 |
|
66 |
uint32_t TXErr; //发送错误计数 |
|
67 |
uint32_t RXErr; //接收错误计数 |
|
68 |
uint32_t CRCErr; //CRC错误计数 |
eaf5d5
|
69 |
uint32_t CADDoneCount; //CAD 完成次数 |
Q |
70 |
uint32_t StepErr1; //步骤错误1 |
|
71 |
uint32_t StepErr2; //步骤错误2 |
|
72 |
uint32_t Err1Count; //微闪报警次数 |
|
73 |
uint32_t Err2Count; //大闪报警次数 |
|
74 |
uint32_t Err3Count; //严重丢失信号次数 |
|
75 |
|
483170
|
76 |
int8_t RSSI; //信号强度 |
Q |
77 |
int8_t SNR; //信噪比 |
|
78 |
int8_t tRSSI; //对方信号强度 |
|
79 |
int8_t tSNR; //对方信噪比 |
|
80 |
|
eaf5d5
|
81 |
uint32_t targetSentCount; //对方发送数量 |
Q |
82 |
uint32_t targetRecvdCount; //对方接受数量 |
|
83 |
|
|
84 |
}stWLRunStat,*pstWLRunStat; |
483170
|
85 |
|
eaf5d5
|
86 |
enum { |
Q |
87 |
enReqSign = 0x55, |
|
88 |
enRplySign = 0xAA, |
|
89 |
|
|
90 |
}; |
|
91 |
|
8b51c7
|
92 |
typedef struct tagWLConfig |
Q |
93 |
{ |
|
94 |
uint32_t RF_Freq; |
|
95 |
uint32_t ChannelSpacing; |
|
96 |
uchar Tx_Power; |
|
97 |
|
|
98 |
uchar workMode; //0: FSK, 1: LoRa |
|
99 |
uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
|
100 |
uchar LoRaFactor; // [SF5 .. SF 12] |
|
101 |
uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7 |
|
102 |
uchar LoRaPreamble_Len; // 2 - 12 |
|
103 |
// uchar ; // |
|
104 |
// uchar |
|
105 |
|
|
106 |
}stWLConfig; |
|
107 |
|
|
108 |
|
eaf5d5
|
109 |
typedef struct tagKLPacket |
Q |
110 |
{ |
|
111 |
uchar STSign; |
|
112 |
uchar DstAddr; |
|
113 |
uchar Func; |
|
114 |
uchar Stat; |
|
115 |
uchar Data[1]; |
|
116 |
|
|
117 |
}stKLPacket, *pstKLPacket; |
483170
|
118 |
|
8b51c7
|
119 |
|
483170
|
120 |
int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn); |
Q |
121 |
int KWireLessStart(void); |
|
122 |
|
|
123 |
void OnTxDone( void ); |
|
124 |
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); |
|
125 |
void OnTxTimeout( void ); |
|
126 |
void OnRxTimeout( void ); |
|
127 |
void OnRxError( void ); |
|
128 |
void OnCadDone( bool channelActivityDetected); |
|
129 |
|
|
130 |
|
|
131 |
void LedToggle(void); |
|
132 |
|
|
133 |
|
|
134 |
int KWL_Process(int nChn); |
|
135 |
|
|
136 |
int KWLMasterProc(int nChn); |
|
137 |
int KWLSlaveProc(int nChn); |
|
138 |
|
eaf5d5
|
139 |
int KWLMasterParsePkt(int nChn, int nSize); |
Q |
140 |
int KWLSlaveParsePkt(int nChn, int nSize); |
483170
|
141 |
|
Q |
142 |
int KWLMasterSendReqPkt(int nChn); |
|
143 |
int KWLSlaveSendRplyPkt(int nChn); |
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
int KWMasterProc(void); |
|
150 |
int KWSlaveProc(void); |
|
151 |
int MkKwPkg(void* pPkg, int len); |
|
152 |
|
|
153 |
int KWSendPkg(void* pPkg, int len); |
|
154 |
int KWProcPkg(void); |
8b51c7
|
155 |
|
Q |
156 |
extern uchar nRadioChannel; |
|
157 |
extern uchar nRadioAddr; |
|
158 |
|
|
159 |
extern stWLRunStat KwRunStat; |
|
160 |
|
|
161 |
|
483170
|
162 |
#endif ///* __KBUS_H__ */ |
Q |
163 |
|