private static async Task SendResponseAsync(GattDeviceService service, RequestBase request, byte errorCode, ResponseBase response = null) { Debug.WriteLine($"Sending Wi-Fi config message protocol response: '{request.WifiRequestType}'"); byte[] responseMessage = MessageProtocolFactory.CreateResponseMessage(request.WifiRequestType, request.SequenceId, errorCode, response); await BluetoothLeHelper.WriteAsync(responseMessage, service, MessageProtocolRxCharacteristicId); }
private static async Task SendEventMessageAsync(GattDeviceService service, WifiEventId wifiEventType) { Debug.WriteLine($"Sending Wi-Fi config message protocol event: '{wifiEventType}'"); byte[] eventMessage = MessageProtocolFactory.CreateEventMessage(wifiEventType); await BluetoothLeHelper.WriteAsync(eventMessage, 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.WifiRequestType}'"); await bluetoothLeHelper.EndNotificationListenerAsync(); 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 WifiStatusRequest_NotificationReceived(object sender, NotifyEventArgs e) { if (MessageProtocolFactory.ReadRequestMessagePayload(e.Data) is WifiStatusRequest wifiStatusRequest) { Debug.WriteLine($"Received Wi-Fi config message protocol request: '{wifiStatusRequest.WifiRequestType}'"); await bluetoothLeHelper.EndNotificationListenerAsync(); bluetoothLeHelper.NotificationReceived -= WifiStatusRequest_NotificationReceived; await SendResponseAsync(currentService, wifiStatusRequest, 0x00); WifiStatusRequestReceived?.Invoke(this, new WifiStatusRequestEventArgs(wifiStatusRequest)); } }
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.WifiRequestType}'"); await bluetoothLeHelper.EndNotificationListenerAsync(); 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); } }