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:
commit
8369ee3ce5
|
@ -68,6 +68,27 @@ static const uint8_t bitmask[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0,
|
||||||
#define PRINTF(...)
|
#define PRINTF(...)
|
||||||
#endif
|
#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
|
uint8_t CC_INLINE
|
||||||
get_bits_in_byte(uint8_t *from, int bitpos, int vallen)
|
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))[0],
|
||||||
((uint8_t *)packetbuf_addr(a->type))[1]);
|
((uint8_t *)packetbuf_addr(a->type))[1]);
|
||||||
} else {
|
} else {
|
||||||
packetbuf_attr_t val;
|
uint8_t buffer[2];
|
||||||
val = packetbuf_attr(a->type);
|
packetbuf_attr_t val = packetbuf_attr(a->type);
|
||||||
set_bits(&hdrptr[byteptr], bitptr & 7,
|
le16_write(buffer, val);
|
||||||
(uint8_t *)&val, len);
|
set_bits(&hdrptr[byteptr], bitptr & 7, buffer, len);
|
||||||
PRINTF("value %d\n",
|
PRINTF("value %d\n",
|
||||||
/*linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],*/
|
/*linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],*/
|
||||||
val);
|
val);
|
||||||
|
@ -349,9 +370,10 @@ unpack_header(void)
|
||||||
a->type, addr.u8[0], addr.u8[1]);
|
a->type, addr.u8[0], addr.u8[1]);
|
||||||
packetbuf_set_addr(a->type, &addr);
|
packetbuf_set_addr(a->type, &addr);
|
||||||
} else {
|
} else {
|
||||||
packetbuf_attr_t val = 0;
|
packetbuf_attr_t val;
|
||||||
get_bits((uint8_t *)&val, &hdrptr[byteptr], bitptr & 7, len);
|
uint8_t buffer[2] = {0};
|
||||||
|
get_bits(buffer, &hdrptr[byteptr], bitptr & 7, len);
|
||||||
|
val = le16_read(buffer);
|
||||||
packetbuf_set_attr(a->type, val);
|
packetbuf_set_attr(a->type, val);
|
||||||
PRINTF("%d.%d: unpack_header type %d, val %d\n",
|
PRINTF("%d.%d: unpack_header type %d, val %d\n",
|
||||||
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
|
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
|
||||||
|
|
Loading…
Reference in a new issue