23 m_sensorLabel =
"WIRELESS_POWER";
32 #ifdef MRPT_OS_WINDOWS 33 # if defined(__GNUC__) 41 #pragma comment(lib, "Wlanapi.lib") 49 #ifdef MRPT_OS_WINDOWS 50 # if defined(__GNUC__) 62 void* ConnectWlanServerW()
64 DWORD dwMaxClient = 2;
65 DWORD dwCurVersion = 0;
69 dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
70 if (dwResult != ERROR_SUCCESS) {
72 std::stringstream excmsg;
73 excmsg <<
"WlanOpenHandle failed with error: " << dwResult << std::endl;
78 return (
void*)hClient;
92 std::vector<PWLAN_INTERFACE_INFO> ListInterfacesW(HANDLE hClient)
96 std::vector<PWLAN_INTERFACE_INFO> outputVector;
97 PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
98 PWLAN_INTERFACE_INFO pIfInfo = NULL;
105 dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
108 if (dwResult != ERROR_SUCCESS) {
110 std::stringstream excmsg;
111 excmsg <<
"WlanEnumInterfaces failed with error: " << dwResult << std::endl;
117 for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
119 pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
120 outputVector.push_back(pIfInfo);
143 WCHAR GuidString[39] = {0};
150 iRet = StringFromGUID2(ifaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/
sizeof(*GuidString));
160 wctostr = wcstombs_s(&sizeGUID, GuidChar, 100, GuidString, 100 );
161 if ( (wctostr == EINVAL) || (wctostr == ERANGE) ){
181 PWLAN_INTERFACE_INFO GetInterfaceW(
std::string guid, HANDLE hClient)
186 std::vector<PWLAN_INTERFACE_INFO> ifaceList;
188 PWLAN_INTERFACE_INFO output = NULL;
191 ifaceList = ListInterfacesW(hClient);
194 for(ifaceIter = ifaceList.begin(); ifaceIter != ifaceList.end(); ++ifaceIter){
195 if (GUID2Str((*ifaceIter)->InterfaceGuid) == guid){
215 std::vector<PWLAN_AVAILABLE_NETWORK> ListNetworksW(PWLAN_INTERFACE_INFO iface, HANDLE hClient)
220 PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
221 PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
224 GUID ifaceGuid = iface->InterfaceGuid;
226 std::vector<PWLAN_AVAILABLE_NETWORK> outputVector;
231 WLAN_RAW_DATA IeData;
232 WlanScan((HANDLE)hClient, &ifaceGuid, NULL, &IeData, NULL);
235 dwResult = WlanGetAvailableNetworkList((HANDLE)hClient, &ifaceGuid, 0, NULL, &pBssList);
238 if (dwResult != ERROR_SUCCESS) {
240 std::stringstream excmsg;
241 excmsg <<
"WlanGetAvailableNetworkList failed with error: " << dwResult << std::endl;
245 for (
unsigned int j = 0; j < pBssList->dwNumberOfItems; j++) {
246 pBssEntry = (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j];
247 outputVector.push_back(pBssEntry);
265 PWLAN_INTERFACE_INFO iface;
266 PWLAN_AVAILABLE_NETWORK output;
270 iface = GetInterfaceW(guid, hClient);
273 std::vector<PWLAN_AVAILABLE_NETWORK> pBssList = ListNetworksW(iface,hClient);
278 for(netIter = pBssList.begin(); netIter != pBssList.end() ; ++netIter){
279 if (
std::string((
char*)((*netIter)->dot11Ssid.ucSSID)) == ssid ){
290 #endif // end of Windows auxiliary functions definition 302 std::vector<std::string> output;
307 char ifaceread[256],*netname;
312 cmdoutput = popen(
"cat /proc/net/wireless|grep \"wlan\"|cut -d\" \" -f2|cut -d\":\" -f1",
"r");
313 if (!fgets(ifaceread,3,cmdoutput))
324 #ifdef MRPT_OS_WINDOWS 325 # if defined(__GNUC__) 330 std::vector<PWLAN_INTERFACE_INFO> ifaces;
335 ifaces = ListInterfacesW(hClient);
338 for (ifacesIter = ifaces.begin(); ifacesIter != ifaces.end() ; ++ifacesIter){
339 output.push_back(GUID2Str((*ifacesIter)->InterfaceGuid));
356 std::vector<std::string> output;
360 std::stringstream commandl;
368 commandl <<
"sudo iwlist " <<
"wlan0" <<
" scan|grep ESSID|cut -d\"\\\"\" -f2";
369 cmdoutput = popen(commandl.str().c_str(),
"r");
370 if (!fgets(listread,3,cmdoutput))
381 #ifdef MRPT_OS_WINDOWS 382 # if defined(__GNUC__) 386 PWLAN_INTERFACE_INFO iface;
389 iface = GetInterfaceW(guid,(HANDLE)hClient);
392 std::vector<PWLAN_AVAILABLE_NETWORK> pBssList = ListNetworksW(iface,(HANDLE)hClient);
396 for(netIter = pBssList.begin(); netIter != pBssList.end() ; ++netIter){
397 output.push_back(
std::string((
char*)((*netIter)->dot11Ssid.ucSSID)));
418 std::stringstream commandl;
420 commandl <<
"sudo iwlist " <<
"wlan0" <<
" scan";
421 cmdoutput = popen(commandl.str().c_str(),
"r");
423 std::vector<std::string> powerReadV;
426 powerReadL = (
char *) malloc (256);
427 std::stringstream ssidLine;
429 ssidLine <<
"ESSID:\"" << ssid <<
"\"";
430 if (getline(&powerReadL,&readBytes,cmdoutput)<0)
THROW_EXCEPTION(
"Error reading response from iwlist")
432 while(!strstr(powerReadL, ssidLine.str().c_str())){
434 if (getline(&powerReadL,&readBytes,cmdoutput))
444 strcpy(powerLine,(*ssiter).c_str());
460 #elif defined(MRPT_OS_WINDOWS) 461 # if defined(__GNUC__) 464 PWLAN_AVAILABLE_NETWORK wlan;
467 wlan = GetNetworkW((HANDLE)hClient,ssid,guid);
469 return wlan->wlanSignalQuality;
489 outObservation.
power = (float)GetPower();
499 cerr <<
"[CWirelessPower::getObservation] Returning false due to exception: " << endl;
500 cerr << e.what() << endl;
520 pose_x = configSource.
read_float(iniSection,
"pose_x",0,
true);
521 pose_y = configSource.
read_float(iniSection,
"pose_y",0,
true);
522 pose_z = configSource.
read_float(iniSection,
"pose_z",0,
true);
523 pose_roll = configSource.
read_float(iniSection,
"pose_roll",0,
true);
524 pose_pitch = configSource.
read_float(iniSection,
"pose_pitch",0,
true);
525 pose_yaw = configSource.
read_float(iniSection,
"pose_yaw",0,
true);
527 ssid = configSource.
read_string(iniSection,
"ssid",
"",
true);
528 guid = configSource.
read_string(iniSection,
"guid",
"",
true);
530 #ifdef MRPT_OS_WINDOWS 531 # if defined(__GNUC__) 534 hClient = ConnectWlanServerW();
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFramePtr &observations, mrpt::obs::CObservationPtr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string §ion)
Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes)
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
#define THROW_EXCEPTION(msg)
Contains classes for various device interfaces.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
static CObservationWirelessPowerPtr Create()
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy.
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 ...
This class implements a wireless power probe.
double power
The power or signal strength as sensed by the Wifi receiver (In percentage: [0-100]) ...
GLsizei const GLchar ** string
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. Where available, this should contain the accurate satellite-based time...
std::vector< std::string > ListNetworks()
Gets a list of the networks available for an interface.
std::vector< std::string > ListInterfaces()
Gets a list of the interfaces.
int GetPower()
Gets the power of a given network.
char BASE_IMPEXP * strtok(char *str, const char *strDelimit, char **context) MRPT_NO_THROWS
An OS-independent method for tokenizing a string.
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)