提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : KBus.h |
|
4 |
* @brief : Header for KBus.c file. |
|
5 |
* This file contains the common defines of the application. |
|
6 |
****************************************************************************** |
|
7 |
*/ |
95322c
|
8 |
#include "KBusDefine.h" |
Q |
9 |
|
483170
|
10 |
#include "KMachine.h" |
Q |
11 |
|
|
12 |
#ifndef __KBUS_H__ |
|
13 |
#define __KBUS_H__ |
|
14 |
|
|
15 |
#define KBUS_VER (0x104) |
|
16 |
|
5dd1b7
|
17 |
#define MAX_CLIENT 16 //最大支持子机数量 |
Q |
18 |
|
842bb6
|
19 |
#define KBUS_WAIT_TIME_OUT1 5 // 0.1mS ticks. |
Q |
20 |
#define KBUS_WAIT_TIME_OUT2 8 // 0.1mS ticks. |
|
21 |
|
|
22 |
#define KBUS_SLAVE_TIME_OUT 500 // 0.1ms ticks |
|
23 |
|
483170
|
24 |
//#define SYN_PREFIX 1 |
Q |
25 |
typedef unsigned char uchar; |
5dd1b7
|
26 |
typedef volatile unsigned char vuchar; |
Q |
27 |
typedef unsigned short ushort; |
483170
|
28 |
|
842bb6
|
29 |
enum enKBusStationType // KBus工作类型 |
Q |
30 |
{ |
|
31 |
KBNone = 0, // 0,未定义 |
|
32 |
KBusMaster = 1, // 1,主机 |
|
33 |
KBusSlave = 2, // 2,子机 |
|
34 |
KBusRepeater = 3, // 3,转发器,中继器 |
|
35 |
}; |
|
36 |
|
|
37 |
// diagnosis |
|
38 |
enum enKBusStats |
|
39 |
{ |
|
40 |
KBusStatUnInited, // 未初始化状态 |
|
41 |
KBusStatInited, // 已初始化状态 |
|
42 |
KBusStatConfig, // 已配置状态 |
|
43 |
KBusStatReady, // 就绪状态 |
|
44 |
KBusStatRunning, // 运行状态 |
|
45 |
KBusStatIdel, // 暂停状态 |
|
46 |
KBusStatSafe, // 安全状态 |
|
47 |
KBusStatError, // 错误状态 |
|
48 |
}; |
|
49 |
/* |
|
50 |
enum enKBusStage |
|
51 |
{ |
|
52 |
KBusStageInit, |
|
53 |
KBusStageFindChild, |
|
54 |
KBusStageConfigChild, |
|
55 |
KBusStagePoll, |
|
56 |
|
|
57 |
}; |
|
58 |
*/ |
|
59 |
typedef enum |
|
60 |
{ |
|
61 |
KBusRunStepBroadCastCfg, |
|
62 |
KBusRunStepTimeSync, |
|
63 |
KBusRunStepTimeSyncWait, |
|
64 |
KBusRunStepMultiDataPoll, |
|
65 |
KBusRunStepMultiDataPollWait, |
|
66 |
KBusRunStepUniDataPoll, |
|
67 |
KBusRunStepUniDataPollWait, |
|
68 |
KBusRunStepUniDataTranster, |
|
69 |
KBusRunStepUniDataTransterWait, |
|
70 |
|
|
71 |
}enKBusRunStep; |
|
72 |
|
|
73 |
enum { |
|
74 |
KB_SYN = 0x55, |
|
75 |
KBStartSign='%', |
|
76 |
KBEndSign=0x0D, |
|
77 |
KBMaxPacketLength=148, |
|
78 |
}; |
|
79 |
|
|
80 |
enum enCMDs |
|
81 |
{ |
|
82 |
|
|
83 |
cmdNone = 0x00, //Nothing |
|
84 |
|
|
85 |
cmdQuery = 0x01, //Query basic Info |
|
86 |
cmdQueryRply = 0x81, //Query Info Reply |
|
87 |
|
|
88 |
cmdSetCfg = 0x02, // Set Configuration |
|
89 |
cmdSetCfgRply = 0x82, // Set Configuration Response |
|
90 |
|
|
91 |
cmdToRunMode = 0x03, |
|
92 |
cmdToRunModeRply = 0x83, |
|
93 |
|
|
94 |
cmdBroadCastCfg = 0x04, // |
|
95 |
|
|
96 |
cmdMuExchgData = 0x05, // |
|
97 |
cmdMuExchgDataRply = 0x85, // |
|
98 |
|
|
99 |
cmdToSafeMode = 0x06, |
|
100 |
|
|
101 |
cmdHeartBeat = 0x07, // |
|
102 |
cmdReHeartBeat = 0x87, // |
|
103 |
|
|
104 |
|
|
105 |
cmdRemoteReq = 0x1B, |
|
106 |
cmdRemoteReqReply = cmdRemoteReq|0x80, // |
|
107 |
|
|
108 |
cmdPing = '1', //Ping |
|
109 |
cmdPingReply = '2', //PingReply |
|
110 |
cmdRead = '3', //Read |
|
111 |
cmdReadReply = '4', //ReadReply |
|
112 |
cmdWrite = '5', //Write |
|
113 |
cmdWriteReply = '6', //WriteReply |
|
114 |
cmdGetVersion = '7', //GetVersion |
|
115 |
cmdVerInfo = '8', //VersionReply |
|
116 |
|
|
117 |
cmdUniExChgData='A', //ExChangeData, = Wirte + Read |
|
118 |
cmdExChgDataReply, //ExchangeData Reply |
|
119 |
|
|
120 |
cmdSyncRead='a', //SyncRead |
|
121 |
cmdSyncWrite, //SyncWrite |
|
122 |
cmdSequenRead, //Sequence Read |
|
123 |
cmdSyncTime, //SyncTime |
|
124 |
}; |
|
125 |
|
|
126 |
|
|
127 |
typedef struct tagVerInfo // KBus 版本信息 |
|
128 |
{ |
|
129 |
unsigned char nMainVer; |
|
130 |
unsigned char nSubVer; |
|
131 |
}stVerInfo; |
|
132 |
|
|
133 |
typedef struct tagMasterStat // KBus 主机状态? |
|
134 |
{ |
|
135 |
unsigned int CycleTime; |
|
136 |
} stMasterStat; |
|
137 |
|
|
138 |
typedef struct tagDeviceInfo // KBus 子机基本信息 |
|
139 |
{ |
|
140 |
unsigned short DeviceType; // 子机类型 |
|
141 |
unsigned short DeviceVer; // 子机版本 |
|
142 |
unsigned char InBitCount; // 输入开关量数量 |
|
143 |
unsigned char OutBitCount; // 输出开关量数量 |
|
144 |
unsigned char ExInBitCount; // 扩展的输入开关量数量 |
|
145 |
unsigned char ExOutBitCount; // 扩展的输出开关量数量 |
|
146 |
unsigned char DWStartAddr; // 输出数据字数 |
|
147 |
unsigned char OutDWCount; // 输出数据字数 |
|
148 |
unsigned char AIWCount; // 输入模拟量通道(字)数 // 16位为一个字(通道) |
|
149 |
unsigned char AQWCount; // 输出模拟量通道(字)数 // 16位为一个字(通道) |
|
150 |
// unsigned char AIBits; // 每通道位数 // 16位以下 |
|
151 |
// unsigned char AQbits; // 每通道位数 // 16位以下 |
|
152 |
|
|
153 |
|
|
154 |
}stDeviceInfo; |
|
155 |
|
|
156 |
typedef struct tagExDeviceInfo // 子机扩展信息 |
|
157 |
{ |
|
158 |
unsigned short DeviceType; // 子机类型 |
|
159 |
unsigned short DeviceVer; // 子机版本 |
|
160 |
|
|
161 |
unsigned char UID[12]; // 12字节 UUID |
|
162 |
unsigned char Name[16]; // 16字节 名称 |
|
163 |
// stVerInfo ClientVer; |
|
164 |
unsigned char InBitCount; |
|
165 |
unsigned char OutBitCount; |
|
166 |
unsigned char ExInBitCount; // 扩展的输入开关量数量 |
|
167 |
unsigned char ExOutBitCount; // 扩展的输出开关量数量 |
|
168 |
unsigned char DWStartAddr; |
|
169 |
unsigned char OutDWCount; |
|
170 |
unsigned char AIWCount; |
|
171 |
unsigned char AQWCount; |
|
172 |
// unsigned char AIBits; |
|
173 |
// unsigned char AQbits; |
|
174 |
|
|
175 |
|
|
176 |
}stExDeviceInfo; |
|
177 |
|
|
178 |
enum enKBusConfigStat |
|
179 |
{ |
|
180 |
KBusUnConfiged = 0, |
|
181 |
KBusDefaultConfiged =1, |
|
182 |
KBusConfiged = 2, |
|
183 |
}; |
|
184 |
|
|
185 |
typedef struct tagClientCfg // 子机配置 |
|
186 |
{ |
|
187 |
unsigned char Addr; // 子机地址 |
|
188 |
unsigned char Configed; // 是否已配置 |
|
189 |
unsigned char bOnline; //当前在线状态 |
|
190 |
unsigned char InStartAddrBit; //输入起始位地址 |
|
191 |
unsigned char OutStartAddrBit; //输出起始位地址 |
|
192 |
unsigned char AIWStartAddrByte; //模拟入起始字地址 |
|
193 |
unsigned char AQWStartAddrByte; //模拟出起始字地址 |
|
194 |
unsigned char DIWStartAddrByte; //数据入起始字地址 |
|
195 |
unsigned char DOWStartAddrByte; //数据出起始字地址 |
|
196 |
unsigned char KeepOut; //Keep Output when comm err; |
|
197 |
}stClientCfg; |
|
198 |
|
|
199 |
/* |
|
200 |
typedef struct ServerStatus |
|
201 |
{ |
|
202 |
unsigned char Addr; |
|
203 |
unsigned char Status; |
|
204 |
unsigned short Input[16]; |
|
205 |
unsigned short DT[128]; |
|
206 |
unsigned short output[16]; |
|
207 |
|
|
208 |
}stServerStatus,*pServerStatus; |
|
209 |
*/ |
|
210 |
typedef struct tagMachineState // 本机状态 |
|
211 |
{ |
|
212 |
unsigned char Addr; // 地址 |
|
213 |
unsigned char state; //״̬ |
|
214 |
unsigned char InStartAddrBit; //输入起始位地址 |
|
215 |
unsigned char OutStartAddrBit; //输出起始位地址 |
|
216 |
unsigned char InDWStartAddrByte; //字输入起始字地址 |
|
217 |
unsigned char OutDWStartAddrByte; //字输出起始字地址 |
|
218 |
}ClientState; |
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
#pragma anon_unions |
|
223 |
typedef struct tagChnStat |
|
224 |
{ |
|
225 |
union{ |
|
226 |
unsigned char MStat; |
|
227 |
struct{ |
|
228 |
unsigned char bOnline:1; |
|
229 |
unsigned char bErr1:1; |
|
230 |
unsigned char bErr2:1; |
|
231 |
unsigned char bReq:1; |
|
232 |
}; |
|
233 |
}; |
|
234 |
unsigned char SStat; |
|
235 |
unsigned short SendPackets; |
|
236 |
unsigned short RecvPackets; |
|
237 |
unsigned short LastSentTimeTick; |
|
238 |
unsigned short LostPackets; |
|
239 |
unsigned short CtnLstPkts; |
|
240 |
unsigned short MaxCtnLstPkts; |
|
241 |
unsigned short NotPkgErr; |
|
242 |
unsigned short PkgLenErr; |
|
243 |
unsigned short BCCErr; |
|
244 |
unsigned short TimeOutErr; |
|
245 |
unsigned short Delay; |
|
246 |
unsigned short MaxDelay; |
|
247 |
unsigned short SendTimeInterval; |
|
248 |
union |
|
249 |
{ |
|
250 |
unsigned short ClientDatas[10]; |
|
251 |
struct { |
|
252 |
unsigned short ClientRecvPkts; // |
|
253 |
unsigned short ClientSendPkts; // |
|
254 |
unsigned short ClientNotPktErr; // |
|
255 |
unsigned short ClientMisIdPkts; // |
|
256 |
// unsigned int ClientNoEndErr; // |
|
257 |
unsigned short ClientPkgLenErr; // |
|
258 |
unsigned short ClientBccErr; // |
|
259 |
unsigned short ClientTimeOutErr; // |
|
260 |
}; |
|
261 |
}; |
|
262 |
} stChnStat; |
|
263 |
|
|
264 |
|
|
265 |
typedef struct tagSlaveStat |
|
266 |
{ |
|
267 |
unsigned int nSlaveTick; |
|
268 |
} stSlaveStat; |
|
269 |
|
|
270 |
typedef struct ServerClientListElement |
|
271 |
{ |
|
272 |
unsigned char Addr; |
|
273 |
unsigned char Status; |
|
274 |
unsigned char Father; |
|
275 |
unsigned char Childs; |
|
276 |
|
|
277 |
} stServerClientListElement; |
|
278 |
|
|
279 |
typedef struct ServerClientList |
|
280 |
{ |
|
281 |
unsigned char Addr; |
|
282 |
}stServerClientList,*pServerClientList; |
|
283 |
|
|
284 |
typedef struct tagMachineConfig |
|
285 |
{ |
|
286 |
int bKBusMaster; |
|
287 |
int nAddr; |
|
288 |
}stMachineConfig; |
|
289 |
|
|
290 |
/* |
|
291 |
typedef struct ClientStatus |
|
292 |
{ |
|
293 |
unsigned char Addr; |
|
294 |
unsigned char Status; |
|
295 |
unsigned char Father; |
|
296 |
unsigned char Childs; |
|
297 |
unsigned short Input[16]; |
|
298 |
unsigned short DT[128]; |
|
299 |
unsigned short output[16]; |
|
300 |
|
|
301 |
}stChnStatus,*pClientStatus; |
|
302 |
*/ |
|
303 |
|
|
304 |
typedef struct tagStatusDef |
|
305 |
{ |
|
306 |
unsigned char nSeq:2; //序列号 |
|
307 |
unsigned char :2; |
|
308 |
unsigned char nErr1:1; |
|
309 |
unsigned char nErr2:1; |
|
310 |
unsigned char bReq:1; |
|
311 |
|
|
312 |
}stStatus; |
|
313 |
|
|
314 |
typedef union tagUnStatusDef |
|
315 |
{ |
|
316 |
unsigned char nStatus; |
|
317 |
stStatus; |
|
318 |
}unStatus; |
|
319 |
|
|
320 |
typedef struct tagKBPacket |
|
321 |
{ |
|
322 |
unsigned char Sign; //起始标记 |
|
323 |
unsigned char DstHost; //目标地址 |
|
324 |
unsigned char SrcAddr; //源地址 |
|
325 |
unsigned char nCMD; //命令 |
|
326 |
union{ |
|
327 |
unsigned char nStatus; //状态+序列号 |
|
328 |
struct{ |
|
329 |
unsigned char nSeq:2; //序列号 |
|
330 |
unsigned char :2; |
|
331 |
unsigned char nErr1:1; |
|
332 |
unsigned char nErr2:1; |
|
333 |
unsigned char bReq:1; |
|
334 |
}; |
|
335 |
}; |
|
336 |
unsigned char DataLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 |
|
337 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 |
|
338 |
}stKBPacket,* pKBPacket; |
|
339 |
|
|
340 |
typedef struct tagKBInfoBlockV1 |
|
341 |
{ |
|
342 |
unsigned short nDeviceType; |
|
343 |
unsigned short nProgVer; |
|
344 |
|
|
345 |
unsigned char InBitCount; |
|
346 |
unsigned char OutBitCount; |
|
347 |
|
|
348 |
unsigned char AICount; |
|
349 |
unsigned char AIBits; |
|
350 |
unsigned char AQCount; |
|
351 |
unsigned char AQbits; |
|
352 |
|
|
353 |
unsigned char InDWCount; |
|
354 |
unsigned char OutDWCount; |
|
355 |
|
|
356 |
}stKBInfoBlockV1, *pKBInfoBlockV1; |
|
357 |
|
|
358 |
enum eResult |
|
359 |
{ |
|
360 |
S_OK =0, |
|
361 |
S_ERR=1, |
|
362 |
S_TIMEOUT=2 |
|
363 |
|
|
364 |
} ; |
|
365 |
|
|
366 |
/* |
|
367 |
typedef struct tagKBPacketV10 |
|
368 |
{ |
|
369 |
unsigned char Sign; //起始标记 |
|
370 |
unsigned char DstHost; //目标地址 |
|
371 |
unsigned char SrcAddr; //源地址 |
|
372 |
unsigned char nCMD; //命令 |
|
373 |
union{ |
|
374 |
unsigned char nStatus; //状态+序列号 |
|
375 |
struct{ |
|
376 |
unsigned char nSeq:2; //序列号 |
|
377 |
unsigned char :2; |
|
378 |
unsigned char nErr1:1; |
|
379 |
unsigned char nErr2:1; |
|
380 |
|
|
381 |
}; |
|
382 |
}; |
|
383 |
unsigned char DataLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 |
|
384 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 |
|
385 |
}stKBPacketV10,* pKBPacketV10; |
|
386 |
|
|
387 |
typedef struct tagKBPacketV20 |
|
388 |
{ |
|
389 |
unsigned char Sign; //起始标记 |
|
390 |
unsigned char DstHost; //目标地址 |
|
391 |
unsigned char SrcAddr; //源地址 |
|
392 |
unsigned char nCMD; //命令 |
|
393 |
union{ |
|
394 |
unsigned char nStatus; //状态+序列号 |
|
395 |
struct{ |
|
396 |
unsigned char nSeq:2; //序列号 |
|
397 |
unsigned char :2; |
|
398 |
unsigned char nErr1:1; |
|
399 |
unsigned char nErr2:1; |
|
400 |
|
|
401 |
}; |
|
402 |
}; |
|
403 |
unsigned char DataLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 |
|
404 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 |
|
405 |
}stKBPacketV20,* pKBPacketV20; |
|
406 |
*/ |
|
407 |
|
|
408 |
enum enumCallBackEvent |
|
409 |
{ |
|
410 |
KBusEvNone = 0, |
|
411 |
KBusEvCreate = 1, |
|
412 |
KBusEvConnected = 2, |
|
413 |
KBusEvDisConnected = 3, |
|
414 |
KBusEvClosed = 4, |
|
415 |
KBusEvStateChange =5, |
|
416 |
KBusEvTimeSync=6, |
|
417 |
KBusEvDataUpdate =7, |
|
418 |
KBusEvCmdResponse = 8, |
|
419 |
|
|
420 |
}; |
|
421 |
|
|
422 |
typedef int (*KBusSendPktFuncDef) (uchar * pBuf, int nLen); // SendPacket CallBack func for KBus |
|
423 |
|
|
424 |
typedef void *(*KBusEvCBFuncDef) (void * , int nEvent, void *, int); //callback func ,prama s is void *,void *,int; return void *; |
|
425 |
|
|
426 |
typedef int (*KBusSvCBFuncDef) (void *, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; |
|
427 |
|
|
428 |
/* |
|
429 |
typedef struct tagKBusRunStat |
|
430 |
{ |
|
431 |
unsigned char bMaster; // 是否主机 |
|
432 |
unsigned char nStationID; // 子机地址 |
|
433 |
unsigned char nChildren; // 子机数量 |
|
434 |
unsigned char nCurPollId; // 当前轮询到的子机 地址。 |
|
435 |
unsigned char nSeq; // 包序列号 |
|
436 |
|
|
437 |
unsigned char bMasterRecved; // 状态, 主机已接收到返回的数据包 |
|
438 |
unsigned char bMasterRecvOK; // 状态, 主机接收到的返回的数据包正确 |
|
439 |
unsigned char bSlaveRecved; // 状态, 子机接受到数据包。 |
|
440 |
unsigned int nSendTimeuS; // 数据包发出时刻。 |
|
441 |
|
|
442 |
}stKBusRunStat , * pstKBusRunStat; |
|
443 |
*/ |
|
444 |
|
5dd1b7
|
445 |
#pragma anon_unions |
Q |
446 |
typedef struct tagKBusDef // KBus 工作内存 |
|
447 |
{ |
842bb6
|
448 |
///* |
Q |
449 |
union { |
|
450 |
uchar nConfig; |
|
451 |
struct { |
|
452 |
uchar bMaster:1; //KBus, 是否主机 |
|
453 |
uchar bSlave:1; //KBus, 是否子机 |
|
454 |
uchar bRepeater:1; //KBus, 是否转发器,中继器 |
|
455 |
}; |
|
456 |
}; |
|
457 |
// */ |
|
458 |
/* |
5dd1b7
|
459 |
uchar bMaster; //KBus, 是否主机 |
Q |
460 |
uchar bSlave; //KBus, 是否子机 |
|
461 |
uchar bRepeater; //KBus, 是否转发器,中继器 |
842bb6
|
462 |
*/ |
Q |
463 |
|
5dd1b7
|
464 |
uchar nStationId; //KBus 站号 |
Q |
465 |
vuchar MyStat; //KBus, 状态机状态 |
842bb6
|
466 |
vuchar nRunStep; //KBus, 运行步 |
5dd1b7
|
467 |
vuchar nSeq; //KBus, 包序列号 |
Q |
468 |
|
|
469 |
vuchar bMasterSent; // 状态 主机已发送 |
|
470 |
vuchar bMasterRecved; // 状态 主机已接收 回包 |
|
471 |
vuchar bMasterRecvOK; // 状态 主机接收回包正确 |
|
472 |
vuchar bSlaveRecved; // 状态 子机已接收包 |
842bb6
|
473 |
|
5dd1b7
|
474 |
vuchar nChildCount; // 子机数量 |
Q |
475 |
uchar nCurPollId; // 当前轮询子机 号 |
|
476 |
ushort ErrStat; |
|
477 |
ushort RunStat; |
842bb6
|
478 |
|
Q |
479 |
uchar bReq; //运行系统请求中 |
|
480 |
uchar nReqSvrId; //请求号 |
|
481 |
uchar nReqChildId; //请求的子机号 |
|
482 |
uchar nReqParam; //请求的参数 |
|
483 |
ushort nReqReCount; // |
|
484 |
|
|
485 |
uchar nReqDataHdr[4]; |
|
486 |
uchar pReqDatas[140]; |
|
487 |
uchar nReqDataOff; |
|
488 |
uchar nReqDataLen; |
5dd1b7
|
489 |
|
842bb6
|
490 |
|
Q |
491 |
|
|
492 |
int SendTimeTick; // 发包时刻 |
|
493 |
int RecvTimeTick; // 收包时刻 |
|
494 |
int DelayTick; // 包循环延迟 |
|
495 |
int nMaxDelayTick; // 最大包循环延迟 |
|
496 |
int LastCircleStartTime; //=0; |
|
497 |
int CircleTime; //=0; |
5dd1b7
|
498 |
|
Q |
499 |
int nSlaveTick; // 子机时间 tick |
|
500 |
|
842bb6
|
501 |
// int ThisuS; |
5dd1b7
|
502 |
//volatile unsigned int nSlaveTick; //=0; |
Q |
503 |
|
|
504 |
int Clk3; //=0; |
|
505 |
int SendTime,Latancy,LatancyClk,SendClk; |
|
506 |
|
|
507 |
//volatile int nCount2; //=0; |
|
508 |
int TimeOutCount; //=0; |
483170
|
509 |
|
Q |
510 |
|
842bb6
|
511 |
stPortDef KBusPort; |
5dd1b7
|
512 |
KBusSendPktFuncDef KBusSendPacket; // 发送数据包函数指针 |
Q |
513 |
KBusEvCBFuncDef KBusEvCBFunc; // 事件回调函数指针 |
|
514 |
KMSvCBDef KBusSvCBFunc; // 服务请求回调指针 |
|
515 |
|
|
516 |
stDeviceInfo* pMyDeviceInfo; |
|
517 |
|
|
518 |
uchar RetryCount; // 重试次数 |
|
519 |
uchar nTimeOutCount; // 超时计数 |
|
520 |
vuchar step; // 当前步骤 |
|
521 |
uchar ChildStat[MAX_CLIENT]; // 子机状态(们) |
|
522 |
|
|
523 |
|
|
524 |
uchar CurXBitAddr; // 已分配 X 位 地址 |
|
525 |
uchar CurYBitAddr; // 已分配 Y 位 地址 |
|
526 |
uchar CurAIWAddr; // 已分配 模拟量入 字 地址 |
|
527 |
uchar CurAQWAddr; // 已分配 模拟量出 字 地址 |
|
528 |
uchar CurDIWAddr; // 已分配 数据入 字 地址 |
|
529 |
uchar CurDOWAddr; // 已分配 数据出 字 地址 |
|
530 |
|
|
531 |
uchar MyYStartBitAddress; // 本机 起始 Y 位地址 |
|
532 |
uchar MyAQWStartWordAddress; // 本机 起始 模拟量 出 字 地址 |
|
533 |
uchar MyDWStartWordAddress; // 本机 起始 数据出 字 地址 |
|
534 |
|
|
535 |
stDeviceInfo DeviceInfos[MAX_CLIENT]; // 子机信息(们) |
|
536 |
stClientCfg ClientCfg[MAX_CLIENT]; // 子机配置(们) |
|
537 |
stChnStat KBusChnStats[MAX_CLIENT]; |
|
538 |
|
|
539 |
|
|
540 |
// uchar bKBusEvCBFuncSet; // 事件回调函数是否已经设置 |
|
541 |
// uchar bKBusSvCBFuncSet; // 事件回调函数是否已经设置 |
|
542 |
|
842bb6
|
543 |
// uchar PacketBuf1[KBMaxPacketLength]; |
5dd1b7
|
544 |
uchar PacketBuf2[KBMaxPacketLength]; |
Q |
545 |
|
|
546 |
|
|
547 |
unsigned char Datas[128]; |
|
548 |
volatile int PacketLength; // = 0; |
|
549 |
|
|
550 |
unsigned char KBusDiagnosis; // =1; // Kbus 诊断模式 |
|
551 |
unsigned char KBusSnapPos; // = 0; // 抓取 Kbus 包 |
|
552 |
|
|
553 |
// unsigned char nStationID; //=0; |
|
554 |
// unsigned char nChilds; |
|
555 |
//int ChildStat[16]; |
|
556 |
// unsigned char nCurPollId; //=0; |
|
557 |
// unsigned char nSeq; //=0; |
|
558 |
unsigned char nClientDataIndex; //=0; |
|
559 |
|
|
560 |
}stKBusDef,*pstKBusDef; |
|
561 |
|
|
562 |
|
|
563 |
typedef struct tagKBusMem |
|
564 |
{ |
|
565 |
union{ |
|
566 |
ushort WLX[16]; |
|
567 |
uchar WLXB[32]; |
|
568 |
}; |
|
569 |
union{ |
|
570 |
ushort WLY[16]; |
|
571 |
uchar WLYB[32]; |
|
572 |
}; |
|
573 |
ushort AIW[16]; |
|
574 |
ushort AOW[16]; |
|
575 |
ushort DIW[16]; |
|
576 |
ushort DOW[16]; |
|
577 |
}stKBusMem, *pstKBusMem; |
|
578 |
|
|
579 |
extern stKBusMem KBusMem; |
|
580 |
|
842bb6
|
581 |
/* |
5dd1b7
|
582 |
typedef struct tagKBusDiag |
Q |
583 |
{ |
|
584 |
|
|
585 |
int Stat; |
|
586 |
unsigned int SendPackets; |
|
587 |
unsigned int RecvPackets; |
|
588 |
unsigned int LastSentTimeuS; |
|
589 |
unsigned int LostPackets; |
|
590 |
unsigned int CtnLstPkts; |
|
591 |
unsigned int MaxCtnLstPkts; |
|
592 |
unsigned int NotPkgErr; |
|
593 |
unsigned int PkgLenErr; |
|
594 |
unsigned int BCCErr; |
|
595 |
unsigned int TimeOutErr; |
|
596 |
unsigned int Delay; |
|
597 |
unsigned int MaxDelay; |
|
598 |
unsigned int SendTimeInterval; |
|
599 |
union |
|
600 |
{ |
|
601 |
unsigned int ClientDatas[10]; |
|
602 |
struct { |
|
603 |
unsigned int ClientRecvPkts; // |
|
604 |
unsigned int ClientSendPkts; // |
|
605 |
unsigned int ClientNotPktErr; // |
|
606 |
unsigned int ClientMisIdPkts; // |
|
607 |
// unsigned int ClientNoEndErr; // |
|
608 |
unsigned int ClientPkgLenErr; // |
|
609 |
unsigned int ClientBccErr; // |
|
610 |
unsigned int ClientTimeOutErr; // |
|
611 |
}; |
|
612 |
}; |
|
613 |
|
|
614 |
}stKBusDiag, *pstKBusDiag; |
842bb6
|
615 |
*/ |
5dd1b7
|
616 |
|
Q |
617 |
|
842bb6
|
618 |
int KBusInit(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int bMaster, int nChildCount); |
5dd1b7
|
619 |
|
842bb6
|
620 |
int KBusInitMaster(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int nChildCount); |
Q |
621 |
int KBusInitSlave(stKBusDef * pKBus, KBusSendPktFuncDef KBusSendPacket, int nStationId, stDeviceInfo *pClientInfo); |
5dd1b7
|
622 |
|
842bb6
|
623 |
int KBusLoadSavedConfig(stKBusDef * pKBus); |
Q |
624 |
int KBusSetEvCallBackFunc(stKBusDef * pKBus, KBusEvCBFuncDef CBFunc); // Set Event CallBack function |
|
625 |
int KBusSetSvCallBackFunc(stKBusDef * pKBus, KMSvCBDef CBFunc); // Set ServiceReq CallBack Function |
|
626 |
int KBusMakeDefaultClildInfo(stKBusDef * pKBus, int nChild); |
|
627 |
int KBusReqService (stKBusDef * pKBus, int ReqId, int nParam1, int nParam2, void **pData, unsigned short * len1); |
5dd1b7
|
628 |
|
842bb6
|
629 |
int KBusStart(stKBusDef * pKBus) ; |
Q |
630 |
int KBusStop(stKBusDef * pKBus) ; |
|
631 |
int KBusDataPoll(stKBusDef * pKBus); |
5dd1b7
|
632 |
|
842bb6
|
633 |
int KBusLoopProcess(stKBusDef * pKBus); |
Q |
634 |
int KBusMasterFunc(stKBusDef * pKBus); |
|
635 |
int KBusSlaveFunc(stKBusDef * pKBus); |
|
636 |
int KBusRepeaterFunc(stKBusDef * pKBus); |
5dd1b7
|
637 |
|
483170
|
638 |
/* Make a Packet and return Packet Length */ |
Q |
639 |
int KBusMakePacket(pKBPacket p1,uchar Src, uchar Dst, uchar nType, uchar nStatus, uchar DataLen, void *pData ); |
|
640 |
|
|
641 |
/* */ |
842bb6
|
642 |
int KBusCheckPacket(stKBusDef * pKBus, pKBPacket p1, int len1); |
483170
|
643 |
|
Q |
644 |
/* */ |
842bb6
|
645 |
int KBusParsePacket(stKBusDef * pKBus, pKBPacket p1, int Len1); |
5dd1b7
|
646 |
|
842bb6
|
647 |
int KBusPacketSendDone(stKBusDef * pKBus); |
5dd1b7
|
648 |
/* |
Q |
649 |
static inline char KBGetClientNum(int nChn) { }; |
|
650 |
static inline char KBGetClientInfo(int nChn, int nClientId) { }; |
|
651 |
static inline char KBGetClientIOCount(int nChn,int nClientId) {}; |
|
652 |
int KBGetClientStatus(int nChn); |
|
653 |
|
|
654 |
static inline char KBisSafeState(int nPortNum) { }; |
|
655 |
static inline char KBisRunState(int nPortNum) { }; |
|
656 |
static inline char KBGetState(int nPortNum) { }; |
|
657 |
static inline char KBChangeState(int nPortNum, int nNewState){ }; |
|
658 |
*/ |
|
659 |
|
|
660 |
unsigned char KBusBCC(void * pData, int nSize); |
|
661 |
// |
842bb6
|
662 |
int KBusSlaveRunRemoteReq(stKBusDef * pKBus, int nReqSvrId, unsigned char * pData , int Len1); |
95322c
|
663 |
|
483170
|
664 |
/* |
Q |
665 |
int InitMachine(stMachineConfig * pConfig); |
|
666 |
|
|
667 |
int SetConfig(void ); |
|
668 |
|
|
669 |
int StartConfig(void); |
|
670 |
|
|
671 |
int SetMasterConfig(void); |
|
672 |
|
|
673 |
int StartPolling(void); |
|
674 |
|
|
675 |
int ReadData(void); |
|
676 |
|
|
677 |
int WriteData(void); |
|
678 |
|
|
679 |
int GetStat(void); |
|
680 |
*/ |
5dd1b7
|
681 |
|
483170
|
682 |
|
Q |
683 |
#endif /* __KBUS_H__ */ |
|
684 |
|