void Propulsiontask(void const * argument)
{
/* USER CODE BEGIN Propulsiontask */
/* Infinite loop */
struct sockaddr_in server_addr_push;
struct sockaddr_in connect_addr_push;
int socket_push;
int socket_connect_push;
socklen_t addr_len;
int err;
int recv_push = 0;
int send_push = 0;
unsigned char data_buffer_push[50];
socket_push = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(socket_push == -1)
{
closesocket(socket_push);
return;
}
memset(&server_addr_push, 0, sizeof(server_addr_push));
server_addr_push.sin_family = AF_INET;
server_addr_push.sin_addr.s_addr =inet_addr("192.168.5.100");
server_addr_push.sin_port = htons(9895);
addr_len = sizeof(struct sockaddr_in);
err = bind(socket_push, (struct sockaddr *)&server_addr_push, sizeof(server_addr_push));
if(err < 0)
{
closesocket(socket_push);
return;
}
err = listen(socket_push, 1);
if(err < 0)
{
closesocket(socket_push);
return;
}
while(1)
{
socket_connect_push = lwip_accept(socket_push, (struct sockaddr *)&connect_addr_push, &addr_len);
if(socket_connect_push >= 0)
{
send(socket_connect_push, "connect success!\n\r", 20, 0);
break;
}
else
{
vTaskDelay(10);
}
}
for(;;)
{
vTaskDelay(10);
recv_push = (int)lwip_recv(socket_connect_push, (void *)data_buffer_push, 50, 0);
if (recv_push > 0)
{
recv_time ++;
if(recv_time == 32762) recv_time = 0;
if(0 == strncmp((const char*)data_buffer_push, "$MTC", 4))
{
CanResive_data_handle(data_buffer_push,recv_push);
}
}
if (true == Propulsion_Flag)
{
Propulsion_Flag = false;
Propulsion_data_handle();
send_push = send(socket_connect_push, (void *)data_propulsion_push ,strlen((char *)data_propulsion_push),0 );
if (send_push < 0)
{
while(1)
{
closesocket(socket_connect_push);
socket_connect_push = lwip_accept(socket_push, (struct sockaddr *)&connect_addr_push, &addr_len);
if(socket_connect_push >= 0)
{
send(socket_connect_push, "connect success!\n\r", 20, 0);
break;
}
else
{
vTaskDelay(30);
}
}
}
}
|
[md]今天又测试出来是`lwip_recv`()影响了send(),我把`lwip_recv`去掉,只接收不发送的时候,接收就完全正常了
老哥 我这f407加freertos程序下载到板子上没反应能不能帮忙看那看那