From 7d8ba5df7d883c86c24aa38449c4a6dd126e920f Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期二, 06 八月 2024 14:41:31 +0800
Subject: [PATCH] Radio_LLCC68 1.15, Stable version

---
 Radio_LLCC68/Radio/KWireLess.h |  163 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 146 insertions(+), 17 deletions(-)

diff --git a/Radio_LLCC68/Radio/KWireLess.h b/Radio_LLCC68/Radio/KWireLess.h
index be3cef1..f7ebad2 100644
--- a/Radio_LLCC68/Radio/KWireLess.h
+++ b/Radio_LLCC68/Radio/KWireLess.h
@@ -38,42 +38,163 @@
 	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
+	uint16_t nCycleTime;			//
+	uchar workMode;			//0: FSK,    1: LoRa	
+	uchar nChannel;
+	uchar bMaster;
+	uchar nRadioAddr;
+	uchar bEnableMulti;
+	
+	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 bAutoPower;				//鑷姩鍔熺巼
+	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_IDLE,
+	RS_MASTER_CAD,
 	RS_SENDING,
+	RS_SENT,
 	RS_RECVING,
+	RS_RECVED,
 }enRunStep;
+
+#pragma anon_unions
 typedef struct tagWLStat
 {
-	uint32_t Stat;							//鐘舵��
-	uint32_t curStat;						//褰撳墠鐘舵��
-	uint32_t runStep;						//宸ヤ綔姝ラ
+	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 lastSenttime;			//涓婃鍙戝畬鏃堕棿
 	uint32_t lastRecvtime;			//涓婃鍚姩鎺ユ敹鏃堕棿
-	uint32_t lastRecvdtime;			//涓婃鎺ユ敹鏃堕棿
+	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閿欒璁℃暟
+	
+	uint16_t LostPackets;				//涓㈠寘璁℃暟
+	uint16_t CtnLstPkts;				//杩炵画涓㈠寘璁℃暟
+	uint16_t MaxCtnLstPkts;			//鏈�澶ц繛缁涪鍖呰鏁�
+	uint16_t TXErr;							//鍙戦�侀敊璇鏁�
+	uint16_t RXErr;							//鎺ユ敹閿欒璁℃暟
+	uint16_t CRCErr; 						//CRC閿欒璁℃暟
+	uint16_t PktErr;						//鍖呴敊璇�	;
+	uint16_t ChnErr;						//棰戦亾閿欒;
+	uint16_t nErrChn;						//閿欒鐨勯閬撳彿;
+	uint16_t CADDoneCount;			//CAD 瀹屾垚娆℃暟
+	uint16_t CADOkCount;				//CAD 鏄鏁�
+	uint16_t CADNgCount;				//CAD 鍚︽鏁�
+	uint16_t CADTimeOut;				//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;							//瀵规柟淇″櫔姣�
 	
-}stWLRunStat;
+	uint32_t targetSentCount;			//瀵规柟鍙戦�佹暟閲�
+	uint32_t targetRecvdCount;		//瀵规柟鎺ュ彈鏁伴噺
+	
+}stWLRunStat,*pstWLRunStat;
 
+enum {
+	enReqSign = 0x55,
+	enRplySign = 0xAA,
+	
+};
 
-extern uint32_t nRadioChannel;
-extern stWLRunStat KwRunStat;
+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);
 
@@ -93,8 +214,8 @@
 int KWLMasterProc(int nChn);
 int KWLSlaveProc(int nChn);
 
-int KWLMasterParsePkt(int nChn);
-int KWLSlaveParsePkt(int nChn);
+int KWLMasterParsePkt(int nChn, int nSize);
+int KWLSlaveParsePkt(int nChn, int nSize);
 
 int KWLMasterSendReqPkt(int nChn);
 int KWLSlaveSendRplyPkt(int nChn);
@@ -109,5 +230,13 @@
 
 int KWSendPkg(void* pPkg, int len);
 int KWProcPkg(void);
+
+//extern uchar nRadioChannel;
+//extern uchar nRadioAddr;
+
+extern stWLConfig WLCfg ;
+extern stWLRunStat KwRunStat;
+
+
 #endif ///*  __KBUS_H__  */
 

--
Gitblit v1.9.1