-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement a different strategy for pairing and unpairing devises us…
…ing a mac address. Device discovering phase before pairing is no longer needed. * Improve console interface * Require providing type of a bluetooth device for pairing and unpairing to avoid collisions when devices have the same name and mac address but different device types.
- Loading branch information
1 parent
a660064
commit d086e5c
Showing
29 changed files
with
616 additions
and
504 deletions.
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
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 |
---|---|---|
@@ -1,35 +1,35 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.32014.148 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BluetoothDevicePairing", "src\BluetoothDevicePairing.csproj", "{728939B3-82EA-4471-9CC7-3403EAD1E537}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{F4EA3749-BB28-4437-8AD6-137D5EBC09DD}" | ||
ProjectSection(SolutionItems) = preProject | ||
.editorconfig = .editorconfig | ||
.gitattributes = .gitattributes | ||
.gitignore = .gitignore | ||
.github\workflows\build.ps1 = .github\workflows\build.ps1 | ||
.github\workflows\continuous-integration-workflow.yaml = .github\workflows\continuous-integration-workflow.yaml | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Debug|x86.ActiveCfg = Debug|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Debug|x86.Build.0 = Debug|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Release|x86.ActiveCfg = Release|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {AFDC97AA-6AE6-428D-A38E-4A4D6335FC0C} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.32014.148 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BluetoothDevicePairing", "src\BluetoothDevicePairing.csproj", "{728939B3-82EA-4471-9CC7-3403EAD1E537}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{F4EA3749-BB28-4437-8AD6-137D5EBC09DD}" | ||
ProjectSection(SolutionItems) = preProject | ||
.editorconfig = .editorconfig | ||
.gitattributes = .gitattributes | ||
.gitignore = .gitignore | ||
.github\workflows\build.ps1 = .github\workflows\build.ps1 | ||
.github\workflows\continuous-integration-workflow.yaml = .github\workflows\continuous-integration-workflow.yaml | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Debug|x86.ActiveCfg = Debug|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Debug|x86.Build.0 = Debug|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Release|x86.ActiveCfg = Release|x86 | ||
{728939B3-82EA-4471-9CC7-3403EAD1E537}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {AFDC97AA-6AE6-428D-A38E-4A4D6335FC0C} | ||
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
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,31 @@ | ||
using System; | ||
|
||
namespace BluetoothDevicePairing.Bluetooth.Adapter | ||
{ | ||
internal sealed class Adapter | ||
{ | ||
private readonly Windows.Devices.Enumeration.DeviceInformation adapterInfo; | ||
private readonly Windows.Devices.Bluetooth.BluetoothAdapter adapterDevice; | ||
private readonly Windows.Devices.Radios.Radio radio; | ||
|
||
public Windows.Devices.Radios.RadioState State => radio.State; | ||
public string Name => adapterInfo.Name; | ||
public AdapterMacAddress MacAddress { get; } | ||
public bool IsDefault { get; } | ||
|
||
public Adapter(Windows.Devices.Enumeration.DeviceInformation bluetoothAdapterInfo, | ||
AdapterMacAddress defaultAdapterMacAddress) | ||
{ | ||
adapterInfo = bluetoothAdapterInfo; | ||
adapterDevice = Windows.Devices.Bluetooth.BluetoothAdapter.FromIdAsync(bluetoothAdapterInfo.Id).GetAwaiter().GetResult(); | ||
radio = adapterDevice.GetRadioAsync().GetAwaiter().GetResult(); | ||
MacAddress = new AdapterMacAddress(adapterDevice); | ||
IsDefault = MacAddress.Equals(defaultAdapterMacAddress); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"name:'{Name}' mac:'{MacAddress}' state:'{State}'"; | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace BluetoothDevicePairing.Bluetooth.Adapter | ||
{ | ||
internal static class AdapterFinder | ||
{ | ||
public static Adapter FindDefaultAdapter() | ||
{ | ||
return FindBluetoothAdapters().Where(adapter => adapter.IsDefault).Single(); | ||
} | ||
|
||
public static IEnumerable<Adapter> FindBluetoothAdapters() | ||
{ | ||
var macOfDefaultAdapter = GetMacAddressOfDefaultAdapter(); | ||
return Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Bluetooth.BluetoothAdapter.GetDeviceSelector()).GetAwaiter().GetResult() | ||
.Select(info => new Adapter(info, macOfDefaultAdapter)) | ||
.ToList(); | ||
} | ||
|
||
private static AdapterMacAddress GetMacAddressOfDefaultAdapter() | ||
{ | ||
var defaultAdapter = GetDefaultAdapter(); | ||
return new(defaultAdapter); | ||
} | ||
|
||
private static Windows.Devices.Bluetooth.BluetoothAdapter GetDefaultAdapter() | ||
{ | ||
return Windows.Devices.Bluetooth.BluetoothAdapter.GetDefaultAsync().GetAwaiter().GetResult(); | ||
} | ||
} | ||
} |
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,49 @@ | ||
using System; | ||
using System.Linq; | ||
using Windows.Devices.Bluetooth; | ||
|
||
namespace BluetoothDevicePairing.Bluetooth.Adapter | ||
{ | ||
internal sealed class AdapterMacAddress : IEquatable<AdapterMacAddress> | ||
{ | ||
public string Address { get; } | ||
|
||
public AdapterMacAddress(BluetoothAdapter adapter) | ||
{ | ||
Address = string.Join(":", BitConverter.GetBytes(adapter.BluetoothAddress) | ||
.Reverse() | ||
.Skip(2) | ||
.Select(b => b.ToString("x2"))); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Address; | ||
} | ||
|
||
public bool Equals(AdapterMacAddress other) | ||
{ | ||
if (other is null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, other)) | ||
{ | ||
return true; | ||
} | ||
|
||
return Address == other.Address; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return ReferenceEquals(this, obj) || obj is AdapterMacAddress other && Equals(other); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Address != null ? Address.GetHashCode() : 0; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.