Merge pull request #1194 from atiselsts/rime_chameleon_bit_endian

Fix Rime attribute serialization in chameleon-bitopts for big endian systems
This commit is contained in:
Simon Duquennoy 2015-11-21 00:19:04 +01:00
commit 8369ee3ce5

View File

@ -68,6 +68,27 @@ static const uint8_t bitmask[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0,
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
/* For get_bits/set_bits functions in this file to work correctly,
* the values contained in packetbuf_attr_t variables (uint16_t internally)
* must be in little endian byte order.
*/
/* Write little endian 16 bit value */
static void CC_INLINE
le16_write(void *ptr, uint16_t v)
{
uint8_t *p = (uint8_t *)ptr;
p[0] = v & 0xff;
p[1] = v >> 8;
}
/*---------------------------------------------------------------------------*/
/* Read little endian 16 bit value */
static uint16_t CC_INLINE
le16_read(const void *ptr)
{
const uint8_t *p = (const uint8_t *)ptr;
return ((uint16_t)p[1] << 8) | p[0];
}
/*---------------------------------------------------------------------------*/
uint8_t CC_INLINE
get_bits_in_byte(uint8_t *from, int bitpos, int vallen)
@ -279,10 +300,10 @@ pack_header(struct channel *c)
((uint8_t *)packetbuf_addr(a->type))[0],
((uint8_t *)packetbuf_addr(a->type))[1]);
} else {
packetbuf_attr_t val;
val = packetbuf_attr(a->type);
set_bits(&hdrptr[byteptr], bitptr & 7,
(uint8_t *)&val, len);
uint8_t buffer[2];
packetbuf_attr_t val = packetbuf_attr(a->type);
le16_write(buffer, val);
set_bits(&hdrptr[byteptr], bitptr & 7, buffer, len);
PRINTF("value %d\n",
/*linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],*/
val);
@ -349,9 +370,10 @@ unpack_header(void)
a->type, addr.u8[0], addr.u8[1]);
packetbuf_set_addr(a->type, &addr);
} else {
packetbuf_attr_t val = 0;
get_bits((uint8_t *)&val, &hdrptr[byteptr], bitptr & 7, len);
packetbuf_attr_t val;
uint8_t buffer[2] = {0};
get_bits(buffer, &hdrptr[byteptr], bitptr & 7, len);
val = le16_read(buffer);
packetbuf_set_attr(a->type, val);
PRINTF("%d.%d: unpack_header type %d, val %d\n",
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],