/**
|
******************************************************************************
|
* @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='%',
|
KLSignReply='U',
|
KLSignEnd=0x0D,
|
KLMaxPacketLength=64,
|
};
|
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,
|
KLCmdReadProgram,
|
KLCmdWriteProgram,
|
|
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 ,
|
|
|
KLCmdReadProg = 0x51,
|
KLCmdWriteProg,
|
KLCmdReadSysCfg,
|
KLCmdWriteSysCfg,
|
KLCmdSaveSysCfg,
|
KLCmdSaveRunStat,
|
|
KLCmdEraseFlashPage = 0x61,
|
KLCmdWriteToFlash = 0x62,
|
|
KLCmdGetEventLogCount,
|
KLCmdGetEventLog,
|
KLCmdClearEventLog,
|
KLCmdGetFactoryData,
|
KLCmdWriteFactoryData,
|
KLCmdResetMachine,
|
KLCmdGetUid,
|
KLCmdSetTime,
|
|
KLCmdMC,
|
KLCmdMD,
|
KLCmdMG,
|
|
|
KLCmdErrRply=0xEE, //ERRORReply
|
};
|
|
enum enKLInfoType
|
{
|
KLInfoTypeInfo = 0,
|
KLInfoTypeUID = 1,
|
KLInfoTypeSN = 2,
|
KLInfoTypeEventLogCount = 3,
|
};
|
|
enum enKLCoilTypes
|
{
|
KLCoilTypeX = 0, //X Input
|
KLCoilTypeY = 1, //Y Output
|
KLCoilTypeR = 2, //R register
|
KLCoilTypeLX = 3, //Link register
|
KLCoilTypeLY = 4, //Link register
|
KLCoilTypeT = 5, //Timer
|
KLCoilTypeC = 5, //Counter
|
KLCoilTypeLR = 6, //Link register
|
|
};
|
enum enKLDataTypes
|
{
|
KLDataTypeWX = 0,
|
KLDataTypeWY = 1,
|
KLDataTypeWR = 2,
|
KLDataTypeWLX = 3,
|
KLDataTypeWLY = 4,
|
KLDataTypeDT = 5,
|
KLDataTypeSDT = 6,
|
KLDataTypeWSR = 7,
|
KLDataTypeSV = 8,
|
KLDataTypeEV = 9,
|
KLDataTypeLD = 10,
|
|
KLDataSysCfg = 25,
|
KLDataTypeFlash = 33 ,
|
|
KLDataTypeTest = 254,
|
};
|
enum enKLDataCounts
|
{
|
KLCoilXCount=256,
|
KLCoilYCount=256,
|
KLCoilRCount=256,
|
KLCoilTCount=64,
|
KLCoilCCount=64,
|
KLCoilLCount=128,
|
KLDataDTCount = 256,
|
KLDataSDTCount = 256,
|
KLDataWXCount = 16,
|
KLDataWYCount = 16,
|
KLDataWRCount = 16,
|
KLDataSVCount = 64,
|
KLDataEVCount = 64,
|
KLDataLDCount = 64,
|
KLDataWLCount = 8,
|
};
|
|
extern unsigned char KLPacketBuf1[256];
|
extern unsigned char KLPacketBuf2[256];
|
|
extern unsigned char KLBufferIn[16];
|
extern unsigned char KLBufferOut[16];
|
|
extern unsigned char nKLAddr;
|
extern unsigned char nKLSeq;
|
|
extern int KLThisuS;
|
extern int KLRecvTimeuS;
|
|
#pragma anon_unions
|
typedef union tagKLStatDef
|
{
|
UCHAR StatByte;
|
struct {
|
UCHAR nSEQ : 4;
|
UCHAR HasExt : 1;
|
UCHAR HasErr : 1;
|
};
|
}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 DstAddr; //
|
unsigned char Stat; //
|
unsigned char nCMD; //
|
unsigned char nType1; //
|
unsigned char Params[1]; //
|
}stKLReqPktHdr,* pKLReqPktHdr;
|
/*
|
typedef struct tagKLPingReqPkt
|
{
|
unsigned char ReqStSgn; //
|
unsigned char DstAddr; //
|
unsigned char nCMD; //
|
unsigned char nSize; //
|
|
}stKLPingReqPkt,* pKLPingReqPkt;
|
*/
|
typedef struct tagKLRplyPktHdr
|
{
|
unsigned char RplyStSgn; //
|
unsigned char DstAddr; //
|
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 DstAddr; //Ä¿±êµØÖ·
|
unsigned char nCMD; //ÃüÁî
|
|
}stKLPtHdr, * pKLPktHdr;
|
*/
|
/*
|
typedef struct tagKLRdPkt
|
{
|
unsigned char StSign; //Æðʼ±ê¼Ç
|
unsigned char SrcAddr; //Ô´µØÖ·
|
unsigned char DstAddr; //Ä¿±êµØÖ·
|
unsigned char nCMD; //ÃüÁî
|
unsigned char nType;
|
unsigned char nAddr; //
|
}stKLRdPkt,* pKLRdKpt;
|
*/
|
/*
|
typedef struct tagKLPacket
|
{
|
unsigned char StSign; //Æðʼ±ê¼Ç
|
unsigned char SrcAddr; //Ô´µØÖ·
|
unsigned char DstAddr; //Ä¿±êµØÖ·
|
unsigned char nCMD; //ÃüÁî
|
unsigned char nSEQ; //ÐòÁкÅ
|
unsigned char LoadLen; //Êý¾ÝÔغɳ¤¶È ²»°üÀ¨Í·²¿5¸ö×Ö½Ú£¬²»°üÀ¨Î²²¿BCC¡£
|
unsigned char data[1]; //Êý¾ÝÔغÉ,×îĩβÊÇBCC£¬Êý¾Ý³¤¶ÈΪ0ʱ£¬Êµ¼ÊÒ²ÓÐÒ»¸öÊý¾Ý¡£
|
}stKLPacket,* pKLPacket;
|
*/
|
|
unsigned char KLBCC(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, void *pData );
|
|
/* */
|
int KLCheckPacket(void * pBuf1,int len1);
|
|
/* */
|
int KLParsePacket(void * pBuf1, int Len1);
|
|
//int ReadData(void);
|
|
//int WriteData(void);
|
|
//int GetStat(void);
|
|
|
#endif /* __KLINK_H__ */
|
|