Skip to content

Commit

Permalink
Merge pull request #55 from CarletonURocketry/m10spg-config
Browse files Browse the repository at this point in the history
Add configuration for dynamic platform and measurement rate
  • Loading branch information
linguini1 authored Jul 1, 2024
2 parents 00fd920 + 31a72ae commit 5af1fc1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/collectors/m10spg_clctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void *m10spg_collector(void *args) {
err = m10spg_open(&loc);
if (err != EOK) {
log_print(stderr, LOG_ERROR, "Could not open M10SPG: %s", strerror(err));
return (void *)((uint64_t)err);
}
} while (err != EOK);

Expand Down
44 changes: 37 additions & 7 deletions src/drivers/m10spg/m10spg.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
#define SYNC_TWO 0x62

/** How long the recieve command for UBX messages should wait between trying to read a message, in usec */
#define RECV_SLEEP_TIME 10000
#define RECV_SLEEP_TIME 1000

/** How long m10spg_read should wait for a response in seconds */
#define DEFAULT_TIMEOUT 10
#define DEFAULT_TIMEOUT 2

/** A configuration key for enabling or disabling output of NMEA messages on I2C */
#define NMEA_I2C_OUTPUT_CONFIG_KEY 0x10720002
/** The confirmation value for the platform model that corresponds to an airborne vehicle doing <4G of acceleration */
#define DYNMODEL_AIR_4G 8

/** A configuration key for enabling or disabling input of poll requests for NMEA messages on I2C */
#define NMEA_I2C_INPUT_CONFIG_KEY 0x10710002
/** The nominal time between gps measurements in milliseconds */
#define NOMINAL_MEASUREMENT_RATE 300

static const UBXFrame PREMADE_MESSAGES[] = {
[UBX_NAV_UTC] = {.header = {.class = 0x01, .id = 0x21, .length = 0x00}, .checksum_a = 0x22, .checksum_b = 0x67},
Expand Down Expand Up @@ -306,22 +306,49 @@ int m10spg_open(const SensorLocation *loc) {
UBXValsetPayload valset_payload;
UBXAckPayload ack_payload;

// Clear the RAM configuration to ensure our settings are the only ones being used
msg.header.class = 0x06;
msg.header.id = 0x04;
msg.header.length = 4;

UBXConfigResetPayload reset_payload;
reset_payload.navBbrMask[0] = 0x00;
reset_payload.navBbrMask[1] = 0x00;
reset_payload.resetMode = UBX_SOFT_RESET;
msg.payload = &reset_payload;
calculate_checksum(&msg, &msg.checksum_a, &msg.checksum_b);
send_message(loc, &msg);
// Has no response, sleep to wait for reset
sleep(1);

// Configure the chip
msg.payload = &valset_payload;

// Put our actual configuration on there
init_valset_message(&msg, RAM_LAYER);
uint8_t config_disabled = 0;
uint8_t config_dynmodel = DYNMODEL_AIR_4G;
uint16_t measurement_rate = NOMINAL_MEASUREMENT_RATE;
// Disable NMEA output on I2C
add_valset_item(&msg, (uint32_t)NMEA_I2C_OUTPUT_CONFIG_KEY, &config_disabled, UBX_TYPE_L);
// Disable NMEA input on I2C
add_valset_item(&msg, (uint32_t)NMEA_I2C_INPUT_CONFIG_KEY, &config_disabled, UBX_TYPE_L);
// Set the dynamic platform model to have the maximum speed, acceleration, and height possible
add_valset_item(&msg, (uint32_t)DYNMODEL_CONFIG_KEY, &config_dynmodel, UBX_TYPE_U1);
// Set the config update rate
add_valset_item(&msg, (uint32_t)MEASUREMENT_RATE_CONFIG_KEY, &measurement_rate, UBX_TYPE_U2);
// Turn off the BDS satellites, which increases the maximum update rate, but needs a reset of the GPS subsystem
add_valset_item(&msg, (uint32_t)BSD_SIGNAL_CONFIG_KEY, &config_disabled, UBX_TYPE_L);

calculate_checksum(&msg, &msg.checksum_a, &msg.checksum_b);

int err = send_message(loc, &msg);
return_err(err);

// Check if configuration was successful
msg.payload = &ack_payload;
err = recv_message(loc, &msg, sizeof(ack_payload), 1);
// Longer timeout for the reboot
err = recv_message(loc, &msg, sizeof(ack_payload), DEFAULT_TIMEOUT);
return_err(err);
if (msg.header.class == 0x05) {
if (msg.header.id == 0x01) {
Expand All @@ -331,6 +358,9 @@ int m10spg_open(const SensorLocation *loc) {
return ECANCELED;
}
}
// Give at least 0.5 seconds for the gps subsystem to restart, because we disabled the BDS signal
usleep(500000);

// Some other response interrupted our exchange
return EINTR;
}
Expand Down
31 changes: 31 additions & 0 deletions src/drivers/m10spg/ubx_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ typedef struct {
uint8_t flags; /**< Flags that describe if this time information is valid (see the interface description) */
} UBXUTCPayload;

typedef enum {
UBX_HARD_RESET = 0x00, /**< Hardware reset (watchdog), immediate */
UBX_SOFT_RESET = 0x01, /**< Controlled software reset (clears RAM) */
UBX_SOFT_GNSS_RESET = 0x02, /**< Controlled software reset, GNSS only */
UBX_HARD_WDT_RESET = 0x04, /**< Hardware reset (watchdog), after shutdown */
UBX_STOP_GNSS = 0x08, /** Controlled GNSS stop */
UBX_START_GNSS = 0x09, /**< Controlled GNSS start */
} UBXResetMode;

/** A struct representing the UBX-CFG-RST (reset reciever) payload */
typedef struct {
uint8_t navBbrMask[2]; /**< Bit fields that select what BBR data to clear (leave as 0 for a hot start) */
uint8_t resetMode; /**< The type of reset to perform, of type UBXResetMode */
uint8_t reserved; /**< Reserved bytes */
} UBXConfigResetPayload;

/** Max bytes to be used for valset payload items (limit of 64 items per message) */
#define MAX_VALSET_ITEM_BYTES 128

Expand All @@ -65,6 +81,21 @@ typedef struct {
uint8_t config_items[MAX_VALSET_ITEM_BYTES]; /** An array of keys and value pairs */
} UBXValsetPayload;

/** A configuration key for enabling or disabling output of NMEA messages on I2C */
#define NMEA_I2C_OUTPUT_CONFIG_KEY 0x10720002

/** A configuration key for enabling or disabling input of poll requests for NMEA messages on I2C */
#define NMEA_I2C_INPUT_CONFIG_KEY 0x10710002

/** A configuration key for selecting the platform model of the reciever */
#define DYNMODEL_CONFIG_KEY 0x20110021

/** A configuration key for enabling or disabling the BeiDou satellites */
#define BSD_SIGNAL_CONFIG_KEY 0x10310022

/** A configuration key for selecting the number of milliseconds between measurements */
#define MEASUREMENT_RATE_CONFIG_KEY 0x30210001

/** A struct representing the UBX-NAV-STAT (navigation status) payload */
typedef struct {
uint32_t iTOW; /**< The GPS time of week of the navigation epoch that created this payload */
Expand Down

0 comments on commit 5af1fc1

Please sign in to comment.