Browse Source

Better U-Blox struct packing

sbg
Lorenz Meier 12 years ago
parent
commit
18c009d2c1
  1. 8
      apps/gps/gps.c
  2. 2
      apps/gps/ubx.c
  3. 26
      apps/gps/ubx.h

8
apps/gps/gps.c

@ -564,10 +564,10 @@ void setup_port(char *device, int speed, int *fd) @@ -564,10 +564,10 @@ void setup_port(char *device, int speed, int *fd)
*fd = open_port(device);
if (*fd != -1) {
if (gps_verbose) printf("[gps] Port opened: %s at %d speed\r\n", device, speed);
if (gps_verbose) printf("[gps] Port opened: %s at %d baud\n", device, speed);
} else {
fprintf(stderr, "[gps] Could not open port, exiting gps app!\r\n");
fprintf(stderr, "[gps] Could not open port, exiting gps app!\n");
fflush(stdout);
}
@ -576,7 +576,7 @@ void setup_port(char *device, int speed, int *fd) @@ -576,7 +576,7 @@ void setup_port(char *device, int speed, int *fd)
int termios_state;
if ((termios_state = tcgetattr(*fd, &uart_config)) < 0) {
fprintf(stderr, "[gps] ERROR getting baudrate / termios config for %s: %d\r\n", device, termios_state);
fprintf(stderr, "[gps] ERROR getting baudrate / termios config for %s: %d\n", device, termios_state);
close(*fd);
}
if (gps_verbose) printf("[gps] Try to set baud rate %d now\n",speed);
@ -584,7 +584,7 @@ void setup_port(char *device, int speed, int *fd) @@ -584,7 +584,7 @@ void setup_port(char *device, int speed, int *fd)
cfsetispeed(&uart_config, speed);
cfsetospeed(&uart_config, speed);
if ((termios_state = tcsetattr(*fd, TCSANOW, &uart_config)) < 0) {
fprintf(stderr, "[gps] ERROR setting baudrate / termios config for %s (tcsetattr)\r\n", device);
fprintf(stderr, "[gps] ERROR setting baudrate / termios config for %s (tcsetattr)\n", device);
close(*fd);
}
}

2
apps/gps/ubx.c

@ -697,7 +697,7 @@ int write_config_message_ubx(uint8_t *message, size_t length, int fd) @@ -697,7 +697,7 @@ int write_config_message_ubx(uint8_t *message, size_t length, int fd)
// printf("[%x,%x]\n", ck_a, ck_b);
int result_write = write(fd, message, length);
unsigned int result_write = write(fd, message, length);
result_write += write(fd, &ck_a, 1);
result_write += write(fd, &ck_b, 1);

26
apps/gps/ubx.h

@ -76,6 +76,7 @@ @@ -76,6 +76,7 @@
// ************
/** the structures of the binary packets */
#pragma pack(push, 1)
typedef struct {
uint32_t time_milliseconds; // GPS Millisecond Time of Week
int32_t lon; // Longitude * 1e-7, deg
@ -87,7 +88,7 @@ typedef struct { @@ -87,7 +88,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_posllh_packet;
} type_gps_bin_nav_posllh_packet;
typedef type_gps_bin_nav_posllh_packet gps_bin_nav_posllh_packet_t;
@ -112,7 +113,7 @@ typedef struct { @@ -112,7 +113,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_sol_packet;
} type_gps_bin_nav_sol_packet;
typedef type_gps_bin_nav_sol_packet gps_bin_nav_sol_packet_t;
@ -131,7 +132,7 @@ typedef struct { @@ -131,7 +132,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_timeutc_packet;
} type_gps_bin_nav_timeutc_packet;
typedef type_gps_bin_nav_timeutc_packet gps_bin_nav_timeutc_packet_t;
@ -148,7 +149,7 @@ typedef struct { @@ -148,7 +149,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_dop_packet;
} type_gps_bin_nav_dop_packet;
typedef type_gps_bin_nav_dop_packet gps_bin_nav_dop_packet_t;
@ -158,7 +159,7 @@ typedef struct { @@ -158,7 +159,7 @@ typedef struct {
uint8_t globalFlags;
uint16_t reserved2;
} __attribute__((__packed__)) type_gps_bin_nav_svinfo_part1_packet;
} type_gps_bin_nav_svinfo_part1_packet;
typedef type_gps_bin_nav_svinfo_part1_packet gps_bin_nav_svinfo_part1_packet_t;
@ -172,7 +173,7 @@ typedef struct { @@ -172,7 +173,7 @@ typedef struct {
int16_t azim; //Azimuth in integer degrees
int32_t prRes; //Pseudo range residual in centimetres
} __attribute__((__packed__)) type_gps_bin_nav_svinfo_part2_packet;
} type_gps_bin_nav_svinfo_part2_packet;
typedef type_gps_bin_nav_svinfo_part2_packet gps_bin_nav_svinfo_part2_packet_t;
@ -180,7 +181,7 @@ typedef struct { @@ -180,7 +181,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_svinfo_part3_packet;
} type_gps_bin_nav_svinfo_part3_packet;
typedef type_gps_bin_nav_svinfo_part3_packet gps_bin_nav_svinfo_part3_packet_t;
@ -198,7 +199,7 @@ typedef struct { @@ -198,7 +199,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_nav_velned_packet;
} type_gps_bin_nav_velned_packet;
typedef type_gps_bin_nav_velned_packet gps_bin_nav_velned_packet_t;
@ -209,7 +210,7 @@ typedef struct { @@ -209,7 +210,7 @@ typedef struct {
//... rest of package is not used in this implementation
} __attribute__((__packed__)) type_gps_bin_rxm_svsi_packet;
} type_gps_bin_rxm_svsi_packet;
typedef type_gps_bin_rxm_svsi_packet gps_bin_rxm_svsi_packet_t;
@ -219,7 +220,7 @@ typedef struct { @@ -219,7 +220,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_ack_ack_packet;
} type_gps_bin_ack_ack_packet;
typedef type_gps_bin_ack_ack_packet gps_bin_ack_ack_packet_t;
@ -229,7 +230,7 @@ typedef struct { @@ -229,7 +230,7 @@ typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} __attribute__((__packed__)) type_gps_bin_ack_nak_packet;
} type_gps_bin_ack_nak_packet;
typedef type_gps_bin_ack_nak_packet gps_bin_ack_nak_packet_t;
@ -283,9 +284,10 @@ typedef struct { @@ -283,9 +284,10 @@ typedef struct {
enum UBX_MESSAGE_IDS message_id;
uint64_t last_message_timestamps[UBX_NO_OF_MESSAGES];
} __attribute__((__packed__)) type_gps_bin_ubx_state;
} type_gps_bin_ubx_state;
typedef type_gps_bin_ubx_state gps_bin_ubx_state_t;
#pragma pack(pop)
extern pthread_mutex_t *ubx_mutex;
extern gps_bin_ubx_state_t *ubx_state;

Loading…
Cancel
Save