net: buf: Add net_buf_add_le32() helper API

The function gets 32bits wide data, converts host order to little
endian and then puts the data on protocol stack to be send.

Change-Id: I29e4040b302a16b551a0922133c327ff694fec5d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-05-06 08:59:53 +02:00 committed by Johan Hedberg
parent 3a66946b0f
commit fcb6e03021
2 changed files with 21 additions and 0 deletions

View file

@ -204,6 +204,19 @@ uint8_t *net_buf_add_u8(struct net_buf *buf, uint8_t value);
*/
void net_buf_add_le16(struct net_buf *buf, uint16_t value);
/** @brief Add 32-bit value at the end of the buffer
*
* Adds 32-bit value in little endian format at the end of buffer.
* Increments the data length of a buffer to account for more data
* at the end.
*
* @param buf Buffer to update.
* @param value 32-bit value to be added.
*
* @return void
*/
void net_buf_add_le32(struct net_buf *buf, uint32_t value);
/** @brief Push data to the beginning of the buffer.
*
* Modifies the data pointer and buffer length to account for more data

View file

@ -139,6 +139,14 @@ void net_buf_add_le16(struct net_buf *buf, uint16_t value)
memcpy(net_buf_add(buf, sizeof(value)), &value, sizeof(value));
}
void net_buf_add_le32(struct net_buf *buf, uint32_t value)
{
NET_BUF_DBG("buf %p value %u\n", buf, value);
value = sys_cpu_to_le32(value);
memcpy(net_buf_add(buf, sizeof(value)), &value, sizeof(value));
}
void *net_buf_push(struct net_buf *buf, size_t len)
{
NET_BUF_DBG("buf %p len %u\n", buf, len);