Skip to content

Update to Altbeacon 2.12.3 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<RootNamespace>AndroidAltBeaconLibrary.UnitTests</RootNamespace>
<AssemblyName>AndroidAltBeaconLibrary.UnitTests</AssemblyName>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Logging;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Logging;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Android.OS;
using NUnit.Framework;

Expand All @@ -20,14 +20,6 @@ public void TestRecognizeBeacon()
[Test]
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");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Android.Annotation;
using Android.Runtime;
using NUnit.Framework;
Expand All @@ -20,16 +20,6 @@ public void TestSetBeaconLayout()
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]);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Distance;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Distance;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand All @@ -12,7 +12,7 @@ public class BeaconTest : TestBase
[SetUp]
public void BeforeEachTest()
{
Beacon.SetHardwareEqualityEnforced(false);
Beacon.HardwareEqualityEnforced = (false);
}

[Test]
Expand Down Expand Up @@ -76,7 +76,7 @@ public void TestBeaconsWithDifferentId3AreNotEqual() {

[Test]
public void TestBeaconsWithSameMacsAreEqual() {
Beacon.SetHardwareEqualityEnforced(true);
Beacon.HardwareEqualityEnforced = (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();
Expand All @@ -88,7 +88,7 @@ public void TestBeaconsWithSameMacsAreEqual() {

[Test]
public void TestBeaconsWithDifferentMacsAreNotEqual() {
Beacon.SetHardwareEqualityEnforced(true);
Beacon.HardwareEqualityEnforced = (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();
Expand Down Expand Up @@ -131,7 +131,7 @@ public void TestCalculateAccuracyWithRssiEqualsPowerOnInternalProperties() {
[Test]
public void TestCalculateAccuracyWithRssiEqualsPowerOnInternalPropertiesAndRunningAverage() {
var beacon = new Beacon.Builder().SetTxPower(-55).SetRssi(0).Build();
beacon.SetRunningAverageRssi(-55);
beacon.RunningAverageRssi = (-55);
double distance = beacon.Distance;
AssertEx.AreEqual("Distance should be one meter if mRssi is the same as power", 1.0, distance, 0.1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Android.App;
using Android.Content;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using AltBeaconOrg.BoundBeacon.Distance;
using Android.Content;
using NUnit.Framework;
using Org.Altbeacon.Beacon.Distance;

namespace AndroidAltBeaconLibrary.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Utils;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Utils;
using Android.App;
using Android.Content;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Java.Lang;
using Java.Util;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Java.Lang;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using NUnit.Framework;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using Android.OS;
using System.Text;

Expand All @@ -11,96 +11,8 @@ public class SBeaconTest : TestBase
{
[Test]
public void testDetectsSBeacon() {
byte[] bytes = HexStringToByteArray("02011a1bff1801031501000100c502000000000000000003");
SBeaconParser parser = new SBeaconParser();
SBeacon sBeacon = (SBeacon) parser.FromScanData(bytes, -55, null);
AssertEx.NotNull("SBeacon should be not null if parsed successfully", sBeacon);
AssertEx.AreEqual("id should be parsed", "0x000000000003", sBeacon.Id);
AssertEx.AreEqual("group should be parsed", 1, sBeacon.Group);
AssertEx.AreEqual("time should be parsed", 2, sBeacon.Time);
AssertEx.AreEqual("txPower should be parsed", -59, sBeacon.TxPower);

}

protected class SBeacon : Beacon {
int mTime;

public SBeacon(int grouping, String id, int time, int txPower, int rssi, int beaconTypeCode, String bluetoothAddress) {
TxPower = txPower;
Rssi = rssi;
BeaconTypeCode = beaconTypeCode;
BluetoothAddress = bluetoothAddress;
Identifiers = new System.Collections.Generic.List<Identifier>();
Identifiers.Add(Identifier.FromInt(grouping));
Identifiers.Add(Identifier.Parse(id));
mTime = time;
}

public SBeacon(Parcel parcel) {
// TODO: Implement me
}

public int Group => ((Identifier)Identifiers[0]).ToInt();

public int Time => mTime;

public String Id => Identifiers[1].ToString();

public override int DescribeContents()
{
return 0;
}

public override void WriteToParcel(Parcel @out, ParcelableWriteFlags flags)
{
// TODO: Implement me
}
}

internal class SBeaconParser : BeaconParser {
//private static final String TAG = "SBeaconParser";

public override Beacon FromScanData(byte[] scanData, int rssi, Android.Bluetooth.BluetoothDevice device)
{
int startByte = 2;
while (startByte <= 5) {
// "m:2-3=0203,i:2-2,i:7-8,i:14-19,d:10-13,p:9-9"
if (((int)scanData[startByte+3] & 0xff) == 0x03 &&
((int)scanData[startByte+4] & 0xff) == 0x15) {
//BeaconManager.logDebug(TAG, "This is a SBeacon beacon advertisement");
// startByte+0 company id (2 bytes)
// startByte+2 = 02 (1) byte header
// startByte+3 = 0315 (2 bytes) header
// startByte+5 = Beacon Type 0x01
// startByte+6 = Reserved (1 bytes)
// startByte+7 = Security Code (2 bytes) => Major little endian
// startByte+9 = Tx Power => Tx Power
// startByte+10 = Timestamp (4 bytes) => Minor (2 LSBs) little endian
// startByte+14 = Beacon ID (6 bytes) -> UUID little endian
int grouping = (scanData[startByte+8] & 0xff) * 0x100 + (scanData[startByte+7] & 0xff);
int clock = (scanData[startByte+13] & 0xff) * 0x1000000 + (scanData[startByte+12] & 0xff) * 0x10000 + (scanData[startByte+11] & 0xff) * 0x100 + (scanData[startByte+10] & 0xff);
int txPower = (int)(sbyte)scanData[startByte+9]; // this one is signed

byte[] beaconId = new byte[6];
//Java.Lang.JavaSystem.Arraycopy(scanData, startByte+14, beaconId, 0, 6);
Array.Copy(scanData, startByte+14, beaconId, 0, 6);
String hexString = BytesToHex(beaconId);
StringBuilder sb = new StringBuilder();
sb.Append(hexString.Substring(0,12));
String id = "0x" + sb.ToString();
int beaconTypeCode = (scanData[startByte+3] & 0xff) * 0x100 + (scanData[startByte+2] & 0xff);


String mac = null;
if (device != null) {
mac = device.Address;
}
Beacon beacon = new SBeacon(grouping, id, clock, txPower, rssi, beaconTypeCode, mac);
return beacon;
}
startByte++;
}
return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using AltBeaconOrg.BoundBeacon.Service;
using NUnit.Framework;
using NUnit.Framework;
using Org.Altbeacon.Beacon.Service;

namespace AndroidAltBeaconLibrary.UnitTests
{
[TestFixture]
[TestFixture]
public class ArmaRssiFilterTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Service;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Service;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Service;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Service;
using Android.Content;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Service;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Service;
using System.Collections.Generic;
using Android.Content;
using Android.OS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using NUnit.Framework;
using AltBeaconOrg.BoundBeacon.Service;
using Org.Altbeacon.Beacon.Service;

namespace AndroidAltBeaconLibrary.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using AltBeaconOrg.BoundBeacon.Service.Scanner;
using Org.Altbeacon.Beacon.Service.Scanner;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Service.Scanner;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Service.Scanner;
using NUnit.Framework;

namespace AndroidAltBeaconLibrary.UnitTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Simulator;
using Org.Altbeacon.Beacon;
using Org.Altbeacon.Beacon.Simulator;
using NUnit.Framework;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using NUnit.Framework;
using AltBeaconOrg.BoundBeacon;
using Org.Altbeacon.Beacon;
using System.Collections.Generic;
using AltBeaconOrg.BoundBeacon.Utils;
using Org.Altbeacon.Beacon.Utils;

namespace AndroidAltBeaconLibrary.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using AltBeaconOrg.BoundBeacon.Utils;
using Org.Altbeacon.Beacon.Utils;
using Java.Util;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using NUnit.Framework;
using AltBeaconOrg.Bluetooth;
using Org.Altbeacon.Bluetooth;

namespace AndroidAltBeaconLibrary.UnitTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Java.Lang;

namespace Org.Altbeacon.Beacon
{
partial class Identifier
{
int Java.Lang.IComparable.CompareTo(Java.Lang.Object other)
{
return CompareTo(other as Identifier);
}
}
}

namespace Org.Altbeacon.Beacon.Distance {
partial class ModelSpecificDistanceUpdater : Android.OS.AsyncTask
{
protected override Object DoInBackground(params Object[] @params)
{
return DoInBackground((Java.Lang.Void[])@params);
}
}
}
Loading