提交 | 用户 | age
|
bfc108
|
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 |
|
a7db3c
|
14 |
extern unsigned char bKBusMaster,bKBusSlave,bKBusRepeater;;
|
bfc108
|
15 |
enum enCMDs
|
Q |
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 |
|
0fe6b0
|
44 |
typedef struct tagKBusRunStat
|
Q |
45 |
{
|
|
46 |
unsigned char bMaster;
|
|
47 |
unsigned char nStationID;
|
|
48 |
unsigned char nChildren;
|
|
49 |
unsigned char nCurPollId;
|
|
50 |
unsigned char nSeq;
|
|
51 |
|
|
52 |
unsigned char bMasterRecved;
|
|
53 |
unsigned char bMasterRecvOK;
|
|
54 |
unsigned char bSlaveRecved;
|
|
55 |
unsigned int nSendTimeuS;
|
|
56 |
|
|
57 |
}stKBusRunStat , * pstKBusRunStat;
|
|
58 |
|
bfc108
|
59 |
extern unsigned char BufferIn[16];
|
Q |
60 |
extern unsigned char BufferOut[16];
|
0fe6b0
|
61 |
extern unsigned char nStationID;
|
e1f350
|
62 |
extern unsigned char nChilds;
|
bfc108
|
63 |
extern int ChildStat[16];
|
e1f350
|
64 |
extern unsigned char nCurPollId;
|
Q |
65 |
extern unsigned char nSeq;
|
bfc108
|
66 |
|
0fe6b0
|
67 |
extern volatile unsigned char KBusMasterRecved;
|
Q |
68 |
extern volatile unsigned char KBusMasterRecvOK;
|
|
69 |
extern volatile unsigned char KBusSlaveRecved;
|
|
70 |
extern unsigned int KBusSendTimeuS;
|
|
71 |
extern volatile int KBusRecvTimeuS;
|
|
72 |
extern int KBusDelayuS;
|
|
73 |
extern int KBusMaxDelayuS;
|
bfc108
|
74 |
|
Q |
75 |
extern volatile unsigned int nSlaveTick;
|
|
76 |
|
|
77 |
typedef struct tagVerInfo
|
|
78 |
{
|
|
79 |
unsigned char nMainVer;
|
|
80 |
unsigned char nSubVer;
|
|
81 |
}stVerInfo;
|
|
82 |
|
|
83 |
typedef struct tagMachineState
|
|
84 |
{
|
|
85 |
unsigned char Addr;
|
|
86 |
unsigned char state;
|
|
87 |
unsigned char InStartAddrBit;
|
|
88 |
unsigned char OutStartAddrBit;
|
|
89 |
unsigned char InDWStartAddrByte;
|
|
90 |
unsigned char OutDWStartAddrByte;
|
|
91 |
}ClientState;
|
|
92 |
|
|
93 |
typedef struct tagMasterStat
|
|
94 |
{
|
|
95 |
unsigned int CycleTime;
|
|
96 |
} stMasterStat;
|
|
97 |
|
|
98 |
typedef struct ServerStatus
|
|
99 |
{
|
|
100 |
unsigned char Addr;
|
|
101 |
unsigned char Status;
|
|
102 |
unsigned short Input[16];
|
|
103 |
unsigned short DT[128];
|
|
104 |
unsigned short output[16];
|
|
105 |
|
|
106 |
}stServerStatus,*pServerStatus;
|
|
107 |
|
|
108 |
typedef struct tagClientCfg
|
|
109 |
{
|
|
110 |
unsigned int KeepOut; //Keep Output when comm err;
|
|
111 |
|
|
112 |
}stClientCfg;
|
|
113 |
|
|
114 |
struct ClientInfo
|
|
115 |
{
|
|
116 |
stVerInfo ClientVer;
|
|
117 |
unsigned char nType;
|
|
118 |
unsigned char nGroup;
|
|
119 |
unsigned char InPutCount;
|
|
120 |
unsigned char OutPutCount;
|
|
121 |
unsigned char InDWCount;
|
|
122 |
unsigned char OutDWCount;
|
0fe6b0
|
123 |
unsigned char bOnline;
|
bfc108
|
124 |
};
|
Q |
125 |
|
|
126 |
#pragma anon_unions
|
|
127 |
typedef struct tagChnStat
|
|
128 |
{
|
|
129 |
unsigned int Stat;
|
|
130 |
unsigned int SendPackets;
|
|
131 |
unsigned int RecvPackets;
|
|
132 |
unsigned int LastSentTimeuS;
|
|
133 |
unsigned int LostPackets;
|
|
134 |
unsigned int CtnLstPkts;
|
|
135 |
unsigned int MaxCtnLstPkts;
|
|
136 |
unsigned int NotPkgErr;
|
|
137 |
unsigned int PkgLenErr;
|
|
138 |
unsigned int BCCErr;
|
|
139 |
unsigned int TimeOutErr;
|
|
140 |
unsigned int Delay;
|
|
141 |
unsigned int MaxDelay;
|
|
142 |
unsigned int SendTimeInterval;
|
|
143 |
union
|
|
144 |
{
|
|
145 |
unsigned int ClientDatas[10];
|
|
146 |
struct {
|
|
147 |
unsigned int ClientRecvPkts; //
|
|
148 |
unsigned int ClientSendPkts; //
|
|
149 |
unsigned int ClientNotPktErr; //
|
|
150 |
unsigned int ClientMisIdPkts; //
|
|
151 |
// unsigned int ClientNoEndErr; //
|
|
152 |
unsigned int ClientPkgLenErr; //
|
|
153 |
unsigned int ClientBccErr; //
|
|
154 |
unsigned int ClientTimeOutErr; //
|
|
155 |
};
|
|
156 |
};
|
|
157 |
} stChnStat;
|
d69aae
|
158 |
|
0fe6b0
|
159 |
extern stChnStat KBusChnStats[8];
|
bfc108
|
160 |
|
Q |
161 |
typedef struct tagSlaveStat
|
|
162 |
{
|
|
163 |
unsigned int nSlaveTick;
|
|
164 |
} stSlaveStat;
|
|
165 |
|
|
166 |
|
|
167 |
typedef struct ServerClientListElement
|
|
168 |
{
|
|
169 |
unsigned char Addr;
|
|
170 |
unsigned char Status;
|
|
171 |
unsigned char Father;
|
|
172 |
unsigned char Childs;
|
|
173 |
|
|
174 |
} stServerClientListElement;
|
|
175 |
|
|
176 |
typedef struct ServerClientList
|
|
177 |
{
|
|
178 |
unsigned char Addr;
|
|
179 |
}stServerClientList,*pServerClientList;
|
|
180 |
|
|
181 |
typedef struct ClientStatus
|
|
182 |
{
|
|
183 |
unsigned char Addr;
|
|
184 |
unsigned char Status;
|
|
185 |
unsigned char Father;
|
|
186 |
unsigned char Childs;
|
|
187 |
unsigned short Input[16];
|
|
188 |
unsigned short DT[128];
|
|
189 |
unsigned short output[16];
|
|
190 |
|
|
191 |
}stChnStatus,*pClientStatus;
|
|
192 |
|
|
193 |
typedef void *(*CBFuncDef) (void*, void *, int); //callback func ,prama s is void *,void *,int; return void *;
|
|
194 |
enum enumCallBackEvent
|
|
195 |
{
|
|
196 |
evNone = 0,
|
|
197 |
evCreate = 1,
|
|
198 |
evConnected = 2,
|
|
199 |
evDisConnected = 3,
|
|
200 |
evClosed = 4,
|
|
201 |
};
|
|
202 |
|
0fe6b0
|
203 |
typedef struct tagKBPacket
|
bfc108
|
204 |
{
|
0fe6b0
|
205 |
unsigned char Sign; //起始标记
|
Q |
206 |
unsigned char DstHost; //目标地址
|
|
207 |
unsigned char SrcAddr; //源地址
|
|
208 |
unsigned char nCMD; //命令
|
|
209 |
unsigned char nSEQ; //序列号
|
|
210 |
unsigned char PacketLen; //数据载荷长度 不包括头部5个字节,不包括尾部BCC。
|
|
211 |
unsigned char data[1]; //数据载荷,最末尾是BCC,数据长度为0时,实际也有一个数据。
|
|
212 |
}stKBPacket,* pKBPacket;
|
bfc108
|
213 |
|
Q |
214 |
enum eResult
|
|
215 |
{
|
|
216 |
S_OK =0,
|
|
217 |
S_ERR=1,
|
|
218 |
S_TIMEOUT=2
|
|
219 |
|
|
220 |
} ;
|
d69aae
|
221 |
|
f4f290
|
222 |
unsigned char KBusBCC(void * pData, int nSize);
|
bfc108
|
223 |
//
|
Q |
224 |
/* Make a Packet and return Packet Length */
|
0fe6b0
|
225 |
int KBusMakePacket(pKBPacket p1,uchar Src, uchar Dst, uchar nType, uchar nSEQ, uchar DataLen, void *pData );
|
bfc108
|
226 |
|
Q |
227 |
/* */
|
0fe6b0
|
228 |
int KBusCheckPacket(int nChn, pKBPacket p1, int len1);
|
bfc108
|
229 |
|
Q |
230 |
/* */
|
0fe6b0
|
231 |
int KBusParsePacket(int nChn, pKBPacket p1, int Len1);
|
bfc108
|
232 |
typedef struct tagMachineConfig
|
Q |
233 |
{
|
a7db3c
|
234 |
int bKBusMaster;
|
bfc108
|
235 |
int nAddr;
|
Q |
236 |
}stMachineConfig;
|
f4f290
|
237 |
/*
|
bfc108
|
238 |
int InitMachine(stMachineConfig * pConfig);
|
Q |
239 |
|
|
240 |
int SetConfig(void );
|
|
241 |
|
|
242 |
int StartConfig(void);
|
|
243 |
|
|
244 |
int SetMasterConfig(void);
|
|
245 |
|
|
246 |
int StartPolling(void);
|
|
247 |
|
|
248 |
int ReadData(void);
|
|
249 |
|
|
250 |
int WriteData(void);
|
|
251 |
|
|
252 |
int GetStat(void);
|
f4f290
|
253 |
*/
|
a7db3c
|
254 |
int KBusRepeaterFunc(int nChn);
|
Q |
255 |
int KBusMasterFunc(int nChn);
|
|
256 |
int KBusSlaveFunc(int nChn);
|
bfc108
|
257 |
|
Q |
258 |
#endif /* __KBUS_H__ */
|
|
259 |
|