Skip to content

Commit 6ddc090

Browse files
authored
Merge pull request #9 from junlon2006/hotfix/issue5
fix issue 5 in v2
2 parents 54e0ae0 + 095a8c1 commit 6ddc090

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/uni_communication.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef struct {
102102
pthread_mutex_t app_send_sync_lock; /* avoid app send concurrency, out of sequence */
103103
uni_bool acked;
104104
CommSequence sequence;
105-
CommSequence current_acked_seq; /* current received sequence */
105+
short current_acked_seq; /* current received sequence */
106106
char *protocol_buffer;
107107
InterruptHandle interrupt_handle;
108108
uni_bool inited;
@@ -128,11 +128,11 @@ static void _unregister_write_handler() {
128128
g_comm_protocol_business.on_write = NULL;
129129
}
130130

131-
static void _set_current_acked_seq(CommSequence seq) {
131+
static void _set_current_acked_seq(short seq) {
132132
g_comm_protocol_business.current_acked_seq = seq;
133133
}
134134

135-
static CommSequence _get_current_acked_seq() {
135+
static short _get_current_acked_seq() {
136136
return g_comm_protocol_business.current_acked_seq;
137137
}
138138

@@ -490,6 +490,11 @@ static uni_bool _is_duplicate_frame(CommProtocolPacket *protocol_packet) {
490490
return duplicate;
491491
}
492492

493+
static uni_bool _is_udp_packet(CommProtocolPacket *protocol_packet) {
494+
return (_byte2_big_endian_2_u16(protocol_packet->cmd) != 0 &&
495+
!_is_ack_set(protocol_packet->control));
496+
}
497+
493498
static void _one_protocol_frame_process(char *protocol_buffer) {
494499
CommProtocolPacket *protocol_packet = (CommProtocolPacket *)protocol_buffer;
495500

@@ -504,7 +509,7 @@ static void _one_protocol_frame_process(char *protocol_buffer) {
504509
LOGD(TAG, "recv ack frame");
505510
/* one sequence can only break once */
506511
if (protocol_packet->sequence == _current_sequence_get() &&
507-
protocol_packet->sequence != _get_current_acked_seq()) {
512+
(short)protocol_packet->sequence != _get_current_acked_seq()) {
508513
_set_acked_sync_flag();
509514
_set_current_acked_seq(protocol_packet->sequence);
510515
InterruptableBreak(g_comm_protocol_business.interrupt_handle);
@@ -536,6 +541,11 @@ static void _one_protocol_frame_process(char *protocol_buffer) {
536541
/* ack automatically when ack attribute set */
537542
_do_ack(protocol_packet);
538543

544+
/* udp frame reset current acked seq -1 */
545+
if (_get_current_acked_seq() != -1 && _is_udp_packet(protocol_packet)) {
546+
_set_current_acked_seq(-1);
547+
}
548+
539549
/* notify application when not ack frame nor duplicate frame */
540550
if (!_is_duplicate_frame(protocol_packet)) {
541551
g_comm_protocol_business.on_recv_frame(&packet);

0 commit comments

Comments
 (0)