Exemplo n.º 1
0
        public UI()
        {
            InitializeComponent();
              if (!Constant.TESTING)
              {
            xb = new Xbee();
            xb.open();
            xb.enter_api_mode();
              }

              //Initiates C# built-in double buffering
              this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

              this.Invalidate();
              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength(new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              loc = new ArrayBasedLocations(d.load());

              panel1.Visible = false;

              this.room = new BasicRoom();
              this.room.location = new Point(panel1.Location.X, panel1.Location.Y);
              room.size = new Size(panel1.Size.Width, panel1.Size.Height);

              // Initialized displayed orientations
              display_north = true;
              display_east = true;
              display_south = true;
              display_west = true;

              generate_new_location_list_from_signal_strength();
              sld_cluster_radius.set_range(0, 6);
              sld_cluster_radius.value = 1;
              this.clusters = Clusterer.cluster(this.locations, (float)sld_cluster_radius.value);
              sld_num_clusters.set_range(1, clusters.Count);
              sld_num_clusters.value = sld_num_clusters.Maximum;
              lbl_cluster_radius.Text = sld_cluster_radius.value.ToString();
              lbl_num_clusters.Text = sld_num_clusters.value.ToString();

              // Initialize renderer type
              this.room.set_renderer_type(Constant.HEAT_MAP_RENDERER);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Xbee xb = new Xbee();
              xb.open();
              xb.enter_api_mode();

              int[] valid_signals = new int[Constant.NUM_NODES + 1];
              for (int i = 0; i < 10000; i++)
              {
            Packet packet = xb.read_packet();
            uint address = packet.get_address();
            Console.WriteLine("{0}, {1}", (address % Constant.NODE_1_ADDR), packet.get_message_length());
            if ((address >= Constant.NODE_1_ADDR) && (address <= Constant.NODE_7_ADDR + 1))
            {
              valid_signals[address % Constant.NODE_1_ADDR]++;
            }
              }

              if(valid_signals[8] > 0)
            Console.WriteLine("Worked");
              else
            Console.WriteLine("Did not work");

              //DataCompiler comp = new DataCompiler();
              //comp.create_empty_text_files_for_positions_not_tested();

              //string[] test;
              //test = SerialPort.GetPortNames();
              //for(int i = 0; i < test.Length; i++)
              //{
              //  if(String.Compare(test[i], "COM3") != 0)
              //    Console.WriteLine("{0}", test[i]);
              //}

              //run_test();
              //run_test("test_data_2/");
        }
 public SignalStrengthReceiver(Xbee xb)
 {
     this.xb = xb;
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Boolean display_north = false;
              Boolean display_east = false;
              Boolean display_south = false;
              Boolean display_west = false;

              PersistedDataBySignalStrength d = new PersistedDataBySignalStrength
            (new FileStream("resources/generated_data_by_signal_strength.txt", FileMode.Open, FileAccess.Read));
              ILocations loc = new ArrayBasedLocations(d.load());
              List<Location> locations = new List<Location>();
              List<Location> l = new List<Location>();

              string orientation = "";
              int diameter = -1;
              if(args.Length == 2)
              {
            orientation = args[0];
            try
            {
              diameter = Convert.ToInt32(args[1]);
            }
            catch
            {
              Console.WriteLine(program_usage("A valid cluster radius was not entered."));
              return;
            }
              }
              else
              {
            Console.WriteLine(program_usage("Incorrect number of arguments specified."));
            return;
              }

              // Determine Orientation
            if      (orientation == "North"   || orientation == "north")
              display_north = true;
            else if (orientation == "South"   || orientation == "south")
              display_south = true;
            else if (orientation == "East"    || orientation == "east")
              display_east  = true;
            else if (orientation == "West"    || orientation == "west")
              display_west  = true;
            else if (orientation == "Unknown" || orientation == "unknown")
            {
              display_north = true;
              display_east  = true;
              display_south = true;
              display_west  = true;
            }
            else
            {
              Console.WriteLine(program_usage("A valid orientation was not entered."));
              return;
            }

              if (!Constant.TESTING)  //Can turn on/off real code and test code
              {
            Xbee xb = new Xbee();
            xb.open();
            xb.enter_api_mode();

            SignalStrengthReceiver receiver;
            if (xb.get_valid_signal_strengths()[Constant.NUM_NODES] > 0)
            {
              receiver = new RelaySignalStrengthReceiver(xb);
            }
            else
            {
              receiver = new DirectSignalStrengthReceiver(xb);
            }

            uint[] avg_signals = new uint[8];

            avg_signals = receiver.get_avg_signal_strength(2, 200);

            if (display_north)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.North, avg_signals[i]));
            }
            if (display_south)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.South, avg_signals[i]));
            }
            if (display_east)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.East, avg_signals[i]));
            }
            if (display_west)
            {
              for (int i = 0; i < avg_signals.Length; i++)
            l.AddRange(loc.get_locations(i, Orientation.West, avg_signals[i]));
            }
              }
              else
              {
            //Test Code
            if (display_north)
            {
              l.AddRange(loc.get_locations(0, Orientation.North, 55));
              l.AddRange(loc.get_locations(1, Orientation.North, 55));
              l.AddRange(loc.get_locations(2, Orientation.North, 55));
              l.AddRange(loc.get_locations(3, Orientation.North, 55));
            }
            if (display_south)
            {
              l.AddRange(loc.get_locations(0, Orientation.South, 60));
              l.AddRange(loc.get_locations(1, Orientation.South, 60));
              l.AddRange(loc.get_locations(2, Orientation.South, 60));
              l.AddRange(loc.get_locations(3, Orientation.South, 60));
            }
            if (display_east)
            {
              l.AddRange(loc.get_locations(0, Orientation.East, 71));
              l.AddRange(loc.get_locations(1, Orientation.East, 71));
              l.AddRange(loc.get_locations(2, Orientation.East, 71));
              l.AddRange(loc.get_locations(3, Orientation.East, 71));
            }
            if (display_west)
            {
              l.AddRange(loc.get_locations(0, Orientation.West, 59));
              l.AddRange(loc.get_locations(1, Orientation.West, 59));
              l.AddRange(loc.get_locations(2, Orientation.West, 59));
              l.AddRange(loc.get_locations(3, Orientation.West, 59));
            }
              }

              l.Sort();
              locations = l;

              List<Cluster> clusters = Clusterer.cluster(locations, diameter);
              List<PositionWithProb> loc_probs = new List<PositionWithProb>();
              for (int i = 0; i < clusters.Count; i++)
              {
            loc_probs.Add(new PositionWithProb(clusters[i].location, clusters[i].probability));
              }
              PositionWithProbComparer compaerer = new PositionWithProbComparer();
              loc_probs.Sort(compaerer);

              Console.WriteLine();
              Console.WriteLine("{0} {1, 16}", "Position", "Probability");
              Console.WriteLine("{0} {1, 13}", "-----------", "-----------");
              Console.WriteLine("{0, 4} {1, 5}", "X", "Y");
              for (int i = 0; i < clusters.Count; i++)
              {
            Console.WriteLine("{0, 4:0.00}, {1, 5:0.00}: {2, 9:0.000}%", loc_probs[i].location.x,
              loc_probs[i].location.y, loc_probs[i].probability * 100);
              }
        }
 public RelaySignalStrengthReceiver(Xbee xb)
     : base(xb)
 {
 }
Exemplo n.º 6
0
        private void data_collection_Load(object sender, EventArgs e)
        {
            lst_orientation.SetSelected(0, true);

              xb = new Xbee();
              xb.open();
              xb.enter_api_mode();
              xb.close();
        }
 public DirectSignalStrengthReceiver(Xbee xb)
     : base(xb)
 {
 }