Skip to content

Commit

Permalink
Make m10spg use int32 vectors instead of floats
Browse files Browse the repository at this point in the history
A temporary measure to ensure no floating point math is preventing gps
data from getting through
  • Loading branch information
AngusJull committed Jun 7, 2024
1 parent 40b21eb commit ca2fed7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/collectors/m10spg_clctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ void *m10spg_collector(void *args) {
err = m10spg_send_command(&loc, UBX_NAV_POSLLH, &buf, sizeof(UBXNavPositionPayload));
if (err == EOK) {
msg.type = TAG_COORDS;
msg.data.VEC2D.x = ((float)buf.pos.lat / LAT_SCALE_TO_DEGREES);
msg.data.VEC2D.y = ((float)buf.pos.lon / LON_SCALE_TO_DEGREES);
// Floating point math to conver to degrees
// msg.data.VEC2D.x = (((float)buf.pos.lat) / LAT_SCALE_TO_DEGREES);
// msg.data.VEC2D.y = (((float)buf.pos.lon) / LON_SCALE_TO_DEGREES);
msg.data.VEC2D_I32.x = buf.pos.lat;
msg.data.VEC2D_I32.y = buf.pos.lon;

if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno));
}
msg.type = TAG_ALTITUDE_SEA;
msg.data.FLOAT = ((float)buf.pos.hMSL / ALT_SCALE_TO_METERS);
msg.data.FLOAT = (((float)buf.pos.hMSL) / ALT_SCALE_TO_METERS);
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno));
}
Expand Down
11 changes: 7 additions & 4 deletions src/drivers/sensor_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const SensorTagData SENSOR_TAG_DATA[] = {
.dtype = TYPE_VEC3D,
.has_id = 0},
[TAG_COORDS] = {.name = "Lat/Long",
.unit = "deg",
.fmt_str = "%.2fX, %.2fY",
.dsize = sizeof(vec2d_t),
.dtype = TYPE_VEC2D,
.unit = "0.1udeg",
.fmt_str = "%dX, %dY",
.dsize = sizeof(vec2d_i32_t),
.dtype = TYPE_VEC2D_I32,
.has_id = 0},
[TAG_VOLTAGE] =
{.name = "Voltage", .unit = "mV", .fmt_str = "%d", .dsize = sizeof(int16_t), .dtype = TYPE_I16, .has_id = 1},
Expand Down Expand Up @@ -216,5 +216,8 @@ void sensor_write_data(FILE *stream, const SensorTag tag, const void *data) {
fprintf(stream, format_str, SENSOR_TAG_DATA[tag].name, drefcast(const vec2d_t, data).x,
drefcast(const vec2d_t, data).y, SENSOR_TAG_DATA[tag].unit);
break;
case TYPE_VEC2D_I32:
fprintf(stream, format_str, SENSOR_TAG_DATA[tag].name, drefcast(const vec2d_i32_t, data).x,
drefcast(const vec2d_i32_t, data).y, SENSOR_TAG_DATA[tag].unit);
}
}
28 changes: 19 additions & 9 deletions src/drivers/sensor_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ typedef struct {
float y;
} vec2d_t;

/** Type for a 2 dimensional vector with integer x, y components */
typedef struct {
/** X component */
int32_t x;
/** Y component */
int32_t y;
} vec2d_i32_t;

/** Type for a 3 dimensional vector with x, y, z components. */
typedef struct {
/** X component. */
Expand Down Expand Up @@ -50,15 +58,16 @@ typedef enum {

/** Describes the data type of the data associated with a tag. */
typedef enum {
TYPE_FLOAT, /**< float */
TYPE_U32, /**< uint32_t */
TYPE_U16, /**< uint16_t */
TYPE_U8, /**< uint8_t */
TYPE_I32, /**< int32_t */
TYPE_I16, /**< int16_t */
TYPE_I8, /**< int8_t */
TYPE_VEC3D, /**< vec3d_t */
TYPE_VEC2D, /**< vec2d_t */
TYPE_FLOAT, /**< float */
TYPE_U32, /**< uint32_t */
TYPE_U16, /**< uint16_t */
TYPE_U8, /**< uint8_t */
TYPE_I32, /**< int32_t */
TYPE_I16, /**< int16_t */
TYPE_I8, /**< int8_t */
TYPE_VEC3D, /**< vec3d_t */
TYPE_VEC2D_I32, /**< vec2d_u32 */
TYPE_VEC2D, /**< vec2d_t */
} SensorTagDType;

/** Describes a message that can be sent on a message queue and recognized by both fetcher and packager */
Expand All @@ -73,6 +82,7 @@ typedef struct {
int16_t I16;
int8_t I8;
vec3d_t VEC3D;
vec2d_i32_t VEC2D_I32;
vec2d_t VEC2D;
} data; /**< The way the contents of this struct should be interpreted */
} common_t;
Expand Down

0 comments on commit ca2fed7

Please sign in to comment.