Skip to content

Commit

Permalink
parse date and time info
Browse files Browse the repository at this point in the history
  • Loading branch information
wertarbyte committed Feb 25, 2012
1 parent 276032f commit a5f2685
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions nmea.c
Expand Up @@ -67,12 +67,41 @@ static void parse_coord(struct coord *co) {
}
}

static void parse_clock(struct clock_t *cl) {
memset(cl, 0, sizeof(struct clock_t));
char buf[3] = "";
strncpy(buf, token_buffer, 2);
buf[2] = '\0';
cl->hour = atoi(buf);
strncpy(buf, token_buffer+2, 2);
buf[2] = '\0';
cl->minute = atoi(buf);
strncpy(buf, token_buffer+4, 2);
buf[2] = '\0';
cl->second = atoi(buf);
}

static void parse_date(struct date_t *d) {
memset(d, 0, sizeof(struct date_t));
char buf[3] = "";
strncpy(buf, token_buffer, 2);
buf[2] = '\0';
d->day = atoi(buf);
strncpy(buf, token_buffer+2, 2);
buf[2] = '\0';
d->month = atoi(buf);
strncpy(buf, token_buffer+4, 2);
buf[2] = '\0';
d->year = atoi(buf);
}

static void process_gprmc_token(void) {
switch (token_nr) {
case 1:
/* time
* HHMMSS(.sssss)
*/
parse_clock(&nmea_rmc.clock);
break;
case 2:
/* status
Expand Down Expand Up @@ -134,6 +163,7 @@ static void process_gprmc_token(void) {
/* date
* DDMMYY
*/
parse_date(&nmea_rmc.date);
break;
case 10:
/* magnetic declination
Expand Down
14 changes: 14 additions & 0 deletions nmea.h
Expand Up @@ -9,13 +9,27 @@ struct coord {
uint8_t frac[(NMEA_MINUTE_FRACTS+1)/2];
};

struct clock_t {
uint8_t hour;
uint8_t minute;
uint8_t second;
};

struct date_t {
uint8_t day;
uint8_t month;
uint8_t year;
};

struct nmea_rmc_t {
/* flag bits (lsb to msb):
* 0 status (1 == OK, 0 == warning)
* 1 latitude alignment (1 == N, 0 == S)
* 2 longitude alignment (1 == E, 0 == W)
*/
uint8_t flags;
struct date_t date;
struct clock_t clock;
struct coord lat;
struct coord lon;
};
Expand Down

0 comments on commit a5f2685

Please sign in to comment.