2021-02-10 19:54:13 +00:00
|
|
|
/***************************************************************************
|
2023-02-08 15:33:02 +00:00
|
|
|
* Copyright (C) 2021 - 2023 by Federico Amedeo Izzo IU2NUO, *
|
2022-06-02 07:56:05 +00:00
|
|
|
* Niccolò Izzo IU2KIN *
|
|
|
|
* Frederik Saraci IU2NRO *
|
|
|
|
* Silvano Seva IU2KWO *
|
2021-02-10 19:54:13 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2023-07-21 06:29:24 +00:00
|
|
|
#include <peripherals/gps.h>
|
2021-03-10 16:06:05 +00:00
|
|
|
#include <interfaces/delays.h>
|
2022-06-16 14:39:50 +00:00
|
|
|
#include <sys/time.h>
|
2021-02-10 19:54:13 +00:00
|
|
|
#include <hwconfig.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-02-16 22:44:18 +00:00
|
|
|
#define MAX_NMEA_LEN 80
|
|
|
|
#define NMEA_SAMPLES 8
|
|
|
|
|
2022-06-16 14:39:50 +00:00
|
|
|
static long long startTime;
|
|
|
|
|
2022-06-14 17:20:42 +00:00
|
|
|
char test_nmea_sentences [NMEA_SAMPLES][MAX_NMEA_LEN] =
|
|
|
|
{
|
2021-02-16 22:44:18 +00:00
|
|
|
"$GPGGA,223659.522,5333.735,N,00959.130,E,1,12,1.0,0.0,M,0.0,M,,*62",
|
|
|
|
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
|
|
|
|
"$GPGSV,3,1,12,30,79,066,27,05,63,275,21,07,42,056,,13,40,289,13*76",
|
|
|
|
"$GPGSV,3,2,12,14,36,147,20,28,30,151,,09,13,100,,02,08,226,30*72",
|
|
|
|
"$GPGSV,3,3,12,18,05,333,,15,04,289,22,08,03,066,,27,02,030,*79",
|
|
|
|
"$GPRMC,223659.522,A,5333.735,N,00959.130,E,,,160221,000.0,W*70",
|
|
|
|
"$GPVTG,92.15,T,,M,0.15,N,0.28,K,A*0C"
|
|
|
|
};
|
|
|
|
|
2022-06-14 17:20:42 +00:00
|
|
|
void gps_init(const uint16_t baud)
|
2021-02-10 19:54:13 +00:00
|
|
|
{
|
2022-06-14 17:20:42 +00:00
|
|
|
(void) baud;
|
|
|
|
return;
|
2021-02-10 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gps_terminate()
|
|
|
|
{
|
2022-06-14 17:20:42 +00:00
|
|
|
return;
|
2021-02-10 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gps_enable()
|
|
|
|
{
|
2022-06-14 17:20:42 +00:00
|
|
|
return;
|
2021-02-10 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gps_disable()
|
|
|
|
{
|
2022-06-14 17:20:42 +00:00
|
|
|
return;
|
2021-02-10 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 17:20:42 +00:00
|
|
|
bool gps_detect(uint16_t timeout)
|
2021-02-10 19:54:13 +00:00
|
|
|
{
|
2022-06-14 17:20:42 +00:00
|
|
|
(void) timeout;
|
2021-02-10 19:54:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gps_getNmeaSentence(char *buf, const size_t maxLength)
|
|
|
|
{
|
2021-02-16 22:44:18 +00:00
|
|
|
static int i = 0;
|
2021-02-10 19:54:13 +00:00
|
|
|
|
2021-02-16 22:44:18 +00:00
|
|
|
// Emulate GPS device by sending NMEA sentences every 1s
|
|
|
|
if(i == 0)
|
2021-03-10 16:06:05 +00:00
|
|
|
sleepFor(1u, 0u);
|
2022-06-16 14:39:50 +00:00
|
|
|
|
2021-02-17 10:21:46 +00:00
|
|
|
size_t len = strnlen(test_nmea_sentences[i], MAX_NMEA_LEN);
|
2022-06-16 14:39:50 +00:00
|
|
|
|
2021-02-17 10:21:46 +00:00
|
|
|
if (len > maxLength)
|
|
|
|
return -1;
|
2022-06-16 14:39:50 +00:00
|
|
|
|
2021-02-17 10:21:46 +00:00
|
|
|
strncpy(buf, test_nmea_sentences[i], maxLength);
|
2021-02-16 22:44:18 +00:00
|
|
|
i++;
|
|
|
|
i %= NMEA_SAMPLES;
|
2022-06-16 14:39:50 +00:00
|
|
|
|
|
|
|
// Save the current timestamp for sentence ready emulation
|
|
|
|
struct timeval te;
|
|
|
|
gettimeofday(&te, NULL);
|
|
|
|
startTime = te.tv_sec*1000LL + te.tv_usec/1000;
|
|
|
|
|
|
|
|
return 0;
|
2021-02-10 19:54:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 17:20:42 +00:00
|
|
|
bool gps_nmeaSentenceReady()
|
|
|
|
{
|
2022-06-16 14:39:50 +00:00
|
|
|
// Return new sentence ready only after 1s from start
|
|
|
|
struct timeval te;
|
|
|
|
gettimeofday(&te, NULL);
|
|
|
|
long long currTime = te.tv_sec*1000LL + te.tv_usec/1000;
|
|
|
|
|
|
|
|
if((currTime - startTime) > 1000) return true;
|
|
|
|
|
|
|
|
return false;
|
2022-06-14 17:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gps_waitForNmeaSentence()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|