QuakeGod
2024-04-12 5dd1b7fdcc52a43867f924e8d220de8467af372a
提交 | 用户 | age
483170 1 /**
Q 2   ******************************************************************************
3   * @file           : KLink.h
4   * @brief          : Header for KLink.c file.
5   *                   This file contains the common defines of the application.
6   ******************************************************************************
7     */
8 #ifndef __KLINK_H__
9 #define __KLINK_H__
10 typedef unsigned char uchar;
11 typedef unsigned char UCHAR;
12 typedef unsigned short USHORT;
13 typedef unsigned int UINT;
14
15 enum eKLResult
16 {    
17         KL_ERR = -1,
18         KL_OK = 0,
19         KL_NG = 1,
20         KL_UNKNOWN =2,
21         KL_TIMEOUT = 3,
22         KL_BCC_ERR = 4,
23         KL_PKG_ERR = 5,
24         KL_SEQ_ERR = 6,
25         KL_LENTH_EXCEED,
26         KL_NEED_PASS,
27         KL_NOT_SUPPORT,
28     
29 }    ;
30
31 enum {KLSignStart='%',    //0x25
32             KLSignReply='U',    //0x55
33             KLSignEnd=0x0D,
5dd1b7 34             KLMaxPacketLength=128,
483170 35 };
Q 36     enum enKLCMDs
37     {
38         KLCmdNone = 0x00,        //Nothing
39         KLCmdPing = 0x01,            //Ping
40 //        KLCmdPingReply = 0x02,        //PingReply
41         KLCmdInfo = 0x03,        //GetInfo
42
43         KLCmdRead = 0x05,                //Read
44 //        KLCmdReadReply = 0x06,        //ReadReply
45         KLCmdWrite = 0x07,                //Write
46 //        KLCmdWriteReply = 0x08,    //WriteReply
47         KLCmdSaveToFlash = 0x09,        //
48         
49         KLCmdExChgData=0x0A,                //ExChangeDate, = Wirte + Read
50 //        KLCmdExChgDataReply,            //ExchangeData Reply
51         
52         KLCmdSyncRead=0x0d,                //SyncRead
53         KLCmdSyncWrite,                        //SyncWrite
54         KLCmdSequenRead,                    //Sequence Read
55         KLCmdSyncTime,                        //SyncTime
56         
57         KLCmdChgMode = 0x11,
58         KLCmdGetMode = 0x12,
59
60         KLCmdChkPass,
61         KLCmdSetPass,
62         KLCmdEraseAll,
5dd1b7 63         KLCmdReadPLCProgram,
Q 64         KLCmdStartPLCProgram,
65         KLCmdWritePLCProgram,
66         KLCmdFinishPLCProgram,
483170 67
Q 68         KLCmdRead1Bit = 0x21,                //ReadSingleBit
69         KLCmdWrite1Bit = 0x22,                //WriteSingleBit
70         KLCmdReadBits = 0x23,                //ReadBits        n = 1 - 8
71         KLCmdWriteBits = 0x24,                //ReadBits        n = 1 - 8
72
73         KLCmdReadBitsByByte = 0x25,            //ReadBitsByByte
74         KLCmdWriteBitsByByte = 0x26,        //ReadBitsByByte
75
76         KLCmdReadBitsByWord = 0x27,            //ReadBitsByWord
77         KLCmdWriteBitsByWord = 0x28,        //ReadBitsByWord
78         
79         KLCmdReadDataByte = 0x31,
80         KLCmdWriteDataByte = 0x32 ,
81
82         KLCmdReadDataWord = 0x33,
83         KLCmdWriteDataWord = 0x34,
84
85         KLCmdReadData = 0x35,
86         KLCmdWriteData = 0x36 ,
87         
88         KLCmdStopBlinkLED = 0x4F,
89         KLCmdBlinkLED = 0x50,
90         
91         KLCmdReadProg = 0x51,
92         KLCmdWriteProg,
93         KLCmdReadSysCfg,
94         KLCmdWriteSysCfg,
95         KLCmdSaveSysCfg,
96         KLCmdSaveRunStat,
97         KLCmdReadRunStat,
98         KLCmdClearRunStat,
99         
100         KLCmdEraseFlashPage = 0x61,
101         KLCmdWriteToFlash = 0x62,
102         
103         KLCmdGetEventLogCount,
104         KLCmdGetEventLog,
105         KLCmdClearEventLog,
106         KLCmdGetFactoryData,
107         KLCmdWriteFactoryData,
108         KLCmdResetMachine,
109         KLCmdGetUid,
110         KLCmdSetTime,
111         KLCmdGetSN,
112         KLCmdReadFactData,
113         KLCmdWriteFactData,
114
115         KLCmdMC = 0x70,         
116         KLCmdMD,
117         KLCmdMG,
118         
5dd1b7 119         KLCmdWriteFirmware,
Q 120         KLCmdWriteFirmInfo,
483170 121         KLCmdErrRply=0xEE,                //ERRORReply
Q 122     };
123
124     enum enKLInfoType
125     {
126         KLInfoTypeInfo = 0,
127         KLInfoTypeUID = 1,
128         KLInfoTypeSN = 2,
129         KLInfoTypeEventLogCount = 3,
130     };
131     
132 extern unsigned char KLPacketBuf1[256];
133 extern unsigned char KLPacketBuf2[256];
134
135 extern unsigned char KLBufferIn[16];
136 extern unsigned char KLBufferOut[16];
137
138 extern unsigned char nKLStationId;
139 extern unsigned char nKLSeq;
140
141 extern int KLThisuS;
142 extern int KLRecvTimeuS;
143
144 #pragma anon_unions
145 typedef union tagKLStatDef
146 {
147     UCHAR StatByte;
148     struct {
149         UCHAR nSEQ : 4;
150         UCHAR HasExt : 1;
151         UCHAR HasErr : 1;
152     };
153 }unKLStat, *pKLStat;
154 /*
155 typedef struct tagKLStatDef
156 {
157     UCHAR Confirm : 2;
158     UCHAR HasExt : 1;
159     UCHAR HasErr : 1;
160 }stKLStat,*pKLStat;
161 */
162 extern unKLStat nKLStatus;
163
164 typedef struct tagKLReqPktHdr
165 {
166     unsigned char ReqStSgn;        //
167     unsigned char DstHost;        //
168     unsigned char Stat;                //
169     unsigned char nCMD;                //
170     unsigned char nType1;            //
171     unsigned char Params[1];        //
172 }stKLReqPktHdr,* pKLReqPktHdr;
173 /*
174 typedef struct tagKLPingReqPkt
175 {
176     unsigned char ReqStSgn;        //
177     unsigned char DstHost;        //
178     unsigned char nCMD;                //
179     unsigned char nSize;            //
180     
181 }stKLPingReqPkt,* pKLPingReqPkt;
182 */
183 typedef struct tagKLRplyPktHdr
184 {
185     unsigned char RplyStSgn;    //
186     unsigned char DstHost;        //
187     unsigned char nStatus;        //    
188     unsigned char nRplyCMD;        //
189     unsigned char nSize1;            //
190     unsigned char Datas[1];        //
191 }stKLRplyPktHdr,* pKLRplyPktHdr;
192
193 /*
194 typedef struct tagKLPktHdr
195 {
196         unsigned char StSign;        //起始标记
197         unsigned char SrcAddr;    //源地址
198         unsigned char DstHost;    //目标地址
199         unsigned char nCMD;        //命令
200     
201 }stKLPtHdr, * pKLPktHdr;
202 */
203 /*
204 typedef struct tagKLRdPkt
205 {
206         unsigned char StSign;        //起始标记        
207         unsigned char SrcAddr;    //源地址
208         unsigned char DstHost;    //目标地址
209         unsigned char nCMD;        //命令
210         unsigned char nType;
211         unsigned char nAddr;    //
212 }stKLRdPkt,* pKLRdKpt;
213 */
214 /*
215 typedef struct tagKLPacket
216     {
217         unsigned char StSign;        //起始标记        
218         unsigned char SrcAddr;    //源地址
219         unsigned char DstHost;    //目标地址
220         unsigned char nCMD;        //命令
221         unsigned char nSEQ;        //序列号
222         unsigned char LoadLen;    //数据载荷长度    不包括头部5个字节,不包括尾部BCC。
223         unsigned char data[1];        //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
224     }stKLPacket,* pKLPacket;    
225 */
226
227 unsigned char KLBCC(const void * pData, int nSize);
228 //
229
230     /* Make a Packet and return Packet Length */
231 int KLMakeReqPacket(void * pBuf1, uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
232 int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
233
234 /*   */
235 int KLCheckPacket(int nChn, void * pBuf1, int len1);
236
237 /* */
238 int KLParsePacket(int nChn, void * pBuf1, int Len1);
239
5dd1b7 240 typedef void *(*KLinkEvCBDef) (int nChn, int nEvent, void *, int);    //Event callback func ,prama s is  void *,void *,int; return void *;
Q 241 typedef int (*KLinkSvCBDef) (int nChn, int nSvType, int ,void *, int);    //Service Req callback func ,param is  int ,int, int, void *,int; return int;
242
483170 243 //int ReadData(void);
Q 244
245 //int WriteData(void);
246
247 //int GetStat(void);
248
249
250 #endif    /* __KLINK_H__ */
251