Skip to content

Commit

Permalink
Added C# client library + GUI sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Emill committed Jul 28, 2016
1 parent 2efda80 commit 4ddb2ac
Show file tree
Hide file tree
Showing 32 changed files with 3,125 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This library is built on top of the HCI_CHANNEL_USER capability of the Linux ker
* `clientlib/python` - A library for python 3.3 or higher, very similar to the Java library. Some example programs included.
* `clientlib/websocket` - A websocket proxy and a demo client in html/javascript which you can use to scan and connect buttons.
* `clientlib/nodejs` - A library for nodejs and examples.
* `clientlib/csharp` - A library for C# with a GUI example that uses Windows Forms.
* `simpleclient` - A simple command line client with source code that can be used to test the protocol.
* `client_protocol_packets.h` - C/C++ structs for all packets that can be included in a C/C++ program.

Expand Down Expand Up @@ -45,7 +46,7 @@ All Bluetooth controllers with support for Bluetooth 4.0 and Bluetooth Low Energ
- Supports 10 concurrent connections and in total 128 pending connections. Can be a bit buggy sometimes, like dropping and duplicating BLE packets. Also sometimes "forgets" to disconnect a BLE link when instructed to. Should however work ok in most cases.

**Sena Technologies Parani-UD100-G03 (Cambridge Silicon Radio, Bluetooth 4.0)**
- Supports 5 concurrent connections and in total 25 pending connections. This one is recommended if you need large range. Other budget bluetooth dongles seem to have very short range.
- Supports 5 concurrent connections and in total 25 pending connections. This one is recommended if you need large range. Other budget bluetooth dongles seem to have very short range. Note that the BLE part of the Microsoft Windows driver for this controller currently does not work, in case you are using https://github.com/50ButtonsEach/fliclib-windows.

## Quick start
### Packages
Expand Down
32 changes: 32 additions & 0 deletions clientlib/csharp/FliclibDotNetClient/FliclibDotNetClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{05FE72CA-02BF-441E-BFF0-B789DE873CC0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1A914936-F6A0-46D2-B245-C21E47780A66}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FliclibDotNetClient", "src\FliclibDotNetClient\FliclibDotNetClient.xproj", "{3115FEF5-C233-42EB-A2C7-181279F60A4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3115FEF5-C233-42EB-A2C7-181279F60A4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3115FEF5-C233-42EB-A2C7-181279F60A4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3115FEF5-C233-42EB-A2C7-181279F60A4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3115FEF5-C233-42EB-A2C7-181279F60A4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3115FEF5-C233-42EB-A2C7-181279F60A4C} = {05FE72CA-02BF-441E-BFF0-B789DE873CC0}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions clientlib/csharp/FliclibDotNetClient/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-update2"
}
}
108 changes: 108 additions & 0 deletions clientlib/csharp/FliclibDotNetClient/src/FliclibDotNetClient/Bdaddr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace FliclibDotNetClient
{
/// <summary>
/// Represents a Bluetooth device address
/// </summary>
public sealed class Bdaddr
{
private readonly byte[] _bytes;

/// <summary>
/// Construct a Bdaddr from a string of the form "xx:xx:xx:xx:xx:xx".
/// </summary>
/// <param name="addr">Bluetooth device address</param>
public Bdaddr(string addr)
{
_bytes = new byte[6];
_bytes[5] = Convert.ToByte(addr.Substring(0, 2), 16);
_bytes[4] = Convert.ToByte(addr.Substring(3, 2), 16);
_bytes[3] = Convert.ToByte(addr.Substring(6, 2), 16);
_bytes[2] = Convert.ToByte(addr.Substring(9, 2), 16);
_bytes[1] = Convert.ToByte(addr.Substring(12, 2), 16);
_bytes[0] = Convert.ToByte(addr.Substring(15, 2), 16);
}

internal Bdaddr(BinaryReader reader)
{
_bytes = reader.ReadBytes(6);
if (_bytes.Length != 6)
{
throw new EndOfStreamException();
}
}

internal void WriteBytes(BinaryWriter writer)
{
writer.Write(_bytes);
}

/// <summary>
/// The string representation of a Bluetooth device address (xx:xx:xx:xx:xx:xx)
/// </summary>
/// <returns>A string</returns>
public override string ToString()
{
return String.Format("{0:x2}:{1:x2}:{2:x2}:{3:x2}:{4:x2}:{5:x2}", _bytes[5], _bytes[4], _bytes[3], _bytes[2], _bytes[1], _bytes[0]);
}

/// <summary>
/// Gets a hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
return _bytes[0] ^ (_bytes[1] << 8) ^ (_bytes[2] << 16) ^ (_bytes[3] << 24) ^ (_bytes[4] & 0xff) ^ (_bytes[5] << 8);
}

/// <summary>
/// Equals
/// </summary>
/// <param name="obj">Other object</param>
/// <returns>Result</returns>
public override bool Equals(object obj)
{
var bdaddrObj = obj as Bdaddr;
if ((object)bdaddrObj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return _bytes.SequenceEqual(((Bdaddr)obj)._bytes);
}

/// <summary>
/// Equality check
/// </summary>
/// <param name="a">First Bdaddr</param>
/// <param name="b">Second Bdaddr</param>
/// <returns>Result</returns>
public static bool operator ==(Bdaddr a, Bdaddr b)
{
if ((object)a == null)
{
return (object)b == null;
}
return a.Equals(b);
}

/// <summary>
/// Inequality check
/// </summary>
/// <param name="a">First Bdaddr</param>
/// <param name="b">Second Bdaddr</param>
/// <returns>Result</returns>
public static bool operator !=(Bdaddr a, Bdaddr b)
{
return !(a == b);
}
}
}
Loading

0 comments on commit 4ddb2ac

Please sign in to comment.