QuakeGod
2022-10-17 eb4ffba9f16634e6f8144b9e85a0291e1cb8dfba
Inc/KLink.h
@@ -28,8 +28,8 @@
   
}   ;
enum {KLSignStart='%',
         KLSignReply='U',
enum {KLSignStart='%',   //0x25
         KLSignReply='U',   //0x55
         KLSignEnd=0x0D,
         KLMaxPacketLength=64,
};
@@ -61,7 +61,9 @@
      KLCmdSetPass,
      KLCmdEraseAll,
      KLCmdReadProgram,
      KLCmdStartProgram,
      KLCmdWriteProgram,
      KLCmdFinishProgram,
      KLCmdRead1Bit = 0x21,            //ReadSingleBit
      KLCmdWrite1Bit = 0x22,            //WriteSingleBit
@@ -90,6 +92,7 @@
      KLCmdWriteSysCfg,
      KLCmdSaveSysCfg,
      KLCmdSaveRunStat,
      KLCmdReadRunStat,
      
      KLCmdEraseFlashPage = 0x61,
      KLCmdWriteToFlash = 0x62,
@@ -102,8 +105,11 @@
      KLCmdResetMachine,
      KLCmdGetUid,
      KLCmdSetTime,
      KLCmdMC,
      KLCmdGetSN,
      KLCmdReadFactData,
      KLCmdWriteFactData,
      KLCmdMC = 0x70,
      KLCmdMD,
      KLCmdMG,
      
@@ -119,55 +125,6 @@
      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,
      KLDataTypeSV = 7,
      KLDataTypeEV = 8,
      KLDataTypeLD = 9,
      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];
@@ -203,7 +160,7 @@
typedef struct tagKLReqPktHdr
{
   unsigned char ReqStSgn;      //
   unsigned char DstAddr;      //
   unsigned char DstHost;      //
   unsigned char Stat;            //
   unsigned char nCMD;            //
   unsigned char nType1;         //
@@ -213,7 +170,7 @@
typedef struct tagKLPingReqPkt
{
   unsigned char ReqStSgn;      //
   unsigned char DstAddr;      //
   unsigned char DstHost;      //
   unsigned char nCMD;            //
   unsigned char nSize;         //
   
@@ -222,7 +179,7 @@
typedef struct tagKLRplyPktHdr
{
   unsigned char RplyStSgn;   //
   unsigned char DstAddr;      //
   unsigned char DstHost;      //
   unsigned char nStatus;      //   
   unsigned char nRplyCMD;      //
   unsigned char nSize1;         //
@@ -234,7 +191,7 @@
{
      unsigned char StSign;      //起始标记
      unsigned char SrcAddr;   //源地址
      unsigned char DstAddr;   //目标地址
      unsigned char DstHost;   //目标地址
      unsigned char nCMD;      //命令
   
}stKLPtHdr, * pKLPktHdr;
@@ -244,7 +201,7 @@
{
      unsigned char StSign;      //起始标记      
      unsigned char SrcAddr;   //源地址
      unsigned char DstAddr;   //目标地址
      unsigned char DstHost;   //目标地址
      unsigned char nCMD;      //命令
      unsigned char nType;
      unsigned char nAddr;   //
@@ -255,7 +212,7 @@
   {
      unsigned char StSign;      //起始标记      
      unsigned char SrcAddr;   //源地址
      unsigned char DstAddr;   //目标地址
      unsigned char DstHost;   //目标地址
      unsigned char nCMD;      //命令
      unsigned char nSEQ;      //序列号
      unsigned char LoadLen;   //数据载荷长度   不包括头部5个字节,不包括尾部BCC。
@@ -263,18 +220,18 @@
   }stKLPacket,* pKLPacket;   
*/
unsigned char KLBCC(void * pData, int nSize);
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, void *pData );
int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
/*   */
int KLCheckPacket(void * pBuf1,int len1);
int KLCheckPacket(int nChn, void * pBuf1, int len1);
/* */
int KLParsePacket(void * pBuf1, int Len1);
int KLParsePacket(int nChn, void * pBuf1, int Len1);
//int ReadData(void);