Skip to content

Commit

Permalink
-Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danardelean committed Sep 26, 2015
1 parent 330b4a0 commit f667e2c
Show file tree
Hide file tree
Showing 42 changed files with 1,986 additions and 0 deletions.
125 changes: 125 additions & 0 deletions Beacons.Helper/Beacons.Helper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http:https://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D372FDC7-9C33-448E-B8A9-C82B57934819}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Beacons.Helper</RootNamespace>
<AssemblyName>Beacons.Helper</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Beacons.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Content Include="Properties\Beacons.Helper.rd.xml" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
116 changes: 116 additions & 0 deletions Beacons.Helper/Beacons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Storage.Streams;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Diagnostics;

namespace Beacons
{
public sealed class iBeaconData
{
public Guid UUID { get; set; }
public ushort Major { get; set; }
public ushort Minor { get; set; }
public short TxPower { get; set; }
public double Distance { get; set; }
public short Rssi { get; set; }

public iBeaconData()
{
UUID = Guid.Empty;
Major = 0;
Minor = 0;
TxPower = 0;
Distance = 0;
Rssi = 0;
}
}
public static class iBeaconExtensions
{
public static void SetiBeaconAdvertisement(this BluetoothLEAdvertisement Advertisment, iBeaconData data)
{
BluetoothLEManufacturerData manufacturerData = new BluetoothLEManufacturerData();

// Set Apple as the manufacturer data
manufacturerData.CompanyId = 76;

var writer = new DataWriter();
writer.WriteUInt16(0x0215); //bytes 0 and 1 of the iBeacon advertisment indicator

if (data!=null& data.UUID!= Guid.Empty)
{
//If UUID is null scanning for all iBeacons
writer.WriteBytes( data.UUID.ToByteArray());
if (data.Major!=0)
{
//If Major not null searching with UUID and Major
writer.WriteBytes(BitConverter.GetBytes(data.Major).Reverse().ToArray());
if (data.Minor != 0)
{
//If Minor not null we are looking for a specific beacon not a class of beacons
writer.WriteBytes(BitConverter.GetBytes(data.Minor).Reverse().ToArray());
if (data.TxPower != 0)
writer.WriteBytes(BitConverter.GetBytes(data.TxPower));
}
}
}

manufacturerData.Data = writer.DetachBuffer();

Advertisment.ManufacturerData.Clear();
Advertisment.ManufacturerData.Add(manufacturerData);
}

public static iBeaconData ParseiBeaconAdvertisement(this BluetoothLEAdvertisement Advertisment,short RawSignalStrengthInDBm)
{
iBeaconData beacon = null;
foreach(var adv in Advertisment.ManufacturerData)
if (adv.CompanyId==76) //Apple
{
var bytes = adv.Data.ToArray();
if (bytes[0] == 0x02 && bytes[1] == 0x15 && bytes.Length==23)
{
//iBeacon Data
beacon = new iBeaconData();
beacon.UUID =new Guid(bytes.Skip(2).Take(16).ToArray());
beacon.Major = BitConverter.ToUInt16(bytes.Skip(18).Take(2).Reverse().ToArray(),0);
beacon.Minor = BitConverter.ToUInt16(bytes.Skip(20).Take(2).Reverse().ToArray(),0);
beacon.TxPower =(short) (sbyte) bytes[22];
beacon.Rssi = RawSignalStrengthInDBm;

//Estimated value
//Read this article http:https://developer.radiusnetworks.com/2014/12/04/fundamentals-of-beacon-ranging.html
beacon.Distance = CalculateDistance(beacon.TxPower,RawSignalStrengthInDBm);

Debug.WriteLine("UUID: "+beacon.UUID.ToString()+" Major: "+beacon.Major+" Minor:"+beacon.Minor+" Power: "+ beacon.TxPower+ " Rssi: "+RawSignalStrengthInDBm+" Distance:"+ beacon.Distance);
}
}

return beacon;
}

internal static double CalculateDistance(int txPower, double rssi)
{
if (rssi == 0)
{
return -1.0; // if we cannot determine accuracy, return -1.
}

double ratio = rssi * 1.0 / txPower;
if (ratio < 1.0)
{
return Math.Pow(ratio, 10);
}
else
{
double accuracy = (0.89976) * Math.Pow(ratio, 7.7095) + 0.111;
return accuracy;
}
}

}
}
29 changes: 29 additions & 0 deletions Beacons.Helper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Beacons.Helper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Beacons.Helper")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
33 changes: 33 additions & 0 deletions Beacons.Helper/Properties/Beacons.Helper.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains Runtime Directives, specifications about types your application accesses
through reflection and other dynamic code patterns. Runtime Directives are used to control the
.NET Native optimizer and ensure that it does not remove code accessed by your library. If your
library does not do any reflection, then you generally do not need to edit this file. However,
if your library reflects over types, especially types passed to it or derived from its types,
then you should write Runtime Directives.
The most common use of reflection in libraries is to discover information about types passed
to the library. Runtime Directives have three ways to express requirements on types passed to
your library.
1. Parameter, GenericParameter, TypeParameter, TypeEnumerableParameter
Use these directives to reflect over types passed as a parameter.
2. SubTypes
Use a SubTypes directive to reflect over types derived from another type.
3. AttributeImplies
Use an AttributeImplies directive to indicate that your library needs to reflect over
types or methods decorated with an attribute.
For more information on writing Runtime Directives for libraries, please visit
http:https://go.microsoft.com/fwlink/?LinkID=391919
-->
<Directives xmlns="http:https://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="Beacons.Helper">

<!-- add directives for your library here -->

</Library>
</Directives>
16 changes: 16 additions & 0 deletions Beacons.Helper/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
Loading

0 comments on commit f667e2c

Please sign in to comment.