-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from CarletonURocketry/m10spg-suggestions
Add some remaining M10SPG suggestions
- Loading branch information
Showing
13 changed files
with
305 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
# Documentation | ||
/docs/html/ | ||
*.pinfo | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
/obj/ | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
fetcher | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
compile_commands.json | ||
.cache | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
# Documentation | ||
/docs/html/ | ||
*.pinfo | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
/obj/ | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
fetcher | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
compile_commands.json | ||
.cache | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
# Editor files | ||
*.code-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,97 @@ | ||
#include "../drivers/m10spg/m10spg.h" | ||
#include "../drivers/m10spg/ubx_def.h" | ||
#include "collectors.h" | ||
|
||
union read_buffer { | ||
UBXNavPositionPayload pos; | ||
UBXNavVelocityPayload vel; | ||
UBXNavStatusPayload stat; | ||
}; | ||
|
||
/** Type for sending measurements over the message queue. */ | ||
typedef struct { | ||
uint8_t type; /**< Measurement type */ | ||
union { | ||
uint32_t U32; | ||
int32_t I32; | ||
uint8_t U8; | ||
}; | ||
} __attribute__((packed)) message_t; | ||
|
||
void *m10spg_collector(void *args) { | ||
|
||
/* Open message queue. */ | ||
mqd_t sensor_q = mq_open(SENSOR_QUEUE, O_WRONLY); | ||
if (sensor_q == -1) { | ||
fprintf(stderr, "M10SPG collector could not open message queue '%s': '%s' \n", SENSOR_QUEUE, strerror(errno)); | ||
return (void *)((uint64_t)errno); | ||
} | ||
|
||
SensorLocation loc = { | ||
.bus = clctr_args(args)->bus, | ||
.addr = {.addr = (clctr_args(args)->addr), .fmt = I2C_ADDRFMT_7BIT}, | ||
}; | ||
|
||
int err = m10spg_open(&loc); | ||
if (err != EOK) { | ||
fprintf(stderr, "Could not open M10SPG: %s\n", strerror(err)); | ||
return (void *)((uint64_t)err); | ||
} | ||
|
||
for (;;) { | ||
// TODO - Don't read if the next epoch hasn't happened | ||
union read_buffer buf; | ||
message_t msg; | ||
/* err = m10spg_send_command(&loc, UBX_NAV_STAT, &buf, sizeof(UBXNavStatusPayload)); */ | ||
/* // Check if we have a valid fix, no point logging bad data */ | ||
/* if (err == EOK) { */ | ||
/* // Make sure that the fix is valid (has a reasonable value and is not a no-fix) */ | ||
/* if ((buf.stat.flags & 0x01) && buf.stat.gpsFix) { */ | ||
/* msg.type = TAG_FIX; */ | ||
/* msg.U8 = buf.stat.gpsFix; */ | ||
/* if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { */ | ||
/* fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); */ | ||
/* } */ | ||
// The else here is commented out so you can see the data processing is working even while an invalid | ||
// fix is held | ||
/* } // else { */ | ||
/* // // Instead of doing a continue, should sleep until the next epoch */ | ||
/* // printf("Bad GPS fix, skipping\n"); */ | ||
/* // continue; */ | ||
/* //} */ | ||
/* } else { */ | ||
/* fprintf(stderr, "M10SPG failed to read status: %s\n", strerror(err)); */ | ||
/* continue; */ | ||
/* } */ | ||
|
||
// Read position | ||
err = m10spg_send_command(&loc, UBX_NAV_POSLLH, &buf, sizeof(UBXNavPositionPayload)); | ||
if (err == EOK) { | ||
|
||
uint8_t coordinates[sizeof(vec2d_t) + 1]; | ||
coordinates[0] = TAG_COORDS; | ||
memcpy(&coordinates[1], &buf.pos.lat, sizeof(buf.pos.lat)); | ||
memcpy(&coordinates[1 + sizeof(buf.pos.lat)], &buf.pos.lon, sizeof(buf.pos.lon)); | ||
|
||
if (mq_send(sensor_q, (char *)coordinates, sizeof(coordinates), 0) == -1) { | ||
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); | ||
} | ||
|
||
msg.type = TAG_ALTITUDE_SEA; | ||
msg.I32 = buf.pos.hMSL; | ||
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { | ||
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); | ||
} | ||
} else { | ||
fprintf(stderr, "M10SPG failed to read position: %s\n", strerror(err)); | ||
continue; | ||
} | ||
|
||
// Read velocity | ||
/* err = m10spg_send_command(&loc, UBX_NAV_VELNED, &buf, sizeof(UBXNavVelocityPayload)); */ | ||
/* if (err == EOK) { */ | ||
/* msg.type = TAG_SPEED; */ | ||
/* msg.U32 = buf.vel.gSpeed; */ | ||
/* 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_COURSE; */ | ||
/* msg.U32 = buf.vel.heading; */ | ||
/* if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { */ | ||
/* fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); */ | ||
/* } */ | ||
/* } else { */ | ||
/* fprintf(stderr, "M10SPG failed to read velocity: %s\n", strerror(err)); */ | ||
/* continue; */ | ||
/* } */ | ||
} | ||
|
||
fprintf(stderr, "%s\n", strerror(err)); | ||
return (void *)((uint64_t)err); | ||
} | ||
#include "../drivers/m10spg/m10spg.h" | ||
#include "../drivers/m10spg/ubx_def.h" | ||
#include "collectors.h" | ||
|
||
union read_buffer { | ||
UBXNavPositionPayload pos; | ||
UBXNavVelocityPayload vel; | ||
UBXNavStatusPayload stat; | ||
}; | ||
|
||
void *m10spg_collector(void *args) { | ||
|
||
/* Open message queue. */ | ||
mqd_t sensor_q = mq_open(SENSOR_QUEUE, O_WRONLY); | ||
if (sensor_q == -1) { | ||
fprintf(stderr, "M10SPG collector could not open message queue '%s': '%s' \n", SENSOR_QUEUE, strerror(errno)); | ||
return (void *)((uint64_t)errno); | ||
} | ||
|
||
SensorLocation loc = { | ||
.bus = clctr_args(args)->bus, | ||
.addr = {.addr = (clctr_args(args)->addr), .fmt = I2C_ADDRFMT_7BIT}, | ||
}; | ||
|
||
int err = m10spg_open(&loc); | ||
if (err != EOK) { | ||
fprintf(stderr, "Could not open M10SPG: %s\n", strerror(err)); | ||
return (void *)((uint64_t)err); | ||
} | ||
|
||
for (;;) { | ||
// TODO - Don't read if the next epoch hasn't happened | ||
union read_buffer buf; | ||
common_t msg; | ||
err = m10spg_send_command(&loc, UBX_NAV_STAT, &buf, sizeof(UBXNavStatusPayload)); | ||
// Check if we have a valid fix, no point logging bad data */ | ||
if (err == EOK) { | ||
// Make sure that the fix is valid (has a reasonable value and is not a no-fix) */ | ||
// if ((buf.stat.flags & 0x01) && buf.stat.gpsFix) { | ||
msg.type = TAG_FIX; | ||
msg.data.U8 = buf.stat.gpsFix; | ||
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { | ||
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); | ||
} | ||
// The else here is commented out so you can see the data processing is working even while an invalid | ||
// fix is held | ||
//} else { | ||
// // Instead of doing a continue, should sleep until the next epoch */ | ||
// printf("Bad GPS fix, skipping\n"); */ | ||
// continue; | ||
//} | ||
} else { | ||
fprintf(stderr, "M10SPG failed to read status: %s\n", strerror(err)); | ||
continue; | ||
} | ||
|
||
// Read position | ||
err = m10spg_send_command(&loc, UBX_NAV_POSLLH, &buf, sizeof(UBXNavPositionPayload)); | ||
if (err == EOK) { | ||
msg.type = TAG_COORDS; | ||
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); | ||
if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { | ||
fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); | ||
} | ||
} else { | ||
fprintf(stderr, "M10SPG failed to read position: %s\n", strerror(err)); | ||
continue; | ||
} | ||
|
||
// Read velocity | ||
/* err = m10spg_send_command(&loc, UBX_NAV_VELNED, &buf, sizeof(UBXNavVelocityPayload)); */ | ||
/* if (err == EOK) { */ | ||
/* msg.type = TAG_SPEED; */ | ||
/* msg.U32 = buf.vel.gSpeed; */ | ||
/* 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_COURSE; */ | ||
/* msg.U32 = buf.vel.heading; */ | ||
/* if (mq_send(sensor_q, (char *)&msg, sizeof(msg), 0) == -1) { */ | ||
/* fprintf(stderr, "M10SPG couldn't send message: %s.\n", strerror(errno)); */ | ||
/* } */ | ||
/* } else { */ | ||
/* fprintf(stderr, "M10SPG failed to read velocity: %s\n", strerror(err)); */ | ||
/* continue; */ | ||
/* } */ | ||
} | ||
fprintf(stderr, "%s\n", strerror(err)); | ||
return (void *)((uint64_t)err); | ||
} |
Oops, something went wrong.