6.4客流量统计
本设计利用w800设计出一款可以实时监控公共场所的人流量系统.其中w800提供混杂接收模式接收数据包,并对其解析,筛选得到周围打开Wi-Fi功能设备发送的Probe Request帧,通过对接收到的Probe Request帧分析和汇总,得到周围区域内的设备使用量(人流量)。
w800可进入该sniffer模式,接收空中的 IEEE802.11包,获取周围设备MAC信息,从而估算客流量。
static void sniffer_callback(struct ieee80211_hdr *hdr, u32 data_len,struct tls_wifi_ext_t *ext)
{
if((ieee80211_is_mgmt(hdr->frame_control) != 0))
{
static u8 last_sa_addr_data[6] = {0};
static u8 last_da_addr_data[6] = {0};
u8 *curr_sa_addr_data = NULL;
u8 *curr_da_addr_data = NULL;
u8 data_diff = FALSE;
char addr[] = "00:00:00:00:00:00";
curr_sa_addr_data = ieee80211_get_SA(hdr);
curr_da_addr_data = ieee80211_get_DA(hdr);
for(int i=0; i< 6; i++)
{
if(*(curr_sa_addr_data + i) != *(last_sa_addr_data +i))
{
data_diff = TRUE;
if(data_diff ==TRUE)
{
count++;
tls_os_time_delay(8000);
data_diff = FALSE;
}
break;
}
if(*(curr_da_addr_data + i) != *(last_da_addr_data +i))
{
data_diff = TRUE;
break;
}
}
if((data_diff) && ((hdr->frame_control & IEEE80211_FCTL_RETRY) == 0))
{
memcpy((u8 *)last_sa_addr_data, curr_sa_addr_data, 6);
memcpy((u8 *)last_da_addr_data, curr_da_addr_data, 6);
sprintf(addr, "%02X:%02X:%02X:%02X:%02X:%02X", *curr_sa_addr_data, *(curr_sa_addr_data+1), *(curr_sa_addr_data+2), *(curr_sa_addr_data+3), *(curr_sa_addr_data+4), *(curr_sa_addr_data+5));
printf("%s|", addr);
printf("count:\r\n%d\r\n", count);
}
}
}
编译程序,下载到开发板,客流统计信息将显示到显示屏