13 #include <winrt/base.h> 14 #include <winrt/windows.devices.bluetooth.h> 15 #include <winrt/windows.devices.bluetooth.genericattributeprofile.h> 16 #include <winrt/windows.devices.enumeration.h> 17 #include <winrt/windows.foundation.h> 18 #include <winrt/windows.foundation.collections.h> 19 #include <winrt/windows.storage.h> 20 #include <winrt/windows.storage.streams.h> 23 using namespace winrt;
24 using namespace Windows::Devices::Bluetooth;
25 using namespace Windows::Devices::Bluetooth::GenericAttributeProfile;
26 using namespace Windows::Devices::Enumeration;
27 using namespace Windows::Foundation;
28 using namespace Windows::Foundation::Collections;
29 using namespace Windows::Storage;
30 using namespace Windows::Storage::Streams;
43 #pragma comment(lib, "windowsapp") 47 { 0x8c853b6a, 0x2297, 0x44c1, { 0x82, 0x77, 0x73, 0x62, 0x7c, 0x8d, 0x2a, 0xbc } };
51 { 0x8c853b6a, 0x2297, 0x44c1, { 0x82, 0x77, 0x73, 0x62, 0x7c, 0x8d, 0x2a, 0xbd } };
55 { 0x8c853b6a, 0x2297, 0x44c1, { 0x82, 0x77, 0x73, 0x62, 0x7c, 0x8d, 0x2a, 0xbe } };
59 { 0xf9eb3fae, 0x947a, 0x4e5b, { 0xab, 0x7c, 0xc7, 0x99, 0xe9, 0x1e, 0xd7, 0x80 } };
63 { 0xf9eb3fae, 0x947a, 0x4e5b, { 0xab, 0x7c, 0xc7, 0x99, 0xe9, 0x1e, 0xd7, 0x81 } };
67 { 0xf9eb3fae, 0x947a, 0x4e5b, { 0xab, 0x7c, 0xc7, 0x99, 0xe9, 0x1e, 0xd7, 0x82 } };
83 template <
typename TAsyncOp>
86 std::promise<void> wait_prom;
87 std::future<void> wait_future = wait_prom.get_future();
89 auto busy_wait = [&](TAsyncOp op)
91 while (op.Status() == AsyncStatus::Started);
94 wait_prom.set_value();
99 std::future_status status = wait_future.wait_for(std::chrono::seconds(
BLE_OP_TIMEOUT_SEC));
102 case std::future_status::ready:
104 case std::future_status::timeout:
105 LOG_ERROR(
"Awaiting asynchronous operation timed out");
107 case std::future_status::deferred:
108 LOG_ERROR(
"Awaiting asynchronous operation deferred");
111 LOG_ERROR(
"Unexpected error occurred while awaiting completion of C++/WinRT asynchronous operation");
118 case AsyncStatus::Completed:
120 case AsyncStatus::Canceled:
121 LOG_ERROR(
"Awaiting asynchronous operation which terminated with status AsyncStatus::Canceled");
123 case AsyncStatus::Started:
124 LOG_ERROR(
"Awaiting asynchronous operation which timed out with status AsyncStatus::Started");
126 case AsyncStatus::Error:
127 LOG_ERROR(
"Error occurred while awaiting asynchronous operation. Error code was: " << op.ErrorCode());
130 LOG_ERROR(
"Unexpected error occurred causing timeout while awaiting completion of C++/WinRT asynchronous operation");
141 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
142 return converter.from_bytes(str);
148 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
149 return converter.to_bytes(wstr);
155 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
156 return converter.to_bytes(hstr.c_str());
163 std::stringstream str;
164 str << std::uppercase << std::hex;
165 str << std::setw(8) << std::setfill(
'0') << uuid.Data1 <<
"-";
166 str << std::setw(4) << std::setfill(
'0') << uuid.Data2 <<
"-";
167 str << std::setw(4) << std::setfill(
'0') << uuid.Data3 <<
"-";
168 str << std::setw(2) << std::setfill('0') << static_cast<short>(uuid.Data4[0])
169 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[1])
171 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[2])
172 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[3])
173 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[4])
174 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[5])
175 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[6])
176 << std::setw(2) << std::setfill(
'0') << static_cast<short>(uuid.Data4[7]);
177 str << std::nouppercase;
184 class ClariusBLEPrivate
190 virtual ~ClariusBLEPrivate() =
default;
193 void DeviceAdded(DeviceWatcher sender, DeviceInformation deviceInfo);
199 void DeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate devInfoUpdate);
202 void PowerStateChanged(GattCharacteristic sender, GattValueChangedEventArgs args);
205 void WifiStateChanged(GattCharacteristic sender, GattValueChangedEventArgs args);
221 std::string GattCommunicationStatusToString(GattCommunicationStatus status);
224 void ProcessWifiInfo(std::string info);
232 std::wstring ProbeId;
235 std::vector<std::string> FoundProbeIds;
238 std::string LastError;
241 DeviceInformation DeviceInfo{
nullptr };
242 std::promise<void> DeviceInfoPromise;
243 BluetoothLEDevice Device{
nullptr };
246 GattDeviceService PowerService{
nullptr };
247 GattDeviceService WifiService{
nullptr };
250 GattCharacteristic PowerPublishedChar{
nullptr };
251 GattCharacteristic PowerRequestChar{
nullptr };
252 GattCharacteristic WifiPublishedChar{
nullptr };
253 GattCharacteristic WifiRequestChar{
nullptr };
256 std::atomic<bool> PowerState;
259 std::promise<void> WifiInfoPromise;
260 std::atomic<bool> WifiInfoSet;
265 PlusStatus RetrieveService(
const guid& serviceUuid, GattDeviceService& service);
269 const GattDeviceService& service,
271 GattCharacteristic& characteristic
275 std::vector<std::string> TokenizeString(std::string str,
const char delimiter);
278 std::mutex WifiInfoMutex;
285 ClariusBLEPrivate::ClariusBLEPrivate(
ClariusBLE* ext)
293 void ClariusBLEPrivate::DeviceAdded(
294 DeviceWatcher sender,
295 DeviceInformation info)
299 std::wstring name{ info.Name().c_str() };
300 if (name == this->ProbeId)
302 this->DeviceInfo = info;
303 this->DeviceInfoPromise.set_value();
305 else if (name.find(L
"CUS") != std::wstring::npos)
312 void ClariusBLEPrivate::DeviceUpdated(
313 winrt::Windows::Devices::Enumeration::DeviceWatcher sender,
314 winrt::Windows::Devices::Enumeration::DeviceInformationUpdate devInfoUpdate)
321 void ClariusBLEPrivate::PowerStateChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
323 DataReader reader = DataReader::FromBuffer(args.CharacteristicValue());
324 uint8_t powered = reader.ReadByte();
325 this->PowerState = bool(powered);
329 void ClariusBLEPrivate::WifiStateChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
331 DataReader reader = DataReader::FromBuffer(args.CharacteristicValue());
332 winrt::hstring wifiHString = reader.ReadString(reader.UnconsumedBufferLength());
334 this->ProcessWifiInfo(wifiStr);
337 this->WifiInfoPromise.set_value();
341 PlusStatus ClariusBLEPrivate::SetupPowerService()
343 LOG_DEBUG(
"Setting up Clarius power service");
363 if (!this->PowerPublishedChar)
365 this->LastError =
"Could not find PowerPublished characteristic";
369 if (!this->PowerRequestChar)
371 this->LastError =
"Could not find PowerRequest characteristic";
376 this->PowerPublishedChar.WriteClientCharacteristicConfigurationDescriptorAsync(
377 GattClientCharacteristicConfigurationDescriptorValue::Notify);
378 this->PowerPublishedChar.ValueChanged({
this, &ClariusBLEPrivate::PowerStateChanged });
384 PlusStatus ClariusBLEPrivate::SetupWifiService()
386 LOG_DEBUG(
"Setting up Clarius wifi service");
406 if (!this->WifiPublishedChar)
408 this->LastError =
"Could not find WifiPublished characteristic";
412 if (!this->WifiRequestChar)
414 this->LastError =
"Could not find WifiRequest characteristic";
420 this->WifiPublishedChar.WriteClientCharacteristicConfigurationDescriptorAsync(
421 GattClientCharacteristicConfigurationDescriptorValue::Notify);
422 this->WifiPublishedChar.ValueChanged({
this, &ClariusBLEPrivate::WifiStateChanged });
428 PlusStatus ClariusBLEPrivate::InitializeState()
430 LOG_DEBUG(
"Initializing Clarius BLE state");
433 IAsyncOperation<GattReadResult> powerOp =
434 this->PowerPublishedChar.ReadValueAsync(BluetoothCacheMode::Uncached);
437 this->LastError =
"Failed to async read power state from BLE device";
441 GattReadResult powerResult = powerOp.GetResults();
442 if (powerResult.Status() != GattCommunicationStatus::Success)
444 std::stringstream msg;
445 msg <<
"Failed to initialize power state in InitializeState with non-successful " 446 "GATT communication. Status was: " 447 << this->GattCommunicationStatusToString(powerResult.Status());
448 this->LastError = msg.str();
452 DataReader powerReader = DataReader::FromBuffer(powerResult.Value());
453 this->PowerState = bool(powerReader.ReadByte());
455 if (!this->PowerState)
463 IAsyncOperation<GattReadResult> wifiOp =
464 this->WifiPublishedChar.ReadValueAsync(BluetoothCacheMode::Uncached);
467 this->LastError =
"Failed to async read wifi state from BLE device";
471 GattReadResult wifiResult = wifiOp.GetResults();
472 if (wifiResult.Status() != GattCommunicationStatus::Success)
474 std::stringstream msg;
475 msg <<
"Failed to initialize wifi state in InitializeState with non-successful " 476 "GATT communication. Status was: " << this->GattCommunicationStatusToString(wifiResult.Status());
477 this->LastError = msg.str();
481 DataReader wifiReader = DataReader::FromBuffer(wifiResult.Value());
482 winrt::hstring wifiHString = wifiReader.ReadString(wifiReader.UnconsumedBufferLength());
484 this->ProcessWifiInfo(wifiStr);
492 std::unique_lock<std::mutex> wifiInfoLock(this->WifiInfoMutex);
493 return this->WifiInfo;
497 std::string ClariusBLEPrivate::GattCommunicationStatusToString(GattCommunicationStatus status)
501 case GattCommunicationStatus::AccessDenied:
502 return "AccessDenied";
503 case GattCommunicationStatus::ProtocolError:
504 return "ProtocolError";
505 case GattCommunicationStatus::Success:
507 case GattCommunicationStatus::Unreachable:
508 return "Unreachable";
510 return "Unknown GattCommunicationStatus";
515 PlusStatus ClariusBLEPrivate::RetrieveService(
const guid& serviceUuid, GattDeviceService& service)
517 IAsyncOperation<GattDeviceServicesResult> getServicesOp =
518 this->Device.GetGattServicesForUuidAsync(serviceUuid, BluetoothCacheMode::Uncached);
521 this->LastError =
"ClariusBLEPrivate::RetrieveService async operation failed";
525 GattDeviceServicesResult servicesResult = getServicesOp.GetResults();
528 if (servicesResult.Status() != GattCommunicationStatus::Success)
530 std::stringstream msg;
531 msg <<
"ClariusBLEPrivate::RetrieveService failed for UUID " <<
uuid_to_string(serviceUuid)
532 <<
" with non-successful GATT communication. Status was: " 533 << this->GattCommunicationStatusToString(servicesResult.Status());
534 this->LastError = msg.str();
539 if (!servicesResult.Services().Size())
541 std::stringstream msg;
542 msg <<
"ClariusBLEPrivate::RetrieveService failed for UUID " <<
uuid_to_string(serviceUuid)
543 <<
". No services with this UUID were found.";
544 this->LastError = msg.str();
548 service = *servicesResult.Services().First();
551 std::stringstream msg;
552 msg <<
"ClariusBLEPrivate::RetrieveService could not find service " <<
uuid_to_string(serviceUuid);
553 this->LastError = msg.str();
560 PlusStatus ClariusBLEPrivate::RetrieveCharacteristic(
561 const GattDeviceService& service,
563 GattCharacteristic& characteristic)
565 IAsyncOperation<GattCharacteristicsResult> getCharsOp =
566 service.GetCharacteristicsForUuidAsync(charUuid, BluetoothCacheMode::Uncached);
569 std::stringstream msg;
570 msg <<
"ClariusBLEPrivate::RetrieveCharacteristic async operation failed for UUID";
572 this->LastError = msg.str();
577 GattCharacteristicsResult charsResult = getCharsOp.GetResults();
578 if (charsResult.Status() != GattCommunicationStatus::Success)
580 std::stringstream msg;
581 msg <<
"ClariusBLEPrivate::RetrieveCharacteristic failed for UUID " <<
uuid_to_string(charUuid)
582 <<
" with non-successful GATT communication. Status was: " 583 << this->GattCommunicationStatusToString(charsResult.Status());
584 this->LastError = msg.str();
589 if (!charsResult.Characteristics().Size())
591 std::stringstream msg;
592 msg <<
"ClariusBLEPrivate::RetrieveCharacteristic failed for UUID " <<
uuid_to_string(charUuid)
593 <<
". No characteristics with this UUID were found.";
594 this->LastError = msg.str();
598 characteristic = *charsResult.Characteristics().First();
603 void ClariusBLEPrivate::ProcessWifiInfo(std::string info)
605 std::unique_lock<std::mutex> wifiInfoLock(this->WifiInfoMutex);
606 std::vector<std::string> infoList = this->TokenizeString(info,
'\n');
607 if (infoList.size() == 1)
610 if (infoList.at(0).find(
"state") == std::string::npos)
612 throw std::runtime_error(
"Format of ClariusWifiInfo string has changed. Please report " 613 "this info the the PLUS developers");
617 newInfo.
Ready =
false;
618 this->WifiInfo = newInfo;
621 else if (infoList.size() != 10)
623 throw std::runtime_error(
"Format of ClariusWifiInfo string has changed. Please report " 624 "this info the the PLUS developers");
630 std::string stateStr = infoList.at(0);
631 newInfo.
Ready = (stateStr.find(
"connected") != std::string::npos);
634 std::string availStr = infoList.at(7);
635 std::string availTag =
"avail: ";
636 availStr = availStr.replace(0, availTag.length(),
"");
637 if (availStr ==
"available")
641 else if (availStr ==
"listen")
651 std::string apStr = infoList.at(1);
652 if (apStr.find(
"true") != std::string::npos)
662 std::string ssidStr = infoList.at(2);
663 std::string ssidTag =
"ssid: ";
664 newInfo.
SSID = ssidStr.replace(0, ssidTag.length(),
"");
667 std::string pwStr = infoList.at(3);
668 std::string pwTag =
"pw: ";
669 newInfo.
Password = pwStr.replace(0, pwTag.length(),
"");
672 std::string ipv4Str = infoList.at(4);
673 std::string ipv4Tag =
"ip4: ";
674 newInfo.
IPv4 = ipv4Str.replace(0, ipv4Tag.length(),
"");
677 std::string macStr = infoList.at(9);
678 std::string macTag =
"mac: ";
679 newInfo.
MacAddress = macStr.replace(0, macTag.length(),
"");
682 std::string ctlStr = infoList.at(5);
683 std::string ctlTag =
"ctl: ";
684 std::string ctlStrInt = ctlStr.replace(0, ctlTag.length(),
"");
688 std::string castStr = infoList.at(6);
689 std::string castTag =
"cast: ";
690 std::string castStrInt = castStr.replace(0, castTag.length(),
"");
691 newInfo.
CastPort = std::stoi(castStrInt);
694 std::string channelStr = infoList.at(8);
695 std::string channelTag =
"channel: ";
696 std::string channelStrInt = channelStr.replace(0, channelTag.length(),
"");
697 newInfo.
Channel = std::stoi(channelStrInt);
700 this->WifiInfo = newInfo;
701 this->WifiInfoSet =
true;
705 std::vector<std::string> ClariusBLEPrivate::TokenizeString(std::string str,
const char delimiter)
707 std::stringstream ss(str);
708 std::vector<std::string> tokens;
711 while (getline(ss, tmp, delimiter))
713 tokens.push_back(tmp);
723 : _impl(std::make_unique<ClariusBLEPrivate>(this))
737 std::string fullBleName =
"CUS-" + serialNum;
740 DeviceWatcher deviceWatcher{
nullptr };
741 winrt::hstring aqsFilter{ BluetoothLEDevice::GetDeviceSelectorFromPairingState(
true) };
742 deviceWatcher = DeviceInformation::CreateWatcher(
745 DeviceInformationKind::AssociationEndpoint
747 deviceWatcher.Added({ _impl.get(), &ClariusBLEPrivate::DeviceAdded });
748 deviceWatcher.Updated({ _impl.get(), &ClariusBLEPrivate::DeviceUpdated });
750 std::future<void> deviceInfoFuture = _impl->DeviceInfoPromise.get_future();
751 deviceWatcher.Start();
753 if (deviceInfoFuture.wait_for(std::chrono::milliseconds(1000)) == std::future_status::ready)
755 deviceWatcher.Stop();
759 deviceWatcher.Stop();
766 return _impl->FoundProbeIds;
772 return (_impl->Device && _impl->Device.ConnectionStatus() == BluetoothConnectionStatus::Connected);
778 if (!_impl->DeviceInfo)
780 _impl->LastError =
"Attempted to call ClariusBLE::Connect with unset m_deviceInfo, " 781 "ensure ClariusBLE::FindBySerial is called successfully before calling Connect";
784 if (_impl->Device && _impl->Device.ConnectionStatus() == BluetoothConnectionStatus::Connected)
786 _impl->LastError =
"Connect called but probe is already connected";
793 int connectionAttemptCount = 0;
794 int retryDelayMs = 1000;
797 if (connectionAttemptCount > 0)
799 LOG_DEBUG(
"Attempt #" << connectionAttemptCount <<
" failed. Last error: \"" << this->
GetLastError() <<
"\"");
801 std::this_thread::sleep_for(std::chrono::milliseconds(retryDelayMs));
804 ++connectionAttemptCount;
805 LOG_DEBUG(
"Trying to connect: Attempt #" << connectionAttemptCount);
807 IAsyncOperation<BluetoothLEDevice> deviceOp = BluetoothLEDevice::FromIdAsync(_impl->DeviceInfo.Id());
810 _impl->LastError =
"Failed to connect to device, async operation to get device failed";
813 _impl->Device = deviceOp.GetResults();
814 if (_impl->Device ==
nullptr)
816 _impl->LastError =
"Failed to connect to device, unable to find device";
837 LOG_DEBUG(
"Device connected: Attempt #" << connectionAttemptCount);
846 if (_impl->PowerService)
848 _impl->PowerService.Close();
850 if (_impl->WifiService)
852 _impl->WifiService.Close();
856 _impl->Device.Close();
859 _impl->PowerPublishedChar =
nullptr;
860 _impl->PowerRequestChar =
nullptr;
861 _impl->WifiPublishedChar =
nullptr;
862 _impl->WifiRequestChar =
nullptr;
864 _impl->PowerService =
nullptr;
865 _impl->WifiService =
nullptr;
867 _impl->Device =
nullptr;
883 _impl->DeviceInfo =
nullptr;
891 return _impl->PowerState;
899 _impl->LastError =
"RequestProbeOn called but no probe is connected";
904 writer.WriteByte(0x01);
905 IBuffer buf = writer.DetachBuffer();
907 IAsyncOperation<GattWriteResult> writeOp =
908 _impl->PowerRequestChar.WriteValueWithResultAsync(buf, GattWriteOption::WriteWithResponse);
911 _impl->LastError =
"RequestProbeOn Failed to async write to PowerRequestChar";
915 GattWriteResult writeResult = writeOp.GetResults();
916 if (writeResult.Status() != GattCommunicationStatus::Success)
918 std::stringstream msg;
919 msg <<
"ClariusBLE::ProbeOn failed with non-successful GATT communication. Status was: " 920 << _impl->GattCommunicationStatusToString(writeResult.Status());
921 _impl->LastError = msg.str();
933 _impl->LastError =
"RequestProbeOff called but no probe is connected";
938 writer.WriteByte(0x00);
939 IBuffer buf = writer.DetachBuffer();
941 if (_impl->PowerRequestChar)
943 IAsyncOperation<GattWriteResult> writeOp =
944 _impl->PowerRequestChar.WriteValueWithResultAsync(buf, GattWriteOption::WriteWithResponse);
947 _impl->LastError =
"RequestProbeOff Failed to async write to PowerRequestChar";
951 GattWriteResult writeResult = writeOp.GetResults();
953 if (writeResult.Status() != GattCommunicationStatus::Success)
955 std::stringstream msg;
956 msg <<
"ClariusBLE::ProbeOff failed with non-successful GATT communication. Status was: " 957 << _impl->GattCommunicationStatusToString(writeResult.Status());
958 _impl->LastError = msg.str();
964 LOG_ERROR(
"Unable to send probe off signal. Power request characteristic not availiable.");
974 if (_impl->WifiInfoSet)
983 if (_impl->WifiInfoSet)
989 std::future<void> wifiInfoFuture = _impl->WifiInfoPromise.get_future();
991 std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();
992 std::chrono::duration<double> duration;
998 if (_impl->WifiInfoSet || wifiInfoFuture.wait_for(std::chrono::seconds(
POWER_ON_POLL_INTERVAL_SEC)) == std::future_status::ready)
1000 duration = std::chrono::steady_clock::now() - start_time;
1001 LOG_DEBUG(
"WiFi info set: " << duration.count() <<
"s");
1005 duration = std::chrono::steady_clock::now() - start_time;
1007 LOG_DEBUG(
"Waiting for WiFi info: " << duration.count() <<
"s");
1010 std::stringstream msg;
1012 <<
" to boot up and provide Wifi info, please try again" << std::endl;
1013 _impl->LastError = msg.str();
1020 IAsyncOperation<GattReadResult> wifiOp =
1021 _impl->WifiPublishedChar.ReadValueAsync(BluetoothCacheMode::Uncached);
1024 GattReadResult wifiResult = wifiOp.GetResults();
1025 if (wifiResult.Status() != GattCommunicationStatus::Success)
1027 std::stringstream msg;
1028 msg <<
"ClariusBLE::ReadWifiInfo failed with non-successful GATT communication. Status was: " 1029 << _impl->GattCommunicationStatusToString(wifiResult.Status());
1030 _impl->LastError = msg.str();
1034 DataReader wifiReader = DataReader::FromBuffer(wifiResult.Value());
1035 winrt::hstring wifiHString = wifiReader.ReadString(wifiReader.UnconsumedBufferLength());
1037 _impl->ProcessWifiInfo(wifiStr);
1049 _impl->LastError =
"ConfigureWifiAP called but no probe is connected";
1053 std::stringstream ss;
1055 ss <<
"channel: auto\n";
1059 IBuffer buf = writer.DetachBuffer();
1061 IAsyncOperation<GattWriteResult> writeOp =
1062 _impl->WifiRequestChar.WriteValueWithResultAsync(buf, GattWriteOption::WriteWithResponse);
1065 _impl->LastError =
"ConfigureWifiAP Failed to write to WifiRequestChar";
1069 GattWriteResult writeResult = writeOp.GetResults();
1070 if (writeResult.Status() != GattCommunicationStatus::Success)
1072 std::stringstream msg;
1073 msg <<
"ClariusBLE::ConfigureWifiAP failed with non-successful GATT communication. Status was: " 1074 << _impl->GattCommunicationStatusToString(writeResult.Status());
1075 _impl->LastError = msg.str();
1087 _impl->LastError =
"ConfigureWifiLAN called but no probe is connected";
1093 _impl->LastError =
"ClariusBLE::ConfigureWifiLAN called with ssid parameter of invalid length (0)";
1098 _impl->LastError =
"ClariusBLE::ConfigureWifiLAN called with password parameter of invalid length (0)";
1102 std::stringstream ss;
1103 ss <<
"ap: false\n";
1104 ss <<
"ssid: " << ssid <<
"\n";
1109 IBuffer buf = writer.DetachBuffer();
1111 IAsyncOperation<GattWriteResult> writeOp =
1112 _impl->PowerRequestChar.WriteValueWithResultAsync(buf, GattWriteOption::WriteWithResponse);
1115 _impl->LastError =
"ConfigureWifiLAN failed to write to WifiRequestChar";
1119 GattWriteResult writeResult = writeOp.GetResults();
1120 if (writeResult.Status() != GattCommunicationStatus::Success)
1122 std::stringstream msg;
1123 msg <<
"ClariusBLE::ConfigureWifiLAN failed with non-successful GATT communication. Status was: " 1124 << _impl->GattCommunicationStatusToString(writeResult.Status());
1125 _impl->LastError = msg.str();
1135 if (!_impl->WifiInfoSet)
1137 _impl->LastError =
"Clarius wifi info not set yet...";
1147 return _impl->LastError;
static const winrt::guid WIFI_SERVICE_UUID
PlusStatus FindBySerial(std::string serialNum)
std::string to_narrow_string(std::wstring wstr)
PlusStatus CloseConnection()
std::string uuid_to_string(const winrt::guid &uuid)
PlusStatus ConfigureWifiAP()
std::pair< PlusStatus, ClariusWifiInfo > GetWifiInfo()
PlusStatus await_async(TAsyncOp op)
static const winrt::guid POWER_SERVICE_UUID
PlusStatus RequestProbeOn()
const char int const char * password
static const int MAX_BLE_CONNECTION_ATTEMPTS
ClariusAvailability Available
bool AwaitWifiInfoReady()
static const winrt::guid WIFI_REQUEST_CHAR_UUID
static const uint64_t POWER_ON_TIMEOUT_SEC
std::string GetLastError()
static const uint64_t POWER_ON_POLL_INTERVAL_SEC
PlusStatus ReadWifiInfo()
static const uint64_t BLE_OP_TIMEOUT_SEC
static const winrt::guid WIFI_PUBLISHED_CHAR_UUID
static const winrt::guid POWER_PUBLISHED_CHAR_UUID
PlusStatus ConfigureWifiLAN(std::string ssid, std::string password)
PlusStatus RequestProbeOff()
static const winrt::guid POWER_REQUEST_CHAR_UUID
std::wstring to_wide_string(std::string str)
std::vector< std::string > RetrieveFoundProbeIds()