新手上路
- 积分
- 24
- 金钱
- 24
- 注册时间
- 2021-11-12
- 在线时间
- 6 小时
|

楼主 |
发表于 2022-5-10 11:11:19
|
显示全部楼层
代码如下:
static void App_Net_Passthrough_Service(void* arg)
{
struct netbuf *pt_recvbuf;
uint16_t pt_pbuf_len = 0;
uint16_t data_len = 0;
void *pt_data;
LWIP_UNUSED_ARG(arg);
p_t_conn = netconn_new(NETCONN_TCP);
p_t_conn->pcb.tcp->so_options |= SOF_KEEPALIVE;
netconn_bind(p_t_conn,
IP_ADDR_ANY,
PASS_THROUGH_PORT);
netconn_listen(p_t_conn);
while(1)
{
if( ERR_OK == netconn_accept(p_t_conn, &p_t_conn_newconn) )
{
g_pt_en_flag = 1; //开启透传服务
while( ERR_OK == netconn_recv(p_t_conn_newconn,&pt_recvbuf) )
{
data_len = 0;
do
{
netbuf_data(pt_recvbuf, &pt_data, &pt_pbuf_len);
log_i("%d", pt_pbuf_len);
memcpy(pt_buf+data_len, pt_data, pt_pbuf_len);
data_len += pt_pbuf_len;
if (data_len > P_T_MESSAGE_MAX) break;
}while( netbuf_next(pt_recvbuf)>=0 );
App_Rs485_Send_Data(pt_buf, data_len);
netbuf_delete(pt_recvbuf);
data_len = 0;
}
/* 关闭连接,丢弃连接标识符 */
g_pt_en_flag = 0; //关闭透传服务
netconn_close(p_t_conn_newconn);
netconn_delete(p_t_conn_newconn);
}
}
} |
|