/** ****************************************************************************** * @file : KBusDefine.h * @brief : Header for KBus protocol. * This file contains the common defines of the KBus Protocol . ****************************************************************************** */ #ifndef __KBUSDEFINE_H__ #define __KBUSDEFINE_H__ #define KBUS_VER (0x104) //#define SYN_PREFIX 1 typedef unsigned char uchar; enum enKBusStationType { KBNone = 0, KBusMaster = 1, KBusSlave = 2, KBusRepeater = 3, }; // diagnosis enum enKBusStats { KBusStatIdel, KBusStatConfig, KBusStatRunning, KBusStatError, }; enum enCMDs { cmdNone = '0', //Nothing cmdPing = '1', //Ping cmdPingReply = '2', //PingReply cmdRead = '3', //Read cmdReadReply = '4', //ReadReply cmdWrite = '5', //Write cmdWriteReply = '6', //WriteReply cmdGetVersion = '7', //GetVersion cmdVerInfo = '8', //VersionReply cmdExChgData='A', //ExChangeData, = Wirte + Read cmdExChgDataReply, //ExchangeData Reply cmdSyncRead='a', //SyncRead cmdSyncWrite, //SyncWrite cmdSequenRead, //Sequence Read 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 bMasterRecved; unsigned char bMasterRecvOK; unsigned char bSlaveRecved; unsigned int nSendTimeuS; }stKBusRunStat , * pstKBusRunStat; typedef struct tagVerInfo { unsigned char nMainVer; unsigned char nSubVer; }stVerInfo; typedef struct tagMasterStat { unsigned int CycleTime; } stMasterStat; typedef struct tagClientInfo { unsigned short ClientType; unsigned short ClientVer; // stVerInfo ClientVer; unsigned char InBitCount; unsigned char OutBitCount; unsigned char AICount; unsigned char AIBits; unsigned char AQCount; unsigned char AQbits; unsigned char InDWCount; unsigned char OutDWCount; unsigned char bOnline; }stClientInfo; typedef struct tagClientCfg { 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; }stClientCfg; typedef struct ServerStatus { unsigned char Addr; unsigned char Status; unsigned short Input[16]; unsigned short DT[128]; unsigned short output[16]; }stServerStatus,*pServerStatus; typedef struct tagMachineState { unsigned char Addr; unsigned char state; unsigned char InStartAddrBit; unsigned char OutStartAddrBit; unsigned char InDWStartAddrByte; unsigned char OutDWStartAddrByte; }ClientState; #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; union { unsigned int ClientDatas[10]; struct { unsigned int ClientRecvPkts; // unsigned int ClientSendPkts; // unsigned int ClientNotPktErr; // unsigned int ClientMisIdPkts; // // unsigned int ClientNoEndErr; // unsigned int ClientPkgLenErr; // unsigned int ClientBccErr; // unsigned int ClientTimeOutErr; // }; }; } stChnStat; typedef struct tagSlaveStat { unsigned int nSlaveTick; } stSlaveStat; typedef struct ServerClientListElement { unsigned char Addr; unsigned char Status; unsigned char Father; unsigned char Childs; } stServerClientListElement; typedef struct ServerClientList { unsigned char Addr; }stServerClientList,*pServerClientList; typedef struct tagMachineConfig { int bKBusMaster; int nAddr; }stMachineConfig; /* typedef struct ClientStatus { unsigned char Addr; unsigned char Status; unsigned char Father; unsigned char Childs; unsigned short Input[16]; unsigned short DT[128]; unsigned short output[16]; }stChnStatus,*pClientStatus; */ typedef struct tagStatusDef { unsigned char nSeq:2; //ÐòÁкŠunsigned char :2; unsigned char nErr1:1; unsigned char nErr2:1; }stStatus; typedef union tagUnStatusDef { unsigned char nStatus; stStatus; }unStatus; typedef struct tagKBPacket { unsigned char Sign; //Æðʼ±ê¼Ç unsigned char DstHost; //Ä¿±êµØÖ· unsigned char SrcAddr; //Ô´µØÖ· unsigned char nCMD; //ÃüÁî union{ unsigned char nStatus; //״̬+ÐòÁкŠstruct{ unsigned char nSeq:2; //ÐòÁкŠunsigned char :2; unsigned char nErr1:1; unsigned char nErr2:1; }; }; unsigned char DataLen; //Êý¾ÝÔغɳ¤¶È ²»°üÀ¨Í·²¿5¸ö×Ö½Ú£¬²»°üÀ¨Î²²¿BCC¡£ unsigned char data[1]; //Êý¾ÝÔغÉ,×îĩβÊÇBCC£¬Êý¾Ý³¤¶ÈΪ0ʱ£¬Êµ¼ÊÒ²ÓÐÒ»¸öÊý¾Ý¡£ }stKBPacket,* pKBPacket; typedef struct tagKBInfoBlockV1 { unsigned short nDeviceType; unsigned short nProgVer; unsigned char InBitCount; unsigned char OutBitCount; unsigned char AICount; unsigned char AIBits; unsigned char AQCount; unsigned char AQbits; unsigned char InDWCount; unsigned char OutDWCount; }stKBInfoBlockV1, *pKBInfoBlockV1; /* typedef struct tagKBPacketV10 { unsigned char Sign; //Æðʼ±ê¼Ç unsigned char DstHost; //Ä¿±êµØÖ· unsigned char SrcAddr; //Ô´µØÖ· unsigned char nCMD; //ÃüÁî union{ unsigned char nStatus; //״̬+ÐòÁкŠstruct{ unsigned char nSeq:2; //ÐòÁкŠunsigned char :2; unsigned char nErr1:1; unsigned char nErr2:1; }; }; unsigned char DataLen; //Êý¾ÝÔغɳ¤¶È ²»°üÀ¨Í·²¿5¸ö×Ö½Ú£¬²»°üÀ¨Î²²¿BCC¡£ unsigned char data[1]; //Êý¾ÝÔغÉ,×îĩβÊÇBCC£¬Êý¾Ý³¤¶ÈΪ0ʱ£¬Êµ¼ÊÒ²ÓÐÒ»¸öÊý¾Ý¡£ }stKBPacketV10,* pKBPacketV10; typedef struct tagKBPacketV20 { unsigned char Sign; //Æðʼ±ê¼Ç unsigned char DstHost; //Ä¿±êµØÖ· unsigned char SrcAddr; //Ô´µØÖ· unsigned char nCMD; //ÃüÁî union{ unsigned char nStatus; //״̬+ÐòÁкŠstruct{ unsigned char nSeq:2; //ÐòÁкŠunsigned char :2; unsigned char nErr1:1; unsigned char nErr2:1; }; }; unsigned char DataLen; //Êý¾ÝÔغɳ¤¶È ²»°üÀ¨Í·²¿5¸ö×Ö½Ú£¬²»°üÀ¨Î²²¿BCC¡£ 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, }; #endif /* __KBUSDEFINE_H__ */