linux: updated GPS driver to new API
This commit is contained in:
parent
f1486c9a41
commit
7684c11328
|
|
@ -314,7 +314,7 @@ linux_src = ['platform/targets/linux/emulator/emulator.c',
|
||||||
'platform/drivers/display/display_libSDL.c',
|
'platform/drivers/display/display_libSDL.c',
|
||||||
'platform/drivers/keyboard/keyboard_linux.c',
|
'platform/drivers/keyboard/keyboard_linux.c',
|
||||||
'platform/drivers/NVM/nvmem_linux.c',
|
'platform/drivers/NVM/nvmem_linux.c',
|
||||||
'platform/drivers/GPS/GPS_linux.c',
|
'platform/drivers/GPS/gps_linux.c',
|
||||||
'platform/mcu/x86_64/drivers/delays.c',
|
'platform/mcu/x86_64/drivers/delays.c',
|
||||||
'platform/mcu/x86_64/drivers/rng.cpp',
|
'platform/mcu/x86_64/drivers/rng.cpp',
|
||||||
'platform/drivers/baseband/radio_linux.cpp',
|
'platform/drivers/baseband/radio_linux.cpp',
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,15 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <peripherals/gps.h>
|
|
||||||
#include <interfaces/delays.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <hwconfig.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <gps.h>
|
||||||
|
|
||||||
#define MAX_NMEA_LEN 80
|
#define MAX_NMEA_LEN 80
|
||||||
#define NMEA_SAMPLES 8
|
#define NMEA_SAMPLES 8
|
||||||
|
|
||||||
static long long startTime;
|
static const char test_nmea_sentences[NMEA_SAMPLES][MAX_NMEA_LEN] =
|
||||||
|
|
||||||
char test_nmea_sentences [NMEA_SAMPLES][MAX_NMEA_LEN] =
|
|
||||||
{
|
{
|
||||||
"$GPGGA,223659.522,5333.735,N,00959.130,E,1,12,1.0,0.0,M,0.0,M,,*62",
|
"$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",
|
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
|
||||||
|
|
@ -40,72 +37,61 @@ char test_nmea_sentences [NMEA_SAMPLES][MAX_NMEA_LEN] =
|
||||||
"$GPVTG,92.15,T,,M,0.15,N,0.28,K,A*0C"
|
"$GPVTG,92.15,T,,M,0.15,N,0.28,K,A*0C"
|
||||||
};
|
};
|
||||||
|
|
||||||
void gps_init(const uint16_t baud)
|
static long long startTime;
|
||||||
|
static bool enabled = true;
|
||||||
|
static int currSentence = 0;
|
||||||
|
|
||||||
|
static inline long long now()
|
||||||
{
|
{
|
||||||
(void) baud;
|
struct timeval te;
|
||||||
return;
|
gettimeofday(&te, NULL);
|
||||||
|
|
||||||
|
return (te.tv_sec*1000LL) + (te.tv_usec/1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_terminate()
|
static void enable(void *priv)
|
||||||
{
|
{
|
||||||
return;
|
(void) priv;
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
currSentence = 0;
|
||||||
|
startTime = now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_enable()
|
static void disable(void *priv)
|
||||||
{
|
{
|
||||||
return;
|
(void) priv;
|
||||||
|
|
||||||
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_disable()
|
static int getNmeaSentence(void *priv, char *buf, const size_t bufSize)
|
||||||
{
|
{
|
||||||
return;
|
(void) priv;
|
||||||
}
|
|
||||||
|
|
||||||
bool gps_detect(uint16_t timeout)
|
// GPS off > no data
|
||||||
{
|
if(!enabled)
|
||||||
(void) timeout;
|
return 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int gps_getNmeaSentence(char *buf, const size_t maxLength)
|
// Emit one sentence every 1s
|
||||||
{
|
long long currTime = now();
|
||||||
static int i = 0;
|
if((currTime - startTime) < 1000)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Emulate GPS device by sending NMEA sentences every 1s
|
size_t len = strnlen(test_nmea_sentences[currSentence], MAX_NMEA_LEN);
|
||||||
if(i == 0)
|
if(len > bufSize)
|
||||||
sleepFor(1u, 0u);
|
|
||||||
|
|
||||||
size_t len = strnlen(test_nmea_sentences[i], MAX_NMEA_LEN);
|
|
||||||
|
|
||||||
if (len > maxLength)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strncpy(buf, test_nmea_sentences[i], maxLength);
|
strncpy(buf, test_nmea_sentences[currSentence], bufSize);
|
||||||
i++;
|
currSentence += 1;
|
||||||
i %= NMEA_SAMPLES;
|
currSentence %= NMEA_SAMPLES;
|
||||||
|
startTime = currTime;
|
||||||
|
|
||||||
// Save the current timestamp for sentence ready emulation
|
return (int) len;
|
||||||
struct timeval te;
|
|
||||||
gettimeofday(&te, NULL);
|
|
||||||
startTime = te.tv_sec*1000LL + te.tv_usec/1000;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gps_nmeaSentenceReady()
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gps_waitForNmeaSentence()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct gpsDevice gps = {
|
||||||
|
.enable = enable,
|
||||||
|
.disable = disable,
|
||||||
|
.getSentence = getNmeaSentence
|
||||||
|
};
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <interfaces/platform.h>
|
#include <interfaces/platform.h>
|
||||||
#include <interfaces/nvmem.h>
|
#include <interfaces/nvmem.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <gps.h>
|
||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -157,3 +158,9 @@ const hwInfo_t *platform_getHwInfo()
|
||||||
{
|
{
|
||||||
return &hwInfo;
|
return &hwInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct gpsDevice *platform_initGps()
|
||||||
|
{
|
||||||
|
extern struct gpsDevice gps;
|
||||||
|
return &gps;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue