Esempio n. 1
0
        private List <ObjectReference> CollectAllRefs(TLCFacilities facilitiesData, Intersection intersectionData, TLCFIClientConfig config)
        {
            if (!config.UseIdsFromTLCForSubscription && intersectionData == null)
            {
                throw new NullReferenceException("IntersectionData may not be null when ids from intersection must be used to gather META data.");
            }
            if (config.UseIdsFromTLCForSubscription && facilitiesData == null)
            {
                throw new NullReferenceException("FacilitiesData may not be null when ids from TLCFacilities must be used to gather META data.");
            }
            var refs = new List <ObjectReference>
            {
                new ObjectReference
                {
                    Ids  = config.UseIdsFromTLCForSubscription ? facilitiesData.Signalgroups : intersectionData.Signalgroups,
                    Type = TLCObjectType.SignalGroup
                },
                new ObjectReference
                {
                    Ids  = config.UseIdsFromTLCForSubscription ? facilitiesData.Detectors : intersectionData.Detectors,
                    Type = TLCObjectType.Detector
                },
                new ObjectReference
                {
                    Ids  = config.UseIdsFromTLCForSubscription || config.SubscribeToAllOutputs ? facilitiesData.Outputs : intersectionData.Outputs,
                    Type = TLCObjectType.Output
                },
                new ObjectReference
                {
                    Ids  = config.UseIdsFromTLCForSubscription ? facilitiesData.Inputs : intersectionData.Inputs,
                    Type = TLCObjectType.Input
                },
                new ObjectReference
                {
                    Ids = config.UseIdsFromTLCForSubscription
                        ? new[] { facilitiesData.Spvehgenerator }
                        : new[] { intersectionData.Spvehgenerator },
                    Type = TLCObjectType.SpecialVehicleEventGenerator
                },
                new ObjectReference
                {
                    Ids  = facilitiesData.Variables,
                    Type = TLCObjectType.Variable
                }
            };

            if (config.UseIdsFromTLCForSubscription)
            {
                refs.Add(new ObjectReference
                {
                    Ids  = new[] { intersectionData.Id },
                    Type = TLCObjectType.Intersection
                });
            }
            return(refs);
        }
        public TLCFIClientStateManager()
        {
            Facilities            = new TLCFacilities();
            InternalIntersections = new List <Intersection>();
            InternalVariables     = new List <Variable>();
            InternalSignalGroups  = new List <SignalGroup>();
            InternalDetectors     = new List <Detector>();
            InternalInputs        = new List <Input>();
            InternalOutputs       = new List <Output>();
            SpvhGenerator         = new SpecialVehicleEventGenerator();

            RequestedStates         = new Dictionary <string, ulong>();
            _requestedStatesTimings = new Queue <int>(50);
        }
Esempio n. 3
0
        private void CheckMetaData(TLCFacilities facilitiesData, Intersection intersectionData, TLCFIClientConfig config)
        {
            bool ok;

            if (config.UseIdsFromTLCForSubscription)
            {
                _logger.Info("Checking CLA config against TLC META data.");
                ok = TLCFIClientCompatabilityChecker.IsCLACompatibleWithTLC(config, facilitiesData);
            }
            else
            {
                _logger.Info("Checking CLA config against Intersection META data.");
                ok = TLCFIClientCompatabilityChecker.IsCLACompatibleWithIntersection(config, intersectionData,
                                                                                     config.SubscribeToAllOutputs ? facilitiesData : null);
            }
            if (ok)
            {
                _logger.Info("All necessarry configured objects were found.");
                return;
            }
            _logger.Fatal("Not all necessarry objects could be matched.");
            throw new TLCFISessionException("Not all necessarry object could be matched (FATAL!)", true);
        }
        public static bool IsCLACompatibleWithIntersection(TLCFIClientConfig tlcfiClientConfig, Intersection intersection, TLCFacilities facilities)
        {
            // SignalGroups: all ids must match
            foreach (var id1 in intersection.Signalgroups)
            {
                if (tlcfiClientConfig.SignalGroupIds.All(id2 => id1 != id2))
                {
                    _logger.Error("SignalGroup with id {0} from TLC intersection not found in CLA config", id1);
                    return(false);
                }
            }
            foreach (var id1 in tlcfiClientConfig.SignalGroupIds)
            {
                if (intersection.Signalgroups.All(id2 => id1 != id2))
                {
                    _logger.Error("SignalGroup with id {0} from CLA config not found in TLC intersection", id1);
                    return(false);
                }
            }

            // Detectors, out- and inputs: all ids from CLA must be present in TLC
            foreach (var id1 in tlcfiClientConfig.DetectorIds)
            {
                if (intersection.Detectors.All(id2 => id1 != id2))
                {
                    _logger.Error("Detector with id {0} from CLA config not found in TLC intersection", id1);
                    return(false);
                }
            }
            foreach (var id1 in intersection.Detectors)
            {
                if (tlcfiClientConfig.DetectorIds.All(id2 => id1 != id2))
                {
                    _logger.Warn("Detector with id {0} from TLC intersection not found in CLA config ", id1);
                }
            }
            foreach (var id1 in tlcfiClientConfig.InputIds)
            {
                if (intersection.Inputs.All(id2 => id1 != id2))
                {
                    _logger.Error("Input with id {0} from CLA config not found in TLC intersection", id1);
                    return(false);
                }
            }
            foreach (var id1 in intersection.Inputs)
            {
                if (tlcfiClientConfig.InputIds.All(id2 => id1 != id2))
                {
                    _logger.Warn("Input with id {0} from TLC intersection not found in CLA config ", id1);
                }
            }

            // for outputs: use outputs from TLC if facilities argument is not null
            // this facilitates configuring non-exclusive outputs
            foreach (var id1 in tlcfiClientConfig.OutputIds)
            {
                if (facilities != null && facilities.Outputs.All(id2 => id1 != id2) ||
                    facilities == null && intersection.Outputs.All(id2 => id1 != id2))
                {
                    _logger.Error("Output with id {0} from CLA config not found in TLC intersection", id1);
                    return(false);
                }
            }
            if (facilities == null)
            {
                foreach (var id1 in intersection.Outputs)
                {
                    if (tlcfiClientConfig.OutputIds.All(id2 => id1 != id2))
                    {
                        _logger.Warn("Output with id {0} from TLC intersection not found in CLA config ", id1);
                    }
                }
            }
            else
            {
                foreach (var id1 in facilities.Outputs)
                {
                    if (tlcfiClientConfig.OutputIds.All(id2 => id1 != id2))
                    {
                        _logger.Warn("Output with id {0} from TLC facilities not found in CLA config ", id1);
                    }
                }
            }

            return(true);
        }
        public static bool IsCLACompatibleWithTLC(TLCFIClientConfig tlcfiClientConfig, TLCFacilities facilities)
        {
            // SignalGroups: all ids must match
            foreach (var id1 in facilities.Signalgroups)
            {
                if (tlcfiClientConfig.SignalGroupIds.All(id2 => id1 != id2))
                {
                    _logger.Error("SignalGroup with id {0} from TLC facilities not found in CLA config", id1);
                    return(false);
                }
            }
            foreach (var id1 in tlcfiClientConfig.SignalGroupIds)
            {
                if (facilities.Signalgroups.All(id2 => id1 != id2))
                {
                    _logger.Error("SignalGroup with id {0} from CLA config not found in TLC facilities", id1);
                    return(false);
                }
            }

            // Detectors, out- and inputs: all ids from CLA must be present in TLC
            foreach (var id1 in tlcfiClientConfig.DetectorIds)
            {
                if (facilities.Detectors.All(id2 => id1 != id2))
                {
                    _logger.Error("Detector with id {0} from CLA config not found in TLC facilities", id1);
                    return(false);
                }
            }
            foreach (var id1 in facilities.Detectors)
            {
                if (tlcfiClientConfig.DetectorIds.All(id2 => id1 != id2))
                {
                    _logger.Warn("Detector with id {0} from TLC facilities not found in CLA config ", id1);
                }
            }
            foreach (var id1 in tlcfiClientConfig.InputIds)
            {
                if (facilities.Inputs.All(id2 => id1 != id2))
                {
                    _logger.Error("Input with id {0} from CLA config not found in TLC facilities", id1);
                    return(false);
                }
            }
            foreach (var id1 in facilities.Inputs)
            {
                if (tlcfiClientConfig.InputIds.All(id2 => id1 != id2))
                {
                    _logger.Warn("Input with id {0} from TLC facilities not found in CLA config ", id1);
                }
            }
            foreach (var id1 in tlcfiClientConfig.OutputIds)
            {
                if (facilities.Outputs.All(id2 => id1 != id2))
                {
                    _logger.Error("Output with id {0} from CLA config not found in TLC facilities", id1);
                    return(false);
                }
            }
            foreach (var id1 in facilities.Outputs)
            {
                if (tlcfiClientConfig.OutputIds.All(id2 => id1 != id2))
                {
                    _logger.Warn("Output with id {0} from TLC facilities not found in CLA config ", id1);
                }
            }

            return(true);
        }