Skip to content
Snippets Groups Projects
Commit faab0066 authored by Hauke Petersen's avatar Hauke Petersen
Browse files

net/rdcli_simple: improved doc and error handling

parent 8320c797
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2017 Freie Universität Berlin
* Copyright (C) 2017-2018 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
......@@ -26,9 +26,21 @@
extern "C" {
#endif
/**
* @brief Error codes used by the rdcli_simple implementation
*/
enum {
RDCLI_SIMPLE_OK = 0, /**< all ok */
RDCLI_SIMPLE_ERR = -1, /**< return for formatting and network errors */
};
/**
* @brief Initiate the node registration by sending an empty CoAP POST message
* to the RD server's /.well-known/core resource
*
* @return RDCLI_SIMPLE_OK on success
* @return RDCLI_ERROR if something goes wrong preparing or sending the
* initial request
*/
int rdcli_simple_register(void);
......
......@@ -42,19 +42,21 @@ static const sock_udp_ep_t remote = {
int rdcli_simple_register(void)
{
/* build the initial CON packet */
int res = gcoap_req_init(&pkt, buf, sizeof(buf), COAP_METHOD_POST,
"/.well-known/core");
if (res < 0) {
return res;
if (gcoap_req_init(&pkt, buf, sizeof(buf), COAP_METHOD_POST,
"/.well-known/core") < 0) {
return RDCLI_SIMPLE_ERR;
}
/* make packet confirmable */
coap_hdr_set_type(pkt.hdr, COAP_TYPE_CON);
/* add Uri-Query options */
res = rdcli_common_add_qstring(&pkt);
if (res < 0) {
return res;
if (rdcli_common_add_qstring(&pkt) < 0) {
return RDCLI_SIMPLE_ERR;
}
/* finish, we don't have any payload */
ssize_t len = gcoap_finish(&pkt, 0, COAP_FORMAT_LINK);
return (int)gcoap_req_send2(buf, len, &remote, NULL);
if (gcoap_req_send2(buf, len, &remote, NULL) == 0) {
return RDCLI_SIMPLE_ERR;
}
return RDCLI_SIMPLE_OK;
}
......@@ -38,8 +38,7 @@ static void *reg_runner(void *arg)
xtimer_sleep(RDCLI_STARTUP_DELAY);
while (1) {
int res = rdcli_simple_register();
if (res < 0) {
if (rdcli_simple_register() != RDCLI_SIMPLE_OK) {
LOG_ERROR("[rdcli_simple] error: unable to trigger registration\n");
}
xtimer_sleep(RDCLI_UPDATE_INTERVAL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment