From e0854ae1c949fef8dcba76c74d3256009fe5932a Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Tue, 16 Jul 2019 15:39:30 -0400 Subject: [PATCH] Fixes bad state transition logic to active --- src/main.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index d0783d5..8e4a8af 100644 --- a/src/main.c +++ b/src/main.c @@ -705,6 +705,10 @@ void gpio_init() { } static linkstate_t do_uninit(struct net_buf const *buf) { + if (packet_is_sync(buf)) { + h5_send_sync_response(); + return UNINIT; + } if (packet_is_sync_response(buf)) { h5_send_config(); LOG_DBG("RX'd SYNC RESPONSE: UNINIT -> INIT"); @@ -725,6 +729,12 @@ static linkstate_t do_init(struct net_buf const *buf) { LOG_DBG("Finished H5 configuration, tx_win %u: INIT -> ACTIVE", h5.tx_win); return ACTIVE; } + + if (packet_is_sync(buf)) { + LOG_DBG("RX'd SYNC: INIT -> INIT"); + h5_send_sync_response(); + } + if (packet_is_config(buf)) { LOG_DBG("RX'd CONFIG: INIT -> INIT"); h5_send_config_response(); @@ -735,11 +745,15 @@ static linkstate_t do_init(struct net_buf const *buf) { } static linkstate_t do_active(struct net_buf *buf) { - if (packet_is_sync_response(buf) || packet_is_config(buf)) { + if (packet_is_sync_response(buf)) { LOG_DBG("Bad packet for ACTIVE state: ACTIVE -> UNINIT"); h5_send_sync(); return UNINIT; + } + if (packet_is_sync(buf)){ + LOG_DBG("SYNC in ACTIVE state: ACTIVE -> UNINIT"); + return UNINIT; } if (packet_is_config(buf)) { @@ -772,13 +786,6 @@ void main(void) while (true) { buf = net_buf_get(&h5.host_queue, K_FOREVER); - if (packet_is_sync(buf)) { - LOG_DBG("RX'd SYNC: %d -> UNINIT", h5.link_state); - h5.link_state = UNINIT; - h5_send_sync_response(); - goto next; - } - switch (h5.link_state) { case UNINIT: h5.link_state = do_uninit(buf);