-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhalfstar.c
More file actions
1617 lines (1474 loc) · 52.1 KB
/
halfstar.c
File metadata and controls
1617 lines (1474 loc) · 52.1 KB
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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* halfstar.c - gegenereerd met TLCGen 12.4.0.18 */
#include "halfstar.h"
#if defined prioFCMAX && (prioFCMAX > 0)
#include "halfstar_prio.h" /* declaratie functies */
#endif
#if (!defined AUTOMAAT && !defined AUTOMAAT_TEST) || defined VISSIM
#include "xyprintf.h"/* voor debug infowindow */
#include <stdio.h> /* declaration printf() */
#endif
#if (CCOL_V >= 95)
boolv COPY_2_TRIG = FALSE; /* nieuwe TX-tijden copieren naar TRIG tabel */
#else
boolv COPY_2_TIG = FALSE; /* nieuwe TX-tijden copieren naar TIG tabel */
#endif
char HalfstarOmschakelenToegestaan = 0;
/*****************************************************************************/
void altcor_kop_halfstar(count fc_aan, count fc_af, count t_nl)
{
/* tijdens rood van de nalooprichting kijken of er genoeg alternatieve realisatieruimte is,
inclusief nalooptijd */
if (R[fc_af])
{
if (!PAR[fc_af] || (tar_max_ple(fc_af) < (TFG_max[fc_af] + T_max[t_nl] + 10)))
PAR[fc_aan] = FALSE;
}
/* tijdens groen van de nalooprichting kijken of er genoeg ruimte is voor de verlengging,
inclusief nalooptijd */
else
{
/* aanvoerende richting alleen alternatief tijdens groen van naloop als er
geen (fictief) conflicterende aanvraag is, of als naloop nog in vastgroen is */
if ((!yv_ar_max_halfstar(fc_af, (mulv)(TFG_max[fc_aan] + T_max[t_nl] + 9))))
PAR[fc_aan] = FALSE;
}
/* koppeling garanderen */
if (TIMER_ACTIVE(t_nl))
RR[fc_af] &= ~RR_ALTCOR_HALFSTAR;
}
/*****************************************************************************/
void altcor_naloopSG_halfstar(count fc1, count fc2, boolv a_bui_fc1, count tnlsg12, boolv voorwaarde)
{
if (voorwaarde)
{
if (a_bui_fc1)
{
if (!(PAR[fc2] && (tar_max_ple(fc2) > (T_max[tnlsg12] + 11))))
PAR[fc1] = FALSE;
}
if (a_bui_fc1 && !PAR[fc1])
PAR[fc2] = FALSE;
}
}
/*****************************************************************************/
/* alternatieve correcties voor tegengestelde richtingen */
void altcor_parfts_pl_halfstar(count fc1, count fc2, boolv voorwaarde)
{
if (voorwaarde)
{
if (A[fc2] && R[fc2] && !PAR[fc2])
PAR[fc1] = FALSE;
if (A[fc1] && R[fc1] && !PAR[fc1])
PAR[fc2] = FALSE;
}
}
/*****************************************************************************/
/* alternatieve correcties voor paralelle voetgangsers en fietsers */
void altcor_parftsvtg_pl_halfstar(count fc1, count fc2, boolv voorwaarde)
{
if (voorwaarde)
{
if (A[fc2] && R[fc2] && !PAR[fc2])
PAR[fc1] = FALSE;
if (A[fc1] && R[fc1] && !PAR[fc1])
PAR[fc2] = FALSE;
/* als 1 richting in RA staat, maar de andere nog een conflict heeft,
dan een RR */
/*if (kcv(fc1) && A[fc1] && !RA[fc1])
RR[fc2] |= RR_ALTCOR_HALFSTAR;
if (kcv(fc2) && A[fc2] && !RA[fc2])
RR[fc1] |= RR_ALTCOR_HALFSTAR;
*/
}
}
/*****************************************************************************/
void alternatief_halfstar(count fc, mulv altp, boolv condition)
{
PAR[fc] &= ~BIT0;
/* als een alternatieve ruimte wordt opgegeven, dan PAR opzetten bij voldoende ruimte, anders
kijken naar vastgroentijd. Minimum is altijd vastgroen
Let op extra 4 vanwege aantal stappen in ccol (FG->WG->VG->MG->GL) */
if (altp > TFG_max[fc])
PAR[fc] |= (boolv)((tar_max_ple(fc) >= (mulv)(altp + 11)) && condition);
else
PAR[fc] |= (boolv)((tar_max_ple(fc) >= (mulv)(TFG_max[fc] + 11)) && condition);
/* afbreken alternatieve realisatie t.b.v. primair realiserend conflict: */
FM[fc] = fm_ar_kpr(fc, TFG_max[fc]);
}
/**********************************************************************************/
void gelijkstart_va_arg_halfstar(count h_x,
count h_rr,
boolv overslag,
...)
{
count fc;
va_list argp;
IH[h_x] = FALSE;
if (h_rr != NG) IH[h_rr] = FALSE;
va_start(argp, overslag);
do
{
fc = va_arg(argp, va_count);
if (fc != END)
{
if ((X[fc] && (R[fc] || GL[fc])) ||
RR[fc] ||
(K[fc] && A[fc]) ||
TRG[fc] || GL[fc] || SGL[fc] ||
(PR[fc] || AR[fc]) && RV[fc] && A[fc] ||
SRA[fc]) IH[h_x] = TRUE;
if ((h_rr != NG) && overslag)
{
if (G[fc] ||
GL[fc]) IH[h_rr] |= TRUE;
}
}
} while (fc != END);
va_end(argp);
}
/**********************************************************************************/
void getrapte_fietser_halfstar(count fc1, /* fc1 */
count fc2, /* fc2 */
boolv a_bui_fc1, /* buitendrukknopaanvraag fc1 */
boolv a_bui_fc2, /* buitendrukknopaanvraag fc2 */
count tkopfc1fc2, /* naloop (SG) fc1 -> fc2 */
count tkopfc2fc1 /* naloop (SG) fc2 -> fc1 */
)
{
/* nalopen */
RT[tkopfc1fc2] = (boolv)((RA[fc1] || TFG[fc1]) && a_bui_fc1);
AT[tkopfc1fc2] = (boolv)((ERA[fc1] && SRV[fc1]));
if ((RT[tkopfc1fc2] || T[tkopfc1fc2]) && ((YV_PL[fc2] && PR[fc2]) /*||
(yv_ar_max_halfstar(fc2, (mulv)(T_max[tkopfc1fc2] - TFG_max[fc2])) && AR[fc2])*/))
{
YV[fc2] |= YV_KOP_HALFSTAR;
}
RT[tkopfc2fc1] = (boolv)((RA[fc2] || TFG[fc2]) && a_bui_fc2);
AT[tkopfc2fc1] = (boolv)((ERA[fc2] && SRV[fc2]));
if ((RT[tkopfc2fc1] || T[tkopfc2fc1]) && ((YV_PL[fc1] && PR[fc1]) /*||
(yv_ar_max_halfstar(fc1, (mulv)(T_max[tkopfc2fc1] - TFG_max[fc1])) && AR[fc1])*/))
{
YV[fc1] |= YV_KOP_HALFSTAR;
}
/* meerealisaties */
set_special_MR(fc1, fc2, (boolv)(PR[fc2] && a_bui_fc2 && R[fc2] && (A[fc2] != A_WS_HALFSTAR)));
set_special_MR(fc2, fc1, (boolv)(PR[fc1] && a_bui_fc1 && R[fc1] && (A[fc1] != A_WS_HALFSTAR)));
/* aanvoerende richting niet te snel realiseren (maximale voorstarttijd gelijk aan nalooptijd) */
/*if (voorstartfc1fc2 != NG)
{
if ((voorstartfc1fc2 > 0) && a_bui_fc1)
{
if (x_aanvoer(fc2, (mulv)(voorstartfc1fc2)))
{
X[fc1] |= X_VOOR_HALFSTAR;
}
}
}
if (voorstartfc2fc1 != NG)
{
if ((voorstartfc2fc1 > 0) && a_bui_fc2)
{
if (x_aanvoer(fc1, (mulv)(voorstartfc2fc1)))
{
X[fc2] |= X_VOOR_HALFSTAR;
}
}
}*/
}
/**********************************************************************************/
/* corrigeert het meeverlengen van de aanvoerende richting van een hard gekoppelde interne richting */
void mgcor_halfstar(count fcaan, count fcnal, count t_nal)
{
if (!ym_max_halfstar(fcnal, (mulv)(T_max[t_nal] + 9))) /* +9 vanwege afronding m.g.b. 10/sec ORT's */
YM[fcaan] &= ~YM_HALFSTAR;
}
/**********************************************************************************/
/* correcties voor parallell langzaamverkeer en autoverkeer in deelconflict tijdens PL */
void mgcor_halfstar_deelc(count fc1, count fc2)
{
if (RA[fc1])
YM[fc2] &= ~YM_HALFSTAR;
}
/**********************************************************************************/
void naloopEG_CV_halfstar(boolv period, count fc1, count fc2, mulv tvs, count tnldet, count tnl)
{
/* geel- en garantieroodtimer tbv tegenhouden aanvoerrichting */
if (GL[fc2])
geeltimer[fc1][fc2] += TE;
if (TRG[fc2])
groodtimer[fc1][fc2] += TE;
if ((R[fc2] && !TRG[fc2]) || G[fc2])
{
geeltimer[fc1][fc2] = 0;
groodtimer[fc1][fc2] = 0;
}
if (tnl != NG)
{
RT[tnl] = (boolv)(G[fc1] && period);
AT[tnl] = (boolv)(ERA[fc1] && SRV[fc1]);
}
if (tnldet != NG)
{
RT[tnldet] = SG[fc1];
AT[tnldet] = (boolv)(ERA[fc1] && SRV[fc1]);
}
if (period && (G[fc1] || GL[fc1] || ((tnl != NG) && TIMER_ACTIVE(tnl)) || ((tnldet != NG) && TIMER_ACTIVE(tnldet))))
{
if (CG[fc1] < CG_MG)
{
if (tnl != NG)
{
if ((YV_PL[fc2] && PR[fc2]) || (yv_ar_max_halfstar(fc2, (mulv)(T_max[tnl] + 9) && AR[fc2])))
{
YV[fc2] |= YV_KOP_HALFSTAR;
}
}
else if (tnldet != NG)
{
if ((YV_PL[fc2] && PR[fc2]) || (yv_ar_max_halfstar(fc2, (mulv)(T_max[tnldet] + 9) && AR[fc2])))
{
YV[fc2] |= YV_KOP_HALFSTAR;
}
}
}
/* naloop in verlenggroen houden, zodat naloop nog kan verlengen na koppeling. Maar als de
aanvoer in MG komt, dan naloop ook in MG anders kan de correctie van de koppeling
op het meeverlengen niet worden uitgevoerd. Na einde MG van aanvoer wordt naloop weer
VG zodat na de koppeling weer kan worden verlengd */
RW[fc2] |= SG[fc1] ? RW_KOP_HALFSTAR : 0;
YM[fc2] |= YM_KOP_HALFSTAR;
}
/* meerealisatie nalooprichting */
set_special_MR(fc2, fc1, (boolv)(period && ((A[fc1] && R[fc1]) || CV[fc1])));
if (tvs > NG)
{
/* aanvoerende richting niet te snel realiseren */
if (period && x_aanvoer(fc2, tvs) && (TX_timer != TXB[PL][fc1]))
X[fc1] |= X_VOOR_HALFSTAR;
/* tegenhouden aanvoerende richting rekening houden met geel en garantieroodtijd; x_aanvoer doet dit niet! */
if (period && (GL[fc2] || TRG[fc2] && (TX_timer != TXB[PL][fc1])))
{
if (((TGL_max[fc2] + TRG_max[fc2]) - (geeltimer[fc1][fc2] + groodtimer[fc1][fc2])) > tvs)
X[fc1] |= X_VOOR_HALFSTAR;
}
}
/* als nalooprichting worden tegengehouden, dan ook aanvoerende richting tegenhouden */
if (period && ((RR[fc2]) && !(TX_timer == TXB[PL][fc1])))
{
RR[fc1] |= RR_KOP_HALFSTAR;
}
/* koppeling garanderen */
if (period && (TIMER_ACTIVE(tnl) || ((tnldet != NG) && TIMER_ACTIVE(tnldet))))
RR[fc2] &= ~RR_ALTCOR_HALFSTAR;
}
/**********************************************************************************/
void naloopSG_halfstar(count fc1, /* fc1 */
count fc2, /* fc2 */
count dk_bui_fc1, /* buitendrukknopaanvraag fc1 */
count hd_bui_fc1, /* onthouden buitendrukknopaanvraag fc1 */
count tkopfc1fc2) /* naloop (SG) fc1 -> fc2 */
{
/* nalopen */
if (dk_bui_fc1 != NG && hd_bui_fc1 != NG)
{
if (SG[fc1]) IH[hd_bui_fc1] = FALSE;
IH[hd_bui_fc1] |= D[dk_bui_fc1] && !G[fc1] && A[fc1];
RT[tkopfc1fc2] = (boolv)(RA[fc1] && IH[hd_bui_fc1]);
}
else
{
RT[tkopfc1fc2] = (boolv)(RA[fc1]);
}
AT[tkopfc1fc2] = (boolv)((ERA[fc1] && SRV[fc1]));
if ((RT[tkopfc1fc2] || T[tkopfc1fc2]) && ((YV_PL[fc2] && PR[fc2]) ||
(yv_ar_max_halfstar(fc2, (mulv)(T_max[tkopfc1fc2] - TFG_max[fc2])) && AR[fc2])))
{
YV[fc2] |= YV_KOP_HALFSTAR;
}
/* meerealisaties */
if (dk_bui_fc1 != NG && hd_bui_fc1 != NG)
{
set_special_MR(fc2, fc1, (boolv)(IH[hd_bui_fc1] && R[fc1] && A[fc2] && (A[fc1] != A_WS_HALFSTAR)));
}
else
{
set_special_MR(fc2, fc1, (boolv)(R[fc1] && A[fc2] && (A[fc1] != A_WS_HALFSTAR)));
}
}
/**********************************************************************************/
void PercentageMaxGroenTijden_halfstar(count fc, count percentage, mulv bit)
{
mulv maxg;
#ifdef TX_PL_TE
maxg = (TX_PL_max + TXD_PL[fc] - TXB_PL[fc]) % TX_PL_max;
#else
maxg = ((TX_PL_max + TXD_PL[fc] - TXB_PL[fc]) % TX_PL_max) * 10;
#endif
if (G[fc] && CV[fc] && !(MK[fc] & ~BIT5)) {
if ((TFG_timer[fc] + TVGA_timer[fc])>(mulv)(((long)PRM[percentage] * (long)maxg) / 100)) {
MK[fc] &= ~bit;
}
}
}
/**********************************************************************************/
void PercentageVerlengGroenTijden_halfstar(count fc, count percentage, mulv bit)
{
mulv maxg;
#ifdef TX_PL_TE
maxg = (TX_PL_max + TXD_PL[fc] - TXB_PL[fc]) % TX_PL_max;
#else
maxg = ((TX_PL_max + TXD_PL[fc] - TXB_PL[fc]) % TX_PL_max) * 10;
#endif
if (G[fc] && CV[fc] && !(MK[fc] & ~BIT5)) {
if ((TVGA_timer[fc])>(mulv)(((long)PRM[percentage] * (long)maxg) / 100)) {
MK[fc] &= ~bit;
}
}
}
/*****************************************************************************/
/* Deze functie retourneert TRUE indien de actuele cyclustijd (TX_timer) zich
tussen s (start) en e (einde) bevindt, waarbij rekening wordt gehouden met
realisaties die over de cyclustijd heen liggen.
Indien tx=NG dan wordt aangenomen dat de actuele TX in de cyclus moet
worden getoetst.
*/
boolv pl_gebied(mulv tx, /* moment in de cyclus afgevraagd (mag NG) */
mulv s, /* startpunt van het gebied */
mulv e) /* eindpunt van het gebied */
{
if (PL < 0)
return FALSE;
if (tx == NG)
tx = TX_timer;
if (s < e)
{
/* realisatie past binnen de cyclustijd */
/* [--------s==========e---------------] */
return (boolv)(tx >= s && tx < e);
}
else if (s > e)
{
/* realisatie ligt over de cyclustijd heen */
/* [=====e----------------------s======] */
return (boolv)(tx >= s || tx < e);
}
else
{
return (boolv)FALSE;
}
}
/*****************************************************************************/
/* retour rood wanneer richting AR heeft maar geen PAR meer */
void reset_altreal_halfstar(void)
{
count i;
for (i = 0; i<FCMAX; i++)
RR[i] |= R[i] && AR[i] && (!PAR[i] || ERA[i]) ? RR_ALTCOR_HALFSTAR : 0;
}
/*****************************************************************************/
void reset_fc_halfstar(void)
{
register count i;
for (i = 0; i<FC_MAX; i++)
{
YS[i] = YW[i] = YV[i] = YM[i] /*= YL[i]*/ = FALSE;
BR[i] = PP[i] = RR[i] = BL[i] = X[i] = RS[i] = RW[i] = FW[i] = FM[i] = Z[i] /*= MK[i]*/ = FALSE;
}
}
/*****************************************************************************/
/* PP bitje opzetten en cyclische aanvraag op TXB moment als PP waar is */
void set_pp_halfstar(count fc, boolv condition, count value)
{
if (!condition)
return;
PP[fc] |= value;
if (PP[fc])
PG[fc] &= ~PRIMAIR_OVERSLAG;
}
/**********************************************************************************/
/* Deze functie is afgeleid van de ccol functie "set_MRLW()".
*/
void set_special_MR(count i, count j, boolv condition)
{
if (AA[j] && condition && !AA[i] && !BL[i] && !fkaa(i) && !RR[j] && !BL[j])
{
PR[i] = AR[i] = BR[i] = MR[i] = FALSE;
AA[i] = MR[i] = TRUE; /* set actuation */
A[i] |= A_MR_HALFSTAR; /* set demand */
if (PR[j]) PR[i] = PR[j]; /* set primary realization */
if (AR[j]) AR[i] = AR[j]; /* set alternative realization */
if (BR[j]) BR[i] = BR[j]; /* set priority realization */
}
}
/**********************************************************************************/
void set_ym_pl_halfstar(count fc, boolv condition)
{
#if !defined NO_TIGMAX
if (ym_max_tig(fc, NG) && /* meeverlengen kan volgens intergroentijden */
#else
if (ym_max_to(fc, NG) && /* meeverlengen kan volgens ontruimingstijden */
#endif
#if (CCOL_V >= 95)
ym_max_trig(fc, NG) && /* meeverlengen kan volgens intergroentijdentabel */
#else
ym_max_tig(fc, NG) && /* meeverlengen kan volgens intergroentijdentabel */
#endif
ym_max_halfstar(fc, 10)&& /* meeverlengen kan volgens signaalplan */
hf_wsg() && /* minimaal 1 richting actief */
condition )
{
YM[fc] |= YM_HALFSTAR;
}
}
void set_ym_pl_halfstar_fcfc(count fc, boolv condition, count fc_from, count fc_until)
{
#if !defined NO_TIGMAX
if (ym_max_tig(fc, NG) && /* meeverlengen kan volgens intergroentijden */
#else
if (ym_max_to(fc, NG) && /* meeverlengen kan volgens ontruimingstijden */
#endif
#if (CCOL_V >= 95)
ym_max_trig(fc, NG) && /* meeverlengen kan volgens intergroentijdentabel */
#else
ym_max_tig(fc, NG) && /* meeverlengen kan volgens intergroentijdentabel */
#endif
ym_max_halfstar(fc, 10) && /* meeverlengen kan volgens signaalplan */
hf_wsg_fcfc(fc_from, fc_until) && /* minimaal 1 richting actief */
condition)
{
YM[fc] |= YM_HALFSTAR;
}
}
/**********************************************************************************/
/* YS_PL[] zelf opzetten bij primair startgroen, dit gebeurt nl.
niet als een fasecyclus voor zijn TXA-moment primair groen krijgt */
void set_yspl(count fc)
{
if (SG[fc] && PR[fc] && (TXA_PL[fc]> 0))
YS_PL[fc] = TRUE;
}
/* dubbele realisatie per richting per plan. Let op, er wordt gebruik gemaakt van baseparameters:
voor de eerste realisatie de eerste TXA parameter en voor de tweede realisatie de tweede TXA
parameter meegeven */
void set_2real(count fc, count prm_eerste_txa, count prm_tweede_txa, mulv pl, boolv condition)
{
if (prm_tweede_txa != NG &&
PRM[prm_tweede_txa + 1] != 0 && PRM[prm_tweede_txa + 3] != 0)
{
set_tx_change(fc, pl, (prm_eerste_txa + 0),
(prm_eerste_txa + 1),
(prm_eerste_txa + 2),
(prm_eerste_txa + 3),
(prm_eerste_txa + 4),
(prm_tweede_txa + 0),
(prm_tweede_txa + 1),
(prm_tweede_txa + 2),
(prm_tweede_txa + 3),
(prm_tweede_txa + 4),
condition);
}
else
{
set_tx_change(fc, pl, (prm_eerste_txa + 0),
(prm_eerste_txa + 1),
(prm_eerste_txa + 2),
(prm_eerste_txa + 3),
(prm_eerste_txa + 4),
(NG),
(NG),
(NG),
(NG),
(NG),
condition);
}
}
void SetPlanTijden(count fc, mulv plan, mulv ta, mulv tb, mulv tc, mulv td, mulv te)
{
TXA[plan][fc] = ta;
TXB[plan][fc] = tb;
TXC[plan][fc] = tc;
TXD[plan][fc] = td;
TXE[plan][fc] = te;
}
/*****************************************************************************/
void SetPlanTijden2R(count fc, mulv plan, mulv ta, mulv tb, mulv tc, mulv td, mulv te,
count fc_2, mulv ta_2, mulv tb_2, mulv tc_2, mulv td_2, mulv te_2)
{
TXA[plan][fc] = ta;
TXB[plan][fc] = tb;
TXC[plan][fc] = tc;
TXD[plan][fc] = td;
TXE[plan][fc] = te;
TXA[plan][fc_2] = ta_2;
TXB[plan][fc_2] = tb_2;
TXC[plan][fc_2] = tc_2;
TXD[plan][fc_2] = td_2;
TXE[plan][fc_2] = te_2;
}
/**********************************************************************************/
void sync_pg(void)
{
register count fc;
boolv **prml = NULL;
count ml = -1;
#ifndef MLMAX
count mlx = -1;
#endif
count mlmax = 0;
for (fc = 0; fc<FCMAX; fc++)
{
#ifdef MLMAX
#else
#ifdef MLAMAX
if (mlx == -1) for (ml = 0; ml < MLAMAX; ++ml) if (PRMLA[ml][fc]) { mlx = MLA; prml = PRMLA; mlmax = MLAMAX; break; }
#endif
#ifdef MLBMAX
if (mlx == -1) for (ml = 0; ml < MLBMAX; ++ml) if (PRMLB[ml][fc]) { mlx = MLB; prml = PRMLB; mlmax = MLBMAX; break; }
#endif
#ifdef MLCMAX
if (mlx == -1) for (ml = 0; ml < MLCMAX; ++ml) if (PRMLC[ml][fc]) { mlx = MLC; prml = PRMLC; mlmax = MLCMAX; break; }
#endif
#ifdef MLDMAX
if (mlx == -1) for (ml = 0; ml < MLDMAX; ++ml) if (PRMLD[ml][fc]) { mlx = MLD; prml = PRMLD; mlmax = MLDMAX; break; }
#endif
#ifdef MLEMAX
if (mlx == -1) for (ml = 0; ml < MLEMAX; ++ml) if (PRMLE[ml][fc]) { mlx = MLE; prml = PRMLE; mlmax = MLEMAX; break; }
#endif
#endif
if (PG[fc] && !prml[ml][fc] && !prml[(ml + 1 == mlmax ? ML1 : ml + 1)][fc])
{
PG[fc] = FALSE;
}
if (IH[hmlact] && RA[fc] && !AAPR[fc] && !PAR[fc])
RR[fc] |= BIT9;
}
}
/**********************************************************************************/
/* Set functies voor het bepalen waar de plaats tussen TX momenten */
boolv tussen_txa_en_txb(count fc)
{
if (TXA_PL[fc] > TXB_PL[fc])
{
if ((TX_timer >= TXA_PL[fc]) || (TX_timer < TXB_PL[fc]))
return (TRUE);
}
else
{
if ((TX_timer >= TXA_PL[fc]) && (TX_timer < TXB_PL[fc]))
return (TRUE);
}
return (FALSE);
}
boolv tussen_txb_en_txc(count fc)
{
if (TXB_PL[fc]> TXC[PL][fc])
{
if ((TX_timer >= TXB_PL[fc]) || (TX_timer < TXC[PL][fc]))
return (TRUE);
}
else
{
if ((TX_timer >= TXB_PL[fc]) && (TX_timer < TXC[PL][fc]))
return (TRUE);
}
return (FALSE);
}
boolv tussen_txb_en_txd(count fc)
{
if (TXB_PL[fc]> TXD[PL][fc])
{
if ((TX_timer >= TXB_PL[fc]) || (TX_timer < TXD[PL][fc]))
return (TRUE);
}
else
{
if ((TX_timer >= TXB_PL[fc]) && (TX_timer < TXD[PL][fc]))
return (TRUE);
}
return (FALSE);
}
/**********************************************************************************/
void set_tx_change(count fc, /* signaalgroep */
count pl, /* actieve plan */
count ptxa1, /* eerste a realisatie */
count ptxb1, /* eerste b realisatie */
count ptxc1, /* eerste c realisatie */
count ptxd1, /* eerste d realisatie */
count ptxe1, /* eerste e realisatie */
count ptxa2, /* tweede a realisatie */
count ptxb2, /* tweede b realisatie */
count ptxc2, /* tweede c realisatie */
count ptxd2, /* tweede d realisatie */
count ptxe2, /* tweede e realisatie */
boolv condition) /* conditie */
{
/* als geen wissel toegepast mag worden of parameters zijn 0 */
if ((PRM[ptxb1] == 0) && (PRM[ptxb1] == 0) && (PRM[ptxb2] == 0) && (PRM[ptxb2] == 0))
{
return;
}
/* als geen tweede realisatie mag worden uitgevoerd, dan eerste realisatie instellen */
if (!condition || (PRM[ptxb2] == 0) || (ptxb2 == NG) || (pl != PL))
{
boolv copy = FALSE;
if (TXA[pl][fc] != PRM[ptxa1])
{
TXA[pl][fc] = PRM[ptxa1];
copy = TRUE;
}
if (TXB[pl][fc] != PRM[ptxb1])
{
TXB[pl][fc] = PRM[ptxb1];
copy = TRUE;
}
if (TXC[pl][fc] != PRM[ptxc1])
{
TXC[pl][fc] = PRM[ptxc1];
copy = TRUE;
}
if (TXD[pl][fc] != PRM[ptxd1])
{
TXD[pl][fc] = PRM[ptxd1];
copy = TRUE;
}
if (TXE[pl][fc] != PRM[ptxe1])
{
TXE[pl][fc] = PRM[ptxe1];
copy = TRUE;
}
if (copy)
{
#if (CCOL_V >= 95)
COPY_2_TRIG = TRUE;
#else
COPY_2_TIG = TRUE;
#endif
}
return;
}
if (PL == pl)
{
boolv change = FALSE;
if (pl_gebied(NG, (mulv)(PRM[ptxd1] + 1), (mulv)(PRM[ptxd2])) ||
(pl_gebied(NG, (mulv)(TXB_PL[fc]), (mulv)(TXD_PL[fc])) && EG[fc]))
{
if (TXA_PL[fc] != PRM[ptxa2])
{
TXA[PL][fc] = PRM[ptxa2];
TXA_PL[fc] = PRM[ptxa2];
change = TRUE;
}
if (TXB_PL[fc] != PRM[ptxb2])
{
TXB[PL][fc] = PRM[ptxb2];
TXB_PL[fc] = PRM[ptxb2];
change = TRUE;
}
if (TXC_PL[fc] != PRM[ptxc2])
{
TXC[PL][fc] = PRM[ptxc2];
TXC_PL[fc] = PRM[ptxc2];
change = TRUE;
}
if (TXD_PL[fc] != PRM[ptxd2])
{
TXD[PL][fc] = PRM[ptxd2];
TXD_PL[fc] = PRM[ptxd2];
change = TRUE;
}
}
if (pl_gebied(NG, (mulv)(PRM[ptxd2] + 1), (mulv)(PRM[ptxd1])) ||
(pl_gebied(NG, (mulv)(TXB_PL[fc]), (mulv)(TXD_PL[fc])) && EG[fc]))
{
if (TXA_PL[fc] != PRM[ptxa1])
{
TXA[PL][fc] = PRM[ptxa1];
TXA_PL[fc] = PRM[ptxa1];
change = TRUE;
}
if (TXB_PL[fc] != PRM[ptxb1])
{
TXB[PL][fc] = PRM[ptxb1];
TXB_PL[fc] = PRM[ptxb1];
change = TRUE;
}
if (TXC_PL[fc] != PRM[ptxc1])
{
TXC[PL][fc] = PRM[ptxc1];
TXC_PL[fc] = PRM[ptxc1];
change = TRUE;
}
if (TXD_PL[fc] != PRM[ptxd1])
{
TXD[PL][fc] = PRM[ptxd1];
TXD_PL[fc] = PRM[ptxd1];
change = TRUE;
}
}
if ((PRM[ptxe1] > 0) && (PRM[ptxe2] > 0))
{
if (TX_timer == PRM[ptxe1])
{
TXE[PL][fc] = PRM[ptxe2];
TXE_PL[fc] = PRM[ptxe2];
change = TRUE;
}
if (TX_timer == PRM[ptxe2])
{
TXE[PL][fc] = PRM[ptxe1];
TXE_PL[fc] = PRM[ptxe1];
change = TRUE;
}
}
if (change) check_signalplans();
}
}
/*****************************************************************************/
/* TXB_GEMIST - om te bepalen of een richting op tijd een aanvraag heeft */
/* is altijd waar behalve wanneer het moment voor het TXB-moment optreedt */
/* wanneer de langste ontruimingstijd inclusief instelbare marge passeert */
/* ====================================================================== */
boolv txb_gemist(count i, int marge)
{
register count n, k;
mulv to_max, to_tmp;
if (R[i]) /* let op! i.v.m. snelheid alleen in R[] behandeld */
{
to_max=to_tmp= 0;
#ifndef TIGNEW
for (n=0; n<KFC_MAX[i]; n++)
{
#if (CCOL_V >= 95)
k = KF_pointer[i][n];
#else
k = TO_pointer[i][n];
#endif
#if (CCOL_V >= 95) && !defined NO_TIGMAX
if (TIG[k][i]) /* zoek grootste ontruimingstijd */
{
to_tmp = TIG_max[k][i] - TIG_timer[k];
#else
if (TO[k][i]) /* zoek grootste ontruimingstijd */
{
to_tmp = TGL_max[k] + TO_max[k][i] - TGL_timer[k] - TO_timer[k];
#endif
if (to_tmp>to_max)
to_max= to_tmp;
}
}
#else
for (n=0; n<FKFC_MAX[i]; n++)
{
#if (CCOL_V >= 95)
k = KF_pointer[i][n];
if (TRIG_max[k][i]>=0)
{
to_tmp= TRIG_max[k][i]-TRIG_timer[k];
#else
k= TO_pointer[i][n];
if (TIG_max[k][i] >= 0)
{
to_tmp = TIG_max[k][i] - TIG_timer[k];
#endif
if (to_tmp>to_max) /* zoek grootste ontruimingstijd */
to_max= to_tmp;
}
}
#endif
if ((TOTXB_PL[i] > 0) && (TOTXB_PL[i] == (to_max + marge)))
return (FALSE);
}
return (TRUE);
}
/**********************************************************************************/
void tvga_timer_halfstar(void)
{
int i;
for (i = 0; i<FC_MAX; i++)
{
if (SG[i]) TVGA_timer[i] = 0;
if (G[i] && (CG[i] > CG_WG)) TVGA_timer[i] += TE;
}
}
/**********************************************************************************/
/* 2e REALISATIE BINNEN SIGNAALPLAN */
void tweederealisatie_halfstar(count fc_1, /* fasecyclus 1e realisatie */
count fc_2) /* fasecyclus 2e realisatie */
{
register mulv tot_txb1,
tot_txb2,
txa1,
txb1,
txc1,
txd1,
txe1;
/* berekenen tijd tot TXB-moment realisatie 1 (mits TXB fc_1 is ingevuld, anders */
/* tot_txb1 groter maken dan cyclustijd waardoor realisatie 1 niet wordt gekozen) */
if (TXB[PL][fc_1] > 0)
{
if (TX_timer < TXB[PL][fc_1]) tot_txb1 = TXB[PL][fc_1] - TX_timer;
else tot_txb1 = TXB[PL][fc_1] + TX_max[PL] - TX_timer;
}
else
{
tot_txb1 = TX_max[PL] + 1;
}
/* berekenen tijd tot TXB-moment realisatie 2 (mits TXB fc_2 is ingevuld, anders */
/* tot_txb2 groter maken dan cyclustijd waardoor realisatie 2 niet wordt gekozen) */
if (TXB[PL][fc_2] > 0)
{
if (TX_timer < TXB[PL][fc_2]) tot_txb2 = TXB[PL][fc_2] - TX_timer;
else tot_txb2 = TXB[PL][fc_2] + TX_max[PL] - TX_timer;
}
else
{
tot_txb2 = TX_max[PL] + 1;
}
/* omschakelen naar 2e realisatie als 2e realisatie eerstvolgende is */
/* en 1e realisatie voorbij het TXD-moment is (2e wordt 1e en omgekeerd) */
/* --------------------------------------------------------------------- */
if ((tot_txb2 < tot_txb1) && !tussen_txb_en_txd(fc_1) && !G[fc_1])
{
/* oude waarden 1e realisatie even onthouden */
txa1 = TXA[PL][fc_1];
txb1 = TXB[PL][fc_1];
txc1 = TXC[PL][fc_1];
txd1 = TXD[PL][fc_1];
txe1 = TXE[PL][fc_1];
/* waarden 2e realisatie kopi?ren naar 1e realisatie */
TXA[PL][fc_1] = TXA[PL][fc_2];
TXB[PL][fc_1] = TXB[PL][fc_2];
TXC[PL][fc_1] = TXC[PL][fc_2];
TXD[PL][fc_1] = TXD[PL][fc_2];
TXE[PL][fc_1] = TXE[PL][fc_2];
/* oude waarden 1e realisatie kopi?ren naar 2e realisatie */
TXA[PL][fc_2] = txa1;
TXB[PL][fc_2] = txb1;
TXC[PL][fc_2] = txc1;
TXD[PL][fc_2] = txd1;
TXE[PL][fc_2] = txe1;
copy_signalplan(PL); /* kopieer de nieuwe signaalplantijden naar de werkvariabelen */
CIF_PARM1WIJZAP = (s_int16)(-2); /* laat weten dat de applicatie TX-tijden heeft anngepast */
PG[fc_1] = FALSE;
}
}
/**********************************************************************************/
/* aangepaste functie van ccol bibliotheek (plfunc.c). Naast een aanvraag wordt ook gekeken naar
PP van een conflicterende richting. De aanvraag van een hoofdrichting wordt pas op TXB moment gezet */
boolv ym_max_halfstar(count i, mulv koppeltijd)
{
register count n, k;
boolv ym;
if (MG[i] && (YM_PL[i] || !PR[i]))
{
ym = TRUE;
for (n = 0; n<FKFC_MAX[i]; n++)
{
#if (CCOL_V >= 95)
k = KF_pointer[i][n];
if (TRIG_max[i][k] >= 0)
#else
k = TO_pointer[i][n];
if (TIG_max[i][k] >= 0)
#endif
{
if ((TOTXB_PL[k] > 0) && !PG[k] && R[k] && (A[k] || PP[k]) || ((TOTXB_PL[k] == 0) && RA[k]))
{
#if (CCOL_V >= 95)
if ((TRIG_max[i][k] + koppeltijd) >= (TOTXB_PL[k] - 9)) /* -9 om rekening te houden met ORT's in tienden van seconden */
#else
if ((TIG_max[i][k] + koppeltijd) >= (TOTXB_PL[k] - 9)) /* -9 om rekening te houden met ORT's in tienden van seconden */
#endif
{ /* (refresh van TOTXB_PL is maar per seconde en niet per 1/10 seconde) */
ym = FALSE;
break;
}
}
}
}
}
else
{
ym = CV[i];
}
return ym;
}
/**********************************************************************************/
/* aangepaste functie van ccol bibliotheek (plfunc.c). Naast een aanvraag wordt ook gekeken naar
PP van een conflicterende richting. De aanvraag van een hoofdrichting wordt pas op TXB moment gezet.
Tevens ook berekening uitvoeren tijdens WG en MG, want een evt nalooprichting kan door TXC moment
worden vastgehouden of kan meeverlengen met andere richtingen */
boolv yv_ar_max_halfstar(count i, mulv koppeltijd)
{
register count n, k;
boolv yv;
if (WG[i] || VG[i] || MG[i])
{
yv= TRUE;
for (n=0; n<FKFC_MAX[i]; n++)