-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaCountDown.cpp
834 lines (746 loc) · 28.9 KB
/
GaCountDown.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
//
// Created by sylar on 24-12-24.
//
#include "GaCountDown.h"
#include "Rs485.h"
#include "ManaKernel.h"
#include "Dbinstance.h"
#include "string.h"
#define SEND_CLIENT_CNTOWN_BYTES 43 //(旧国标GAT508-2004 8个方向)
#define GANEW_MAX_DIRECT 4 //北东南西
#define GANEW_MAX_LANE 8 //左,直,右,人行 ,二次人行 ,调头 ,其他 ,特殊(左直右)
#define GANEW_CHKDATA_INDEX 67 //校验字节下标
#define GANEW_FRAMEHEAD_INDEX0 0 //帧头地址下标0
#define GANEW_FRAMEHEAD_INDEX1 1 //帧头地址下标1
#define GANEW_CNTDEVNUM_INDEX 2 //倒计时数量地址下标
/**************************************************************
Function: CGaCountDown::CGaCountDown
Description: CGaCountDown,用于倒计时类初始化处理
Input: 无
Output: 无
Return: 无
***************************************************************/
CGaCountDown::CGaCountDown()
{
ACE_OS::memset(m_sGaSendBuf , 0 , GA_MAX_SEND_BUF );
ACE_OS::memset(m_ucLampBoardFlashBreak, 0x0 , MAX_LAMP_BOARD);
ACE_OS::memset(m_newGbCntDownDevTime, 0x0 , MAX_CNTDOWNDEV*sizeof(SNewGBCntDownTimeInfo));
m_newsGaSendBuf[0]= 0x55; //新国标帧头
m_newsGaSendBuf[1]= 0xAA; //新国标帧头
m_newsGaSendBuf[2]= MAX_CNTDOWNDEV; //最大倒计时数32
m_newsGaSendBuf4D[0]= 0x55; //新国标帧头
m_newsGaSendBuf4D[1]= 0xAA; //新国标帧头
m_newsGaSendBuf4D[2]= 0x4; //最大倒计时数4 北东南西 地址 0 1 2 3
for(Byte index = 0 ;index<MAX_CLIENT_NUM ; index++)
{
sSendCDN[index].bSend = false ;
sSendCDN[index].bUsed = false ;
}
ACE_DEBUG((LM_DEBUG,"%s:%d Init GaCountDown object ok !\n",__FILE__,__LINE__));
}
/**************************************************************
Function: CGaCountDown::~CGaCountDown
Description: CGaCountDown类 析构函数
Input: 无
Output: 无
Return: 无
***************************************************************/
CGaCountDown::~CGaCountDown()
{
ACE_DEBUG((LM_DEBUG,"%s:%d Destruct GaCountDown object ok !\n",__FILE__,__LINE__));
}
/**************************************************************
Function: CGaCountDown::CreateInstance
Description: 创建CGaCountDown静态对象
Input: 无
Output: 无
Return: 静态对象指针
***************************************************************/
CGaCountDown* CGaCountDown::CreateInstance()
{
static CGaCountDown oGaCountDown;
return &oGaCountDown;
}
/**************************************************************
Function: CGaCountDown::GaGetCntDownInfo
Description: 判断各个方向/属性(左、直、右与人行)是否需要倒计时
以及计算对应的倒计时秒数和灯色信息
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown::GaGetCntDownInfo()
{
CManaKernel* pCWorkParaManager = CManaKernel::CreateInstance();
STscRunData* pRunData = pCWorkParaManager->m_pRunData;
STscConfig * pConfig = pCWorkParaManager->m_pTscConfig;
Byte ucCurStep = pRunData->ucStepNo;
SStepInfo*pStepInfo = pRunData->sStageStepInfo + ucCurStep;
bool bIsAllowPhase = false;
Byte ucPhaseId = 0;
Byte ucSignalGrpNum = 0;
Byte ucLightLamp = 0;
Byte ucDirIndex = 0;
Byte ucLaneIndex = 0;
Byte ucSignalGrp[MAX_CHANNEL] = {0};
for ( ucDirIndex=0; ucDirIndex<GA_MAX_DIRECT-4; ucDirIndex++ )
{
for ( ucLaneIndex=0; ucLaneIndex<GA_MAX_LANE; ucLaneIndex++ )
{
if(m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucOverlapPhase == 0 &&
m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucPhase == 0)
{
m_bGaNeedCntDown[ucDirIndex][ucLaneIndex] = false;
continue ;
}
else if ( m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucOverlapPhase != 0 )
{
ucPhaseId = m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucOverlapPhase;
bIsAllowPhase = false;
}
else if ( m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucPhase != 0 )
{
ucPhaseId = m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucPhase;
bIsAllowPhase = true;
}
//相位类型+相位id-->通道信息(ryg)
ucSignalGrpNum = 0;
pCWorkParaManager->GetSignalGroupId(bIsAllowPhase ,ucPhaseId,&ucSignalGrpNum,ucSignalGrp);
if ( ucSignalGrpNum > 0 ) //相位对应通道个数大于0
{
ucLightLamp = (ucSignalGrp[0] - 1) * 3; //ucLightLamp 通道组号,下面判断当前通道组号亮什么灯。
if ( 1 == pStepInfo->ucLampOn[ucLightLamp] )
{
m_ucGaColor[ucDirIndex][ucLaneIndex] = GANEW_COLOR_RED;
}
else if ( 1 == pStepInfo->ucLampOn[ucLightLamp+1] )
{
m_ucGaColor[ucDirIndex][ucLaneIndex] = GANEW_COLOR_YELLOW;
ucLightLamp = ucLightLamp + 1;
}
else if ( 1 == pStepInfo->ucLampOn[ucLightLamp+2] )
{
m_ucGaColor[ucDirIndex][ucLaneIndex] = GANEW_COLOR_GREEN;
ucLightLamp = ucLightLamp + 2;
}
m_bGaNeedCntDown[ucDirIndex][ucLaneIndex] = true; //相位方向上有放行相位和通道 或者有跟随相位有跟随通道
m_ucGaRuntime[ucDirIndex][ucLaneIndex] = GaGetCntTime(ucLightLamp); //获取剩余时间
if(pConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_FLASHOFF)
{
for(Byte ucIndex = 0;ucIndex < MAX_CNTDOWNDEV;ucIndex++ )
{
if((pConfig->sCntDownDev[ucIndex].usPhase == ucPhaseId )||(pConfig->sCntDownDev[ucIndex].ucOverlapPhase == ucPhaseId ))
{
if(((pConfig->sCntDownDev[ucIndex].ucMode>>3)&0xf) == m_ucGaRuntime[ucDirIndex][ucLaneIndex])
{
pConfig->sCntDownDev[ucIndex].ucMode |= 1<<7 ;
break ;
}
}
}
}
}
else
{
m_bGaNeedCntDown[ucDirIndex][ucLaneIndex] = false;//该方向上无相位无通道则无倒计时,跟随相位无跟随通道则无倒计时
}
}
}
}
/**************************************************************
Function: CGaCountDown::GaSendStepPer
Description: 每一次步伐开始发送一次
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown::GaSendStepPer()
{
Byte CountDonwType = CManaKernel::CreateInstance()->m_pTscConfig->sSpecFun[FUN_COUNT_DOWN].ucValue ;
GaGetCntDownInfo();
if(CountDonwType == COUNTDOWN_GAT5082004 || CountDonwType == COUNTDOWN_GAT5082004V2)
{
GaSetSendBuffer();
for ( Byte iDir=0; iDir<GA_MAX_DIRECT; iDir++ )
{
CRs485::CreateInstance()->Send(m_sGaSendBuf[iDir], GA_MAX_SEND_BUF);
}
}
else if(CountDonwType == COUNTDOWN_GAT5082014)
{
GaSetSendBufferNewGB();
CRs485::CreateInstance()->Send(m_newsGaSendBuf, GANEW_CHKDATA_INDEX+1);
}
else if(CountDonwType == COUNTDOWN_GAT5082014V2)
{
GaSetSendBufferNewGB4Direc();
CRs485::CreateInstance()->Send(m_newsGaSendBuf4D,0xc);
}
for(Byte iClinetDex = 0 ;iClinetDex<MAX_CLIENT_NUM ;iClinetDex++)
{
if(sSendCDN[iClinetDex].bSend== true && sSendCDN[iClinetDex].bUsed == true )
{
Byte SendClientData[SEND_CLIENT_CNTOWN_BYTES] ={0};
SendClientData[0] = 0x84 ; //应答
SendClientData[1] = 0xE6 ;
SendClientData[2] = 0x0 ;
ACE_OS::memcpy((Byte*)SendClientData+3,m_sGaSendBuf,GA_MAX_DIRECT*GA_MAX_SEND_BUF);
(CGbtMsgQueue::CreateInstance()->m_sockLocal).send(SendClientData,SEND_CLIENT_CNTOWN_BYTES,sSendCDN[iClinetDex].addClient);
}
}
}
/**************************************************************
Function: CGaCountDown::GaSetSendBuffer
Description: 构造发送数据
Input: 无
Output: 无
Return: 无
Date: 20150324
***************************************************************/
void CGaCountDown::GaSetSendBuffer()
{
Byte ucColor = GANEW_COLOR_BLACK;
Byte ucCountTime = 0;
for (Byte ucDirIndex=0; ucDirIndex<GA_MAX_DIRECT-4; ucDirIndex++ ) //没有东北 西北 东南西南方向
{
ucColor = GANEW_COLOR_BLACK;
ucCountTime = 0;
//获取某一方向倒计时牌的颜色与秒数
ComputeColorCount(ucDirIndex,ucColor,ucCountTime);
//打包数据
PackSendBuf(ucDirIndex,ucColor,ucCountTime);
}
}
/**************************************************************
Function: CGaCountDown::GaSetSendBufferNewGB4Direc
Description: 构造发送数据新国标4方向
Input: 无
Output: 无
Return: 无
Date: 20150325
***************************************************************/
void CGaCountDown::GaSetSendBufferNewGB4Direc()
{
Byte ucColor = GANEW_COLOR_BLACK;
Byte ucCountTime = 0;
for (Byte ucDirIndex=0; ucDirIndex<GA_MAX_DIRECT-4; ucDirIndex++ ) //没有东北 西北 东南西南方向
{
//获取某一方向倒计时牌的颜色与秒数
ComputeColorCount(ucDirIndex,ucColor,ucCountTime);
//打包数据
PackSendBufNewGB4Direc(ucDirIndex,ucColor,ucCountTime);
}
}
/**************************************************************
Function: CGaCountDown::GaSetSendBufferNewGB
Description: 根据新国标GAT508-2014构造全部倒计时的发送数据
Input: 无
Output: 无
Return: 无
Date: 20150324
***************************************************************/
void CGaCountDown::GaSetSendBufferNewGB()
{
ComputeColorCountNewGB();
PackSendBufNewGB();
}
/**************************************************************
Function: CGaCountDown::ComputeColorCount
Description: 根据方向计算某方向的倒计时颜色和总秒数,不考虑人行
倒计时优先级:有绿倒绿 无绿倒黄 同绿同黄同红倒最小
Input: ucDirIndex-方向(0 1 2 3)
Output: ucColor-颜色(r y g)
ucCountTime-秒数
Return: false-失败 true-成功
***************************************************************/
bool CGaCountDown::ComputeColorCount( Byte ucDirIndex , Byte& ucColor , Byte& ucCountTime )
{
bool bRed = false;
bool bYellow = false;
bool bGreen = false;
Byte ucLaneIndex = 0;
Byte ucMinRedCnt = 254;
Byte ucMinYellowCnt = 254;
Byte ucMinGreenCnt = 254;
STscConfig * pConfig = CManaKernel::CreateInstance()->m_pTscConfig;
if(pConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082004||pConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082014V2)
{
//左 直 右 不算人行
for ( ucLaneIndex=0; ucLaneIndex<GA_MAX_LANE; ucLaneIndex++ )
{
if ( false == m_bGaNeedCntDown[ucDirIndex][ucLaneIndex])
{
continue;
}
if(ucLaneIndex == GA_LANE_FOOT || ucLaneIndex == GA_LANE_SECOND_FOOT)
continue ;
switch ( m_ucGaColor[ucDirIndex][ucLaneIndex] )
{
case GANEW_COLOR_GREEN:
bGreen = true;
if ( ucMinGreenCnt > m_ucGaRuntime[ucDirIndex][ucLaneIndex] )
{
ucMinGreenCnt = m_ucGaRuntime[ucDirIndex][ucLaneIndex];
}
break;
case GANEW_COLOR_YELLOW:
bYellow = true;
if ( ucMinYellowCnt > m_ucGaRuntime[ucDirIndex][ucLaneIndex] )
{
ucMinYellowCnt = m_ucGaRuntime[ucDirIndex][ucLaneIndex];
}
break;
case GANEW_COLOR_RED:
bRed = true;
if ( ucMinRedCnt > m_ucGaRuntime[ucDirIndex][ucLaneIndex] )
{
ucMinRedCnt = m_ucGaRuntime[ucDirIndex][ucLaneIndex];
}
break;
default:
break;
}
}
if ( bGreen ) //绿灯倒计时
{
ucColor = GANEW_COLOR_GREEN;
ucCountTime = ucMinGreenCnt;
}
else if ( bYellow ) //如不倒黄灯 在此处做限制
{
ucColor = GANEW_COLOR_YELLOW;
ucCountTime = ucMinYellowCnt;
}
else if ( bRed )
{
ucColor = GANEW_COLOR_RED;
ucCountTime = ucMinRedCnt;
}
else
{
return false;
}
}
else if(pConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082004V2) //8个地址倒计时
{
Byte CntDownDevPhase = pConfig->sCntDownDev[ucDirIndex].usPhase ;
Byte CntDownDevOverPhase = pConfig->sCntDownDev[ucDirIndex].ucOverlapPhase ;
if((CntDownDevPhase!=0 )||(CntDownDevOverPhase !=0 ))
{
for ( ucDirIndex=0; ucDirIndex<GA_MAX_DIRECT-4; ucDirIndex++ )
{
for ( ucLaneIndex=0; ucLaneIndex<GA_MAX_LANE; ucLaneIndex++ )
{
if(m_bGaNeedCntDown[ucDirIndex][ucLaneIndex]==true)
{
if((CntDownDevPhase==m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucPhase)||
(CntDownDevPhase==m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex].ucOverlapPhase)
)
{
ucColor = m_ucGaColor[ucDirIndex][ucLaneIndex] ;
ucCountTime = m_ucGaRuntime[ucDirIndex][ucLaneIndex];
return true ;
}
}
}
}
return false ;
}
}
return true;
}
/**************************************************************
Function: CGaCountDown::ComputeColorCountNewGB
Description: 根据方向计算某方向的倒计时颜色和总秒数,不考虑人行
倒计时优先级:有绿倒绿 无绿倒黄 同绿同黄同红倒最小
Input: 无
Output: 无
Return: false-失败 true-成功
***************************************************************/
bool CGaCountDown::ComputeColorCountNewGB()
{
Byte CntDownDevAddr = 0 ;
for (Byte ucDirIndex=0; ucDirIndex<GANEW_MAX_DIRECT; ucDirIndex++ ) //没有东北 西北 东南西南方向
{
for(Byte ucLaneIndex = 0 ;ucLaneIndex<GANEW_MAX_LANE; ucLaneIndex++)
{
if ( false == m_bGaNeedCntDown[ucDirIndex][ucLaneIndex] )
{
continue;
}
else
{
CntDownDevAddr = ucDirIndex*GANEW_MAX_LANE+ucLaneIndex ;
m_newGbCntDownDevTime[CntDownDevAddr].CntDownColor = m_ucGaColor[ucDirIndex][ucLaneIndex] ;
m_newGbCntDownDevTime[CntDownDevAddr].CntDownTime = m_ucGaRuntime[ucDirIndex][ucLaneIndex];
//if(ucDirIndex == 0x2 && ucLaneIndex == 0x0)
// {
//ACE_OS::printf("%s:%d CntDownDevAddr=%d color =%d time=%d \r\n",__FILE__,__LINE__,CntDownDevAddr,m_ucGaColor[ucDirIndex][ucLaneIndex],m_ucGaRuntime[ucDirIndex][ucLaneIndex]);
//}
}
}
}
return true;
}
/**************************************************************
Function: CGaCountDown::PackSendBufNewGB
Description: 打包发送的数据(根据GAT508-2014)
Input: 无
Output: 无
Return: false-失败 true-成功
***************************************************************/
bool CGaCountDown::PackSendBufNewGB()
{
m_newsGaSendBuf[GANEW_CHKDATA_INDEX] = MAX_CNTDOWNDEV ;
for(Byte CntDownDevAddr = 0x0 ; CntDownDevAddr <MAX_CNTDOWNDEV ;CntDownDevAddr++)
{
m_newsGaSendBuf[3+2*CntDownDevAddr] = ( m_newGbCntDownDevTime[CntDownDevAddr].CntDownColor)|(0<<2)|(CntDownDevAddr<<3);
m_newsGaSendBuf[3+2*CntDownDevAddr+1] = m_newGbCntDownDevTime[CntDownDevAddr].CntDownTime;
m_newsGaSendBuf[GANEW_CHKDATA_INDEX] ^= (m_newsGaSendBuf[3+2*CntDownDevAddr])^(m_newsGaSendBuf[3+2*CntDownDevAddr+1]);
}
return true;
}
/**************************************************************
Function: CGaCountDown::PackSendBuf
Description: 打包发送的数据
Input: ucDirIndex-方向(0 1 2 3)
Output: ucColor-颜色(0r 1y 2g)
* ucCountTime-秒数
Return: false-失败 true-成功
***************************************************************/
bool CGaCountDown::PackSendBuf( Byte ucDirIndex , Byte ucColor , Byte ucCountTime )
{
Byte ucColorDir = 0;
Byte ucThousand = 0;
Byte ucHundred = 0;
Byte ucTen = 0;
Byte ucEntries = 0;
Byte ucCheckSum = 0;
ACE_OS::memset(m_sGaSendBuf[ucDirIndex] , 0 , GA_MAX_SEND_BUF);
m_sGaSendBuf[ucDirIndex][0] = 0xFE; //帧头
ucColorDir |= ucColor; //D0-D1 表示颜色
ucColorDir |= (ucDirIndex<<2); //D2-D4 表示方向
ucColorDir |= 0x20; //D5位为1 D6-D7扩展
m_sGaSendBuf[ucDirIndex][1] = ucColorDir;
ucThousand = ucCountTime / 1000;
ucHundred = (ucCountTime %1000)/100;
ucTen = ((ucCountTime%1000)%100)/10;
ucEntries = ucCountTime % 10;
m_sGaSendBuf[ucDirIndex][2] |= ucHundred;
m_sGaSendBuf[ucDirIndex][2] |= (ucThousand<<4);
m_sGaSendBuf[ucDirIndex][3] |= ucEntries;
m_sGaSendBuf[ucDirIndex][3] |= (ucTen<<4);
ucCheckSum = 0x7f & (m_sGaSendBuf[ucDirIndex][1] ^ m_sGaSendBuf[ucDirIndex][2] ^ m_sGaSendBuf[ucDirIndex][3]);
m_sGaSendBuf[ucDirIndex][4] = ucCheckSum;
return true;
}
/**************************************************************
Function: CGaCountDown::PackSendBuf
Description: 打包发送的数据
Input: ucDirIndex-方向(0 1 2 3)
Output: ucColor-颜色(0r 1y 2g)
* ucCountTime-秒数
Return: false-失败 true-成功
***************************************************************/
bool CGaCountDown::PackSendBufNewGB4Direc(Byte ucDirIndex , Byte ucColor , Byte ucCountTime )
{
m_newsGaSendBuf4D[3+2*ucDirIndex] = (ucColor)|(0<<2)|(ucDirIndex<<3);
m_newsGaSendBuf4D[3+2*ucDirIndex+1] = ucCountTime ;
if(ucDirIndex == 0x3)
m_newsGaSendBuf4D[11] = 0x4^m_newsGaSendBuf4D[3]^m_newsGaSendBuf4D[4]^m_newsGaSendBuf4D[5]^m_newsGaSendBuf4D[6]^m_newsGaSendBuf4D[7]^m_newsGaSendBuf4D[8]^m_newsGaSendBuf4D[9]^m_newsGaSendBuf4D[10];
return true;
}
/**************************************************************
Function: CGaCountDown::GaGetCntTime
Description: 根据通道获取该通道同一灯色剩余的持续时间
Input: ucSignalId: 通道Id 1-16
Output: 无
Return: 该灯色的剩余时间
***************************************************************/
Byte CGaCountDown::GaGetCntTime(Byte ucSignalId)
{
STscRunData* pRunData = CManaKernel::CreateInstance()->m_pRunData;
Byte ucCurStep = pRunData->ucStepNo;
SStepInfo* pStepInfo = NULL;
Byte ucRuntime = 0;
if ( pRunData->ucStepTime >= pRunData->ucElapseTime )
{
ucRuntime = pRunData->ucStepTime - pRunData->ucElapseTime;
}
else
{
ucRuntime = 0;
}
//其他步伐该灯色还会亮,比如通道的红灯可能会除了通道组绿灯步外其他步伐时候也一直亮
for (int iStep = ((ucCurStep+1) % pRunData->ucStepNum); iStep != ucCurStep;iStep = (iStep + 1) % pRunData->ucStepNum)
{
pStepInfo = pRunData->sStageStepInfo + iStep;
if ( 1 == pStepInfo->ucLampOn[ucSignalId] )
{
ucRuntime += pStepInfo->ucStepLen;
}
else
{
break;
}
}
return ucRuntime;
}
/**************************************************************
Function: CGaCountDown::GaUpdateCntDownCfg
Description: 更新倒计时配置参数 数据库更新时需要调用
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown::GaUpdateCntDownCfg()
{
Byte ucRecordCnt = 0;
Byte ucDirIndex = 0;
Byte ucLaneIndex = 0;
Byte iIndex = 0;
GBT_DB::PhaseToDirec* pPhaseToDirec = NULL;
GBT_DB::TblPhaseToDirec tTblPhaseToDirec;
/******方向与相位对应表******/
(CDbInstance::m_cGbtTscDb).QueryPhaseToDirec(tTblPhaseToDirec);
pPhaseToDirec = tTblPhaseToDirec.GetData(ucRecordCnt);
ACE_OS::memset(m_sGaPhaseToDirec , 0, (GA_MAX_DIRECT*GA_MAX_LANE)*sizeof(GBT_DB::PhaseToDirec));
iIndex = 0;
while ( iIndex < ucRecordCnt )
{
if(pPhaseToDirec[iIndex].ucPhase ==0 && pPhaseToDirec[iIndex].ucOverlapPhase == 0)
{
iIndex++;
continue ;
}
//ACE_DEBUG((LM_DEBUG,"%s:%d Direc=%d phase=%d overlapphase=%d \n",__FILE__,__LINE__,pPhaseToDirec[iIndex].ucId,pPhaseToDirec[iIndex].ucPhase,pPhaseToDirec[iIndex].ucOverlapPhase));
GaGetDirLane(pPhaseToDirec[iIndex].ucId , ucDirIndex , ucLaneIndex );
if ( ucDirIndex < GA_MAX_DIRECT && ucLaneIndex < GA_MAX_LANE )
{
ACE_OS::memcpy(&m_sGaPhaseToDirec[ucDirIndex][ucLaneIndex],&pPhaseToDirec[iIndex],sizeof(GBT_DB::PhaseToDirec));
}
iIndex++;
}
}
/**************************************************************
Function: CGaCountDown::GaUpdateCntDownCfg
Description: 获取方向与转向 如:左 直
Input: ucTableId - 方向与相位表的id
Output: ucDir - 方向
* ucLane - 转向
Return: 无
***************************************************************/
void CGaCountDown::GaGetDirLane(Byte ucTableId , Byte& ucDir , Byte& ucLane)
{
Byte ucDirCfg = (ucTableId >> 5) & 0x07;
Byte ucCrossWalkFlag = (ucTableId >> 3) & 0x03;
Byte ucVelhileFlag = ucTableId & 0x07;
switch ( ucDirCfg )
{
case 0:
ucDir = GA_DIRECT_NORTH; //北
break;
case 2:
ucDir = GA_DIRECT_EAST; //东
break;
case 4:
ucDir = GA_DIRECT_SOUTH; //南
break;
case 6:
ucDir = GA_DIRECT_WEST; //西
break;
case 1:
ucDir = GA_DIRECT_NORTH_EAST ; //
break ;
case 3:
ucDir = GA_DIRECT_SOUTH_EAST ;
break ;
case 5:
ucDir = GA_DIRECT_SOUTH_WEST;
break ;
case 7:
ucDir = GA_DIRECT_NORTH_WEST ;
default:
ucDir = GA_MAX_DIRECT;
break;
}
if ( ucCrossWalkFlag ==1)
{
ucLane = GA_LANE_FOOT;
}
else if(ucCrossWalkFlag ==2)
{
ucLane = GA_LANE_SECOND_FOOT ;
}
else if ( ucVelhileFlag == 0x0 )
{
ucLane = GA_LANE_TRUNAROUND;
}
else if ( ucVelhileFlag == 0x1 )
{
ucLane = GA_LANE_LEFT;
}
else if ( ucVelhileFlag == 0x2 )
{
ucLane = GA_LANE_STRAIGHT;
}
else if(ucVelhileFlag == 0x3)
{
ucLane = GA_LANE_LEFT_STRAIGHT ;
}
else if ( ucVelhileFlag == 0x4 )
{
ucLane = GA_LANE_RIGHT;
}
else if ( ucVelhileFlag == 0x5 )
{
ucLane = GA_LANE_OTHER;
}
else if(ucVelhileFlag == 0x6)
{
ucLane = GA_LANE_RIGHT_STRAIGHT;
}
else if(ucVelhileFlag == 0x7)
{
ucLane = GA_LANE_LEFT_RIGHT_STRAIGHT;
}
}
/**************************************************************
Function: CGaCountDown::sendblack
Description: 用于发送倒计时黑屏
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown::sendblack()
{
CManaKernel* pManaKernel = CManaKernel::CreateInstance();
if(pManaKernel->m_pTscConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082004)
{
for ( Byte iDir=0; iDir< GA_MAX_DIRECT-4; iDir++ )
{
PackSendBuf( iDir,GANEW_COLOR_BLACK , 199) ;
CRs485::CreateInstance()->Send(m_sGaSendBuf[iDir], GA_MAX_SEND_BUF);
}
}
else if(pManaKernel->m_pTscConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082014 ||
pManaKernel->m_pTscConfig->sSpecFun[FUN_COUNT_DOWN].ucValue == COUNTDOWN_GAT5082014V2)
{
m_newsGaSendBuf[GANEW_CHKDATA_INDEX] = MAX_CNTDOWNDEV ;
for(Byte CntDownDevAddr = 0x0 ; CntDownDevAddr <MAX_CNTDOWNDEV ;CntDownDevAddr++)
{
m_newsGaSendBuf[3+2*CntDownDevAddr] = (0<<2)|(CntDownDevAddr<<3);
m_newsGaSendBuf[3+2*CntDownDevAddr+1] =0x0;
m_newsGaSendBuf[GANEW_CHKDATA_INDEX] ^= (m_newsGaSendBuf[3+2*CntDownDevAddr])^(m_newsGaSendBuf[3+2*CntDownDevAddr+1]);
}
CRs485::CreateInstance()->Send(m_newsGaSendBuf, GANEW_CHKDATA_INDEX+1);
}
}
/**************************************************************
Function: CGaCountDown::send8cntdown
Description: 用于感应控制时的8秒倒计时发送
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown:: send8cntdown()
{
CManaKernel * p_ManaKernel = CManaKernel::CreateInstance();
bool bSend8CntDwon[GA_MAX_DIRECT] ={false};
Byte iStepNum = p_ManaKernel->m_pRunData->ucStepNo ;
Uint iAllowPhase = p_ManaKernel->m_pRunData->sStageStepInfo[iStepNum].uiAllowPhase ;
Byte iNdex = 0 ;
Byte iColor = 0 ;
Byte iCostTime = 0 ;
//ACE_OS::printf("%s:%d StepNum= %d iAllowPhase = %d \n",__FILE__,__LINE__,iStepNum,iAllowPhase);
while(iNdex < MAX_PHASE)
{
if ( (iAllowPhase>>iNdex) & 1 )
{
for(Byte iDirec = 0 ;iDirec < GA_MAX_DIRECT ;iDirec++)
{
for(Byte iLan = 0 ;iLan < (GA_MAX_LANE-1) ;iLan++)
{
if((iNdex+1) == m_sGaPhaseToDirec[iDirec][iLan].ucPhase)
{
bSend8CntDwon[iDirec] = true ;
ACE_OS::printf("%s:%d Phase= %d Direc = %d \n",__FILE__,__LINE__,iNdex+1,iDirec);
}
}
}
}
iNdex++;
}
iNdex = 0 ;
ACE_OS::printf("%s:%d Begin Send 8 cntdown \n",__FILE__,__LINE__);
while(iNdex < GA_MAX_DIRECT)
{
if(bSend8CntDwon[iNdex] == true)
{
PackSendBuf( iNdex , GANEW_COLOR_GREEN , 8 ) ;
CRs485::CreateInstance()->Send(m_sGaSendBuf[iNdex], GA_MAX_SEND_BUF);
}
else
{
ComputeColorCount(iNdex,iColor,iCostTime);
PackSendBuf( iNdex , GANEW_COLOR_RED , iCostTime-8 ) ;
CRs485::CreateInstance()->Send(m_sGaSendBuf[iNdex], GA_MAX_SEND_BUF);
}
iNdex++;
}
}
/**************************************************************
Function: CGaCountDown::SetClinetCntDown
Description: 用于配置向上位机发送各个方向倒计时信息
Input: 无
Output: 无
Return: 无
***************************************************************/
void CGaCountDown::SetClinetCntDown(ACE_INET_Addr& addremote, Uint uBufCnt , Byte* pBuf)
{
Byte ucSndType = pBuf[3];
Byte ucRecvOptType = pBuf[0] & 0xf;
Byte iClientdex = 0 ;
Byte sErrMsg[3] = {0x86 , GBT_ERROR_OTHER , 0};
CGbtMsgQueue* pGbtMsgQueue = CGbtMsgQueue::CreateInstance();
if(uBufCnt >4)
{
pGbtMsgQueue->m_sockLocal.send(sErrMsg ,3, addremote);
return ;
}
for( ;iClientdex<MAX_CLIENT_NUM;iClientdex++)
{
if(ACE_OS::strcmp(sSendCDN[iClientdex].addClient.get_host_addr(),addremote.get_host_addr()) != 0 && sSendCDN[iClientdex].bUsed ==true)
{
continue ;
}
else
{
sSendCDN[iClientdex].addClient.set(ACE_INET_Addr(addremote));
sSendCDN[iClientdex].bSend = (ucSndType == 1)?true:false ;
sSendCDN[iClientdex].bUsed =(ucSndType == 1)?true:false ;
break;
}
}
if(iClientdex == MAX_CLIENT_NUM)
{
pGbtMsgQueue->m_sockLocal.send(sErrMsg ,3, addremote);
return ;
}
else if ( GBT_SET_REQ == ucRecvOptType || GBT_SET_REQ_NOACK == ucRecvOptType ) //设置
{
//正确的应答
if ( GBT_SET_REQ == ucRecvOptType )
{
Byte sSendMsg[4] = {0};
sSendMsg[0] = ( pBuf[0] & 0xf0 ) | GBT_SET_ACK;
sSendMsg[1] = pBuf[1];
sSendMsg[2] = pBuf[2];
pGbtMsgQueue->m_sockLocal.send(sSendMsg ,3, addremote);
}
}
else
{
pGbtMsgQueue->m_sockLocal.send(sErrMsg ,3, addremote);
}
}