From 262cea11f1168afb3fe5320db07e421c106b73fe Mon Sep 17 00:00:00 2001 From: "carlosgp143@gmail.com" Date: Wed, 23 May 2018 15:59:43 +0200 Subject: [PATCH 1/2] Implemented instant feedback in CoAp_send_request --- os/net/app-layer/coap/coap-callback-api.c | 8 +++++--- os/net/app-layer/coap/coap-callback-api.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/os/net/app-layer/coap/coap-callback-api.c b/os/net/app-layer/coap/coap-callback-api.c index b1b05597e..0f0ab2c99 100644 --- a/os/net/app-layer/coap/coap-callback-api.c +++ b/os/net/app-layer/coap/coap-callback-api.c @@ -65,7 +65,7 @@ static void coap_request_callback(void *callback_data, coap_message_t *response) /*---------------------------------------------------------------------------*/ -static void +static int progress_request(coap_request_state_t *state) { coap_message_t *request = state->request; request->mid = coap_get_mid(); @@ -83,7 +83,9 @@ progress_request(coap_request_state_t *state) { coap_send_transaction(state->transaction); LOG_DBG("Requested #%"PRIu32" (MID %u)\n", state->block_num, request->mid); + return 1; } + return 0; } /*---------------------------------------------------------------------------*/ @@ -134,7 +136,7 @@ coap_request_callback(void *callback_data, coap_message_t *response) /*---------------------------------------------------------------------------*/ -void +int coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, coap_message_t *request, void (*callback)(coap_request_state_t *state)) @@ -151,7 +153,7 @@ coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, state->remote_endpoint = endpoint; state->callback = callback; - progress_request(state); + return progress_request(state); } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/app-layer/coap/coap-callback-api.h b/os/net/app-layer/coap/coap-callback-api.h index 6de7ab587..7f144af96 100644 --- a/os/net/app-layer/coap/coap-callback-api.h +++ b/os/net/app-layer/coap/coap-callback-api.h @@ -65,7 +65,7 @@ struct coap_request_state { void (*callback)(coap_request_state_t *state); }; -void coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, +int coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, coap_message_t *request, void (*callback)(coap_request_state_t *state)); From b50d143966d89895117dd67974833b76f56d3758 Mon Sep 17 00:00:00 2001 From: "carlosgp143@gmail.com" Date: Thu, 24 May 2018 08:53:33 +0200 Subject: [PATCH 2/2] Added doxygen annotation to the prototype --- os/net/app-layer/coap/coap-callback-api.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/os/net/app-layer/coap/coap-callback-api.h b/os/net/app-layer/coap/coap-callback-api.h index 7f144af96..69ceea4f5 100644 --- a/os/net/app-layer/coap/coap-callback-api.h +++ b/os/net/app-layer/coap/coap-callback-api.h @@ -65,6 +65,14 @@ struct coap_request_state { void (*callback)(coap_request_state_t *state); }; +/** + * \brief Send a CoAP request to a remote endpoint + * \param state The state to handle the CoAP request + * \param endpoint The destination endpoint + * \param request The request to be sent + * \param callback callback to execute when the response arrives or the timeout expires + * \return 1 if there is a transaction available to send, 0 otherwise + */ int coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, coap_message_t *request, void (*callback)(coap_request_state_t *state));