Now i want to scan ssid of the enviroment using cc3200.I have see the demo of scan_policy .
First my cc3200 works in ap mode which have created a udp socket,and i use pc connect the 3200.
Then i send a command to it,after the 3200 recives the command ,it begin to scan the ssid of other ap.
After it get the list of ssid, it turn to the AP mode and send these ssids to the pc.
Now i have one problem, it takes too long to scan the list.What should i do to reduce the time .
Follow is my code:
sl_Close(iSockID); //close the udp socket
sl_WlanSetMode(ROLE_STA);
sl_Stop(10); //
sl_Start(NULL,NULL,NULL);
ucpolicyOpt = SL_CONNECTION_POLICY(0, 0, 0, 0,0);
lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , ucpolicyOpt, NULL, 0);
if(lRetVal != 0)
{
UART_PRINT("Unable to clear the Connection Policy\r\n");
}
ucpolicyOpt = SL_SCAN_POLICY(1);
//
// set scan cycle to 1 seconds
//
policyVal.uiPolicyLen = 1; //the least is 900 ms?
//
// set scan policy - this starts the scan
//
lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucpolicyOpt,
(unsigned char*)(policyVal.ucPolicy), sizeof(policyVal));
if(lRetVal!=0)
{
UART_PRINT("Unable to set the Scan Policy\r\n");
//return lRetVal;
}
usr_Report("start scan");
MAP_UtilsDelay(1000000);//wait to read list
sl_WlanGetNetworkList(0, (unsigned char)20,
&netEntries[0]);
usr_Report("get list");
for(j=0;j<20-1;j++)
{
for(i=0;i<20-1-j;i++)
{
if(netEntries[i].rssi>netEntries[i+1].rssi)//数组元素大小按升序排列
{
data_temp1=netEntries[i];
netEntries[i]=netEntries[i+1];
netEntries[i+1]=data_temp1;
}
}
}
sl_WlanSetMode(ROLE_AP);
sl_Stop(10); //
sl_Start(NULL,NULL,NULL);
for(j=0;j<32;j++)
{
para[j]=init_flash_temp[init_flash_ap_sta+j];
}
sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen((const char *)para), (unsigned char *)para);
val = SL_SEC_TYPE_OPEN;
sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, (unsigned char *)&val);
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
if( iSockID < 0 )
{
usr_Report("Creat search UDP SOCKET err\r\n");
goto start;
}
// binding the UDP socket to the UDP server address
iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
if( iStatus < 0 )
{
usr_Report("Creat search UDP SOCKET bind err\r\n");
goto start;
}
iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&lNonBlocking, sizeof(lNonBlocking));
if( iStatus < 0 )
{
usr_Report("Creat search UDP SOCKET set opt err\r\n");
goto start;
}
for(i=20;i>0;i--)
{
usr_Report("%s\r\n",netEntries[i-1].ssid);
usr_Report("%d\r\n",netEntries[i-1].rssi);
}
g_cBsdBuf[0]=0xff;
g_cBsdBuf[1]=0xff;//length
g_cBsdBuf[2]=0xff;
g_cBsdBuf[3]=0x81;//return cmd
g_cBsdBuf[4]=0x00;//num of ap
i=5;
for(j=20;j>0;j--)//ap ssid
{
if(netEntries[j-1].ssid_len==0)
{
continue;
}
else
{
for(k=0;k<netEntries[j-1].ssid_len;k++)
{
g_cBsdBuf[i++]=netEntries[j-1].ssid[k];
}
g_cBsdBuf[i++]=0x00;//end of ssid
if((netEntries[j-1].rssi+95)*2<0)
{
g_cBsdBuf[i++]=0;//ssid rssi
}
else if((netEntries[j-1].rssi+95)*2>100)
{
g_cBsdBuf[i++]=100;//ssid rssi
}
else
{
g_cBsdBuf[i++]=(netEntries[j-1].rssi+95)*2;
}
g_cBsdBuf[i++]=0x0d;//end ssid rssi
g_cBsdBuf[i++]=0x0a;//end ssid rssi
g_cBsdBuf[4]++;
}
}
g_cBsdBuf[1]=(i-3)<<8;//length
g_cBsdBuf[2]=i-3;
data_sum=0;
for(j=1;j<i;j++)
{
data_sum+=g_cBsdBuf[j];
}
g_cBsdBuf[i++]=data_sum;//sum check
sl_SendTo(iSockID, g_cBsdBuf, i, 0,( SlSockAddr_t *)&sAddr, (SlSocklen_t)iAddrSize);