mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
gcoap: Separate out observe option generation in own function
This commit is contained in:
parent
6425fda812
commit
a6a8f6e1cd
@ -1630,6 +1630,14 @@ ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len,
|
||||
return ((res > 0 || res == -ENOTCONN) ? res : 0);
|
||||
}
|
||||
|
||||
static void _add_generated_observe_option(coap_pkt_t *pdu)
|
||||
{
|
||||
/* generate initial notification value */
|
||||
uint32_t now = ztimer_now(ZTIMER_MSEC);
|
||||
pdu->observe_value = (now >> GCOAP_OBS_TICK_EXPONENT) & 0xFFFFFF;
|
||||
coap_opt_add_uint(pdu, COAP_OPT_OBSERVE, pdu->observe_value);
|
||||
}
|
||||
|
||||
int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
|
||||
{
|
||||
int header_len = coap_build_reply(pdu, code, buf, len, 0);
|
||||
@ -1644,10 +1652,7 @@ int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
|
||||
pdu->payload_len = len - header_len;
|
||||
|
||||
if (coap_get_observe(pdu) == COAP_OBS_REGISTER) {
|
||||
/* generate initial notification value */
|
||||
uint32_t now = ztimer_now(ZTIMER_MSEC);
|
||||
pdu->observe_value = (now >> GCOAP_OBS_TICK_EXPONENT) & 0xFFFFFF;
|
||||
coap_opt_add_uint(pdu, COAP_OPT_OBSERVE, pdu->observe_value);
|
||||
_add_generated_observe_option(pdu);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1672,9 +1677,7 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
if (hdrlen > 0) {
|
||||
coap_pkt_init(pdu, buf, len, hdrlen);
|
||||
|
||||
uint32_t now = ztimer_now(ZTIMER_MSEC);
|
||||
pdu->observe_value = (now >> GCOAP_OBS_TICK_EXPONENT) & 0xFFFFFF;
|
||||
coap_opt_add_uint(pdu, COAP_OPT_OBSERVE, pdu->observe_value);
|
||||
_add_generated_observe_option(pdu);
|
||||
|
||||
return GCOAP_OBS_INIT_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user