From bf2dc4bbbcd96be578784601d9eff16058b2ec23 Mon Sep 17 00:00:00 2001 From: shangjinlong Date: Thu, 13 Aug 2020 10:42:25 +0800 Subject: [PATCH 1/2] fix issue 5 in v2 --- src/uni_communication.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/uni_communication.c b/src/uni_communication.c index 3d0abe9..adeb444 100644 --- a/src/uni_communication.c +++ b/src/uni_communication.c @@ -102,7 +102,7 @@ typedef struct { pthread_mutex_t app_send_sync_lock; /* avoid app send concurrency, out of sequence */ uni_bool acked; CommSequence sequence; - CommSequence current_acked_seq; /* current received sequence */ + short current_acked_seq; /* current received sequence */ char *protocol_buffer; InterruptHandle interrupt_handle; uni_bool inited; @@ -128,11 +128,11 @@ static void _unregister_write_handler() { g_comm_protocol_business.on_write = NULL; } -static void _set_current_acked_seq(CommSequence seq) { +static void _set_current_acked_seq(short seq) { g_comm_protocol_business.current_acked_seq = seq; } -static CommSequence _get_current_acked_seq() { +static short _get_current_acked_seq() { return g_comm_protocol_business.current_acked_seq; } @@ -490,6 +490,11 @@ static uni_bool _is_duplicate_frame(CommProtocolPacket *protocol_packet) { return duplicate; } +static uni_bool _is_udp_packet(CommProtocolPacket *protocol_packet) { + return (_byte2_big_endian_2_u16(protocol_packet->cmd) != 0 && + !_is_ack_set(protocol_packet->control)); +} + static void _one_protocol_frame_process(char *protocol_buffer) { CommProtocolPacket *protocol_packet = (CommProtocolPacket *)protocol_buffer; @@ -504,7 +509,7 @@ static void _one_protocol_frame_process(char *protocol_buffer) { LOGD(TAG, "recv ack frame"); /* one sequence can only break once */ if (protocol_packet->sequence == _current_sequence_get() && - protocol_packet->sequence != _get_current_acked_seq()) { + (short)protocol_packet->sequence != _get_current_acked_seq()) { _set_acked_sync_flag(); _set_current_acked_seq(protocol_packet->sequence); InterruptableBreak(g_comm_protocol_business.interrupt_handle); @@ -536,6 +541,12 @@ static void _one_protocol_frame_process(char *protocol_buffer) { /* ack automatically when ack attribute set */ _do_ack(protocol_packet); + /* udp frame reset current acked seq -1 */ + if (_is_udp_packet(protocol_packet)) { + LOGT(TAG, "reset cur acked sequence to -1"); + _set_current_acked_seq(-1); + } + /* notify application when not ack frame nor duplicate frame */ if (!_is_duplicate_frame(protocol_packet)) { g_comm_protocol_business.on_recv_frame(&packet); From 095a8c16b730fabf560f8f4707db58d3d3a72539 Mon Sep 17 00:00:00 2001 From: shangjinlong Date: Thu, 13 Aug 2020 11:04:13 +0800 Subject: [PATCH 2/2] fix issue 5 in v2 --- src/uni_communication.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/uni_communication.c b/src/uni_communication.c index adeb444..c1a8ef0 100644 --- a/src/uni_communication.c +++ b/src/uni_communication.c @@ -542,8 +542,7 @@ static void _one_protocol_frame_process(char *protocol_buffer) { _do_ack(protocol_packet); /* udp frame reset current acked seq -1 */ - if (_is_udp_packet(protocol_packet)) { - LOGT(TAG, "reset cur acked sequence to -1"); + if (_get_current_acked_seq() != -1 && _is_udp_packet(protocol_packet)) { _set_current_acked_seq(-1); }