Exemplo n.º 1
0
        private static string format_euroradio_message(DBMessage message)
        {
            EFSSystem system = EFSSystem.INSTANCE;

            NameSpace rbcRoot = findNameSpace("Messages.MESSAGE");

            // Get the EFS namespace corresponding to the message
            // Select the appropriate message type, tracktotrain or traintotrack
            DBField nidMessage = message.Fields[0] as DBField;
            string msg_id = get_namespace_from_ID(nidMessage.Value);

            NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(rbcRoot, msg_id);

            if (nameSpace == null)
            {
                throw new Exception("Message type not found in EFS");
            }

            // The EURORADIO messages are defined in the namespaces TRACK_TO_TRAIN and TRAIN_TO_TRACK, which enclose the specific message namespaces
            // So we get the message type from nameSpace.EnclosingNameSpace and the actual structure corresponding to the message in nameSpace
            Structure enclosingStructureType = (Structure) system.FindType(nameSpace.EnclosingNameSpace, "Message");
            StructureValue Message = new StructureValue(enclosingStructureType);

            // Within the message, get the appropriate field and get that structure
            Structure structureType = (Structure) system.FindType(nameSpace, "Message");
            StructureValue structure = new StructureValue(structureType);

            // Fill the structure
            int currentIndex = 0;
            FillStructure(nameSpace, message.Fields, ref currentIndex, structure);

            // Fill the default packets
            int translatedPackets = 0;
            foreach (KeyValuePair<string, IVariable> subVariable in structure.SubVariables)
            {
                if (subVariable.Value.TypeName.EndsWith("Message"))
                {
                    // The structure of packets will always be a Message, but in some cases, it is a message that contains
                    // the different options for a single field in the message
                    structure.getVariable(subVariable.Value.Name).Value = FillDefaultPacket(message, subVariable.Value);

                    translatedPackets++;
                }
            }

            // and fill the packets
            IVariable subSequenceVariable;
            if (structure.SubVariables.TryGetValue("Sequence1", out subSequenceVariable)
                && message.Packets.Count > translatedPackets)
            {
                subSequenceVariable.Value = get_message_packets(message, nameSpace, system);
            }

            // Fill the correct field in Message with the structure.
            foreach (KeyValuePair<string, IVariable> pair in Message.SubVariables)
            {
                if (msg_id.EndsWith(pair.Key))
                {
                    pair.Value.Type = structureType;
                    pair.Value.Value = structure;
                }
            }

            return Message.Name;
        }
Exemplo n.º 2
0
        private static IValue FillDefaultPacket(DBMessage message, IVariable structure)
        {
            IValue retVal = structure.Value;

            if (isPacket(structure))
            {
                Structure defaultPacketType = (Structure) structure.Type;
                StructureValue defaultPacket = new StructureValue(defaultPacketType);

                NameSpace packetNameSpace = structure.NameSpace;

                foreach (DBPacket packet in message.Packets)
                {
                    DBField nidPacketField = packet.Fields[0] as DBField;
                    int packetID = int.Parse(nidPacketField.Value);

                    Structure packetType = (Structure) FindStructure(packetID).Type;

                    if (packetType == defaultPacketType)
                    {
                        int defaultPacketIndex = 0;
                        FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                        retVal = defaultPacket;
                    }
                }
            }
            else
            {
                Structure structureType = structure.Type as Structure;
                StructureValue Structure = new StructureValue(structureType);
                if (Structure != null)
                {
                    foreach (KeyValuePair<string, IVariable> subVariable in Structure.SubVariables)
                    {
                        if (isPacket(subVariable.Value))
                        {
                            Structure defaultPacketType = (Structure) subVariable.Value.Type;
                            StructureValue defaultPacket = new StructureValue(defaultPacketType);

                            NameSpace packetNameSpace = subVariable.Value.NameSpace;

                            foreach (DBPacket packet in message.Packets)
                            {
                                DBField nidPacketField = packet.Fields[0] as DBField;
                                int packetID = int.Parse(nidPacketField.Value);

                                Structure packetType = (Structure) FindStructure(packetID).Type;

                                if (packetType == defaultPacketType)
                                {
                                    int defaultPacketIndex = 0;
                                    FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                                    Structure.getVariable(subVariable.Value.Name).Value = defaultPacket;
                                }
                            }
                        }
                    }
                    retVal = Structure;
                }
            }

            return retVal;
        }