QuakeGod
2024-10-14 005755edcdc332315ba077598d4746ac195b069e
提交 | 用户 | 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,
842bb6 34             KLMaxPacketLength=256,
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,
842bb6 67         KLCmdReadPLCAnno,
Q 68         KLCmdStartPLCAnno,
69         KLCmdWritePLCAnno,
70         KLCmdFinishPLCAnno,    
71     
483170 72         KLCmdRead1Bit = 0x21,                //ReadSingleBit
Q 73         KLCmdWrite1Bit = 0x22,                //WriteSingleBit
74         KLCmdReadBits = 0x23,                //ReadBits        n = 1 - 8
75         KLCmdWriteBits = 0x24,                //ReadBits        n = 1 - 8
76
77         KLCmdReadBitsByByte = 0x25,            //ReadBitsByByte
78         KLCmdWriteBitsByByte = 0x26,        //ReadBitsByByte
79
80         KLCmdReadBitsByWord = 0x27,            //ReadBitsByWord
81         KLCmdWriteBitsByWord = 0x28,        //ReadBitsByWord
82         
83         KLCmdReadDataByte = 0x31,
84         KLCmdWriteDataByte = 0x32 ,
85
86         KLCmdReadDataWord = 0x33,
87         KLCmdWriteDataWord = 0x34,
88
89         KLCmdReadData = 0x35,
90         KLCmdWriteData = 0x36 ,
91         
92         KLCmdStopBlinkLED = 0x4F,
93         KLCmdBlinkLED = 0x50,
94         
95         KLCmdReadProg = 0x51,
96         KLCmdWriteProg,
97         KLCmdReadSysCfg,
98         KLCmdWriteSysCfg,
99         KLCmdSaveSysCfg,
100         KLCmdSaveRunStat,
101         KLCmdReadRunStat,
102         KLCmdClearRunStat,
103         
104         KLCmdEraseFlashPage = 0x61,
105         KLCmdWriteToFlash = 0x62,
106         
107         KLCmdGetEventLogCount,
108         KLCmdGetEventLog,
109         KLCmdClearEventLog,
110         KLCmdGetFactoryData,
111         KLCmdWriteFactoryData,
112         KLCmdResetMachine,
113         KLCmdGetUid,
114         KLCmdSetTime,
115         KLCmdGetSN,
116         KLCmdReadFactData,
117         KLCmdWriteFactData,
118
119         KLCmdMC = 0x70,         
120         KLCmdMD,
121         KLCmdMG,
122         
5dd1b7 123         KLCmdWriteFirmware,
Q 124         KLCmdWriteFirmInfo,
842bb6 125         KLCmdGetPortInfo,
Q 126         KLCmdGetPortChnInfo,
127         KLCmdGetPortChildInfo,
128         KLCmdPortRemoteReq,
129         
483170 130         KLCmdErrRply=0xEE,                //ERRORReply
Q 131     };
132
133     enum enKLInfoType
134     {
135         KLInfoTypeInfo = 0,
136         KLInfoTypeUID = 1,
137         KLInfoTypeSN = 2,
138         KLInfoTypeEventLogCount = 3,
139     };
140     
842bb6 141 //extern unsigned char KLPacketBuf1[256];
483170 142 extern unsigned char KLPacketBuf2[256];
Q 143
144 extern unsigned char KLBufferIn[16];
145 extern unsigned char KLBufferOut[16];
146
147 extern unsigned char nKLStationId;
148 extern unsigned char nKLSeq;
149
150 extern int KLThisuS;
151 extern int KLRecvTimeuS;
152
842bb6 153 //PendReq 状态
Q 154     //0, 没有
155     //1, 执行中
156     //2, 成功完成
157     //3, 失败
483170 158 #pragma anon_unions
Q 159 typedef union tagKLStatDef
160 {
161     UCHAR StatByte;
162     struct {
163         UCHAR nSEQ : 4;
164         UCHAR HasExt : 1;
165         UCHAR HasErr : 1;
842bb6 166         UCHAR PendReqStat : 2;
483170 167     };
Q 168 }unKLStat, *pKLStat;
169 /*
170 typedef struct tagKLStatDef
171 {
172     UCHAR Confirm : 2;
173     UCHAR HasExt : 1;
174     UCHAR HasErr : 1;
175 }stKLStat,*pKLStat;
176 */
177 extern unKLStat nKLStatus;
178
179 typedef struct tagKLReqPktHdr
180 {
181     unsigned char ReqStSgn;        //
182     unsigned char DstHost;        //
183     unsigned char Stat;                //
184     unsigned char nCMD;                //
185     unsigned char nType1;            //
186     unsigned char Params[1];        //
187 }stKLReqPktHdr,* pKLReqPktHdr;
188 /*
189 typedef struct tagKLPingReqPkt
190 {
191     unsigned char ReqStSgn;        //
192     unsigned char DstHost;        //
193     unsigned char nCMD;                //
194     unsigned char nSize;            //
195     
196 }stKLPingReqPkt,* pKLPingReqPkt;
197 */
198 typedef struct tagKLRplyPktHdr
199 {
200     unsigned char RplyStSgn;    //
201     unsigned char DstHost;        //
202     unsigned char nStatus;        //    
203     unsigned char nRplyCMD;        //
204     unsigned char nSize1;            //
205     unsigned char Datas[1];        //
206 }stKLRplyPktHdr,* pKLRplyPktHdr;
207
208 /*
209 typedef struct tagKLPktHdr
210 {
211         unsigned char StSign;        //起始标记
212         unsigned char SrcAddr;    //源地址
213         unsigned char DstHost;    //目标地址
214         unsigned char nCMD;        //命令
215     
216 }stKLPtHdr, * pKLPktHdr;
217 */
218 /*
219 typedef struct tagKLRdPkt
220 {
221         unsigned char StSign;        //起始标记        
222         unsigned char SrcAddr;    //源地址
223         unsigned char DstHost;    //目标地址
224         unsigned char nCMD;        //命令
225         unsigned char nType;
226         unsigned char nAddr;    //
227 }stKLRdPkt,* pKLRdKpt;
228 */
229 /*
230 typedef struct tagKLPacket
231     {
232         unsigned char StSign;        //起始标记        
233         unsigned char SrcAddr;    //源地址
234         unsigned char DstHost;    //目标地址
235         unsigned char nCMD;        //命令
236         unsigned char nSEQ;        //序列号
237         unsigned char LoadLen;    //数据载荷长度    不包括头部5个字节,不包括尾部BCC。
238         unsigned char data[1];        //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
239     }stKLPacket,* pKLPacket;    
240 */
241
842bb6 242 int KLinkInit(int );
Q 243
483170 244 unsigned char KLBCC(const void * pData, int nSize);
Q 245 //
246
247     /* Make a Packet and return Packet Length */
248 int KLMakeReqPacket(void * pBuf1, uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
249 int KLMakeRplyPacket(void * pBuf1, uchar Dst, uchar Status, uchar nCmd, uchar DataLen, const void *pData );
250
251 /*   */
252 int KLCheckPacket(int nChn, void * pBuf1, int len1);
253
254 /* */
255 int KLParsePacket(int nChn, void * pBuf1, int Len1);
256
5dd1b7 257 typedef void *(*KLinkEvCBDef) (int nChn, int nEvent, void *, int);    //Event callback func ,prama s is  void *,void *,int; return void *;
Q 258 typedef int (*KLinkSvCBDef) (int nChn, int nSvType, int ,void *, int);    //Service Req callback func ,param is  int ,int, int, void *,int; return int;
259
483170 260 //int ReadData(void);
Q 261
262 //int WriteData(void);
263
264 //int GetStat(void);
265
266
267 #endif    /* __KLINK_H__ */
268