private static async Task SendEventMessageAsync(GattDeviceService service, CategoryIdType categoryId, ushort eventType) { Debug.WriteLine($"Sending message protocol event: '{categoryId}, {eventType}'"); byte[] eventMessage = MessageProtocolFactory.CreateEventMessage(categoryId, eventType); await BluetoothLeHelper.WriteAsync(eventMessage, service, MessageProtocolRxCharacteristicId); }
private static async Task SendResponseAsync(GattDeviceService service, RequestBase request, byte errorCode, ResponseBase response = null) { Debug.WriteLine($"Sending message protocol response: '{request.CategoryId}, {request.RequestType}'"); byte[] responseMessage = MessageProtocolFactory.CreateResponseMessage(request.CategoryId, request.RequestType, request.SequenceId, errorCode, response); await BluetoothLeHelper.WriteAsync(responseMessage, service, MessageProtocolRxCharacteristicId); }
private async void WifiScanSummaryRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is WifiScanSummaryRequest wifiScanSummaryRequest) { Debug.WriteLine($"Received Wi-Fi config message protocol request: '{wifiScanSummaryRequest.RequestType}'"); bluetoothLeHelper.NotificationReceived -= WifiScanSummaryRequest_NotificationReceived; if (wifiScanSummaryRequest.ErrorCode != 0x00) { throw new InvalidOperationException($"Wi-Fi network scan failed with error code {wifiScanSummaryRequest.ErrorCode}"); } if (wifiScanSummaryRequest.NetworkCount == 0) { // Report that we're not getting anything. WifiNetworkScanReceived?.Invoke(this, new WifiScanRequestEventArgs(null, 0, 0)); } else { bluetoothLeHelper.NotificationReceived += WifiScanResultRequest_NotificationReceived; await bluetoothLeHelper.StartNotificationListenerAsync(currentService, MessageProtocolTxCharacteristicId); actualWifiNetworkCount = 0; expectedWifiNetworkCount = wifiScanSummaryRequest.NetworkCount; await SendResponseAsync(currentService, wifiScanSummaryRequest, wifiScanSummaryRequest.ErrorCode); } } }
private async void DeviceControlGetDesiredLedStatusRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is DeviceControlGetDesiredLedStatusRequest deviceControlGetDesiredLedStatusRequest) { Debug.WriteLine($"Received Device Control message protocol request: '{deviceControlGetDesiredLedStatusRequest.RequestType}'"); bluetoothLeHelper.NotificationReceived -= DeviceControlGetDesiredLedStatusRequest_NotificationReceived; // Send the get desired LED status response. await SendResponseAsync(currentService, deviceControlGetDesiredLedStatusRequest, 0x00, deviceControlGetDesiredLedStatusResponse); } }
private async void WifiStatusRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is WifiStatusRequest wifiStatusRequest) { Debug.WriteLine($"Received Wi-Fi config message protocol request: '{wifiStatusRequest.RequestType}'"); bluetoothLeHelper.NotificationReceived -= WifiStatusRequest_NotificationReceived; await SendResponseAsync(currentService, wifiStatusRequest, 0x00); WifiStatusRequestReceived?.Invoke(this, new WifiStatusRequestEventArgs(wifiStatusRequest)); } }
private async void DeviceControlReportLedStatusRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is DeviceControlReportLedStatusRequest deviceControlReportLedStatusRequest) { Debug.WriteLine($"Received Device Control message protocol request: '{deviceControlReportLedStatusRequest.RequestType}'"); // Need to listen to DeviceControlUpdateLedStatusRequest all the time. // Send the report LED status response. await SendResponseAsync(currentService, deviceControlReportLedStatusRequest, 0x00); // Need to call back to DevicePage.xaml.cs to update Toggle Switch's value & enabled. ReportLedStatusRequestReceived?.Invoke(this, new DeviceControlLedStatusNeededEventArgs(deviceControlReportLedStatusRequest)); } }
private async void WifiGetNewDetailsRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is WifiGetNewDetailsRequest wifiGetNewDetailsRequest) { Debug.WriteLine($"Received Wi-Fi config message protocol request: '{wifiGetNewDetailsRequest.RequestType}'"); bluetoothLeHelper.NotificationReceived -= WifiGetNewDetailsRequest_NotificationReceived; // Setup success status check with device bluetoothLeHelper.NotificationReceived += WifiSetRequest_NotificationReceived; await bluetoothLeHelper.StartNotificationListenerAsync(currentService, MessageProtocolTxCharacteristicId); // Send the add network request. await SendResponseAsync(currentService, wifiGetNewDetailsRequest, 0x00, wifiGetNewDetailsResponse); } }