Example #1
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);
        }
        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);
        }
Example #3
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);
        }
		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;
		}
        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);
        }
Example #6
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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());
        }
Example #11
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 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());
        }
Example #13
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));
        }
Example #14
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));
        }
Example #15
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);
        }
        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();
            //}
        }
Example #17
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);
        }
Example #18
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);
        }
Example #19
0
        public void TestLittleEndianIdentifierParsing()
        {
            var bytes  = HexStringToByteArray("02011a1bff1801beac0102030405060708090a0b0c0d0e0f1011121314c50900000000");
            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);

            AssertEx.AreEqual("mRssi should be as passed in", -55, beacon.Rssi);
            AssertEx.AreEqual("id1 should be big endian", "0x010203040506", beacon.GetIdentifier(0).ToString());
            AssertEx.AreEqual("id2 should be little endian", "0x0c0b0a090807", beacon.GetIdentifier(1).ToString());
            AssertEx.AreEqual("id3 should be big endian", "0x0d0e0f1011121314", beacon.GetIdentifier(2).ToString());
            AssertEx.AreEqual("txPower should be parsed", -59, beacon.TxPower);
            AssertEx.AreEqual("manufacturer should be parsed", 0x118, beacon.Manufacturer);
        }
Example #20
0
        public void TestRecognizeBeaconWithFormatSpecifyingManufacturer()
        {
            var bytes  = HexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509000000");
            var parser = new BeaconParser();

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

            AssertEx.AreEqual("mRssi should be as passed in", -55, beacon.Rssi);
            AssertEx.AreEqual("uuid should be parsed", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", beacon.GetIdentifier(0).ToString());
            AssertEx.AreEqual("id2 should be parsed", "1", beacon.GetIdentifier(1).ToString());
            AssertEx.AreEqual("id3 should be parsed", "2", beacon.GetIdentifier(2).ToString());
            AssertEx.AreEqual("txPower should be parsed", -59, beacon.TxPower);
            AssertEx.AreEqual("manufacturer should be parsed", 0x118, beacon.Manufacturer);
        }
        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());
        }
        private void StartBeaconManager()
        {
            _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.Bind(this);
            _rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;

            if (_beaconManager.IsBound(this))
            {
                _beaconManager.SetBackgroundMode(false);
            }
        }
Example #23
0
        public void DoesNotCashWithOverflowingByteCodeComparisonOnPdu()
        {
            // Test for https://github.com/AltBeacon/android-beacon-library/issues/323

            // 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("02010604ffe000be");
            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.Null("beacon not be parsed without an exception being thrown", beacon);
        }
Example #24
0
        public void TestParsesBeaconMissingDataField()
        {
            var bytes  = HexStringToByteArray("02011a1aff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c5000000");
            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("mRssi should be as passed in", -55, beacon.Rssi);
            AssertEx.AreEqual("uuid should be parsed", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", beacon.GetIdentifier(0).ToString());
            AssertEx.AreEqual("id2 should be parsed", "1", beacon.GetIdentifier(1).ToString());
            AssertEx.AreEqual("id3 should be parsed", "2", beacon.GetIdentifier(2).ToString());
            AssertEx.AreEqual("txPower should be parsed", -59, beacon.TxPower);
            AssertEx.AreEqual("manufacturer should be parsed", 0x118, beacon.Manufacturer);
            AssertEx.AreEqual("missing data field zero should be zero", Convert.ToInt64(0), Convert.ToInt64(beacon.DataFields[0]));
        }
        public void testGenericScanFilter()
        {
            BeaconParser parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=1111,i:4-6,p:24-24");
            BeaconManager.ManifestCheckingDisabled = 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)0x11, (byte)0x11 }, sfd.Filter.ToArray());
            AssertEx.Null("serviceUuid should be null", sfd.ServiceUuid);
        }
Example #26
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);
        }
Example #27
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);
		}
Example #29
0
        public void TestSetBeaconLayout()
        {
            var bytes  = HexStringToByteArray("02011a1bffbeac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509000000");
            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");

            Assert.AreEqual(2, parser.MatchingBeaconTypeCodeStartOffset, "parser should get beacon type code start offset");
            Assert.AreEqual(3, parser.MatchingBeaconTypeCodeEndOffset, "parser should get beacon type code end offset");
            Assert.AreEqual(Convert.ToInt64(0xbeacL), Convert.ToInt64(parser.MatchingBeaconTypeCode), "parser should get beacon type code");
            Assert.AreEqual(4, parser.IdentifierStartOffsets[0], "parser should get identifier start offset");
            AssertEx.AreEqual("parser should get identifier end offset", 19, parser.IdentifierEndOffsets[0]);
            AssertEx.AreEqual("parser should get identifier start offset", 20, parser.IdentifierStartOffsets[1]);
            AssertEx.AreEqual("parser should get identifier end offset", 21, parser.IdentifierEndOffsets[1]);
            AssertEx.AreEqual("parser should get identifier start offset", 22, parser.IdentifierStartOffsets[2]);
            AssertEx.AreEqual("parser should get identifier end offset", 23, parser.IdentifierEndOffsets[2]);
            AssertEx.AreEqual("parser should get power start offset", 24, Convert.ToInt32(parser.PowerStartOffset));
            AssertEx.AreEqual("parser should get power end offset", 24, Convert.ToInt32(parser.PowerEndOffset));
            AssertEx.AreEqual("parser should get data start offset", 25, parser.DataStartOffsets[0]);
            AssertEx.AreEqual("parser should get data end offset", 25, parser.DataEndOffsets[0]);
        }
Example #30
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);
        }
		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;
		}
        /// <summary>
        /// Initializes the beacon manager, sets the Monitoring and Ranging Regions.
        /// Furthermore the standard of the Beacon which is suppose to be found, is
        /// set here. In the current context iBeacon standard beacons are searched/found.
        /// </summary>
        /// <returns>The beacon manager.</returns>
        private BeaconManager InitializeBeaconManager()
        {
            // Enable the BeaconManager
            BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);

            var iBeaconParser = new BeaconParser();

            //  sets the requirement for the Beacons (here 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;

            region = new Region("beaconId", null, null, null);

            bm.SetBackgroundMode(true);
            bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
            return(bm);
        }
        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);
        }
Example #34
0
        public void TestCanParseLongDataTypeOfDifferentSize()
        {
            // Create a beacon parser
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=0118,i:4-7,p:8-8,d:9-16,d:18-21,d:22-25");

            // Generate sample beacon for test purpose.
            var sampleData = new List <Java.Lang.Long>();
            var now        = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            sampleData.Add(new Java.Lang.Long(now));
            sampleData.Add(new Java.Lang.Long(1234L));
            sampleData.Add(new Java.Lang.Long(9876L));
            var beacon = new Beacon.Builder()
                         .SetManufacturer(0x0118)
                         .SetId1("02646576656c6f7065722e636f6d")
                         .SetTxPower(-59)
                         .SetDataFields(sampleData)
                         .Build();

            AssertEx.AreEqual("beacon contains a valid data on index 0", now, beacon.DataFields[0].LongValue());

            // Make byte array
            byte[] headerBytes = HexStringToByteArray("1bff1801");
            byte[] bodyBytes   = parser.GetBeaconAdvertisementData(beacon);
            byte[] bytes       = new byte[headerBytes.Length + bodyBytes.Length];
            Array.Copy(headerBytes, 0, bytes, 0, headerBytes.Length);
            Array.Copy(bodyBytes, 0, bytes, headerBytes.Length, bodyBytes.Length);

            // Try parsing the byte array
            Beacon parsedBeacon = parser.FromScanData(bytes, -59, null);

            AssertEx.AreEqual("parsed beacon should contain a valid data on index 0", now, parsedBeacon.DataFields[0].LongValue());
            AssertEx.AreEqual("parsed beacon should contain a valid data on index 1", Convert.ToInt64(1234L), parsedBeacon.DataFields[1].LongValue());
            AssertEx.AreEqual("parsed beacon should contain a valid data on index 2", Convert.ToInt64(9876L), parsedBeacon.DataFields[2].LongValue());
        }
Example #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;
		}