From 5dd1b7fdcc52a43867f924e8d220de8467af372a Mon Sep 17 00:00:00 2001 From: QuakeGod <quakegod@sina.com> Date: 星期五, 12 四月 2024 14:27:26 +0800 Subject: [PATCH] Change KBus to OOP and Packge --- ComLib/Inc/KBusDefine.h | 259 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 166 insertions(+), 93 deletions(-) diff --git a/ComLib/Inc/KBusDefine.h b/ComLib/Inc/KBusDefine.h index 70623ad..6c191dc 100644 --- a/ComLib/Inc/KBusDefine.h +++ b/ComLib/Inc/KBusDefine.h @@ -15,26 +15,67 @@ typedef unsigned char uchar; -enum enKBusStationType +enum enKBusStationType // KBus工作类型 { - KBNone = 0, - KBusMaster = 1, - KBusSlave = 2, - KBusRepeater = 3, + KBNone = 0, // 0,未定义 + KBusMaster = 1, // 1,主机 + KBusSlave = 2, // 2,子机 + KBusRepeater = 3, // 3,转发器,中继器 }; // diagnosis enum enKBusStats { - KBusStatIdel, - KBusStatConfig, - KBusStatRunning, - KBusStatError, + KBusStatUnInited, // 未初始化状态 + KBusStatInited, // 已初始化状态 + KBusStatConfig, // 已配置状态 + KBusStatReady, // 就绪状态 + KBusStatRunning, // 运行状态 + KBusStatIdel, // 暂停状态 + KBusStatSafe, // 安全状态 + KBusStatError, // 错误状态 +}; +/* +enum enKBusStage +{ + KBusStageInit, + KBusStageFindChild, + KBusStageConfigChild, + KBusStagePoll, + +}; +*/ +enum { + KB_SYN = 0x55, + KBStartSign='%', + KBEndSign=0x0D, + KBMaxPacketLength=128, }; enum enCMDs { - cmdNone = '0', //Nothing + + cmdNone = 0x00, //Nothing + + cmdQuery = 0x01, //Query basic Info + cmdQueryRply = 0x81, //Query Info Reply + + cmdSetCfg = 0x02, // Set Configuration + cmdSetCfgRply = 0x82, // Set Configuration Response + + cmdToRunMode = 0x03, + cmdToRunModeRply = 0x83, + + cmdBroadCastCfg = 0x04, // + + cmdMuExchgData = 0x05, // + cmdMuExchgDataRply = 0x85, // + + cmdToSafeMode = 0x06, + + cmdHeartBeat = 0x07, // + cmdReHeartBeat = 0x87, // + cmdPing = '1', //Ping cmdPingReply = '2', //PingReply cmdRead = '3', //Read @@ -44,7 +85,7 @@ cmdGetVersion = '7', //GetVersion cmdVerInfo = '8', //VersionReply - cmdExChgData='A', //ExChangeData, = Wirte + Read + cmdUniExChgData='A', //ExChangeData, = Wirte + Read cmdExChgDataReply, //ExchangeData Reply cmdSyncRead='a', //SyncRead @@ -53,69 +94,92 @@ cmdSyncTime, //SyncTime }; -enum { - SYN = 0x55, - StartSign='%', - EndSign=0x0D, - MaxPacketLength=128, -}; + typedef struct tagKBusRunStat { - unsigned char bMaster; - unsigned char nStationID; - unsigned char nChildren; - unsigned char nCurPollId; - unsigned char nSeq; + unsigned char bMaster; // 是否主机 + unsigned char nStationID; // 子机地址 + unsigned char nChildren; // 子机数量 + unsigned char nCurPollId; // 当前轮询到的子机 地址。 + unsigned char nSeq; // 包序列号 - unsigned char bMasterRecved; - unsigned char bMasterRecvOK; - unsigned char bSlaveRecved; - unsigned int nSendTimeuS; + unsigned char bMasterRecved; // 状态, 主机已接收到返回的数据包 + unsigned char bMasterRecvOK; // 状态, 主机接收到的返回的数据包正确 + unsigned char bSlaveRecved; // 状态, 子机接受到数据包。 + unsigned int nSendTimeuS; // 数据包发出时刻。 }stKBusRunStat , * pstKBusRunStat; -typedef struct tagVerInfo +typedef struct tagVerInfo // KBus 版本信息 { unsigned char nMainVer; unsigned char nSubVer; }stVerInfo; -typedef struct tagMasterStat +typedef struct tagMasterStat // KBus 主机状态? { unsigned int CycleTime; } stMasterStat; -typedef struct tagClientInfo +typedef struct tagDeviceInfo // KBus 子机基本信息 { - unsigned short ClientType; - unsigned short ClientVer; + unsigned short DeviceType; // 子机类型 + unsigned short DeviceVer; // 子机版本 + unsigned char InBitCount; // 输入开关量数量 + unsigned char OutBitCount; // 输出开关量数量 + 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 tagExDeviceInfo // 子机扩展信息 +{ + unsigned short DeviceType; // 子机类型 + unsigned short DeviceVer; // 子机版本 + + unsigned char UID[12]; // 12字节 UUID + unsigned char Name[16]; // 16字节 名称 // stVerInfo ClientVer; - unsigned char InBitCount; + unsigned char InBitCount; unsigned char OutBitCount; - unsigned char AICount; - unsigned char AIBits; - unsigned char AQCount; - unsigned char AQbits; - unsigned char InDWCount; + unsigned char DWStartAddr; unsigned char OutDWCount; - unsigned char bOnline; -}stClientInfo; + unsigned char AIWCount; + unsigned char AQWCount; +// unsigned char AIBits; +// unsigned char AQbits; -typedef struct tagClientCfg +}stExDeviceInfo; + +enum enKBusConfigStat { - unsigned char nGroup; - unsigned char Addr; - unsigned char InStartAddrBit; - unsigned char OutStartAddrBit; - unsigned char InAWStartAddrByte; - unsigned char OutAWStartAddrByte; - unsigned char InDWStartAddrByte; - unsigned char OutDWStartAddrByte; - unsigned int KeepOut; //Keep Output when comm err; + KBusUnConfiged = 0, + KBusDefaultConfiged =1, + KBusConfiged = 2, +}; + +typedef struct tagClientCfg // 子机配置 +{ + unsigned char Addr; // 子机地址 + unsigned char Configed; // 是否已配置 + unsigned char bOnline; //当前在线状态 + unsigned char InStartAddrBit; //输入起始位地址 + unsigned char OutStartAddrBit; //输出起始位地址 + unsigned char AIWStartAddrByte; //模拟入起始字地址 + unsigned char AQWStartAddrByte; //模拟出起始字地址 + unsigned char DIWStartAddrByte; //数据入起始字地址 + unsigned char DOWStartAddrByte; //数据出起始字地址 + unsigned char KeepOut; //Keep Output when comm err; }stClientCfg; +/* typedef struct ServerStatus { unsigned char Addr; @@ -125,15 +189,15 @@ unsigned short output[16]; }stServerStatus,*pServerStatus; - -typedef struct tagMachineState +*/ +typedef struct tagMachineState // 本机状态 { - unsigned char Addr; - unsigned char state; - unsigned char InStartAddrBit; - unsigned char OutStartAddrBit; - unsigned char InDWStartAddrByte; - unsigned char OutDWStartAddrByte; + unsigned char Addr; // 地址 + unsigned char state; //状态 + unsigned char InStartAddrBit; //输入起始位地址 + unsigned char OutStartAddrBit; //输出起始位地址 + unsigned char InDWStartAddrByte; //字输入起始字地址 + unsigned char OutDWStartAddrByte; //字输出起始字地址 }ClientState; @@ -141,32 +205,32 @@ #pragma anon_unions typedef struct tagChnStat { - unsigned int Stat; - unsigned int SendPackets; - unsigned int RecvPackets; - unsigned int LastSentTimeuS; - unsigned int LostPackets; - unsigned int CtnLstPkts; - unsigned int MaxCtnLstPkts; - unsigned int NotPkgErr; - unsigned int PkgLenErr; - unsigned int BCCErr; - unsigned int TimeOutErr; - unsigned int Delay; - unsigned int MaxDelay; - unsigned int SendTimeInterval; + unsigned short Stat; + unsigned short SendPackets; + unsigned short RecvPackets; + unsigned short LastSentTimeuS; + unsigned short LostPackets; + unsigned short CtnLstPkts; + unsigned short MaxCtnLstPkts; + unsigned short NotPkgErr; + unsigned short PkgLenErr; + unsigned short BCCErr; + unsigned short TimeOutErr; + unsigned short Delay; + unsigned short MaxDelay; + unsigned short SendTimeInterval; union { - unsigned int ClientDatas[10]; + unsigned short ClientDatas[10]; struct { - unsigned int ClientRecvPkts; // - unsigned int ClientSendPkts; // - unsigned int ClientNotPktErr; // - unsigned int ClientMisIdPkts; // + unsigned short ClientRecvPkts; // + unsigned short ClientSendPkts; // + unsigned short ClientNotPktErr; // + unsigned short ClientMisIdPkts; // // unsigned int ClientNoEndErr; // - unsigned int ClientPkgLenErr; // - unsigned int ClientBccErr; // - unsigned int ClientTimeOutErr; // + unsigned short ClientPkgLenErr; // + unsigned short ClientBccErr; // + unsigned short ClientTimeOutErr; // }; }; } stChnStat; @@ -263,6 +327,13 @@ }stKBInfoBlockV1, *pKBInfoBlockV1; +enum eResult +{ + S_OK =0, + S_ERR=1, + S_TIMEOUT=2 + +} ; /* typedef struct tagKBPacketV10 @@ -305,25 +376,27 @@ unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 }stKBPacketV20,* pKBPacketV20; */ -typedef void *(*CBFuncDef) (void*, void *, int); //callback func ,prama s is void *,void *,int; return void *; - -enum eResult -{ - S_OK =0, - S_ERR=1, - S_TIMEOUT=2 - -} ; enum enumCallBackEvent { - evNone = 0, - evCreate = 1, - evConnected = 2, - evDisConnected = 3, - evClosed = 4, + KBusEvNone = 0, + KBusEvCreate = 1, + KBusEvConnected = 2, + KBusEvDisConnected = 3, + KBusEvClosed = 4, + KBusEvStateChange =5, + KBusEvTimeSync=6, + KBusEvDataUpdate =7, + KBusEvCmdResponse = 8, + }; +typedef int (*KBusSendPktFuncDef) (uchar * pBuf, int nLen); // SendPacket CallBack func for KBus + +typedef void *(*KBusEvCBFuncDef) (void * , int nEvent, void *, int); //callback func ,prama s is void *,void *,int; return void *; + +typedef int (*KBusSvCBFuncDef) (void *, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; + #endif /* __KBUSDEFINE_H__ */ -- Gitblit v1.9.1