/** ****************************************************************************** * @file : KLink.h * @brief : Header for KLink.c file. * This file contains the common defines of the application. ****************************************************************************** */ #ifndef __KLINK_H__ #define __KLINK_H__ typedef unsigned char uchar; typedef unsigned char UCHAR; typedef unsigned short USHORT; typedef unsigned int UINT; enum eKLResult { KL_ERR = -1, KL_OK = 0, KL_NG = 1, KL_UNKNOWN =2, KL_TIMEOUT = 3, KL_BCC_ERR = 4, KL_PKG_ERR = 5, KL_SEQ_ERR = 6, KL_LENTH_EXCEED, KL_NEED_PASS, KL_NOT_SUPPORT, } ; enum {KLSignStart='%', //0x25 KLSignReply='U', //0x55 KLSignEnd=0x0D, KLMaxPacketLength=256, }; enum enKLCMDs { KLCmdNone = 0x00, //Nothing KLCmdPing = 0x01, //Ping // KLCmdPingReply = 0x02, //PingReply KLCmdInfo = 0x03, //GetInfo KLCmdRead = 0x05, //Read // KLCmdReadReply = 0x06, //ReadReply KLCmdWrite = 0x07, //Write // KLCmdWriteReply = 0x08, //WriteReply KLCmdSaveToFlash = 0x09, // KLCmdExChgData=0x0A, //ExChangeDate, = Wirte + Read // KLCmdExChgDataReply, //ExchangeData Reply KLCmdSyncRead=0x0d, //SyncRead KLCmdSyncWrite, //SyncWrite KLCmdSequenRead, //Sequence Read KLCmdSyncTime, //SyncTime KLCmdChgMode = 0x11, KLCmdGetMode = 0x12, KLCmdChkPass, KLCmdSetPass, KLCmdEraseAll, KLCmdReadPLCProgram, KLCmdStartPLCProgram, KLCmdWritePLCProgram, KLCmdFinishPLCProgram, KLCmdReadPLCAnno, KLCmdStartPLCAnno, KLCmdWritePLCAnno, KLCmdFinishPLCAnno, KLCmdRead1Bit = 0x21, //ReadSingleBit KLCmdWrite1Bit = 0x22, //WriteSingleBit KLCmdReadBits = 0x23, //ReadBits n = 1 - 8 KLCmdWriteBits = 0x24, //ReadBits n = 1 - 8 KLCmdReadBitsByByte = 0x25, //ReadBitsByByte KLCmdWriteBitsByByte = 0x26, //ReadBitsByByte KLCmdReadBitsByWord = 0x27, //ReadBitsByWord KLCmdWriteBitsByWord = 0x28, //ReadBitsByWord KLCmdReadDataByte = 0x31, KLCmdWriteDataByte = 0x32 , KLCmdReadDataWord = 0x33, KLCmdWriteDataWord = 0x34, KLCmdReadData = 0x35, KLCmdWriteData = 0x36 , KLCmdStopBlinkLED = 0x4F, KLCmdBlinkLED = 0x50, KLCmdReadProg = 0x51, KLCmdWriteProg, KLCmdReadSysCfg, KLCmdWriteSysCfg, KLCmdSaveSysCfg, KLCmdSaveRunStat, KLCmdReadRunStat, KLCmdClearRunStat, KLCmdEraseFlashPage = 0x61, KLCmdWriteToFlash = 0x62, KLCmdGetEventLogCount, KLCmdGetEventLog, KLCmdClearEventLog, KLCmdGetFactoryData, KLCmdWriteFactoryData, KLCmdResetMachine, KLCmdGetUid, KLCmdSetTime, KLCmdGetSN, KLCmdReadFactData, KLCmdWriteFactData, KLCmdMC = 0x70, KLCmdMD, KLCmdMG, KLCmdWriteFirmware, KLCmdWriteFirmInfo, KLCmdGetPortInfo, KLCmdGetPortChnInfo, KLCmdGetPortChildInfo, KLCmdPortRemoteReq, KLCmdErrRply=0xEE, //ERRORReply }; enum enKLInfoType { KLInfoTypeInfo = 0, KLInfoTypeUID = 1, KLInfoTypeSN = 2, KLInfoTypeEventLogCount = 3, }; //extern unsigned char KLPacketBuf1[256]; extern unsigned char KLPacketBuf2[256]; extern unsigned char KLBufferIn[16]; extern unsigned char KLBufferOut[16]; extern unsigned char nKLStationId; extern unsigned char nKLSeq; extern int KLThisuS; extern int KLRecvTimeuS; //PendReq 状态 //0, 没有 //1, 执行中 //2, 成功完成 //3, 失败 #pragma anon_unions typedef union tagKLStatDef { UCHAR StatByte; struct { UCHAR nSEQ : 4; UCHAR HasExt : 1; UCHAR HasErr : 1; UCHAR PendReqStat : 2; }; }unKLStat, *pKLStat; /* typedef struct tagKLStatDef { UCHAR Confirm : 2; UCHAR HasExt : 1; UCHAR HasErr : 1; }stKLStat,*pKLStat; */ extern unKLStat nKLStatus; typedef struct tagKLReqPktHdr { unsigned char ReqStSgn; // unsigned char DstHost; // unsigned char Stat; // unsigned char nCMD; // unsigned char nType1; // unsigned char Params[1]; // }stKLReqPktHdr,* pKLReqPktHdr; /* typedef struct tagKLPingReqPkt { unsigned char ReqStSgn; // unsigned char DstHost; // unsigned char nCMD; // unsigned char nSize; // }stKLPingReqPkt,* pKLPingReqPkt; */ typedef struct tagKLRplyPktHdr { unsigned char RplyStSgn; // unsigned char DstHost; // unsigned char nStatus; // unsigned char nRplyCMD; // unsigned char nSize1; // unsigned char Datas[1]; // }stKLRplyPktHdr,* pKLRplyPktHdr; /* typedef struct tagKLPktHdr { unsigned char StSign; //起始标记 unsigned char SrcAddr; //源地址 unsigned char DstHost; //目标地址 unsigned char nCMD; //命令 }stKLPtHdr, * pKLPktHdr; */ /* typedef struct tagKLRdPkt { unsigned char StSign; //起始标记 unsigned char SrcAddr; //源地址 unsigned char DstHost; //目标地址 unsigned char nCMD; //命令 unsigned char nType; unsigned char nAddr; // }stKLRdPkt,* pKLRdKpt; */ /* typedef struct tagKLPacket { unsigned char StSign; //起始标记 unsigned char SrcAddr; //源地址 unsigned char DstHost; //目标地址 unsigned char nCMD; //命令 unsigned char nSEQ; //序列号 unsigned char LoadLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 }stKLPacket,* pKLPacket; */ int KLinkInit(int ); unsigned char KLBCC(const void * pData, int nSize); // /* Make a Packet and return Packet Length */ int KLMakeReqPacket(void * pBuf1, uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData ); int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData ); /* */ int KLCheckPacket(int nChn, void * pBuf1, int len1); /* */ int KLParsePacket(int nChn, void * pBuf1, int Len1); typedef void *(*KLinkEvCBDef) (int nChn, int nEvent, void *, int); //Event callback func ,prama s is void *,void *,int; return void *; typedef int (*KLinkSvCBDef) (int nChn, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; //int ReadData(void); //int WriteData(void); //int GetStat(void); #endif /* __KLINK_H__ */