Skip to content

Commit

Permalink
First simple impl serial comm
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Nov 23, 2013
1 parent 7843e13 commit 99eeea9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "serial.h"

extern void gps_init(void) {
/*serial_init();*/
serial_init();
serial_config();

//Write commands
}
Expand All @@ -19,12 +20,36 @@ extern void gps_on(void) {

// Compute the GPS location using decimal scale
extern void gps_location(loc_t *coord) {
coord->latitude = 43.941866f;
coord->longitude = 7.828637f;
/*coord->latitude = 43.941866f;
coord->longitude = 7.828637f;*/

//Write command
uint8_t status = _EMPTY;
while(status != _COMPLETED) {
gpgga_t gpgga;
gprmc_t gprmc;
char buffer[256];

//Read nmea
serial_readln(buffer, 256);
switch (nmea_get_message_type(buffer)) {
case NMEA_GPGGA:
nmea_parse_gpgga(buffer, &gpgga);

coord->latitude = gpgga.latitude;
coord->longitude = gpgga.longitude;
coord->altitude = gpgga.altitude;

status |= NMEA_GPGGA;
break;
case NMEA_GPRMC:
nmea_parse_gprmc(buffer, &gprmc);

coord->speed = gprmc.speed;
coord->course = gprmc.course;

status |= NMEA_GPRMC;
break;
}
}
}

extern void gps_off(void) {
Expand Down
13 changes: 13 additions & 0 deletions src/nmea.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@ void nmea_parse_gprmc(char *nmea, gprmc_t *loc)
loc->course = atof(p);
}

uint8_t nmea_get_message_type(const char *message)
{
if (strstr(message, NMEA_GPGGA_STR) != NULL) {
return NMEA_GPGGA;
}

if (strstr(message, NMEA_GPRMC_STR) != NULL) {
return NMEA_GPRMC;
}

return NMEA_UNKNOWN;
}

9 changes: 9 additions & 0 deletions src/nmea.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#include <stdlib.h>
#include <inttypes.h>

#define _EMPTY 0x00
#define NMEA_GPRMC 0x01
#define NMEA_GPRMC_STR "$GPRMC"
#define NMEA_GPGGA 0x02
#define NMEA_GPGGA_STR "$GPGGA"
#define NMEA_UNKNOWN 0x00
#define _COMPLETED 0x03

struct gpgga {
// Latitude eg: 4124.8963 (XXYY.ZZKK.. DEG, MIN, SEC.SS)
double latitude;
Expand Down Expand Up @@ -33,6 +41,7 @@ struct gprmc {
};
typedef struct gprmc gprmc_t;

uint8_t nmea_get_message_type(const char *);
void nmea_parse_gpgga(char *, gpgga_t *);
void nmea_parse_gprmc(char *, gprmc_t *);

Expand Down
1 change: 1 addition & 0 deletions src/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endif

void serial_init(void);
void serial_config(void);
void serial_println(const char *, int);
void serial_readln(char *, int);
void serial_close(void);
Expand Down

0 comments on commit 99eeea9

Please sign in to comment.