/// <summary> /// Coputes targets from the function and adds them to the collection /// </summary> /// <param name="function">Function containing targets</param> /// <param name="collection">Collection to be filled with targets</param> private void ComputeTargets(Function function, Values.ListValue collection) { if (function != null) { Graph graph = function.Graph; if (graph != null && graph.Segments.Count > 1) { double prevSpeed = Double.MaxValue; for (int i = 1; i < graph.Segments.Count; i++) { Graph.Segment s = graph.Segments[i]; Types.Structure structureType = (Types.Structure)EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSupervision"), "Kernel.SpeedAndDistanceMonitoring.TargetSupervision.Target"); Values.StructureValue value = new Values.StructureValue(structureType, structureType.NameSpace); Variables.Variable speed = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable(); speed.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Speed"); speed.Name = "Speed"; speed.Mode = Generated.acceptor.VariableModeEnumType.aInternal; speed.Default = "0.0"; speed.Enclosing = value; speed.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.Val(s.Start)); value.set(speed); Variables.Variable location = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable(); location.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Distance"); location.Name = "Location"; location.Mode = Generated.acceptor.VariableModeEnumType.aInternal; location.Default = "0.0"; location.Enclosing = value; location.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.Start); value.set(location); Variables.Variable length = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable(); length.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Length"); length.Name = "Length"; length.Mode = Generated.acceptor.VariableModeEnumType.aInternal; length.Default = "0.0"; length.Enclosing = value; length.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.End); value.set(length); if (s.Val(s.Start) < prevSpeed) { collection.Val.Add(value); } prevSpeed = s.Val(s.Start); } } } }
/// <summary> /// Finds the type of the structure corresponding to the provided NID_PACKET /// </summary> /// <param name="nameSpace">The namespace where the type has to be found</param> /// <param name="nidPacket">The id of the packet</param> /// <returns></returns> private Values.StructureValue FindStructure(int nidPacket) { Types.Structure structure = null; DataDictionary.Types.NameSpace nameSpace; if (nidPacket != 44) { nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.TRACK_TO_TRAIN"); foreach (DataDictionary.Types.NameSpace subNameSpace in nameSpace.SubNameSpaces) { Types.Structure structureType = (Types.Structure)EFSSystem.findType(subNameSpace, subNameSpace.FullName + ".Message"); Values.StructureValue structureValue = new Values.StructureValue(structureType, nameSpace); foreach (KeyValuePair <string, Variables.IVariable> pair in structureValue.SubVariables) { string variableName = pair.Key; if (variableName.Equals("NID_PACKET")) { Values.IntValue value = pair.Value.Value as Values.IntValue; if (value.Val == nidPacket) { structure = structureType; } } if (structure != null) { break; } } } } else { nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.DATA_USED_BY_APPLICATIONS_OUTSIDE_THE_ERTMS_ETCS_SYSTEM"); structure = (Types.Structure)EFSSystem.findType(nameSpace, nameSpace.FullName + ".Message"); } Values.StructureValue retVal = null; if (structure != null) { retVal = new Values.StructureValue(structure, nameSpace); } return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="instance">the instance on which the function is evaluated</param> /// <param name="actuals">the actual parameters values</param> /// <returns>The value for the function application</returns> public override Values.IValue Evaluate(Interpreter.InterpretationContext context, Dictionary <Variables.Actual, Values.IValue> actuals) { Values.IValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Types.Collection collectionType = (Types.Collection)EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSupervision"), "Kernel.SpeedAndDistanceMonitoring.TargetSupervision.Targets"); Values.ListValue collection = new Values.ListValue(collectionType, new List <Values.IValue>()); // compute targets from the MRSP Function function1 = context.findOnStack(Targets1).Value as Functions.Function; if (function1 != null && !function1.Name.Equals("EMPTY")) { Graph graph1 = createGraphForValue(context, function1); ComputeTargets(graph1.Function, collection); } // compute targets from the MA Function function2 = context.findOnStack(Targets2).Value as Functions.Function; if (function2 != null && !function2.Name.Equals("EMPTY")) { Graph graph2 = createGraphForValue(context, function2); ComputeTargets(graph2.Function, collection); } // compute targets from the SR Function function3 = context.findOnStack(Targets3).Value as Functions.Function; if (function3 != null && !function3.Name.Equals("EMPTY")) { Graph graph3 = createGraphForValue(context, function3); ComputeTargets(graph3.Function, collection); } context.LocalScope.PopContext(token); retVal = collection; return(retVal); }
/// <summary> /// Fills the given structure with the values provided from the database /// </summary> /// <param name="aNameSpace">Namespace of the structure</param> /// <param name="fields">Fields to be copied into the structure</param> /// <param name="index">Index (of fields list) from which we have to start copying</param> /// <param name="aStructure">The structure to be filled</param> private void FillStructure(Types.NameSpace aNameSpace, ArrayList fields, ref int index, Values.StructureValue aStructure) { int j = 0; for (int i = index; i < fields.Count; i++) { Tests.DBElements.DBField field = fields[i] as Tests.DBElements.DBField; KeyValuePair <string, Variables.IVariable> pair = aStructure.SubVariables.ElementAt(j); Variables.IVariable variable = pair.Value; if (variable.Name.StartsWith(field.Variable)) // we use StartsWith and not Equals because we can have N_ITER_1 and N_ITER { if (variable.Type is Types.Enum) { Types.Enum type = variable.Type as Types.Enum; foreach (DataDictionary.Constants.EnumValue enumValue in type.Values) { int value = Int32.Parse(enumValue.getValue()); if (value == field.Value) { variable.Value = enumValue; j++; break; } } } else if (variable.Type is Types.Range) { Types.Range type = variable.Type as Types.Range; variable.Value = new Values.IntValue(type, (decimal)field.Value); j++; } else { throw new Exception("Unhandled variable type"); } if (field.Variable.Equals("N_ITER")) // we have to create a sequence { KeyValuePair <string, Variables.IVariable> sequencePair = aStructure.SubVariables.ElementAt(j); Variables.IVariable sequenceVariable = sequencePair.Value; Types.Collection collectionType = (Types.Collection)EFSSystem.findType(aNameSpace, sequenceVariable.TypeName); Values.ListValue sequence = new Values.ListValue(collectionType, new List <Values.IValue>()); for (int k = 0; k < field.Value; k++) { Types.Structure structureType = (Types.Structure)EFSSystem.findType(aNameSpace, sequence.CollectionType.Type.FullName); Values.StructureValue structureValue = new Values.StructureValue(structureType, structureType.NameSpace); FillStructure(aNameSpace, fields, ref index, structureValue); sequence.Val.Add(structureValue); } sequenceVariable.Value = sequence; j++; } } // if all the fields of the structue are filled, we terminated if (j == aStructure.SubVariables.Count) { index = i; break; } } }
private string format_eurobalise_message(DBElements.DBMessage message) { DataDictionary.Types.NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages"); Types.Structure structureType = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Message"); Values.StructureValue structure = new Values.StructureValue(structureType, nameSpace); int index = 0; FillStructure(nameSpace, message.Fields, ref index, structure); // fills the message fields // then we fill the packets KeyValuePair <string, Variables.IVariable> subSequencePair = structure.SubVariables.ElementAt(structure.SubVariables.Count - 1); Variables.IVariable subSequenceVariable = subSequencePair.Value; Types.Collection collectionType = (Types.Collection)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.Collection1"); Values.ListValue collection = new Values.ListValue(collectionType, new List <Values.IValue>()); Types.Structure subStructure1Type = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.EUROBALISE.SubStructure1"); Values.StructureValue subStructure1 = new Values.StructureValue(subStructure1Type, nameSpace); Types.Structure packetStructure = (Types.Structure)EFSSystem.findType(nameSpace, "Messages.PACKET.TRACK_TO_TRAIN.Message"); Values.StructureValue packetValue = new Values.StructureValue(packetStructure, nameSpace); // will contain the list of all packets of the message and then be added to the structure packetValue ArrayList subStructures = new ArrayList(); foreach (DBElements.DBPacket packet in message.Packets) { Tests.DBElements.DBField nidPacketField = packet.Fields[0] as Tests.DBElements.DBField; if (nidPacketField.Value != 255) // 255 means "end of information" { Values.StructureValue subStructure = FindStructure(nidPacketField.Value); index = 0; FillStructure(nameSpace, packet.Fields, ref index, subStructure); subStructures.Add(subStructure); } } // the collection of the message packets is copied to the structure packetValue int i = 0; foreach (KeyValuePair <string, Variables.IVariable> pair in packetValue.SubVariables) { if (i == subStructures.Count) { break; } string variableName = pair.Key; Values.StructureValue structureValue = subStructures[i] as Values.StructureValue; if (structureValue.Structure.FullName.Contains(variableName)) { Variables.IVariable variable = pair.Value; variable.Value = structureValue; i++; } } subStructure1.SubVariables.ElementAt(0).Value.Value = packetValue; collection.Val.Add(subStructure1); subSequenceVariable.Value = collection; return(structure.Name); }