提交 | 用户 | 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 |
*/ |
|
8 |
#include "KMachine.h" |
|
9 |
|
|
10 |
#ifndef __KBUS_H__ |
|
11 |
#define __KBUS_H__ |
|
12 |
typedef unsigned char uchar; |
|
13 |
|
|
14 |
extern unsigned char bKBusMaster,bKBusSlave,bKBusRepeater;; |
|
15 |
enum enCMDs |
|
16 |
{ |
|
17 |
cmdNone = '0', //Nothing |
|
18 |
cmdPing = '1', //Ping |
|
19 |
cmdPingReply = '2', //PingReply |
|
20 |
cmdRead = '3', //Read |
|
21 |
cmdReadReply = '4', //ReadReply |
|
22 |
cmdWrite = '5', //Write |
|
23 |
cmdWriteReply = '6', //WriteReply |
|
24 |
cmdGetVersion = '7', //GetVersion |
|
25 |
cmdVerInfo = '8', //VersionReply |
|
26 |
|
|
27 |
cmdExChgData='A', //ExChangeDate, = Wirte + Read |
|
28 |
cmdExChgDataReply, //ExchangeData Reply |
|
29 |
|
|
30 |
cmdSyncRead='a', //SyncRead |
|
31 |
cmdSyncWrite, //SyncWrite |
|
32 |
cmdSequenRead, //Sequence Read |
|
33 |
cmdSyncTime, //SyncTime |
|
34 |
}; |
|
35 |
enum {StartSign='%', |
|
36 |
EndSign=0x0D, |
|
37 |
MaxPacketLength=128, |
|
38 |
|
|
39 |
}; |
|
40 |
|
|
41 |
extern unsigned char PacketBuf1[128]; |
|
42 |
extern unsigned char PacketBuf2[128]; |
|
43 |
|
|
44 |
extern unsigned char BufferIn[16]; |
|
45 |
extern unsigned char BufferOut[16]; |
|
46 |
extern unsigned char nAddr; |
|
47 |
extern unsigned char nChilds; |
|
48 |
extern int ChildStat[16]; |
|
49 |
extern unsigned char nCurPollId; |
|
50 |
extern unsigned char nSeq; |
|
51 |
|
|
52 |
extern volatile unsigned char MasterRecved; |
|
53 |
extern volatile unsigned char MasterRecvOK; |
|
54 |
extern volatile unsigned char SlaveRecved; |
|
55 |
extern unsigned int SendTimeuS; |
|
56 |
extern volatile int RecvTimeuS; |
|
57 |
extern int DelayuS; |
|
58 |
extern int MaxDelayuS; |
|
59 |
|
|
60 |
extern volatile unsigned int nSlaveTick; |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
typedef struct tagVerInfo |
|
65 |
{ |
|
66 |
unsigned char nMainVer; |
|
67 |
unsigned char nSubVer; |
|
68 |
}stVerInfo; |
|
69 |
|
|
70 |
typedef struct tagMachineState |
|
71 |
{ |
|
72 |
unsigned char Addr; |
|
73 |
unsigned char state; |
|
74 |
unsigned char InStartAddrBit; |
|
75 |
unsigned char OutStartAddrBit; |
|
76 |
unsigned char InDWStartAddrByte; |
|
77 |
unsigned char OutDWStartAddrByte; |
|
78 |
}ClientState; |
|
79 |
|
|
80 |
typedef struct tagMasterStat |
|
81 |
{ |
|
82 |
unsigned int CycleTime; |
|
83 |
} stMasterStat; |
|
84 |
|
|
85 |
typedef struct ServerStatus |
|
86 |
{ |
|
87 |
unsigned char Addr; |
|
88 |
unsigned char Status; |
|
89 |
unsigned short Input[16]; |
|
90 |
unsigned short DT[128]; |
|
91 |
unsigned short output[16]; |
|
92 |
|
|
93 |
}stServerStatus,*pServerStatus; |
|
94 |
|
|
95 |
typedef struct tagClientCfg |
|
96 |
{ |
|
97 |
unsigned int KeepOut; //Keep Output when comm err; |
|
98 |
|
|
99 |
}stClientCfg; |
|
100 |
|
|
101 |
struct ClientInfo |
|
102 |
{ |
|
103 |
stVerInfo ClientVer; |
|
104 |
unsigned char nType; |
|
105 |
unsigned char nGroup; |
|
106 |
unsigned char InPutCount; |
|
107 |
unsigned char OutPutCount; |
|
108 |
unsigned char InDWCount; |
|
109 |
unsigned char OutDWCount; |
|
110 |
|
|
111 |
unsigned char Online; |
|
112 |
}; |
|
113 |
|
|
114 |
#pragma anon_unions |
|
115 |
typedef struct tagChnStat |
|
116 |
{ |
|
117 |
unsigned int Stat; |
|
118 |
unsigned int SendPackets; |
|
119 |
unsigned int RecvPackets; |
|
120 |
unsigned int LastSentTimeuS; |
|
121 |
unsigned int LostPackets; |
|
122 |
unsigned int CtnLstPkts; |
|
123 |
unsigned int MaxCtnLstPkts; |
|
124 |
unsigned int NotPkgErr; |
|
125 |
unsigned int PkgLenErr; |
|
126 |
unsigned int BCCErr; |
|
127 |
unsigned int TimeOutErr; |
|
128 |
unsigned int Delay; |
|
129 |
unsigned int MaxDelay; |
|
130 |
unsigned int SendTimeInterval; |
|
131 |
union |
|
132 |
{ |
|
133 |
unsigned int ClientDatas[10]; |
|
134 |
struct { |
|
135 |
unsigned int ClientRecvPkts; // |
|
136 |
unsigned int ClientSendPkts; // |
|
137 |
unsigned int ClientNotPktErr; // |
|
138 |
unsigned int ClientMisIdPkts; // |
|
139 |
// unsigned int ClientNoEndErr; // |
|
140 |
unsigned int ClientPkgLenErr; // |
|
141 |
unsigned int ClientBccErr; // |
|
142 |
unsigned int ClientTimeOutErr; // |
|
143 |
}; |
|
144 |
}; |
|
145 |
} stChnStat; |
|
146 |
|
|
147 |
extern stChnStat ChnStats[8]; |
|
148 |
|
|
149 |
typedef struct tagSlaveStat |
|
150 |
{ |
|
151 |
unsigned int nSlaveTick; |
|
152 |
} stSlaveStat; |
|
153 |
|
|
154 |
|
|
155 |
typedef struct ServerClientListElement |
|
156 |
{ |
|
157 |
unsigned char Addr; |
|
158 |
unsigned char Status; |
|
159 |
unsigned char Father; |
|
160 |
unsigned char Childs; |
|
161 |
|
|
162 |
} stServerClientListElement; |
|
163 |
|
|
164 |
typedef struct ServerClientList |
|
165 |
{ |
|
166 |
unsigned char Addr; |
|
167 |
}stServerClientList,*pServerClientList; |
|
168 |
|
|
169 |
typedef struct ClientStatus |
|
170 |
{ |
|
171 |
unsigned char Addr; |
|
172 |
unsigned char Status; |
|
173 |
unsigned char Father; |
|
174 |
unsigned char Childs; |
|
175 |
unsigned short Input[16]; |
|
176 |
unsigned short DT[128]; |
|
177 |
unsigned short output[16]; |
|
178 |
|
|
179 |
}stChnStatus,*pClientStatus; |
|
180 |
|
|
181 |
typedef void *(*CBFuncDef) (void*, void *, int); //callback func ,prama s is void *,void *,int; return void *; |
|
182 |
enum enumCallBackEvent |
|
183 |
{ |
|
184 |
evNone = 0, |
|
185 |
evCreate = 1, |
|
186 |
evConnected = 2, |
|
187 |
evDisConnected = 3, |
|
188 |
evClosed = 4, |
|
189 |
}; |
|
190 |
|
|
191 |
typedef struct tagPacket |
|
192 |
{ |
|
193 |
unsigned char Sign; //起始标记 |
|
194 |
unsigned char DstHost; //目标地址 |
|
195 |
unsigned char SrcAddr; //源地址 |
|
196 |
unsigned char nCMD; //命令 |
|
197 |
unsigned char nSEQ; //序列号 |
|
198 |
unsigned char PacketLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。 |
|
199 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。 |
|
200 |
}stPacket,* pPacket; |
|
201 |
|
|
202 |
enum eResult |
|
203 |
{ |
|
204 |
S_OK =0, |
|
205 |
S_ERR=1, |
|
206 |
S_TIMEOUT=2 |
|
207 |
|
|
208 |
} ; |
|
209 |
|
|
210 |
unsigned char KBusBCC(void * pData, int nSize); |
|
211 |
// |
|
212 |
/* Make a Packet and return Packet Length */ |
|
213 |
int KBusMakePacket(pPacket p1,uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData ); |
|
214 |
|
|
215 |
/* */ |
|
216 |
int KBusCheckPacket(int nChn, pPacket p1, int len1); |
|
217 |
|
|
218 |
/* */ |
|
219 |
int KBusParsePacket(int nChn, pPacket p1, int Len1); |
|
220 |
typedef struct tagMachineConfig |
|
221 |
{ |
|
222 |
int bKBusMaster; |
|
223 |
int nAddr; |
|
224 |
}stMachineConfig; |
|
225 |
/* |
|
226 |
int InitMachine(stMachineConfig * pConfig); |
|
227 |
|
|
228 |
int SetConfig(void ); |
|
229 |
|
|
230 |
int StartConfig(void); |
|
231 |
|
|
232 |
int SetMasterConfig(void); |
|
233 |
|
|
234 |
int StartPolling(void); |
|
235 |
|
|
236 |
int ReadData(void); |
|
237 |
|
|
238 |
int WriteData(void); |
|
239 |
|
|
240 |
int GetStat(void); |
|
241 |
*/ |
|
242 |
int KBusRepeaterFunc(int nChn); |
|
243 |
int KBusMasterFunc(int nChn); |
|
244 |
int KBusSlaveFunc(int nChn); |
|
245 |
|
|
246 |
#endif /* __KBUS_H__ */ |
|
247 |
|