mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
net/nanocoap: refactor block option control use
This commit is contained in:
parent
4311f17e81
commit
9dce54b54b
@ -811,6 +811,52 @@ static inline size_t coap_opt_put_block2(uint8_t *buf, uint16_t lastonum,
|
||||
return coap_opt_put_block(buf, lastonum, slicer, more, COAP_OPT_BLOCK2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert block option into buffer from block struct
|
||||
*
|
||||
* @param[in] buf buffer to write to
|
||||
* @param[in] lastonum last option number (must be < @p option)
|
||||
* @param[in] block block option attribute struct
|
||||
* @param[in] option option number (block1 or block2)
|
||||
*
|
||||
* @returns amount of bytes written to @p buf
|
||||
*/
|
||||
size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum,
|
||||
coap_block1_t *block, uint16_t option);
|
||||
|
||||
/**
|
||||
* @brief Insert block1 option into buffer in control usage
|
||||
*
|
||||
* @param[in] buf buffer to write to
|
||||
* @param[in] lastonum last option number (must be < 27)
|
||||
* @param[in] block block option attribute struct
|
||||
*
|
||||
* @returns amount of bytes written to @p buf
|
||||
*/
|
||||
static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum,
|
||||
coap_block1_t *block)
|
||||
{
|
||||
return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert block2 option into buffer in control usage
|
||||
*
|
||||
* Forces value of block 'more' attribute to zero, per spec.
|
||||
*
|
||||
* @param[in] buf buffer to write to
|
||||
* @param[in] lastonum last option number (must be < 27)
|
||||
* @param[in] block block option attribute struct
|
||||
*
|
||||
* @returns amount of bytes written to @p buf
|
||||
*/
|
||||
static inline size_t coap_opt_put_block2_control(uint8_t *buf, uint16_t lastonum,
|
||||
coap_block1_t *block)
|
||||
{
|
||||
block->more = 0;
|
||||
return coap_opt_put_block_object(buf, lastonum, block, COAP_OPT_BLOCK2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode the given string as multi-part option into buffer
|
||||
*
|
||||
|
@ -720,6 +720,15 @@ size_t coap_opt_put_block(uint8_t *buf, uint16_t lastonum, coap_block_slicer_t *
|
||||
return coap_put_option(buf, lastonum, option, (uint8_t *)&blkopt, olen);
|
||||
}
|
||||
|
||||
size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum,
|
||||
coap_block1_t *block, uint16_t option)
|
||||
{
|
||||
uint32_t blkopt = (block->blknum << 4) | block->szx | (block->more ? 0x8 : 0);
|
||||
size_t olen = _encode_uint(&blkopt);
|
||||
|
||||
return coap_put_option(buf, lastonum, option, (uint8_t *)&blkopt, olen);
|
||||
}
|
||||
|
||||
size_t coap_opt_put_string(uint8_t *buf, uint16_t lastonum, uint16_t optnum,
|
||||
const char *string, char separator)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user