From 3d99d81c9a256eca9c565aa97bcf053f23fc3791 Mon Sep 17 00:00:00 2001 From: Nenad Kljajic Date: Wed, 12 Apr 2023 14:50:45 +0200 Subject: [PATCH] Recover from unexpected FUNC_ID_SERIAL_API_STARTED Fix TX process stuck waiting for callback if transmission ongoing Abort Add/Remove if in progress Fix zwapi send data abort after emerency timeout --- .../zpc/components/zwave/zwave_rx/CMakeLists.txt | 5 ++++- .../zwave/zwave_rx/src/zwave_rx_zwapi_callbacks.c | 11 +++++++++++ .../zwave_api_transport/src/zwave_api_transport.c | 1 + .../zwave_api/src/zwapi_protocol_rx_dispatch.c | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/applications/zpc/components/zwave/zwave_rx/CMakeLists.txt b/applications/zpc/components/zwave/zwave_rx/CMakeLists.txt index ff9153be86..453d214237 100644 --- a/applications/zpc/components/zwave/zwave_rx/CMakeLists.txt +++ b/applications/zpc/components/zwave/zwave_rx/CMakeLists.txt @@ -9,11 +9,14 @@ ENDIF() # Library add_library(zwave_rx ${SOURCE_LIST} src/zwave_rx_zwapi_callbacks.c) -target_include_directories(zwave_rx PUBLIC include) +target_include_directories(zwave_rx PUBLIC include + PRIVATE ../zwave_transports/zwave_api_transport/include +) target_link_libraries(zwave_rx PRIVATE zwave_controller zwave_definitions + zwave_api_transport unify) IF(NOT ZWAVE_BUILD_SYSTEM EQUAL 1) diff --git a/applications/zpc/components/zwave/zwave_rx/src/zwave_rx_zwapi_callbacks.c b/applications/zpc/components/zwave/zwave_rx/src/zwave_rx_zwapi_callbacks.c index 3300047001..2d4c95c85d 100644 --- a/applications/zpc/components/zwave/zwave_rx/src/zwave_rx_zwapi_callbacks.c +++ b/applications/zpc/components/zwave/zwave_rx/src/zwave_rx_zwapi_callbacks.c @@ -25,6 +25,10 @@ // Includes from other components #include "zwapi_protocol_controller.h" #include "zwapi_protocol_mem.h" +#include "zwave_api_transport.h" +#include "sl_log.h" + +#define LOG_TAG "zwave_rx_zwapi_callbacks" // Static helper function static void @@ -157,6 +161,7 @@ void zwave_rx_zwave_api_started(const uint8_t *buffer, uint8_t buffer_length) { (void)buffer; (void)buffer_length; + zwave_api_transport_reset(); // Make sure we are still running the right settings: zwapi_set_node_id_basetype(NODEID_16BITS); @@ -166,6 +171,12 @@ void zwave_rx_zwave_api_started(const uint8_t *buffer, uint8_t buffer_length) zwapi_set_learn_mode(LEARN_MODE_DISABLE, NULL); // I can't think of a reason to do something with our NIF here. (buffer, buffer_length) + zwave_network_management_state_t nms_state = zwave_network_management_get_state(); + if (nms_state != NM_IDLE) { + sl_log_warning(LOG_TAG, + "Network management is busy.\n"); + zwave_network_management_abort(); + } } /** diff --git a/applications/zpc/components/zwave/zwave_transports/zwave_api_transport/src/zwave_api_transport.c b/applications/zpc/components/zwave/zwave_transports/zwave_api_transport/src/zwave_api_transport.c index 973c31de95..7096504dc8 100644 --- a/applications/zpc/components/zwave/zwave_transports/zwave_api_transport/src/zwave_api_transport.c +++ b/applications/zpc/components/zwave/zwave_transports/zwave_api_transport/src/zwave_api_transport.c @@ -97,6 +97,7 @@ static void zwave_api_transport_emergency_timeout_step() // Use the Z-Wave API to abort. zwapi_abort_send_data(); + zwave_api_send_data_callback(TRANSMIT_COMPLETE_FAIL, NULL); } // Intercepting Protocol specific commands diff --git a/applications/zpc/components/zwave_api/src/zwapi_protocol_rx_dispatch.c b/applications/zpc/components/zwave_api/src/zwapi_protocol_rx_dispatch.c index d36a433894..aac7487624 100644 --- a/applications/zpc/components/zwave_api/src/zwapi_protocol_rx_dispatch.c +++ b/applications/zpc/components/zwave_api/src/zwapi_protocol_rx_dispatch.c @@ -630,6 +630,7 @@ void zwave_api_protocol_rx_dispatch(uint8_t *pData, uint16_t len) break; case FUNC_ID_SERIAL_API_STARTED: + sl_log_warning(LOG_TAG, "SERIAL API STARTED\n"); /* ZW->HOST: bWakeupReason | bWatchdogStarted | deviceOptionMask | */ /* node_type.generic | node_type.specific | cmdClassLength | cmdClass[] */ zwapi_set_awaiting_zwave_api_started(false);