示例#1
0
        protected override Route LoadRoute(XmlElement element)
        {
            WSNChannel route = new WSNChannel(null, null);

            route.LoadFromXML(element, this);

            return(route);
        }
示例#2
0
        public ChannelEditForm(Route route, LTSCanvas canvas, NetMode mode)
        {
            do
            {
                InitializeComponent();

                mChannel = (WSNChannel)route;
                mMode = mode;
                mCanvas = canvas;

                List<LTSCanvas.CanvasItemData> canvasItems = canvas.itemsList;
                foreach (LTSCanvas.CanvasItemData itemData in canvasItems)
                {
                    if (itemData.Item is StateItem)
                    {
                        this.cmbSource.Items.Add(itemData.Item);
                        this.cmbDest.Items.Add(itemData.Item);

                        if (itemData.Item.Equals(route.From))
                            this.cmbSource.SelectedItem = itemData.Item;

                        if (itemData.Item.Equals(route.To))
                            this.cmbDest.SelectedItem = itemData.Item;
                    }
                }

                if (!mMode.Equals(NetMode.MULTICAST))
                {
                    txtSensorsConn.Visible = false;
                    lblSensorsConn.Visible = false;
                    break;
                }

                StringBuilder subConn = new StringBuilder();
                subConn.Append(((WSNSensor)mChannel.To).ID.ToString());

                foreach (int item in mChannel.SubIdList)
                    subConn.Append("," + item);

                txtSensorsConn.Text = subConn.ToString();
            } while (false);
        }
示例#3
0
        protected override Route LoadRoute(XmlElement element)
        {
            WSNChannel route = new WSNChannel(null, null);
            route.LoadFromXML(element, this);

            return route;
        }
示例#4
0
        /// <summary>
        /// Initialize code for sensor in multicast mode
        /// </summary>
        /// <param name="channel">Channel object</param>
        /// <returns>Program's code of transition source</returns>
        private static string initSensorSendMulti(WSNChannel channel)
        {
            StringBuilder ret = new StringBuilder();
            ret.Append("var sub;");
            ret.AppendFormat(PBK_CHANNEL_MULTI_SEND, channel.ID, ((WSNSensor)channel.To).ID);

            foreach (int sensorID in channel.SubIdList)
                ret.AppendFormat(PBK_CHANNEL_MULTI_SEND, channel.ID, sensorID);

            ret.AppendFormat("\n\nif (b{0} > 0)\n\tMain{0} = 1;", channel.ID);
            return ret.ToString();
        }
示例#5
0
        /// <summary>
        /// Get [x,y,z...] for nodes connected to channel
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        private static String getStringOfNodesConnectedChannel(WSNChannel channel)
        {
            StringBuilder sbuilder = new StringBuilder();
            sbuilder.Append("[");
            sbuilder.Append(((WSNSensor)channel.To).ID);

            if (Build.mMode.Equals(NetMode.BROADCAST))
                foreach (int item in channel.SubIdList)
                    sbuilder.Append("," + item);

            sbuilder.Append("]");
            return sbuilder.ToString();
        }
示例#6
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;
            }
        }
示例#7
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;
            }
        }
示例#8
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);
        }