1
|
|
2
|
#if defined(WIN32)
|
3
|
#include <io.h>
|
4
|
#include "stdafx.h"
|
5
|
#endif
|
6
|
#include <limits.h>
|
7
|
#include <sys/stat.h>
|
8
|
#include <sys/timeb.h>
|
9
|
#include <time.h>
|
10
|
|
11
|
#include "mBim4.h"
|
12
|
#include "se_log.h"
|
13
|
#include "daq/daq_utl.h"
|
14
|
|
15
|
extern CRdbTable DEF_DCDLL RDB_Chan;
|
16
|
|
17
|
unsigned int CRC_16(unsigned char * pSendBuf, unsigned char len)//CRC??????
|
18
|
{
|
19
|
unsigned short wCrc = 0xFFFF;
|
20
|
for(int i=0; i<len;i++)
|
21
|
{
|
22
|
wCrc ^= pSendBuf[i];
|
23
|
for(int j=0; j<8; j++)
|
24
|
{
|
25
|
if(wCrc & 1)
|
26
|
{
|
27
|
wCrc >>= 1;
|
28
|
wCrc ^= 0xA001;
|
29
|
}
|
30
|
else
|
31
|
wCrc >>= 1;
|
32
|
}
|
33
|
}
|
34
|
return wCrc;
|
35
|
}
|
36
|
|
37
|
|
38
|
CMBim::CMBim()
|
39
|
{
|
40
|
#ifdef OS_WIN
|
41
|
m_logger = new Logger("BimS", "mBimS.log");
|
42
|
m_logger->WriteLineSeparator("Create a new class instance. ", 2);
|
43
|
#endif
|
44
|
|
45
|
readIni();
|
46
|
}
|
47
|
|
48
|
CMBim::~CMBim()
|
49
|
{
|
50
|
if (m_iniConfig.rtuConfArray != NULL)
|
51
|
{
|
52
|
delete [] m_iniConfig.rtuConfArray;
|
53
|
}
|
54
|
|
55
|
#ifdef OS_WIN
|
56
|
delete m_logger;
|
57
|
#endif
|
58
|
}
|
59
|
|
60
|
void CMBim::Init( S_PROTOCOLCFG * pcfg )
|
61
|
{
|
62
|
PRawCtrl = pcfg->PRawCtrl;
|
63
|
pRxBuf = pcfg->pRxBuf;
|
64
|
pTxBuf = pcfg->pTxBuf;
|
65
|
pCmdMem = pcfg->pCmdMem;
|
66
|
pRtu = pcfg->pRtu;
|
67
|
pLink = pcfg->pLink;
|
68
|
pTable = pcfg->pTable;
|
69
|
pZfDataCtrl = pcfg->pZfDataCtrl;
|
70
|
|
71
|
sint32 buflen = pRxBuf->GetReadableSize();
|
72
|
pRxBuf->Move(buflen);
|
73
|
buflen = pTxBuf->GetReadableSize();
|
74
|
pTxBuf->Move(buflen);
|
75
|
m_sendData.headP = m_sendData.trailP=m_sendData.databuf;
|
76
|
initStation();
|
77
|
}
|
78
|
|
79
|
void CMBim::initStation()
|
80
|
{
|
81
|
m_flagSendType = 3;
|
82
|
m_nSendFrameNo = 0;
|
83
|
m_nSendSeqNo = 0;
|
84
|
|
85
|
pLink->SetCommStatus(CMST_NORMAL);
|
86
|
}
|
87
|
|
88
|
void CMBim::readIni()
|
89
|
{
|
90
|
memset(&m_iniConfig, 0, sizeof(BimIniConfig));
|
91
|
|
92
|
char *home = getenv("SEROOT");
|
93
|
if (NULL == home)
|
94
|
{
|
95
|
PrintLog(LOG_ERROR, "????????SEROOTδ????");
|
96
|
return;
|
97
|
}
|
98
|
char filename[256] = {0};
|
99
|
#if defined(__unix)
|
100
|
sprintf(filename, "%s%s", home, "/cfg/p104exs.ini");
|
101
|
#else
|
102
|
sprintf(filename, "%s%s", home, "\\cfg\\p104exs.ini");
|
103
|
#endif
|
104
|
|
105
|
CReadConf readconf;
|
106
|
|
107
|
int nValue = readconf.ReadLong("PORT1", "RTUCOUNT", filename, "0");
|
108
|
if (nValue <= 0)
|
109
|
{
|
110
|
PrintLog(LOG_ERROR, "RTU??????????");
|
111
|
return;
|
112
|
}
|
113
|
m_iniConfig.totalRtus = nValue;
|
114
|
// nValue = readconf.ReadLong("PORT1", "PORTNO", filename, "0");
|
115
|
// if (nValue <= 0) {
|
116
|
// PrintLog(LOG_ERROR, "?˿ں???????", sSection);
|
117
|
// return;
|
118
|
// }
|
119
|
// else
|
120
|
// m_iniConfig.portNo = nValue;
|
121
|
|
122
|
uint32 i;
|
123
|
char sSection[6] = {0};
|
124
|
uint32 nRtuCount = m_iniConfig.totalRtus;
|
125
|
m_iniConfig.rtuConfArray = new BimRTUConfig[nRtuCount];
|
126
|
for (i=0; i<nRtuCount; i++)
|
127
|
{
|
128
|
memset(sSection, 0, sizeof(char)*6);
|
129
|
sprintf(sSection, "RTU%d", i+1);
|
130
|
LPBimRTUConfig pRTU = m_iniConfig.rtuConfArray + i;
|
131
|
pRTU->rtuNo = readconf.ReadLong(sSection, "rtuNo", filename, "0");
|
132
|
pRTU->totalYX = readconf.ReadLong(sSection, "yx", filename, "0");
|
133
|
pRTU->totalYC = readconf.ReadLong(sSection, "yc", filename, "0");
|
134
|
|
135
|
pRTU->totalYxBlock = (pRTU->totalYX + DINumberPerBlock - 1) / DINumberPerBlock;
|
136
|
pRTU->totalYcFrame = (pRTU->totalYC + MaxObjPerFrame_DIAI/2 - 1) / (MaxObjPerFrame_DIAI/2);
|
137
|
}
|
138
|
}
|
139
|
|
140
|
//
|
141
|
sint32 CMBim::RxProc()
|
142
|
{
|
143
|
#if 1
|
144
|
if ( (m_flagSendType & 0x3) == 0)
|
145
|
m_flagSendType = 0x3;
|
146
|
|
147
|
sint32 count = RDB_Chan.GetRcdCount();
|
148
|
if( count>DEF_DCV_MAX_CHANNUM )
|
149
|
count = DEF_DCV_MAX_CHANNUM;
|
150
|
S_RDB_Chan * pChan = (S_RDB_Chan * )RDB_Chan.GetRcdAddr(0);
|
151
|
sint32 chanNo = pLink->GetChanNo();
|
152
|
for (int i=0; i<count; i++)
|
153
|
{
|
154
|
if (pChan[i].ChanNo == chanNo)
|
155
|
{
|
156
|
pChan[i].State = EDEV_UP_STATE;
|
157
|
break;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
pLink->RegisterFrm( FRAME_RX_SUC );
|
162
|
// pLink->SetCommStatus(CMST_NORMAL);
|
163
|
return 1;
|
164
|
|
165
|
#else
|
166
|
|
167
|
uint8 buf[256];
|
168
|
|
169
|
sint32 buflen = pRxBuf->GetReadableSize();
|
170
|
if (buflen < RxDataLen)
|
171
|
return 1;
|
172
|
|
173
|
pLink->RegisterFrm( FRAME_RX_SUC );
|
174
|
pLink->SetCommStatus(CMST_NORMAL);
|
175
|
|
176
|
sint32 datalen = 0;
|
177
|
while ( (buflen=pRxBuf->GetReadableSize()) >= RxDataLen)
|
178
|
{
|
179
|
if (buflen > 256)
|
180
|
buflen = 256;
|
181
|
datalen = pRxBuf->Read(buf, buflen, DEF_BUFF_NOMOVE);
|
182
|
if (buf[0] != 0xEB || buf[1] != 0x90)
|
183
|
{
|
184
|
sint32 unuse = 0;
|
185
|
while (unuse < datalen)
|
186
|
{
|
187
|
if (buf[unuse] != 0xEB || buf[unuse+1] != 0x90)
|
188
|
unuse++;
|
189
|
else
|
190
|
break;
|
191
|
}
|
192
|
pRxBuf->Move(unuse);
|
193
|
continue;
|
194
|
}
|
195
|
|
196
|
if (buf[2] != FixSysID_Req)
|
197
|
{
|
198
|
pRxBuf->Move(3);
|
199
|
continue;
|
200
|
}
|
201
|
|
202
|
if (buf[5] != 5 || buf[6] != 0)//?̶?????Ϊ5
|
203
|
{
|
204
|
pRxBuf->Move(3);
|
205
|
continue;
|
206
|
}
|
207
|
|
208
|
if (buf[8] != ReqTypeID_DI && buf[8] != ReqTypeID_AI)
|
209
|
{
|
210
|
pRxBuf->Move(7);
|
211
|
continue;
|
212
|
}
|
213
|
|
214
|
unsigned int crcValue = CRC_16(buf, RxDataLen-2);
|
215
|
if (buf[RxDataLen-2] != (crcValue%0x100) || buf[RxDataLen-1] != (crcValue/0x100))
|
216
|
{
|
217
|
pRxBuf->Move(RxDataLen);
|
218
|
PrintLog(LOG_ERROR, "У???????");
|
219
|
return 0;
|
220
|
}
|
221
|
|
222
|
if (buf[8] == ReqTypeID_DI)//DI
|
223
|
{
|
224
|
setFlagToDI(buf, datalen);
|
225
|
}
|
226
|
else if (buf[8] == ReqTypeID_AI)//AI
|
227
|
{
|
228
|
setFlagToAI(buf, datalen);
|
229
|
}
|
230
|
}
|
231
|
|
232
|
return 1;
|
233
|
#endif
|
234
|
}
|
235
|
|
236
|
//
|
237
|
sint32 CMBim::TxProc()
|
238
|
{
|
239
|
uint16 wLen=pTxBuf->GetWritableSize();
|
240
|
int len = m_sendData.trailP - m_sendData.headP;
|
241
|
if(wLen<=len)
|
242
|
return 0;
|
243
|
if ( (m_flagSendType & 0x1) == 0x1)
|
244
|
{
|
245
|
if (procSendDI() == 1)
|
246
|
return 1;
|
247
|
}
|
248
|
|
249
|
if ( (m_flagSendType & 0x2) == 0x2)
|
250
|
{
|
251
|
if (procSendAI() == 1)
|
252
|
return 1;
|
253
|
}
|
254
|
|
255
|
return 1;
|
256
|
}
|
257
|
|
258
|
// sint32 CMBim::GetNowSecond()
|
259
|
// {
|
260
|
// CSeTime SE_T;
|
261
|
// TCriterionTime tmptime;
|
262
|
// SE_T.GetNow(&tmptime);
|
263
|
// return (sint32)tmptime;
|
264
|
// }
|
265
|
|
266
|
void CMBim::setFlagToDI(uint8 *buf, sint32 buflen)
|
267
|
{
|
268
|
PrintLog(LOG_INFORMATION, "?յ?????DI֡");
|
269
|
m_flagSendType |= 0x1;
|
270
|
pLink->RegisterFrmCode(RAW_CODEDIR_UP, (char *)buf, RxDataLen);
|
271
|
pRxBuf->Move(RxDataLen);
|
272
|
}
|
273
|
|
274
|
void CMBim::setFlagToAI(uint8 *buf, sint32 buflen)
|
275
|
{
|
276
|
PrintLog(LOG_INFORMATION, "?յ?????AI֡");
|
277
|
m_flagSendType |= 0x2;
|
278
|
pLink->RegisterFrmCode(RAW_CODEDIR_UP, (char *)buf, RxDataLen);
|
279
|
pRxBuf->Move(RxDataLen);
|
280
|
}
|
281
|
|
282
|
void CMBim::appToLink()
|
283
|
{
|
284
|
BYTE * p = m_sendData.databuf;
|
285
|
int len = m_sendData.trailP - m_sendData.headP;
|
286
|
|
287
|
unsigned int crcValue = CRC_16(p, len);
|
288
|
*m_sendData.trailP++ = crcValue % 0x100;
|
289
|
*m_sendData.trailP++ = crcValue / 0x100;
|
290
|
|
291
|
len = m_sendData.trailP - m_sendData.headP;
|
292
|
/*
|
293
|
#ifdef OS_WIN
|
294
|
if (m_logger->IfLogData()) {
|
295
|
TCHAR strLog[MaxCodeLen] = {0};
|
296
|
_stprintf(strLog, _T("???ͱ???(?ֽ??? %d) :\n"), len);
|
297
|
sint32 i;
|
298
|
for (i=0; i<len; i++)
|
299
|
{
|
300
|
TCHAR tmpStr[5] = {0};
|
301
|
if ( (i+1)/32 > 0 && (i+1)%32 == 0)
|
302
|
_stprintf(tmpStr, _T("%02X \n"), *(p+i));
|
303
|
else
|
304
|
_stprintf(tmpStr, _T("%02X "), *(p+i));
|
305
|
|
306
|
if ( _tcslen(strLog) + _tcslen(tmpStr) > MaxCodeLen-1) {
|
307
|
m_logger->WriteFmtStrWithTime_L3(strLog);
|
308
|
memset(strLog, 0, sizeof(TCHAR)*MaxCodeLen);
|
309
|
}
|
310
|
_tcscat(strLog, tmpStr);
|
311
|
}
|
312
|
m_logger->WriteFmtStrWithTime_L3(strLog);
|
313
|
}
|
314
|
#endif*/
|
315
|
int txMaxLen=TxDataMaxLen;
|
316
|
if(16*1024<TxDataMaxLen)txMaxLen=16*1024;
|
317
|
// pLink->RegisterFrmCode(RAW_CODEDIR_DOWN, (char *)p, len);
|
318
|
uint16 wLen=pTxBuf->GetWritableSize();//WYF 20190526
|
319
|
if(wLen>=len){
|
320
|
// if(len>txMaxLen-1100)
|
321
|
{
|
322
|
pTxBuf->Write(p, len);
|
323
|
m_sendData.headP = m_sendData.trailP=m_sendData.databuf;
|
324
|
}
|
325
|
}
|
326
|
else{
|
327
|
// m_sendData.headP = m_sendData.trailP=m_sendData.databuf;
|
328
|
PrintLog(LOG_ERROR, "TxBuffʣ??%d??ʵ???跢??%d",wLen,len);
|
329
|
return;
|
330
|
}
|
331
|
// pLink->SetCommStatus(CMST_NORMAL);
|
332
|
|
333
|
pLink->RegisterFrm( FRAME_TX_SUC );
|
334
|
|
335
|
return;
|
336
|
}
|
337
|
|
338
|
// index base 0
|
339
|
sint32 CMBim::procSendDI()
|
340
|
{
|
341
|
if (NULL == m_iniConfig.rtuConfArray)
|
342
|
{
|
343
|
PrintLog(LOG_ERROR, "RTUδ????");
|
344
|
m_flagSendType &= 0xFE;
|
345
|
m_nSendFrameNo = 0;
|
346
|
return 0;
|
347
|
}
|
348
|
|
349
|
// get start RTU
|
350
|
uint32 nRtuNo = 0;
|
351
|
uint32 nCalcFrames = 0; // total frames have been sent (not include current RTU)
|
352
|
uint32 nTotalFramesRTU = 0; // total frames of current RTU
|
353
|
uint32 nInfoAddrStart = 0; // start address of current frame (:= 0~0xFFFFFF)
|
354
|
LPBimRTUConfig pRtu = NULL;
|
355
|
bool bFinishedCycle =false;
|
356
|
while ( nRtuNo < m_iniConfig.totalRtus)
|
357
|
{
|
358
|
pRtu = m_iniConfig.rtuConfArray + nRtuNo;
|
359
|
nTotalFramesRTU = (pRtu->totalYxBlock + MaxObjPerFrame_DIAI - 1) / MaxObjPerFrame_DIAI;
|
360
|
if (m_nSendFrameNo < nCalcFrames + nTotalFramesRTU)//SendFrameNo : index base from 0
|
361
|
break;
|
362
|
nCalcFrames += nTotalFramesRTU;
|
363
|
nInfoAddrStart += (pRtu->totalYxBlock * 2);
|
364
|
nRtuNo++;
|
365
|
}
|
366
|
if (nRtuNo >= m_iniConfig.totalRtus || NULL == pRtu)
|
367
|
{
|
368
|
PrintLog(LOG_ERROR, "RTU?????????????????????ļ?????ǰRTU %d", nRtuNo+1);
|
369
|
m_flagSendType &= 0xFE;
|
370
|
m_nSendFrameNo = 0;
|
371
|
return 0;
|
372
|
}
|
373
|
|
374
|
uint32 nRtuFrameNo = m_nSendFrameNo - nCalcFrames; // frame number of current RTU
|
375
|
nInfoAddrStart += (MaxObjPerFrame_DIAI * nRtuFrameNo*2);//wyf 2018
|
376
|
uint32 nRtuPointStart = (MaxObjPerFrame_DIAI * DINumberPerBlock) * nRtuFrameNo; // get from which DI start
|
377
|
|
378
|
#ifdef OS_WIN
|
379
|
if (m_nSendFrameNo == 0) {
|
380
|
m_SendData_TimeBegin = m_SendTypeData_TimeBegin = GetTickCount();
|
381
|
// m_logger->WriteFmtStrWithTime_L2("Begin to send DI, time : %ums", m_SendTypeData_TimeBegin);
|
382
|
}
|
383
|
#endif
|
384
|
|
385
|
// re-calculate max DI
|
386
|
uint32 nRetPoint = pRtu->totalYX - nRtuPointStart;
|
387
|
uint32 nMaxPoint = (MaxObjPerFrame_DIAI * DINumberPerBlock); // max DI of current frame
|
388
|
nMaxPoint = nRetPoint < nMaxPoint ? nRetPoint : nMaxPoint;
|
389
|
|
390
|
// save DI into buffer
|
391
|
uint8 buf[1024] = {0};
|
392
|
uint32 byteIndex, bitIndex;
|
393
|
uint32 i;
|
394
|
for (i=0; i<nMaxPoint; i++)
|
395
|
{
|
396
|
byteIndex = i/DINumberPerBlock * 2 + i%DINumberPerBlock / 8;
|
397
|
bitIndex = i % 8;
|
398
|
|
399
|
uint8 btVal = 0;
|
400
|
PRawCtrl->GetAYx(pRtu->rtuNo, nRtuPointStart+i, &btVal);
|
401
|
if (btVal == 1)
|
402
|
buf[byteIndex] |= (1 << bitIndex);
|
403
|
}
|
404
|
|
405
|
// DATA_HEAD
|
406
|
DATA_HEAD dataHead;
|
407
|
dataHead.HeadLo = 0xEB;
|
408
|
dataHead.HeadHi = 0x90;
|
409
|
dataHead.SysID = FixSysID_Ans;
|
410
|
dataHead.PacketNoLo = m_nSendSeqNo % 256;
|
411
|
dataHead.PacketNoHi = m_nSendSeqNo / 256;
|
412
|
|
413
|
uint16 nBlock = (nMaxPoint+DINumberPerBlock-1) / DINumberPerBlock;
|
414
|
uint16 framelen = nBlock * 2 + 8;
|
415
|
dataHead.LenLo = framelen % 256;
|
416
|
dataHead.LenHi = framelen / 256;
|
417
|
|
418
|
bFinishedCycle = false;
|
419
|
if ( (nRtuNo >= m_iniConfig.totalRtus-1) && (nRtuFrameNo >= nTotalFramesRTU-1) )
|
420
|
bFinishedCycle = true;
|
421
|
if (bFinishedCycle)
|
422
|
dataHead.MultiFlag = 0;
|
423
|
else
|
424
|
dataHead.MultiFlag = 1;
|
425
|
|
426
|
dataHead.MsgID = ReqTypeID_DI;
|
427
|
|
428
|
//
|
429
|
uint8 *ptr = m_sendData.trailP;//m_sendData.databuf+;
|
430
|
// m_sendData.headP = m_sendData.trailP = ptr;
|
431
|
|
432
|
memcpy(ptr, (BYTE *)&dataHead, DataHeadLen);
|
433
|
ptr += DataHeadLen;
|
434
|
|
435
|
// uint32 nMaxCount = nBlock * DINumberPerBlock;
|
436
|
uint32 nMaxCount = nMaxPoint;
|
437
|
*ptr++ = nMaxCount & 0xFF;
|
438
|
*ptr++ = (nMaxCount >> 8) & 0xFF;
|
439
|
*ptr++ = (nMaxCount >> 16) & 0xFF;
|
440
|
|
441
|
*ptr++ = nInfoAddrStart & 0xFF;
|
442
|
*ptr++ = (nInfoAddrStart >> 8) & 0xFF;
|
443
|
*ptr++ = (nInfoAddrStart >> 16) & 0xFF;
|
444
|
|
445
|
memcpy(ptr, (BYTE *)buf, nBlock*2);
|
446
|
ptr += nBlock * 2;
|
447
|
m_sendData.trailP = ptr;
|
448
|
|
449
|
PrintLog(LOG_INFORMATION, "????DI??Ӧ֡");
|
450
|
appToLink();
|
451
|
m_nSendSeqNo = (m_nSendSeqNo + 1) % 0xFFFF;
|
452
|
|
453
|
if (bFinishedCycle)
|
454
|
{
|
455
|
m_flagSendType &= 0xFE;
|
456
|
m_nSendFrameNo = 0;
|
457
|
#ifdef OS_WIN
|
458
|
DWORD curTick = GetTickCount();
|
459
|
m_logger->WriteFmtStrWithTime_L2(_T("ң?? ??????ϣ???ʱ: %us(%ums)"), (curTick-m_SendTypeData_TimeBegin)/1000, curTick-m_SendTypeData_TimeBegin);
|
460
|
m_SendTypeData_TimeBegin = 0;
|
461
|
#endif
|
462
|
}
|
463
|
else
|
464
|
m_nSendFrameNo++;
|
465
|
return 1;
|
466
|
}
|
467
|
|
468
|
sint32 CMBim::procSendAI()
|
469
|
{
|
470
|
if (NULL == m_iniConfig.rtuConfArray)
|
471
|
{
|
472
|
PrintLog(LOG_ERROR, "RTUδ????");
|
473
|
m_flagSendType &= 0xFD;
|
474
|
m_nSendFrameNo = 0;
|
475
|
return 0;
|
476
|
}
|
477
|
|
478
|
// get start RTU
|
479
|
uint32 nRtuNo = 0;
|
480
|
uint32 nCalcFrames = 0; // total frames have been sent (not include current RTU)
|
481
|
uint32 nTotalFramesRTU = 0; // total frames of current RTU
|
482
|
uint32 nInfoAddrStart = 0; // start address of current frame (:= 0~0xFFFFFF)
|
483
|
LPBimRTUConfig pRtu = NULL;
|
484
|
bool bFinishedCycle =false;
|
485
|
while (nRtuNo < m_iniConfig.totalRtus)
|
486
|
{
|
487
|
pRtu = m_iniConfig.rtuConfArray + nRtuNo;
|
488
|
nTotalFramesRTU = pRtu->totalYcFrame;
|
489
|
if (m_nSendFrameNo < nCalcFrames + nTotalFramesRTU)//SendFrameNo : index base from 0
|
490
|
break;
|
491
|
nCalcFrames += nTotalFramesRTU;
|
492
|
nInfoAddrStart += pRtu->totalYC;
|
493
|
nRtuNo++;
|
494
|
}
|
495
|
if (nRtuNo >= m_iniConfig.totalRtus || NULL == pRtu)
|
496
|
{
|
497
|
PrintLog(LOG_ERROR, "AI?㳬?????????????ļ?????ǰRTU %d", nRtuNo+1);
|
498
|
m_flagSendType &= 0xFD;
|
499
|
m_nSendFrameNo = 0;
|
500
|
return 0;
|
501
|
}
|
502
|
|
503
|
uint32 nRtuFrameNo = m_nSendFrameNo - nCalcFrames; // frame number of current RTU
|
504
|
nInfoAddrStart += MaxObjPerFrame_DIAI/2 * nRtuFrameNo;
|
505
|
uint32 nMaxPoint = MaxObjPerFrame_DIAI/2; // max DI of current frame
|
506
|
uint32 nRtuPointStart = nMaxPoint * nRtuFrameNo; // get from which DI start
|
507
|
|
508
|
#ifdef OS_WIN
|
509
|
if (m_nSendFrameNo == 0) {
|
510
|
m_SendTypeData_TimeBegin = GetTickCount();
|
511
|
// m_logger->WriteFmtStrWithTime_L2("Begin to send AI, time : %ums", m_SendTypeData_TimeBegin);
|
512
|
}
|
513
|
#endif
|
514
|
|
515
|
// re-calculate max DI
|
516
|
uint32 nRetPoint = pRtu->totalYC - nRtuPointStart;
|
517
|
nMaxPoint = nRetPoint < nMaxPoint ? nRetPoint : nMaxPoint;
|
518
|
|
519
|
// save DI into buffer
|
520
|
uint8 buf[1024] = {0};
|
521
|
uint32 byteIndex;
|
522
|
uint32 i;
|
523
|
if(pRtu->rtuNo==18 && nRtuPointStart<2)//test
|
524
|
nRtuPointStart=nRtuPointStart;//test
|
525
|
for (i=0; i<nMaxPoint; i++)
|
526
|
{
|
527
|
byteIndex = i*2*2;
|
528
|
|
529
|
float32 fVal = 0.0f;
|
530
|
PRawCtrl->GetAYc(pRtu->rtuNo, nRtuPointStart+i, &fVal);
|
531
|
uint8 *tmp=(uint8 *)&fVal;
|
532
|
buf[byteIndex] = *tmp;
|
533
|
buf[byteIndex+1] = *(tmp+1);
|
534
|
buf[byteIndex+2] = *(tmp+2);
|
535
|
buf[byteIndex+3] = *(tmp+3);
|
536
|
}
|
537
|
|
538
|
// DATA_HEAD
|
539
|
DATA_HEAD dataHead;
|
540
|
dataHead.HeadLo = 0xEB;
|
541
|
dataHead.HeadHi = 0x90;
|
542
|
dataHead.SysID = FixSysID_Ans;
|
543
|
dataHead.PacketNoLo = m_nSendSeqNo % 256;
|
544
|
dataHead.PacketNoHi = m_nSendSeqNo / 256;
|
545
|
|
546
|
uint16 framelen = nMaxPoint * 2*2 + 8;
|
547
|
dataHead.LenLo = framelen % 256;
|
548
|
dataHead.LenHi = framelen / 256;
|
549
|
|
550
|
bFinishedCycle = false;
|
551
|
if ( (nRtuNo >= m_iniConfig.totalRtus-1) && (nRtuFrameNo >= nTotalFramesRTU-1) )
|
552
|
bFinishedCycle = true;
|
553
|
if (bFinishedCycle)
|
554
|
dataHead.MultiFlag = 0;
|
555
|
else
|
556
|
dataHead.MultiFlag = 1;
|
557
|
|
558
|
dataHead.MsgID = ReqTypeID_AI;
|
559
|
|
560
|
//
|
561
|
uint8 *ptr = m_sendData.trailP;//m_sendData.databuf;
|
562
|
// m_sendData.headP = m_sendData.trailP = ptr;
|
563
|
|
564
|
memcpy(ptr, (BYTE *)&dataHead, DataHeadLen);
|
565
|
ptr += DataHeadLen;
|
566
|
|
567
|
*ptr++ = nMaxPoint & 0xFF;
|
568
|
*ptr++ = (nMaxPoint >> 8) & 0xFF;
|
569
|
*ptr++ = (nMaxPoint >> 16) & 0xFF;
|
570
|
|
571
|
*ptr++ = nInfoAddrStart & 0xFF;
|
572
|
*ptr++ = (nInfoAddrStart >> 8) & 0xFF;
|
573
|
*ptr++ = (nInfoAddrStart >> 16) & 0xFF;
|
574
|
|
575
|
memcpy(ptr, (BYTE *)buf, nMaxPoint*2*2);
|
576
|
ptr += nMaxPoint * 2*2;
|
577
|
m_sendData.trailP = ptr;
|
578
|
|
579
|
PrintLog(LOG_INFORMATION, "????AI??Ӧ֡");
|
580
|
appToLink();
|
581
|
m_nSendSeqNo = (m_nSendSeqNo + 1) % 0xFFFF;
|
582
|
|
583
|
if (bFinishedCycle)
|
584
|
{
|
585
|
m_flagSendType &= 0xFD;
|
586
|
m_nSendFrameNo = 0;
|
587
|
#ifdef OS_WIN
|
588
|
DWORD curTick = GetTickCount();
|
589
|
m_logger->WriteFmtStrWithTime_L2(_T("ң?? ??????ϣ???ʱ: %us(%ums)"), (curTick-m_SendTypeData_TimeBegin)/1000, curTick-m_SendTypeData_TimeBegin);
|
590
|
m_logger->WriteFmtStrWithTime_L2(_T("???? ???? ??????ϣ???ʱ: %us(%ums)"), (curTick-m_SendData_TimeBegin)/1000, curTick-m_SendData_TimeBegin);
|
591
|
if (curTick-m_SendData_TimeBegin > 2000)
|
592
|
m_logger->WriteFmtStrWithTime_L2(_T("\n???η??????? ??ʱ????2s\n"));
|
593
|
m_SendData_TimeBegin = m_SendTypeData_TimeBegin = 0;
|
594
|
#endif
|
595
|
}
|
596
|
else
|
597
|
m_nSendFrameNo++;
|
598
|
return 1;
|
599
|
}
|
600
|
|
601
|
|
602
|
////////////////////////////////////////////////////////////////
|
603
|
#if defined(WIN32)
|
604
|
extern "C" __declspec(dllexport)
|
605
|
#else
|
606
|
extern "C"
|
607
|
#endif
|
608
|
CProtocol *CreateProtocol(char *defpara)
|
609
|
{
|
610
|
return (CProtocol*)(new CMBim());
|
611
|
}
|