CC3000控制疑问
我是用传感器那个例子程序的,把原来接到DATA后就向Client端发送数据修改了一下,变成接到接定的数据就做相应的动作。就是下面带标记的while。这样写有以下问题咨询:
1.hci_unsolicited_event_handler();和mDNS_packet_trigger_timer_enable();具体有什么作用。特别是前一个
2.这个while这样写开始时是可以控制CC3000,但是过一段时间后发现就不能控制了,不知是什么问题。
while(1)
{
//
// Handle any un-solicited event if required - the function shall be triggered
// few times in a second
//
hci_unsolicited_event_handler();
addrlen = sizeof(clientaddr);
terminalPrint("Waiting for Clients\r\n");
// accept blocks until we receive a connection
while ( (clientDescriptor == -1) || (clientDescriptor == -2) )
{
clientDescriptor = accept(serverSocket, (sockaddr *) &clientaddr, &addrlen);
}
//
// Handle any un-solicited event if required - the function shall be triggered
// few times in a second
//
hci_unsolicited_event_handler();
// Call user specified Clietn Accepted Event Handler
if(clientDescriptor >= 0)
{
setCC3000MachineState(CC3000_CLIENT_CONNECTED);
terminalPrint("Client ");
// Read IP and print
clientIP[0] = clientaddr.sa_data[2];
clientIP[1] = clientaddr.sa_data[3];
clientIP[2] = clientaddr.sa_data[4];
clientIP[3] = clientaddr.sa_data[5];
printIpAddr(clientIP);
terminalPrint(" Connected\r\n");
// Connection Accepted, Wait for data exchange
char requestBuffer[SERVER_RECV_BUF_SIZE];
//这个while就是所做的修改
while(1)
{
hci_unsolicited_event_handler();
bytesRecvd = recv(clientDescriptor, requestBuffer, sizeof(requestBuffer), 0);
if(strncmp(requestBuffer,"CTRL1",strlen("CTRL1")) == 0)
{
toggleLed(LED6);
}
if(strncmp(requestBuffer,"CTRL2",strlen("CTRL2")) == 0)
{
toggleLed(LED7);
}
if(strncmp(requestBuffer,"CTRL3",strlen("CTRL3")) == 0)
{
toggleLed(LED8);
}
}
__delay_cycles(1000);
}
else if(clientDescriptor == SOCKET_INACTIVE_ERR)
{
terminalPrint("Socket Server Timeout. Restarting Server\r\n");
clientDescriptor = -1;
// Reinitialize the server
shutdownServer();
initServer();
}
hci_unsolicited_event_handler();
}
你可以不用while结构,而用for结构,一定次数循环后跳出试试。