提交 | 用户 | 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 |
|
842bb6
|
41 |
#define STORE_KWCONFIG_BASE (FLASH_BASE + 0x0000F000) //50k K //and |
Q |
42 |
//#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K |
|
43 |
#define STORE_KWCONFIG_PAGES 1 //use 1 pages |
|
44 |
|
|
45 |
enum enWLWorkMode |
|
46 |
{ |
|
47 |
WLWorkModeNone, // |
|
48 |
WLWorkModeUni, // 一对一 |
|
49 |
WLWorkModeMul, // 一对多 |
|
50 |
WLWorkModeThr, // 透传 |
|
51 |
|
|
52 |
}; |
|
53 |
|
|
54 |
typedef struct tagWLConfig |
|
55 |
{ |
|
56 |
uint32_t RF_T_Freq; //Hz |
|
57 |
uint32_t RF_R_Freq; //Hz |
|
58 |
uint16_t nChnSpacing; //kHz |
|
59 |
uchar workMode; //0: FSK, 1: LoRa |
|
60 |
uchar Tx_Power; // dBm 5 - 22 dBm |
|
61 |
uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
|
62 |
uchar LoRaFactor; // [SF5 .. SF 12] |
|
63 |
uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7, 4: 4/8 ] |
|
64 |
uint8_t NetWorkAddr; |
|
65 |
uint16_t DeviceAddr; |
|
66 |
uchar bEnableAddr; |
|
67 |
uchar bEnableEncrypt; |
|
68 |
uchar bEnableRelay; |
|
69 |
uchar LoRaPreambleLen; // 2 - 12 |
|
70 |
uchar bAutoReSend; //自动重发 |
|
71 |
|
|
72 |
|
|
73 |
// uchar ; // |
|
74 |
// uchar |
|
75 |
|
|
76 |
}stWLConfig, *pstWLConfig; |
|
77 |
|
|
78 |
typedef struct tagStoredWLConfig |
|
79 |
{ |
|
80 |
unsigned short BlockSign; |
|
81 |
unsigned char BlockType; |
|
82 |
unsigned char nSeq; |
|
83 |
unsigned short nSize; |
|
84 |
unsigned short nCRC16; |
|
85 |
stWLConfig WLConfig; |
|
86 |
}stStoredWLConfig, *pstStoredWLConfig; |
|
87 |
|
|
88 |
|
483170
|
89 |
typedef enum tag_runstep{ |
Q |
90 |
RS_IDEL, |
|
91 |
RS_SENDING, |
|
92 |
RS_RECVING, |
|
93 |
}enRunStep; |
8b51c7
|
94 |
|
842bb6
|
95 |
#pragma anon_unions |
483170
|
96 |
typedef struct tagWLStat |
Q |
97 |
{ |
842bb6
|
98 |
union { |
Q |
99 |
uint32_t Status; //状态 |
|
100 |
struct { |
|
101 |
uint32_t bMasterSent:1; |
|
102 |
uint32_t bMasterRecved:1; |
|
103 |
}; |
|
104 |
}; |
|
105 |
uint16_t curStat; //当前状态 |
|
106 |
uint16_t runStep; //工作步骤 |
|
107 |
|
|
108 |
uint16_t RunStat; //运行状态 |
|
109 |
uint16_t ErrStat; //错误状态 |
|
110 |
|
|
111 |
uint32_t RF_Freq; //运行频率 |
|
112 |
uint16_t nTimeOnAir; |
|
113 |
uint16_t DeviceAddr; |
|
114 |
|
|
115 |
uint8_t NetWorkAddr; |
|
116 |
|
|
117 |
uchar Tx_Power; // dBm 5 - 22 dBm |
|
118 |
uchar LoraBandWidth; // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved ] |
|
119 |
uchar LoRaFactor; // [SF5 .. SF 12] |
|
120 |
uchar LoRaCodingRate; // [1 : 4/5, 2: 4/6, 3: 4/7, 4: 4/8 ] |
|
121 |
|
|
122 |
uchar LoRaPreambleLen; // 2 - 12 |
|
123 |
|
|
124 |
uchar bEnableAddr; |
|
125 |
uchar bEnableEncrypt; |
|
126 |
uchar bEnableRelay; |
|
127 |
uchar bAutoReSend; //自动重发 |
|
128 |
|
483170
|
129 |
uint32_t sentCount; //发送计数 |
Q |
130 |
uint32_t recvCount; //接收计数 |
|
131 |
uint32_t lastSendtime; //上次发送时间 |
eaf5d5
|
132 |
uint32_t lastSenttime; //上次发完时间 |
483170
|
133 |
uint32_t lastRecvtime; //上次启动接收时间 |
eaf5d5
|
134 |
uint32_t lastRecvdtime; //上次收到时间 |
483170
|
135 |
uint32_t lastActTime; //上次动作时间 |
Q |
136 |
uint32_t lastAckTime; //上次应答时间 |
eaf5d5
|
137 |
uint32_t lastErrTime; //上次错误时间 |
483170
|
138 |
uint32_t latancy; //延迟 |
Q |
139 |
uint32_t cycleTime; //循环时间 |
842bb6
|
140 |
uint16_t LostPackets; //丢包计数 |
Q |
141 |
uint16_t CtnLstPkts; //连续丢包计数 |
|
142 |
uint16_t MaxCtnLstPkts; //最大连续丢包计数 |
|
143 |
uint16_t TXErr; //发送错误计数 |
|
144 |
uint16_t RXErr; //接收错误计数 |
|
145 |
uint16_t CRCErr; //CRC错误计数 |
|
146 |
uint16_t ChnErr; //频道错误 |
|
147 |
uint16_t PktErr; //包错误 |
|
148 |
uint16_t CADDoneCount; //CAD 完成次数 |
|
149 |
uint16_t StepErr1; //步骤错误1 |
|
150 |
uint16_t StepErr2; //步骤错误2 |
|
151 |
uint16_t Err1Count; //微闪报警次数 |
|
152 |
uint16_t Err2Count; //大闪报警次数 |
|
153 |
uint16_t Err3Count; //严重丢失信号次数 |
eaf5d5
|
154 |
|
483170
|
155 |
int8_t RSSI; //信号强度 |
Q |
156 |
int8_t SNR; //信噪比 |
|
157 |
int8_t tRSSI; //对方信号强度 |
|
158 |
int8_t tSNR; //对方信噪比 |
|
159 |
|
eaf5d5
|
160 |
uint32_t targetSentCount; //对方发送数量 |
Q |
161 |
uint32_t targetRecvdCount; //对方接受数量 |
|
162 |
|
|
163 |
}stWLRunStat,*pstWLRunStat; |
483170
|
164 |
|
eaf5d5
|
165 |
enum { |
Q |
166 |
enReqSign = 0x55, |
|
167 |
enRplySign = 0xAA, |
|
168 |
|
|
169 |
}; |
|
170 |
|
|
171 |
typedef struct tagKLPacket |
|
172 |
{ |
|
173 |
uchar STSign; |
|
174 |
uchar DstAddr; |
|
175 |
uchar Func; |
|
176 |
uchar Stat; |
|
177 |
uchar Data[1]; |
|
178 |
|
|
179 |
}stKLPacket, *pstKLPacket; |
483170
|
180 |
|
842bb6
|
181 |
int LoadKwConfig(void); |
Q |
182 |
int SaveKwConfig(void); |
8b51c7
|
183 |
|
483170
|
184 |
int KWireLessInit(bool bRadioEnableMaster, uint32_t nChn); |
Q |
185 |
int KWireLessStart(void); |
|
186 |
|
|
187 |
void OnTxDone( void ); |
|
188 |
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); |
|
189 |
void OnTxTimeout( void ); |
|
190 |
void OnRxTimeout( void ); |
|
191 |
void OnRxError( void ); |
|
192 |
void OnCadDone( bool channelActivityDetected); |
|
193 |
|
|
194 |
|
|
195 |
void LedToggle(void); |
|
196 |
|
|
197 |
|
|
198 |
int KWL_Process(int nChn); |
|
199 |
|
|
200 |
int KWLMasterProc(int nChn); |
|
201 |
int KWLSlaveProc(int nChn); |
|
202 |
|
eaf5d5
|
203 |
int KWLMasterParsePkt(int nChn, int nSize); |
Q |
204 |
int KWLSlaveParsePkt(int nChn, int nSize); |
483170
|
205 |
|
Q |
206 |
int KWLMasterSendReqPkt(int nChn); |
|
207 |
int KWLSlaveSendRplyPkt(int nChn); |
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
int KWMasterProc(void); |
|
214 |
int KWSlaveProc(void); |
|
215 |
int MkKwPkg(void* pPkg, int len); |
|
216 |
|
|
217 |
int KWSendPkg(void* pPkg, int len); |
|
218 |
int KWProcPkg(void); |
8b51c7
|
219 |
|
Q |
220 |
extern uchar nRadioChannel; |
|
221 |
extern uchar nRadioAddr; |
|
222 |
|
842bb6
|
223 |
extern stWLConfig WLCfg ; |
8b51c7
|
224 |
extern stWLRunStat KwRunStat; |
Q |
225 |
|
|
226 |
|
483170
|
227 |
#endif ///* __KBUS_H__ */ |
Q |
228 |
|