From a8a9afb0de2a084dd90f5ba566f8f8e589672d6d Mon Sep 17 00:00:00 2001 From: Mas Azalya Yusof Date: Tue, 4 Jan 2022 12:50:25 +0800 Subject: [PATCH 1/4] handle sensor not or just paired --- .../Communications/IVerisenseBLE.cs | 3 ++- .../Devices/VerisenseBLEDevice.cs | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs index ea30af59..f081e698 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs @@ -43,6 +43,7 @@ public enum ShimmerDeviceBluetoothState Connected, Streaming, StreamingLoggedData, - Limited + Limited, + NotPairedAndDisconnected } } diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs index 06046f65..f078a63b 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs @@ -34,6 +34,7 @@ public class VerisenseBLEDevice : VerisenseDevice, IDisposable, IVerisenseBLE int TimerCount; int TaskCount; int MaximumNumberOfBytesPerBinFile = 100000000; // 100MB limit + int iOSConnectCount; public int GallCallBackErrorCount = 0; protected const string LogObject = "VerisenseBLEDevice"; @@ -1671,6 +1672,29 @@ public async Task Connect(bool initialize, DeviceByteArraySettings configu } else { + if (Device.RuntimePlatform == Device.iOS) + { + //test sensor connection state for pairing cancelled/failed or sensor just paired + var sresult = await ExecuteRequest(RequestType.ReadStatus); + if (sresult == null) + { + if (iOSConnectCount > 0) + { + iOSConnectCount = 0; + await Disconnect(); + StateChange(ShimmerDeviceBluetoothState.NotPairedAndDisconnected); + return false; + } + else + { + await Disconnect(); + iOSConnectCount++; + await Connect(true); + return true; + } + + } + } if (initialize) { var sresult = await ExecuteRequest(RequestType.ReadStatus); From 97c4ab304c2fd7a6e05f13ee3c73cd0dff6b56d2 Mon Sep 17 00:00:00 2001 From: Mas Azalya Yusof Date: Thu, 6 Jan 2022 15:30:58 +0800 Subject: [PATCH 2/4] more updates --- .../Communications/VerisenseBLEManager.cs | 13 +++++++--- .../Devices/VerisenseBLEDevice.cs | 25 +------------------ .../Devices/VerisenseBLEDeviceIOS.cs | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/ShimmerBLE/ShimmerBLEAPI.iOS/Communications/VerisenseBLEManager.cs b/ShimmerBLE/ShimmerBLEAPI.iOS/Communications/VerisenseBLEManager.cs index 56dff6d4..f6fba69f 100644 --- a/ShimmerBLE/ShimmerBLEAPI.iOS/Communications/VerisenseBLEManager.cs +++ b/ShimmerBLE/ShimmerBLEAPI.iOS/Communications/VerisenseBLEManager.cs @@ -2,6 +2,7 @@ using Plugin.BLE.Abstractions.Contracts; using shimmer.Communications; using ShimmerBLEAPI.Communications; +using ShimmerBLEAPI.Devices; using ShimmerBLEAPI.iOS.Communications; using ShimmerBLEAPI.Models; using System; @@ -34,7 +35,7 @@ private void BLEManager_BLEEvent(object sender, BLEManagerEvent e) } else if (e.CurrentEvent == shimmer.Communications.BLEManagerEvent.BLEAdapterEvent.DevicePaired) { - Console.WriteLine(((VerisenseBLEScannedDevice)e.objMsg).Uuid.ToString() + " is paired."); + Console.WriteLine(((VerisenseBLEDeviceIOS)e.objMsg).Asm_uuid.ToString() + " is paired."); } } public List GetListOfScannedDevices() @@ -102,9 +103,15 @@ public static bool GetBondingStatus(string id) return isBonded; } - public Task PairVerisenseDevice(object Device, IBLEPairingKeyGenerator generator) + public async Task PairVerisenseDevice(object Device, IBLEPairingKeyGenerator generator) { - throw new NotImplementedException(); + var pairingResult = await ((VerisenseBLEDeviceIOS)Device).PairDeviceAsync(); + if (pairingResult) + { + if (BLEManagerEvent != null) + BLEManagerEvent.Invoke(null, new BLEManagerEvent { CurrentEvent = shimmer.Communications.BLEManagerEvent.BLEAdapterEvent.DevicePaired, objMsg = (VerisenseBLEDeviceIOS)Device, message = "Device Is Successfully Paired" }); + } + return pairingResult; } public void StopScanForDevices() diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs index 3b43d73e..0781cdbf 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs @@ -1672,29 +1672,6 @@ public async Task Connect(bool initialize, DeviceByteArraySettings configu } else { - if (Device.RuntimePlatform == Device.iOS) - { - //test sensor connection state for pairing cancelled/failed or sensor just paired - var sresult = await ExecuteRequest(RequestType.ReadStatus); - if (sresult == null) - { - if (iOSConnectCount > 0) - { - iOSConnectCount = 0; - await Disconnect(); - StateChange(ShimmerDeviceBluetoothState.NotPairedAndDisconnected); - return false; - } - else - { - await Disconnect(); - iOSConnectCount++; - await Connect(true); - return true; - } - - } - } if (initialize) { var sresult = await ExecuteRequest(RequestType.ReadStatus); @@ -1710,7 +1687,7 @@ public async Task Connect(bool initialize, DeviceByteArraySettings configu } opConfig = UpdateDefaultDeviceConfigBytes(deviceOpConfig, configuration.GetOperationalConfigurationBytes()); } - + var wopcresult = await ExecuteRequest(RequestType.WriteOperationalConfig, opConfig); if (wopcresult == null) { diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDeviceIOS.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDeviceIOS.cs index 4c9e881b..66c56587 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDeviceIOS.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDeviceIOS.cs @@ -19,7 +19,7 @@ public VerisenseBLEDeviceIOS(string id, string name) : base(id, name) public async Task PairDeviceAsync() { var result = await Connect(false); - + /* InitializeRadio(); BLERadio.Asm_uuid = Asm_uuid; From 507afafc3c7132318604a9a08acb200489b90f8b Mon Sep 17 00:00:00 2001 From: Mas Azalya Yusof Date: Thu, 6 Jan 2022 15:40:46 +0800 Subject: [PATCH 3/4] remove unused update --- ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs index f081e698..ea30af59 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseBLE.cs @@ -43,7 +43,6 @@ public enum ShimmerDeviceBluetoothState Connected, Streaming, StreamingLoggedData, - Limited, - NotPairedAndDisconnected + Limited } } From 1e32a9bb0e81ed0e457e28687790d1bb8330e397 Mon Sep 17 00:00:00 2001 From: Jong Chern Date: Thu, 13 Jan 2022 12:09:06 +0800 Subject: [PATCH 4/4] remove unused variable --- ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs index 0781cdbf..43e6c6cd 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs @@ -34,7 +34,6 @@ public class VerisenseBLEDevice : VerisenseDevice, IDisposable, IVerisenseBLE int TimerCount; int TaskCount; int MaximumNumberOfBytesPerBinFile = 100000000; // 100MB limit - int iOSConnectCount; public int GallCallBackErrorCount = 0; protected const string LogObject = "VerisenseBLEDevice";