コード例 #1
0
        public AlgorithmsCalculator()
        {
            DataSet TempSet;
            MyDb = new MySQLClass("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=senseless;UID=root;PASSWORD=admin;OPTION=3;");

            TempSet = FetchData();

            ExecuteAlgorithms(TempSet);

            Console.WriteLine("Done! Press ENTER to exit");
            Console.ReadLine();
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// Initializes the log file
        /// Contains the loop which calls all the required functions for simulation
        /// </summary>
        CalibrationRunner()
        {
            MyDb = new MySQLClass("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=senseless;UID=root;PASSWORD=admin;OPTION=3;");
            string response;

            do
            {
                Console.WriteLine("Using a new batch of data!");
                DataSet TempSet = FetchData();
                ExecuteCalibrationBlindNode(TempSet);
                Console.Write("Process another batch of data? (Y/N) ");
                response = Console.ReadLine();
            } while (response == "Yes" || response == "Y");

            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();
        }
コード例 #3
0
        public void ClusteredTriLaterationTest()
        {
            MySQLClass MyDB = new MySQLClass("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=senseless;UID=root;PASSWORD=admin;OPTION=3;");

            Node BlindNode = new Node("Test", MyDB);
            BlindNode.NewAnchor("1", 50.00, 0.00, 0.00, 1);
            BlindNode.NewAnchor("2", 50.00, 2.00, 0.00, 1);
            BlindNode.NewAnchor("3", 50.00, 2.00, 2.00, 1);

            Node.FilterMethod filterMethod = RangeBasedPositioning.AverageFilter;
            Point expected = new Point(1,1);

            Point actual;

            actual = ClusterTrilateration.CalculatePosition(BlindNode, filterMethod, false);
            //Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #4
0
        /// <summary>
        /// Constructor
        /// Initializes the log file
        /// Contains the loop which calls all the required functions for simulation
        /// </summary>
        public AlgorithmsCalculator()
        {
            //connection string for the database
            MyDb = new MySQLClass("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=senseless;UID=root;PASSWORD=admin;OPTION=3;");
            string response, fileName;

            //add the blind node
            BlindNodes.Add(new Node("11", MyDb));

            Console.Write("Enter the file which you wish to write to: ");
            fileName = Console.ReadLine();
            logger = new StreamWriter(fileName, true);

            //writing the csv header
            logger.WriteLine("idLocalization, time, WsnID, #anchors, CL X, CL X, CL AbsErr, CL RelErr," +
            "WCL X, WCL X, WCL AbsErr, WCL RelErr, MinMax R X, MinMax R Y, MinMax R AbsErr, MinMax R RelErr," +
            "MinMax DR X, MinMax DR Y, MinMax DR AbsErr, MinMax DR RelErr," +
            "TriLat R X, TriLat R Y, TriLat R AbsErr, TriLat R RelErr," +
            "TriLat DR X, TriLat DR Y, TriLat DR AbsErr, TriLat DR RelErr," +
            "LSTriLat R X, LSTriLat R Y, LSTriLat R AbsErr, LSTriLat R RelErr," +
            "LSTriLat DR X, LSTriLat DR Y, LSTriLat DR AbsErr, LSTriLat DR RelErr\n\n");

            do
            {
                //anchors can change of position over time, therefore it is smart to update this as well
                UpdateAnhors();
                //blind can change of position over time, therefore it is smart to update this as well
                UpdateBlind();

                //fetches the RSS data from the database
                Console.WriteLine("Using a new batch of data!");
                DataSet TempSet = FetchData();
                Console.Write("Enter the number of anchor nodes that should be in this dataset: ");
                int numberAnchors = Convert.ToInt32(Console.ReadLine());
                ExecuteAlgorithms(TempSet, numberAnchors);

                Console.Write("Process another batch of data? (Y/N) ");
                response = Console.ReadLine();
            } while (response == "Yes" || response == "Y");

            logger.Close();
            Console.WriteLine("Done! Press ENTER to exit");
            Console.ReadLine();
        }
コード例 #5
0
        /// <summary>
        /// Read the config.txt in the base-directory of the executable and prepare the database-linkers.
        /// Peter: Loads the database info 
        /// </summary>
        private void LoadOptions()
        {
            Options.ReadXml("config.txt"); //Read the options
            try
            {
                //Try to set up the MySQL-database linker
                MySQLConn = new MySQLClass(Options.Tables["ConnectionString"].Select("ID = 'MySQL'")[0]["ConnString"].ToString());
                MySQLAllowedConn = true;
            }
            catch (Exception ex)
            {
                MySQLAllowedConn = false;

                //MySQL connection not available...
                radioButtonMySQL.Enabled = false;
                radioButtonDB2.Checked = true;
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.TargetSite);
            }
            try
            {
                //Try to set up the DB2-database linker
                DB2Conn = new DB2Class(Options.Tables["ConnectionString"].Select("ID = 'DB2'")[0]["ConnString"].ToString());
                DB2AllowedConn = true;
                if (!MySQLAllowedConn)
                    UseMySQLForInfo = false;
            }
            catch (Exception ex)
            {
                DB2AllowedConn = false;
                //DB2 connection not available...
                radioButtonDB2.Enabled = false;
                radioButtonMySQL.Checked = true;
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.TargetSite);
            }

            //Should there be no database in the config-file, don't allow the user to start the controller.
            if ((!DB2AllowedConn) && (!MySQLAllowedConn))
            {
                StartSocketServerButton.Enabled = false;
                radioButtonDB2.Checked = false;
                radioButtonMySQL.Checked = false;
            }
        }
コード例 #6
0
 public Node(string WsnId, MySQLClass MyDb, string AnchorWsnId, double RSS)
 {
     this.MyDb = MyDb;
     this.WsnId = WsnId;
     AddAnchor(AnchorWsnId, RSS);
 }
コード例 #7
0
 public Node(string WsnId, MySQLClass MyDb)
 {
     this.MyDb = MyDb;
     this.WsnId = WsnId;
 }
コード例 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="MySQLConn"></param>
 public Positioning(MySQLClass MySQLConn)
 {
     this.MySQLConn = MySQLConn;
 }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="MySQLConn"></param>
 public ConnectivityBasedPositioning(MySQLClass MySQLConn)
     : base(MySQLConn)
 {
 }
コード例 #10
0
 public CentroidLocalization(string WSNid, MySQLClass MySQLConn)
     : base(MySQLConn)
 {
     this.WSNid = WSNid;
 }
コード例 #11
0
 /// <summary>
 /// Read the config.txt in the base-directory of the executable and prepare the database-linkers.
 /// Peter: Loads the database info 
 /// </summary>
 private void LoadOptions()
 {
     Options.ReadXml("config.txt"); //Read the options
     try
     {
         //Try to set up the MySQL-database linker
         MySQLConn = new MySQLClass(Options.Tables["ConnectionString"].Select("ID = 'MySQL'")[0]["ConnString"].ToString());
         MySQLAllowedConn = true;
     }
     catch (Exception ex)
     {
         MySQLAllowedConn = false;
         //MySQL connection not available...
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.TargetSite);
     }
 }
コード例 #12
0
        /// <summary>
        /// Read the config.txt in the base-directory of the executable and prepare the database-linkers.
        /// Peter: Loads the database info
        /// No use putting this into a try catch, the controller can not run withouth the database or connecction parameters 
        /// </summary>
        private void LoadOptions()
        {
            Options.ReadXml("config.txt");

                MySQLConn = new MySQLClass(Options.Tables["ConnectionString"].Select("ID = 'MySQL'")[0]["ConnString"].ToString());
        }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="WsnId">WsnId of this node</param>
 /// <param name="MyDb">Connectionstring to use for the connection to the database (MySQL!)</param>
 public Node(string WsnId, MySQLClass MyDb)
 {
     this.MyDb = MyDb;
     this.WsnId = WsnId;
     this.position = new Point(0.00, 0.00);
 }
コード例 #14
0
        /// <summary>
        /// Processes the Query 
        /// Retreives the data from database
        /// For use in IQueryable
        /// </summary>
        /// <param name="query">Query</param>
        /// <returns>QueryResult</returns>
        public static QueryResponse Query(Query query, MySQLClass MyDB)
        {
            //decode the Query and perform the SQL queries accordingly
            StringBuilder QueryCmd = new StringBuilder("", 3000);
            DataSet ReturnSet;

            //Query consists of 4 elements: 
            //QueryName: this is always the same in the API and can be ignored for now

            //Ignore the fields in the SQL request, just request them all for now...
            //Fields
            QueryCmd.Append("select idnode, sensor, name, button1, temperature, X, Y, Z  from (select idnode, sensor, name from node) as nd inner join (select * from (select button1, temperature, max(time) as senstime, node as sensnode from sensormeasurements group by node) as sens left outer join (select X, Y, Z, max(time) as loctime, node as locnode from localization group by node) as loc on sens.sensnode = loc.locnode union select * from (select button1, temperature, max(time) as senstime, node as sensnode from sensormeasurements group by node) as sens right outer join (select X, Y, Z, max(time) as loctime, node as locnode from localization group by node) as loc on sens.sensnode = loc.locnode) as sq on nd.idnode = sq.sensnode");


            //Filter
            //Olivier: only ANDs and = 
            //New filter format is for the next Sprint
            //which filters???
            //use TagID, Mac only rest is for later ...
            //use a where in the SQL query
            QueryCmd.Append(" where ");

            //there is a better way to do this but just lazy atm.
            int max = query.Filters.Count, i = 1;

            foreach (string filter in query.Filters.Keys)
            {
                switch (filter)
                {
                    case "Serial":
                        QueryCmd.Append("sensor = " + query.Filters["Serial"]);
                        break;
                    case "TagID":
                        QueryCmd.Append("idnode = " + query.Filters["TagID"]);
                        break;
                    case "Name":
                        QueryCmd.Append("name = " + query.Filters["Name"]);
                        break;
                    default:
                        throw new FaultException("The filter" + filter.ToString() + "is not implemented yet");
                }
                if (i < max)
                    QueryCmd.Append(" AND ");
                i++;
            }

            //Sortby
            if (query.SortBy != null)
                QueryCmd.Append(" order by " + query.SortBy + ";");


            //assemble the SQL results into TagBlinks
            //parse them into the correct type
            TagBlinks tagBlinks = new TagBlinks();

            try
            {
                //Execute the Query
                ReturnSet = MyDB.Query(QueryCmd.ToString());

                //determine the UTC offset
                int hours = TimeZoneInfo.Local.BaseUtcOffset.Hours;
                string timezone = hours >= 0 ? " +" + hours : " " + hours;

                //one for each TagBlink
                foreach (DataRow Row in ReturnSet.Tables[0].Rows)
                {
                    //declare a single tagblink
                    TagBlink tagBlink = new TagBlink();

                    foreach (string field in query.QueryFields)
                    {
                        switch (field)
                        {
                            //convert to the correct formats
                            //add the fields to the Query (select)
                            case "TagID":
                                tagBlink["TagID"] = Row["idnode"].ToString();
                                break;
                            case "Name":
                                tagBlink["Name"] = Row["name"].ToString();
                                break;
                            case "Serial":
                                tagBlink["Serial"] = Row["sensor"].ToString();
                                break;
                            case "Location":
                                tagBlink["Location/X"] = Row["X"].ToString();
                                tagBlink["Location/Y"] = Row["Y"].ToString();
                                break;
                            case "Location/X":
                                tagBlink["Location/X"] = Row["X"].ToString();
                                break;
                            case "Location/Y":
                                tagBlink["Location/Y"] = Row["Y"].ToString();
                                break;
                            case "Buttons":
                                //skip if this boolean is 0
                                tagBlink["Buttons"] = Row["button1"].ToString();
                                break;
                            case "Temperature":
                                tagBlink["Temperature"] = Row["temperature"].ToString();
                                break;
                            case "RTLSBlinkTime":
                                tagBlink["RTLSBlinkTime"] = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + timezone;
                                break;
                            default:
                                throw new FaultException("The field" + field.ToString() + " is not available");
                        }
                    }
                    tagBlinks.Add(tagBlink);
                }
            }
            //Jerry won't like this...
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                throw new FaultException("The database of the WSN could not be accessed properly or the SQL query was unable to execute\n Check the connection parameters");
            }

            QueryResult queryResult = new QueryResult(tagBlinks);
            return new QueryResponse(queryResult);
        }