diff --git a/src/uni_communication.c b/src/uni_communication.c index 3d0abe9..c1a8ef0 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,11 @@ 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 (_get_current_acked_seq() != -1 && _is_udp_packet(protocol_packet)) { + _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);