提交 | 用户 | 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 |
|
|
88 |
|
|
89 |
KLCmdReadProg = 0x51,
|
|
90 |
KLCmdWriteProg,
|
|
91 |
KLCmdReadSysCfg,
|
|
92 |
KLCmdWriteSysCfg,
|
|
93 |
KLCmdSaveSysCfg,
|
|
94 |
KLCmdSaveRunStat,
|
e1f350
|
95 |
KLCmdReadRunStat,
|
bfc108
|
96 |
|
Q |
97 |
KLCmdEraseFlashPage = 0x61,
|
|
98 |
KLCmdWriteToFlash = 0x62,
|
|
99 |
|
|
100 |
KLCmdGetEventLogCount,
|
|
101 |
KLCmdGetEventLog,
|
|
102 |
KLCmdClearEventLog,
|
|
103 |
KLCmdGetFactoryData,
|
|
104 |
KLCmdWriteFactoryData,
|
|
105 |
KLCmdResetMachine,
|
|
106 |
KLCmdGetUid,
|
|
107 |
KLCmdSetTime,
|
e1f350
|
108 |
KLCmdGetSN,
|
Q |
109 |
KLCmdReadFactData,
|
|
110 |
KLCmdWriteFactData,
|
|
111 |
|
|
112 |
KLCmdMC = 0x70,
|
bfc108
|
113 |
KLCmdMD,
|
Q |
114 |
KLCmdMG,
|
|
115 |
|
|
116 |
|
|
117 |
KLCmdErrRply=0xEE, //ERRORReply
|
|
118 |
};
|
|
119 |
|
|
120 |
enum enKLInfoType
|
|
121 |
{
|
|
122 |
KLInfoTypeInfo = 0,
|
|
123 |
KLInfoTypeUID = 1,
|
|
124 |
KLInfoTypeSN = 2,
|
|
125 |
KLInfoTypeEventLogCount = 3,
|
|
126 |
};
|
|
127 |
|
|
128 |
extern unsigned char KLPacketBuf1[256];
|
|
129 |
extern unsigned char KLPacketBuf2[256];
|
|
130 |
|
|
131 |
extern unsigned char KLBufferIn[16];
|
|
132 |
extern unsigned char KLBufferOut[16];
|
|
133 |
|
|
134 |
extern unsigned char nKLAddr;
|
|
135 |
extern unsigned char nKLSeq;
|
|
136 |
|
|
137 |
extern int KLThisuS;
|
|
138 |
extern int KLRecvTimeuS;
|
|
139 |
|
|
140 |
#pragma anon_unions
|
|
141 |
typedef union tagKLStatDef
|
|
142 |
{
|
|
143 |
UCHAR StatByte;
|
|
144 |
struct {
|
|
145 |
UCHAR nSEQ : 4;
|
|
146 |
UCHAR HasExt : 1;
|
|
147 |
UCHAR HasErr : 1;
|
|
148 |
};
|
|
149 |
}unKLStat, *pKLStat;
|
|
150 |
/*
|
|
151 |
typedef struct tagKLStatDef
|
|
152 |
{
|
|
153 |
UCHAR Confirm : 2;
|
|
154 |
UCHAR HasExt : 1;
|
|
155 |
UCHAR HasErr : 1;
|
|
156 |
}stKLStat,*pKLStat;
|
|
157 |
*/
|
|
158 |
extern unKLStat nKLStatus;
|
|
159 |
|
|
160 |
typedef struct tagKLReqPktHdr
|
|
161 |
{
|
|
162 |
unsigned char ReqStSgn; //
|
e1f350
|
163 |
unsigned char DstHost; //
|
bfc108
|
164 |
unsigned char Stat; //
|
Q |
165 |
unsigned char nCMD; //
|
|
166 |
unsigned char nType1; //
|
|
167 |
unsigned char Params[1]; //
|
|
168 |
}stKLReqPktHdr,* pKLReqPktHdr;
|
|
169 |
/*
|
|
170 |
typedef struct tagKLPingReqPkt
|
|
171 |
{
|
|
172 |
unsigned char ReqStSgn; //
|
e1f350
|
173 |
unsigned char DstHost; //
|
bfc108
|
174 |
unsigned char nCMD; //
|
Q |
175 |
unsigned char nSize; //
|
|
176 |
|
|
177 |
}stKLPingReqPkt,* pKLPingReqPkt;
|
|
178 |
*/
|
|
179 |
typedef struct tagKLRplyPktHdr
|
|
180 |
{
|
|
181 |
unsigned char RplyStSgn; //
|
e1f350
|
182 |
unsigned char DstHost; //
|
bfc108
|
183 |
unsigned char nStatus; //
|
Q |
184 |
unsigned char nRplyCMD; //
|
|
185 |
unsigned char nSize1; //
|
|
186 |
unsigned char Datas[1]; //
|
|
187 |
}stKLRplyPktHdr,* pKLRplyPktHdr;
|
|
188 |
|
|
189 |
/*
|
|
190 |
typedef struct tagKLPktHdr
|
|
191 |
{
|
091773
|
192 |
unsigned char StSign; //起始标记
|
Q |
193 |
unsigned char SrcAddr; //源地址
|
|
194 |
unsigned char DstHost; //目标地址
|
|
195 |
unsigned char nCMD; //命令
|
bfc108
|
196 |
|
Q |
197 |
}stKLPtHdr, * pKLPktHdr;
|
|
198 |
*/
|
|
199 |
/*
|
|
200 |
typedef struct tagKLRdPkt
|
|
201 |
{
|
091773
|
202 |
unsigned char StSign; //起始标记
|
Q |
203 |
unsigned char SrcAddr; //源地址
|
|
204 |
unsigned char DstHost; //目标地址
|
|
205 |
unsigned char nCMD; //命令
|
bfc108
|
206 |
unsigned char nType;
|
Q |
207 |
unsigned char nAddr; //
|
|
208 |
}stKLRdPkt,* pKLRdKpt;
|
|
209 |
*/
|
|
210 |
/*
|
|
211 |
typedef struct tagKLPacket
|
|
212 |
{
|
091773
|
213 |
unsigned char StSign; //起始标记
|
Q |
214 |
unsigned char SrcAddr; //源地址
|
|
215 |
unsigned char DstHost; //目标地址
|
|
216 |
unsigned char nCMD; //命令
|
|
217 |
unsigned char nSEQ; //序列号
|
|
218 |
unsigned char LoadLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。
|
|
219 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
|
bfc108
|
220 |
}stKLPacket,* pKLPacket;
|
Q |
221 |
*/
|
|
222 |
|
e1f350
|
223 |
unsigned char KLBCC(const void * pData, int nSize);
|
bfc108
|
224 |
//
|
Q |
225 |
|
|
226 |
/* Make a Packet and return Packet Length */
|
|
227 |
int KLMakeReqPacket(void * pBuf1,uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
|
e1f350
|
228 |
int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
|
bfc108
|
229 |
|
Q |
230 |
/* */
|
d69aae
|
231 |
int KLCheckPacket(int nChn, void * pBuf1, int len1);
|
bfc108
|
232 |
|
Q |
233 |
/* */
|
d69aae
|
234 |
int KLParsePacket(int nChn, void * pBuf1, int Len1);
|
bfc108
|
235 |
|
Q |
236 |
//int ReadData(void);
|
|
237 |
|
|
238 |
//int WriteData(void);
|
|
239 |
|
|
240 |
//int GetStat(void);
|
|
241 |
|
|
242 |
|
|
243 |
#endif /* __KLINK_H__ */
|
|
244 |
|