Exemplo n.º 1
0
        public void TestBeaconAdvertisingBytesForEddystone()
        {
            Context context = Application.Context;

            Beacon beacon = new Beacon.Builder()
                            .SetId1("0x2f234454f4911ba9ffa6")
                            .SetId2("0x000000000001")
                            .SetManufacturer(0x0118)
                            .SetTxPower(-59)
                            .Build();
            BeaconParser beaconParser = new BeaconParser()
                                        .SetBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19");

            byte[]            data = beaconParser.GetBeaconAdvertisementData(beacon);
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(context, beaconParser);
            // TODO: can't actually start transmitter here because Robolectric does not support API 21

            String byteString = "";

            for (int i = 0; i < data.Length; i++)
            {
                byteString += String.Format("{0:x2}", data[i]);
                byteString += " ";
            }

            AssertEx.AreEqual("Data should be 24 bytes long", 18, data.Length);
            AssertEx.AreEqual("Advertisement bytes should be as expected", "00 C5 2F 23 44 54 F4 91 1B A9 FF A6 00 00 00 00 00 01 ", byteString);
        }
Exemplo n.º 2
0
        public void TestBeaconAdvertisingBytes()
        {
            Context context = Application.Context;

            Beacon beacon = new Beacon.Builder()
                            .SetId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
                            .SetId2("1")
                            .SetId3("2")
                            .SetManufacturer(0x0118)
                            .SetTxPower(-59)
                            .SetDataFields(new List <Java.Lang.Long> {
                new Java.Lang.Long(0L)
            })
                            .Build();
            BeaconParser beaconParser = new BeaconParser()
                                        .SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

            byte[]            data = beaconParser.GetBeaconAdvertisementData(beacon);
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(context, beaconParser);

            // TODO: can't actually start transmitter here because Robolectric does not support API 21

            AssertEx.AreEqual("Data should be 24 bytes long", 24, data.Length);
            String byteString = "";

            for (int i = 0; i < data.Length; i++)
            {
                byteString += String.Format("{0:x2}", data[i]);
                byteString += " ";
            }
            AssertEx.AreEqual("Advertisement bytes should be as expected", "BE AC 2F 23 44 54 CF 6D 4A 0F AD F2 F4 91 1B A9 FF A6 00 01 00 02 C5 00 ", byteString);
        }
		private BeaconManager InitializeBeaconManager()
		{
			// Enable the BeaconManager 
			BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

			#region Set up Beacon Simulator if testing without a BLE device
//			var beaconSimulator = new BeaconSimulator();
//			beaconSimulator.CreateBasicSimulatedBeacons();
//
//			BeaconManager.BeaconSimulator = beaconSimulator;
			#endregion

			var iBeaconParser = new BeaconParser();
			//	Estimote > 2013
			iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
			bm.BeaconParsers.Add(iBeaconParser);

			_monitorNotifier.EnterRegionComplete += EnteredRegion;
			_monitorNotifier.ExitRegionComplete += ExitedRegion;
			_monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
			_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

			_tagRegion = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("E4C8A4FC-F68B-470D-959F-29382AF72CE7"), null, null);
			_tagRegion = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
			_emptyRegion = new AltBeaconOrg.BoundBeacon.Region("myEmptyBeaconId", null, null, null);

			bm.SetBackgroundMode(false);
			bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);

			return bm;
		}
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);

            var iBeaconParser = new BeaconParser();

            //	Estimote > 2013
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            _monitorNotifier.EnterRegionComplete             += EnteredRegion;
            _monitorNotifier.ExitRegionComplete              += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete   += RangingBeaconsInRegion;

            _tagRegion   = new Org.Altbeacon.Beacon.Region/* AltBeaconOrg.BoundBeacon.Region*/ ("Beacon 2", Identifier.Parse("8E6DBFBB-489D-418A-9560-1BA1CE6301AA"), null, null);
            _tagRegion   = new Org.Altbeacon.Beacon.Region/* AltBeaconOrg.BoundBeacon.Region*/ ("myUniqueBeaconId", Identifier.Parse("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
            _emptyRegion = new Org.Altbeacon.Beacon.Region/* AltBeaconOrg.BoundBeacon.Region*/ ("myEmptyBeaconId", null, null, null);

            //bm.SetBackgroundMode(false);

            bm.BackgroundMode = false;
            bm.Bind((IBeaconConsumer)Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);

            return(bm);
        }
Exemplo n.º 5
0
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

            #region Set up Beacon Simulator if testing without a BLE device
//			var beaconSimulator = new BeaconSimulator();
//			beaconSimulator.CreateBasicSimulatedBeacons();
//
//			BeaconManager.BeaconSimulator = beaconSimulator;
            #endregion

            var iBeaconParser = new BeaconParser();
            //	Estimote > 2013
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            _monitorNotifier.EnterRegionComplete             += EnteredRegion;
            _monitorNotifier.ExitRegionComplete              += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete   += RangingBeaconsInRegion;

            _tagRegion   = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("E4C8A4FC-F68B-470D-959F-29382AF72CE7"), null, null);
            _tagRegion   = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
            _emptyRegion = new AltBeaconOrg.BoundBeacon.Region("myEmptyBeaconId", null, null, null);

            bm.BackgroundMode = false;
            bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);

            return(bm);
        }
        private BeaconManager InitializeBeaconManager()
        {
            if (isBinded)
            {
                return(_beaconManager);
            }

            // Enable the BeaconManager
            var bm = BeaconManager.GetInstanceForApplication(ApplicationContext);

            //  Estimote > 2013
            var iBeaconParser = new BeaconParser();

            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            // events
            _monitorNotifier.EnterRegionComplete             += EnteredRegion;
            _monitorNotifier.ExitRegionComplete              += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete   += RangingBeaconsInRegion;

            bm.BackgroundMode = false;
            bm.Bind(this);

            isBinded = true;

            logService.WriteToLog(LOG_FILENAME, "InitializeBeaconManager");

            return(bm);
        }
Exemplo n.º 7
0
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

            #region Set up Beacon Simulator if testing without a BLE device
            //			var beaconSimulator = new BeaconSimulator();
            //			beaconSimulator.CreateBasicSimulatedBeacons();
            //
            //			BeaconManager.BeaconSimulator = beaconSimulator;
            #endregion

            var iBeaconParser = new BeaconParser();
            //	Estimote > 2013
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            bm.BeaconParsers.Add(iBeaconParser);

            _monitorNotifier.EnterRegionComplete             += EnteredRegion;
            _monitorNotifier.ExitRegionComplete              += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete   += RangingBeaconsInRegion;

            _tagRegion   = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId", Identifier.Parse("F0018B9B-7509-4C31-A905-1A27D39C003C"), null, null);
            _emptyRegion = new AltBeaconOrg.BoundBeacon.Region("myEmptyBeaconId", null, null, null);

            //bm.SetBackgroundMode(false);
            bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);

            return(bm);
        }
        public void testBeaconAdvertisingBytes()
        {
            Context context = Application.Context;


            Beacon beacon = new Beacon.Builder()
                            .SetId1("0x454452e29735323d81c0")
                            .SetId2("0x060504030201")
                            .SetDataFields(new List <Java.Lang.Long> {
                new Java.Lang.Long(0x25L)
            })
                            .SetTxPower(-59)
                            .Build();
            // TODO: need to use something other than the d: prefix here for an internally generated field
            BeaconParser beaconParser = new BeaconParser()
                                        .SetBeaconLayout("s:0-1=0123,m:2-2=00,d:3-3,p:4-4,i:5-14,i:15-20");

            byte[]            data = beaconParser.GetBeaconAdvertisementData(beacon);
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(context, beaconParser);

            // TODO: can't actually start transmitter here because Robolectric does not support API 21

            AssertEx.AreEqual("Data should be 19 bytes long", 19, data.Length);
            String byteString = "";

            for (int i = 0; i < data.Length; i++)
            {
                byteString += String.Format("{0:x2}", data[i]);
                byteString += " ";
            }
            AssertEx.AreEqual("Advertisement bytes should be as expected", "00 25 C5 45 44 52 E2 97 35 32 3D 81 C0 06 05 04 03 02 01 ", byteString);
        }
Exemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            beaconIds = FindViewById <TextView>(Resource.Id.beaconCount);
            //tvDistance = FindViewById<TextView>(Resource.Id.tvDistance);
            image = FindViewById <ImageView>(Resource.Id.digitarc);
            //tableName = FindViewById<TextView>(Resource.Id.tableName);
            var imageBitmap = GetImageBitmapFromUrl("https://digitarc.net/assets/img/digitarc-logo-gri.png");

            image.SetImageBitmap(imageBitmap);
            beaconManager = BeaconManager.GetInstanceForApplication(this);

            //-------------------------
            // To detect proprietary beacons, you must add a line like below corresponding to your beacon
            // type.  Do a web search for "setBeaconLayout" to get the proper expression.
            //var beaconParser = new BeaconParser();
            //beaconParser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            //beaconManager.BeaconParsers.Add(beaconParser);
            //-------------------------

            var beaconParser = new BeaconParser();

            beaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");

            var beaconParser2 = new BeaconParser();

            beaconParser2.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            CreateNotificationChannel();
            beaconManager.BeaconParsers.Add(beaconParser);
            beaconManager.BeaconParsers.Add(beaconParser2);
            beaconManager.AddRangeNotifier(this);
            beaconManager.Bind(this);
        }
Exemplo n.º 10
0
        public void TestCanParseLocationBeacon()
        {
            double latitude  = 38.93;
            double longitude = -77.23;
            var    beacon    = new Beacon.Builder()
                               .SetManufacturer(0x0118) // Radius Networks
                               .SetId1("1")             // device sequence number
                               .SetId2(String.Format("{0:X8}", (long)((latitude + 90) * 10000.0)))
                               .SetId3(String.Format("{0:X8}", (long)((longitude + 180) * 10000.0)))
                               .SetTxPower(-59) // The measured transmitter power at one meter in dBm
                               .Build();
            // TODO: make this pass if data fields are little endian or > 4 bytes (or even > 2 bytes)
            var p = new BeaconParser().
                    SetBeaconLayout("m:2-3=10ca,i:4-9,i:10-13,i:14-17,p:18-18");
            var bytes       = p.GetBeaconAdvertisementData(beacon);
            var headerBytes = HexStringToByteArray("02011a1bff1801");
            var advBytes    = new byte[bytes.Length + headerBytes.Length];

            Array.Copy(headerBytes, 0, advBytes, 0, headerBytes.Length);
            Array.Copy(bytes, 0, advBytes, headerBytes.Length, bytes.Length);

            Beacon parsedBeacon = p.FromScanData(advBytes, -59, null);

            AssertEx.NotNull(String.Format("Parsed beacon from {0} should not be null", ByteArrayToHexString(advBytes)), parsedBeacon);
            double parsedLatitude  = Int64.Parse(parsedBeacon.Id2.ToString().Substring(2), System.Globalization.NumberStyles.HexNumber) / 10000.0 - 90.0;
            double parsedLongitude = Int64.Parse(parsedBeacon.Id3.ToString().Substring(2), System.Globalization.NumberStyles.HexNumber) / 10000.0 - 180.0;

            long encodedLatitude = (long)((latitude + 90) * 10000.0);

            AssertEx.AreEqual("encoded latitude hex should match", string.Format("0x{0:x8}", encodedLatitude).ToLowerInvariant(), parsedBeacon.Id2.ToString().ToLowerInvariant());
            AssertEx.AreEqual("device sequence num should be same", "0x000000000001", parsedBeacon.Id1.ToString());
            AssertEx.AreEqual("latitude should be about right", latitude, parsedLatitude, 0.0001);
            AssertEx.AreEqual("longitude should be about right", longitude, parsedLongitude, 0.0001);
        }
Exemplo n.º 11
0
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(CurrentContext);

            #region Set up Beacon Simulator if testing without a BLE device
            //			var beaconSimulator = new BeaconSimulator();
            //			beaconSimulator.CreateBasicSimulatedBeacons();
            //
            //			BeaconManager.BeaconSimulator = beaconSimulator;
            #endregion

            var iBeaconParser = new BeaconParser();
            // iBeacon layout
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            bm.BeaconParsers.Add(iBeaconParser);

            _monitorNotifier.EnterRegionComplete             += EnteredRegion;
            _monitorNotifier.ExitRegionComplete              += ExitedRegion;
            _monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
            _rangeNotifier.DidRangeBeaconsInRegionComplete   += RangingBeaconsInRegion;

            _tagRegion = new AltBeaconOrg.BoundBeacon.Region("com.example.myBeaconRegion", Identifier.Parse("39ED98FF-2900-441A-802F-9C398FC199D2"), null, null);

            bm.SetBackgroundMode(false);
            bm.Bind((IBeaconConsumer)CurrentContext);

            return(bm);
        }
Exemplo n.º 12
0
        public static IEnumerable <Beacon> CreateEnumerableBeacons(IStreamReaderFactory streamReaderFactory)
        {
            var beaconParser            = new BeaconParser();
            var beaconEnumeratorFactory = new BeaconEnumeratorFactory(beaconParser);
            var result = new StreamebleBeacons(beaconEnumeratorFactory, streamReaderFactory);

            return(result);
        }
        public void TestDetectsEddystoneUID()
        {
            byte[]       bytes              = HexStringToByteArray("0201060303aafe1516aafe00e700010203040506070809010203040506000000000000000000000000000000000000000000000000000000000000000000");
            BeaconParser parser             = new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneUidLayout);
            Beacon       eddystoneUidBeacon = parser.FromScanData(bytes, -55, null, DateTime.UtcNow.Ticks);

            AssertEx.NotNull("Eddystone-UID should be not null if parsed successfully", eddystoneUidBeacon);
        }
Exemplo n.º 14
0
        public void TestAllowsAccessToParserIdentifier()
        {
            var bytes  = HexStringToByteArray("02011a1aff180112342f234454cf6d4a0fadf2f4911ba9ffa600010002c5");
            var parser = new BeaconParser("my_beacon_type");

            parser.SetBeaconLayout("m:2-3=1234,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.AreEqual("parser identifier should be accessible", "my_beacon_type", beacon.ParserIdentifier);
        }
Exemplo n.º 15
0
        public void TestRecognizeBeaconCapturedManufacturer()
        {
            var bytes  = HexStringToByteArray("0201061bffaabbbeace2c56db5dffb48d2b060d0f5a71096e000010004c50000000000000000000000000000000000000000000000000000000000000000");
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.AreEqual("manufacturer should be parsed", "bbaa", beacon.Manufacturer.ToString("X").ToLowerInvariant());
        }
Exemplo n.º 16
0
        public void TestLongUrlBeaconIdentifier()
        {
            var bytes  = HexStringToByteArray("0201060303aafe0d16aafe10e70102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f00000000000000000000000000000000000000");
            var parser = new BeaconParser();

            parser.SetBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v");
            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.AreEqual("URL Identifier should be truncated at 8 bytes", 8, beacon.Id1.ToByteArray().Length);
        }
Exemplo n.º 17
0
        public void TestParseGattIdentifierThatRunsOverPduLength()
        {
            var bytes  = HexStringToByteArray("0201060303aafe0d16aafe10e702676f6f676c65000c09526164426561636f6e204700000000000000000000000000000000000000000000000000000000");
            var parser = new BeaconParser();

            parser.SetAllowPduOverflow(Java.Lang.Boolean.False);
            parser.SetBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20");
            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.Null("beacon should not be parsed", beacon);
        }
        public void TestDetectsGattBeacon2MaxLength()
        {
            byte[]       bytes      = HexStringToByteArray("020106030334121616341210ec007261646975736e6574776f726b7373070000000000000000000000000000000000000000000000000000000000000000");
            BeaconParser parser     = new BeaconParser().SetBeaconLayout("s:0-1=1234,m:2-2=10,p:3-3:-41,i:4-20v");
            Beacon       gattBeacon = parser.FromScanData(bytes, -55, null, DateTime.UtcNow.Ticks);

            AssertEx.NotNull("GattBeacon should be not null if parsed successfully", gattBeacon);
            AssertEx.AreEqual("GattBeacon identifier length should be proper length",
                              17,
                              gattBeacon.Id1.ToByteArray().Length);
        }
Exemplo n.º 19
0
        public void TestReEncodesBeaconForEddystoneTelemetry()
        {
            var bytes  = HexStringToByteArray("0201060303aafe1516aafe2001021203130414243405152535");
            var parser = new BeaconParser();

            parser.SetBeaconLayout(BeaconParser.EddystoneTlmLayout);
            var beacon           = parser.FromScanData(bytes, -55, null);
            var regeneratedBytes = parser.GetBeaconAdvertisementData(beacon);
            var expectedMatch    = Java.Util.Arrays.CopyOfRange(bytes, 11, bytes.Length);

            AssertEx.AreEqual("beacon advertisement bytes should be the same after re-encoding", ByteArrayToHexString(expectedMatch), ByteArrayToHexString(regeneratedBytes));
        }
        public void testEddystoneScanFilterData()
        {
            BeaconParser parser = new BeaconParser();

            parser.SetBeaconLayout(BeaconParser.EddystoneUidLayout);
            BeaconManager.SetsManifestCheckingDisabled(true);     // no manifest available in robolectric
            var scanFilterDatas = new ScanFilterUtils().CreateScanFilterDataForBeaconParser(parser);

            AssertEx.AreEqual("scanFilters should be of correct size", 1, scanFilterDatas.Count);
            ScanFilterUtils.ScanFilterData sfd = scanFilterDatas[0];
            AssertEx.AreEqual("serviceUuid should be right", new Java.Lang.Long(0xfeaa).LongValue(), sfd.ServiceUuid.LongValue());
        }
Exemplo n.º 21
0
        public void TestReEncodesLittleEndianBeacon()
        {
            var bytes  = HexStringToByteArray("02011a1bff1801beac0102030405060708090a0b0c0d0e0f1011121314c509");
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=beac,i:4-9,i:10-15l,i:16-23,p:24-24,d:25-25");
            var beacon           = parser.FromScanData(bytes, -55, null);
            var regeneratedBytes = parser.GetBeaconAdvertisementData(beacon);
            var expectedMatch    = Java.Util.Arrays.CopyOfRange(bytes, 7, bytes.Length);

            AssertEx.AreEqual("beacon advertisement bytes should be the same after re-encoding", ByteArrayToHexString(expectedMatch), ByteArrayToHexString(regeneratedBytes));
        }
        public void TestDetectsGattBeaconWithCnn()
        {
            byte[]       bytes  = HexStringToByteArray("020106030334120a16341210ed00636e6e070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
            BeaconParser parser = new BeaconParser().SetBeaconLayout("s:0-1=1234,m:2-2=10,p:3-3:-41,i:4-20v");

            Beacon gattBeacon = parser.FromScanData(bytes, -55, null, DateTime.UtcNow.Ticks);

            AssertEx.NotNull("GattBeacon should be not null if parsed successfully", gattBeacon);
            AssertEx.AreEqual("GattBeacon identifier length should be adjusted smaller if packet is short",
                              5,
                              gattBeacon.Id1.ToByteArray().Length);
        }
Exemplo n.º 23
0
        public void TestReEncodesBeacon()
        {
            var bytes  = HexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509");
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            var beacon           = parser.FromScanData(bytes, -55, null);
            var regeneratedBytes = parser.GetBeaconAdvertisementData(beacon);
            var expectedMatch    = Java.Util.Arrays.CopyOfRange(bytes, 7, bytes.Length);

            AssertEx.AreEqual("beacon advertisement bytes should be the same after re-encoding", expectedMatch, regeneratedBytes);
        }
Exemplo n.º 24
0
        public void TestCanGetAdvertisementDataForUrlBeacon()
        {
            var beacon = new Beacon.Builder()
                         .SetManufacturer(0x0118)
                         .SetId1("02646576656c6f7065722e636f6d") // http://developer.com
                         .SetTxPower(-59)                        // The measured transmitter power at one meter in dBm
                         .Build();
            var p = new BeaconParser().
                    SetBeaconLayout("s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v");
            var bytes = p.GetBeaconAdvertisementData(beacon);

            AssertEx.AreEqual("First byte of url should be in position 3", 0x02, bytes[2]);
        }
        public override void OnCreate()
        {
            base.OnCreate();

            var beaconManager = BeaconManager.GetInstanceForApplication(this);

            // By default the AndroidBeaconLibrary will only find AltBeacons.  If you wish to make it
            // find a different type of beacon, you must specify the byte layout for that beacon's
            // advertisement with a line like below.  The example shows how to find a beacon with the
            // same byte layout as AltBeacon but with a beaconTypeCode of 0xaabb.  To find the proper
            // layout expression for other beacon types, do a web search for "setBeaconLayout"
            // including the quotes.
            //
            //beaconManager.getBeaconParsers().clear();
            //beaconManager.getBeaconParsers().add(new BeaconParser().
            //        setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
            //
            // Estimote
            // iBeacons
            //beaconManager.getBeaconParsers().add(new BeaconParser().
            //	      setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

            var altBeaconParser = new BeaconParser();

            altBeaconParser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            beaconManager.BeaconParsers.Add(altBeaconParser);

            var iBeaconParser = new BeaconParser();

            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            beaconManager.BeaconParsers.Add(iBeaconParser);

            Debug.WriteLine("setting up background monitoring for beacons and power saving", TAG);

            // wake up the app when a beacon is seen
            var region = new Region("backgroundRegion", null, null, null);

            regionBootstrap = new RegionBootstrap(this, region);

            // simply constructing this class and holding a reference to it in your custom Application
            // class will automatically cause the BeaconLibrary to save battery whenever the application
            // is not visible.  This reduces bluetooth power usage by about 60%
            backgroundPowerSaver = new BackgroundPowerSaver(this);

            // If you wish to test beacon detection in the Android Emulator, you can use code like this:
            //BeaconManager.BeaconSimulator = new TimedBeaconSimulator();
            //if (BeaconManager.BeaconSimulator is TimedBeaconSimulator simulator) {
            //	//simulator.CreateTimedSimulatedBeacons();
            //	simulator.CreateBasicSimulatedBeacons();
            //}
        }
Exemplo n.º 26
0
        private BeaconManager InitializeBeaconManager()
        {
            RequestPermission();
            // Enable the BeaconManager
            _beaconManager = BeaconManager.GetInstanceForApplication(_mainActivity);

            /*
             #region Set up Beacon Simulator for TEST USE
             * // Beacon Simulator
             * var beaconSimulator = new BeaconSimulator();
             * beaconSimulator.CreateBasicSimulatedBeacons();
             * BeaconManager.BeaconSimulator = beaconSimulator;
             * // Beacon Simulator
             #endregion Set up Beacon Simulator for TEST USE
             */

            _monitorNotifier = new MonitorNotifier();
            _rangeNotifier   = new RangeNotifier();

            //iBeacon
            BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(AppConstants.iBeaconFormat);

            _beaconManager.BeaconParsers.Add(beaconParser);

            // BeaconManager Setting
            // Check Touch おそらくmain activity beacon consumer側で設定

            /*
             * _beaconManager.SetForegroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetForegroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.SetBackgroundBetweenScanPeriod(AppConstants.BEACONS_UPDATES_IN_MILLISECONDS);
             * _beaconManager.UpdateScanPeriods();
             */

            // MonitorNotifier
            _monitorNotifier.DetermineStateForRegionComplete += DetermineStateForRegionComplete;
            _monitorNotifier.EnterRegionComplete             += EnterRegionComplete;
            _monitorNotifier.ExitRegionComplete += ExitRegionComplete;
            _beaconManager.AddMonitorNotifier(_monitorNotifier);

            // RangeNotifier
            _rangeNotifier.DidRangeBeaconsInRegionComplete += DidRangeBeaconsInRegionComplete;
            _beaconManager.AddRangeNotifier(_rangeNotifier);


            _fieldRegion = new AltBeaconOrg.BoundBeacon.Region("AppAppApp", Identifier.Parse(AppConstants.iBeaconAppUuid), null, null);

            _beaconManager.Bind(_mainActivity);
            return(_beaconManager);
        }
        public void TestDetectsGattBeacon()
        {
            byte[]       bytes  = HexStringToByteArray("020106030334121516341200e72f234454f4911ba9ffa6000000000001000000000000000000000000000000000000000000000000000000000000000000");
            BeaconParser parser = new BeaconParser().SetBeaconLayout("s:0-1=1234,m:2-2=00,p:3-3:-41,i:4-13,i:14-19");

            AssertEx.NotNull("Service uuid parsed should not be null", parser.ServiceUuid);
            Beacon gattBeacon = parser.FromScanData(bytes, -55, null, DateTime.UtcNow.Ticks);

            AssertEx.NotNull("GattBeacon should be not null if parsed successfully", gattBeacon);
            AssertEx.AreEqual("id1 should be parsed", "0x2f234454f4911ba9ffa6", gattBeacon.Id1.ToString());
            AssertEx.AreEqual("id2 should be parsed", "0x000000000001", gattBeacon.Id2.ToString());
            AssertEx.AreEqual("serviceUuid should be parsed", 0x1234, gattBeacon.ServiceUuid);
            AssertEx.AreEqual("txPower should be parsed", -66, gattBeacon.TxPower);
        }
Exemplo n.º 28
0
        public void TestParseProblematicBeaconFromIssue229()
        {
            // Note that the length field below is 0x16 instead of 0x1b, indicating that the packet ends
            // one byte before the second identifier field starts

            var bytes  = HexStringToByteArray("0201061bffe000beac7777772e626c756b692e636f6d000100010001abaa000000");
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.NotNull("beacon should be parsed", beacon);
        }
Exemplo n.º 29
0
        public void TestParseManufacturerIdentifierThatRunsOverPduLength()
        {
            // Note that the length field below is 0x16 instead of 0x1b, indicating that the packet ends
            // one byte before the second identifier field starts
            var bytes  = HexStringToByteArray("02011a16ff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509000000");
            var parser = new BeaconParser();

            parser.SetAllowPduOverflow(Java.Lang.Boolean.False);
            parser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

            var beacon = parser.FromScanData(bytes, -55, null);

            AssertEx.Null("beacon should not be parsed", beacon);
        }
Exemplo n.º 30
0
        public void StartBeacon()

        {
            _beaconManager          = BeaconManager.GetInstanceForApplication(this);
            _monitorNotifier        = new MonitorNotifier();
            _rangeNotifier          = new RangeNotifier();
            _dictionaryOfBeaconData = new Dictionary <string, BeaconDataModel>();

            //iBeacon
            BeaconParser beaconParser = new BeaconParser().SetBeaconLayout(AppConstants.IBEACON_FORMAT);

            _beaconManager.BeaconParsers.Add(beaconParser);
            _beaconManager.Bind(this);
        }
        public void testZeroOffsetScanFilter()
        {
            BeaconParser parser = new BeaconParser();

            parser.SetBeaconLayout("m:0-3=11223344,i:4-6,p:24-24");
            BeaconManager.SetsManifestCheckingDisabled(true);     // no manifest available in robolectric
            var scanFilterDatas = new ScanFilterUtils().CreateScanFilterDataForBeaconParser(parser);

            AssertEx.AreEqual("scanFilters should be of correct size", 1, scanFilterDatas.Count);
            ScanFilterUtils.ScanFilterData sfd = scanFilterDatas[0];
            AssertEx.AreEqual("manufacturer should be right", 0x004c, sfd.Manufacturer);
            AssertEx.AreEqual("mask length should be right", 2, sfd.Mask.Count);
            AssertEx.AreEqual("mask should be right", new byte[] { (byte)0xff, (byte)0xff }, sfd.Mask.ToArray());
            AssertEx.AreEqual("filter should be right", new byte[] { (byte)0x33, (byte)0x44 }, sfd.Filter.ToArray());
        }
Exemplo n.º 32
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            _status = FindViewById<TextView>(Resource.Id.Status);

            _beaconManager = BeaconManager.GetInstanceForApplication(this);

            var iBeaconParser = new BeaconParser();
            iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            _beaconManager.BeaconParsers.Add(iBeaconParser);

            _beaconManager.SetRangeNotifier(this);
            _beaconManager.Bind(this);
        }
		public override void OnCreate()
		{
			base.OnCreate();

			_beaconManager = BeaconManager.GetInstanceForApplication(this);

			var iBeaconParser = new BeaconParser();
			//	Estimote > 2013
			iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
			_beaconManager.BeaconParsers.Add(iBeaconParser);

			Log.Debug(TAG, "setting up background monitoring for beacons and power saving");
			// wake up the app when a beacon is seen
			_backgroundRegion = new Region("backgroundRegion", null, null, null);
			regionBootstrap = new RegionBootstrap(this, _backgroundRegion);

			// simply constructing this class and holding a reference to it in your custom Application
			// class will automatically cause the BeaconLibrary to save battery whenever the application
			// is not visible.  This reduces bluetooth power usage by about 60%
			backgroundPowerSaver = new BackgroundPowerSaver(this);
		}
Exemplo n.º 34
0
		private BeaconManager InitializeBeaconManager()
		{
			// Enable the BeaconManager 
			BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

			#region Set up Beacon Simulator if testing without a BLE device
			var beaconSimulator = new BeaconSimulator();
			beaconSimulator.CreateBasicSimulatedBeacons();
			BeaconManager.BeaconSimulator = beaconSimulator;
			#endregion

			var iBeaconParser = new BeaconParser();
			//	Estimote > 2013
//			iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
			iBeaconParser.SetBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24");

//			bm.BeaconParsers.Add(iBeaconParser);

			if (bm.BeaconParsers.Count == 1) {
				bm.BeaconParsers.Add(iBeaconParser);
			}

			_monitorNotifier.EnterRegionComplete += EnteredRegion;
			_monitorNotifier.ExitRegionComplete += ExitedRegion;
			_monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
			_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

			//			region1 = new AltBeaconOrg.BoundBeacon.Region("myUniqueBeaconId1", Identifier.Parse("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A"), null, null);
			region1 = new AltBeaconOrg.BoundBeacon.Region ("myUniqueBeaconId1", Identifier.Parse ("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A"), null, null);
			//			region2 = new AltBeaconOrg.BoundBeacon.Region ("Prompt2", Identifier.Parse ("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A"), null, null);
			//			region3 = new AltBeaconOrg.BoundBeacon.Region ("Prompt3", Identifier.Parse("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A"), null, null);
			//			region4 = new AltBeaconOrg.BoundBeacon.Region ("Prompt4", Identifier.Parse("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A"), null, null);
			_emptyRegion = new AltBeaconOrg.BoundBeacon.Region("myEmptyBeaconId", null, null, null);

			bm.SetBackgroundMode(false);
			bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);

			return bm;
		}
Exemplo n.º 35
0
		private static BeaconManager InitializeBeaconManager()
		{
			// Enable the BeaconManager 
			BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

			var iBeaconParser = new BeaconParser();
			//	Estimote > 2013
			iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
			bm.BeaconParsers.Add(iBeaconParser);

			_monitorNotifier.EnterRegionComplete += EnteredRegion;
			_monitorNotifier.ExitRegionComplete += ExitedRegion;
			_monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
			_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

			foreach (KeyValuePair<string, string> kvp in _info) {
				beaconRegion.Add (new AltBeaconOrg.BoundBeacon.Region (kvp.Key, Identifier.Parse (kvp.Value), null, null));
			}

			bm.SetBackgroundMode(false);
			bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);

			return bm;
		}