diff --git a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs index 9ba9fdf1..3f6ef993 100644 --- a/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs +++ b/ShimmerBLE/PasskeyConfigurationApp/PasskeyConfigurationApp/MainPage.xaml.cs @@ -54,6 +54,7 @@ public async void ScanDevices() public void PasskeySettings_SelectedIndexChanged(object sender, EventArgs e) { + writePasskeyConfigurationButton.IsEnabled = true; switch (passkeySettings.SelectedIndex) { // no passkey @@ -76,6 +77,7 @@ public void PasskeySettings_SelectedIndexChanged(object sender, EventArgs e) break; // custom case 3: + writePasskeyConfigurationButton.IsEnabled = false; deviceAdvertisingNamePrefix.Text = ""; passkeyId.Text = ""; passkey.Text = ""; @@ -146,6 +148,14 @@ private void ShimmerDevice_BLEEvent(object sender, ShimmerBLEEventData e) { deviceState.Text = device.GetVerisenseBLEState().ToString(); }); + if(device.GetVerisenseBLEState() == ShimmerDeviceBluetoothState.Connected) + { + if (!device.MeetsMinimumFWRequirement(1,2,99)) // check if meets minimum requirement of 1.2.99 + { + DisconnectDevices(); + DisplayAlert("Error!", "Firmware below 1.02.99 is not supported\nYour device will now be disconnect", "OK"); + } + } } } @@ -222,7 +232,7 @@ public async void WritePasskeyConfigurationButton() break; // custom case 3: - break; + return; default: break; } } diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs index 3cd5bf14..3176204a 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs @@ -607,6 +607,19 @@ public async Task ExecuteRequest(params Object[] reqObjects) case RequestType.WriteProductionConfig: if (additionalBytesToWrite != null) { + if (additionalBytesToWrite.Length >= 55) + { + byte[] passkeyBytes = new byte[ProdConfig.PasskeyLength]; + Array.Copy(additionalBytesToWrite, (int)ProdConfigPayload.ConfigurationBytesIndexName.PASSKEY, passkeyBytes, 0, passkeyBytes.Length); + for (int i = 0; i < passkeyBytes.Length; i++) + { + if (passkeyBytes[i] != 0xFF && !int.TryParse(Encoding.UTF8.GetString(passkeyBytes, i, 1), out _)) + { + throw new Exception("Passkey Must Be Numeric Values"); + } + } + } + //needs a header request = new byte[additionalBytesToWrite.Length + 3]; Array.Copy(additionalBytesToWrite, 0, request, 3, additionalBytesToWrite.Length); diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs index 2e2d8e49..0d6ca83f 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseDevice.cs @@ -600,6 +600,30 @@ public DeviceByteArraySettings(string displayName, byte[] operationalConfigurati public string GetDescription() { return Description; } } + /// + /// Returns true if the input version is smaller or equal + /// + /// + /// + /// + /// + public bool MeetsMinimumFWRequirement(int compMajor, int compMinor, int compInternal) + { + if (ProdConfig != null) + { + if ((compMajor < ProdConfig.REV_FW_MAJOR) + || (ProdConfig.REV_FW_MAJOR == compMajor && compMinor < ProdConfig.REV_FW_MINOR) + || (ProdConfig.REV_FW_MAJOR == compMajor && ProdConfig.REV_FW_MINOR == compMinor && compInternal <= ProdConfig.REV_FW_INTERNAL)) + { + return true; // if the version is smaller or equal + } + } else + { + throw new Exception("Production Config Unknown"); + } + return false; // if less + } + public static DeviceByteSetting GetDeviceSettingFromConfigurationValue(DeviceByteSetting[] settings, int value) { foreach (DeviceByteSetting setting in settings) diff --git a/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs b/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs index 723f9a74..9d52ac28 100644 --- a/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs +++ b/ShimmerBLE/ShimmerBLEAPI/Models/ProdConfigPayload.cs @@ -31,9 +31,9 @@ public enum ConfigurationBytesIndexName ADVERTISING_NAME_PREFIX = 23 } - readonly int PasskeyIDLength = 2; - readonly int PasskeyLength = 6; - readonly int AdvertisingNameLength = 32; + public readonly int PasskeyIDLength = 2; + public readonly int PasskeyLength = 6; + public readonly int AdvertisingNameLength = 32; public ProdConfigPayload(string payload) { @@ -137,9 +137,12 @@ protected void SetPasskey(string passkey) } else if (passkey.Length == PasskeyLength) { - if (!int.TryParse(passkey, out _)) + for (int i = 0; i < PasskeyLength; i++) { - throw new Exception("Passkey Must Be Numeric Values"); + if (!int.TryParse(passkey[i].ToString(), out _)) + { + throw new Exception("Passkey Must Be Numeric Values"); + } } byte[] passkeyArray = Encoding.UTF8.GetBytes(passkey);