Exemplo n.º 1
0
        /// <summary>
        /// Gets the nodes status and compares it to the currently stored status.
        /// </summary>
        /// <returns>Bool indicating whether the statuses are different or not</returns>
        private bool CheckStatus()
        {
            //fetch status
            //static part of the message
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getStatus</RequestName>";

            //return the nodeid with sensor as input
            try
            {
                //make the XML string to send
                string selected = listBoxControl.SelectedItem.ToString();
                string nodeid = getNodeID(selected);

                xml_send += "<arg>" + nodeid + "</arg></Request></Requests>";

                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                //set the textfields to the received XML nodes
                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("Status");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        //compare status to changes
                        if (
                            oldChanges.Active == ID.GetElementsByTagName("active")[0].InnerText &&
                            oldChanges.AN == ID.GetElementsByTagName("AN")[0].InnerText &&
                            oldChanges.X == ID.GetElementsByTagName("X")[0].InnerText &&
                            oldChanges.Y == ID.GetElementsByTagName("Y")[0].InnerText &&
                            oldChanges.samplerate == ID.GetElementsByTagName("Samplerate")[0].InnerText &&
                            oldChanges.locrate == ID.GetElementsByTagName("LocRate")[0].InnerText &&
                            oldChanges.leds == ID.GetElementsByTagName("Leds")[0].InnerText &&
                            oldChanges.power == ID.GetElementsByTagName("Power")[0].InnerText &&
                            oldChanges.frequency == ID.GetElementsByTagName("Frequency")[0].InnerText)
                            return false;
                        else
                            return true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                        Console.WriteLine("Some field is not available");
                    }
                }
            }
            //catch the exceptions
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    Disconnect();
                MessageBox.Show("Lost connection to the controller");
            }
            catch (SocketException sockex)
            {
                Console.WriteLine(sockex.Message);
                Console.WriteLine(sockex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                {
                    buttonDisconnect_Click(this, EventArgs.Empty);
                    MessageBox.Show("Lost connection to the controller");
                }
                else
                    MessageBox.Show("The WSN took to long to respond");
            }
            return false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retreives the localization data of the selected node from the controller
        /// </summary>
        private void GetLocData()
        {
            //static part of the message
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getnodeLocInfo</RequestName>";

            //return the nodeid with sensor as input
            try
            {

                if (listBoxLoc.SelectedItem != null)
                {
                    string nodeid;
                    nodeid = getNodeID(listBoxLoc.SelectedItem.ToString());

                    xml_send += "<arg>" + nodeid + "</arg></Request></Requests>";

                    SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                    // Receiving data
                    string xml_receive = socket_client.Connect(xml_send, true);


                    XmlDocument tempdoc = new XmlDocument();
                    tempdoc.LoadXml(xml_receive);

                    XmlNodeList bookList = tempdoc.GetElementsByTagName("Position");
                    foreach (XmlNode node in bookList)
                    {
                        XmlElement ID = (XmlElement)(node);
                        try
                        {
                            textBoxNodeID.Text = ID.GetElementsByTagName("node")[0].InnerText;
                            textBoxANodeID.Text = getTelosbId(ID.GetElementsByTagName("ANode")[0].InnerText);
                            textBoxRSSI.Text = ID.GetElementsByTagName("RSSI")[0].InnerText;
                            textBoxX.Text = ID.GetElementsByTagName("X")[0].InnerText;
                            textBoxY.Text = ID.GetElementsByTagName("Y")[0].InnerText;

                            try
                            {
                                int index = ID.GetElementsByTagName("Time")[0].InnerText.IndexOf('T');
                                textBoxLocUpdate.Text = ID.GetElementsByTagName("Time")[0].InnerText.Substring(index);
                            }
                            catch
                            {
                                Console.WriteLine("No time available for loc info");
                            }

                            try
                            {
                                textBoxZ.Text = ID.GetElementsByTagName("Z")[0].InnerText;
                            }
                            catch
                            {
                                textBoxZ.Text = "N/A";
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Some field is not available");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.TargetSite);
                        }
                    }
                }
                else
                    return;
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    Disconnect();
                MessageBox.Show("Lost connection to the controller");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends any changes to the control tab to the controller.
        /// Fields are accessible according to business rules
        /// An acknowledgment is sent back, this is compared with the current values in the control tab 
        /// to determine if the changes were applied succesfully
        /// </summary>
        private void AcceptChanges()
        {
            DialogResult result = DialogResult.OK;

            //disable status timer to prevent race conditions
            timerStatus.Enabled = false;

            //TODO: needs validation;
            buttonWSNControl.Enabled = false;

            if (
                oldChanges.Active != ActiveProperty || oldChanges.AN != AnchorProperty || oldChanges.X != textBoxControlX.Text ||
                oldChanges.Y != textBoxControlY.Text || oldChanges.locrate != textBoxLocRate.Text || oldChanges.samplerate != textBoxSampleRate.Text ||
                oldChanges.leds != LedsProperty || oldChanges.power != PowerProperty || oldChanges.frequency != FrequencyProperty)
            {
                //we send the WSNactionRequest here
                //static part of the message
                string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><WSNReq xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><WSNReq><RequestAction>";

                //return the nodeid with sensor as input
                try
                {
                    string selected = listBoxControl.SelectedItem.ToString();
                    string nodeid;
                    nodeid = getNodeID(selected);
                    xml_send += "<NodeID>" + nodeid + "</NodeID>";

                    //secondly we must check which fields have changed
                    //we can then add them ass nodes in the XML

                    //specific to our localization scheme
                    if (oldChanges.Active != ActiveProperty)
                        xml_send += "<active>" + ActiveProperty + "</active>";
                    //only process these parameters if the node is active in the localization algorithm
                    if (ActiveProperty == "1")
                    {
                        //if the AN status has changed send it
                        if (oldChanges.AN != AnchorProperty)
                            xml_send += "<AN>" + AnchorProperty + "</AN>";
                        //if the AN status has just changed to AN send all the parameters
                        if (AnchorProperty == "1" && oldChanges.AN != AnchorProperty)
                        {
                            xml_send += "<X>" + textBoxControlX.Text + "</X>";
                            xml_send += "<Y>" + textBoxControlY.Text + "</Y>";
                            xml_send += "<LocRate>" + textBoxLocRate.Text + "</LocRate>";

                            result = MessageBox.Show("Make this node an Anchor Node with these parameters?","Check parameters",MessageBoxButtons.OKCancel);
                        }
                        // if the node was an AN already we should still check if any of the parameters has changed
                        else if (AnchorProperty == "1")
                        {
                            if (oldChanges.X != textBoxControlX.Text)
                                xml_send += "<X>" + textBoxControlX.Text + "</X>";
                            if (oldChanges.Y != textBoxControlY.Text)
                                xml_send += "<Y>" + textBoxControlY.Text + "</Y>";
                            if (oldChanges.locrate != textBoxLocRate.Text)
                                xml_send += "<LocRate>" + textBoxLocRate.Text + "</LocRate>";
                        }
                    }

                    //these field are not unique to the localization algorithm and are thus independent
                    //sensor parameters
                    if (oldChanges.samplerate != textBoxSampleRate.Text)
                        xml_send += "<Samplerate>" + textBoxSampleRate.Text + "</Samplerate>";
                    //leds
                    if (oldChanges.leds != LedsProperty)
                        xml_send += "<Leds>" + LedsProperty + "</Leds>";
                    //radio parameters
                    if (oldChanges.power != PowerProperty)
                        xml_send += "<Power>" + PowerProperty + "</Power>";
                    if (oldChanges.frequency != FrequencyProperty)
                        xml_send += "<Frequency>" + FrequencyProperty + "</Frequency>";

                    xml_send += "</RequestAction></WSNReq></WSNReq>";

                    if (result == DialogResult.OK)
                    {
                    //we can now send the request, we will receive a status message as a response
                    SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                    // Sends: ActionRequest
                    // Receives: Status
                    string xml_receive = socket_client.Connect(xml_send, true);

                    XmlDocument tempdoc = new XmlDocument();
                    tempdoc.LoadXml(xml_receive);

                    if (tempdoc.DocumentElement.Name.ToString() == "Replies") 
                    {
                        DiscardChanges();
                        MessageBox.Show("The WSN did not reply in time");
                        buttonWSNControl.Enabled = true;
                        return;
                    }

                    XmlNodeList bookList = tempdoc.GetElementsByTagName("WSNReply");
                    foreach (XmlNode node in bookList)
                    {
                        XmlElement ID = (XmlElement)(node);
                        try
                        {
                            if (
                            ActiveProperty == ID.GetElementsByTagName("active")[0].InnerText &&
                            AnchorProperty == ID.GetElementsByTagName("AN")[0].InnerText &&
                            textBoxControlX.Text == ID.GetElementsByTagName("X")[0].InnerText &&
                            textBoxControlY.Text == ID.GetElementsByTagName("Y")[0].InnerText &&
                            textBoxSampleRate.Text == ID.GetElementsByTagName("Samplerate")[0].InnerText &&
                            textBoxLocRate.Text == ID.GetElementsByTagName("LocRate")[0].InnerText &&
                            LedsProperty == ID.GetElementsByTagName("Leds")[0].InnerText &&
                            PowerProperty == ID.GetElementsByTagName("Power")[0].InnerText &&
                            FrequencyProperty == ID.GetElementsByTagName("Frequency")[0].InnerText)
                            {
                                //WSN Succesfully replied to our request
                                //changes struct
                                oldChanges.Active = ActiveProperty;
                                oldChanges.AN = AnchorProperty;
                                oldChanges.X = textBoxControlX.Text;
                                oldChanges.Y = textBoxControlY.Text;
                                oldChanges.samplerate = textBoxSampleRate.Text;
                                oldChanges.locrate = textBoxLocRate.Text;
                                oldChanges.power = PowerProperty;
                                oldChanges.frequency = FrequencyProperty;
                                oldChanges.conn = textBoxConn.Text;
                                oldChanges.leds = LedsProperty;

                                Console.WriteLine("WSN succesfully replied");
                                MessageBox.Show("WSN succesfully replied");
                            }
                            else
                            {
                                //WSN did NOT! Succesfully replied to our request
                                //roll back to previous state;
                                DiscardChanges();

                                Console.WriteLine("WSN did not succesfully reply");
                                MessageBox.Show("WSN did not succesfully reply");
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Some field is not available");
                        }
                    }
                }
                }
                //good ol' catches
                catch (ArgumentNullException nullex)
                {
                    Console.WriteLine(nullex.Message);
                    Console.WriteLine(nullex.TargetSite);
                    SocketClient sc = new SocketClient(Port, controllerIP.Text);
                    if (!sc.TryConnection())
                        buttonDisconnect_Click(this, EventArgs.Empty);
                    MessageBox.Show("Lost connection to the controller");
                }
                catch (SocketException sockex)
                {
                    Console.WriteLine(sockex.Message);
                    Console.WriteLine(sockex.TargetSite);
                    SocketClient sc = new SocketClient(Port, controllerIP.Text);
                    if (!sc.TryConnection())
                        Disconnect();
                    MessageBox.Show("Lost connection to the controller");
                }
            }


            timerStatus.Enabled = true;
            buttonWSNControl.Enabled = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retreives the graph data from the controller
        /// </summary>
        private void GetGraphData()
        {
                //static part
                string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>";

                //dynamic part
                if (comboBox1.SelectedItem.ToString() == "RSSI" || comboBox1.SelectedItem.ToString() == "Position")
                    xml_send += "getLocHistoryLast</RequestName>";
                else
                    xml_send += "getHistoryLast</RequestName>";

                //return the nodeid with sensor as input
                try
                {
                    if (comboBox2.SelectedItem != null)
                    {
                        string nodeid = getNodeID(comboBox2.SelectedItem.ToString()); ;

                        xml_send += "<arg>" + nodeid + "</arg>";

                        if (comboBox1.SelectedItem != null)
                        {
                            xml_send += "<arg>" + comboBox1.SelectedItem.ToString() + "</arg><arg>" + comboBoxGraphNumMeasurements.Text + "</arg></Request></Requests>";
                        }
                        else
                            return;
                    }
                    else
                        return;

                    //communication: send the command string to the controller and receive a response
                    SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                    string xml_receive = socket_client.Connect(xml_send, true);


                    //process the reply
                    XmlDocument tempdoc = new XmlDocument();
                    tempdoc.LoadXml(xml_receive);

                    //put the received values in the graph list
                    listViewGraphValues.Items.Clear();
                    XmlNodeList bookList = tempdoc.GetElementsByTagName("MeasurementValue");

                    foreach (XmlNode node in bookList)
                    {
                        string id_Measurement = node.InnerText.ToString();
                        listViewGraphValues.Items.Add(id_Measurement);
                    }

                    CreateGraph(zg1, xml_receive, "number of measurements", comboBox1.SelectedItem.ToString());
                    SetSize();
                }
                catch (ArgumentNullException nullex)
                {
                    Console.WriteLine(nullex.Message);
                    Console.WriteLine(nullex.TargetSite);
                    SocketClient sc = new SocketClient(Port, controllerIP.Text);
                    if (!sc.TryConnection())
                        Disconnect();
                    MessageBox.Show("Lost connection to the controller");
                }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retreives the sensordata from the controller
        /// </summary>
        public void GetSensorData()
        {
            //static part of the message
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getnodeInfo</RequestName>";

            //return the nodeid with sensor as input
            try
            {
                if (listBoxLoc.SelectedItem != null)
                {
                    string nodeid = getNodeID(listBoxLoc.SelectedItem.ToString());

                    xml_send += "<arg>" + nodeid + "</arg></Request></Requests>";

                    SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                    // Receiving data
                    string xml_receive = socket_client.Connect(xml_send, true);


                    XmlDocument tempdoc = new XmlDocument();
                    tempdoc.LoadXml(xml_receive);

                    XmlNodeList bookList = tempdoc.GetElementsByTagName("SensorMeasurements");
                    foreach (XmlNode node in bookList)
                    {
                        XmlElement ID = (XmlElement)(node);
                        try
                        {
                            textBox1.Text = ID.GetElementsByTagName("Node")[0].InnerText;
                            textBox2.Text = ID.GetElementsByTagName("Sensortype")[0].InnerText;
                            textBox3.Text = ID.GetElementsByTagName("Temperature")[0].InnerText;
                            textBox4.Text = ID.GetElementsByTagName("Light")[0].InnerText;
                            textBox5.Text = ID.GetElementsByTagName("Humidity")[0].InnerText;
                            if (ID.GetElementsByTagName("Sensortype")[0].InnerText == "2")
                            {
                                textBox6.Text = ID.GetElementsByTagName("Power")[0].InnerText;
                            }
                            else
                            {
                                textBox6.Text = "N/A";
                            }
                            int index = ID.GetElementsByTagName("Time")[0].InnerText.IndexOf('T');
                            textBoxSensUpdate.Text = ID.GetElementsByTagName("Time")[0].InnerText.Substring(index);
                        }
                        //unable to parse some field
                        catch (Exception ex)
                        {
                            Console.WriteLine("Some field is not available");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.TargetSite);
                        }
                    }
                }
                else
                    return;
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    Disconnect();
                MessageBox.Show("Lost connection to the controller");
            }

        }
Exemplo n.º 6
0
        /// <summary>
        /// Active nodes are selected when they have sent a packet within a given time limit
        /// TODO: process empty string
        /// </summary>
        private void SensorsTimeOut()
        {
            //clear the existing sensors
            Sensorlijst.Clear();
            listBoxControl.Items.Clear();
            listBoxLoc.Items.Clear();
            comboBox2.Items.Clear();
            
            //Get the TimeOut timespan and parse it into the correct string format (d hh:mm:ss)
            //TimeSpan TimeOut = new TimeSpan(maskedTextBox1.Text;
            //string TimeOutString = TimeOut.Days.ToString() + " " + TimeOut.Hours.ToString() + ":" + TimeOut.Minutes.ToString() + ":" + TimeOut.Seconds.ToString();
            //string TimeOut = maskedTextBox1.Text;
            //TimeOu
            //TimeSpan TimeOut = new TimeSpan();

            //string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getTimeOutSensors</RequestName><arg>" + TimeOutString + "</arg></Request></Requests>";
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getTimeOutSensors</RequestName><arg>" + maskedTextBox1.Text + "</arg></Request></Requests>";
            try
            {
                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("Sensor");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        string sensor = ID.GetElementsByTagName("sensor")[0].InnerText;
                        string idnode = ID.GetElementsByTagName("idnode")[0].InnerText;
                        Sensorlijst.Add(new SensorNames(sensor, idnode));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.TargetSite);
                    }
                }

                Sensorlijst.ForEach(delegate(SensorNames SN)
                {
                    comboBox2.Items.Add(SN.Sensorname);
                    listBoxLoc.Items.Add(SN.Sensorname);
                    listBoxControl.Items.Add(SN.Sensorname);
                });
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch (Exception ex )
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.TargetSite);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Helper method for retreiving the WSNid of the framework
        /// </summary>
        /// <param name="selected">
        /// node id, unique identifier within Senseless
        /// </param>
        /// <returns>
        /// The MAC or TOSid of the mote
        /// </returns>
        private string getTelosbId(string selected)
        {
            string sensorname;
            foreach (SensorNames telosb in Sensorlijst)
            {
                if (telosb.id == selected)
                {
                    sensorname = telosb.Sensorname;
                    return sensorname;
                }
            }
            try
            {
                string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getWSNID</RequestName><arg>" + selected + "</arg></Request></Requests>";

                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("WSNID");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        string sensor = ID.GetElementsByTagName("sensor")[0].InnerText;
                        Sensorlijst.Add(new SensorNames(sensor, selected));
                        return sensor;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine("Node id not found in DB");
                    }
                }
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    Disconnect();
                MessageBox.Show("Lost connection to the controller");
            }
            catch { }
            return "N/A";
        }
Exemplo n.º 8
0
        private void Connect()
        {
            Port = Convert.ToInt32(controllerPort.Text);
            SocketClient sc = new SocketClient(Port, controllerIP.Text);

            if (sc.TryConnection())
            {
                timerSensor.Enabled = true;
                timerLoc.Enabled = true;

                //GUI tasks
                buttonConnect.Enabled = false;
                buttonDisconnect.Enabled = true;

                //Disable the connection fields
                controllerIP.Enabled = false;
                controllerPort.Enabled = false;

                toolStripStatusLabel.Text = "Connected to controller at IP " + controllerIP.Text + ", port " + controllerPort.Text;

                //Sensorfetch
                if (radioButtonGetSensors.Checked == true)
                    GetSensors();
                else if (radioButtonDiscovery.Checked == true)
                    timerSensorFetch.Enabled = true;
                else
                    SensorsTimeOut();
            }
            else
            {
                Console.WriteLine("Incorrect connection parameters");
                MessageBox.Show("Could not reach the controller!\n Are the connection parameters correct?");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Fetches all the motes in the databases
        /// Has NO offline detection mechanism
        /// </summary>
        private void GetSensors()
        {
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getAllTelosb</RequestName></Request></Requests>";
            try
            {
                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("Sensor");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        string sensor = ID.GetElementsByTagName("sensor")[0].InnerText;
                        string idnode = ID.GetElementsByTagName("idnode")[0].InnerText;
                        Sensorlijst.Add(new SensorNames(sensor, idnode));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.TargetSite);
                    }
                }

                Sensorlijst.ForEach(delegate(SensorNames SN)
                {
                    comboBox2.Items.Add(SN.Sensorname);
                    listBoxLoc.Items.Add(SN.Sensorname);
                    listBoxControl.Items.Add(SN.Sensorname);
                });
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch { }
        }
Exemplo n.º 10
0
        ///<summary>
        ///Helper method for retreiving the nodeid of the framework
        /// </summary>
        /// <param name="selected">
        /// The MAC or TOSid of the mote
        /// </param>
        /// <returns>
        /// node id, unique identifier within Senseless
        /// </returns>
        private string getNodeID(string selected)
        {
            //first search local for the nodeid
            string nodeid;
            foreach (SensorNames telosb in Sensorlijst)
            {
                if (telosb.Sensorname == selected)
                {
                    nodeid = telosb.id;
                    return nodeid;
                }
            }
            try
            {
                //generate string
                string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getNodeid</RequestName><arg>" + selected + "</arg></Request></Requests>";

                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                //process reply
                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("NodeIDs");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        string idnode = ID.GetElementsByTagName("idnode")[0].InnerText;
                        Sensorlijst.Add(new SensorNames(selected, idnode));
                        return idnode;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine("Node id not found in DB");
                    }
                }
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch { }
            return "N/A";
        }
Exemplo n.º 11
0
        /// <summary>
        /// Occurs when the apply changes button is click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonWSNControl_Click(object sender, EventArgs e)
        {
            //TODO: needs validation;
            panelControl.Enabled = false;
            buttonWSNControl.Enabled = false;

            //we send the WSNactionRequest here
            //first
            //static part of the message
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><WSNReq xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><WSNReq><RequestAction>";

            //return the nodeid with sensor as input
            try
            {
                string selected = listBoxControl.SelectedItem.ToString();
                string nodeid;
                nodeid = getNodeID(selected);
                xml_send += "<NodeID>" + nodeid + "</NodeID>";

                //secondly we must check which fields have changed
                //we can then add them ass nodes in the XML

                //specific to our localization scheme
                if (oldChanges.Active != ActiveProperty)
                    xml_send += "<active>" + ActiveProperty + "</active>";
                //only process these parameters if the node is active in the localization algorithm
                if (ActiveProperty == "1")
                {
                    if (oldChanges.AN != AnchorProperty)
                        xml_send += "<AN>" + AnchorProperty + "</AN>";
                    //only process these parameters if the node is an Anchor Node
                    if (AnchorProperty == "0")
                    {
                        if (oldChanges.X != textBoxControlX.Text)
                        {
                            xml_send += "<X>" + textBoxControlX.Text + "</X>";
                            if ((Convert.ToInt32(textBoxControlX.Text)) < (Convert.ToInt32(textBoxXmin.Text)) || (Convert.ToInt32(textBoxControlX.Text)) > (Convert.ToInt32(textBoxXmax.Text)))
                            {
                                MessageBox.Show("X is not within bounds");
                                textBoxControlX.Text = oldChanges.X;
                                return;
                            }
                        }
                        if (oldChanges.Y != textBoxControlY.Text)
                        {
                            xml_send += "<Y>" + textBoxControlY.Text + "</y>";
                            if ((Convert.ToInt32(textBoxControlX.Text)) < (Convert.ToInt32(textBoxYmin)) || (Convert.ToInt32(textBoxControlX.Text)) > (Convert.ToInt32(textBoxYmax)))
                            {
                                MessageBox.Show("Y is not within bounds");
                                textBoxControlX.Text = oldChanges.Y;
                                return;
                            }
                        }
                        if (oldChanges.locrate != textBoxLocRate.Text)
                        {
                            xml_send += "<LocRate>" + textBoxLocRate.Text + "</LocRate>";
                            if ((Convert.ToInt32(textBoxLocRate)) < (Convert.ToInt32(textBoxLocRateMin)) || (Convert.ToInt32(textBoxLocRate)) > (Convert.ToInt32(textBoxLocRateMax)))
                            {
                                MessageBox.Show("LocRate is not within bounds");
                                textBoxControlX.Text = oldChanges.locrate;
                                return;
                            }
                        }
                    }
                }

                //these field are not unique to the localization algorithm and are thus independent
                if (oldChanges.samplerate != textBoxSampleRate.Text)
                {
                    xml_send += "<Samplerate>" + textBoxSampleRate.Text + "</Samplerate>";
                    if ((Convert.ToInt32(textBoxSampleRate)) < (Convert.ToInt32(textBoxSensorRateMin)) || (Convert.ToInt32(textBoxSampleRate)) > (Convert.ToInt32(textBoxSensorRateMax)))
                    {
                        MessageBox.Show("SampleRate is not within bounds");
                        textBoxControlX.Text = oldChanges.samplerate;
                        return;
                    }
                }
                if (oldChanges.leds != LedsProperty)
                    xml_send += "<Leds>" + LedsProperty + "</Leds>";
                if (oldChanges.power != PowerProperty)
                    xml_send += "<Power>" + PowerProperty + "</Power>";
                if (oldChanges.frequency != FrequencyProperty)
                    xml_send += "<Frequency>" + FrequencyProperty+ "</Frequency>";

                xml_send += "</RequestAction></WSNReq></WSNReq>";

                //we can now send the request, we will receive a status message as a response
                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Sends: ActionRequest
                // Receives: Status
                string xml_receive = socket_client.Connect(xml_send, true);

                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("Status");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        if (
                        ActiveProperty == ID.GetElementsByTagName("active")[0].InnerText &&
                        AnchorProperty == ID.GetElementsByTagName("AN")[0].InnerText &&
                        textBoxControlX.Text == ID.GetElementsByTagName("X")[0].InnerText &&
                        textBoxControlY.Text == ID.GetElementsByTagName("Y")[0].InnerText &&
                        textBoxSampleRate.Text == ID.GetElementsByTagName("Samplerate")[0].InnerText &&
                        textBoxLocRate.Text == ID.GetElementsByTagName("LocRate")[0].InnerText &&
                        LedsProperty == ID.GetElementsByTagName("Leds")[0].InnerText &&
                        PowerProperty == ID.GetElementsByTagName("Power")[0].InnerText &&
                        FrequencyProperty == ID.GetElementsByTagName("Frequency")[0].InnerText)
                        {
                            //WSN Succesfully replied to our request
                            //changes struct
                            oldChanges.Active = ActiveProperty;
                            oldChanges.AN = AnchorProperty;
                            oldChanges.X = textBoxControlX.Text;
                            oldChanges.Y = textBoxControlY.Text;
                            oldChanges.samplerate = textBoxSampleRate.Text;
                            oldChanges.locrate = textBoxLocRate.Text;
                            oldChanges.power = PowerProperty;
                            oldChanges.frequency = FrequencyProperty;
                            oldChanges.conn = textBoxConn.Text;
                            oldChanges.leds = LedsProperty;

                            Console.WriteLine("WSN succesfully replied");
                            MessageBox.Show("WSN succesfully replied");
                        }
                        else
                        {
                            //WSN did NOT! Succesfully replied to our request
                            //roll back to previous state;
                            ActiveProperty = oldChanges.Active;
                            AnchorProperty = oldChanges.AN;
                            textBoxControlX.Text = oldChanges.X;
                            textBoxControlY.Text = oldChanges.Y;
                            textBoxSampleRate.Text = oldChanges.samplerate;
                            textBoxLocRate.Text = oldChanges.locrate;
                            FrequencyProperty = oldChanges.power;
                            FrequencyProperty = oldChanges.frequency;
                            textBoxConn.Text = oldChanges.conn;
                            LedsProperty = oldChanges.leds;

                            Console.WriteLine("WSN did not succesfully reply");
                            MessageBox.Show("WSN did not succesfully reply");
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Some field is not available");
                    }

                }
            }
            //good ol' catches
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch (SocketException sockex)
            {
                Console.WriteLine(sockex.Message);
                Console.WriteLine(sockex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.TargetSite);
            }

            panelControl.Enabled = true;
            buttonWSNControl.Enabled = true;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the statusdata off the selected node from the controller
        /// </summary>
        private void GetStatData()
        {
            //static part of the message
            string xml_send = @"<?xml version=""1.0"" standalone=""yes""?><Requests xmlns:xsi=""='http://www.w3.org/2001/XMLSchema-instance'""  xmlns=""xmlns='http://tempuri.org/Requests.xsd\'""><Request><RequestName>getStatus</RequestName>";

            //return the nodeid with sensor as input
            try
            {
                string selected = listBoxControl.SelectedItem.ToString();
                string nodeid = getNodeID(selected);

                xml_send += "<arg>" + nodeid + "</arg></Request></Requests>";

                SocketClient socket_client = new SocketClient(Port, controllerIP.Text);
                // Receiving data
                string xml_receive = socket_client.Connect(xml_send, true);

                XmlDocument tempdoc = new XmlDocument();
                tempdoc.LoadXml(xml_receive);

                XmlNodeList bookList = tempdoc.GetElementsByTagName("Status");
                foreach (XmlNode node in bookList)
                {
                    XmlElement ID = (XmlElement)(node);
                    try
                    {
                        //assign the values of the textboxes
                        ActiveProperty = ID.GetElementsByTagName("active")[0].InnerText;
                        AnchorProperty = ID.GetElementsByTagName("AN")[0].InnerText;

                        textBoxControlX.Text = ID.GetElementsByTagName("X")[0].InnerText;
                        textBoxControlY.Text = ID.GetElementsByTagName("Y")[0].InnerText;
                        textBoxSampleRate.Text = ID.GetElementsByTagName("Samplerate")[0].InnerText;
                        textBoxLocRate.Text = ID.GetElementsByTagName("LocRate")[0].InnerText;

                        //set the led bitmask
                        LedsProperty = ID.GetElementsByTagName("Leds")[0].InnerText;

                        PowerProperty = ID.GetElementsByTagName("Power")[0].InnerText;
                        FrequencyProperty = ID.GetElementsByTagName("Frequency")[0].InnerText;

                        textBoxConn.Text = ID.GetElementsByTagName("Conn")[0].InnerText;

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                        Console.WriteLine("Some field is not available");
                    }

                    //backup these values in the changes struct
                    oldChanges.Active = ActiveProperty;
                    oldChanges.AN = AnchorProperty;

                    oldChanges.X = textBoxControlX.Text;
                    oldChanges.Y = textBoxControlY.Text;
                    oldChanges.samplerate = textBoxSampleRate.Text;
                    oldChanges.locrate = textBoxLocRate.Text;

                    oldChanges.power = PowerProperty;
                    oldChanges.frequency = FrequencyProperty;
                    oldChanges.conn = textBoxConn.Text;

                    oldChanges.leds = LedsProperty;
                }
            }
            catch (ArgumentNullException nullex)
            {
                Console.WriteLine(nullex.Message);
                Console.WriteLine(nullex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                    buttonDisconnect_Click(this, EventArgs.Empty);
                MessageBox.Show("Lost connection to the controller");
            }
            catch (SocketException sockex)
            {
                Console.WriteLine(sockex.Message);
                Console.WriteLine(sockex.TargetSite);
                SocketClient sc = new SocketClient(Port, controllerIP.Text);
                if (!sc.TryConnection())
                {
                    buttonDisconnect_Click(this, EventArgs.Empty);
                    MessageBox.Show("Lost connection to the controller");
                }
                else
                    MessageBox.Show("The WSN took to long to respond");
            }
            catch
            {
                Console.WriteLine("Error in getStatData");
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Event for the connect button in the options tab
        /// Allows the user to connect & disconnect to the controller and set various parameters
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            Port = Convert.ToInt32(controllerPort.Text);
            SocketClient sc = new SocketClient(Port, controllerIP.Text);

            if (sc.TryConnection())
            {
                timer1.Enabled = true;
                timerLoc.Enabled = true;

                //GUI tasks
                buttonConnect.Enabled = false;
                buttonDisconnect.Enabled = true;

                //Disable the connection fields
                controllerIP.Enabled = false;
                controllerPort.Enabled = false;

                toolStripStatusLabel.Text = "Connected to controller at IP " + controllerIP.Text + ", port " + controllerPort.Text;

                //Sensorfetch
                //TODO: give the user the choice
                //discovery
                if (radioButtonGetSensors.Checked == true)
                    GetSensors();
                else if (radioButtonDiscovery.Checked == true)
                    timerDiscovery.Enabled = true;
                else
                    //not implemented yet
                    SensorsTimeOut();
            }
            else
            {
                Console.WriteLine("Incorrect connection parameters");
                MessageBox.Show("Could not reach the controller!\n Are the connection parameters correct?");
            }
        }
Exemplo n.º 14
0
        //-----------------------------------------------------------------
        //
        //Options tab
        //
        //connect button
        //corrently the connection data is not checked, if it is incorrect the application will fail
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            Port = Convert.ToInt32(controllerPort.Text);
            SocketClient sc = new SocketClient(Port, controllerIP.Text);

            if (sc.TryConnection())
            {
                timer1.Enabled = true;
                timerLoc.Enabled = true;
                //timerDiscovery.Enabled = true;

                //GUI tasks
                buttonConnect.Enabled = false;
                buttonDisconnect.Enabled = true;

                controllerIP.Enabled = false;
                controllerPort.Enabled = false;

                toolStripStatusLabel.Text = "Connected to controller at IP " + controllerIP.Text + ", port " + controllerPort.Text;

                //discovery
                GetSensors();
            }
            else
            {
                Console.WriteLine("Incorrect connection parameters");
                MessageBox.Show("Could not reach the controller!");
            }
        }