.gitignore | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
CCT6_TestApp1/MDK-ARM/CCT6_TestApp1/F030CCT6_TestApp1.map | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
CCT6_TestApp1/Src/FP0.c | 补丁 | 查看 | 原始文档 | blame | 历史 | |
ComLib/Inc/KBus.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ComLib/Inc/KBusDefine.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ComLib/Src/KBus.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
.gitignore
@@ -12,8 +12,12 @@ *.iex *.iex *.bin *.map MDK-ARM/*/* */MDK-ARM/*/* *.uvguix.* *.uvgui.* *.uvoptx CCT6_TestApp1/MDK-ARM/CCT6_TestApp1/F030CCT6_TestApp1.map
File was deleted CCT6_TestApp1/Src/FP0.c
ComLib/Inc/KBus.h
@@ -5,6 +5,8 @@ * This file contains the common defines of the application. ****************************************************************************** */ #include "KBusDefine.h" #include "KMachine.h" #ifndef __KBUS_H__ @@ -18,61 +20,10 @@ extern unsigned char bKBusMaster,bKBusSlave,bKBusRepeater;; // 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', //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]; @@ -92,179 +43,21 @@ extern volatile unsigned int nSlaveTick; typedef struct tagVerInfo { unsigned char nMainVer; unsigned char nSubVer; }stVerInfo; 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 tagClientInfo { stVerInfo ClientVer; unsigned char nType; unsigned char nGroup; unsigned char InCount; unsigned char OutCount; unsigned char InDWCount; unsigned char OutDWCount; unsigned char bOnline; }stClientInfo; typedef struct tagClientCfg { unsigned int KeepOut; //Keep Output when comm err; }stClientCfg; 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; 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); // @@ -276,11 +69,7 @@ /* */ int KBusParsePacket(int nChn, pKBPacket p1, int Len1); typedef struct tagMachineConfig { int bKBusMaster; int nAddr; }stMachineConfig; /* int InitMachine(stMachineConfig * pConfig); ComLib/Inc/KBusDefine.h
New file @@ -0,0 +1,329 @@ /** ****************************************************************************** * @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__ */ ComLib/Src/KBus.c
@@ -53,6 +53,7 @@ stClientInfo ClientInfo[16]; unsigned char KBusBCC(void * pData, int nSize) { unsigned char k;