/** ****************************************************************************** * @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 // KBus¹¤×÷ÀàÐÍ { KBNone = 0, // 0,䶨Òå KBusMaster = 1, // 1,Ö÷»ú KBusSlave = 2, // 2,×Ó»ú KBusRepeater = 3, // 3,ת·¢Æ÷,ÖмÌÆ÷ }; // diagnosis enum enKBusStats { 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 = 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 cmdReadReply = '4', //ReadReply cmdWrite = '5', //Write cmdWriteReply = '6', //WriteReply cmdGetVersion = '7', //GetVersion cmdVerInfo = '8', //VersionReply cmdUniExChgData='A', //ExChangeData, = Wirte + Read cmdExChgDataReply, //ExchangeData Reply cmdSyncRead='a', //SyncRead cmdSyncWrite, //SyncWrite cmdSequenRead, //Sequence Read cmdSyncTime, //SyncTime }; 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 // KBus °æ±¾ÐÅÏ¢ { unsigned char nMainVer; unsigned char nSubVer; }stVerInfo; typedef struct tagMasterStat // KBus Ö÷»ú״̬£¿ { unsigned int CycleTime; } stMasterStat; typedef struct tagDeviceInfo // KBus ×Ó»ú»ù±¾ÐÅÏ¢ { 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 OutBitCount; unsigned char DWStartAddr; unsigned char OutDWCount; unsigned char AIWCount; unsigned char AQWCount; // unsigned char AIBits; // unsigned char AQbits; }stExDeviceInfo; enum enKBusConfigStat { 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; 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 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 short ClientDatas[10]; struct { unsigned short ClientRecvPkts; // unsigned short ClientSendPkts; // unsigned short ClientNotPktErr; // unsigned short ClientMisIdPkts; // // unsigned int ClientNoEndErr; // unsigned short ClientPkgLenErr; // unsigned short ClientBccErr; // unsigned short 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; enum eResult { S_OK =0, S_ERR=1, S_TIMEOUT=2 } ; /* 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; */ enum enumCallBackEvent { 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__ */