43 if (in == NULL || msg == NULL || len < 10 || pos == NULL) {
return NULL; }
46 while (((*pos) + 10) < len) {
60 msg->
id = in[start + 1] + ((uint16_t)in[start + 2] << 8);
61 msg->
command = in[start + 3] + ((uint16_t)in[start + 4] << 8);
62 msg->
length = in[start + 5] + ((uint16_t)in[start + 6] << 8);
69 if ((len - start - 10) < msg->
length) {
73 msg->
data = calloc(msg->
length,
sizeof(uint8_t));
74 if (msg->
data == NULL) {
80 for (
int i = 0; i < msg->
length; i++) {
81 msg->
data[i] = in[(*pos)++];
84 msg->
checksum = in[(*pos)] + ((uint16_t)in[(*pos) + 1] << 8);
105 if ((msg == NULL) || (out == NULL)) {
return false; }
106 (*len) = msg->
length + 11;
107 (*out) = calloc((*len),
sizeof(uint8_t));
108 if ((*out) == NULL) {
109 perror(
"lpms_to_bytes");
113 (*out)[1] = (msg->
id & 0x00FF);
114 (*out)[2] = (msg->
id & 0xFF00) >> 8;
115 (*out)[3] = (msg->
command & 0x00FF);
116 (*out)[4] = (msg->
command & 0xFF00) >> 8;
117 (*out)[5] = (msg->
length & 0x00FF);
118 (*out)[6] = (msg->
length & 0xFF00) >> 8;
120 for (
int j = 0; j < msg->
length; j++) {
121 (*out)[p++] = msg->
data[j];
123 (*out)[p++] = (msg->
checksum & 0x00FF);
124 (*out)[p++] = (msg->
checksum & 0xFF00) >> 8;
127 return (p == (*len));
136 if (msg == NULL || csum == NULL) {
return false; }
138 cs += (msg->
id & 0x00FF);
139 cs += (msg->
id & 0xFF00) >> 8;
141 cs += (msg->
command & 0xFF00) >> 8;
142 cs += (msg->
length & 0x00FF);
143 cs += (msg->
length & 0xFF00) >> 8;
145 if (msg->
data == NULL) {
return false; }
146 for (
int i = 0; i < msg->
length; ++i) {
163 if (msg->
length < 4) {
return false; }
166 ((uint32_t)msg->
data[3] << 24);
201 if (msg->
length < (ix + 12)) {
return false; }
222 if (msg->
length < (ix + 12)) {
return false; }
244 if (msg->
length < (ix + 12)) {
return false; }
267 if (msg->
length < (ix + 12)) {
return false; }
291 if (msg->
length < (ix + 12)) {
return false; }
316 if (msg->
length < (ix + 12)) {
return false; }
342 if (msg->
length < (ix + 12)) {
return false; }
369 if (msg->
length < (ix + 16)) {
return false; }
397 if (msg->
length < (ix + 12)) {
return false; }
426 if (msg->
length < (ix + 12)) {
return false; }
456 if (msg->
length < (ix + 4)) {
return false; }
487 if (msg->
length < (ix + 4)) {
return false; }
519 if (msg->
length < (ix + 4)) {
return false; }
bool lpms_imu_set_temperature(const lpms_message *msg, lpms_data *d)
Extract temperature from lpms_message into lpms_data, if available.
bool lpms_checksum(const lpms_message *msg, uint16_t *csum)
Calculate checksum for LPMS message packet.
bool lpms_imu_set_gyro_aligned(const lpms_message *msg, lpms_data *d)
Extract gyro_aligned from lpms_message into lpms_data, if available.
#define LPMS_START
Message prefix byte.
bool lpms_imu_set_mag_cal(const lpms_message *msg, lpms_data *d)
Extract mag_cal from lpms_message into lpms_data, if available.
bool lpms_imu_set_altitude(const lpms_message *msg, lpms_data *d)
Extract altitude from lpms_message into lpms_data, if available.
bool lpms_imu_set_euler_angles(const lpms_message *msg, lpms_data *d)
Extract euler_angles from lpms_message into lpms_data, if available.
#define LPMS_END2
Second message suffix byte.
bool lpms_to_bytes(const lpms_message *msg, uint8_t **out, size_t *len)
Convert message structure to flat array.
bool lpms_imu_set_gyro_raw(const lpms_message *msg, lpms_data *d)
Extract gyro_raw from lpms_message into lpms_data, if available.
bool lpms_imu_set_quaternion(const lpms_message *msg, lpms_data *d)
Extract quaternion from lpms_message into lpms_data, if available.
#define LPMS_END1
First message suffix byte.
bool lpms_imu_set_accel_raw(const lpms_message *msg, lpms_data *d)
Extract accel_raw from lpms_message into lpms_data, if available.
bool lpms_imu_set_timestamp(const lpms_message *msg, lpms_data *d)
Extract timestamp from lpms_message into lpms_data, if available.
bool lpms_imu_set_accel_cal(const lpms_message *msg, lpms_data *d)
Extract accel_cal from lpms_message into lpms_data, if available.
bool lpms_imu_set_pressure(const lpms_message *msg, lpms_data *d)
Extract pressure from lpms_message into lpms_data, if available.
bool lpms_imu_set_mag_raw(const lpms_message *msg, lpms_data *d)
Extract mag_raw from lpms_message into lpms_data, if available.
bool lpms_imu_set_gyro_cal(const lpms_message *msg, lpms_data *d)
Extract gyro_cal from lpms_message into lpms_data, if available.
bool lpms_from_bytes(const uint8_t *in, const size_t len, lpms_message *msg, size_t *pos)
Read bytes and populate message structure.
bool lpms_imu_set_accel_linear(const lpms_message *msg, lpms_data *d)
Extract accel_linear from lpms_message into lpms_data, if available.
bool lpms_imu_set_omega(const lpms_message *msg, lpms_data *d)
Extract omega from lpms_message into lpms_data, if available.
#define LPMS_IMU_MAG_RAW
mag_raw[] will contain data
#define LPMS_IMU_EULER
euler[] will contain data
#define LPMS_IMU_ACCEL_LINEAR
accel_linear[] will contain data
#define LPMS_IMU_OMEGA
omega[] will contain data
#define LPMS_IMU_ACCEL_CAL
accel_cal[] will contain data
#define LPMS_IMU_PRESSURE
pressure will contain data
#define LPMS_IMU_QUATERNION
quaternion[] will contain data
#define LPMS_IMU_MAG_CAL
mag_cal[] will contain data
#define LPMS_IMU_GYRO_ALIGN
gyro_align[] will contain data
#define LPMS_IMU_TEMPERATURE
temperature will contain data
#define LPMS_IMU_ALTITUDE
altitude will contain data
#define LPMS_IMU_GYRO_CAL
gyro_cal[] will contain data
#define LPMS_IMU_GYRO_RAW
gyro_raw[] will contain data
#define LPMS_IMU_ACCEL_RAW
accel_raw[] will contain data
#define LPMS_MSG_GET_IMUDATA
IMU data, as configured by LPMS_MSG_SET_OUTPUTS.
float euler_angles[3]
Orientation as Euler roll angles [X].
float altitude
Altitude [m].
float temperature
Temperature [Celsius].
float gyro_aligned[3]
Calibrated and aligned gyroscope values [X/s].
float mag_cal[3]
Calibrated magnetometer values [uT].
float gyro_raw[3]
Raw gyroscope values [X/s].
float accel_linear[3]
Linear acceleration (only) [g].
uint32_t timestamp
Counted in 0.002s increments.
float accel_cal[3]
Calibrated accelerometer values [g].
float gyro_cal[3]
Calibrated gyroscope values [X/s].
float mag_raw[3]
Raw magnetometer values [uT].
float quaternion[4]
Orientation in quaternion form.
float accel_raw[3]
Raw accelerometer values [g].
float omega[3]
Angular velocity [X/s].
uint32_t present
Bitmask indicating set/valid members.
float pressure
Atmospheric pressure [kPa].
uint16_t length
Length of data, in bytes.
uint16_t checksum
Sum of all preceding message bytes.
uint8_t * data
Pointer to data array.
uint16_t id
Source/Destination Sensor ID.
uint16_t command
Message type.