1
|
// CdtZf.cpp: implementation of the CZFCasco class.
|
2
|
//
|
3
|
//////////////////////////////////////////////////////////////////////
|
4
|
|
5
|
#include "zfCasco.h"
|
6
|
|
7
|
#ifdef _DEBUG
|
8
|
#undef THIS_FILE
|
9
|
static char THIS_FILE[] = __FILE__;
|
10
|
#define new DEBUG_NEW
|
11
|
#endif
|
12
|
|
13
|
//////////////////////////////////////////////////////////////////////
|
14
|
// Construction/Destruction
|
15
|
//////////////////////////////////////////////////////////////////////
|
16
|
CZFCasco::CZFCasco() {
|
17
|
this->m_popt_train = NULL;
|
18
|
}
|
19
|
|
20
|
CZFCasco::~CZFCasco() {
|
21
|
|
22
|
}
|
23
|
|
24
|
void CZFCasco::PrtBuf(uint8 *buf, int len) {
|
25
|
char prttmp[3000] = { "" };
|
26
|
int i = 0, n = 0, k = len;//1000
|
27
|
if (len<1000) {
|
28
|
for (i = 0; i<len; i++)
|
29
|
sprintf(prttmp + 3 * i, "%02x ", buf[i]);
|
30
|
prttmp[3000 - 1] = '\n';
|
31
|
PrintLog(LOG_INFORMATION, prttmp);
|
32
|
} else {
|
33
|
while (k>1000) {
|
34
|
for (i = 0; i<1000; i++)
|
35
|
sprintf(prttmp + 3 * i, "%02x ", buf[i + 1000 * n]);
|
36
|
PrintLog(LOG_INFORMATION, prttmp);
|
37
|
n++;
|
38
|
k -= 1000;
|
39
|
}
|
40
|
prttmp[3000 - 2] = '\n';
|
41
|
}
|
42
|
}
|
43
|
|
44
|
void CZFCasco::readini() {
|
45
|
|
46
|
char* home = getenv("FEPROOT");
|
47
|
if (home == NULL) {
|
48
|
PrintLog(LOG_ERROR, "????????δ????");
|
49
|
return;
|
50
|
}
|
51
|
char filename[512];
|
52
|
#if defined(__unix)
|
53
|
sprintf(filename, "%s%s", home, "/cfg/atsredis.ini");
|
54
|
#else
|
55
|
sprintf(filename, "%s%s", home, "\\cfg\\atsredis.ini");
|
56
|
#endif
|
57
|
CReadConf readconf;
|
58
|
readconf.ReadString("LoginInfo", "redis_ip", redisip, filename, "192.168.2.47");
|
59
|
redisport = readconf.ReadLong("LoginInfo", "redis_port", filename, "6379");
|
60
|
|
61
|
}
|
62
|
|
63
|
//??Լ???????ú???,?????ʼ????Լ?ӿڶ????Լ
|
64
|
void CZFCasco::Init(S_PROTOCOLCFG * pcfg) {
|
65
|
int i = 0;
|
66
|
PRawCtrl = pcfg->PRawCtrl;
|
67
|
pRxBuf = pcfg->pRxBuf;
|
68
|
pTxBuf = pcfg->pTxBuf;
|
69
|
pCmdMem = pcfg->pCmdMem;
|
70
|
pRtu = pcfg->pRtu;
|
71
|
pLink = pcfg->pLink;
|
72
|
pTable = pcfg->pTable;
|
73
|
pZfDataCtrl = pcfg->pZfDataCtrl;
|
74
|
// pHis = pcfg->pHis;
|
75
|
bInited = 0;
|
76
|
bFas = 0;
|
77
|
bEmcs = 0;
|
78
|
bScada = 0;
|
79
|
bIdle = 0; //??ʼ???ù?Լ?IJ???
|
80
|
m_SysId = 0xff;
|
81
|
// StaNums=13;//??վ??
|
82
|
memset(winHan, 0, sizeof(winHan));
|
83
|
memset(zfFas, 0, sizeof(zfFas));
|
84
|
memset(zfScada, 0, sizeof(zfScada));
|
85
|
memset(zfEmcs, 0, sizeof(zfEmcs));
|
86
|
memset(Fas, 0, sizeof(Fas));
|
87
|
memset(ScadaZone, 0, sizeof(ScadaZone));
|
88
|
memset(Emcs, 0, sizeof(Emcs));
|
89
|
memset(zfYX, 0, sizeof(zfYX));
|
90
|
memset(zfYCmx, 0, sizeof(zfYCmx));
|
91
|
m_RcvTimeOuts = pLink->GetRxTimeouts();
|
92
|
if (m_RcvTimeOuts <= 0) m_RcvTimeOuts = 10;
|
93
|
m_CallAllData = pLink->GetAllDataScanInterval();//Planned?ƻ??г???????Ϣ*60
|
94
|
if (m_CallAllData <= 0) m_CallAllData = 3600;
|
95
|
m_CallKWH = pLink->GetKwhScanInterval();//Practicalʵ???г???????Ϣ
|
96
|
if (m_CallKWH <= 0) m_CallKWH = 10;
|
97
|
|
98
|
sint32 rtuno = pLink->GetRtuNo();
|
99
|
m_SyncTime = pRtu->GetSyncTimeInt(rtuno) * 60;
|
100
|
|
101
|
m_LastSendTime = 0;
|
102
|
m_LastCallAllTime = 0;
|
103
|
m_LastCallKWHTime = 0;
|
104
|
m_LastSynctime = 0;
|
105
|
cnt_sequence = 0;
|
106
|
|
107
|
for (i = 0; i<pRtu->GetYxNum(rtuno); i++)PRawCtrl->PutAYx(rtuno, i, 0);
|
108
|
for (i = 0; i<pRtu->GetYcNum(rtuno); i++)PRawCtrl->PutAYc(rtuno, i, 0);
|
109
|
|
110
|
readini();
|
111
|
}
|
112
|
|
113
|
uint8 CZFCasco::GetZf() {
|
114
|
sint32 rtuno = pLink->GetRtuNo();
|
115
|
bFas = 0; bEmcs = 0; bScada = 0;
|
116
|
int i = 0, j = 0;
|
117
|
uint8 ret = 0;
|
118
|
uint16 YxNum, YcNum;
|
119
|
S_RDB_ZFYx *yxinfo;
|
120
|
CEasyList * pYxList = pZfDataCtrl->GetYxStructList();
|
121
|
YxNum = pYxList->GetListLen();
|
122
|
S_RDB_ZFYc *ycinfo;
|
123
|
CEasyList * pYcList = pZfDataCtrl->GetYcStructList();
|
124
|
YcNum = pYcList->GetListLen();
|
125
|
if (!bInited) {
|
126
|
for (i = 0; i<YxNum; i++) {//all
|
127
|
yxinfo = (S_RDB_ZFYx *)((*pYxList)[i]);
|
128
|
zfYX[i] = yxinfo->Val;
|
129
|
yxinfo->OldVal = yxinfo->Val;
|
130
|
yxinfo->qds/*chgFlag*/ = 0x80;
|
131
|
//FAS
|
132
|
if (yxinfo->YxNo >= 1 && yxinfo->YxNo <= 30) {
|
133
|
zfFas[i] = yxinfo->Val;
|
134
|
Fas[i] = 2 - (yxinfo->Val & 1);
|
135
|
// PRawCtrl->PutAYx(rtuno,i,zfFas[i]);
|
136
|
}
|
137
|
//SCADA
|
138
|
if (yxinfo->YxNo >= 31 && yxinfo->YxNo <= 200)
|
139
|
zfScada[i - 30] = yxinfo->Val;
|
140
|
//EMCS
|
141
|
if (yxinfo->YxNo >= 201 && yxinfo->YxNo <= 344)
|
142
|
zfEmcs[i - 200] = yxinfo->Val;
|
143
|
}
|
144
|
//1500MX
|
145
|
for (i = 0; i<YcNum; i++) {
|
146
|
ycinfo=(S_RDB_ZFYc *)((*pYcList)[i]);
|
147
|
if(ycinfo->Val>30)zfYCmx[i]=1;
|
148
|
else zfYCmx[i]=0;
|
149
|
ycinfo->OldVal=ycinfo->Val;
|
150
|
ycinfo->qds/*chgFlag*/ = 0x80;
|
151
|
}
|
152
|
bInited=1;
|
153
|
ret=0;//fas-scada-emcs???跢??ats
|
154
|
zfScadaToATS(zfYCmx,zfScada,120);//12??
|
155
|
zfEmcsToATS(zfEmcs,48*3);
|
156
|
}
|
157
|
else
|
158
|
{
|
159
|
for(int i=0;i<YxNum;i++)
|
160
|
{
|
161
|
|
162
|
|
163
|
//FAS
|
164
|
yxinfo=(S_RDB_ZFYx *)((*pYxList)[i]);
|
165
|
yxinfo->OldVal=yxinfo->Val;
|
166
|
yxinfo->qds/*chgFlag*/ = 0x80;
|
167
|
if(yxinfo->YxNo>=1 && yxinfo->YxNo<=30){
|
168
|
if(yxinfo->Val!=zfYX[i]){
|
169
|
zfFas[i]=yxinfo->Val;
|
170
|
zfYX[i]=yxinfo->Val;
|
171
|
Fas[i]=2-(yxinfo->Val & 1);
|
172
|
bFas++;
|
173
|
}
|
174
|
}
|
175
|
//SCADA
|
176
|
if(yxinfo->YxNo>=31 && yxinfo->YxNo<=200){
|
177
|
if(yxinfo->Val!=zfYX[i]){
|
178
|
zfScada[i-30]=yxinfo->Val;
|
179
|
zfYX[i]=yxinfo->Val;
|
180
|
bScada++;
|
181
|
}
|
182
|
}
|
183
|
//EMCS
|
184
|
if(yxinfo->YxNo>=201 && yxinfo->YxNo<=344){
|
185
|
if(yxinfo->Val!=zfYX[i]){
|
186
|
zfEmcs[i-200]=yxinfo->Val;
|
187
|
zfYX[i]=yxinfo->Val;
|
188
|
bEmcs++;
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
//1500MX
|
193
|
for(i=0;i<YcNum;i++)
|
194
|
{ ycinfo=(S_RDB_ZFYc *)((*pYcList)[i]);
|
195
|
if(ycinfo->Val>=30 && zfYCmx[i]==0)
|
196
|
{
|
197
|
zfYCmx[i]=1;bScada++;}
|
198
|
if(ycinfo->Val<30 && zfYCmx[i]==1)
|
199
|
{
|
200
|
zfYCmx[i]=0;bScada++;}
|
201
|
ycinfo->OldVal=ycinfo->Val;
|
202
|
ycinfo->qds/*chgFlag*/ = 0x80;
|
203
|
}
|
204
|
ret=0x80;
|
205
|
if(bFas>0) ret+=1;
|
206
|
if(bScada>0){
|
207
|
ret+=2;zfScadaToATS(zfYCmx,zfScada,120);}
|
208
|
if(bEmcs>0){ ret+=4;zfEmcsToATS(zfEmcs,48*3);}
|
209
|
}
|
210
|
return ret;
|
211
|
}
|
212
|
//yc-13??ǣ????ֱ??ĸ?ߴ??????ޣ?yx-ֱ?????ء?բ??״̬
|
213
|
//12?δ??? -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11
|
214
|
// ELZ-ZJJ,-ZDB,-DSH,-CYR,-QPS,-HJR,-ZXS,-JSR,-XYR,-PLR,-NBL,-HQS
|
215
|
void CZFCasco::zfScadaToATS(uint8 *yc,uint8 *yx,int len)
|
216
|
{
|
217
|
//len-116
|
218
|
int i=0,j=0,k=0,tmp=0;
|
219
|
//ELZ-ZJJ
|
220
|
if((yc[0]>0 && yx[0]>0 && yx[0+2]>0) || (yc[0+1]>0 && yx[10]>0 && yx[10+4]>0))//XX
|
221
|
ScadaZone[0][1]=1;
|
222
|
else ScadaZone[0][1]=0;
|
223
|
if((yc[0]>0 && yx[1]>0 && yx[1+2]>0) || (yc[0+1]>0 && yx[10+1]>0 && yx[10+1+4]>0))//SX
|
224
|
ScadaZone[0][2]=1;
|
225
|
else ScadaZone[0][2]=0;
|
226
|
//ZJJ-ZDB---NBL 10
|
227
|
for(i=0;i<len/10-2;i++)
|
228
|
{//XX
|
229
|
if((yc[1+i]>0 && yx[10+10*i+2]>0 && yx[10+10*i+2+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)]>0 && yx[10+10*(i+1)+4]>0))
|
230
|
ScadaZone[1+i][1]=1;
|
231
|
else ScadaZone[1+i][1]=0;
|
232
|
//SX
|
233
|
if((yc[1+i]>0 && yx[10+10*i+3]>0 && yx[10+10*i+3+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)+1]>0 && yx[10+10*(i+1)+1+4]>0))
|
234
|
ScadaZone[1+i][2]=1;
|
235
|
else ScadaZone[1+i][2]=0;
|
236
|
}
|
237
|
i=10;
|
238
|
//NBL-HQS
|
239
|
if((yc[1+i]>0 && yx[10+10*i+2]>0 && yx[10+10*i+2+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)]>0 && yx[10+10*(i+1)+2]>0))
|
240
|
ScadaZone[1+i][1]=1;
|
241
|
else ScadaZone[1+i][1]=0;
|
242
|
if((yc[1+i]>0 && yx[10+10*i+3]>0 && yx[10+10*i+3+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)+1]>0 && yx[10+10*(i+1)+1+2]>0))
|
243
|
ScadaZone[1+i][2]=1;
|
244
|
else ScadaZone[1+i][2]=0;
|
245
|
|
246
|
//ZJJ-ZJT
|
247
|
if(yc[1]>0 && yx[10*12+4]>0 && yx[10*12+4+2]>0)
|
248
|
ScadaZone[1][0]=1;//in
|
249
|
else ScadaZone[1][0]=0;
|
250
|
if(yc[1]>0 && yx[10*12+4+1]>0 && yx[10*12+4+2+1]>0)
|
251
|
ScadaZone[1][3]=1;//out
|
252
|
else ScadaZone[1][3]=0;
|
253
|
//ZJT
|
254
|
if(yc[13]>0 && yx[10*13+0]>0 && yx[10*13+7]>0)
|
255
|
ScadaZone[12][0]=1;
|
256
|
else ScadaZone[12][0]=0;
|
257
|
if(yc[13]>0 && yx[10*13+1]>0 && yx[10*13+7+1]>0)
|
258
|
ScadaZone[12][1]=1;
|
259
|
else ScadaZone[12][1]=0;
|
260
|
if(yc[13]>0 && yx[10*13+2]>0 && yx[10*13+7+2]>0)
|
261
|
ScadaZone[12][2]=1;
|
262
|
else ScadaZone[12][2]=0;
|
263
|
if(yc[13]>0 && yx[10*13+3]>0 && yx[10*13+7+3]>0)
|
264
|
ScadaZone[12][3]=1;
|
265
|
else ScadaZone[12][3]=0;
|
266
|
|
267
|
if(yc[13]>0 && yx[10*13+4]>0 && yx[10*13+7+4]>0)
|
268
|
ScadaZone[13][0]=1;
|
269
|
else ScadaZone[13][0]=0;
|
270
|
if(yc[13]>0 && yx[10*13+5]>0)
|
271
|
ScadaZone[13][1]=1;
|
272
|
else ScadaZone[13][1]=0;
|
273
|
if(yc[13]>0 && yx[10*13+6]>0 && yx[10*13+7+6]>0)
|
274
|
ScadaZone[13][2]=1;
|
275
|
else ScadaZone[13][2]=0;
|
276
|
|
277
|
//???絶???//0-9
|
278
|
for(i=0;i<len/10-2;i++)
|
279
|
{ //XX
|
280
|
if(yx[10*(i+1)+8]>0){
|
281
|
if(ScadaZone[i][1]!=ScadaZone[i+1][1]){
|
282
|
ScadaZone[i+1][1]=ScadaZone[i][1]=1;}
|
283
|
}
|
284
|
//SX
|
285
|
if(yx[10*(i+1)+9]>0){
|
286
|
if(ScadaZone[i][2]!=ScadaZone[i+1][2]){
|
287
|
ScadaZone[i+1][2]=ScadaZone[i][2]=1;}
|
288
|
}
|
289
|
}
|
290
|
//9-0
|
291
|
for(i=len/10-2-1;i>=0;i--)
|
292
|
{ //XX
|
293
|
if(yx[10*(i+1)+8]>0){
|
294
|
if(ScadaZone[i][1]!=ScadaZone[i+1][1]){
|
295
|
ScadaZone[i+1][1]=ScadaZone[i][1]=1;}
|
296
|
}
|
297
|
//SX
|
298
|
if(yx[10*(i+1)+9]>0){
|
299
|
if(ScadaZone[i][2]!=ScadaZone[i+1][2]){
|
300
|
ScadaZone[i+1][2]=ScadaZone[i][2]=1;}
|
301
|
}
|
302
|
}
|
303
|
|
304
|
//ZJJ-ZJT???絶
|
305
|
if(yx[128]>0){//2151
|
306
|
if(ScadaZone[1][0]!=ScadaZone[1][1]){
|
307
|
ScadaZone[1][1]=ScadaZone[1][0]=1;}
|
308
|
}
|
309
|
if(yx[129]>0){//2162
|
310
|
if(ScadaZone[1][3]!=ScadaZone[1][2]){
|
311
|
ScadaZone[1][2]=ScadaZone[1][3]=1;}
|
312
|
}
|
313
|
|
314
|
//ZJT???絶
|
315
|
if(yx[144+2]>0){//ZT03
|
316
|
if(ScadaZone[12][0]!=ScadaZone[12][2]){
|
317
|
ScadaZone[12][2]=ScadaZone[12][0]=1;}
|
318
|
}
|
319
|
if(yx[144+2+1]>0){//ZT04
|
320
|
if(ScadaZone[12][1]!=ScadaZone[12][3]){
|
321
|
ScadaZone[12][3]=ScadaZone[12][1]=1;}
|
322
|
}
|
323
|
if(yx[144+2+2]>0){//ZT05
|
324
|
if(ScadaZone[12][3]!=ScadaZone[13][0]){
|
325
|
ScadaZone[13][0]=ScadaZone[12][3]=1;}
|
326
|
}
|
327
|
if(yx[144+2+3]>0){//ZT06
|
328
|
if(ScadaZone[13][0]!=ScadaZone[13][2]){
|
329
|
ScadaZone[13][2]=ScadaZone[13][0]=1;}
|
330
|
}
|
331
|
if(yx[144+2+2]>0){//ZT05
|
332
|
if(ScadaZone[12][3]!=ScadaZone[13][0]){
|
333
|
ScadaZone[13][0]=ScadaZone[12][3]=1;}
|
334
|
}
|
335
|
if(yx[144+2+1]>0){//ZT04
|
336
|
if(ScadaZone[12][1]!=ScadaZone[12][3]){
|
337
|
ScadaZone[12][3]=ScadaZone[12][1]=1;}
|
338
|
}
|
339
|
if(yx[144+2]>0){//ZT03
|
340
|
if(ScadaZone[12][0]!=ScadaZone[12][2]){
|
341
|
ScadaZone[12][2]=ScadaZone[12][0]=1;}
|
342
|
}
|
343
|
if(yx[144+0]>0){//ZT01-chu
|
344
|
if(ScadaZone[13][0]>0)ScadaZone[14][0]=1;
|
345
|
else ScadaZone[14][0]=0;
|
346
|
}
|
347
|
else ScadaZone[14][0]=0;
|
348
|
if(yx[144+1]>0){//ZT02-ru
|
349
|
if(ScadaZone[12][2]>0)ScadaZone[14][1]=1;
|
350
|
else ScadaZone[14][1]=0;
|
351
|
}
|
352
|
else ScadaZone[14][1]=0;
|
353
|
|
354
|
//ELZ-L01-L02
|
355
|
if(ScadaZone[0][1]>0 && yx[4]>0)ScadaZone[0][0]=1;
|
356
|
else ScadaZone[0][0]=0;
|
357
|
if(ScadaZone[0][2]>0 && yx[5]>0)ScadaZone[0][3]=1;
|
358
|
else ScadaZone[0][3]=0;
|
359
|
if(ScadaZone[0][0]+ScadaZone[0][3]<1)
|
360
|
{ScadaZone[0][0]=0;ScadaZone[0][3]=0;}
|
361
|
else
|
362
|
{ScadaZone[0][0]=1;ScadaZone[0][3]=1;}
|
363
|
//ZDB-DSH-L03-L04
|
364
|
if(ScadaZone[2][1]>0 && yx[6]>0)ScadaZone[3][0]=1;
|
365
|
else ScadaZone[3][0]=0;
|
366
|
if(ScadaZone[2][2]>0 && yx[7]>0)ScadaZone[3][3]=1;
|
367
|
else ScadaZone[3][3]=0;
|
368
|
if(ScadaZone[3][0]+ScadaZone[3][3]<1)
|
369
|
{ScadaZone[3][0]=0;ScadaZone[3][3]=0;}
|
370
|
else
|
371
|
{ScadaZone[3][0]=1;ScadaZone[3][3]=1;}
|
372
|
//QPS-HJR-L05-L06
|
373
|
if(ScadaZone[5][1]>0 && yx[8]>0)ScadaZone[6][0]=1;
|
374
|
else ScadaZone[6][0]=0;
|
375
|
if(ScadaZone[5][2]>0 && yx[9]>0)ScadaZone[6][3]=1;
|
376
|
else ScadaZone[6][3]=0;
|
377
|
if(ScadaZone[6][0]+ScadaZone[6][3]<1)
|
378
|
{ScadaZone[6][0]=0;ScadaZone[6][3]=0;}
|
379
|
else
|
380
|
{ScadaZone[6][0]=1;ScadaZone[6][3]=1;}
|
381
|
|
382
|
sint32 rtuno = pLink->GetRtuNo();
|
383
|
//1?е?2??0δ֪
|
384
|
/* for(i=0;i<len/10+3;i++)
|
385
|
{
|
386
|
for(j=0;j<4;j++)
|
387
|
{
|
388
|
ScadaZone[i][j]=2-(ScadaZone[i][j]&1);
|
389
|
PRawCtrl->PutAYx(rtuno,i*4+j+1,ScadaZone[i][j]&1);
|
390
|
}
|
391
|
}*/
|
392
|
}
|
393
|
|
394
|
void CZFCasco::zfEmcsToATS(uint8 *buf,int len)
|
395
|
{
|
396
|
sint32 rtuno = pLink->GetRtuNo();
|
397
|
//up-dn-stop
|
398
|
int i=0,num=len/3;
|
399
|
for(i=0;i<num;i++)
|
400
|
{
|
401
|
// PRawCtrl->PutAYx(rtuno,i*3+0+81,buf[3*i+0]);
|
402
|
// PRawCtrl->PutAYx(rtuno,i*3+1+81,buf[3*i+1]);
|
403
|
// PRawCtrl->PutAYx(rtuno,i*3+2+81,buf[3*i+2]);
|
404
|
//Status-1on2off0unknown
|
405
|
if(buf[3*i+0]+buf[3*i+1]==1 && buf[3*i+2]<=0)
|
406
|
Emcs[i][0]=1;//run-100-010
|
407
|
else if(buf[3*i+0]+buf[3*i+1]==0 && buf[3*i+2]>0)
|
408
|
Emcs[i][0]=2;//stop-001
|
409
|
else
|
410
|
Emcs[i][0]=0;//unknown
|
411
|
//Director-1up2dn0unknown
|
412
|
if(buf[3*i+0]>0 && buf[3*i+1]<=0 && buf[3*i+2]<=0 )Emcs[i][1]=1;//up
|
413
|
else if(buf[3*i+1]>0 && buf[3*i+0]<=0 && buf[3*i+2]<=0 )Emcs[i][1]=2;//dn
|
414
|
else Emcs[i][1]=0;
|
415
|
}
|
416
|
}
|
417
|
|
418
|
|
419
|
sint32 CZFCasco::TxProc()
|
420
|
{
|
421
|
uint8 ret=GetZf();
|
422
|
sint32 nowtime = GetNowSecond();
|
423
|
E_RAW_ComStat commstatus = pLink->GetCommStatus();
|
424
|
if( commstatus !=CMST_TX_CNT && commstatus !=CMST_NORMAL)
|
425
|
return 0;
|
426
|
if((nowtime - m_LastSendTime) >= 5)//5sPolling
|
427
|
{ret=0;}
|
428
|
if(ret==0){
|
429
|
IscsAtsFasInfo();
|
430
|
IscsAtsScadaInfo();
|
431
|
IscsAtsEmcsInfo();
|
432
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
433
|
}
|
434
|
else{
|
435
|
if(ret&1>0){
|
436
|
IscsAtsFasInfo();
|
437
|
}
|
438
|
if(ret&2){
|
439
|
IscsAtsScadaInfo();
|
440
|
}
|
441
|
if(ret&4){
|
442
|
IscsAtsEmcsInfo();
|
443
|
}
|
444
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
445
|
}
|
446
|
if((nowtime - m_LastSendTime) >= 5)//5sPolling
|
447
|
{
|
448
|
MsgPolling();
|
449
|
//bInited=0;
|
450
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
451
|
pLink->SetCommStatus(CMST_RX_CNT);
|
452
|
}
|
453
|
if((nowtime - m_LastCallAllTime) > m_CallAllData)
|
454
|
{//???????г??ƻ???Ϣ
|
455
|
// IscsAtsPlannedTrain();
|
456
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
457
|
// pLink->SetCommStatus(CMST_RX_CNT);
|
458
|
}
|
459
|
|
460
|
if(( nowtime - m_LastCallKWHTime)>m_CallKWH)
|
461
|
{//????ʵ???г??ƻ???Ϣ
|
462
|
// IscsAtsPracticalTrain();
|
463
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
464
|
// pLink->SetCommStatus(CMST_RX_CNT);
|
465
|
}
|
466
|
|
467
|
|
468
|
return 1;
|
469
|
}
|
470
|
|
471
|
sint32 CZFCasco::RxProc()
|
472
|
{ int xx=0;
|
473
|
E_RAW_ComStat commstatus = pLink->GetCommStatus();
|
474
|
|
475
|
sint32 rtuno = pLink->GetRtuNo();
|
476
|
uint8 rtuaddr = pRtu->GetRtuAddr(rtuno);
|
477
|
uint8 buf[80000];
|
478
|
int datalen = 0 ,datanum =0,dlen=0;
|
479
|
memset(buf,0,sizeof(buf));
|
480
|
sint32 buflen=pRxBuf->GetReadableSize();
|
481
|
datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
|
482
|
int nowtime=GetNowSecond();
|
483
|
if ( commstatus==CMST_RX_CNT && (nowtime-m_LastSendTime) >= m_RcvTimeOuts)
|
484
|
{
|
485
|
//??ʱ???ط???ֱ????????һ???ն?
|
486
|
if(buflen>0)pRxBuf->Move(buflen);
|
487
|
pLink->RegisterFrm(FRAME_RX_TIMEOUT);
|
488
|
pLink->SetCommStatus(CMST_TX_CNT);
|
489
|
m_LastSendTime=0;
|
490
|
PrintLog(LOG_VIOLATION,"???ݳ?ʱ\n");
|
491
|
return -1;
|
492
|
}
|
493
|
if(buflen<6){
|
494
|
return 0;
|
495
|
}
|
496
|
dlen=buf[2]+buf[1]*256+3;
|
497
|
while(buf[0]==m_SysId && datalen>=buf[2]+buf[1]*256+3 && buf[2]+buf[1]*256<=1025) //??һλΪ0xff ??֡????û?к???֡ ??Լ??????ȡ??????֡????
|
498
|
{ xx=0;
|
499
|
switch(buf[7]+buf[6]*256) //?ж???֡???ݵ???ϢID????
|
500
|
{
|
501
|
case 0x0FA0://4000//0x1001://
|
502
|
RxAtsTrainLocation(buf); //?г?λ????Ϣ
|
503
|
break;
|
504
|
case 0x1005://0x1002://
|
505
|
RxAtsBlockInfo(buf); //?г???????Ϣ
|
506
|
break;
|
507
|
case 0x1006://0x1003://
|
508
|
//if(buf[2]+buf[1]*256>10)
|
509
|
switch(buf[9]+buf[8]*256)
|
510
|
{
|
511
|
case 0x1101://start
|
512
|
|
513
|
break;
|
514
|
case 0x1102://content
|
515
|
RxAtsPlannedTrain(buf); //?ƻ??г???????Ϣ
|
516
|
break;
|
517
|
case 0x1103://end
|
518
|
|
519
|
break;
|
520
|
default:
|
521
|
break;
|
522
|
}
|
523
|
break;
|
524
|
case 0x1007://0x1004://PracticalTrain
|
525
|
//if(buf[2]+buf[1]*256>10)
|
526
|
switch(buf[9]+buf[8]*256)
|
527
|
{
|
528
|
case 0x1101://start
|
529
|
|
530
|
break;
|
531
|
case 0x1102://content
|
532
|
RxAtsPracticalTrain(buf);
|
533
|
break;
|
534
|
case 0x1103://end
|
535
|
|
536
|
break;
|
537
|
default:
|
538
|
break;
|
539
|
}
|
540
|
break;
|
541
|
case 0x1008://0x1005://DynamicTrain
|
542
|
RxAtsDynamicTrain(buf);
|
543
|
break;
|
544
|
case 0x1009://0x2002://Request PlannedTrain
|
545
|
|
546
|
break;
|
547
|
case 0x100A://0x2003://Request PracticalTrain
|
548
|
|
549
|
break;
|
550
|
case 0x2001://0x2004://fas
|
551
|
|
552
|
break;
|
553
|
case 0x2002://0x2005://scada
|
554
|
|
555
|
break;
|
556
|
case 0x2003://0x2006://bas
|
557
|
|
558
|
break;
|
559
|
case 0x3001://MessagePolling
|
560
|
|
561
|
break;
|
562
|
default:
|
563
|
PrintLog(LOG_VIOLATION," FromATS Error Type %02x %02x\n",buf[6],buf[7]);
|
564
|
xx=1;
|
565
|
pRxBuf->Move(1);
|
566
|
buflen-=1;
|
567
|
datalen-=1;
|
568
|
datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
|
569
|
break;
|
570
|
|
571
|
}
|
572
|
if(xx>0)break;
|
573
|
// if(datalen>0){
|
574
|
if(buf[7]+buf[6]*256!=0x1007 || buf[7]+buf[6]*256!=0x1006 || buf[7]+buf[6]*256!=0x3001)
|
575
|
{
|
576
|
PrintLog(LOG_INFORMATION,"RTU%d?յ?MsgID%02x%02x,buflen=%d,datalen=%d--<<",rtuno,buf[6],buf[7],buf[2]+buf[1]*256+3,datalen);
|
577
|
// PrtBuf(buf,buf[2]+buf[1]*256+3);
|
578
|
}
|
579
|
//PrintLog(LOG_INFORMATION,"BeforeMove:buf[0]=%02x%02x%02x,buf[%d]=%02x%02x%02x\n",buf[0],buf[1],buf[2],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3+1],buf[buf[2]+buf[1]*256+3+2]);
|
580
|
pRxBuf->Move(buf[2]+buf[1]*256+3);
|
581
|
buflen-=buf[2]+buf[1]*256+3;
|
582
|
datalen-=buf[2]+buf[1]*256+3;
|
583
|
datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
|
584
|
//PrintLog(LOG_INFORMATION,"AfterMove:buf[0]=%02x%02x%02x,buf[%d]=%02x%02x%02x\n",buf[0],buf[1],buf[2],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3+1],buf[buf[2]+buf[1]*256+3+2]);
|
585
|
//buflen=pRxBuf->GetReadableSize();
|
586
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
587
|
pLink->SetCommStatus(CMST_TX_CNT);
|
588
|
}
|
589
|
while(buflen>0 && (buf[0]!=m_SysId || (buf[0]==m_SysId && buf[2]+buf[1]*256>1025)))
|
590
|
{
|
591
|
PrintLog(LOG_INFORMATION,"-1");PrtBuf(buf,1);
|
592
|
pRxBuf->Move(1);
|
593
|
buflen=pRxBuf->GetReadableSize();
|
594
|
datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
|
595
|
}
|
596
|
return 1;
|
597
|
}
|
598
|
|
599
|
sint32 CZFCasco::GetNowSecond()
|
600
|
{
|
601
|
CSeTime SE_T;
|
602
|
TCriterionTime tmptime;//sint32
|
603
|
SE_T.GetNow(&tmptime);
|
604
|
return (sint32)tmptime;
|
605
|
}
|
606
|
|
607
|
void CZFCasco::IscsAtsPlannedTrain()
|
608
|
{
|
609
|
uint8 conLen=StaNums*2;
|
610
|
uint8 txbuff[8];
|
611
|
uint8 len=0, tLen=5;
|
612
|
memset(txbuff,0,8);
|
613
|
if(cnt_sequence>=65535)
|
614
|
cnt_sequence=0;
|
615
|
else
|
616
|
cnt_sequence++;
|
617
|
//7bytes Head
|
618
|
txbuff[len++]=m_SysId;//SystemID
|
619
|
txbuff[len++]=tLen / 0x100;//L Total Lenth
|
620
|
txbuff[len++]=tLen % 0x100;//H
|
621
|
txbuff[len++]=0;//Multi-Flag
|
622
|
////////////////////////////
|
623
|
txbuff[len++]=0;//msgID len + content len
|
624
|
txbuff[len++]=2;//
|
625
|
txbuff[len++]=4105/0x100;//0x20;//H msgID 4105
|
626
|
txbuff[len++]=4105%0x100;//0x02;//L msgID
|
627
|
//content
|
628
|
|
629
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
630
|
pTxBuf->Write(txbuff,len);
|
631
|
pLink->SetCommStatus(CMST_RX_CNT);
|
632
|
m_LastCallAllTime = GetNowSecond();
|
633
|
|
634
|
PrintLog(LOG_INFORMATION,"ISCS->ATS Send PlannedTrain MsgID = 0x2002");
|
635
|
// PrtBuf(txbuff,len);
|
636
|
|
637
|
}
|
638
|
|
639
|
void CZFCasco::IscsAtsPracticalTrain()
|
640
|
{
|
641
|
uint8 conLen=StaNums*2;
|
642
|
uint8 txbuff[8];
|
643
|
uint8 len=0,tLen=5;
|
644
|
memset(txbuff,0,8);
|
645
|
if(cnt_sequence>=65535)
|
646
|
cnt_sequence=0;
|
647
|
else
|
648
|
cnt_sequence++;
|
649
|
//7bytes Head
|
650
|
txbuff[len++]=m_SysId;//SystemID
|
651
|
txbuff[len++]=tLen/0x100;//H Total Lenth
|
652
|
txbuff[len++]=tLen%0x100;//L
|
653
|
txbuff[len++]=0;//Multi-Flag
|
654
|
////////////////////////////
|
655
|
txbuff[len++]=0;//msgID len + content len
|
656
|
txbuff[len++]=2;//
|
657
|
txbuff[len++]=4106/0x100;//0x20;//H msgID 4106
|
658
|
txbuff[len++]=4106%0x100;//0x03;//L msgID
|
659
|
//content
|
660
|
|
661
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
662
|
pTxBuf->Write(txbuff,len);
|
663
|
pLink->SetCommStatus(CMST_RX_CNT);
|
664
|
m_LastCallKWHTime = GetNowSecond();
|
665
|
|
666
|
PrintLog(LOG_INFORMATION,"ISCS->ATS Send PracticalTrain MsgID = 0x2003");
|
667
|
// PrtBuf(txbuff,len);
|
668
|
|
669
|
}
|
670
|
|
671
|
void CZFCasco::IscsAtsFasInfo()
|
672
|
{
|
673
|
uint8 conLen=StaNums*2; //13*2
|
674
|
uint8 txbuff[35];
|
675
|
uint8 len=0,tLen;
|
676
|
memset(txbuff,0,sizeof(txbuff));
|
677
|
if(cnt_sequence>=65535) //????
|
678
|
cnt_sequence=0;
|
679
|
else
|
680
|
cnt_sequence++;
|
681
|
tLen=1+2+(2+1+conLen);
|
682
|
//7bytes Head
|
683
|
txbuff[len++]=m_SysId;//SystemID
|
684
|
txbuff[len++]=tLen/0x100;//H Total Lenth
|
685
|
txbuff[len++]=tLen%0x100;//L
|
686
|
txbuff[len++]=0;//Multi-Flag
|
687
|
////////////////////////////MsgLen2+MsgID2+MsgContent
|
688
|
txbuff[len++]=(2+1+conLen)/0x100;//msgID len + content len
|
689
|
txbuff[len++]=(2+1+conLen)%0x100;
|
690
|
txbuff[len++]=8193/0x100;//0x20;//H msgID 8193
|
691
|
txbuff[len++]=8193%0x100;//0x04;//L msgID
|
692
|
//content
|
693
|
txbuff[len++]=StaNums;//Number of Stations
|
694
|
for(int i=0;i<StaNums;i++){
|
695
|
txbuff[len++]=i+1;//StationID
|
696
|
txbuff[len++]=Fas[i];//Status:0-unknown;1-On;2-Off
|
697
|
}
|
698
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
699
|
pTxBuf->Write(txbuff,len);
|
700
|
// pLink->SetCommStatus(CMST_RX_CNT);
|
701
|
m_LastSendTime = GetNowSecond();
|
702
|
|
703
|
PrintLog(LOG_INFORMATION,"ISCS->ATS Send FasInfo MsgID = 0x2004");
|
704
|
// PrtBuf(txbuff,len);
|
705
|
|
706
|
}
|
707
|
|
708
|
void CZFCasco::IscsAtsScadaInfo()
|
709
|
{
|
710
|
int conLen=15*4;
|
711
|
uint8 txbuff[210];
|
712
|
uint8 len=0,tLen;
|
713
|
memset(txbuff,0,sizeof(txbuff));
|
714
|
if(cnt_sequence>=65535)
|
715
|
cnt_sequence=0;
|
716
|
else
|
717
|
cnt_sequence++;
|
718
|
tLen=1+2+(2+2+conLen*3);
|
719
|
//7bytes Head
|
720
|
txbuff[len++]=m_SysId;//SystemID
|
721
|
txbuff[len++]=tLen/0x100;//H Total Lenth
|
722
|
txbuff[len++]=tLen%0x100;//L
|
723
|
txbuff[len++]=0;//Multi-Flag
|
724
|
////////////////////////////
|
725
|
txbuff[len++]=(2+2+conLen*3)/0x100;//msgID len + content len
|
726
|
txbuff[len++]=(2+2+conLen*3)%0x100;
|
727
|
txbuff[len++]=8194/0x100;//0x20;//H msgID 8194
|
728
|
txbuff[len++]=8194%0x100;//0x05;//L msgID
|
729
|
txbuff[len++]=(conLen)/0x100;//H msgID
|
730
|
txbuff[len++]=(conLen)%0x100;//L msgID
|
731
|
//content
|
732
|
for(int i=0;i<12+3;i++){
|
733
|
for(int j=0;j<4;j++){
|
734
|
txbuff[len++]=(j+4*i+1)/0x100;//H
|
735
|
txbuff[len++]=(j+4*i+1)%0x100;//L
|
736
|
txbuff[len++]=2-ScadaZone[i][j];//Status:0-unknown;1-On;2-Off
|
737
|
}
|
738
|
}
|
739
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
740
|
pTxBuf->Write(txbuff,len);
|
741
|
// pLink->SetCommStatus(CMST_RX_CNT);
|
742
|
m_LastSendTime = GetNowSecond();
|
743
|
|
744
|
PrintLog(LOG_INFORMATION,"ISCS->ATS Send ScadaInfo MsgID = 0x2005");
|
745
|
// PrtBuf(txbuff,len);
|
746
|
|
747
|
}
|
748
|
//ATS-CASCO?ȸ??ֽ?-????ֽ?
|
749
|
void CZFCasco::IscsAtsEmcsInfo()
|
750
|
{
|
751
|
uint8 conLen=48*3;//?????
|
752
|
uint8 txbuff[210];
|
753
|
uint8 len=0,tLen;
|
754
|
memset(txbuff,0,sizeof(txbuff));
|
755
|
if(cnt_sequence>=65535)
|
756
|
cnt_sequence=0;
|
757
|
else
|
758
|
cnt_sequence++;
|
759
|
tLen=1+2+(2+2+conLen/3*4);
|
760
|
//7bytes Head
|
761
|
txbuff[len++]=m_SysId;//SystemID
|
762
|
txbuff[len++]=tLen/0x100;//H Total Lenth
|
763
|
txbuff[len++]=tLen%0x100;//L
|
764
|
txbuff[len++]=0;//Multi-Flag
|
765
|
////////////////////////////
|
766
|
txbuff[len++]=(2+2+conLen/3*4)/0x100;//msgID len + content len
|
767
|
txbuff[len++]=(2+2+conLen/3*4)%0x100;
|
768
|
txbuff[len++]=8195/0x100;//0x20;//H msgID 8195
|
769
|
txbuff[len++]=8195%0x100;//0x06;//L msgID
|
770
|
txbuff[len++]=(conLen/3)/0x100;//H msgID
|
771
|
txbuff[len++]=(conLen/3)%0x100;//L msgID
|
772
|
//content
|
773
|
for(int i=0;i<conLen/3;i++){
|
774
|
txbuff[len++]=(i+1)/0x100;//FJnoATS?ȸ??ֽ?-????ֽ?
|
775
|
txbuff[len++]=(i+1)%0x100;//FJno
|
776
|
txbuff[len++]=Emcs[i][0];//Status:0-unknown;1-On;2-Off
|
777
|
txbuff[len++]=Emcs[i][1];//Direction:0-unknown;1-????Up;2-????Dn
|
778
|
}
|
779
|
|
780
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
781
|
pTxBuf->Write(txbuff,len);
|
782
|
// pLink->SetCommStatus(CMST_RX_CNT);
|
783
|
m_LastSendTime = GetNowSecond();
|
784
|
|
785
|
PrintLog(LOG_INFORMATION,"ISCS->ATS Send EmcsInfo MsgID = 0x2006");
|
786
|
// PrtBuf(txbuff,len);
|
787
|
|
788
|
}
|
789
|
|
790
|
void CZFCasco::MsgPolling()
|
791
|
{
|
792
|
uint8 conLen=0;
|
793
|
uint8 txbuff[8];
|
794
|
uint16 len=0,tLen;
|
795
|
memset(txbuff,0,8);
|
796
|
if(cnt_sequence>=65535)
|
797
|
cnt_sequence=0;
|
798
|
else
|
799
|
cnt_sequence++;
|
800
|
tLen=1+2+(2+conLen);
|
801
|
//7bytes Head
|
802
|
txbuff[len++]=m_SysId;//SystemID
|
803
|
txbuff[len++]=tLen/0x100;//H Total Lenth
|
804
|
txbuff[len++]=tLen%0x100;//L
|
805
|
txbuff[len++]=0;//Multi-Flag
|
806
|
////////////////////////////
|
807
|
txbuff[len++]=0;//msgID len + content len
|
808
|
txbuff[len++]=2;//
|
809
|
txbuff[len++]=0x30;//H msgID
|
810
|
txbuff[len++]=0x01;//L msgID
|
811
|
//content no
|
812
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
813
|
pTxBuf->Write(txbuff,len);
|
814
|
pLink->SetCommStatus(CMST_RX_CNT);
|
815
|
m_LastSendTime = GetNowSecond();
|
816
|
|
817
|
// PrintLog(LOG_INFORMATION,"ISCS->ATS Send MsgPolling MsgID = 0x3001");
|
818
|
// PrtBuf(txbuff,len);
|
819
|
}
|
820
|
|
821
|
uint8 CZFCasco::RxAtsTrainLocation(uint8 *buf)
|
822
|
{//ATS ÿ?? 10 ?뷢??һ?ε?ǰ??ȫ???г???Ϣ
|
823
|
int i=0,j=0;
|
824
|
sint32 rtuno = pLink->GetRtuNo();
|
825
|
//Dir??0????1????2δ֪??Stat bit0?ƻ???bit2-3??00??10????11unknown
|
826
|
PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS Location Tcnt=%d",buf[6],buf[7],buf[8]);
|
827
|
for(i=0;i<buf[8];i++){
|
828
|
/* PrintLog(LOG_INFORMATION,"Tr[%d]Uno=%d,TSno=%d,DesID=%d,Dir=%d,StaUpS=%d,StaDnS=%d,Stat=%x,Win=%d\n",i+1,
|
829
|
buf[10+12*i]+buf[9+12*i]*256,buf[12+12*i]+buf[11+12*i]*256,buf[14+12*i]+buf[13+12*i]*256,
|
830
|
buf[15+12*i],buf[16+12*i],buf[17+12*i],buf[18+12*i],buf[20+12*i]+buf[19+12*i]*256);
|
831
|
*/
|
832
|
//101??ʼ??//dn-1;up-0
|
833
|
PRawCtrl->PutAYc(rtuno,buf[20+12*i]+buf[19+12*i]*256,buf[10+12*i]+buf[9+12*i]*256); //???δ???ŵ㡪??>?г??????
|
834
|
winHan[buf[20+12*i]+buf[19+12*i]*256]=buf[10+12*i]+buf[9+12*i]*256; //????ǰ???δ??µ??г?????ż?¼??winHan[]??
|
835
|
for(j=100;j<1500;j++)
|
836
|
{if(winHan[j]>0 && buf[10+12*i]+buf[9+12*i]*256==winHan[j] && j!=buf[20+12*i]+buf[19+12*i]*256)
|
837
|
winHan[j]=0;
|
838
|
PRawCtrl->PutAYc(rtuno,j,0); //?????һ?ε?ǰ?г?????????ڵij??δ??ŵļ?¼
|
839
|
}
|
840
|
}
|
841
|
return 1;
|
842
|
}
|
843
|
|
844
|
uint8 CZFCasco::RxAtsBlockInfo(uint8 *buf)
|
845
|
{//Block ATS ʵʱ????
|
846
|
//????2-3,6-7,10-11????
|
847
|
//?羮3-4,4-5,5-6,12-13
|
848
|
int i=0,j=0,dnWin=0,upWin=0;//dn-1;up-0
|
849
|
sint32 rtuno = pLink->GetRtuNo();
|
850
|
PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS Block Tcnt=%d",buf[6],buf[7],buf[8]);
|
851
|
if(buf[8]==0){//noBlock??reset0
|
852
|
for(i=0;i<20;i++){
|
853
|
PRawCtrl->PutAYc(rtuno,2*i+1,0);
|
854
|
PRawCtrl->PutAYc(rtuno,2*i+2,0);
|
855
|
PRawCtrl->PutAYx(rtuno,2*i+1,0);
|
856
|
PRawCtrl->PutAYx(rtuno,2*i+2,0);
|
857
|
}
|
858
|
}
|
859
|
for(i=0;i<buf[8];i++){
|
860
|
PrintLog(LOG_INFORMATION,"Tr[%d]Uno=%d,TSno=%d,Dir=%d,StaUpS=%d,StaDnS=%d,Stop=%d\n",i+1,
|
861
|
buf[10+8*i]+buf[9+8*i]*256,buf[12+8*i]+buf[11+8*i]*256,
|
862
|
buf[13+8*i],buf[14+8*i],buf[15+8*i],buf[16+8*i]);
|
863
|
|
864
|
if(buf[14+8*i]!=buf[15+8*i] && buf[16+8*i]==1){//??????stop
|
865
|
PRawCtrl->PutAYc(rtuno,2*(min(buf[14+8*i],buf[15+8*i]))-buf[13+8*i],buf[10+8*i]+buf[9+8*i]*256); //AI??λ??˫????¼???С???????¼???? ֵΪ?????
|
866
|
PRawCtrl->PutAYx(rtuno,2*(min(buf[14+8*i],buf[15+8*i]))-buf[13+8*i],1); //DI??λ??˫????¼???С???????¼???? ֵΪ?Ƿ???????1??????
|
867
|
}
|
868
|
}
|
869
|
return 1;
|
870
|
}
|
871
|
|
872
|
uint8 CZFCasco::RxAtsPlannedTrain(uint8 *buf)
|
873
|
{//ATS ??·?????ɹ?????????һ?Σ??ƻ??б䶯ATS???????͵???ƻ???Ϣ
|
874
|
PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS PlannedTrain TableID%d Tripcnt=%d TrainId%d%d DesID=%d\n",
|
875
|
buf[6],buf[7],buf[11]+buf[10]*256,buf[12],buf[14]+buf[13]*256,buf[16]+buf[15]*256,buf[18]+buf[17]*256);
|
876
|
int num=0;
|
877
|
/* for(int j=0;j<buf[12];j++)//CASCOǰH??L ?ó?????ĵ??̸???
|
878
|
{
|
879
|
for(int i=0;i<buf[20+num]+buf[19+num]*256;i++)//CASCOǰH??L ?õ??̾??????ٸ?վ
|
880
|
PrintLog(LOG_INFORMATION,"Rec[%d]StaId=%d,PlatId=%d,aTime=%02x%02x%02x%02x,dTime=%02x%02x%02x%02x,flag%d\n",
|
881
|
buf[20+num]+buf[19+num]*256,
|
882
|
buf[21+16*i],buf[23+16*i]+buf[22+16*i]*256,buf[24+16*i],buf[25+16*i],buf[26+16*i],buf[27+16*i],
|
883
|
buf[28+16*i],buf[29+16*i],buf[30+16*i],buf[31+16*i],buf[32+16*i]);
|
884
|
num+=8+(buf[12+8+num]+buf[12+8+num-1]*256)*16;
|
885
|
}
|
886
|
*/
|
887
|
return 1;
|
888
|
}
|
889
|
|
890
|
uint8 CZFCasco::RxAtsPracticalTrain(uint8 *buf)
|
891
|
{//ATS ʵ???г???????Ϣ??ISCS???跢??????ATSӦ??
|
892
|
PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS PracticalTrain GroupID%d Reccnt=%d\n",
|
893
|
buf[6],buf[7],buf[11]+buf[10]*256,buf[13]+buf[12]*256);
|
894
|
/* for(int i=0;i<buf[13]+buf[12]*256;i++)//CASCOǰH??L
|
895
|
PrintLog(LOG_INFORMATION,"StaId=%d,PlatId=%d,aTime=%02x%02x%02x%02x,dTime=%02x%02x%02x%02x,flag%d,TrainId%d-%d,TableId%d,DesId%d,Type%d\n",
|
896
|
buf[14+25*i],buf[16+25*i]+buf[15+25*i]*256,buf[17+25*i],buf[18+25*i],buf[19+25*i],buf[20+25*i],
|
897
|
buf[21+25*i],buf[22+25*i],buf[23+25*i],buf[24+25*i],buf[25+25*i],
|
898
|
buf[27+25*i]+buf[26+25*i]*256,buf[29+25*i]+buf[28+25*i]*256,
|
899
|
buf[31+25*i]+buf[30+25*i]*256,buf[33+25*i]+buf[32+25*i]*256,buf[34+25*i]);
|
900
|
*/
|
901
|
|
902
|
return 1;
|
903
|
}
|
904
|
uint8 CZFCasco::RxAtsDynamicTrain(uint8 *buf)
|
905
|
{//ATS Dynamic?г???????Ϣ
|
906
|
PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS DynamicTrain GroupID%d-TrainID%d:%d-SeviceID%d-DesID%d-Dir%d-Type%d-StaID%d-PlatID%d-%c\n",
|
907
|
buf[6],buf[7],buf[9]+buf[8]*256,buf[11]+buf[10]*256,buf[13]+buf[12]*256,buf[15]+buf[14]*256,buf[17]+buf[16]*256
|
908
|
,buf[18],buf[19],buf[20],buf[22]+buf[21]*256,buf[27]);
|
909
|
|
910
|
//13*2 Station Platform//Ԥ??20??վ*2
|
911
|
sint32 rtuno = pLink->GetRtuNo();
|
912
|
switch(buf[27]){//ÿ????վ??2վ̨YC????վ??ʾ?г????GroupID????վ=0
|
913
|
case 'a'://2*(StaID-1)+(Dir-1)//dn-1;up-2
|
914
|
PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],buf[9]+buf[8]*256);
|
915
|
|
916
|
break;
|
917
|
case 'd':
|
918
|
PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],0);
|
919
|
break;
|
920
|
default:
|
921
|
PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],0);
|
922
|
break;
|
923
|
}
|
924
|
|
925
|
if (((buf[22] + buf[21] * 256 == 1) || (buf[22] + buf[21] * 256 == 2)) && buf[20] != 14 && buf[20] != 15 && buf[20] != 36 && buf[20] != 37 && buf[20] != 39) {
|
926
|
PrintLog(LOG_INFORMATION, "ip:%s port:%d \n",redisip,redisport);
|
927
|
|
928
|
this->m_popt_train = new CTrainDataOpt;
|
929
|
this->m_popt_train->SetSeverAddr(redisip, redisport);
|
930
|
TrainsInfo redisdata;
|
931
|
memset(&redisdata, 0, sizeof(TrainsInfo));
|
932
|
switch (buf[20]) {
|
933
|
case 1:strcpy(redisdata.group, "ELZ"); break;
|
934
|
case 2:strcpy(redisdata.group, "ZJJ"); break;
|
935
|
case 3:strcpy(redisdata.group, "DSH"); break;
|
936
|
case 4:strcpy(redisdata.group, "CYR"); break;
|
937
|
case 5:strcpy(redisdata.group, "QPS"); break;
|
938
|
case 6:strcpy(redisdata.group, "HJR"); break;
|
939
|
case 7:strcpy(redisdata.group, "ZXS"); break;
|
940
|
case 8:strcpy(redisdata.group, "JSR"); break;
|
941
|
case 9:strcpy(redisdata.group, "NXJ"); break;
|
942
|
case 10:strcpy(redisdata.group, "XYR"); break;
|
943
|
case 11:strcpy(redisdata.group, "PLR"); break;
|
944
|
case 12:strcpy(redisdata.group, "NBL"); break;
|
945
|
case 13:strcpy(redisdata.group, "HQS"); break;
|
946
|
// case 14:strcpy(redisdata.group, "ZJJD"); break;
|
947
|
// case 15:strcpy(redisdata.group, "XJD"); break;
|
948
|
case 16:strcpy(redisdata.group, "XCZ"); break;
|
949
|
// case 36:strcpy(redisdata.group, "ZJJD_TT"); break;
|
950
|
// case 37:strcpy(redisdata.group, "ZJJD_TT"); break;
|
951
|
// case 39:strcpy(redisdata.group, "XJD_TT"); break;
|
952
|
default:
|
953
|
strcpy(redisdata.group, "");
|
954
|
break;
|
955
|
}
|
956
|
switch (buf[17] + buf[16] * 256) {
|
957
|
case 1:strcpy(redisdata.groupend, "ELZ"); break;
|
958
|
case 11:strcpy(redisdata.groupend, "ELZ"); break;
|
959
|
case 91:strcpy(redisdata.groupend, "ELZ"); break;
|
960
|
|
961
|
case 2:strcpy(redisdata.groupend, "ZJJ"); break;
|
962
|
case 62:strcpy(redisdata.groupend, "ZJJ"); break;
|
963
|
case 61:strcpy(redisdata.groupend, "ZJJ"); break;
|
964
|
case 70:strcpy(redisdata.groupend, "ZJJ"); break;
|
965
|
case 71:strcpy(redisdata.groupend, "ZJJ"); break;
|
966
|
|
967
|
case 3:strcpy(redisdata.groupend, "DSH"); break;
|
968
|
case 63:strcpy(redisdata.groupend, "DSH"); break;
|
969
|
|
970
|
case 64:strcpy(redisdata.groupend, "HJR"); break;
|
971
|
case 65:strcpy(redisdata.groupend, "HJR"); break;
|
972
|
case 66:strcpy(redisdata.groupend, "HJR"); break;
|
973
|
case 80:strcpy(redisdata.groupend, "HJR"); break;
|
974
|
case 81:strcpy(redisdata.groupend, "HJR"); break;
|
975
|
|
976
|
case 7:strcpy(redisdata.groupend, "ZXS"); break;
|
977
|
case 67:strcpy(redisdata.groupend, "ZXS"); break;
|
978
|
|
979
|
case 9:strcpy(redisdata.groupend, "NXJ"); break;
|
980
|
case 88:strcpy(redisdata.groupend, "NXJ"); break;
|
981
|
case 68:strcpy(redisdata.groupend, "NXJ"); break;
|
982
|
case 72:strcpy(redisdata.groupend, "NXJ"); break;
|
983
|
case 73:strcpy(redisdata.groupend, "NXJ"); break;
|
984
|
|
985
|
case 12:strcpy(redisdata.groupend, "NBL"); break;
|
986
|
case 69:strcpy(redisdata.groupend, "NBL"); break;
|
987
|
|
988
|
case 13:strcpy(redisdata.groupend, "HQS"); break;
|
989
|
case 14:strcpy(redisdata.groupend, "HQS"); break;
|
990
|
|
991
|
case 60:strcpy(redisdata.groupend, "XCZ"); break;
|
992
|
|
993
|
default:
|
994
|
strcpy(redisdata.groupend, "");
|
995
|
break;
|
996
|
}
|
997
|
redisdata.trainsno = buf[9] + buf[8] * 256;
|
998
|
redisdata.srvno = buf[15] + buf[14] * 256; //?????
|
999
|
redisdata.direction = 0;
|
1000
|
if (buf[18] == 1) redisdata.direction = 2;
|
1001
|
if (buf[18] == 2) redisdata.direction = 1;
|
1002
|
// redisdata.direction = 2 - buf[18];
|
1003
|
if (buf[27] == 0x61) {
|
1004
|
redisdata.state = 1;
|
1005
|
redisdata.arrivet = buf[23] * 256 * 256 * 256 + buf[24] * 256 * 256 + buf[25] * 256 + buf[26];
|
1006
|
redisdata.departuret = 0;
|
1007
|
}
|
1008
|
if (buf[27] == 0x64) {
|
1009
|
redisdata.state = 2;
|
1010
|
redisdata.arrivet = 0;
|
1011
|
redisdata.departuret = buf[23] * 256 * 256 * 256 + buf[24] * 256 * 256 + buf[25] * 256 + buf[26];
|
1012
|
}
|
1013
|
redisdata.platlocation = (buf[22] + buf[21] * 256) - 1;
|
1014
|
redisdata.jumpsta = 0;
|
1015
|
|
1016
|
int redisflag = this->m_popt_train->PutTrainsInfo(redisdata);
|
1017
|
if (redisflag == 0) PrintLog(LOG_ERROR, "?ǵ????ݴ???redisʧ??\n");
|
1018
|
if (redisflag == 1) PrintLog(LOG_INFORMATION, "?ǵ????ݴ???redis?ɹ?\n");
|
1019
|
if (redisflag == 2) PrintLog(LOG_ERROR, "?????˼ǵ????ݣ????ڷ???δ֪\n");
|
1020
|
if (redisflag == -1) PrintLog(LOG_ERROR, "redis????ʧ??\n");
|
1021
|
delete this->m_popt_train;
|
1022
|
this->m_popt_train = NULL;
|
1023
|
}
|
1024
|
|
1025
|
|
1026
|
|
1027
|
return 1;
|
1028
|
}
|
1029
|
|
1030
|
#ifdef __unix
|
1031
|
extern "C" CProtocol* CreateProtocol(char *defpara)
|
1032
|
#else
|
1033
|
extern "C" __declspec(dllexport) CProtocol* CreateProtocol(char *defpara)
|
1034
|
#endif
|
1035
|
{
|
1036
|
CProtocol *pEpv = new CZFCasco;
|
1037
|
return pEpv;
|
1038
|
}
|
1039
|
|
1040
|
/*
|
1041
|
From To MessageID MsgID Content
|
1042
|
ATS ISCS TrainLocation 0x1001 1+12n
|
1043
|
ATS ISCS BlockInfo 0x1002 1+8n
|
1044
|
ATS ISCS PlannedTrainData 0x1003 5+n*(8+16m)
|
1045
|
ATS ISCS PracticalTrainData 0x1004 6+25n
|
1046
|
ATS ISCS DynamicTrainData 0x1005
|
1047
|
ATS ISCS DataStart 0x1101 2
|
1048
|
ATS ISCS DataContent 0x1102
|
1049
|
ATS ISCS DataEnd 0x1103 2
|
1050
|
ISCS ATS RequestPlannedTrainData 0x2002 2
|
1051
|
ISCS ATS RequestPracticalTrainData 0x2003 2
|
1052
|
ISCS ATS FASinfo 0x2004 1+StaNums*2
|
1053
|
ISCS ATS SCADAinfo 0x2005 2+14*4
|
1054
|
ISCS ATS BASinfo 0x2006 2+4n
|
1055
|
ATS/ISCS ISCS/ATS MessagePolling 0x3001
|
1056
|
|
1057
|
*/
|