52 int main(
int argc,
char *argv[]) {
56 char *usage =
"Usage: %1$s [-v] [-q] port\n"
57 "\t-v\tIncrease verbosity\n"
58 "\t-q\tDecrease verbosity\n"
64 while ((go = getopt(argc, argv,
"vq")) != -1) {
73 log_error(&state,
"Unknown option `-%c'", optopt);
79 if (argc - optind != 1) {
85 fprintf(stderr, usage, argv[0]);
92 bool processing =
true;
111 while (processing || hw > 10) {
114 perror(
"lpms_message calloc");
123 ((uint32_t)m->
data[2] << 16) +
124 ((uint32_t)m->
data[3] << 24);
125 log_info(&state, 2,
"%02x: Output configuration received", m->
id);
127 log_info(&state, 2,
"%02x: Sensor model: %-24s", m->
id,
130 log_info(&state, 2,
"%02x: Serial number: %-24s", m->
id,
133 log_info(&state, 2,
"%02x: Firmware version: %-24s", m->
id,
137 log_info(&state, 1,
"%02x: Timestamp: %u", m->
id,
144 "%02x: Raw Acceleration: (%+.4f, %+.4f, %+4.f)",
151 "%02x: Calibrated Acceleration: (%+.4f, %+.4f, %+4.f)",
157 "%02x: Raw Gyro: (%+.4f, %+.4f, %+4.f)", m->
id,
162 "%02x: Calibrated Gyro: (%+.4f, %+.4f, %+4.f)",
168 "%02x: Aligned Gyro: (%+.4f, %+.4f, %+4.f)",
174 "%02x: Raw Magnetic Field: (%+.4f, %+.4f, %+4.f)",
180 "%02x: Calibrated Magnetic Field: (%+.4f, %+.4f, %+4.f)",
185 "%02x: Euler roll angles: (%+.4f, %+.4f, %+.4f)",
190 log_info(&state, 1,
"%02x: Pressure: %.2f", m->
id,
194 log_info(&state, 1,
"%02x: Altitude: %.2f", m->
id,
198 log_info(&state, 1,
"%02x: Temperature: %.2f", m->
id,
202 log_info(&state, 1,
"%02x: Command %02x, %u bytes, checksum %s",
208 log_info(&state, 1,
"%02x: [Error] - Command %02x, %u bytes",
211 if (m->
id == 0xAA || m->
id == 0xEE) {
213 "Error reading messages from file (Code: 0x%02x)\n",
219 if (end < hw) { end++; }
229 log_info(&state, 0,
"%d messages successfully read from file", count);
bool lpms_readMessage_buf(int handle, lpms_message *out, uint8_t buf[LPMS_BUFF], size_t *index, size_t *hw)
Read data from handle, and parse message if able.
bool lpms_send_command(const int handle, lpms_message *m)
Write command defined by structure to handle.
int lpms_openConnection(const char *device, const int baud)
Open connection to an LPMS serial device.
bool lpms_send_stream_mode(const int handle)
Shortcut: Send LPMS_MSG_MODE_STREAM.
bool lpms_send_command_mode(const int handle)
Shortcut: Send LPMS_MSG_MODE_CMD.
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.
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.
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_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.
int main(int argc, char *argv[])
#define BUFSIZE
Allocated read buffer size.
#define LPMS_MSG_GET_OUTPUTS
Get fields configured for IMUDATA messages.
#define LPMS_MSG_GET_SERIALNUM
Get serial number as 24 character string.
#define LPMS_MSG_GET_IMUDATA
IMU data, as configured by LPMS_MSG_SET_OUTPUTS.
#define LPMS_MSG_GET_FIRMWAREVER
Get firmware version as 24 character string.
#define LPMS_MSG_GET_SENSORMODEL
Get hardware model as 24 character string.
void log_info(const program_state *s, const int level, const char *format,...)
Output formatted information message at a given level.
void log_warning(const program_state *s, const char *format,...)
Output formatted warning message.
void log_error(const program_state *s, const char *format,...)
Output formatted error message.
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].
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 accel_raw[3]
Raw accelerometer values [g].
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.
Program state and logging information.
int verbose
Current log verbosity (console output)
bool started
Indicates startup completed.
#define GIT_VERSION_STRING
Git version description.