From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期二, 24 十二月 2024 08:37:21 +0800
Subject: [PATCH] 2024-12-24

---
 MTerm1/KDefine.h |  314 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 294 insertions(+), 20 deletions(-)

diff --git a/MTerm1/KDefine.h b/MTerm1/KDefine.h
index 6fac2e0..fb45c92 100644
--- a/MTerm1/KDefine.h
+++ b/MTerm1/KDefine.h
@@ -109,15 +109,178 @@
 	Output_Set_1 = 2,
 };
 
-enum enPortType
+enum enPortHardType
 {
-	PortType_Com = 0,	//录脝脣茫禄煤脥篓脩露
-	PortType_Gen = 1,	//脥篓脫脙脥篓脩露拢卢脳脭脫脡驴脷
-	PortType_KLink = 2, //Klink脥篓脩露
-	PortType_KBus = 3, 	//KBus脥篓脩露
-	PortType_KNet = 4, 	// KNet脥篓脩露
-	PortType_ModbusRTU = 5, //Modbus RTU 脥篓脩露
+	PortHardType_None	=	0,	//	绌烘帴鍙�,鏃犵被鍨�
+	PortHardType_SOFT	=	1,	//	杞欢铏氭嫙鎺ュ彛,鍙兘鏄毀閬撶瓑.
+	PortHardType_UART	=	2,	//	涓茶鎺ュ彛
+	PortHardType_RS232	=	3,	//	232鎺ュ彛
+	PortHardType_RS485	=	4,	//	485鎺ュ彛
+	PortHardType_SLP	=	5,	//	鍗曟�荤嚎鎺ュ彛
+	PortHardType_RF		=	6,	//	鏃犵嚎鎺ュ彛
+	PortHardType_LORA	=	7,	//	LoRa鏃犵嚎鎺ュ彛
+	PortHardType_OPTI	=	8,	//	鍏夌氦鎺ュ彛
+	PortHardType_ETH	=	9,	//	浠ュお缃戞帴鍙�
+	PortHardType_WIFI	=	10,	//	WiFi鎺ュ彛
+	PortHardType_BT		=	11,	//	浠ュお缃戞帴鍙�
+
 };
+static CString PortHardTypeToStr(int nPortHardType)
+{
+	static CString s1;
+	switch (nPortHardType)
+	{
+	case PortHardType_None:
+		return _T("NULL");
+	case PortHardType_SOFT:		// = 1,	//	杞欢铏氭嫙鎺ュ彛,鍙兘鏄毀閬撶瓑.
+		return _T("Soft");
+	case PortHardType_UART:		// = 2,	//	涓茶鎺ュ彛
+		return _T("UART");
+	case PortHardType_RS232:	//= 3,	//	232鎺ュ彛
+		return _T("RS232");
+	case PortHardType_RS485:	//= 4,	//	485鎺ュ彛
+		return _T("RS485");
+	case PortHardType_SLP:		//= 5,	//	鍗曟�荤嚎鎺ュ彛
+		return _T("SLP");
+	case PortHardType_RF:		//= 6,	//	鏃犵嚎鎺ュ彛
+		return _T("RF");
+	case PortHardType_LORA:		//= 7,	//	LoRa鏃犵嚎鎺ュ彛
+		return _T("LoRa");
+	case PortHardType_OPTI:		//= 8,	//	鍏夌氦鎺ュ彛
+		return _T("Opti");
+	case PortHardType_ETH:		//= 9,	//	浠ュお缃戞帴鍙�
+		return _T("ETH");
+	case PortHardType_WIFI:		//= 10,	//	WiFi鎺ュ彛
+		return _T("WiFi");
+	case PortHardType_BT:		//= 11,	//	浠ュお缃戞帴鍙�		
+		return _T("BT");
+	default:
+		return _T("UNKNOWN");
+		break;
+	}
+}
+
+enum enPortUseType
+{
+	PortUse_Default = 0,	//榛樿
+	PortUse_Console = 1,	//鎺у埗鍙版帴鍙�
+	PortUse_KLink = 2,		//KLink閫氳
+	PortUse_KBus = 3, 		//KBus閫氳
+	PortUse_KNet = 4, 		// KNet閫氳
+	PortUse_SLP = 5,		// SLP鍗曟�荤嚎
+	PortUse_KRF = 6, 		// 鏃犵嚎閫氳
+	PortUse_ModbusRTU = 7, //Modbus RTU 閫氳
+	PortUse_ModbusTCP = 8, //Modbus TCP 閫氳
+	PortUse_Com = 9,		//	璁$畻鏈洪�氳
+	PortUse_Gen = 10,		//閫氱敤閫氳锛岃嚜鐢卞彛
+};
+
+static CString PortUseTypeToStr(int nPortHardType)
+{
+	static CString s1;
+	switch (nPortHardType)
+	{
+	case PortUse_Default:		// = 0 榛樿
+		return _T("NULL");
+	case PortUse_Console:		// = 1,	//鎺у埗鍙版帴鍙�
+		return _T("缁堢");
+	case PortUse_KLink:		// = 2,	//KLink閫氳
+		return _T("KLink");
+	case PortUse_KBus:	//= 3,	//	KNet閫氳
+		return _T("KBus");
+	case PortUse_KNet:	//= 4,	//	涓茶鎺ュ彛
+		return _T("KNet");
+	case PortHardType_SLP:		//= 5,	//	SLP鍗曟�荤嚎
+		return _T("KSLP");
+	case PortUse_KRF:		//= 6,	//	鏃犵嚎閫氳
+		return _T("KwRF");
+	case PortUse_ModbusRTU:		//= 7,	//	Modbus RTU 閫氳
+		return _T("ModbusRTU");
+	case PortUse_ModbusTCP:		//= 8,	//	Modbus TCP 閫氳
+		return _T("ModbusTCP");
+	case PortUse_Com:		//= 9,	//	璁$畻鏈洪�氳
+		return _T("");
+	case PortUse_Gen:		//= 10,	//	閫氱敤閫氳锛岃嚜鐢卞彛
+		return _T("WiFi");
+	default:
+		return _T("UNKNOWN");
+		break;
+	}
+}
+
+enum enServiceReqs
+{
+	ReqNone,
+	ReqInit,
+	ReqReset,
+	ReqStop,
+	ReqRun,
+	ReqBlinkLED,
+	ReqStartDiag,
+	ReqStopDiag,
+	ReqPortChildInfo,
+	ReqPortChnInfo,
+	ReqUpdateFirm,
+	ReqUpdateFirmInfo,
+
+	ReqTransFirmware,
+	ReqTransCfg,
+	ReqTransProg,
+	ReqTransData,
+	ReqTransBlink,
+	ReqTransChild,
+	ReqTransInfo,
+	ReqTransOutBandData,
+	ReqRead1Bit,
+	ReqWrite1Bit,
+	ReqReadBits,
+	ReqWriteBits,
+	ReqReadData,
+	ReqWriteData,
+	ReqRemoteTran,
+};
+
+typedef struct tagPortAbility
+{
+	USHORT ChildList : 1;
+	USHORT AccessChild : 1;
+	USHORT TranProg : 1;
+	USHORT TranCfg : 1;
+	USHORT Diag : 1;
+	USHORT TranOutBandData : 1;
+	USHORT Tunnel : 1;
+	USHORT TranFirmware : 1;
+	USHORT TranBlink : 1;
+}stPortAbility;
+
+// 鍚勭鍙� 浜掕仈 閫氫俊
+typedef int (*CommFuncDef)(int ReqId, int nParam, void* pData, int len1);
+typedef struct tagPortDef
+{
+	union {
+		USHORT nPortType;
+		struct {
+			UCHAR nPortHardType;
+			UCHAR nPortUseType;
+		};
+	};
+	USHORT ability;		//鑳藉姏, 鑾峰彇瀛愭満淇℃伅绛夈��
+	UCHAR bEnable;
+	UCHAR bRunning;
+	UCHAR StationId;
+	UCHAR bMaster;
+	UCHAR nMaxStations;
+	UCHAR nCurStations;
+	UCHAR nHealth;
+	short PortConfigType;
+	short PortConfigSize;
+	short PortRunStatType;
+	short PortRunStatSize;
+
+//	CommFuncDef ReqCommFunc;
+	// func2 CommReq;
+
+}stPortDef, * pstPortDef;
 
 enum enKeventType
 {
@@ -132,17 +295,75 @@
 	EventTypeProg = 8,
 	EventTypeForce = 9,
 	EventTypeClearEvent = 10,
-
-
 	EventType
 };
+
+typedef struct tagDevPortDef
+{
+	union {
+		USHORT nPortType;
+		struct {
+			UCHAR nPortHardType;
+			UCHAR nPortUseType;
+		};
+	};
+	UCHAR bEnabled;
+	UCHAR bRunning;
+	UCHAR StationID;
+	UCHAR bMaster;
+	UCHAR MaxStations;
+	UCHAR CurStations;
+	UCHAR Health;
+
+}stDevPortDef;
+
+typedef struct tagDeviceDef
+{
+	USHORT nDeviceTypeVer;
+	USHORT nProgVer;
+	UCHAR InBitCount;
+	UCHAR OutBitCount;
+	unsigned short nPortCount;
+	stDevPortDef Ports[8];		//鏈�澶�8涓�氳绔彛
+}stDeviceDef;
+
+typedef struct tagDeviceInfo		// KBus 瀛愭満鍩烘湰淇℃伅		
+{
+	unsigned short DeviceType;		// 瀛愭満绫诲瀷
+	union {
+		unsigned short DeviceVer;			// 瀛愭満鐗堟湰
+		struct {
+			unsigned char DeviceVerMinor;
+			unsigned char DeviceVerMajor;
+		};
+	};
+	unsigned char InBitCount;			// 杈撳叆寮�鍏抽噺鏁伴噺
+	unsigned char OutBitCount;		// 杈撳嚭寮�鍏抽噺鏁伴噺
+	unsigned char ExInBitCount;		// 鎵╁睍鐨勮緭鍏ュ紑鍏抽噺鏁伴噺
+	unsigned char ExOutBitCount;	// 鎵╁睍鐨勮緭鍑哄紑鍏抽噺鏁伴噺
+	unsigned char DWStartAddr;		// 杈撳嚭鏁版嵁瀛楁暟
+	unsigned char OutDWCount;			// 杈撳嚭鏁版嵁瀛楁暟
+	unsigned char AIWCount;				// 杈撳叆妯℃嫙閲忛�氶亾(瀛�)鏁�	// 16浣嶄负涓�涓瓧(閫氶亾)
+	unsigned char AQWCount;				// 杈撳嚭妯℃嫙閲忛�氶亾(瀛�)鏁�	// 16浣嶄负涓�涓瓧(閫氶亾)
+//	unsigned char AIBits;					//  姣忛�氶亾浣嶆暟		// 16浣嶄互涓�
+//	unsigned char AQbits;					//	姣忛�氶亾浣嶆暟		// 16浣嶄互涓�
+
+
+}stDeviceInfo;
 
 typedef struct tagInfoBlock // 20 bytes
 {
 	//	USHORT nBlockLenth;
 	USHORT nDeviceTypeVer;			//device type		x.y
 //	UCHAR nDevierVer;
-	USHORT nProgVer;					//prog version	x.y
+	union {
+		USHORT nProgVer;					//prog version	x.y
+		struct {
+			UCHAR nProgVerMinor;
+			UCHAR nProgVerMajor;
+		};
+	};
+
 	USHORT nKLinkVer;				//x.y
 	USHORT nKBusVer;				//x.y
 //	USHORT nKNetVer;				//x.y
@@ -186,6 +407,14 @@
 
 }stFactoryData, *pFactoryData;
 
+typedef struct tagNewAppInfoBlock
+{
+	unsigned short Sign;
+	unsigned short Version;
+	unsigned int Length;
+	unsigned int nCRC;
+
+}stNewAppInfoBlock, * pNewAppInfoBlock;
 
 typedef struct tagKMFuncParam
 {
@@ -233,23 +462,68 @@
 	BYTE Hold2 : 4;
 }stOutputHoldParam;
 // 纭欢鎻忚堪鏂囦欢
+typedef struct tagOutMapping
+{
+	USHORT bitPos : 4;
+	USHORT byteAddr : 8;
+	USHORT type : 4;
+}stOutMapping;
+
+typedef struct tagCfgBlockInfo
+{
+	UCHAR nBlockType;
+	UCHAR nBlockSize;
+}stCfgBlockInfo;
 
 //#pragma pack(2)
+
 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 Space1;						// 2 bytes
+	USHORT Version;										// SC0	// 2 Bytes
+	USHORT workmode;									// SC1  // 2 Bytes 0=From jumper  
+	USHORT SwitchFunc;								// SC2  // 2 Bytes 
+	USHORT nCfgBlockCount;											// 2 Bytes
 
-	stComPortParam PortParams[2];					// 28 Bytes
-	stInputFilterParam InputParams[16];				//8 Bytes
+	stComPortParam PortParams[2];							// 8 Bytes
+	stInputFilterParam InputParams[16];				//16 Bytes
 	stOutputHoldParam OutputParams[16];				//16 Bytes
-	USHORT OutMappings[6];				//12 Bytes //杈撳嚭鏄犲皠
 
-	UINT Space2[12];								//48 bytes
+	union {
+		USHORT value;										//12 Bytes //杈撳嚭鏄犲皠
+		struct {
+			USHORT bitPos : 4;
+			USHORT byteAddr : 8;
+			USHORT type : 4;
+		};
+	}OutMappings[8];
 
-}stKMSysCfg, *pKMSysCfg;
+	USHORT nProgBank;
+	USHORT nProgSize;
+	USHORT nAnnoSize;
+	USHORT nCount;
+
+	stCfgBlockInfo CfgBlockInfos[8];
+	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, * pstKMSysCfg;
+
+typedef struct tagStoredKMSysCfg
+{
+	unsigned short Sign1;
+	unsigned short Seq1;
+	stKMSysCfg theKMSysCfg;
+	unsigned short CRC1;
+	unsigned short EndSign1;
+}stStoredKMSysCfg, * pStoredKMSysCfg;
 
 
 typedef struct tagTimer
@@ -392,7 +666,7 @@
 	OP_TMR = 0xDC,	//
 	OP_TMX = 0xDD,	//
 	OP_TMY = 0xFA,	//
-
+	OP_END = 0xFF,
 };
 
 typedef struct stBinProg1

--
Gitblit v1.9.1