From 2f855fcd5fea89f0857ab03f286b5da96c81ec1f Mon Sep 17 00:00:00 2001 From: AngusJull Date: Sat, 1 Jun 2024 23:14:20 -0400 Subject: [PATCH] Cast M10SPG altitude to float --- src/collectors/m10spg_clctr.c | 3 ++- src/drivers/m10spg/ubx_def.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/collectors/m10spg_clctr.c b/src/collectors/m10spg_clctr.c index d355e5b..862ae33 100644 --- a/src/collectors/m10spg_clctr.c +++ b/src/collectors/m10spg_clctr.c @@ -16,6 +16,7 @@ typedef struct { int32_t I32; /**< The message payload, interpreted as a int32_t */ uint8_t U8; /**< The message payload, interpreted as a uint8_t */ vec2d_t VEC2D; /**< The message payload, interpreted as a vec2d_t */ + float FLOAT; /**< The message payload, interpreted as a float */ }; } __attribute__((packed)) message_t; @@ -76,7 +77,7 @@ void *m10spg_collector(void *args) { fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); } msg.type = TAG_ALTITUDE_SEA; - msg.I32 = buf.pos.hMSL; + msg.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)); } diff --git a/src/drivers/m10spg/ubx_def.h b/src/drivers/m10spg/ubx_def.h index 4b5aa89..6e4e310 100644 --- a/src/drivers/m10spg/ubx_def.h +++ b/src/drivers/m10spg/ubx_def.h @@ -87,9 +87,14 @@ typedef struct { uint32_t vAcc; /**< Vertical accuracy measurement in millimeters */ } UBXNavPositionPayload; -/** A conversion constant to go from the scale of the UBX lat/lon (1E-7deg) to regular degrees */ -#define LAT_SCALE_TO_DEGREES 10000000 -#define LON_SCALE_TO_DEGREES 10000000 +/** A conversion constant to go from the scale of UBX latitude (1E-7deg) to regular degrees */ +#define LAT_SCALE_TO_DEGREES 1e7f + +/** A conversion constant to go from the scale of UBX longitude (1E-7deg) to regular degrees */ +#define LON_SCALE_TO_DEGREES 1e7f + +/** A conversion constant to go from the scale of UBX altitude (mm) to meters */ +#define ALT_SCALE_TO_METERS 1e3f /** A struct representing the UBX-NAV-VELNED (velocity) payload */ typedef struct {