Skip to content

Commit

Permalink
Use sbyte instead of byte for accessing ranging data in Eddystone UID…
Browse files Browse the repository at this point in the history
… frames to ease development and remove the need for manual casting.
  • Loading branch information
andijakl committed Feb 8, 2016
1 parent 629e288 commit 835ab58
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ To try the Windows 10 example app, download the complete library package from th

## Version History

### 1.8.0 - February 2016
* Use sbyte instead of byte for accessing ranging data in Eddystone UID frames to ease development and remove the need for manual casting.

### 1.7.0 - January 2016
* Added translations to Chinese, French, Russian and Portuguese

### 1.6.0 - January 2016
* Added translation to German
* Fix crash when a Bluetooth Beacon with no further data is found.
Expand Down
15 changes: 10 additions & 5 deletions UniversalBeaconLibrary/Beacon/UidEddystoneFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ namespace UniversalBeaconLibrary.Beacon
/// </summary>
public class UidEddystoneFrame : BeaconFrameBase
{
private byte _rangingData;
private sbyte _rangingData;

/// <summary>
/// Tx power level - the received power level at 0 m, in dBm.
/// Values range from -100 to +20 dBM, with a resolution of 1 dBm.
/// Signed 8 bit integer according to:
/// https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.tx_power_level.xml
/// Conversion between sbyte and byte works at runtime with simple casting for variables.
/// In order to convert constants at compile time, you might need to run the conversion in
/// an unchecked() context. For example:
/// sbyte rangingData = unchecked((sbyte)0xEE);
/// According to the documentation, this corresponds to the dBm value of -18.
/// </summary>
public byte RangingData
public sbyte RangingData
{
get { return _rangingData; }
set
Expand Down Expand Up @@ -125,7 +130,7 @@ public ulong InstanceIdAsNumber
}
}

public UidEddystoneFrame(byte rangingData, byte[] namespaceId, byte[] instanceId)
public UidEddystoneFrame(sbyte rangingData, byte[] namespaceId, byte[] instanceId)
{
_rangingData = rangingData;
if (namespaceId != null && namespaceId.Length == 10)
Expand Down Expand Up @@ -158,7 +163,7 @@ public void ParsePayload()
// Note that this is different from other beacon protocol specifications that require the Tx power
// to be measured at 1 m.The value is an 8-bit integer as specified by the Tx Power Level Characteristic
// and ranges from -100 dBm to +20 dBm to a resolution of 1 dBm.
var newRangingData = Payload[BeaconFrameHelper.EddystoneHeaderSize];
var newRangingData = (sbyte)Payload[BeaconFrameHelper.EddystoneHeaderSize];
if (newRangingData != RangingData)
{
_rangingData = newRangingData;
Expand Down Expand Up @@ -208,7 +213,7 @@ private void UpdatePayload()
// Frame header
ms.Write(header, 0, header.Length);
// Ranging data
ms.WriteByte(RangingData);
ms.WriteByte((byte)RangingData);
// Namespace ID
ms.Write(NamespaceId, 0, NamespaceId.Length);
// Instance ID
Expand Down
6 changes: 6 additions & 0 deletions UniversalBeaconLibrary/NuGetPackage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo --------------------------------------------------------------------------
@echo Remember to update the release notes in /UniversalBeaconLibrary.nuspec
@echo --------------------------------------------------------------------------
nuget pack ./UniversalBeaconLibrary.nuspec -OutputDirectory ./nupkg -Build -Symbols -Prop Configuration=Release


28 changes: 28 additions & 0 deletions UniversalBeaconLibrary/UniversalBeaconLibrary.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="3.0">
<id>UniversalBeaconLibrary</id>
<version>1.8.0</version>
<releaseNotes>Fix for correctly handling beacon advertisements that are null</releaseNotes>
<title>Universal Beacon Library for the Universal Windows Platform (Windows 10 UWP)</title>
<authors>Andreas Jakl</authors>
<owners>Andreas Jakl</owners>
<licenseUrl>https://github.com/andijakl/universal-beacon/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/andijakl/universal-beacon</projectUrl>
<iconUrl>https://raw.githubusercontent.com/andijakl/universal-beacon/master/UniversalBeaconLibraryLogo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>Support Bluetooth Beacons in UWP / Windows 10 apps. Manages beacon instances, advertisements, frames and protocols. Includes Eddystone parsing.</summary>
<description>Adds support for Bluetooth Beacons to the Universal Windows Platform (Windows 10). Manages received Bluetooth advertisements, clusters them into individual beacons and parses the advertisement payloads according to specifications including the Eddystone open Bluetooth Smart beacon format from Google.</description>
<copyright>Copyright 2015 - 2016 Andreas Jakl, Tieto Corporation. All rights reserved.</copyright>
<tags>bluetooth beacon beacons ibeacon eddystone altbeacon bluetoothle bluetoothsmart bluetooth le bluetooth smart ble proximity universal</tags>
<dependencies>
<dependency id="Microsoft.NETCore.UniversalWindowsPlatform" version="5.0.0" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\UniversalBeaconLibrary.dll" target="lib\uap10.0\UniversalBeaconLibrary.dll" />
<file src="bin\Release\UniversalBeaconLibrary.pdb" target="lib\uap10.0\UniversalBeaconLibrary.pdb" />
<file src="Beacon\**\*.cs" target="src\Beacon" exclude="**\TemporaryGeneratedFile*.cs"/>
<file src="Properties\**\*.cs" target="src\Properties" exclude="**\TemporaryGeneratedFile*.cs"/>
</files>
</package>
5 changes: 4 additions & 1 deletion WindowsBeacons/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public MainPage()
//#if DEBUG
// var eddystoneBeacon = new Beacon(Beacon.BeaconTypeEnum.Eddystone);
// eddystoneBeacon.BeaconFrames.Add(new TlmEddystoneFrame(0, 3100, (float)25.5, 2000, 1000));
// eddystoneBeacon.BeaconFrames.Add(new UidEddystoneFrame(220,
// // Ranging Data 0xEE = -18dbM: needs unchecked syntax to cast constants, works without unchecked for runtime variables
// // (sbyte)0x12 = +18dbM
// // Sample values from: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.tx_power_level.xml
// eddystoneBeacon.BeaconFrames.Add(new UidEddystoneFrame(unchecked((sbyte)0xEE),
// new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
// new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }));
// eddystoneBeacon.BeaconFrames.Add(new UrlEddystoneFrame(220, "http://www.tieto.at"));
Expand Down
2 changes: 1 addition & 1 deletion WindowsBeacons/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="39745AndreasJakl.BluetoothBeaconInteractor" Publisher="CN=AA09B9A0-DEBB-4495-BAA8-7D2028458E75" Version="1.7.23.0" />
<Identity Name="39745AndreasJakl.BluetoothBeaconInteractor" Publisher="CN=AA09B9A0-DEBB-4495-BAA8-7D2028458E75" Version="1.8.24.0" />
<mp:PhoneIdentity PhoneProductId="27f10f31-b0a2-48e3-96e6-5d89c3d36518" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>Bluetooth Beacon Interactor</DisplayName>
Expand Down
4 changes: 2 additions & 2 deletions WindowsBeacons/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
[assembly: ComVisible(false)]

0 comments on commit 835ab58

Please sign in to comment.