QuakeGod
2024-02-24 8b51c78f1b88d94a89bb8c37ae38a54f523cb597
提交 | 用户 | 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,
34             KLMaxPacketLength=64,
35 };
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,
63         KLCmdReadProgram,
64         KLCmdStartProgram,
65         KLCmdWriteProgram,
66         KLCmdFinishProgram,
67
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         
119         
120         KLCmdErrRply=0xEE,                //ERRORReply
121     };
122
123     enum enKLInfoType
124     {
125         KLInfoTypeInfo = 0,
126         KLInfoTypeUID = 1,
127         KLInfoTypeSN = 2,
128         KLInfoTypeEventLogCount = 3,
129     };
130     
131 extern unsigned char KLPacketBuf1[256];
132 extern unsigned char KLPacketBuf2[256];
133
134 extern unsigned char KLBufferIn[16];
135 extern unsigned char KLBufferOut[16];
136
137 extern unsigned char nKLStationId;
138 extern unsigned char nKLSeq;
139
140 extern int KLThisuS;
141 extern int KLRecvTimeuS;
142
143 #pragma anon_unions
144 typedef union tagKLStatDef
145 {
146     UCHAR StatByte;
147     struct {
148         UCHAR nSEQ : 4;
149         UCHAR HasExt : 1;
150         UCHAR HasErr : 1;
151     };
152 }unKLStat, *pKLStat;
153 /*
154 typedef struct tagKLStatDef
155 {
156     UCHAR Confirm : 2;
157     UCHAR HasExt : 1;
158     UCHAR HasErr : 1;
159 }stKLStat,*pKLStat;
160 */
161 extern unKLStat nKLStatus;
162
163 typedef struct tagKLReqPktHdr
164 {
165     unsigned char ReqStSgn;        //
166     unsigned char DstHost;        //
167     unsigned char Stat;                //
168     unsigned char nCMD;                //
169     unsigned char nType1;            //
170     unsigned char Params[1];        //
171 }stKLReqPktHdr,* pKLReqPktHdr;
172 /*
173 typedef struct tagKLPingReqPkt
174 {
175     unsigned char ReqStSgn;        //
176     unsigned char DstHost;        //
177     unsigned char nCMD;                //
178     unsigned char nSize;            //
179     
180 }stKLPingReqPkt,* pKLPingReqPkt;
181 */
182 typedef struct tagKLRplyPktHdr
183 {
184     unsigned char RplyStSgn;    //
185     unsigned char DstHost;        //
186     unsigned char nStatus;        //    
187     unsigned char nRplyCMD;        //
188     unsigned char nSize1;            //
189     unsigned char Datas[1];        //
190 }stKLRplyPktHdr,* pKLRplyPktHdr;
191
192 /*
193 typedef struct tagKLPktHdr
194 {
195         unsigned char StSign;        //起始标记
196         unsigned char SrcAddr;    //源地址
197         unsigned char DstHost;    //目标地址
198         unsigned char nCMD;        //命令
199     
200 }stKLPtHdr, * pKLPktHdr;
201 */
202 /*
203 typedef struct tagKLRdPkt
204 {
205         unsigned char StSign;        //起始标记        
206         unsigned char SrcAddr;    //源地址
207         unsigned char DstHost;    //目标地址
208         unsigned char nCMD;        //命令
209         unsigned char nType;
210         unsigned char nAddr;    //
211 }stKLRdPkt,* pKLRdKpt;
212 */
213 /*
214 typedef struct tagKLPacket
215     {
216         unsigned char StSign;        //起始标记        
217         unsigned char SrcAddr;    //源地址
218         unsigned char DstHost;    //目标地址
219         unsigned char nCMD;        //命令
220         unsigned char nSEQ;        //序列号
221         unsigned char LoadLen;    //数据载荷长度    不包括头部5个字节,不包括尾部BCC。
222         unsigned char data[1];        //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
223     }stKLPacket,* pKLPacket;    
224 */
225
226 unsigned char KLBCC(const void * pData, int nSize);
227 //
228
229     /* Make a Packet and return Packet Length */
230 int KLMakeReqPacket(void * pBuf1, uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
231 int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
232
233 /*   */
234 int KLCheckPacket(int nChn, void * pBuf1, int len1);
235
236 /* */
237 int KLParsePacket(int nChn, void * pBuf1, int Len1);
238
239 //int ReadData(void);
240
241 //int WriteData(void);
242
243 //int GetStat(void);
244
245
246 #endif    /* __KLINK_H__ */
247