From 69ed42f4910253592b2a827a7b04b658b16fc384 Mon Sep 17 00:00:00 2001 From: wohdo <98126482+wohdo@users.noreply.github.com> Date: Thu, 27 Jan 2022 06:28:18 +0100 Subject: [PATCH] [coap] add 'otCoapMessageSetCode' (#7339) (#7351) Provide a setter for the message code to change it after initialization of the message. This complements the existing getter function `otCoapMessageGetCode`. --- include/openthread/coap.h | 9 +++++++++ include/openthread/instance.h | 2 +- src/core/api/coap_api.cpp | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/openthread/coap.h b/include/openthread/coap.h index 7e2312040..396d53573 100644 --- a/include/openthread/coap.h +++ b/include/openthread/coap.h @@ -717,6 +717,15 @@ otCoapType otCoapMessageGetType(const otMessage *aMessage); */ otCoapCode otCoapMessageGetCode(const otMessage *aMessage); +/** + * This function sets the Code value. + * + * @param[inout] aMessage A pointer to the CoAP message to initialize. + * @param[in] aCode CoAP message code. + * + */ +void otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode); + /** * This method returns the CoAP Code as human readable string. * diff --git a/include/openthread/instance.h b/include/openthread/instance.h index e06b7754e..699941c5d 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (186) +#define OPENTHREAD_API_VERSION (187) /** * @addtogroup api-instance diff --git a/src/core/api/coap_api.cpp b/src/core/api/coap_api.cpp index 48353678e..4dfb35edf 100644 --- a/src/core/api/coap_api.cpp +++ b/src/core/api/coap_api.cpp @@ -144,6 +144,11 @@ otCoapCode otCoapMessageGetCode(const otMessage *aMessage) return static_cast(AsCoapMessage(aMessage).GetCode()); } +void otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode) +{ + AsCoapMessage(aMessage).SetCode(MapEnum(aCode)); +} + const char *otCoapMessageCodeToString(const otMessage *aMessage) { return AsCoapMessage(aMessage).CodeToString();