Skip to content

Commit

Permalink
net/nanocoap: use coap_opt_add_uint() and remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
kb2ma committed Feb 24, 2019
1 parent c02872f commit 1420c8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
21 changes: 16 additions & 5 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,8 @@ size_t coap_opt_put_block_object(uint8_t *buf, uint16_t lastonum,
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);
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1,
(block->blknum << 4) | block->szx | (block->more ? 0x8 : 0));
}

/**
Expand All @@ -991,8 +992,9 @@ static inline size_t coap_opt_put_block1_control(uint8_t *buf, uint16_t lastonum
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);
/* block.more must be zero, so no need to 'or' it in */
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK2,
(block->blknum << 4) | block->szx);
}

/**
Expand Down Expand Up @@ -1127,7 +1129,12 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
*
* @returns amount of bytes written to @p buf
*/
size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more);
static inline size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum,
unsigned blknum, unsigned szx, int more)
{
return coap_opt_put_uint(buf, lastonum, COAP_OPT_BLOCK1,
(blknum << 4) | szx | (more ? 0x8 : 0));
}

/**
* @brief Insert content type option into buffer
Expand All @@ -1139,7 +1146,11 @@ size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum,
*
* @returns amount of bytes written to @p buf
*/
size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type);
static inline size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum,
uint16_t content_type)
{
return coap_opt_put_uint(buf, lastonum, COAP_OPT_CONTENT_FORMAT, content_type);
}
/**@}*/


Expand Down
27 changes: 0 additions & 27 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,6 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
return (size_t)n;
}

size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type)
{
if (content_type == 0) {
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, NULL, 0);
}
else if (content_type <= 255) {
uint8_t tmp = content_type;
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, &tmp, sizeof(tmp));
}
else {
return coap_put_option(buf, lastonum, COAP_OPT_CONTENT_FORMAT, (uint8_t *)&content_type, sizeof(content_type));
}
}

static unsigned _size2szx(size_t size)
{
unsigned szx = 0;
Expand Down Expand Up @@ -612,19 +598,6 @@ static unsigned _slicer_blknum(coap_block_slicer_t *slicer)
return blknum;
}

static size_t coap_put_option_block(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more, uint16_t option)
{
uint32_t blkopt = (blknum << 4) | szx | (more ? 0x8 : 0);
size_t olen = _encode_uint(&blkopt);

return coap_put_option(buf, lastonum, option, (uint8_t *)&blkopt, olen);
}

size_t coap_put_option_block1(uint8_t *buf, uint16_t lastonum, unsigned blknum, unsigned szx, int more)
{
return coap_put_option_block(buf, lastonum, blknum, szx, more, COAP_OPT_BLOCK1);
}

int coap_get_block1(coap_pkt_t *pkt, coap_block1_t *block1)
{
uint32_t blknum;
Expand Down

0 comments on commit 1420c8e

Please sign in to comment.