| | |
| | | * This file contains the common defines of the application. |
| | | ****************************************************************************** |
| | | */ |
| | | #include "KBusDefine.h" |
| | | |
| | | #include "KMachine.h" |
| | | |
| | | #ifndef __KBUS_H__ |
| | |
| | | |
| | | extern unsigned char bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | |
| | | // diagnosis |
| | | |
| | | enum enKBusStats |
| | | { |
| | | KBusStatIdel, |
| | | KBusStatConfig, |
| | | KBusStatRunning, |
| | | KBusStat |
| | | }; |
| | | |
| | | 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', //ExChangeDate, = Wirte + Read |
| | | cmdExChgDataReply, //ExchangeData Reply |
| | | |
| | | cmdSyncRead='a', //SyncRead |
| | | cmdSyncWrite, //SyncWrite |
| | | cmdSequenRead, //Sequence Read |
| | | cmdSyncTime, //SyncTime |
| | | }; |
| | | |
| | | enum { |
| | | SYN = 0x55, |
| | | StartSign='%', |
| | | EndSign=0x0D, |
| | | MaxPacketLength=128, |
| | | }; |
| | | |
| | | extern unsigned char PacketBuf1[MaxPacketLength]; |
| | | extern unsigned char PacketBuf2[MaxPacketLength]; |
| | | |
| | | 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; |
| | | |
| | | extern unsigned char BufferIn[16]; |
| | | extern unsigned char BufferOut[16]; |
| | |
| | | |
| | | extern volatile unsigned int nSlaveTick; |
| | | |
| | | typedef struct tagVerInfo |
| | | { |
| | | unsigned char nMainVer; |
| | | unsigned char nSubVer; |
| | | }stVerInfo; |
| | | |
| | | typedef struct tagMachineState |
| | | { |
| | | unsigned char Addr; |
| | | unsigned char state; |
| | | unsigned char InStartAddrBit; |
| | | unsigned char OutStartAddrBit; |
| | | unsigned char InDWStartAddrByte; |
| | | unsigned char OutDWStartAddrByte; |
| | | }ClientState; |
| | | |
| | | typedef struct tagMasterStat |
| | | { |
| | | unsigned int CycleTime; |
| | | } stMasterStat; |
| | | |
| | | 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 tagClientCfg |
| | | { |
| | | unsigned int KeepOut; //Keep Output when comm err; |
| | | |
| | | }stClientCfg; |
| | | |
| | | struct ClientInfo |
| | | { |
| | | stVerInfo ClientVer; |
| | | unsigned char nType; |
| | | unsigned char nGroup; |
| | | unsigned char InPutCount; |
| | | unsigned char OutPutCount; |
| | | unsigned char InDWCount; |
| | | unsigned char OutDWCount; |
| | | unsigned char bOnline; |
| | | }; |
| | | |
| | | #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; |
| | | |
| | | extern stChnStat KBusChnStats[8]; |
| | | |
| | | 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 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]; |
| | | static inline char KWInit(int nPortNum) { }; |
| | | static inline char KWStart(int nPortNum) { }; |
| | | static inline char KWGetClientNum(int nPortNum) { }; |
| | | static inline char KWGetClientInfo(int nPortNum, int nClientId) { }; |
| | | static inline char KWGetClientInCount(int nPortNum,int nClientId) {}; |
| | | |
| | | |
| | | }stChnStatus,*pClientStatus; |
| | | static inline char KWisSafeState(int nPortNum) { }; |
| | | static inline char KWisRunState(int nPortNum) { }; |
| | | static inline char KWGetState(int nPortNum) { }; |
| | | static inline char KWChangeState(int nPortNum, int nNewState){ }; |
| | | */ |
| | | typedef void *(*CBFuncDef) (void*, void *, int); //callback func ,prama s is void *,void *,int; return void *; |
| | | enum enumCallBackEvent |
| | | { |
| | | evNone = 0, |
| | | evCreate = 1, |
| | | evConnected = 2, |
| | | evDisConnected = 3, |
| | | evClosed = 4, |
| | | }; |
| | | |
| | | 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; |
| | | |
| | | enum eResult |
| | | { |
| | | S_OK =0, |
| | | S_ERR=1, |
| | | S_TIMEOUT=2 |
| | | |
| | | } ; |
| | | |
| | | unsigned char KBusBCC(void * pData, int nSize); |
| | | // |
| | |
| | | |
| | | /* */ |
| | | int KBusParsePacket(int nChn, pKBPacket p1, int Len1); |
| | | typedef struct tagMachineConfig |
| | | { |
| | | int bKBusMaster; |
| | | int nAddr; |
| | | }stMachineConfig; |
| | | |
| | | /* |
| | | int InitMachine(stMachineConfig * pConfig); |
| | | |