30 #pragma comment(lib, "Wlanapi.lib")
58 DWORD dwMaxClient = 2;
59 DWORD dwCurVersion = 0;
63 dwResult = WlanOpenHandle(dwMaxClient,
nullptr, &dwCurVersion, &hClient);
64 if (dwResult != ERROR_SUCCESS)
67 std::stringstream excmsg;
68 excmsg <<
"WlanOpenHandle failed with error: " << dwResult << std::endl;
73 return (
void*)hClient;
90 std::vector<PWLAN_INTERFACE_INFO> outputVector;
91 PWLAN_INTERFACE_INFO_LIST pIfList =
nullptr;
92 PWLAN_INTERFACE_INFO pIfInfo =
99 dwResult = WlanEnumInterfaces(hClient,
nullptr, &pIfList);
102 if (dwResult != ERROR_SUCCESS)
105 std::stringstream excmsg;
106 excmsg <<
"WlanEnumInterfaces failed with error: " << dwResult
115 for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
117 pIfInfo = (WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
118 outputVector.push_back(pIfInfo);
140 WCHAR GuidString[39] = {0};
143 std::string outputString;
146 iRet = StringFromGUID2(
147 ifaceGuid, (LPOLESTR)&GuidString,
148 sizeof(GuidString) /
sizeof(*GuidString));
160 wctostr = wcstombs_s(&sizeGUID, GuidChar, 100, GuidString, 100);
161 if ((wctostr == EINVAL) || (wctostr == ERANGE))
167 outputString = std::string(GuidChar);
190 std::vector<PWLAN_INTERFACE_INFO> ifaceList;
191 std::vector<PWLAN_INTERFACE_INFO>::iterator ifaceIter;
192 PWLAN_INTERFACE_INFO output =
nullptr;
198 for (ifaceIter = ifaceList.begin(); ifaceIter != ifaceList.end();
201 if (
GUID2Str((*ifaceIter)->InterfaceGuid) == guid)
223 PWLAN_INTERFACE_INFO iface, HANDLE hClient)
228 PWLAN_AVAILABLE_NETWORK_LIST pBssList =
230 PWLAN_AVAILABLE_NETWORK pBssEntry =
233 GUID ifaceGuid = iface->InterfaceGuid;
235 std::vector<PWLAN_AVAILABLE_NETWORK> outputVector;
240 WLAN_RAW_DATA IeData;
241 WlanScan((HANDLE)hClient, &ifaceGuid,
nullptr, &IeData,
nullptr);
245 dwResult = WlanGetAvailableNetworkList(
246 (HANDLE)hClient, &ifaceGuid, 0,
nullptr, &pBssList);
249 if (dwResult != ERROR_SUCCESS)
252 std::stringstream excmsg;
253 excmsg <<
"WlanGetAvailableNetworkList failed with error: " << dwResult
260 for (
unsigned int j = 0; j < pBssList->dwNumberOfItems; j++)
262 pBssEntry = (WLAN_AVAILABLE_NETWORK*)&pBssList
264 outputVector.push_back(pBssEntry);
281 HANDLE hClient,
const std::string& ssid,
const std::string& guid)
284 PWLAN_INTERFACE_INFO iface;
285 PWLAN_AVAILABLE_NETWORK output;
291 std::vector<PWLAN_AVAILABLE_NETWORK> pBssList =
295 std::vector<PWLAN_AVAILABLE_NETWORK>::iterator netIter;
296 for (netIter = pBssList.begin(); netIter != pBssList.end(); ++netIter)
298 if (std::string((
char*)((*netIter)->dot11Ssid.ucSSID)) == ssid)
310 #endif // end of Windows auxiliary functions definition
319 std::vector<std::string> output;
324 char ifaceread[256], *netname;
334 "cat /proc/net/wireless|grep \"wlan\"|cut -d\" \" -f2|cut -d\":\" -f1",
336 if (!fgets(ifaceread, 3, cmdoutput))
340 netname =
::strtok(ifaceread,
"\n");
343 output.emplace_back(netname);
349 #if defined(__GNUC__)
354 std::vector<PWLAN_INTERFACE_INFO>
356 std::vector<PWLAN_INTERFACE_INFO>::iterator
363 for (ifacesIter = ifaces.begin(); ifacesIter != ifaces.end(); ++ifacesIter)
365 output.push_back(
GUID2Str((*ifacesIter)->InterfaceGuid));
380 std::vector<std::string> output;
384 std::stringstream commandl;
396 commandl <<
"sudo iwlist "
398 <<
" scan|grep ESSID|cut -d\"\\\"\" -f2";
399 cmdoutput = popen(commandl.str().c_str(),
"r");
400 if (!fgets(listread, 3, cmdoutput))
406 output.emplace_back(netname);
413 #if defined(__GNUC__)
417 PWLAN_INTERFACE_INFO iface;
422 std::vector<PWLAN_AVAILABLE_NETWORK> pBssList =
426 std::vector<PWLAN_AVAILABLE_NETWORK>::iterator netIter;
427 for (netIter = pBssList.begin(); netIter != pBssList.end(); ++netIter)
429 output.push_back(std::string((
char*)((*netIter)->dot11Ssid.ucSSID)));
447 std::stringstream commandl;
449 commandl <<
"sudo iwlist "
452 cmdoutput = popen(commandl.str().c_str(),
"r");
454 std::vector<std::string> powerReadV;
457 powerReadL = (
char*)malloc(256);
458 std::stringstream ssidLine;
460 ssidLine <<
"ESSID:\"" << ssid <<
"\"";
461 if (getline(&powerReadL, &readBytes, cmdoutput) < 0)
464 while (!strstr(powerReadL, ssidLine.str().c_str()))
466 powerReadV.emplace_back(powerReadL);
467 if (getline(&powerReadL, &readBytes, cmdoutput))
471 auto ssiter = powerReadV.end() - 2;
478 strcpy(powerLine, (*ssiter).c_str());
494 #elif defined(_WIN32)
495 #if defined(__GNUC__)
498 PWLAN_AVAILABLE_NETWORK wlan;
503 return wlan->wlanSignalQuality;
522 outObservation.
power = (float)GetPower();
535 cerr <<
"[CWirelessPower::getObservation] Returning false due to "
538 cerr << e.what() << endl;
555 const std::string& iniSection)
558 pose_x = configSource.
read_float(iniSection,
"pose_x", 0,
true);
559 pose_y = configSource.
read_float(iniSection,
"pose_y", 0,
true);
560 pose_z = configSource.
read_float(iniSection,
"pose_z", 0,
true);
561 pose_roll = configSource.
read_float(iniSection,
"pose_roll", 0,
true);
562 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch", 0,
true);
563 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw", 0,
true);
565 ssid = configSource.
read_string(iniSection,
"ssid",
"",
true);
567 iniSection,
"guid",
"",
true);
571 #if defined(__GNUC__)