//calculate the position(xpos,ypos) public int[] calculatePos(PersonInformation p) { int[] pos = new int[2]; List <Round> round = new List <Round>(); if (p.getNumList() == 3) { List <ArrayList> posList = p.getList(); for (int i = 0; i < 3; i++) { double distance = formula((double)posList[i][0]); int roomx = 0; int roomy = 0; //find xpos and ypos of room for (int j = 0; j < roomList.Count; j++) { if ((int)roomList[j][0] == (int)posList[i][2]) { roomx = (int)roomList[j][1]; roomy = (int)roomList[j][2]; break; } } //find xpos and ypos of antenna int antennax = 0; int antennay = 0; for (int k = 0; k < atennuList.Count; k++) { if ((int)atennuList[k][0] == (int)posList[i][1]) { antennax = (int)atennuList[k][1]; antennay = (int)atennuList[k][2]; break; } } int x = roomx + antennax; int y = roomy + antennay; Round r = new Round(x * 20, y * 20, distance); round.Add(r); } Coordinate coor = Centroid.triCentroid((Round)round[0], (Round)round[1], (Round)round[1]); if (coor != null) { pos[0] = (int)((double)coor.getX()); pos[1] = (int)((double)coor.getY()); return(pos); } pos[0] = -1; pos[1] = -1; return(pos); } pos[0] = -1; pos[1] = -1; return(pos); }
public MainWindow() { InitializeComponent(); this.Closing += Window_Closing; //将阅读器与房间对应起来 模拟 roomNameList.Add("111111111111"); roomNameList.Add("222222222222"); roomNameList.Add("333333333333"); roomNameList.Add("444444444444"); roomNameList.Add("555555555555"); roomNameList.Add("666666666666"); roomNameList.Add("777777777777"); roomNameList.Add("888888888888"); roomNameList.Add("999999999999"); roomNameList.Add("AAAAAAAAAAAA"); roomNameList.Add("BBBBBBBBBBBB"); roomNameList.Add("CCCCCCCCCCCC"); //initialize reader for (int i = 0; i < roomNameList.Count; i++) { ArrayList reader = new ArrayList(); reader.Add(roomNameList[i]); reader.Add(i / 3);//(0,1,2)--0/(1,2,3)--1/(3,4,5)--2/(4,5,6)--3以此类推,实际上12个房间需要36个阅读器 readerList.Add(reader); } //initialize room[the roomId is from 1-12] //1-7 行号2 餐厅这一排21 8-12 行号42 for (int i = 1; i < 7; i++) { ArrayList room = RoomOrAntennaInformationList(i, 2, 1 + (i - 1) * 20); roomList.Add(room); } for (int i = 7; i < 13; i++) { ArrayList room = RoomOrAntennaInformationList(i, 42, (20 * (i - 7) + 1)); roomList.Add(room); } //initialize antenna for (int i = 0; i < 9; i++) { ArrayList antenna = RoomOrAntennaInformationList(i + 1, antennaX[i], antennaY[i]); atennuList.Add(antenna); } //初始化每个人的信息。 for (int i = 0; i < 5; i++) { PersonInformation p = new PersonInformation(id[i], 0, 0, 0); array1.Add(p); } for (int i = 2; i < 7; i++) { Image image = new Image(); Imagelist.Add(image); grad1.Children.Add(image); image.Source = new BitmapImage(new Uri(@"Resources\" + i + ".jpg", UriKind.Relative)); image.Stretch = Stretch.None; } timer.Interval = TimeSpan.FromMilliseconds(1000); timer.Tick += new EventHandler(rssiDetection); //你的事件 timer.Start(); /** * //假设将12个阅读器全部加入到里面 * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * MacList.Add("SpeedwayR-xx-xx-xx"); * * //初始化阅读器 * for (int i = 0; i < 12; i++) * { * SpeedwayReader Reader = new SpeedwayReader(); * ReaderList.Add(Reader); * Console.WriteLine(ReaderList[i]); * * try * { * // Connect to the reader. * // Replace "SpeedwayR-xx-xx-xx" with your * // reader's host name or IP address. * SpeedwayReader readertemp = (SpeedwayReader)ReaderList[i]; * string macString = (String)MacList[i]; * readertemp.Connect(macString); * * // Remove all settings from the reader. * readertemp.ClearSettings(); * * // Get the factory default settings * // We'll use these as a starting point * // and then modify the settings we're * // interested in * Settings settings = readertemp.QueryFactorySettings(); * settings.Report.IncludeAntennaPortNumber = true; * settings.Report.Mode = ReportMode.Individual; * readertemp.ApplySettings(settings); * * // Assign the TagsReported handler. * // This specifies which function to call * // when tags reports are available. * // This function will in turn call a delegate * // to update the UI (Listbox). * readertemp.TagsReported += new EventHandler<TagsReportedEventArgs>(OnTagsReported); * } * catch (OctaneSdkException ex) * { * // An Octane SDK exception occurred. Handle it here. * System.Diagnostics.Trace.WriteLine("An Octane SDK exception has occured : {0}", ex.Message); * } * catch (Exception ex) * { * System.Diagnostics.Trace.WriteLine("An exception has occured : {0}", ex.Message); * } * } */ }