-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added C# client library + GUI sample
- Loading branch information
Showing
32 changed files
with
3,125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
clientlib/csharp/FliclibDotNetClient/FliclibDotNetClient.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
108
clientlib/csharp/FliclibDotNetClient/src/FliclibDotNetClient/Bdaddr.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.