public void AddBLEDevice(BluetoothLEDevice device) { //var exist = this.items.FirstOrDefault(obj => obj.DeviceID == device.DeviceId); //if (exist != null) // this.items.Remove(exist); this.items.Clear(); var addedDevice = new DeviceInformationItem(device); this.items.Add(addedDevice); }
public void StartHeartRateMonitor(DeviceInformationItem heartRateDevice) { GattDeviceService hrService; GattDeviceService baService; if (heartRateDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.HEART_RATE, out hrService)) heartRateService.Start(hrService); if (heartRateDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.BATTERY, out baService)) batteryService.Start(baService); }
public async void StartServicesOnDevice(DeviceInformationItem chosenBLEDevice) { var linkLossServiceOnDevice = chosenBLEDevice.Device.GetGattService(GattServiceUuids.LinkLoss); var batteryServiceOnDevice = chosenBLEDevice.Device.GetGattService(GattServiceUuids.Battery); var ImmediateAlertServiceOnDevice = chosenBLEDevice.Device.GetGattService(GattServiceUuids.ImmediateAlert); await BatteryService.Start(batteryServiceOnDevice); await LinkLossService.Start(linkLossServiceOnDevice); LinkLossService.WriteAlertLevelCharacteristicAsync(AlertLevelEnum.HighAlert); await ImmediateAlertService.Start(ImmediateAlertServiceOnDevice); BatteryService.ValueChangeCompleted += BatteryService_ValueChangeCompleted; }
public void InitializeDevice(DeviceInformationItem chosenUartDevice) { if (this.chosenDevice == null || this.chosenDevice.DeviceID != chosenUartDevice.DeviceID) { this.chosenDevice = chosenUartDevice; GattDeviceService service = null; if (chosenDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.NORDIC_UART, out service)) { uartService.Start(service); uartService.EchoReceived += uartService_EchoReceived; IsReadyToTalk = true; } } else if (this.chosenDevice != null || uartService.IsServiceStarted) { IsReadyToTalk = true; } //give error message or success message }
public async Task<bool> StartDeviceFirmwareUpdate(DeviceInformationItem targetDevice) { GattDeviceService genericAttribute; GattDeviceService deviceFirmwareUpdate; targetDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.GENERIC_ATTRIBUTES, out genericAttribute); targetDevice.Services.TryGetValue(ToolboxIdentifications.GattServiceNames.DEVICE_FIRMWARE_UPDATE, out deviceFirmwareUpdate); if (genericAttribute != null && deviceFirmwareUpdate != null) { try { var type = DFUPackageHandler.GetFirmwareType(SelectedDeviceFirmwareTypeName); if (type.Equals(FirmwareTypeEnum.Softdevice_Bootloader)) { var imageFile = ChosenFiles.Find(x => x.Name == dfuSettingViewModel.manifestObject.manifest.softdevice_bootloader.bin_file); var dataFile = ChosenFiles.Find(x => x.Name == dfuSettingViewModel.manifestObject.manifest.softdevice_bootloader.dat_file); var sdSize = dfuSettingViewModel.manifestObject.manifest.softdevice_bootloader.sd_size; var blSize = dfuSettingViewModel.manifestObject.manifest.softdevice_bootloader.bl_size; await deviceFirmwareUpdateService.Start(deviceFirmwareUpdate, genericAttribute, type, dataFile, imageFile, sdSize, blSize); } else { var dat = ChosenFiles.Find(x => x.FileType == DeviceFirmwareUpdateSettingPageViewModel.DataFile_dat); var img = ChosenFiles.Find(x => x.FileType == DeviceFirmwareUpdateSettingPageViewModel.ImageFile_Bin); await deviceFirmwareUpdateService.Start(deviceFirmwareUpdate, genericAttribute, type, dat, img); } await deviceFirmwareUpdateService.EnableServiceChange(); await deviceFirmwareUpdateService.SwitchOnBootLoader(); } catch (Exception e) { this.exception = e; } if(this.exception != null) { await UpdateDFUStatus(DeviceFirmwareUpdateStatusEnum.DFU_ERROR, 0, this.exception.GetType().ToString(), this.exception.Message); return false; } else { RegisterTimer(); return true; } } else { await UpdateDFUStatus(DeviceFirmwareUpdateStatusEnum.SERVICES_NOT_AVAILABLE); return false; } }
public void StopUartService() { if(this.InvalidateDialog != null) uartService.EchoReceived -= uartService_EchoReceived; this.uartService.Stop(); this.chosenDevice = null; }