Skip to content

Commit

Permalink
Change priorities so that acceleration, altitude and GPS data are hig…
Browse files Browse the repository at this point in the history
…hest priority.
  • Loading branch information
linguini1 committed Jun 10, 2024
1 parent c285698 commit a95f092
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/collectors/lsm6dso32_clctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void *lsm6dso32_collector(void *args) {
lsm6dso32_convert_accel(LA_FS_32G, &x, &y, &z);
msg.type = TAG_LINEAR_ACCEL_REL;
msg.data.VEC3D = (vec3d_t){.x = x, .y = y, .z = z};
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 1) == -1) {
fetcher_log(stderr, LOG_ERROR, "LSM6DSO32 couldn't send message: %s", strerror(errno));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/collectors/m10spg_clctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ union read_buffer {
/**
* Helper function to simplify sending a message on the message queue
*/
#define send_msg(sensor_q, msg) \
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { \
#define send_msg(sensor_q, msg, prio) \
if (mq_send((sensor_q), (char *)(&(msg)), sizeof(msg), (prio)) == -1) { \
fetcher_log(stderr, LOG_WARN, "M10SPG couldn't send message: %s.", strerror(errno)); \
}

Expand Down Expand Up @@ -73,7 +73,7 @@ void *m10spg_collector(void *args) {
case GPS_3D_FIX:
msg.type = TAG_ALTITUDE_SEA;
msg.data.FLOAT = (((float)buf.pos.hMSL) / ALT_SCALE_TO_METERS);
send_msg(sensor_q, msg);
send_msg(sensor_q, msg, 2);
// FALL THROUGH
case GPS_FIX_DEAD_RECKONING:
// FALL THROUGH
Expand All @@ -83,7 +83,7 @@ void *m10spg_collector(void *args) {
msg.type = TAG_COORDS;
msg.data.VEC2D_I32.x = buf.pos.lat;
msg.data.VEC2D_I32.y = buf.pos.lon;
send_msg(sensor_q, msg);
send_msg(sensor_q, msg, 3);
break;
case GPS_TIME_ONLY:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/collectors/ms5611_clctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ void *ms5611_collector(void *args) {
// Transmit pressure
msg.type = TAG_PRESSURE;
msg.data.FLOAT = (float)pressure;
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 1) == -1) {
fetcher_log(stderr, LOG_ERROR, "MS5611 couldn't send message: %s.", strerror(errno));
}

// Transmit altitude
msg.type = TAG_ALTITUDE_REL;
msg.data.FLOAT = (float)altitude;
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 2) == -1) {
fetcher_log(stderr, LOG_ERROR, "MS5611 couldn't send message: %s.", strerror(errno));
}
}
Expand Down
27 changes: 19 additions & 8 deletions src/collectors/sysclock_clctr.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "../drivers/sensor_api.h"
#include "collectors.h"
#include "logging.h"
#include <errno.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>

/** Macro to cast `errno_t` to void pointer before returning. */
#define return_err(err) return (void *)((uint64_t)err)

/**
* Collector thread for the system clock.
* @param args Arguments in the form of `collector_args_t`
Expand All @@ -23,23 +27,30 @@ void *sysclock_collector(void *args) {
}

// Get the current UNIX time and time information
time_t start_unix_time;
time(&start_unix_time);
struct tm *time_info = localtime(&start_unix_time);
struct timezone tz = {.tz_dsttime = 0, .tz_minuteswest = time_info->tm_gmtoff};
struct timeval tval;
struct timespec start;
int err = clock_gettime(CLOCK_REALTIME, &start);
if (err) {
fetcher_log(stderr, LOG_ERROR, "Could not get startup time: %s", strerror(errno));
return_err(errno);
}

// Infinitely check the time
struct timespec now;
common_t msg;
msg.type = TAG_TIME;
for (;;) {

// Get time with nanosecond precision
gettimeofday(&tval, &tz);
err = clock_gettime(CLOCK_REALTIME, &now);
if (err) {
fetcher_log(stderr, LOG_ERROR, "Could not get current time: %s", strerror(errno));
continue;
}

// Calculate elapsed time from launch
time_t elapsed_s = tval.tv_sec - start_unix_time;
msg.data.U32 = (elapsed_s * 1000) + (tval.tv_usec / 1000);
long elapsed_s = now.tv_sec - start.tv_sec;
long elapsed_ns = now.tv_nsec - start.tv_nsec;
msg.data.U32 = (elapsed_s * 1000) + (elapsed_ns / 1000000);

// Infinitely send the time
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) {
Expand Down

0 comments on commit a95f092

Please sign in to comment.