// if received "01", send logs via notification from HistoryData characteristic protected override bool WriteRequested(GattSession session, GattWriteRequest request) { byte[] receivedWrite; CryptographicBuffer.CopyToByteArray(request.Value, out receivedWrite); var receivedWriteHexString = Helpers.ToHexString(request.Value); QuickLockHistoryService parent = (QuickLockHistoryService)this.ParentService; if ((request.Value.Length != 1) || (receivedWrite[0] != 0x01)) { Debug.WriteLine($"Quicklock history cmd WriteRequested, but invalid format: {receivedWriteHexString} ({request.Value.Length})"); //do not update Value, return OnPropertyChanged(new PropertyChangedEventArgs("InvalidRequest")); return(true); } Debug.WriteLine($"Quicklock history cmd received, sending out logs"); // OnPropertyChanged(new PropertyChangedEventArgs("Logs")); // set the status characteristic and send notification parent.QuickLockHistoryData.SendLogs(); return(true); }
public async Task <bool> StartAdvertisingQuickLock() { isCurrentlyStarting = true; batteryService = new BLEServices.BatteryService(); //check if we can start service try { await batteryService.Init(); } catch // e.g. when Bluetooth adapter is off { Debug.WriteLine("Service start exception, probably Bluetooth adapter is off!"); return(false); } batteryService.IsConnectable = false; batteryService.IsDiscoverable = false; batteryService.Start(); currentTimeService = new BLEServices.CurrentTimeService(); await currentTimeService.Init(); currentTimeService.IsConnectable = false; currentTimeService.IsDiscoverable = false; currentTimeService.Start(); quickLockMainService = new BLEServices.QuickLockMainService(); await quickLockMainService.Init(); quickLockMainService.IsConnectable = true; // advertise in services list quickLockMainService.IsDiscoverable = true; quickLockMainService.Start(); quickLockHistoryService = new BLEServices.QuickLockHistoryService(); await quickLockHistoryService.Init(); quickLockHistoryService.IsConnectable = false; quickLockHistoryService.IsDiscoverable = false; quickLockHistoryService.Start(); // wait 0.5s for the service publishing callbacks to kick in await Task.Delay(500); // the service publishing callback can hit back with error a bit later // checking actual state if ((!batteryService.IsPublishing) || (!currentTimeService.IsPublishing) || (!quickLockMainService.IsPublishing) || (!quickLockHistoryService.IsPublishing)) { Debug.WriteLine("Service start exception, isPublishing = false (from service callback?), restart Bluetooth adapter?"); isCurrentlyStarting = false; return(false); } else { isCurrentlyStarting = false; return(true); } }
public bool StopAdvertisingServices() { if (heartRateService != null) { heartRateService.Stop(); heartRateService = null; } if (batteryService != null) { batteryService.Stop(); batteryService = null; } if (currentTimeService != null) { currentTimeService.Stop(); currentTimeService = null; } if (lightBulbService != null) { lightBulbService.Stop(); lightBulbService = null; } if (quickLockMainService != null) { quickLockMainService.Stop(); quickLockMainService = null; } if (quickLockHistoryService != null) { quickLockHistoryService.Stop(); quickLockHistoryService = null; } return(true); }