diff --git a/ProftaakRH/BLELibrary.dll b/ProftaakRH/BLELibrary.dll new file mode 100644 index 0000000..709a9a3 Binary files /dev/null and b/ProftaakRH/BLELibrary.dll differ diff --git a/ProftaakRH/FietsDemo.cs b/ProftaakRH/FietsDemo.cs new file mode 100644 index 0000000..8d08381 --- /dev/null +++ b/ProftaakRH/FietsDemo.cs @@ -0,0 +1,92 @@ +using Avans.TI.BLE; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace FietsDemo +{ + internal class Program + { + private static async Task Main(string[] args) + { + int errorCode = 0; + BLE bleBike = new BLE(); + BLE bleHeart = new BLE(); + Thread.Sleep(1000); // We need some time to list available devices + + // List available devices + List bleBikeList = bleBike.ListDevices(); + Console.WriteLine("Devices found: "); + foreach (var name in bleBikeList) + { + Console.WriteLine($"Device: {name}"); + } + + // Connecting + errorCode = errorCode = await bleBike.OpenDevice("Avans Bike B5F0"); + // __TODO__ Error check + + var services = bleBike.GetServices; + foreach (var service in services) + { + Console.WriteLine($"Service: {service}"); + } + + // Set service + errorCode = await bleBike.SetService("6e40fec1-b5a3-f393-e0a9-e50e24dcca9e"); + // __TODO__ error check + + // Subscribe + bleBike.SubscriptionValueChanged += BleBike_SubscriptionValueChanged; + errorCode = await bleBike.SubscribeToCharacteristic("6e40fec2-b5a3-f393-e0a9-e50e24dcca9e"); + + // Heart rate + errorCode = await bleHeart.OpenDevice("Avans Bike B5F0"); + + await bleHeart.SetService("HeartRate"); + + bleHeart.SubscriptionValueChanged += BleBike_SubscriptionValueChanged; + await bleHeart.SubscribeToCharacteristic("HeartRateMeasurement"); + + Console.Read(); + } + + private static void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e) + { + Console.WriteLine("Received from {0}: {1}, {2}", e.ServiceName, + BitConverter.ToString(e.Data).Replace("-", " "), + Encoding.UTF8.GetString(e.Data)); + + string[] bytes = BitConverter.ToString(e.Data).Split('-'); + string[] ANT = new string[5]; + if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e") + { + Console.WriteLine("SYNC : " + bytes[0]); + ANT[0] = bytes[0]; + Console.WriteLine("LENGTH : " + bytes[1]); + + int length = Convert.ToInt32(bytes[1], 16); + ANT[1] = length.ToString(); + Console.WriteLine("MSG ID : " + bytes[2]); + ANT[2] = bytes[2]; + string msg = string.Empty; + for (int i = 3; i < 3 + length; i++) + { + msg += bytes[i]; + } + ANT[3] = msg; + + Console.WriteLine("MSG : " + msg); + string checksum = bytes[3 + length]; + ANT[4] = checksum; + Console.WriteLine("CHECKSUM : " + checksum); + } else + { + Console.WriteLine("BPM: " + Convert.ToInt32(bytes[1], 16)); + } + Console.WriteLine(); + } + } +} \ No newline at end of file diff --git a/ProftaakRH.csproj b/ProftaakRH/ProftaakRH.csproj similarity index 57% rename from ProftaakRH.csproj rename to ProftaakRH/ProftaakRH.csproj index c73e0d1..06fdf06 100644 --- a/ProftaakRH.csproj +++ b/ProftaakRH/ProftaakRH.csproj @@ -4,5 +4,10 @@ Exe netcoreapp3.1 + + + .\BLELibrary.dll + + diff --git a/ProftaakRH.sln b/ProftaakRH/ProftaakRH.sln similarity index 65% rename from ProftaakRH.sln rename to ProftaakRH/ProftaakRH.sln index e28f334..a756a82 100644 --- a/ProftaakRH.sln +++ b/ProftaakRH/ProftaakRH.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +11,15 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Release|Any CPU.Build.0 = Release|Any CPU + {0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AD8FC239-049F-4332-A21F-76C30779630C} + SolutionGuid = {E8D4CDF6-747D-47AE-B655-159CEBA801D5} EndGlobalSection EndGlobal diff --git a/Program.cs b/ProftaakRH/Program.cs similarity index 100% rename from Program.cs rename to ProftaakRH/Program.cs