Skip to content

Commit

Permalink
Merge pull request #9 from junlon2006/hotfix/issue5
Browse files Browse the repository at this point in the history
fix issue 5 in v2
  • Loading branch information
junlon2006 authored Aug 13, 2020
2 parents 54e0ae0 + 095a8c1 commit 6ddc090
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/uni_communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6ddc090

Please sign in to comment.