Exemplo n.º 1
0
        /// <summary>
        /// Handle a request for information about a device
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        void GetDevice(IARequest request, IAResponse response)
        {
            String deviceIdentifier = request.Parameters["identifier"];

            // Find the associated device in the Current Devices
            Device device = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier));

            if (device == null)
            {
                response.StatusCode = 404;
                return;
            }

            // Get the intermediateDevice for serialization
            IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(device);

            if (intermediateDevice == null)
            {
                //TODO: Should this status code be different, to reflect that the device exists but couldn't be returned due to incompleteness?
                response.StatusCode = 404;
                return;
            }

            // Respond with the device
            response.SetBodyWith(intermediateDevice);
        }
Exemplo n.º 2
0
        public void DeviceLost(IADevice iaDevice)
        {
            List <PairablePerson> pairablePersons = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
            List <PairableDevice> pairableDevices = locator.Devices.OfType <PairableDevice>().ToList <PairableDevice>();

            // Find and remove the pairable device from the Locator's list of devices
            PairableDevice pairableDevice = pairableDevices.Find(d => d.Identifier.Equals(iaDevice.Name));

            locator.Devices.Remove(pairableDevice);


            // If the device was paired, we mark its corresponding person unpaired.
            PairablePerson person = pairablePersons.Find(p => p.Identifier.Equals(pairableDevice.HeldByPersonIdentifier));

            if (person != null)
            {
                //Remove the pairing information associated with the Perpon
                person.HeldDeviceIdentifier = null;
                person.PairingState         = PairingState.NotPaired;
            }
            pairableDevice.HeldByPersonIdentifier = null;

            if (pairableDevice == null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR: tried to remove nonexistent pairable device.");
            }

            if (DeviceRemoved != null)
            {
                DeviceRemoved(this, pairableDevice);
            }
        }
Exemplo n.º 3
0
        void GetNearestDeviceInView(IARequest request, IAResponse response)
        {
            String deviceIdentifier = request.Parameters["identifier"];

            // Find the associated device in the Current Devices
            Device observer = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier));

            if (observer == null)
            {
                //TODO: Should we use distinct status codes for distinct failure types here?
                response.StatusCode = 404;
                return;
            }

            // Find the nearest device that we observe
            Device nearestDevice = locator.GetNearestDeviceInView(observer);

            if (nearestDevice == null)
            {
                response.StatusCode = 404;
                return;
            }

            // Prepare the device for serialization
            IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(nearestDevice);

            if (intermediateDevice == null)
            {
                response.StatusCode = 404;
                return;
            }

            response.SetBodyWith(intermediateDevice);
        }
Exemplo n.º 4
0
        void GetNearestDeviceInRange(IARequest request, IAResponse response)
        {
            String deviceIdentifier = request.Parameters["identifier"];
            double range            = Double.Parse(request.Parameters["range"]);

            // Find the associated device in the Current Devices
            Device observer = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier));

            if (observer == null)
            {
                response.StatusCode = 404;
                return;
            }

            Device nearestDevice = locator.GetNearestDeviceWithinRange(observer, range);

            if (nearestDevice == null)
            {
                response.StatusCode = 404;
                return;
            }

            IntermediateDevice intermediateDevice = PairableDevice.GetCompleteIntermediateDevice(nearestDevice);

            if (intermediateDevice == null)
            {
                response.StatusCode = 404;
                return;
            }

            // Respond with the device
            response.SetBodyWith(intermediateDevice);
        }
Exemplo n.º 5
0
        void GetDevicesInView(IARequest request, IAResponse response)
        {
            String deviceIdentifier = request.Parameters["identifier"];

            // Find the associated device in the Current Devices
            Device observer = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier));

            if (observer == null)
            {
                response.StatusCode = 404;
                return;
            }

            // Get the devices in view, and convert them for serialization
            List <Device>             devicesInView = locator.GetDevicesInView(observer);
            List <IntermediateDevice> intDevices    = PairableDevice.GetCompleteIntermediateDevicesList(devicesInView);

            if (intDevices.Count == 0)
            {
                response.StatusCode = 404;
                return;
            }

            response.SetBodyWith(intDevices);
        }
Exemplo n.º 6
0
        //TODO Deal with the cause where more then two Devices (or persons) are Attempting to Pair
        //TODO Consider how the timer
        /// <summary>
        /// This function attempts to pair a Person and a Device. This occurs if both have had their states
        /// sets to 'PairingAttempt'.
        /// </summary>
        /// <param name="devices"> The list of current devices</param>
        /// <param name="persons"> The list of current persons</param>
        /// <returns></returns>
        internal bool AttemptPairing(List <PairableDevice> devices, List <PairablePerson> persons)
        {
            //Find a device set to PairingAttempt
            PairableDevice pairingDevice = devices.Find(device => device.PairingState == PairingState.PairingAttempt);

            //Find a person set to PairingAttempt
            PairablePerson pairingPerson = persons.Find(person => person.PairingState == PairingState.PairingAttempt);

            //Check Device & Person
            if (pairingDevice == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "Cannot Pair Because No Device Is Marked For Pairing");
            }

            if (pairingPerson == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "Cannot Pair Because No Person Is Marked For Pairing");
            }

            //Debug Intermittent Failure
            String deviceExists = (pairingDevice != null) ? "Pairing Device" : "Null";
            String personExists = (pairingPerson != null) ? "Pairing Person" : "Null";

            logger.TraceEvent(TraceEventType.Verbose, 0, "Device: {0} and Person: {1}", deviceExists, personExists);

            if (pairingDevice != null && pairingPerson != null)
            {
                Pair(pairingDevice, pairingPerson);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        void GetDevicesInRange(IARequest request, IAResponse response)
        {
            String deviceIdentifier = request.Parameters["identifier"];
            double range            = Double.Parse(request.Parameters["range"]);

            // Find the associated device in the Current Devices
            Device device = locator.Devices.Find(d => d.Identifier.Equals(deviceIdentifier));

            if (device == null)
            {
                response.StatusCode = 404;
                return;
            }

            List <Device>             devicesInView       = locator.GetDevicesWithinRange(device, range);
            List <IntermediateDevice> intermediateDevices = PairableDevice.GetCompleteIntermediateDevicesList(devicesInView);

            if (intermediateDevices.Count == 0)
            {
                response.StatusCode = 404;
                return;
            }

            // Respond with the device
            response.SetBodyWith(intermediateDevices);
        }
Exemplo n.º 8
0
        internal PairableDevice CreateTestDevice(int newId, int? heldById = null)
        {
            PairableDevice device = new PairableDevice
            {
                Identifier = newId.ToString(),
                HeldByPersonIdentifier = heldById.ToString() ?? null,
                PairingState = PairingState.NotPaired
            };

            return device;
        }
Exemplo n.º 9
0
        internal void DevicePairAttempt(String DeviceId, List <PairableDevice> Devices)
        {
            PairableDevice d = Devices.Find(device => device.Identifier.Equals(DeviceId));

            logger.TraceEvent(TraceEventType.Information, 0, "Device Wave Gesture Recognized");
            if (d != null && d.PairingState != PairingState.Paired)
            {
                d.PairingState = PairingState.PairingAttempt;
            }
            AttemptPairing();
        }
Exemplo n.º 10
0
        public void AllDevicesInViewTest()
        {
            Setup();
            PairableDevice observer = new PairableDevice
            {
                Location = new Point(0, 0),
                Orientation = 225,
                Identifier = "observer",
            };

            PairableDevice nearest = new PairableDevice
            {
                Location = new Point(-1, -1),
                Identifier = "nearest",
                Orientation = 20,
            };

            PairableDevice furthest = new PairableDevice
            {
                Location = new Point(-2, -2),
                Identifier = "furthest",
                Orientation = 20,
            };

            Server.Locator.Devices.Add(observer);
            Server.Locator.Devices.Add(furthest);
            Server.Locator.Devices.Add(nearest);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetAllDevicesInViewRoute);
            request.Parameters["identifier"] = observer.Identifier;

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                List<IntermediateDevice> intDevices = response.BodyAs<IntermediateDevice>();

                IntermediateDevice intDevice = intDevices.Find(x => x.identifier == nearest.Identifier);
                Assert.AreEqual(nearest.Location, intDevice.location);
                Assert.AreEqual(nearest.Orientation, intDevice.orientation);

                intDevice = intDevices.Find(x => x.identifier == furthest.Identifier);
                Assert.AreEqual(furthest.Location, intDevice.location);
                Assert.AreEqual(furthest.Orientation, intDevice.orientation);

                doneWaitingForResponse = true;
            });

            WaitForResponse();
            Teardown();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Return All Devices known to the Locator
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        void GetDevices(IARequest request, IAResponse response)
        {
            List <IntermediateDevice> intermediateDevices = PairableDevice.GetCompleteIntermediateDevicesList(locator.Devices);

            if (intermediateDevices.Count == 0)
            {
                response.StatusCode = 404;
            }
            else
            {
                response.SetBodyWith(intermediateDevices);
            }
        }
Exemplo n.º 12
0
        public void DeviceFound(IADevice iaDevice, bool ownDevice)
        {
            PairableDevice pairableDevice = new PairableDevice
            {
                Identifier   = iaDevice.Name,
                PairingState = PairingState.NotPaired
            };

            FindDeviceWidthAndHeight(iaDevice);


            if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                IARequest request = new IARequest(Routes.GetLocationRoute);
                IntAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception error)
                {
                    if (response == null || response.StatusCode == 404)
                    {
                        // Device has no location
                    }
                    else if (response.StatusCode == 200)
                    {
                        IntermediatePoint intermediatePoint = response.BodyAs <IntermediatePoint>();
                        Point result = intermediatePoint.ToPoint();

                        Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(iaDevice.Name));

                        if (localDevice != null)
                        {
                            localDevice.Location = result;
                            response.StatusCode  = 201; // created
                        }
                        else
                        {
                            response.StatusCode = 404; // not found
                        }
                    }
                });
            }

            locator.Devices.Add(pairableDevice);

            if (DeviceAdded != null)
            {
                DeviceAdded(this, pairableDevice);
            }
        }
Exemplo n.º 13
0
        public void DeviceFound(IADevice iaDevice, bool ownDevice)
        {
            PairableDevice pairableDevice = new PairableDevice
            {
                Identifier = iaDevice.Name,
                PairingState = PairingState.NotPaired
            };

            FindDeviceWidthAndHeight(iaDevice);

            if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                IARequest request = new IARequest(Routes.GetLocationRoute);
                IntAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception error)
                {
                    if (response == null || response.StatusCode == 404)
                    {
                        // Device has no location

                    }
                    else if (response.StatusCode == 200)
                    {
                        IntermediatePoint intermediatePoint = response.BodyAs<IntermediatePoint>();
                        Point result = intermediatePoint.ToPoint();

                        Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(iaDevice.Name));

                        if (localDevice != null)
                        {
                            localDevice.Location = result;
                            response.StatusCode = 201; // created
                        }
                        else
                        {
                            response.StatusCode = 404; // not found
                        }

                    }
                });
            }

            locator.Devices.Add(pairableDevice);

            if (DeviceAdded != null)
                DeviceAdded(this, pairableDevice);
        }
Exemplo n.º 14
0
        public void UnpairDevice(PairableDevice pairingDevice)
        {
            if (pairingDevice.PairingState != PairingState.NotPaired)
            {
                List <PairablePerson> pPersons      = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
                PairablePerson        pairingPerson = pPersons.Find(p => p.HeldDeviceIdentifier == pairingDevice.Identifier);

                pairingDevice.HeldByPersonIdentifier = null;
                pairingDevice.PairingState           = PairingState.NotPaired;

                pairingPerson.PairingState         = PairingState.NotPaired;
                pairingPerson.HeldDeviceIdentifier = null;

                // Dispatch a message to the device
                IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                // Find the IntAirAct device matching the current device.
                IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == pairingDevice.Identifier);
                intAirAct.SendRequest(request, iaDevice);
                System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);
            }
        }
Exemplo n.º 15
0
        public void CastingTest()
        {
            //Create A List of Pairable Devices
            List<Device> listOfDevices = new List<Device>();

            //Add Devices to List
            String testIdentifier = "ChrisBurnsiPhone";
            PairableDevice pairableDevice = new PairableDevice
            {
                Identifier = testIdentifier,
                Orientation = null,
                PairingState = PairingState.NotPaired
            };

            listOfDevices.Add(pairableDevice);

            //Cast the List Using the OfType Operator
            List<PairableDevice> listOfPD = listOfDevices.OfType<PairableDevice>().ToList<PairableDevice>();

            Assert.AreEqual(pairableDevice, listOfPD[0]);
        }
Exemplo n.º 16
0
        public DeviceControl(PairableDevice pairableDevice, IADevice iaDevice)
        {
            InitializeComponent();

            this.iaDevice = iaDevice;
            this.pairableDevice = pairableDevice;

            deviceRotationControl = new DeviceRotationControl();
            deviceRotationControl.onSliderValueChanged += new EventHandler<RotationSliderEventArgs>(onOrientationSliderChanged);
            canvas.Children.Add(deviceRotationControl);
            Canvas.SetLeft(deviceRotationControl, -170);
            Canvas.SetTop(deviceRotationControl, -40);

            //Setup Events
            pairableDevice.LocationChanged += onLocationChanged;
            pairableDevice.OrientationChanged += onOrientationChanged;
            pairableDevice.PairingStateChanged += onPairingStateChanged;

            LeftLine.StrokeThickness = DrawingResources.DEVICE_FOV_WIDTH;
            RightLine.StrokeThickness = DrawingResources.DEVICE_FOV_WIDTH;

            //Setup Display
            DeviceNameLabel.Text = pairableDevice.Identifier;
            InnerBorder.BorderBrush = DrawingResources.unpairedBrush;

            // If it supports this route, then we know it's a surface
            if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                MyDisplayState = DisplayState.UnlocatedAndOnStackPanel;
            }
            // Likewise, if it supports this route, we know it's a pairable device
            else if (iaDevice.SupportedRoutes.Contains(Routes.BecomePairedRoute))
            {
                MyDisplayState = DisplayState.UnpairedAndOnStackPanel;
            }

            formatForStackPanel();
        }
Exemplo n.º 17
0
        public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson)
        {
            //Change the Pairing State
            pairingDevice.PairingState = PairingState.Paired;
            pairingPerson.PairingState = PairingState.Paired;

            //Create a Holds-Device and Held-By-Person Relationship
            pairingPerson.HeldDeviceIdentifier   = pairingDevice.Identifier;
            pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier;

            List <IADevice> devices = intAirAct.Devices;
            IADevice        device  = devices.Find(d => d.Name == pairingDevice.Identifier);

            if (device != null)
            {
                IARequest request = new IARequest(Routes.BecomePairedRoute);
                intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception)
                {
                    logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier);
                });
            }

            logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier);
        }
Exemplo n.º 18
0
        public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson)
        {
            //Change the Pairing State
            pairingDevice.PairingState = PairingState.Paired;
            pairingPerson.PairingState = PairingState.Paired;

            //Create a Holds-Device and Held-By-Person Relationship
            pairingPerson.HeldDeviceIdentifier = pairingDevice.Identifier;
            pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier;

            List<IADevice> devices = intAirAct.Devices;
            IADevice device = devices.Find(d => d.Name == pairingDevice.Identifier);
            if (device != null)
            {
                IARequest request = new IARequest(Routes.BecomePairedRoute);
                intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception)
                {
                    logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier);
                });

            }

            logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier);
        }
Exemplo n.º 19
0
        private void RemoveOldPeople(List <Skeleton> skeletons, List <PairablePerson> pairablePersons, List <PairableDevice> pairableDevices, String kinectID)
        {
            // If a person has dissappeared, remove the kinect ID from they TrackIDwithSkeletonID dictionary
            List <PairablePerson> vanishedPersons = new List <PairablePerson>();

            foreach (PairablePerson person in pairablePersons)
            {
                foreach (KeyValuePair <string, string> entry in person.TrackerIDwithSkeletonID.ToList())
                {
                    if (entry.Key != null && entry.Key.Equals(kinectID))
                    {
                        bool found = false;
                        foreach (Skeleton skeleton in skeletons)
                        {
                            if (entry.Value.Equals(skeleton.TrackingId.ToString()))
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            // Remove from the dictionary
                            person.TrackerIDwithSkeletonID.Remove(kinectID);
                        }
                    }
                }


                //If that person is not tracked by anyone then make them an occluded person.
                if (person.TrackerIDwithSkeletonID.Count == 0)
                {
                    //Remove Held-By-Person Identifier
                    PairableDevice device = pairableDevices.Find(x => x.Identifier.Equals(person.HeldDeviceIdentifier));

                    // If the person was not paired to a device, we can remove them immediately
                    if (device == null)
                    {
                        RemovePerson(vanishedPersons, person);
                    }
                    // If the person was paired, then we allow a grace period for them to reappear, to avoid immediately unpairing them
                    else
                    {
                        if (person.PairingState == PairingState.Paired)
                        {
                            person.PairingState = PairingState.PairedButOccluded;
                            person.Identifier   = null;
                        }
                        // The person will remain with PairingState == PairedButOccluded for a few seconds, after which it will mark itself NotPaired
                        // If this happens, we remove the person for good, and unpair their device
                        else if (person.PairingState == PairingState.NotPaired)
                        {
                            device.HeldByPersonIdentifier = null;
                            device.PairingState           = PairingState.NotPaired;

                            // Dispatch a message to the device
                            IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                            // Find the IntAirAct device matching the current device.
                            IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == device.Identifier);
                            intAirAct.SendRequest(request, iaDevice);
                            System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);

                            RemovePerson(vanishedPersons, person);
                        }
                    }
                }
            }
            foreach (PairablePerson person in vanishedPersons)
            {
                pairablePersons.Remove(person);
            }
        }
Exemplo n.º 20
0
        public void AllDevicesWithinRangeTest()
        {
            Setup();

            PairableDevice observer = new PairableDevice
            {
                Location = new Point(10, 10),
                Orientation = 0,
                Identifier = "observer",
            };

            PairableDevice nearest = new PairableDevice
            {
                Location = new Point(0, 5),
                Identifier = "nearest",
                Orientation = 0,
            };

            PairableDevice furthest = new PairableDevice
            {
                Location = new Point(-5, 0),
                Identifier = "furthest",
                Orientation = 0,
            };

            PairableDevice tooFar = new PairableDevice
            {
                Location = new Point(100,100),
                Identifier = "tooFar",
                Orientation = 50,
            };

            Server.Locator.Devices.Add(observer);
            Server.Locator.Devices.Add(furthest);
            Server.Locator.Devices.Add(nearest);
            Server.Locator.Devices.Add(tooFar);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetAllDevicesInRangeRoute);
            request.Parameters["identifier"] = observer.Identifier;
            request.Parameters["range"] = "50.0";

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                List<IntermediateDevice> intDevices = response.BodyAs<IntermediateDevice>();

                IntermediateDevice intDevice = intDevices.Find(x => x.identifier == nearest.Identifier);
                Assert.AreEqual(nearest.Location, intDevice.location);
                Assert.AreEqual(nearest.Orientation, intDevice.orientation);

                intDevice = intDevices.Find(x => x.identifier == furthest.Identifier);
                Assert.AreEqual(furthest.Location, intDevice.location);
                Assert.AreEqual(furthest.Orientation, intDevice.orientation);

                // The 'tooFar' device should not be returned
                Assert.AreEqual(2, intDevices.Count);

                doneWaitingForResponse = true;
            });

            WaitForResponse();
            Teardown();
        }
Exemplo n.º 21
0
        public void GetAllDeviceInfoTest()
        {
            Setup();

            PairableDevice deviceOne = new PairableDevice
            {
                Location = new Point(1, 0),
                Orientation = 90,
                Identifier = "deviceOne",
            };

            PairableDevice deviceTwo = new PairableDevice
            {
                Location = new Point(-1, 0),
                Identifier = "deviceTwo",
                Orientation = 20,
            };

            Server.Locator.Devices.Add(deviceOne);
            Server.Locator.Devices.Add(deviceTwo);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetAllDeviceInfoRoute);

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                List<IntermediateDevice> ids = response.BodyAs<IntermediateDevice>();

                IntermediateDevice intDevice = ids.Find(x => x.identifier.Equals("deviceOne"));
                Assert.AreEqual(deviceOne.Location, intDevice.location);
                Assert.AreEqual(deviceOne.Orientation, intDevice.orientation.Value);
                intDevice = ids.Find(x => x.identifier.Equals("deviceTwo"));
                Assert.AreEqual(deviceTwo.Location, intDevice.location);
                Assert.AreEqual(deviceTwo.Orientation, intDevice.orientation.Value);

                doneWaitingForResponse = true;
            });

            WaitForResponse();

            Teardown();
        }
Exemplo n.º 22
0
        public void GetDeviceInfoTest()
        {
            Setup();

            PairableDevice deviceOne = new PairableDevice
            {
                Location = new Point(1,0),
                Orientation = 90,
                Identifier = "deviceOne",
            };

            PairableDevice deviceTwo = new PairableDevice
            {
                Location = new Point(-1,0),
                Identifier = "deviceTwo",
            };

            Server.Locator.Devices.Add(deviceOne);
            Server.Locator.Devices.Add(deviceTwo);

            Server.Start();
            Client.Start();
            WaitForConnections();

            // Successful get device info test
            IARequest request = new IARequest(Routes.GetDeviceInfoRoute);
            request.Parameters["identifier"] = deviceOne.Identifier;

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                IntermediateDevice id = response.BodyAs<IntermediateDevice>();

                Assert.AreEqual("deviceOne", id.identifier);
                Assert.AreEqual(new Point(1, 0), id.location.Value);
                Assert.AreEqual(90.0, id.orientation.Value, 0.01);

                doneWaitingForResponse = true;
            });

            WaitForResponse();
            doneWaitingForResponse = false;

            // Unsuccessful get device info test
            // Device two is incomplete, missing orientation, the correct server behaviour is to return http status 404
            request = new IARequest(Routes.GetDeviceInfoRoute);
            request.Parameters["identifier"] = deviceTwo.Identifier;

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                Assert.AreEqual(404, response.StatusCode);
                doneWaitingForResponse = true;
            });

            WaitForResponse();

            Teardown();
        }
Exemplo n.º 23
0
        public void GetOffsetAngleTest()
        {
            Setup();

            // Create a person and device, paired and positioned
            PairablePerson person = new PairablePerson
            {
                PairingState = PairingState.Paired,
                Identifier = "Bob",
                Location = new Point(1, 1),
                HeldDeviceIdentifier = "myPad"
            };

            PairableDevice device = new PairableDevice
            {
                HeldByPersonIdentifier = "Bob",
                Identifier = "myPad",
                Location = new Point(1, 1),
                PairingState = PairingState.Paired
            };

            // Position the tracker
            //Server.PersonManager.Tracker.Location = new Point(0, 2);
            //Server.PersonManager.Tracker.Orientation = 270;
            Server.Locator.Devices.Add(device);
            Server.Locator.Persons.Add(person);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetOffsetAngleRoute);
            request.Parameters["identifier"] = "myPad";

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                double offsetOrientation = double.Parse(response.BodyAsString());
                // The angle between the device and the tracker should be 135 degrees
                Assert.AreEqual(135, offsetOrientation, 0.01);
            });

            Teardown();
        }
Exemplo n.º 24
0
        void deviceRemoved(DeviceManager deviceManager, PairableDevice pairableDevice)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (DeviceControlDictionary.ContainsKey(pairableDevice.Identifier))
                {
                    canvas.Children.Remove(DeviceControlDictionary[pairableDevice.Identifier]);
                    unpairedDeviceStackPanel.Children.Remove(DeviceControlDictionary[pairableDevice.Identifier]);
                    surfaceStackPanel.Children.Remove(DeviceControlDictionary[pairableDevice.Identifier]);

                    DeviceControlDictionary.Remove(pairableDevice.Identifier);
                }
            }));
        }
Exemplo n.º 25
0
        void deviceAdded(DeviceManager deviceManager, PairableDevice pairableDevice)
        {
            // Finds the matching IADevice from the pairableDevice Identifier
            IADevice iaDevice = deviceManager.IntAirAct.Devices.Find(d => d.Name.Equals(pairableDevice.Identifier));

            if (iaDevice.SupportedRoutes.Contains(Routes.BecomePairedRoute))
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    DeviceControlDictionary[pairableDevice.Identifier] = new DeviceControl(pairableDevice, iaDevice);
                    unpairedDeviceStackPanel.Children.Add(DeviceControlDictionary[pairableDevice.Identifier]);
                }));
            }
            else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    DeviceControlDictionary[pairableDevice.Identifier] = new DeviceControl(pairableDevice, iaDevice);
                    surfaceStackPanel.Children.Add(DeviceControlDictionary[pairableDevice.Identifier]);
                }));
            }
        }
Exemplo n.º 26
0
        public void NearestDeviceInRangeTest()
        {
            Setup();

            PairableDevice observer = new PairableDevice
            {
                Location = new Point(10, 10),
                Orientation = 0,
                Identifier = "observer",
            };

            PairableDevice nearest = new PairableDevice
            {
                Location = new Point(0, 5),
                Identifier = "nearest",
                Orientation = 0,
            };

            PairableDevice furthest = new PairableDevice
            {
                Location = new Point(-5, 0),
                Identifier = "furthest",
                Orientation = 0,
            };

            Server.Locator.Devices.Add(observer);
            Server.Locator.Devices.Add(furthest);
            Server.Locator.Devices.Add(nearest);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetNearestDeviceInRangeRoute);
            request.Parameters["identifier"] = observer.Identifier;
            request.Parameters["range"] = "100.0";

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception e)
            {
                IntermediateDevice intDevice = response.BodyAs<IntermediateDevice>();
                Assert.AreEqual(nearest.Identifier, intDevice.identifier);
                Assert.AreEqual(nearest.Location, intDevice.location);
                Assert.AreEqual(nearest.Orientation, intDevice.orientation);

                doneWaitingForResponse = true;
            });

            WaitForResponse();
            Teardown();
        }
Exemplo n.º 27
0
        public void SetLocationTest()
        {
            Setup();

            // Set up a device
            PairableDevice device = new PairableDevice
            {
                Identifier = "myPad",
                Location = new Point(1,1)
            };
            Server.Locator.Devices.Add(device);

            Server.Start();
            Client.Start();
            WaitForConnections();

            // Build a request to set the device's orientation
            IARequest request = new IARequest(Routes.SetOrientationRoute);
            request.Parameters["identifier"] = "myPad";
            Point newLocation = new Point(2,2);
            request.SetBodyWith(new IntermediatePoint(newLocation));

            // Send the request, and test
            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                Assert.AreEqual(newLocation, device.Location.Value);
            });

            Teardown();
        }
Exemplo n.º 28
0
        public void SetOrientationTest()
        {
            Setup();

            // Set up a device
            PairableDevice device = new PairableDevice
            {
                Identifier = "myPad",
                Orientation = 20.0
            };
            Server.Locator.Devices.Add(device);

            Server.Start();
            Client.Start();
            WaitForConnections();

            // Build a request to set the device's orientation
            IARequest request = new IARequest(Routes.SetOrientationRoute);
            request.Parameters["identifier"] = "myPad";
            double newOrientation = 240.0;
            request.SetBodyWithString(newOrientation.ToString());

            // Send the request, and test
            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                Assert.AreEqual(240.0, device.Orientation.Value, 0.01);
            });

            Teardown();
        }
Exemplo n.º 29
0
        public void onPairingStateChanged(PairableDevice pairableDevice)
        {
            //Dispatch UI Changes to Main Thread
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                //Set device border to appropriate colour
                InnerBorder.BorderBrush = DrawingResources.GetBrushFromPairingState(pairableDevice.PairingState);

                //Set the control's owner
                if (pairableDevice.PairingState == PairingState.Paired)
                {
                    // When paired, we move the device to the canvas.
                    this.MyDisplayState = DisplayState.PairedAndOnCanvas;
                }
                else
                {
                    // If we are not paired or in pairing attempt, we go to stackpanel
                    this.MyDisplayState = DisplayState.UnpairedAndOnStackPanel;
                }

            }));
        }
Exemplo n.º 30
0
        private void AddNewPeople(List <Skeleton> skeletons, List <PairablePerson> pairablePersons, String kinectID)
        {
            //if a skeleton is very close to an existing person, that kinect will be added to the person's list of TrackerIDwithSkeletonID
            //this is how one person can be tracked by multiple kinects.
            foreach (Skeleton skeleton in skeletons)
            {
                Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                foreach (PairablePerson pairablePerson in pairablePersons)
                {
                    if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - PROXIMITYDISTANCE))
                    {
                        if (!pairablePerson.TrackerIDwithSkeletonID.ContainsKey(kinectID))
                        {
                            pairablePerson.TrackerIDwithSkeletonID.Add(kinectID, skeleton.TrackingId.ToString());
                        }
                        break;
                    }
                }
            }

            // Then, test each new skeleton to see if it matches an occluded person
            foreach (Skeleton skeleton in skeletons)
            {
                //if (pairablePersons.Find(x => x.Identifier.Equals(skeleton.TrackingId.ToString())) == null)
                if (pairablePersons.Find(x => skeleton.TrackingId.ToString().Equals(x.Identifier)) == null)
                {
                    foreach (PairablePerson pairablePerson in pairablePersons)
                    {
                        if (pairablePerson.PairingState == PairingState.PairedButOccluded)
                        {
                            Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                            if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - SAVINGDISTANCE))
                            {
                                // "Repair them"
                                pairablePerson.Identifier   = skeleton.TrackingId.ToString();
                                pairablePerson.PairingState = PairingState.Paired;

                                PairableDevice device = (PairableDevice)locator.Devices.Find(x => x.Identifier == pairablePerson.HeldDeviceIdentifier);
                                device.HeldByPersonIdentifier = pairablePerson.Identifier;
                            }
                        }
                    }
                }
            }

            // For any skeletons that could not be matched to an existing person or if it wasn't matched to an occluded person, we create a new PairablePerson
            foreach (Skeleton skeleton in skeletons)
            {
                if (skeleton.TrackingId == 0)
                {
                    continue;
                }

                //New Skeleton Found
                if (pairablePersons.Find(x => x.TrackerIDwithSkeletonID.ContainsValue(skeleton.TrackingId.ToString())) == null)
                {
                    PairablePerson person = new PairablePerson
                    {
                        Location                = new Point(0, 0),
                        Orientation             = 0.0,
                        Identifier              = skeleton.TrackingId.ToString(),
                        PairingState            = PairingState.NotPaired,
                        CalibrationState        = PairablePerson.CallibrationState.NotUsedCalibration,
                        TrackerIDwithSkeletonID = new Dictionary <string, string>(),
                        TrackedByIdentifier     = kinectID
                    };

                    //add the tracker id to the top of the list
                    person.TrackerIDwithSkeletonID.Add(kinectID, skeleton.TrackingId.ToString());

                    pairablePersons.Add(person);

                    if (PersonAdded != null)
                    {
                        PersonAdded(this, person);
                    }
                }
            }
        }
Exemplo n.º 31
0
        public void UnpairDevice(PairableDevice pairingDevice)
        {
            if (pairingDevice.PairingState != PairingState.NotPaired)
            {
                List<PairablePerson> pPersons = locator.Persons.OfType<PairablePerson>().ToList<PairablePerson>();
                PairablePerson pairingPerson = pPersons.Find(p => p.HeldDeviceIdentifier == pairingDevice.Identifier);

                pairingDevice.HeldByPersonIdentifier = null;
                pairingDevice.PairingState = PairingState.NotPaired;

                pairingPerson.PairingState = PairingState.NotPaired;
                pairingPerson.HeldDeviceIdentifier = null;

                // Dispatch a message to the device
                IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                // Find the IntAirAct device matching the current device.
                IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == pairingDevice.Identifier);
                intAirAct.SendRequest(request, iaDevice);
                System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);
            }
        }