Skip to content

Commit

Permalink
new repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Malachi Griffie committed Dec 14, 2016
0 parents commit 1d50f4e
Show file tree
Hide file tree
Showing 24 changed files with 1,772 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.env

.vs/
.sass-cache/
.tscache/
node_modules/
lib/packages/
obj/
bin/
csx/
rcf/
Backup/

.baseDir.ts
.userprefs
gulp-tsc-tmp*
Resource.Designer.cs

*.tmp.txt
*.userprefs
*.db
*.log
*.sublime-project
*.sublime-workspace
*.sass-cache
*.suo
*.user
*.nupkg
*.bak
project.lock.json
370 changes: 370 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ble.net [![Build status](https://img.shields.io/appveyor/ci/nexussays/ble-net.svg?style=flat-square)](https://ci.appveyor.com/project/nexussays/ble-net) [![NuGet](https://img.shields.io/nuget/v/ble.net.svg?style=flat-square)](https://www.nuget.org/packages/ble.net) [![MPLv2 License](https://img.shields.io/badge/license-MPLv2-blue.svg?style=flat-square)](https://www.mozilla.org/MPL/2.0/)

`ble.net` is a Bluetooth Low Energy (aka BLE, aka Bluetooth LE, aka Bluetooth Smart) PCL to enable simple development of BLE clients on Android, iOS, and Windows 10 (advertising only at the moment, the underlying UWP connection API is pretty bad).

> Currently only client operations are supported. Server operations will be added in the future if there is significant enough interest.
### Getting Started

#### Install NuGet packages

Include `ble.net` in your shared project
```powershell
Install-Package ble.net
```

In each platform project, install the relevant package:
```powershell
Install-Package ble.net-android
```
> Note that there are two packages for Android, `ble.net-android` and `ble.net-android21`; the API 21+ package is not materially different for client operations but will be needed if/when server operations are implemented. You should probably just use `ble.net-android` unless you have a specific reason not to.
```powershell
Install-Package ble.net-ios
```
```powershell
Install-Package ble.net-uwp
```

#### Obtain a reference to `BluetoothLowEnergyAdapter`

Each platform project has a class `BluetoothLowEnergyAdapter` with a static method `BluetoothLowEnergyAdapter.ObtainDefault(/*possible arguments*/)`. Obtain this reference and then provide it to your application code using whatever dependency injector or manual referene passing you are using.
95 changes: 95 additions & 0 deletions ble.net.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ble.net", "src\ble.net\ble.net.csproj", "{48788CDA-AD31-4D16-BA67-831D0F6897F1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{89014F7A-2A01-4A85-9F3C-737316A7B0D2}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
nuget.config = nuget.config
Readme.md = Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Ad-Hoc|ARM = Ad-Hoc|ARM
Ad-Hoc|iPhone = Ad-Hoc|iPhone
Ad-Hoc|iPhoneSimulator = Ad-Hoc|iPhoneSimulator
Ad-Hoc|x64 = Ad-Hoc|x64
Ad-Hoc|x86 = Ad-Hoc|x86
AppStore|Any CPU = AppStore|Any CPU
AppStore|ARM = AppStore|ARM
AppStore|iPhone = AppStore|iPhone
AppStore|iPhoneSimulator = AppStore|iPhoneSimulator
AppStore|x64 = AppStore|x64
AppStore|x86 = AppStore|x86
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|iPhone = Debug|iPhone
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|iPhone = Release|iPhone
Release|iPhoneSimulator = Release|iPhoneSimulator
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|ARM.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|x64.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|Any CPU.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|ARM.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|ARM.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|iPhone.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|iPhone.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|x64.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|x64.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|x86.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.AppStore|x86.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|ARM.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|iPhone.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|x64.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|x64.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|x86.ActiveCfg = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Debug|x86.Build.0 = Debug|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|Any CPU.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|ARM.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|ARM.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|iPhone.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|iPhone.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|x64.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|x64.Build.0 = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|x86.ActiveCfg = Release|Any CPU
{48788CDA-AD31-4D16-BA67-831D0F6897F1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositorypath" value="./lib/packages" />
</config>
</configuration>
29 changes: 29 additions & 0 deletions src/ble.net/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Malachi Griffie
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;

#pragma warning disable 1591

namespace nexus.protocols.ble
{
public static class AssemblyInfo
{
public const String VERSION = "0.10.5";
public const String VERSION_SHORT = "0.10.5";
public const String ID = "ble.net";
public const String URL = "https://github.com/nexussays/ble.net";
public const Boolean IS_DEBUG =
#if DEBUG
true;
#else
false;
#endif

internal const String DESCRIPTION =
"Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and (partially) UWP";
}
}
75 changes: 75 additions & 0 deletions src/ble.net/BlePeripheral.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright Malachi Griffie
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;
using nexus.core;

namespace nexus.protocols.ble
{
/// <inheritDoc />
internal abstract class BlePeripheral : IBlePeripheral
{
public abstract IBlePeripheralAdvertisement Advertisement { get; }

/// <summary>
/// Constructor for subclasses to call.
/// </summary>
/// <remarks>
/// No point in this being public since it serves no purpose to instantiate outside of retrieving an the actual peripheral
/// from an adapter -- the interface can always be implemented if needed.
/// </remarks>
protected internal BlePeripheral( Guid guid, Byte[] address, Boolean? addressIsRandom )
{
DeviceId = guid;
Address = address;
AddressIsRandom = addressIsRandom;
}

/// <inheritdoc />
public Byte[] Address { get; }

/// <inheritDoc />
public Boolean? AddressIsRandom { get; }

/// <inheritDoc />
public Guid DeviceId { get; }

/// <inheritDoc />
public Int32 Rssi { get; protected set; }

/// <inheritDoc />
public override Boolean Equals( Object obj )
{
return Equals( obj as IBlePeripheral );
}

/// <inheritDoc />
public Boolean Equals( IBlePeripheral other )
{
return !ReferenceEquals( null, other ) && other.DeviceId.Equals( DeviceId );
}

/// <inheritDoc />
public override Int32 GetHashCode()
{
return DeviceId.GetHashCode();
}

/// <inheritDoc />
public override String ToString()
{
return Advertisement?.DeviceName?.IsNullOrWhiteSpace() != true
? "{0} <{1}>".F( Advertisement?.DeviceName, DeviceId )
: DeviceId.ToString();
}

/// <inheritDoc />
protected Boolean Equals( BlePeripheral other )
{
return Equals( (IBlePeripheral)other );
}
}
}
42 changes: 42 additions & 0 deletions src/ble.net/BlePeripheralAdvertisement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Malachi Griffie
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System;
using System.Collections.Generic;
using nexus.protocols.ble.advertisement;

namespace nexus.protocols.ble
{
internal abstract class BlePeripheralAdvertisement : IBlePeripheralAdvertisement
{
protected IDictionary<Int32, Byte[]> m_manufacturerData;
protected IList<AdvertisingDataItem> m_rawData;
protected IDictionary<Guid, Byte[]> m_serviceData;
protected ISet<Guid> m_services;

protected internal BlePeripheralAdvertisement()
{
m_services = new HashSet<Guid>();
m_serviceData = new Dictionary<Guid, Byte[]>();
m_manufacturerData = new Dictionary<Int32, Byte[]>();
m_rawData = new List<AdvertisingDataItem>();
}

public String DeviceName { get; protected set; }

public AdvertisingDataFlags Flags { get; protected set; }

public IEnumerable<KeyValuePair<Int32, Byte[]>> ManufacturerSpecificData => m_manufacturerData;

public IEnumerable<AdvertisingDataItem> RawData => m_rawData;

public IEnumerable<KeyValuePair<Guid, Byte[]>> ServiceData => m_serviceData;

public IEnumerable<Guid> Services => m_services;

public Int32 TxPowerLevel { get; protected set; }
}
}
Loading

0 comments on commit 1d50f4e

Please sign in to comment.