Exemplo n.º 1
0
        //TODO: Implement ISerializable
        public void TestCanSerialize()
        {
            var beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                         .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothName("xx")
                         .SetBluetoothAddress("1:2:3:4:5:6").SetDataFields(new List <Java.Lang.Long> {
                new Java.Lang.Long(100L)
            }).Build();

            byte[] serializedBeacon = ConvertToBytes(beacon);
            Beacon beacon2          = (Beacon)ConvertFromBytes(serializedBeacon);

            AssertEx.AreEqual("Right number of identifiers after deserialization", 3, beacon2.Identifiers.Count);
            AssertEx.AreEqual("id1 is same after deserialization", beacon.GetIdentifier(0), beacon2.GetIdentifier(0));
            AssertEx.AreEqual("id2 is same after deserialization", beacon.GetIdentifier(1), beacon2.GetIdentifier(1));
            AssertEx.AreEqual("id3 is same after deserialization", beacon.GetIdentifier(2), beacon2.GetIdentifier(2));
            AssertEx.AreEqual("txPower is same after deserialization", beacon.TxPower, beacon2.TxPower);
            AssertEx.AreEqual("rssi is same after deserialization", beacon.Rssi, beacon2.Rssi);
            AssertEx.AreEqual("distance is same after deserialization", beacon.Distance, beacon2.Distance, 0.001);
            AssertEx.AreEqual("bluetoothAddress is same after deserialization", beacon.BluetoothAddress, beacon2.BluetoothAddress);
            AssertEx.AreEqual("bluetoothAddress is same after deserialization", beacon.BluetoothName, beacon2.BluetoothName);
            AssertEx.AreEqual("beaconTypeCode is same after deserialization", beacon.BeaconTypeCode, beacon2.BeaconTypeCode);
            AssertEx.AreEqual("manufacturer is same after deserialization", beacon.Manufacturer, beacon2.Manufacturer);
            AssertEx.AreEqual("data field 0 is the same after deserialization", beacon.DataFields[0], beacon2.DataFields[0]);
            AssertEx.AreEqual("data field 0 is the right value", beacon.DataFields[0], new Java.Lang.Long(100L));
        }
Exemplo n.º 2
0
        public void testBeaconMatchesRegionWithSameIdentifiers()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", Identifier.Parse("1"), Identifier.Parse("2"), Identifier.Parse("3"));

            AssertEx.True("Beacon should match region with all identifiers the same", region.MatchesBeacon(beacon));
        }
Exemplo n.º 3
0
        public void testBeaconMatchesRegionWithDifferentIdentifier1()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", Identifier.Parse("22222"), null, null);

            AssertEx.True("Beacon should not match region with first identifier different", !region.MatchesBeacon(beacon));
        }
Exemplo n.º 4
0
        public void testBeaconMatchesRegionWithSameBluetoothMac()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("01:02:03:04:05:06").Build();
            Region region = new Region("myRegion", "01:02:03:04:05:06");

            AssertEx.True("Beacon should match region with mac the same", region.MatchesBeacon(beacon));
        }
Exemplo n.º 5
0
        public void TestHashCodeWithNullIdentifier()
        {
            Beacon beacon = new AltBeacon.Builder()
                            .SetIdentifiers(new List <Identifier> {
                Identifier.Parse("0x1234"), null
            })
                            .Build();

            AssertEx.True("hashCode() should not throw exception", beacon.GetHashCode() >= int.MinValue);
        }
Exemplo n.º 6
0
        public void testBeaconMatchesRegionWithShorterIdentifierList()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", new List <Identifier> {
                Identifier.Parse("1")
            });

            AssertEx.True("Beacon should match region with first identifier equal and shorter Identifier list", region.MatchesBeacon(beacon));
        }
Exemplo n.º 7
0
        public void TestBeaconsWithDifferentId3AreNotEqual()
        {
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("13").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            AssertEx.True("Beacons with different id3 are not equal", !beacon1.Equals(beacon2));
        }
Exemplo n.º 8
0
        public void testBeaconMatchesRegionWithSingleNullIdentifierList()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            var identifiers = new List <Identifier>();

            identifiers.Add(null);
            Region region = new Region("all-beacons-region", identifiers);

            AssertEx.True("Beacon should match region with first identifier null and shorter Identifier list", region.MatchesBeacon(beacon));
        }
Exemplo n.º 9
0
        public void NoDoubleWrappingOfExtraDataFields()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothName("xx")
                            .SetBluetoothAddress("1:2:3:4:5:6").SetDataFields(new List <Java.Lang.Long> {
                new Java.Lang.Long(100L)
            }).Build();
            var list = beacon.ExtraDataFields;

            beacon.ExtraDataFields = list;
            AssertEx.True("getter should return same object after first wrap ", beacon.ExtraDataFields == list);
        }
Exemplo n.º 10
0
        public void TestBeaconsWithSameMacsAreEqual()
        {
            Beacon.SetHardwareEqualityEnforced(true);
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            AssertEx.True("Beacons with same same macs are equal", beacon1.Equals(beacon2));
        }
Exemplo n.º 11
0
        public void TestBeaconsWithSameIdentifersAreEqual()
        {
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            //AssertEx.AreEqual("Beacons with same identifiers are equal", beacon1, beacon2);
            AssertEx.True("Beacons with same identifiers are equal", beacon1.Equals(beacon2));
        }
Exemplo n.º 12
0
        public void TestAccessBeaconIdentifiers()
        {
            Beacon beacon = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6)
                            .SetBluetoothAddress("1:2:3:4:5:6").Build();

            AssertEx.AreEqual("First beacon id should be 1", beacon.GetIdentifier(0).ToString(), "1");
            AssertEx.AreEqual("Second beacon id should be 1", beacon.GetIdentifier(1).ToString(), "2");
            AssertEx.AreEqual("Third beacon id should be 1", beacon.GetIdentifier(2).ToString(), "3");
            AssertEx.AreEqual("First beacon id should be 1", beacon.Id1.ToString(), "1");
            AssertEx.AreEqual("Second beacon id should be 1", beacon.Id2.ToString(), "2");
            AssertEx.AreEqual("Third beacon id should be 1", beacon.Id3.ToString(), "3");
        }
        public void TestCanSerializeParcelable()
        {
            var parcel = Parcel.Obtain();
            var beacon = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                         .SetBeaconTypeCode(5).SetTxPower(6)
                         .SetBluetoothAddress("1:2:3:4:5:6").Build();

            beacon.WriteToParcel(parcel, 0);
            parcel.SetDataPosition(0);
            var beacon2 = new AltBeacon(parcel);

            Assert.AreEqual(((AltBeacon)beacon).MfgReserved, ((AltBeacon)beacon2).MfgReserved, "beaconMfgReserved is same after deserialization");
        }
Exemplo n.º 14
0
        public void CreateTimedSimulatedBeacons()
        {
            if (USE_SIMULATED_BEACONS)
            {
                Beacons = new List <Beacon>();

                Beacon beacon1 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon2 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("2").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon3 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("3").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon4 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("4").SetRssi(-55).SetTxPower(-55).Build();

                Beacons.Add(beacon1);
                Beacons.Add(beacon2);
                Beacons.Add(beacon3);
                Beacons.Add(beacon4);

                var finalBeacons = new List <Beacon>(Beacons);

                //Clearing beacons list to prevent all beacons from appearing immediately.
                //These will be added back into the beacons list from finalBeacons later.
                Beacons.Clear();

                scheduleTaskExecutor = Executors.NewScheduledThreadPool(5);

                // This schedules an beacon to appear every 10 seconds:
                scheduleTaskExecutor.ScheduleAtFixedRate(new Runnable(() =>
                {
                    try{
                        //putting a single beacon back into the beacons list.
                        if (finalBeacons.Count > Beacons.Count)
                        {
                            Beacons.Add(finalBeacons[Beacons.Count]);
                        }
                        else
                        {
                            scheduleTaskExecutor.Shutdown();
                        }
                    }
                    catch (Java.Lang.Exception ex) {
                        ex.PrintStackTrace();
                    }
                }), 0, 10, TimeUnit.Seconds);
            }
        }
Exemplo n.º 15
0
        public void StartBroadcasting()
        {
            Context context = Android.App.Application.Context;

            beaconset.StopAdvertising();

            BeaconTransmitter mBeaconTransmitter = new BeaconTransmitter(context, new BeaconParser().SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
            Beacon            beacon             = new AltBeacon.Builder()
                                                   .SetId1("FDA50693-A4E2-4FB1-AFCF-C6EB07647825")
                                                   .SetId2("1010") //Major
                                                   .SetId3("2000") //Minor
                                                   .SetManufacturer(0x004C)
                                                   .SetTxPower(-59)
                                                   .Build();

            beaconset.StartAdvertising(beacon);
        }
Exemplo n.º 16
0
		public void CreateBasicSimulatedBeacons()
		{
			if(!UseSimulatedBeacons) return;

			var beacon1 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
				.SetId2("1").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();

//			var beacon2 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
//				.SetId2("2").SetId3("1").SetRssi(-50).SetTxPower(-50).Build();

//			var beacon3 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
//				.SetId2("1").SetId3("3").SetRssi(-55).SetTxPower(-55).Build();

//			var beacon4 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
//				.SetId2("1").SetId3("4").SetRssi(-55).SetTxPower(-55).Build();

			_beacons.AddRange(new [] { beacon1 });
		}
Exemplo n.º 17
0
        public void CreateBasicSimulatedBeacons()
        {
            if (USE_SIMULATED_BEACONS)
            {
                Beacon beacon1 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon2 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("2").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon3 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("3").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon4 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("4").SetRssi(-55).SetTxPower(-55).Build();

                Beacons.Add(beacon1);
                Beacons.Add(beacon2);
                Beacons.Add(beacon3);
                Beacons.Add(beacon4);
            }
        }
Exemplo n.º 18
0
        public void CreateBasicSimulatedBeacons()
        {
            if (!UseSimulatedBeacons)
            {
                return;
            }

            var beacon1 = new AltBeacon.Builder().SetId1(AppConstants.AppUUID)
                          .SetId2("111").SetId3("111").SetRssi(-55).SetTxPower(-55).Build();

            var beacon2 = new AltBeacon.Builder().SetId1(AppConstants.AppUUID)
                          .SetId2("2").SetId3("32768").SetRssi(-55).SetTxPower(-55).Build();

            var beacon3 = new AltBeacon.Builder().SetId1(AppConstants.AppUUID)
                          .SetId2("32768").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();

            var beacon4 = new AltBeacon.Builder().SetId1(AppConstants.AppUUID)
                          .SetId2("65535").SetId3("65535").SetRssi(-55).SetTxPower(-55).Build();

            _beacons.AddRange(new[] { beacon1, beacon2, beacon3, beacon4 });
        }
Exemplo n.º 19
0
        public void CreateBasicSimulatedBeacons()
        {
            if (!UseSimulatedBeacons)
            {
                return;
            }

            var beacon1 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                          .SetId2("1").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();

            var beacon2 = new AltBeacon.Builder().SetId1("DF7E1C78-43E9-44FF-886F-1D1F7DA6997A")
                          .SetId2("2").SetId3("2").SetRssi(-55).SetTxPower(-55).Build();

            var beacon3 = new AltBeacon.Builder().SetId1("DF7E1C77-43E9-44FF-886F-1D1F7DA6997A")
                          .SetId2("3").SetId3("3").SetRssi(-55).SetTxPower(-55).Build();

            var beacon4 = new AltBeacon.Builder().SetId1("DF7E1C76-43E9-44FF-886F-1D1F7DA6997A")
                          .SetId2("4").SetId3("4").SetRssi(-55).SetTxPower(-55).Build();

            _beacons.AddRange(new[] { beacon1, beacon2, beacon3, beacon4 });
        }