QuakeGod
2023-02-01 2364f06313efb8eb97d4ae741a31cdd2efc175d2
提交 | 用户 | age
bfc108 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
d69aae 31 enum {KLSignStart='%',    //0x25
Q 32             KLSignReply='U',    //0x55
bfc108 33             KLSignEnd=0x0D,
Q 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,
e1f350 64         KLCmdStartProgram,
bfc108 65         KLCmdWriteProgram,
e1f350 66         KLCmdFinishProgram,
bfc108 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         
0fe6b0 88         KLCmdStopBlinkLED = 0x4F,
Q 89         KLCmdBlinkLED = 0x50,
bfc108 90         
Q 91         KLCmdReadProg = 0x51,
92         KLCmdWriteProg,
93         KLCmdReadSysCfg,
94         KLCmdWriteSysCfg,
95         KLCmdSaveSysCfg,
96         KLCmdSaveRunStat,
e1f350 97         KLCmdReadRunStat,
0fe6b0 98         KLCmdClearRunStat,
bfc108 99         
Q 100         KLCmdEraseFlashPage = 0x61,
101         KLCmdWriteToFlash = 0x62,
102         
103         KLCmdGetEventLogCount,
104         KLCmdGetEventLog,
105         KLCmdClearEventLog,
106         KLCmdGetFactoryData,
107         KLCmdWriteFactoryData,
108         KLCmdResetMachine,
109         KLCmdGetUid,
110         KLCmdSetTime,
e1f350 111         KLCmdGetSN,
Q 112         KLCmdReadFactData,
113         KLCmdWriteFactData,
114
115         KLCmdMC = 0x70,         
bfc108 116         KLCmdMD,
Q 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
0fe6b0 137 extern unsigned char nKLStationId;
bfc108 138 extern unsigned char nKLSeq;
Q 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;        //
e1f350 166     unsigned char DstHost;        //
bfc108 167     unsigned char Stat;                //
Q 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;        //
e1f350 176     unsigned char DstHost;        //
bfc108 177     unsigned char nCMD;                //
Q 178     unsigned char nSize;            //
179     
180 }stKLPingReqPkt,* pKLPingReqPkt;
181 */
182 typedef struct tagKLRplyPktHdr
183 {
184     unsigned char RplyStSgn;    //
e1f350 185     unsigned char DstHost;        //
bfc108 186     unsigned char nStatus;        //    
Q 187     unsigned char nRplyCMD;        //
188     unsigned char nSize1;            //
189     unsigned char Datas[1];        //
190 }stKLRplyPktHdr,* pKLRplyPktHdr;
191
192 /*
193 typedef struct tagKLPktHdr
194 {
0fe6b0 195         unsigned char StSign;        //起始标记
Q 196         unsigned char SrcAddr;    //源地址
197         unsigned char DstHost;    //目标地址
198         unsigned char nCMD;        //命令
bfc108 199     
Q 200 }stKLPtHdr, * pKLPktHdr;
201 */
202 /*
203 typedef struct tagKLRdPkt
204 {
0fe6b0 205         unsigned char StSign;        //起始标记        
Q 206         unsigned char SrcAddr;    //源地址
207         unsigned char DstHost;    //目标地址
208         unsigned char nCMD;        //命令
bfc108 209         unsigned char nType;
Q 210         unsigned char nAddr;    //
211 }stKLRdPkt,* pKLRdKpt;
212 */
213 /*
214 typedef struct tagKLPacket
215     {
0fe6b0 216         unsigned char StSign;        //起始标记        
Q 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时,实际也有一个数据。
bfc108 223     }stKLPacket,* pKLPacket;    
Q 224 */
225
e1f350 226 unsigned char KLBCC(const void * pData, int nSize);
bfc108 227 //
Q 228
229     /* Make a Packet and return Packet Length */
0fe6b0 230 int KLMakeReqPacket(void * pBuf1, uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
e1f350 231 int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
bfc108 232
Q 233 /*   */
d69aae 234 int KLCheckPacket(int nChn, void * pBuf1, int len1);
bfc108 235
Q 236 /* */
d69aae 237 int KLParsePacket(int nChn, void * pBuf1, int Len1);
bfc108 238
Q 239 //int ReadData(void);
240
241 //int WriteData(void);
242
243 //int GetStat(void);
244
245
246 #endif    /* __KLINK_H__ */
247