Commit 200e9d2f authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

GPS now fixes to satellites

Implemented and tested some utility functions
parent b2073475
......@@ -50,26 +50,22 @@
#define GPS_OK_TO_SEND "$PSRF150,1*3E\r\n"
#define RXBUFSIZE 16
#define RXBUFSIZE 128
static char rxbuf[RXBUFSIZE];
volatile char idx = 0;
volatile int idx = 0;
volatile char gps_rdy = 0;
static nmeaINFO gps_info;
static nmeaPARSER gps_parser;
void LEUART0_IRQHandler()
{
if (LEUART0->IF & LEUART_IF_RXDATAV) {
rxbuf[idx++] = LEUART_Rx(LEUART0);
if ((gps_rdy == 0) && (strncmp(rxbuf, GPS_OK_TO_SEND,
strlen(GPS_OK_TO_SEND)) == 0)) {
gps_rdy = 1;
usbdbg_puts("GPS ready to send!\r\n");
if ((rxbuf[idx-2] == '\r') && (rxbuf[idx-1] == '\n')) {
rxbuf[idx] = '\0';
idx = 0;
}
if ((gps_rdy) && (idx == RXBUFSIZE)) {
idx = 0;
usbdbg_puts(rxbuf);
nmea_parse(&gps_parser, rxbuf, strlen(rxbuf),
&gps_info);
}
}
}
......@@ -116,6 +112,9 @@ void gps_init()
LEUART_Enable(LEUART0, leuartEnable);
/* NMEA parser & info structure init */
nmea_zero_INFO(&gps_info);
nmea_parser_init(&gps_parser);
}
void gps_on_off_pulse()
......@@ -166,3 +165,35 @@ int gps_nmea_crc(const char *nmeastr)
return chksum;
}
int gps_fixed()
{
return gps_info.sig;
}
void gps_get_utc(int *yr, int *mon, int *day, int *hr, int *min, int *sec)
{
*yr = 1900 + gps_info.utc.year;
*mon = 1 + gps_info.utc.mon;
*day = gps_info.utc.day;
*hr = gps_info.utc.hour;
*min = gps_info.utc.min;
*sec = gps_info.utc.sec;
}
void gps_get_coord(double *lat, double *lon, double *elv)
{
*lat = gps_info.lat;
*lon = gps_info.lon;
*elv = gps_info.elv;
}
void gps_get_speed(double *spd)
{
*spd = gps_info.speed;
}
void gps_get_direction(double *dir)
{
*dir = gps_info.direction;
}
......@@ -47,6 +47,10 @@ void gps_on_off_pulse();
void gps_reset(int val);
int gps_puts(char *s);
int gps_nmea_crc(const char *nmeastr);
int gps_fixed();
void gps_get_utc(int *yr, int *mon, int *day, int *hr, int *min, int *sec);
void gps_get_coord(double *lat, double *lon, double *elv);
void gps_get_speed(double *spd);
void gps_get_direction(double *dir);
#endif // __GPS_H_
......@@ -47,6 +47,7 @@
#include "usbdbg.h"
#include "gps.h"
int main()
{
......@@ -62,40 +63,28 @@ int main()
usbdbg_puts("init done!\r\n");
int i, one = 1;
static char tmp[64];
static char c[2];
static char cmd[64];
static char tmp[128];
double lat, lon, elv;
double spd, dir;
for (;;) {
GPIO_PinInGet(gpioPortA, 1) ?
GPIO_PinOutSet(gpioPortE, 11) :
GPIO_PinOutClear(gpioPortE, 11);
LEUART_Tx(LEUART0, 0x54);
// if (one) {
// one = 0;
// for (i = 0; i < 20000000; i++)
// ;
//// usbdbg_puts("\r\n\r\n\r\n\r\n"); //strcpy(tmp, "$PSRF105,1*");
//// sprintf(c, "%02X", nmea_crc(tmp));
//// strcat(tmp, c);
//// strcat(tmp, "\r\n");
//// usbdbg_puts(tmp);
//// gps_puts(tmp);
//// usbdbg_puts("\r\n\r\n\r\n\r\n");
// /* Send init command */
//// strcpy(tmp, "$PSRF104,46.22954,6.06156,100,0,55020,1807,12,1*");
// strcpy(tmp, "$PSRF125*");
// sprintf(c, "%02X", nmea_crc(tmp));
// strcpy(cmd, tmp);
// strcat(cmd, c);
// strcat(cmd, "\r\n");
// if (gps_puts(cmd)) {
// usbdbg_puts("\r\n\r\n\r\n\r\n");
// usbdbg_puts(cmd);
// usbdbg_puts("\r\n\r\n\r\n\r\n");
// }
// }
gps_get_coord(&lat, &lon, &elv);
gps_get_speed(&spd);
gps_get_direction(&dir);
sprintf(tmp, "%d: ", gps_fixed());
sprintf(tmp + strlen(tmp), "%4.4f / %4.4f / %2.3f / ",
lat, lon, elv);
sprintf(tmp + strlen(tmp), "%3.2f / %3.2f", spd, dir);
sprintf(tmp + strlen(tmp), "\r\n");
usbdbg_puts(tmp);
for (i = 0; i < 1000000; i++)
;
}
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment