From 50dc67c34f82dbfb6acee4f51e4d6ed82b492c3c Mon Sep 17 00:00:00 2001 From: kyz Date: Sat, 10 May 2025 14:54:19 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96tcp=E9=80=9A=E4=BF=A1=E5=A4=84?= =?utf8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- user/user_noise_sensor.c | 4 ++-- user/user_tcp.c | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/user/user_noise_sensor.c b/user/user_noise_sensor.c index 09d35e0..83b480b 100644 --- a/user/user_noise_sensor.c +++ b/user/user_noise_sensor.c @@ -100,12 +100,12 @@ static void user_noise_task(void *argument) while(1){ osDelay(1000); - printf( "noise read ...\n" ); + //printf( "noise read ...\n" ); if( user_noise_sensor_read( &noise ) == 0 ){ err = 0; noise_state = 1; user_noise_info_update( noise, noise_state ); - printf( "noise db:%.1f ...\n", noise ); + //printf( "noise db:%.1f ...\n", noise ); }else{ if( noise_state >= 0 ){ if( err++ > 10 ){ diff --git a/user/user_tcp.c b/user/user_tcp.c index 6d9f564..bab15ad 100644 --- a/user/user_tcp.c +++ b/user/user_tcp.c @@ -20,7 +20,8 @@ static int32_t wrap_pkt( uint8_t *buf, uint16_t sn, uint16_t cmd, uint8_t *data, struct tcp_pcb *tcp_server_pcb; static struct tcp_pcb *tcp_connected_pcb = NULL; -static uint16_t tx_sn = 0; +static uint16_t tx_pkt_sn = 0; +static uint16_t rx_pkt_sn; void Tcp_Server_Init(void) { @@ -54,8 +55,8 @@ int32_t user_tcp_write_pkt( uint16_t cmd, uint8_t *data, uint32_t data_sz ) { uint8_t buf[256]; uint16_t n; - tx_sn++; - n = wrap_pkt( buf, tx_sn, cmd, data, data_sz ); + tx_pkt_sn++; + n = wrap_pkt( buf, tx_pkt_sn, cmd, data, data_sz ); return user_tcp_write_data( buf, n ); } @@ -74,7 +75,7 @@ static err_t tcp_server_accept(void *arg, struct tcp_pcb *pcb, err_t err) /* ÅäÖýÓÊջص÷º¯Êý */ tcp_recv(pcb, tcp_server_recv); - + printf( "tcp accept, pcb:%p\n", pcb ); return ERR_OK; } @@ -99,7 +100,7 @@ CMD: 3002: Laki Rx */ -static uint16_t rx_pkt_sn; + int32_t wrap_pkt( uint8_t *buf, uint16_t sn, uint16_t cmd, uint8_t *data, uint32_t data_sz ) { uint8_t *p = buf; @@ -140,9 +141,11 @@ int32_t tcp_recv_cb(struct tcp_pcb *pcb, uint8_t *data, uint32_t len ) sensor_info_t sensor; -// uint16_t noise; -// uint16_t sound_freq; -// uint16_t sound_amplitude; + + if( tcp_connected_pcb == 0 ){ + rx_pkt_sn = 0; + tx_pkt_sn = 0; + } resp_sz = 0; if( len >= 10 && p[0]==0x55 && p[1]==0xAA ){ @@ -190,7 +193,7 @@ static err_t tcp_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *tcp_re //struct pbuf *tcp_send_pbuf; struct name *name = (struct name *)arg; uint8_t *rx_data; - + printf( "tcp recv, pcb:%p\n", pcb ); if (tcp_recv_pbuf != NULL) { /* À©´óÊÕ·¢Êý¾ÝµÄ´°¿Ú */ @@ -228,6 +231,8 @@ static err_t tcp_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *tcp_re { /* ÊÍ·ÅÄÚ´æ */ mem_free(name); + printf( "tcp_close: pcb:%p\n", tcp_connected_pcb ); + tcp_connected_pcb = 0; return tcp_close(pcb); } -- 2.34.1