From f4f290279d32d3cd656472a3298345bc7418cd78 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期一, 17 十月 2022 20:42:45 +0800 Subject: [PATCH] arrange again radio fp0 klink knet --- Inc/KMachine.h | 160 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 110 insertions(+), 50 deletions(-) diff --git a/Inc/KMachine.h b/Inc/KMachine.h index 827a591..e3fb8a4 100644 --- a/Inc/KMachine.h +++ b/Inc/KMachine.h @@ -43,8 +43,38 @@ 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 +{ + 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; + enum enStoreCfg { + CFG_VER = 0x100, START_SIGN = 0x55aa, END_SIGN = 0x5aa5, }; @@ -81,6 +111,21 @@ PortType_ModbusRTU = 5, //Modbus RTU 通讯 }; +//每个模块有 0/1/2/3/4/5/6/7/8个 通讯port +//不限于 UART, 网口,无线,单总线等,都是port +//甚至可以有虚拟的port + +typedef struct tagPortStat +{ + UCHAR nWorking; //工作中 + UCHAR nStation; //自己站号 + UCHAR bBus; //总线?,,全双工? + UCHAR bMaster; //主机 + UCHAR PortType; //端口工作模式 + UCHAR nDevices; //连接的设备数量//不包括自己 //device list; + +}stPortStat,*pPortStat; + enum enKeventType { EventTypeNone = 0, @@ -98,22 +143,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 { @@ -123,59 +152,76 @@ // 输入输出地址映射 -typedef struct tagComPortParam +typedef struct tagComPortParam //4 Bytes { - USHORT PortType:4; /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */ + USHORT Station; /* 0=From jumper */ + USHORT WorkMode; /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */ + USHORT BaudRate; /* =*100 Baudrate at which running */ +// 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 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 BaudRate; /* =*100 Baudrate at which running */ + USHORT EndTime; + USHORT RecvAddr; + USHORT RecvSize; + }stComPortParam; -typedef struct tagInputFilterParam +typedef struct tagInputFilterParam // 1 Bytes { BYTE Filter0:4; BYTE Filter1:4; }stInputFilterParam; -typedef struct tagOutputHoldParam +typedef struct tagOutputHoldParam //1 Bytes { BYTE Hold1:4; BYTE Hold2:4; }stOutputHoldParam; #pragma anon_unions -typedef struct tagMSysCfg +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 OutMappings[6]; //12 Bytes //输出映射 + + stComPortParam PortParams[2]; // 8 Bytes + stOutputHoldParam OutputParams[16]; //16 Bytes + stInputFilterParam InputParams[16]; //16 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[5]; //20 Bytes + +}stKMSysCfg,* pKMSysCfg; + +typedef struct tagStoredKMSysCfg { 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]; - + stKMSysCfg theKMSysCfg; unsigned short CRC1; unsigned short EndSign1; -}stKMSysCfg,* pKMSysCfg; +}stStoredKMSysCfg,*pStoredKMSysCfg; /* typedef struct tagFactData @@ -242,7 +288,7 @@ //stStoreCfg * GetCurStoreCfgAddr(void ); //stStoreCfg * GetNextStoreCfgAddr(stStoreCfg * CurCfg ); -extern stKMSysCfg KMSysCfg; +extern stStoredKMSysCfg storedKMSysCfg; #define TYPECOIL 0x00 #define TYPEDATA 0x80 @@ -348,9 +394,15 @@ unsigned char CurVALs[TOTAL_CurVAL]; unsigned char CurVAL; stTimer Timers[TOTALTIMERS]; - + + union { unsigned short WX[KLDataWXCount]; //本机的X和Y + unsigned char WXB[KLDataWXCount*2]; + }; + union { unsigned short WY[KLDataWYCount]; //本机的X和Y + unsigned char WYB[KLDataWYCount*2]; //本机的X和Y + }; unsigned short WR[KLDataWRCount]; unsigned short WT[16]; @@ -365,8 +417,12 @@ unsigned short WLR[16]; unsigned short WSR[16]; +union { + unsigned int DTD[KLDataDTCount]; unsigned short DT[KLDataDTCount]; - + unsigned char DTB[KLDataDTCount*2]; +}; + // 配置寄存器 // 系统状态寄存器 // 特殊寄存器 @@ -405,6 +461,10 @@ 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); int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize); @@ -417,8 +477,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