Exemplo n.º 1
0
 /// <summary>
 /// Get transition by Name and ID
 /// </summary>
 /// <param name="wsnData">Root xml content transision</param>
 /// <param name="name">Name of transition</param>
 /// <param name="id">ID of transition</param>
 /// <returns></returns>
 private static XmlNode getTransition(WSNPNData wsnData, string name, int id)
 {
     return getTransition(wsnData, name, id.ToString());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Embed code for receive place on unicast mode
        /// </summary>
        /// <param name="data">data mode</param>
        /// <param name="channel">channel item</param>
        /// <param name="stringOfSensorConnected">String [...] sensor id connected</param>
        /// <param name="isSensorAbstract">mark sensor abstract</param>
        /// <param name="isChannelAbstract">mark channel abstract</param>
        private static void embedReceiveUnicast(ref WSNPNData data, WSNChannel channel)
        {
            WSNSensor fromSensor = (WSNSensor)channel.From;
            XmlNode transition = getTransition(data, "Receive", channel.ID);

            switch (fromSensor.NodeType)
            {
                //case SensorType.Source:
                //    setXmlNodeData(transition, "Guard", GBK_CHANNEL_SOURCE_RECEIVE);
                //    setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_SOURCE_RECEIVE, fromSensor.ID, channel.ID));
                //    break;

                case SensorType.Intermediate:
                    setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_INTER_RECEIVE, fromSensor.ID));
                    setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_INTER_RECEIVE, fromSensor.ID, channel.ID));
                    break;

                default:
                    break;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get transition by Name and ID
 /// </summary>
 /// <param name="wsnData">Root xml content transision</param>
 /// <param name="name">Name of transition</param>
 /// <param name="id">ID of transition</param>
 /// <returns></returns>
 private static XmlNode getTransition(WSNPNData wsnData, string name, string id)
 {
     return wsnData.transitions.SelectSingleNode(
         String.Format("./Transition[@Name='{0}{1}']", name, id));
 }
Exemplo n.º 4
0
        //******************************************************************
        //*********************** CHANNEL BUILD UTIL **********************
        /// <summary>
        /// Compute center XY of between fromData and toData
        /// </summary>
        /// <param name="fromData"></param>
        /// <param name="toData"></param>
        /// <returns>Float point</returns>
        private static PointF computeCenterXY(WSNPNData fromData, WSNPNData toData)
        {
            PointF p = new PointF();
            float outX = fromData.outNode.pos.x;
            float outY = fromData.outNode.pos.y;
            float inX = toData.inNode.pos.x;
            float inY = toData.inNode.pos.y;

            p.X = Math.Min(outX, inX) + Math.Abs(outX - inX) / 2;
            p.Y = Math.Min(outY, inY) + Math.Abs(outY - inY) / 2;
            return p;
        }
Exemplo n.º 5
0
        private static void compileReceiveMulticast(ref WSNPNData data, WSNChannel channel, string stringOfSensorConnected, bool isSensorAbstract, bool isChannelAbstract)
        {
            WSNSensor fromSensor = (WSNSensor)channel.From;
            SensorType type = fromSensor.NodeType;
            XmlNode transition = getTransition(data, "Receive", channel.ID);

            switch (type)
            {
                //case SensorType.Source:
                //    setXmlNodeData(transition, "Guard", GBK_CHANNEL_SOURCE_RECEIVE);
                //    setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_SOURCE_RECEIVE, fromSensor.ID, channel.ID));
                //    break;

                case SensorType.Intermediate:
                    setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_INTER_RECEIVE, fromSensor.ID));
                    setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_INTER_RECEIVE, fromSensor.ID, channel.ID));
                    break;

                default:
                    break;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Embed code to sensor
        /// </summary>
        /// <param name="data">Sensor data</param>
        /// <param name="sensor">Sensor object</param>
        /// <param name="channels">Channel Object list</param>
        /// <param name="sensorAbstract">Flag sensor has abstracted</param>
        public static void embedCodeToSensor(WSNPNData data, WSNSensor sensor, IList<WSNChannel> channels, bool sensorAbstract)
        {
            XmlNode transition;
            switch (sensor.NodeType)
            {
                case SensorType.Source:
                    if (sensorAbstract && Build.mMode == NetMode.BROADCAST)
                        break;

                    transition = getTransition(data, "Send", sensor.ID);
                    setXmlNodeData(transition, "Guard", GBK_SENSOR_SOURCE_SEND);
                    setXmlNodeData(transition, "Program", initSensorSource(channels, sensor.ID));
                    break;

                case SensorType.Intermediate:
                    if (sensorAbstract)
                        break;

                    // Receive transition
                    transition = getTransition(data, "Receive", sensor.ID);
                    setXmlNodeData(transition, "Program", String.Format(PBK_SENSOR_INTERFULL_RECEIVE, sensor.ID));
                    setXmlNodeData(transition, "Guard", String.Format(GBK_SENSOR_INTERFULL_RECEIVE, sensor.ID));

                    // Send transition
                    transition = getTransition(data, "Send", sensor.ID);
                    setXmlNodeData(transition, "Program", initSensorSend(channels, sensor.ID));

                    // Congestion transition
                    transition = getTransition(data, "Congestion", sensor.ID);
                    setXmlNodeData(transition, "Guard", String.Format(GBK_SENSOR_INTERFULL_CONGESTION, sensor.ID));
                    break;

                case SensorType.Sink:
                    transition = getTransition(data, "Receive", sensor.ID);
                    setXmlNodeData(transition, "Program", String.Format(PBK_SENSOR_SINK_RECEIVE, sensor.ID));
                    break;

                default:
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Combine code for channel 
        /// </summary>
        /// <param name="data">Channel data</param>
        /// <param name="channel">Channel item</param>
        /// <param name="channelAbstract"></param>
        /// <param name="sensorAbstract"></param>
        public static void embedCodeToChannel(WSNPNData data, WSNChannel channel, bool channelAbstract, bool sensorAbstract)
        {
            do
            {
                XmlNode transition; // get xml node to transition then edit content
                XmlNode progNode = null; // get program xml node

                String stringOfSensorConnected = getStringOfNodesConnectedChannel(channel);

                if (channelAbstract)
                {
                    switch (Build.mMode)
                    {
                        case NetMode.BROADCAST:
                        case NetMode.UNICAST:
                            transition = getTransition(data, "Channel", channel.ID);
                            setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_TRANSITION_ASTRACTION, ((WSNSensor)channel.To).ID, channel.ID));
                            break;

                        case NetMode.MULTICAST:
                            StringBuilder prgBuilder = new StringBuilder();
                            prgBuilder.AppendFormat("while (b{0} > 0) {{", channel.ID);
                            prgBuilder.AppendFormat(PBK_CHANNEL_TRANSITION_ASTRACTION, ((WSNSensor)channel.To).ID, channel.ID);

                            foreach (int sensorID in channel.SubIdList)
                            {
                                prgBuilder.Append("\n");
                                prgBuilder.AppendFormat(PBK_CHANNEL_TRANSITION_ASTRACTION, sensorID, channel.ID);
                            }
                            prgBuilder.Append("\n}");

                            transition = getTransition(data, "Channel", channel.ID);
                            setXmlNodeData(transition, "Program", prgBuilder.ToString());
                            break;

                        default:
                            break;
                    }
                    break;
                }

                switch (channel.Type)
                {
                    case ChannelType.Unicast:
                        if (sensorAbstract)
                            embedReceiveUnicast(ref data, channel);

                        // Embed code for transition's send
                        transition = getTransition(data, "Send", channel.ID);
                        setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_SEND, channel.ID, ((WSNSensor)channel.To).ID));
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_SEND, channel.ID));

                        // Embed code for transition's congestion
                        transition = getTransition(data, "Congestion", channel.ID);
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_CONGESTION, channel.ID));
                        break;

                    case ChannelType.Multicast:
                        if (sensorAbstract)
                            compileReceiveMulticast(ref data, channel, stringOfSensorConnected, sensorAbstract, channelAbstract);

                        // Embed code for transition's send
                        transition = getTransition(data, "Send", channel.ID);
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_SEND, channel.ID));
                        setXmlNodeData(transition, "Program", initSensorSendMulti(channel));

                        // Embed cpde for transition's congestion
                        transition = getTransition(data, "Congestion", channel.ID);
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_CONGESTION, channel.ID));
                        break;

                    case ChannelType.Broadcast:
                        // Embed code for transition's send
                        transition = getTransition(data, "Send", channel.ID);
                        setXmlNodeData(transition, "Program", String.Format(PBK_CHANNEL_SEND, channel.ID, ((WSNSensor)channel.To).ID));
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_SEND, channel.ID));

                        // Embed code for transition's congestion
                        transition = getTransition(data, "Congestion", channel.ID);
                        setXmlNodeData(transition, "Guard", String.Format(GBK_CHANNEL_CONGESTION, channel.ID));
                        break;

                    default:
                        break;
                }
            } while (false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Update the PN data to the final output file
        /// </summary>
        /// <param name="data">The input PN data of current item</param>
        /// <param name="places">Places node parent</param>
        /// <param name="transitions">Transitions node parent</param>
        /// <param name="arcs">Arcs node parent</param>
        private void addPNData(WSNPNData data, ref XmlElement places, ref XmlElement transitions, ref XmlElement arcs)
        {
            XmlElement[,] map = new XmlElement[,]
            {
                { data.places, places },
                { data.transitions, transitions },
                { data.arcs, arcs },
            };
            XmlDocumentFragment xFrag = null;

            for (int i = 0; i < map.GetLength(0); i++)
            {
                foreach (XmlElement xml in map[i, 0].ChildNodes)
                {
                    xFrag = mDocOut.CreateDocumentFragment();
                    xFrag.InnerXml = xml.OuterXml;
                    map[i, 1].AppendChild(xFrag);
                }
            }
        }