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__)
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION(msg)
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
void * ConnectWlanServerW()
Gets a connection to the server.
PWLAN_AVAILABLE_NETWORK GetNetworkW(HANDLE hClient, const std::string &ssid, const std::string &guid)
Gets a handle to the network that has been set by setNet() (in Windows format)
Contains classes for various device interfaces.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
std::vector< PWLAN_INTERFACE_INFO > ListInterfacesW(HANDLE hClient)
Gets a list of the interfaces available in the system (in Windows format)
This class allows loading and storing values and vectors of different types from a configuration text...
bool getObservation(mrpt::obs::CObservationWirelessPower &outObservation)
Gets the power of a given network as a timestamped observation NOTE: Deprecated, use getObservations ...
static Ptr Create(Args &&... args)
This class implements a wireless power probe.
char * strtok(char *str, const char *strDelimit, char **context) noexcept
An OS-independent method for tokenizing a string.
double power
The power or signal strength as sensed by the Wifi receiver (In percentage: [0-100]) ...
PWLAN_INTERFACE_INFO GetInterfaceW(std::string guid, HANDLE hClient)
Gets a handle to the interface that has been set by setNet() (in Windows format)
This represents a measurement of the wireless strength perceived by the robot.
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
std::vector< std::string > ListNetworks()
Gets a list of the networks available for an interface.
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string §ion) override
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see config::CConfigFileBase and derived classes)
std::vector< PWLAN_AVAILABLE_NETWORK > ListNetworksW(PWLAN_INTERFACE_INFO iface, HANDLE hClient)
Gets a list of the networks available for an interface (in Windows format)
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFrame::Ptr &observations, mrpt::obs::CObservation::Ptr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
std::vector< std::string > ListInterfaces()
Gets a list of the interfaces.
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz)
int GetPower()
Gets the power of a given network.
std::string GUID2Str(const GUID &ifaceGuid)
Transforms a GUID structure (in Windows format) to a string.