rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
gps_uart.cpp File Reference

Detailed Description

GPS receiver hardware UART driver.

Tested and developed for NEO-6M http://www.u-blox.com/en/gps-modules/pvt-modules/previous-generations/neo-6-family.html Technically any UART GPS should work with this driver since NMEA protocol is pretty common anyway

Date
Dec 28, 2013
Author
Andrey Belomutskiy, (c) 2012-2020 Kot_dnz 2014

Definition in file gps_uart.cpp.

Functions

static THD_WORKING_AREA (gpsThreadStack, UTILITY_THREAD_STACK_SIZE)
 
float getCurrentSpeed (void)
 
static void printGpsInfo ()
 
static void onGpsMessage (const char *const buffer)
 
static THD_FUNCTION (GpsThreadEntryPoint, arg)
 
static bool isGpsEnabled ()
 
void initGps (void)
 

Variables

static SerialConfig GPSserialConfig = { GPS_SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }
 
static loc_t GPSdata
 
static efidatetime_t lastDateTime
 
static int gpsMessageCount = 0
 
static int uartErrors = 0
 
static char gps_str [GPS_MAX_STRING]
 

Function Documentation

◆ getCurrentSpeed()

float getCurrentSpeed ( void  )

Definition at line 38 of file gps_uart.cpp.

38 {
39 // TODO: ???
40 return GPSdata.speed;
41}
static loc_t GPSdata
Definition gps_uart.cpp:30
float speed
Definition nmea.h:30

Referenced by printGpsInfo().

Here is the caller graph for this function:

◆ initGps()

void initGps ( void  )

Definition at line 102 of file gps_uart.cpp.

102 {
103 if (!isGpsEnabled())
104 return;
105
106
107 sdStart(GPS_SERIAL_DEVICE, &GPSserialConfig);
108// GPS we have USART1: PB7 -> USART1_RX and PB6 -> USART1_TX
109 efiSetPadMode("GPS tx", engineConfiguration->gps_tx_pin, PAL_MODE_ALTERNATE(7));
110 efiSetPadMode("GPS rx", engineConfiguration->gps_rx_pin, PAL_MODE_ALTERNATE(7));
111
112// todo: add a thread which would save location. If the GPS 5Hz - we should save the location each 200 ms
113 chThdCreateStatic(gpsThreadStack, sizeof(gpsThreadStack), LOWPRIO, (tfunc_t)(void*) GpsThreadEntryPoint, NULL);
114
115 addConsoleAction("gpsinfo", &printGpsInfo);
116}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static constexpr engine_configuration_s * engineConfiguration
static SerialConfig GPSserialConfig
Definition gps_uart.cpp:26
static bool isGpsEnabled()
Definition gps_uart.cpp:97
static void printGpsInfo()
Definition gps_uart.cpp:43

Referenced by initHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGpsEnabled()

static bool isGpsEnabled ( )
static

Definition at line 97 of file gps_uart.cpp.

97 {
98 return (isBrainPinValid(engineConfiguration->gps_rx_pin) &&
100}
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by initGps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onGpsMessage()

static void onGpsMessage ( const char *const  buffer)
static

Definition at line 56 of file gps_uart.cpp.

56 {
58
59 if (GPSdata.quality == 4 && GPSdata.time.year > 0) {
61 if (GPSdata.time.second != dateTime.second) {
62 // quality =4 (valid GxRMC), year > 0, and difference more than second
64 }
65 }
66
68}
static int gpsMessageCount
Definition gps_uart.cpp:33
static efidatetime_t lastDateTime
Definition gps_uart.cpp:31
void gps_location(loc_t *coord, char const *const buffer)
Definition nmea.cpp:298
void setRtcDateTime(efidatetime_t const *const dateTime)
efidatetime_t getRtcDateTime()
efidatetime_t time
Definition nmea.h:33
int quality
Definition nmea.h:35
uint32_t year
static BigBufferHandle buffer

Referenced by THD_FUNCTION().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printGpsInfo()

static void printGpsInfo ( )
static

Definition at line 43 of file gps_uart.cpp.

43 {
44 efiPrintf("GPS RX %s", hwPortname(engineConfiguration->gps_rx_pin));
45 efiPrintf("GPS TX %s", hwPortname(engineConfiguration->gps_tx_pin));
46
47 efiPrintf("m=%d,e=%d: vehicle speed = %.2f", gpsMessageCount, uartErrors, getCurrentSpeed());
48
49 float sec = getTimeNowMs() / 1000.0;
50 efiPrintf("communication speed: %.2f", gpsMessageCount / sec);
51
52 efiPrintf("GPS latitude = %.2f\r\n", GPSdata.latitude);
53 efiPrintf("GPS longitude = %.2f\r\n", GPSdata.longitude);
54}
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition efitime.cpp:34
static int uartErrors
Definition gps_uart.cpp:34
float getCurrentSpeed(void)
Definition gps_uart.cpp:38
const char * hwPortname(brain_pin_e brainPin)
float latitude
Definition nmea.h:28
float longitude
Definition nmea.h:29

Referenced by initGps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ THD_FUNCTION()

static THD_FUNCTION ( GpsThreadEntryPoint  ,
arg   
)
static

Definition at line 73 of file gps_uart.cpp.

73 {
74 (void) arg;
75 chRegSetThreadName("GPS thread");
76
77 int count = 0;
78
79 while (true) {
80 msg_t charbuf = streamGet(GPS_SERIAL_DEVICE);
81 if (charbuf == 10 || count == GPS_MAX_STRING) { // if 0xD,0xA or limit
82 if (count >= 1)
83 gps_str[--count] = '\0'; // delete 0xD
84
85 // scheduleMsg(&logger, "got GPS [%s]", gps_str);
86
87 // 'gps_str' string completed
89 memset(&gps_str, '\0', GPS_MAX_STRING); // clear buffer
90 count = 0;
91 } else {
92 gps_str[count++] = charbuf;
93 }
94 }
95}
static char gps_str[GPS_MAX_STRING]
Definition gps_uart.cpp:71
static void onGpsMessage(const char *const buffer)
Definition gps_uart.cpp:56
uint16_t count
Definition tunerstudio.h:1
Here is the call graph for this function:

◆ THD_WORKING_AREA()

static THD_WORKING_AREA ( gpsThreadStack  ,
UTILITY_THREAD_STACK_SIZE   
)
static

Variable Documentation

◆ gps_str

char gps_str[GPS_MAX_STRING]
static

Definition at line 71 of file gps_uart.cpp.

Referenced by THD_FUNCTION().

◆ GPSdata

loc_t GPSdata
static

Definition at line 30 of file gps_uart.cpp.

Referenced by getCurrentSpeed(), onGpsMessage(), and printGpsInfo().

◆ gpsMessageCount

int gpsMessageCount = 0
static

Definition at line 33 of file gps_uart.cpp.

Referenced by onGpsMessage(), and printGpsInfo().

◆ GPSserialConfig

SerialConfig GPSserialConfig = { GPS_SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }
static

Definition at line 26 of file gps_uart.cpp.

26{ GPS_SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };

Referenced by initGps().

◆ lastDateTime

efidatetime_t lastDateTime
static

Definition at line 31 of file gps_uart.cpp.

Referenced by onGpsMessage().

◆ uartErrors

int uartErrors = 0
static

Definition at line 34 of file gps_uart.cpp.

Referenced by printGpsInfo().

Go to the source code of this file.