46 #pragma comment(lib, "wlanapi.lib") 47 #pragma comment(lib, "ole32.lib") 51 #include <sys/socket.h> 52 #include <linux/wireless.h> 53 #include <sys/ioctl.h> 70 else if(quality >= 100)
73 return (quality / 2) - 100;
80 WifiThread(
const std::string & interfaceName,
float rate = 0.5) :
96 HANDLE hClient =
NULL;
97 DWORD dwMaxClient = 2;
98 DWORD dwCurVersion = 0;
102 PWLAN_INTERFACE_INFO_LIST pIfList =
NULL;
103 PWLAN_INTERFACE_INFO pIfInfo =
NULL;
106 PWLAN_CONNECTION_ATTRIBUTES pConnectInfo =
NULL;
107 DWORD connectInfoSize =
sizeof(WLAN_CONNECTION_ATTRIBUTES);
108 WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;
110 dwResult = WlanOpenHandle(dwMaxClient,
NULL, &dwCurVersion, &hClient);
111 if (dwResult != ERROR_SUCCESS)
113 UERROR(
"WlanOpenHandle failed with error: %u\n", dwResult);
117 dwResult = WlanEnumInterfaces(hClient,
NULL, &pIfList);
118 if (dwResult != ERROR_SUCCESS)
120 UERROR(
"WlanEnumInterfaces failed with error: %u\n", dwResult);
126 pIfInfo = (WLAN_INTERFACE_INFO *) & pIfList->InterfaceInfo[i];
127 if(pIfInfo->isState == wlan_interface_state_connected)
129 dwResult = WlanQueryInterface(hClient,
130 &pIfInfo->InterfaceGuid,
131 wlan_intf_opcode_current_connection,
134 (PVOID *) &pConnectInfo,
137 if (dwResult != ERROR_SUCCESS)
139 UERROR(
"WlanQueryInterface failed with error: %u\n", dwResult);
143 int quality = pConnectInfo->wlanAssociationAttributes.wlanSignalQuality;
149 UERROR(
"Interface not connected!");
153 if (pConnectInfo !=
NULL)
155 WlanFreeMemory(pConnectInfo);
161 WlanFreeMemory(pIfList);
172 if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
173 UERROR(
"Could not create simple datagram socket");
178 struct iw_statistics stats;
183 req.u.data.pointer = (caddr_t) &stats;
184 req.u.data.length =
sizeof(stats);
186 req.u.data.flags = 1;
189 if(ioctl(sockfd, SIOCGIWSTATS, &req) == -1)
194 else if(((iw_statistics *)req.u.data.pointer)->qual.updated & IW_QUAL_DBM)
197 dBm = ((iw_statistics *)req.u.data.pointer)->qual.level - 256;
201 UERROR(
"Could not get signal level.");
211 cv::Mat data(1, 2, CV_64FC1);
212 data.at<
double>(0) =
double(dBm);
213 data.at<
double>(1) = stamp;
214 this->
post(
new UserDataEvent(data));
WifiThread(const std::string &interfaceName, float rate=0.5)
int getRssi(const std::string &interfaceName)
int quality2dBm(int quality)
std::string interfaceName_
void post(UEvent *event, bool async=true) const
void uSleep(unsigned int ms)