From 0fe6b074f3f3994d87af195f37e349a83e27882c Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期六, 10 十二月 2022 16:55:40 +0800
Subject: [PATCH] FP0 fix utf8 char

---
 Inc/KMachine.h |  418 ++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 256 insertions(+), 162 deletions(-)

diff --git a/Inc/KMachine.h b/Inc/KMachine.h
index 827a591..15e119e 100644
--- a/Inc/KMachine.h
+++ b/Inc/KMachine.h
@@ -43,12 +43,86 @@
 typedef unsigned short WORD;
 typedef unsigned char BYTE;
 
+#define LoBofW(x) ((x)&0xff)
+#define HiBofW(x) (((x)>>8)&0xff)
+
+#define LoHofB(x) ((x)&0xf)
+#define HiHofB(x) (((x)>>4)&0xf)
+
+//  淇℃伅鍧�
+//  宸ュ巶鍙傛暟閰嶇疆鍧�
+//  鐢ㄦ埛/绯荤粺鍙傛暟閰嶇疆鍧�
+//  
+//
+
+typedef struct tagInfoBlock // 20 bytes
+{
+//	USHORT nBlockLenth;
+	USHORT nDeviceTypeVer;			//device type		x.y
+//	UCHAR nDevierVer;
+	USHORT ProgVer;					//prog version	x.y
+	USHORT KLinkVer;				//x.y
+	USHORT KBusVer;					//x.y
+	
+	UCHAR nCapacity1;				//	? K
+	UCHAR nCapacity2;				//	? k
+	
+	UCHAR nDInput;
+	UCHAR nDOutput;
+	UCHAR nAInput;
+	UCHAR nAOutput;
+	UCHAR nHInput;
+	UCHAR nHOutput;
+	UCHAR nExt1;
+	UCHAR nExt2;
+	UCHAR nLogSize;
+	UCHAR nPorts;
+	UCHAR nManSize;
+	UCHAR nAbility;
+	UCHAR nSwitchBits;
+	
+}stKMInfoBlock;
+
+/*
+typedef struct tagFactData
+{
+	USHORT Sign;					//
+	USHORT nLength;				//
+	UCHAR LOT_NO[16];			//
+	UINT MANDate;					//
+	UINT SN;							//
+	UINT REV1[24];				//
+	USHORT rev9;
+	USHORT CRC;
+	
+}stFactData;
+*/
+typedef struct tagFactoryData		//宸ュ巶閲忎骇鍙傛暟锛屾暟鎹�
+{
+	USHORT Sign1;
+	USHORT Seq1;
+	USHORT nModelNo;
+	USHORT nModelVer;
+	UINT nLotNo;
+ 	UINT nProductDateTime;
+	UINT SN1;
+	UINT nProtocalVer;
+	UINT nDefaultFunc;
+	UCHAR ModelStr[16];
+	UCHAR LOT_NO[16];			//
+	UCHAR SNStr[16];
+	unsigned short CRC1;
+	unsigned short EndSign1;
+	
+}stFactoryData,* pFactoryData;
+
+
 enum enStoreCfg
 {
+	CFG_VER		= 0x100,
 	START_SIGN = 0x55aa,
 	END_SIGN	=	0x5aa5,
 };
-
 
 enum enInputFilter
 {
@@ -71,15 +145,119 @@
 	Output_Set_1 = 2,
 };
 
+typedef struct tagPortStatus
+{
+	USHORT porttype;		//232,485,net , wireless// KLink, KBus, KNet, KWireless
+	UCHAR StationID;
+	UCHAR MaxStations;
+	UCHAR CurStations;
+	UCHAR Running;
+	UCHAR Health;
+};
+
 enum enPortType
 {
-	PortType_Com = 0,	//计算机通讯
-	PortType_Gen = 1,	//通用通讯,自由口
-	PortType_KLink = 2, //Klink通讯
-	PortType_KBus = 3, 	//KBus通讯
-	PortType_KNet = 4, 	// KNet通讯
-	PortType_ModbusRTU = 5, //Modbus RTU 通讯
+	PortType_Default = 0, //榛樿
+	PortType_KLink = 1, //KLink閫氳
+	PortType_KBus = 2, 	//KBus閫氳
+	PortType_KNet = 3, 	// KNet閫氳
+	PortType_ModbusRTU = 4, //Modbus RTU 閫氳
+	PortType_Com = 5,	//	璁$畻鏈洪�氳
+	PortType_Gen = 6,	//閫氱敤閫氳锛岃嚜鐢卞彛
 };
+
+typedef struct tagComPortParam			//4 Bytes
+{
+	USHORT WorkMode;				/* 0-5=Default,KLink,KBus,KNet,RTU,Com,Gen */
+	USHORT Station;					/* 0=From jumper */
+	USHORT BaudRate;       /* =*100 Baudrate at which running       */
+  USHORT ByteSize:2;        /* 0-1=Number of bits/byte, 7-8    */
+	USHORT Parity:4;					/* 0-4=None,Odd,Even,Mark,Space    */
+  USHORT StopBits:2;        /* 0,1,2 = 1, 1.5, 2               */
+	USHORT EndType:2;					/* 0=ByChar, 1= ByTime */
+  USHORT EofChar:4;         /* 0,1,2 = None, CR, CR+LF, ETX;  End of character  */
+	USHORT SofChar:2;					/* 0,1,2 = None, STX */
+	USHORT EndTime;						/*(*0.01mS) */
+	USHORT RecvAddr;
+	USHORT RecvSize;
+
+}stComPortParam, *pstComPortParam;
+
+//姣忎釜妯″潡鏈� 0/1/2/3/4/5/6/7/8涓� 閫氳port
+//涓嶉檺浜� UART, 缃戝彛锛屾棤绾匡紝鍗曟�荤嚎绛夛紝閮芥槸port
+//鐢氳嚦鍙互鏈夎櫄鎷熺殑port
+
+typedef struct tagPortStat
+{
+	UCHAR PortType;			//绔彛宸ヤ綔妯″紡
+	UCHAR nStation;			//鑷繁绔欏彿
+	UCHAR bWorking;			//宸ヤ綔涓�
+	UCHAR bBus;					//鎬荤嚎?,,鍏ㄥ弻宸�?
+	UCHAR bMaster;			//涓绘満
+	UCHAR nDevices;			//杩炴帴鐨勮澶囨暟閲�//涓嶅寘鎷嚜宸� //device list;
+	
+}stPortStat,*pPortStat;
+
+typedef struct tagKMFuncParam
+{
+	USHORT EnablePLC:1;		//浣胯兘鍐呴儴PLC鍔熻兘
+	USHORT RunMode;				//宸ヤ綔妯″紡
+}stKMFuncParam;
+
+// 杈撳叆杈撳嚭鍦板潃鏄犲皠
+
+typedef struct tagInputFilterParam		// 1 Bytes
+{
+	BYTE Filter0:4;
+	BYTE Filter1:4;
+
+}stInputFilterParam;
+
+typedef struct tagOutputHoldParam			//1 Bytes
+{
+	BYTE Hold1:4;
+	BYTE Hold2:4;
+}stOutputHoldParam;	
+
+#pragma anon_unions
+typedef struct tagKMSysCfg		//120 Bytes total
+{
+	USHORT Version;										// SC0	// 2 Bytes
+	USHORT workmode;									// SC1  // 2 Bytes 0=From jumper  
+	USHORT SwitchFunc;								// SC2  // 2 Bytes 
+	USHORT pad1;											// 2 Bytes
+	
+	stComPortParam PortParams[2];							// 8 Bytes
+	stInputFilterParam InputParams[16];				//16 Bytes
+	stOutputHoldParam OutputParams[16];				//16 Bytes
+	USHORT OutMappings[6];				//12 Bytes //杈撳嚭鏄犲皠
+	
+	UINT cfgvar3;															// 4 Bytes
+	UINT cfgvar4;															// 4 Bytes
+	UINT cfgvar5;															// 4 Bytes
+	UINT cfgvar6;															// 4 Bytes
+	UINT cfgvar7;															// 4 Bytes
+	UINT cfgvar8;															// 4 Bytes
+	UINT cfgvar9;															// 4 Bytes
+	UINT cfgvar10;														// 4 Bytes
+	UINT cfgvar11;														// 4 Bytes
+	UINT cfgvar12;														// 4 Bytes
+//	UINT cfgvar13;														// 4 Bytes
+//	UINT cfgvar14;														// 4 Bytes
+//	UINT cfgvar15;														// 4 Bytes
+//	UINT cfgvar16;														// 4 Bytes
+//	UINT Space1[4];														//16 Bytes
+
+}stKMSysCfg,* pKMSysCfg;
+
+typedef struct tagStoredKMSysCfg
+{
+	unsigned short Sign1;
+	unsigned short Seq1;
+	stKMSysCfg theKMSysCfg;
+	unsigned short CRC1;
+	unsigned short EndSign1;
+}stStoredKMSysCfg,*pStoredKMSysCfg;
 
 enum enKeventType
 {
@@ -98,117 +276,6 @@
 	
 	EventType
 };
-typedef struct tagInfoBlock
-{
-	USHORT nDeviceType;
-	USHORT ProgVer;
-	USHORT KlinkVer;
-	USHORT nCapacity;
-	UCHAR nDInput;
-	UCHAR nDOutput;
-	UCHAR nAInput;
-	UCHAR nAOutput;
-	UCHAR nHInput;
-	UCHAR nHOutput;
-	UCHAR nExt1;
-	UCHAR nEXT2;
-	
-}stKMInfoBlock;
-
-typedef struct tagKMFuncParam
-{
-	USHORT EnablePLC:1;		//使能内部PLC功能
-	USHORT RunMode;				//工作模式
-}stKMFuncParam;
-
-// 输入输出地址映射
-
-typedef struct tagComPortParam
-{
-	USHORT PortType:4;				/* 0-5=Com,Gen,KLink,KBus,KNet,RTU */
-  USHORT ByteSize:2;        /* 0-1=Number of bits/byte, 7-8    */
-	USHORT Parity:4;					/* 0-4=None,Odd,Even,Mark,Space    */
-  USHORT StopBits:2;        /* 0,1,2 = 1, 1.5, 2               */
-  USHORT EofChar:2;         /* 0,1,2 = None, CR, CR+LF, ETX;  End of character  */
-	USHORT SofChar:2;					/* 0,1,2 = None, STX */
-	USHORT BaudRate;       /* =*100 Baudrate at which running       */
-}stComPortParam;
-
-typedef struct tagInputFilterParam
-{
-	BYTE Filter0:4;
-	BYTE Filter1:4;
-
-}stInputFilterParam;
-
-typedef struct tagOutputHoldParam
-{
-	BYTE Hold1:4;
-	BYTE Hold2:4;
-}stOutputHoldParam;	
-
-#pragma anon_unions
-typedef struct tagMSysCfg
-{
-	unsigned short Sign1;
-	unsigned short Seq1;
-	UINT cfgvar2;
-	stComPortParam Ports[2];
-	stOutputHoldParam OutputParams[16];
-	stInputFilterParam InputParams[16];
-	
-	UINT cfgvar3;
-	UINT cfgvar4;
-	UINT cfgvar5;
-	UINT cfgvar6;
-	UINT cfgvar7;
-	UINT cfgvar8;
-	UINT cfgvar9;
-	UINT cfgvar10;
-	UINT cfgvar11;
-	UINT cfgvar12;
-	UINT cfgvar13;
-	UINT cfgvar14;
-	UINT cfgvar15;
-	UINT cfgvar16;
-	UINT Space1[5];
-
-	unsigned short CRC1;
-	unsigned short EndSign1;
-}stKMSysCfg,* pKMSysCfg;
-
-/*
-typedef struct tagFactData
-{
-	USHORT Sign;					//
-	USHORT nLength;				//
-	UCHAR LOT_NO[16];			//
-	UINT MANDate;					//
-	UINT SN;							//
-	UINT REV1[24];				//
-	USHORT rev9;
-	USHORT CRC;
-	
-}stFactData;
-*/
-typedef struct tagFactoryData		//工厂量产参数,数据
-{
-	USHORT Sign1;
-	USHORT Seq1;
-	USHORT nModelNo;
-	USHORT nModelVer;
-	UINT nLotNo;
- 	UINT nProductDateTime;
-	UINT SN1;
-	UINT nProtocalVer;
-	UINT nDefaultFunc;
-	UCHAR ModelStr[16];
-	UCHAR LOT_NO[16];			//
-	UCHAR SNStr[16];
-	unsigned short CRC1;
-	unsigned short EndSign1;
-	
-}stFactoryData,* pFactoryData;
 
 typedef struct tagEventLog
 {
@@ -232,7 +299,8 @@
 	volatile unsigned short WorkMode2;
 	volatile unsigned short nBinProgBank;
 	volatile unsigned short nBinProgSize;
-	unsigned int Reserved2[1];
+	unsigned short bLEDFlick;
+	unsigned short Reserved2[1];
 	unsigned short CRC1;
 	unsigned short EndSign1;
 }stRunStat, *pRunStat;
@@ -242,7 +310,7 @@
 //stStoreCfg * GetCurStoreCfgAddr(void );
 //stStoreCfg * GetNextStoreCfgAddr(stStoreCfg * CurCfg );
 
-extern stKMSysCfg KMSysCfg;
+extern stStoredKMSysCfg storedKMSysCfg;
 
 #define TYPECOIL 0x00
 #define TYPEDATA 0x80
@@ -278,40 +346,11 @@
 		KLDataTypeLD = 13 | TYPEDATA,
 		KLDataSysCfg = 25 | TYPEDATA,
 		KLDataTypeFlash = 33 | TYPEDATA,
+		KLDataTypeWDT = 41 | TYPEDATA,
+		KLDataTypeKBD = 51 | TYPEDATA,
 		KLDataTypeTest = 254 | TYPEDATA,
 	};
 	
-enum enKLDataCounts
-	{
-		KLDataDTCount = 256,
-		KLDataSDTCount = 256,
-
-		KLDataWXCount = 16,
-		KLDataWYCount = 16,
-		KLDataWRCount = 16,
-		KLDataLDCount = 64,
-		KLDataWLCount = 8, 
-		
-		KLCoilXCount = KLDataWXCount * 16,
-		KLCoilYCount = KLDataWYCount * 16,
-		KLCoilRCount = KLDataWRCount * 16,
-
-		KLCoilTCount = 64,
-		KLCoilCCount = KLCoilTCount,
-
-		KLDataSVCount = KLCoilTCount,
-		KLDataEVCount = KLCoilTCount,
-
-		KLCoilLXCount = 128,
-		KLCoilLYCount = 128,
-		KLCoilLRCount = 128,
-		KLCoilSRCount = 128,
-
-	};
-#define TOTAL_WDFS (16)		//Total DF Count
-#define TOTAL_CurVAL (16)		//
-#define TOTALTIMERS (64)
-
 typedef struct tagTimerStat
 {
 	unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
@@ -342,15 +381,55 @@
 	};
 }stTimer;
 
+#define TOTAL_WDFS (32)		//Total DF Count
+#define TOTAL_CurVAL (16)		//
+#define TOTALTIMERS (64)
+
+enum enKLDataCounts
+	{
+
+		KLDataWXCount = 16,
+		KLDataWYCount = 16,
+		KLDataWRCount = 16,
+		KLDataLDCount = 64,
+		KLDataWLCount = 8, 
+		
+		KLCoilXCount = KLDataWXCount * 16,
+		KLCoilYCount = KLDataWYCount * 16,
+		KLCoilRCount = KLDataWRCount * 16,
+
+		KLCoilTCount = 64,
+		KLCoilCCount = KLCoilTCount,
+
+		KLDataSVCount = KLCoilTCount,
+		KLDataEVCount = KLCoilTCount,
+
+		KLCoilLXCount = 128,
+		KLCoilLYCount = 128,
+		KLCoilLRCount = 128,
+		KLCoilSRCount = 128,
+
+		KLDataDTCount = 128,
+		KLDataSDTCount = 128,
+		KLDataWDTCount = 128,
+
+	};
+
 typedef struct tagKMem
 {
 	unsigned short WDFs[TOTAL_WDFS];
 	unsigned char CurVALs[TOTAL_CurVAL];
 	unsigned char CurVAL;
 	stTimer Timers[TOTALTIMERS];
-	
-	unsigned short WX[KLDataWXCount];		//本机的X和Y
-	unsigned short WY[KLDataWYCount];		//本机的X和Y
+
+	union {
+	unsigned short WX[KLDataWXCount];		//鏈満鐨刋鍜孻
+	unsigned char WXB[KLDataWXCount*2];	
+	};
+	union {
+	unsigned short WY[KLDataWYCount];		//鏈満鐨刋鍜孻
+	unsigned char WYB[KLDataWYCount*2];		//鏈満鐨刋鍜孻
+	}; 
 	unsigned short WR[KLDataWRCount];
 	
 	unsigned short WT[16];
@@ -360,17 +439,21 @@
 	unsigned short SV[KLDataSVCount];
 	
 	
-	unsigned short WLX[16];		//虚拟的X和Y,远程通讯时映射用。
+	unsigned short WLX[16];		//铏氭嫙鐨刋鍜孻锛岃繙绋嬮�氳鏃舵槧灏勭敤銆�
 	unsigned short WLY[16];
 	unsigned short WLR[16];	
 	unsigned short WSR[16];
 
+union {
+	unsigned int DTD[KLDataDTCount/2];
 	unsigned short DT[KLDataDTCount];
-	
-	// 配置寄存器
-	// 系统状态寄存器
-	// 特殊寄存器
-	// 调试,监控寄存器
+	unsigned char DTB[KLDataDTCount*2];
+};
+
+	// 閰嶇疆瀵勫瓨鍣�
+	// 绯荤粺鐘舵�佸瘎瀛樺櫒
+	// 鐗规畩瀵勫瓨鍣�
+
 	union {
 		unsigned int SDD[KLDataSDTCount/2];
 		unsigned short SDT[KLDataSDTCount];
@@ -399,11 +482,22 @@
 			unsigned short ADCValues[20];
 		};
 	};
+	// 璋冭瘯锛岀洃鎺у瘎瀛樺櫒
+	union {
+		unsigned int WDD[KLDataWDTCount/2];
+		unsigned short WDT[KLDataWDTCount];
+		unsigned char WDB[KLDataWDTCount*2];
+	};
+	
 }stKMem;
 
 
 extern stKMem KMem;
 extern const stKMInfoBlock KMInfoBlock;
+
+extern volatile int PowerDownEvent;
+extern volatile int OldPowerDownEvent;
+extern volatile int OldPowerDownEventTime;
 
 int KMachineInit(void);
 int ReadFlashMem(void * pBuf, void * pAddrFlash, int nByteSize);
@@ -417,8 +511,8 @@
 int ReadProgram(int nProgByteAddr, void *pBuf, int nByteSize, int nBank);
 int WriteProgram(int nProgByteAddr, void * pBuf, int nByteSize, int nBank);
 
-int WriteSysCfgToFlash(pKMSysCfg theKMSysCfg);
-int ReadSysCfgFromFlash(pKMSysCfg theKMSysCfg);
+int WriteSysCfgToFlash(pStoredKMSysCfg theStoredKMSysCfg);
+int ReadSysCfgFromFlash(pStoredKMSysCfg theStoredKMSysCfg);
 
 int AddEventLog(uint32_t nTime, USHORT nEvent, USHORT nParam1, UINT nParam2);
 pEventLog GetEventLogAddr(int nIndex);

--
Gitblit v1.9.1