Пример #1
0
        internal void GenerateFcTimingsC(ControllerModel c, TimingsDataModel model, string ts)
        {
            var sb = new StringBuilder();

            sb.AppendLine("/* DEFINITIE FCTMING FUNCTIES */");
            sb.AppendLine("/* -------------------------- */");
            sb.AppendLine();
            sb.Append(CCOLHeaderGenerator.GenerateFileHeader(c.Data, "fctimings.c"));
            sb.AppendLine();
            sb.Append(CCOLHeaderGenerator.GenerateVersionHeader(c.Data));
            sb.AppendLine();
            //sb.AppendLine("/* INCLUDE FILES */");
            //sb.AppendLine("/* ============= */");
            //sb.AppendLine($"#include \"{c.Data.Naam}sys.h\"");
            //sb.AppendLine("#include \"cif.inc\"            /* declaratie CIF_IS[]              */");
            //sb.AppendLine("#include \"fcvar.h\"            /* declaratie fasecycli variabelen  */");
            //sb.AppendLine();
            sb.AppendLine("/* DEFINITIE EVENTSTATE */");
            sb.AppendLine("/* ==================== */");
            sb.AppendLine();
            sb.AppendLine("#ifdef EVENTSTATE_MACRODEFINITIES_CIF_INC");
            sb.AppendLine();
            sb.AppendLine("/* Macrodefinities status EVENTSTATE (Nederlands) */");
            sb.AppendLine("/* ---------------------------------------------- */");
            sb.AppendLine("#define CIF_TIMING_ONBEKEND           0    /* Unknown(0)                             */");
            sb.AppendLine("#define CIF_TIMING_GEDOOFD            1    /* Dark(1)                                */");
            sb.AppendLine("#define CIF_TIMING_ROOD_KNIPPEREN     2    /* stop - Then - Proceed(2)               */");
            sb.AppendLine("#define CIF_TIMING_ROOD               3    /* stop - And - Remain(3)                 */");
            sb.AppendLine("#define CIF_TIMING_GROEN_OVERGANG     4    /* pre - Movement(4) - not used in NL     */");
            sb.AppendLine("#define CIF_TIMING_GROEN_DEELCONFLICT 5    /* permissive - Movement - Allowed(5)     */");
            sb.AppendLine("#define CIF_TIMING_GROEN              6    /* protected - Movement - Allowed(6)      */");
            sb.AppendLine("#define CIF_TIMING_GEEL_DEELCONFLICT  7    /* permissive - clearance(7)              */");
            sb.AppendLine("#define CIF_TIMING_GEEL               8    /* protected - clearance(8)               */");
            sb.AppendLine("#define CIF_TIMING_GEEL_KNIPPEREN     9    /* caution - Conflicting - Traffic(9)     */");
            sb.AppendLine("#define CIF_TIMING_GROEN_KNIPPEREN_DEELCONFLICT 10    /* permissive - Movement - PreClearance - not in J2735 */");
            sb.AppendLine("#define CIF_TIMING_GROEN_KNIPPEREN              11    /* protected -  Movement - PreClearance - not in J2735 */");
            sb.AppendLine();
            sb.AppendLine("#endif");
            sb.AppendLine();
            sb.AppendLine($"/* De functie kr52_Eventstate_Definition() definieert de eventstate voor de fasecycli.");
            sb.AppendLine($" * De functie kr52_Eventstate_Definition() wordt aangeroepn door de functie control_parameters().");
            sb.AppendLine($" */");
            sb.AppendLine($"void Timings_Eventstate_Definition(void)");
            sb.AppendLine($"{{");
            sb.AppendLine($"{ts}register count i;");
            sb.AppendLine();
            sb.AppendLine($"{ts}/* Zet defaultwaarde */");
            sb.AppendLine($"{ts}/* ----------------- */");
            sb.AppendLine($"{ts}for (i = 0; i < FCMAX; i++)");
            sb.AppendLine($"{ts}{{");
            sb.AppendLine($"{ts}{ts}CCOL_FC_EVENTSTATE[i][CIF_ROOD]= CIF_TIMING_ONBEKEND;       /* Rood   */");
            sb.AppendLine($"{ts}{ts}CCOL_FC_EVENTSTATE[i][CIF_GROEN]= CIF_TIMING_ONBEKEND;      /* Groen  */");
            sb.AppendLine($"{ts}{ts}CCOL_FC_EVENTSTATE[i][CIF_GEEL]= CIF_TIMING_ONBEKEND;       /* Geel   */");
            sb.AppendLine($"{ts}}}");
            sb.AppendLine();
            foreach (var fc in model.TimingsFasen)
            {
                sb.AppendLine($"/* Fase {fc.FaseCyclus} */");
                var fcfc = c.Fasen.FirstOrDefault(x => x.Naam == fc.FaseCyclus);
                switch (fc.ConflictType)
                {
                case TimingsFaseCyclusTypeEnum.Conflictvrij:
                    sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_ROOD]= CIF_TIMING_ROOD;       /* Rood   */");
                    sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_GROEN]= CIF_TIMING_GROEN;      /* Groen  */");
                    if (fcfc != null)
                    {
                        sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_GEEL]= CIF_TIMING_GEEL;       /* Geel   */");
                    }
                    break;

                case TimingsFaseCyclusTypeEnum.Deelconflict:
                    sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_ROOD]= CIF_TIMING_ROOD;       /* Rood   */");
                    sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_GROEN]= CIF_TIMING_GROEN_DEELCONFLICT;      /* Groen  */");
                    if (fcfc != null)
                    {
                        sb.AppendLine($"{ts}CCOL_FC_EVENTSTATE[{_fcpf}{fc.FaseCyclus}][CIF_GEEL]= CIF_TIMING_GEEL_DEELCONFLICT;       /* Geel   */");
                    }
                    break;
                }
                sb.AppendLine();
            }
            sb.AppendLine("}");

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(DataAccess.TLCGenControllerDataProvider.Default.ControllerFileName), $"{c.Data.Naam}fctimings.c"), sb.ToString(), Encoding.Default);
        }
Пример #2
0
        internal void GenerateRisSimC(ControllerModel c, RISDataModel model, string ts)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("/* APPLICATIE RIS SIMULATIEPROGRAMMA */");
            sb.AppendLine("/* --------------------------------- */");
            sb.AppendLine();
            sb.Append(CCOLHeaderGenerator.GenerateFileHeader(c.Data, "rissim.c"));
            sb.AppendLine();
            sb.Append(CCOLHeaderGenerator.GenerateVersionHeader(c.Data));
            sb.AppendLine();
            sb.AppendLine("/* INCLUDE FILES */");
            sb.AppendLine("/* ============= */");
            sb.AppendLine($"#include \"{c.Data.Naam}sys.h\"");
            sb.AppendLine("#include \"cif.inc\"            /* declaratie CIF_IS[]           */");
            sb.AppendLine("#include \"isvar.h\"            /* declaratie IS[]               */");
            sb.AppendLine("#include \"rissimvar.c\"        /* ris-simulatie variabelen      */");
            sb.AppendLine("#include \"xyprintf.h\"         /* declaratie xyprintf-functie   */");
            sb.AppendLine();
            sb.AppendLine("/* RIS-FI - ObjectID<Intersection, LaneID en ObjectID<SIgnalGroupID> */");
            sb.AppendLine("/* ================================================================= */");
            sb.AppendLine("/* The ID of the intersection can be retrieved from the ITF controlData section, ");
            sb.AppendLine(" * element “name” in “controlledIntersection” (SYSTEM_ITF).");
            sb.AppendLine(" * The LaneNr is a unique number within the intersection (LaneID).");
            sb.AppendLine(" * The (TLC) ID of the signal group can be retrieved from the ITF controlData section, ");
            sb.AppendLine(" * element “name” in “sg” (FC_code[]).");
            sb.AppendLine(" */");
            sb.AppendLine($"/*RIS SIMULATIE PARAMETERS */");
            sb.AppendLine($"/*======================== */");
            sb.AppendLine($"");
            sb.AppendLine($"void ris_simulation_parameters(void)");
            sb.AppendLine($"{{");
            sb.AppendLine($"{ts}#ifdef RISSIMULATIE");
            foreach (var l in model.RISFasen.SelectMany(x => x.LaneData).Where(x => x.SimulatedStations.Any()))
            {
                foreach (var s in l.SimulatedStations)
                {
                    var sitf = "SYSTEM_ITF";
                    if (_RISModel.HasMultipleSystemITF)
                    {
                        var msitf = _RISModel.MultiSystemITF.FirstOrDefault(x => x.SystemITF == s.SystemITF);
                        if (msitf != null)
                        {
                            var j = _RISModel.MultiSystemITF.IndexOf(msitf);
                            sitf = $"SYSTEM_ITF{j + 1}";
                        }
                    }
                    sb.AppendLine($"{ts}ris_simulation_itsstation_parameters({sitf}, ris_lane{l.SignalGroupName}{l.RijstrookIndex}, {_fcpf}{l.SignalGroupName}, RIF_STATIONTYPE_{s.Type}, 0, 0, {s.Flow}, {s.Snelheid}, 10, {s.Afstand}, 10, 1);");
                }
            }
            sb.AppendLine($"{ts}#endif // RISSIMULATIE");
            sb.AppendLine();
            foreach (var l in model.RISFasen.SelectMany(x => x.LaneData).Where(x => x.SimulatedStations.Any()))
            {
                foreach (var s in l.SimulatedStations)
                {
                    var tl   = s.Type == RISStationTypeSimEnum.PEDESTRIAN ? 1 : s.Type == RISStationTypeSimEnum.CYCLIST ? 2 : 6;
                    var dl   = s.Type == RISStationTypeSimEnum.PEDESTRIAN ? 50 : s.Type == RISStationTypeSimEnum.CYCLIST ? 100 : 300;
                    var sitf = "SYSTEM_ITF";
                    if (_RISModel.HasMultipleSystemITF)
                    {
                        var msitf = _RISModel.MultiSystemITF.FirstOrDefault(x => x.SystemITF == s.SystemITF);
                        if (msitf != null)
                        {
                            var j = _RISModel.MultiSystemITF.IndexOf(msitf);
                            sitf = $"SYSTEM_ITF{j + 1}";
                        }
                    }
                    sb.AppendLine($"{ts}ris_display_lane_parameters({sitf}, ris_lane{l.SignalGroupName}{l.RijstrookIndex}, \"{l.SignalGroupName}-{l.RijstrookIndex}\", {tl}, {dl});");
                }
            }
            sb.AppendLine($"}}");
            sb.AppendLine($"");
            sb.AppendLine($"/* RIS SIMULATIE APPLICATIE */");
            sb.AppendLine($"/* ======================== */");
            sb.AppendLine($"");
            sb.AppendLine($"#define SIS(is)  (IS[is] && !IS_old[is])");
            sb.AppendLine($"void ris_simulation_application(void)");
            sb.AppendLine($"{{");
            sb.AppendLine($"{ts}#if (!defined AUTOMAAT_TEST)");
            foreach (var l in model.RISFasen.SelectMany(x => x.LaneData).Where(x => x.SimulatedStations.Any()))
            {
                foreach (var s in l.SimulatedStations)
                {
                    var sitf = "SYSTEM_ITF";
                    if (_RISModel.HasMultipleSystemITF)
                    {
                        var msitf = _RISModel.MultiSystemITF.FirstOrDefault(x => x.SystemITF == s.SystemITF);
                        if (msitf != null)
                        {
                            var j = _RISModel.MultiSystemITF.IndexOf(msitf);
                            sitf = $"SYSTEM_ITF{j + 1}";
                        }
                    }
                    sb.AppendLine($"{ts}if (SIS({_ispf}{s.Naam})) ris_simulation_put_itsstation_pb({sitf}, ris_lane{l.SignalGroupName}{l.RijstrookIndex}, {_fcpf}{l.SignalGroupName}, RIF_STATIONTYPE_{s.Type}, 0, 0, {s.Snelheid}, {s.Afstand}, 1);");
                }
            }
            sb.AppendLine($"");
            sb.AppendLine($"/* Display ris_lanes met ItsStations */");
            sb.AppendLine($"/* --------------------------------- */");
            var i = 15;

            foreach (var l in model.RISFasen.SelectMany(x => x.LaneData).Where(x => x.SimulatedStations.Any()))
            {
                sb.AppendLine($"xyprintf(0, {i}, \"%s\", RIS_DISPLAY_LANE_STRING[ris_lane{l.SignalGroupName}{l.RijstrookIndex}]);");
                ++i;
            }
            sb.AppendLine($"");
            sb.AppendLine($"/* Display aantal ItsStations en PrioRequests */");
            sb.AppendLine($"/* ------------------------------------------ */  ");
            sb.AppendLine($"xyprintf(0, {i + 1}, \"ItsStation =% -3d ItsStation - Ex =% -3d\", RIS_ITSSTATION_AP_NUMBER,  RIS_ITSSTATION_EX_AP_NUMBER);");
            sb.AppendLine($"xyprintf(0, {i + 2}, \"PrioRequest =% -3d PrioRequest_Ex =% -3d\", RIS_PRIOREQUEST_AP_NUMBER, RIS_PRIOREQUEST_EX_AP_NUMBER);");
            sb.AppendLine($"{ts}#endif");

            sb.AppendLine("}");

            File.WriteAllText(Path.Combine(Path.GetDirectoryName(DataAccess.TLCGenControllerDataProvider.Default.ControllerFileName), $"{c.Data.Naam}rissim.c"), sb.ToString(), Encoding.Default);
        }