bitE is a binary data serializer which uses .dbc -like format to read and write data into uint8_t arrays.
It is primarily used as a helper tool to prevent user from manualy managing bit arrays, especially if there's '.dbc' description available.
It's particularly useful for handling data formats like those used in automotive CAN networks.
For example .dbc variable: SG_ PCS_dcdcHvBusVolt m6: 16|12@1+ (0.146484,0) [0|0] "V" X
may be expressed as: struct bite b_obj = bite_init(u8array, BITE_ORDER_DBC1, 16, 12);
then it may be written or read, using bite_put_u8(struct bite *self, uint8_t data) or bite_get_u8(struct bite *self).
bitE will read 8 or less bits and will increment its internal pointer to the next relevant byte inside u8array.
If there's less than 8 bits available, MSB bits will be masked with zeros.
bitE handles it for you.
.dbc parsing involved. It's up to user to manually express .dbc data, performing bitE calls.
- Initialize the
bitestruct: Usebite_init()to set up abiteobject. You'll need to provide the data buffer, endianness, start bit, and length in bits.
#include "bite.h"
uint8_t my_buffer[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
struct bite my_data;
...
/* Initialize a little-endian bit field starting at bit 12, with a length of 16 bits */
my_data = bite_init(my_buffer, BITE_ORDER_LITTLE_ENDIAN, 12, 16);- Read or Write Data:
Use the provided functions to get or put data of different sizes. The
bitestruct's internal state is automatically updated after each operation, allowing you to chain calls to process consecutive bit fields.
bite_put_u8(struct bite *self, uint8_t data);
bite_get_u8(struct bite *self);
bite_get_i8(struct bite *self);
bite_put_u16(struct bite *self, uint16_t data);
bite_get_u16(struct bite *self);
bite_get_i16(struct bite *self);
bite_put_u32(struct bite *self, uint32_t data);
bite_get_u32(struct bite *self);
bite_get_i32(struct bite *self);
...
/* Write a 16-bit value */
bite_put_u16(&my_data, 0xABCD);
/* Read a 16-bit value */
uint16_t value = bite_get_u16(&my_data);01.06.2026
I plan to eliminate all dangers and enhance functionality by:
- Explicit bound checking
- Creating internal
.dbcvariable database. - Creating simple
.dbcparser which automatically adds variable entries to internal database.
I have found a bug, pointed by fanalyzer. Looks like there are out of bound access during normal tests… Can't confirm yet.