mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
GPS update
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
- - With speed optimizations by RogueMaster.
|
||||
- - Rename the [minimal animation file](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/assets/resources/dolphin/manifest.txt.exampleMin) to see it, or [RM select](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/assets/resources/dolphin/manifest.txt.exampleRM) if you have copied over [the RM select](https://github.com/RogueMaster/awesome-flipperzero-withModules/tree/rogue_main/dolphin-RMselect) animations.
|
||||
- Updated: [i2c Tools (By NaejEL)](https://github.com/NaejEL/flipperzero-i2ctools)
|
||||
- Updated: [GPS (By ezod)](https://github.com/ezod/flipperzero-gps) `Req: NMEA 0183`
|
||||
|
||||
<details>
|
||||
<summary><B>TO DO / REMOVED</b></summary><br/>
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
# GPS for Flipper Zero
|
||||
|
||||
[Original link](https://github.com/ezod/flipperzero-gps)
|
||||
A simple Flipper Zero application for NMEA 0183 serial GPS modules, such as the
|
||||
[Adafruit Ultimate GPS Breakout].
|
||||
|
||||
A simple Flipper Zero application for NMEA 0183 serial GPS modules, such as the [Adafruit Ultimate GPS Breakout].
|
||||

|
||||
|
||||
Heavy lifting (NMEA parsing) provided by [minmea], which is included in this repository.
|
||||
Heavy lifting (NMEA parsing) provided by [minmea], which is included in this
|
||||
repository.
|
||||
|
||||
## Hardware Setup
|
||||
|
||||
Connect the GPS module to power and the USART using GPIO pins 9 (3.3V), 11 (GND), 13 (TX), and 14 (RX), as appropriate.
|
||||
Connect the GPS module to power and the USART using GPIO pins 9 (3.3V), 11
|
||||
(GND), 13 (TX), and 14 (RX), as appropriate.
|
||||
|
||||

|
||||
|
||||
## Building the FAP
|
||||
|
||||
1. Clone the [flipperzero-firmware] repository.
|
||||
2. Create a symbolic link in `applications_user` named `gps`, pointing to this
|
||||
repository.
|
||||
3. Compile with `./fbt fap_gps`.
|
||||
4. Copy `build/f7-firmware-D/.extapps/gps.fap` to `apps/Tools` on the SD card
|
||||
(directly or using [qFlipper]).
|
||||
|
||||
## Contributing
|
||||
|
||||
This project was a learning exercise and is more or less "complete" from my
|
||||
perspective, but I will happily accept pull requests that improve and enhance
|
||||
the functionality for others.
|
||||
|
||||
Currently, the app only parses RMC and GGA sentences, and displays a subset of
|
||||
the data that fits on the screen. The UART is also hard-coded to 9600 baud.
|
||||
These limitations are largely driven by the GPS module I have to work with. A
|
||||
more elaborate UI with scrolling or multiple screens, as well as a configurable
|
||||
baud rate, may be useful for other GPS modules.
|
||||
|
||||
[Adafruit Ultimate GPS Breakout]: https://www.adafruit.com/product/746
|
||||
[minmea]: https://github.com/kosma/minmea
|
||||
[flipperzero-firmware]: https://github.com/flipperdevices/flipperzero-firmware
|
||||
[qFlipper]: https://flipperzero.one/update
|
||||
|
||||
@@ -4,118 +4,134 @@
|
||||
#include <gui/gui.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
typedef enum
|
||||
{
|
||||
EventTypeTick,
|
||||
EventTypeKey,
|
||||
} EventType;
|
||||
|
||||
typedef struct {
|
||||
EventType type;
|
||||
InputEvent input;
|
||||
typedef struct
|
||||
{
|
||||
EventType type;
|
||||
InputEvent input;
|
||||
} PluginEvent;
|
||||
|
||||
static void render_callback(Canvas* const canvas, void* context) {
|
||||
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
||||
if(gps_uart == NULL) {
|
||||
return;
|
||||
}
|
||||
static void render_callback(Canvas* const canvas, void* context)
|
||||
{
|
||||
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
||||
if (gps_uart == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
char buffer[64];
|
||||
snprintf(buffer, 64, "LAT: %f", (double)gps_uart->status.latitude);
|
||||
canvas_draw_str_aligned(canvas, 10, 10, AlignLeft, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "LON: %f", (double)gps_uart->status.longitude);
|
||||
canvas_draw_str_aligned(canvas, 10, 20, AlignLeft, AlignBottom, buffer);
|
||||
snprintf(
|
||||
buffer,
|
||||
64,
|
||||
"C/S: %.1f / %.2fkn",
|
||||
(double)gps_uart->status.course,
|
||||
(double)gps_uart->status.speed);
|
||||
canvas_draw_str_aligned(canvas, 10, 30, AlignLeft, AlignBottom, buffer);
|
||||
snprintf(
|
||||
buffer,
|
||||
64,
|
||||
"ALT: %.1f %c",
|
||||
(double)gps_uart->status.altitude,
|
||||
gps_uart->status.altitude_units);
|
||||
canvas_draw_str_aligned(canvas, 10, 40, AlignLeft, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "FIX: %d", gps_uart->status.fix_quality);
|
||||
canvas_draw_str_aligned(canvas, 10, 50, AlignLeft, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "SAT: %d", gps_uart->status.satellites_tracked);
|
||||
canvas_draw_str_aligned(canvas, 10, 60, AlignLeft, AlignBottom, buffer);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 32, 8, AlignCenter, AlignBottom, "Latitude");
|
||||
canvas_draw_str_aligned(canvas, 96, 8, AlignCenter, AlignBottom, "Longitude");
|
||||
canvas_draw_str_aligned(canvas, 21, 30, AlignCenter, AlignBottom, "Course");
|
||||
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignBottom, "Speed");
|
||||
canvas_draw_str_aligned(canvas, 107, 30, AlignCenter, AlignBottom, "Altitude");
|
||||
canvas_draw_str_aligned(canvas, 32, 52, AlignCenter, AlignBottom, "Satellites");
|
||||
canvas_draw_str_aligned(canvas, 96, 52, AlignCenter, AlignBottom, "Last Fix");
|
||||
|
||||
release_mutex((ValueMutex*)context, gps_uart);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
char buffer[64];
|
||||
snprintf(buffer, 64, "%f", (double)gps_uart->status.latitude);
|
||||
canvas_draw_str_aligned(canvas, 32, 18, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%f", (double)gps_uart->status.longitude);
|
||||
canvas_draw_str_aligned(canvas, 96, 18, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%.1f", (double)gps_uart->status.course);
|
||||
canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
|
||||
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%.1f %c", (double)gps_uart->status.altitude, tolower(gps_uart->status.altitude_units));
|
||||
canvas_draw_str_aligned(canvas, 107, 40, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%d", gps_uart->status.satellites_tracked);
|
||||
canvas_draw_str_aligned(canvas, 32, 62, AlignCenter, AlignBottom, buffer);
|
||||
snprintf(buffer, 64, "%02d:%02d:%02d UTC", gps_uart->status.time_hours, gps_uart->status.time_minutes,
|
||||
gps_uart->status.time_seconds);
|
||||
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
|
||||
|
||||
release_mutex((ValueMutex*)context, gps_uart);
|
||||
}
|
||||
|
||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
furi_assert(event_queue);
|
||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue)
|
||||
{
|
||||
furi_assert(event_queue);
|
||||
|
||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
|
||||
int32_t gps_app(void* p) {
|
||||
UNUSED(p);
|
||||
int32_t gps_app(void* p)
|
||||
{
|
||||
UNUSED(p);
|
||||
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||
|
||||
GpsUart* gps_uart = gps_uart_enable();
|
||||
GpsUart* gps_uart = gps_uart_enable();
|
||||
|
||||
ValueMutex gps_uart_mutex;
|
||||
if(!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart))) {
|
||||
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
||||
free(gps_uart);
|
||||
return 255;
|
||||
}
|
||||
ValueMutex gps_uart_mutex;
|
||||
if (!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart)))
|
||||
{
|
||||
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
||||
free(gps_uart);
|
||||
return 255;
|
||||
}
|
||||
|
||||
// set system callbacks
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, render_callback, &gps_uart_mutex);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
// set system callbacks
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, render_callback, &gps_uart_mutex);
|
||||
view_port_input_callback_set(view_port, input_callback, event_queue);
|
||||
|
||||
// open GUI and register view_port
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
// open GUI and register view_port
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
PluginEvent event;
|
||||
for(bool processing = true; processing;) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
PluginEvent event;
|
||||
for (bool processing = true; processing;)
|
||||
{
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
|
||||
GpsUart* gps_uart = (GpsUart*)acquire_mutex_block(&gps_uart_mutex);
|
||||
GpsUart* gps_uart = (GpsUart*)acquire_mutex_block(&gps_uart_mutex);
|
||||
|
||||
if(event_status == FuriStatusOk) {
|
||||
// press events
|
||||
if(event.type == EventTypeKey) {
|
||||
if(event.input.type == InputTypePress) {
|
||||
switch(event.input.key) {
|
||||
case InputKeyUp:
|
||||
case InputKeyDown:
|
||||
case InputKeyRight:
|
||||
case InputKeyLeft:
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack:
|
||||
processing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
||||
if (event_status == FuriStatusOk)
|
||||
{
|
||||
// press events
|
||||
if (event.type == EventTypeKey)
|
||||
{
|
||||
if (event.input.type == InputTypePress)
|
||||
{
|
||||
switch (event.input.key)
|
||||
{
|
||||
case InputKeyUp:
|
||||
case InputKeyDown:
|
||||
case InputKeyRight:
|
||||
case InputKeyLeft:
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack:
|
||||
processing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
view_port_update(view_port);
|
||||
release_mutex(&gps_uart_mutex, gps_uart);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
||||
}
|
||||
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
furi_record_close("gui");
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
delete_mutex(&gps_uart_mutex);
|
||||
gps_uart_disable(gps_uart);
|
||||
view_port_update(view_port);
|
||||
release_mutex(&gps_uart_mutex, gps_uart);
|
||||
}
|
||||
|
||||
return 0;
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
furi_record_close("gui");
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
delete_mutex(&gps_uart_mutex);
|
||||
gps_uart_disable(gps_uart);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3,153 +3,194 @@
|
||||
#include "minmea.h"
|
||||
#include "gps_uart.h"
|
||||
|
||||
typedef enum {
|
||||
WorkerEvtStop = (1 << 0),
|
||||
WorkerEvtRxDone = (1 << 1),
|
||||
typedef enum
|
||||
{
|
||||
WorkerEvtStop = (1 << 0),
|
||||
WorkerEvtRxDone = (1 << 1),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
||||
|
||||
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||
GpsUart* gps_uart = (GpsUart*)context;
|
||||
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context)
|
||||
{
|
||||
GpsUart* gps_uart = (GpsUart*)context;
|
||||
|
||||
if(ev == UartIrqEventRXNE) {
|
||||
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
||||
}
|
||||
if (ev == UartIrqEventRXNE)
|
||||
{
|
||||
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
||||
}
|
||||
}
|
||||
|
||||
static void gps_uart_serial_init(GpsUart* gps_uart) {
|
||||
furi_hal_console_disable();
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
||||
static void gps_uart_serial_init(GpsUart* gps_uart)
|
||||
{
|
||||
furi_hal_console_disable();
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
||||
}
|
||||
|
||||
static void gps_uart_serial_deinit(GpsUart* gps_uart) {
|
||||
UNUSED(gps_uart);
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||
furi_hal_console_enable();
|
||||
static void gps_uart_serial_deinit(GpsUart* gps_uart)
|
||||
{
|
||||
UNUSED(gps_uart);
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||
furi_hal_console_enable();
|
||||
}
|
||||
|
||||
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
|
||||
switch(minmea_sentence_id(line, false)) {
|
||||
case MINMEA_SENTENCE_RMC: {
|
||||
struct minmea_sentence_rmc frame;
|
||||
if(minmea_parse_rmc(&frame, line)) {
|
||||
gps_uart->status.valid = frame.valid;
|
||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||
gps_uart->status.speed = minmea_tofloat(&frame.speed);
|
||||
gps_uart->status.course = minmea_tofloat(&frame.course);
|
||||
}
|
||||
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
|
||||
{
|
||||
switch (minmea_sentence_id(line, false))
|
||||
{
|
||||
case MINMEA_SENTENCE_RMC:
|
||||
{
|
||||
struct minmea_sentence_rmc frame;
|
||||
if (minmea_parse_rmc(&frame, line))
|
||||
{
|
||||
gps_uart->status.valid = frame.valid;
|
||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||
gps_uart->status.speed = minmea_tofloat(&frame.speed);
|
||||
gps_uart->status.course = minmea_tofloat(&frame.course);
|
||||
gps_uart->status.time_hours = frame.time.hours;
|
||||
gps_uart->status.time_minutes = frame.time.minutes;
|
||||
gps_uart->status.time_seconds = frame.time.seconds;
|
||||
|
||||
notification_message_block(gps_uart->notifications, &sequence_blink_green_10);
|
||||
}
|
||||
} break;
|
||||
|
||||
case MINMEA_SENTENCE_GGA: {
|
||||
struct minmea_sentence_gga frame;
|
||||
if(minmea_parse_gga(&frame, line)) {
|
||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
||||
gps_uart->status.altitude_units = frame.altitude_units;
|
||||
gps_uart->status.fix_quality = frame.fix_quality;
|
||||
gps_uart->status.satellites_tracked = frame.satellites_tracked;
|
||||
}
|
||||
case MINMEA_SENTENCE_GGA:
|
||||
{
|
||||
struct minmea_sentence_gga frame;
|
||||
if (minmea_parse_gga(&frame, line))
|
||||
{
|
||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
||||
gps_uart->status.altitude_units = frame.altitude_units;
|
||||
gps_uart->status.fix_quality = frame.fix_quality;
|
||||
gps_uart->status.satellites_tracked = frame.satellites_tracked;
|
||||
gps_uart->status.time_hours = frame.time.hours;
|
||||
gps_uart->status.time_minutes = frame.time.minutes;
|
||||
gps_uart->status.time_seconds = frame.time.seconds;
|
||||
|
||||
notification_message_block(gps_uart->notifications, &sequence_blink_magenta_10);
|
||||
}
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t gps_uart_worker(void* context) {
|
||||
GpsUart* gps_uart = (GpsUart*)context;
|
||||
static int32_t gps_uart_worker(void* context)
|
||||
{
|
||||
GpsUart* gps_uart = (GpsUart*)context;
|
||||
|
||||
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
||||
size_t rx_offset = 0;
|
||||
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
||||
size_t rx_offset = 0;
|
||||
|
||||
gps_uart_serial_init(gps_uart);
|
||||
gps_uart_serial_init(gps_uart);
|
||||
|
||||
while(1) {
|
||||
uint32_t events =
|
||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_check((events & FuriFlagError) == 0);
|
||||
while (1)
|
||||
{
|
||||
uint32_t events =
|
||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_check((events & FuriFlagError) == 0);
|
||||
|
||||
if(events & WorkerEvtStop) {
|
||||
break;
|
||||
}
|
||||
if (events & WorkerEvtStop)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(events & WorkerEvtRxDone) {
|
||||
size_t len = 0;
|
||||
do {
|
||||
len = furi_stream_buffer_receive(
|
||||
gps_uart->rx_stream,
|
||||
gps_uart->rx_buf + rx_offset,
|
||||
RX_BUF_SIZE - 1 - rx_offset,
|
||||
0);
|
||||
if(len > 0) {
|
||||
rx_offset += len;
|
||||
gps_uart->rx_buf[rx_offset] = '\0';
|
||||
if (events & WorkerEvtRxDone)
|
||||
{
|
||||
size_t len = 0;
|
||||
do
|
||||
{
|
||||
len = furi_stream_buffer_receive(gps_uart->rx_stream, gps_uart->rx_buf + rx_offset, RX_BUF_SIZE - 1 - rx_offset,
|
||||
0);
|
||||
if (len > 0)
|
||||
{
|
||||
rx_offset += len;
|
||||
gps_uart->rx_buf[rx_offset] = '\0';
|
||||
|
||||
char* line_current = (char*)gps_uart->rx_buf;
|
||||
while(1) {
|
||||
while(*line_current == '\0' &&
|
||||
line_current < (char*)gps_uart->rx_buf + rx_offset - 1) {
|
||||
line_current++;
|
||||
}
|
||||
char * line_current = (char *)gps_uart->rx_buf;
|
||||
while (1)
|
||||
{
|
||||
while (*line_current == '\0' && line_current < (char *)gps_uart->rx_buf + rx_offset - 1)
|
||||
{
|
||||
line_current++;
|
||||
}
|
||||
|
||||
char* newline = strchr(line_current, '\n');
|
||||
if(newline) {
|
||||
*newline = '\0';
|
||||
gps_uart_parse_nmea(gps_uart, line_current);
|
||||
line_current = newline + 1;
|
||||
} else {
|
||||
if(line_current > (char*)gps_uart->rx_buf) {
|
||||
rx_offset = 0;
|
||||
while(*line_current) {
|
||||
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
char * newline = strchr(line_current, '\n');
|
||||
if (newline)
|
||||
{
|
||||
*newline = '\0';
|
||||
gps_uart_parse_nmea(gps_uart, line_current);
|
||||
line_current = newline + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line_current > (char *)gps_uart->rx_buf)
|
||||
{
|
||||
rx_offset = 0;
|
||||
while (*line_current)
|
||||
{
|
||||
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
||||
}
|
||||
} while(len > 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (len > 0);
|
||||
}
|
||||
}
|
||||
|
||||
gps_uart_serial_deinit(gps_uart);
|
||||
furi_stream_buffer_free(gps_uart->rx_stream);
|
||||
gps_uart_serial_deinit(gps_uart);
|
||||
furi_stream_buffer_free(gps_uart->rx_stream);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
GpsUart* gps_uart_enable() {
|
||||
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
||||
GpsUart* gps_uart_enable()
|
||||
{
|
||||
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
||||
|
||||
gps_uart->status.valid = false;
|
||||
gps_uart->status.latitude = 0.0;
|
||||
gps_uart->status.longitude = 0.0;
|
||||
gps_uart->status.speed = 0.0;
|
||||
gps_uart->status.course = 0.0;
|
||||
gps_uart->status.altitude = 0.0;
|
||||
gps_uart->status.altitude_units = ' ';
|
||||
gps_uart->status.fix_quality = 0;
|
||||
gps_uart->status.satellites_tracked = 0;
|
||||
gps_uart->status.valid = false;
|
||||
gps_uart->status.latitude = 0.0;
|
||||
gps_uart->status.longitude = 0.0;
|
||||
gps_uart->status.speed = 0.0;
|
||||
gps_uart->status.course = 0.0;
|
||||
gps_uart->status.altitude = 0.0;
|
||||
gps_uart->status.altitude_units = ' ';
|
||||
gps_uart->status.fix_quality = 0;
|
||||
gps_uart->status.satellites_tracked = 0;
|
||||
gps_uart->status.time_hours = 0;
|
||||
gps_uart->status.time_minutes = 0;
|
||||
gps_uart->status.time_seconds = 0;
|
||||
|
||||
gps_uart->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
||||
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
||||
furi_thread_set_context(gps_uart->thread, gps_uart);
|
||||
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
||||
gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
furi_thread_start(gps_uart->thread);
|
||||
return gps_uart;
|
||||
gps_uart->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(gps_uart->thread, "GpsUartWorker");
|
||||
furi_thread_set_stack_size(gps_uart->thread, 1024);
|
||||
furi_thread_set_context(gps_uart->thread, gps_uart);
|
||||
furi_thread_set_callback(gps_uart->thread, gps_uart_worker);
|
||||
|
||||
furi_thread_start(gps_uart->thread);
|
||||
return gps_uart;
|
||||
}
|
||||
|
||||
void gps_uart_disable(GpsUart* gps_uart) {
|
||||
furi_assert(gps_uart);
|
||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
||||
furi_thread_join(gps_uart->thread);
|
||||
furi_thread_free(gps_uart->thread);
|
||||
free(gps_uart);
|
||||
void gps_uart_disable(GpsUart* gps_uart)
|
||||
{
|
||||
furi_assert(gps_uart);
|
||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
||||
furi_thread_join(gps_uart->thread);
|
||||
furi_thread_free(gps_uart->thread);
|
||||
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
free(gps_uart);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#define GPS_BAUDRATE 9600
|
||||
#define RX_BUF_SIZE 1024
|
||||
|
||||
typedef struct {
|
||||
bool valid;
|
||||
float latitude;
|
||||
float longitude;
|
||||
float speed;
|
||||
float course;
|
||||
float altitude;
|
||||
char altitude_units;
|
||||
int fix_quality;
|
||||
int satellites_tracked;
|
||||
typedef struct
|
||||
{
|
||||
bool valid;
|
||||
float latitude;
|
||||
float longitude;
|
||||
float speed;
|
||||
float course;
|
||||
float altitude;
|
||||
char altitude_units;
|
||||
int fix_quality;
|
||||
int satellites_tracked;
|
||||
int time_hours;
|
||||
int time_minutes;
|
||||
int time_seconds;
|
||||
} GpsStatus;
|
||||
|
||||
typedef struct {
|
||||
FuriThread* thread;
|
||||
FuriStreamBuffer* rx_stream;
|
||||
uint8_t rx_buf[RX_BUF_SIZE];
|
||||
typedef struct
|
||||
{
|
||||
FuriThread* thread;
|
||||
FuriStreamBuffer* rx_stream;
|
||||
uint8_t rx_buf[RX_BUF_SIZE];
|
||||
|
||||
GpsStatus status;
|
||||
NotificationApp* notifications;
|
||||
|
||||
GpsStatus status;
|
||||
} GpsUart;
|
||||
|
||||
GpsUart* gps_uart_enable();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -87,10 +87,8 @@ struct minmea_sentence_gga {
|
||||
int fix_quality;
|
||||
int satellites_tracked;
|
||||
struct minmea_float hdop;
|
||||
struct minmea_float altitude;
|
||||
char altitude_units;
|
||||
struct minmea_float height;
|
||||
char height_units;
|
||||
struct minmea_float altitude; char altitude_units;
|
||||
struct minmea_float height; char height_units;
|
||||
struct minmea_float dgps_age;
|
||||
};
|
||||
|
||||
@@ -181,22 +179,22 @@ struct minmea_sentence_zda {
|
||||
/**
|
||||
* Calculate raw sentence checksum. Does not check sentence integrity.
|
||||
*/
|
||||
uint8_t minmea_checksum(const char* sentence);
|
||||
uint8_t minmea_checksum(const char *sentence);
|
||||
|
||||
/**
|
||||
* Check sentence validity and checksum. Returns true for valid sentences.
|
||||
*/
|
||||
bool minmea_check(const char* sentence, bool strict);
|
||||
bool minmea_check(const char *sentence, bool strict);
|
||||
|
||||
/**
|
||||
* Determine talker identifier.
|
||||
*/
|
||||
bool minmea_talker_id(char talker[3], const char* sentence);
|
||||
bool minmea_talker_id(char talker[3], const char *sentence);
|
||||
|
||||
/**
|
||||
* Determine sentence identifier.
|
||||
*/
|
||||
enum minmea_sentence_id minmea_sentence_id(const char* sentence, bool strict);
|
||||
enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict);
|
||||
|
||||
/**
|
||||
* Scanf-like processor for NMEA sentences. Supports the following formats:
|
||||
@@ -212,70 +210,72 @@ enum minmea_sentence_id minmea_sentence_id(const char* sentence, bool strict);
|
||||
* ; - following fields are optional
|
||||
* Returns true on success. See library source code for details.
|
||||
*/
|
||||
bool minmea_scan(const char* sentence, const char* format, ...);
|
||||
bool minmea_scan(const char *sentence, const char *format, ...);
|
||||
|
||||
/*
|
||||
* Parse a specific type of sentence. Return true on success.
|
||||
*/
|
||||
bool minmea_parse_gbs(struct minmea_sentence_gbs* frame, const char* sentence);
|
||||
bool minmea_parse_rmc(struct minmea_sentence_rmc* frame, const char* sentence);
|
||||
bool minmea_parse_gga(struct minmea_sentence_gga* frame, const char* sentence);
|
||||
bool minmea_parse_gsa(struct minmea_sentence_gsa* frame, const char* sentence);
|
||||
bool minmea_parse_gll(struct minmea_sentence_gll* frame, const char* sentence);
|
||||
bool minmea_parse_gst(struct minmea_sentence_gst* frame, const char* sentence);
|
||||
bool minmea_parse_gsv(struct minmea_sentence_gsv* frame, const char* sentence);
|
||||
bool minmea_parse_vtg(struct minmea_sentence_vtg* frame, const char* sentence);
|
||||
bool minmea_parse_zda(struct minmea_sentence_zda* frame, const char* sentence);
|
||||
bool minmea_parse_gbs(struct minmea_sentence_gbs *frame, const char *sentence);
|
||||
bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence);
|
||||
bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence);
|
||||
bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence);
|
||||
bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence);
|
||||
bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence);
|
||||
bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence);
|
||||
bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence);
|
||||
bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence);
|
||||
|
||||
/**
|
||||
* Convert GPS UTC date/time representation to a UNIX calendar time.
|
||||
*/
|
||||
int minmea_getdatetime(
|
||||
struct tm* tm,
|
||||
const struct minmea_date* date,
|
||||
const struct minmea_time* time_);
|
||||
int minmea_getdatetime(struct tm *tm, const struct minmea_date *date, const struct minmea_time *time_);
|
||||
|
||||
/**
|
||||
* Convert GPS UTC date/time representation to a UNIX timestamp.
|
||||
*/
|
||||
int minmea_gettime(
|
||||
struct timespec* ts,
|
||||
const struct minmea_date* date,
|
||||
const struct minmea_time* time_);
|
||||
int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_);
|
||||
|
||||
/**
|
||||
* Rescale a fixed-point value to a different scale. Rounds towards zero.
|
||||
*/
|
||||
static inline int_least32_t minmea_rescale(const struct minmea_float* f, int_least32_t new_scale) {
|
||||
if(f->scale == 0) return 0;
|
||||
if(f->scale == new_scale) return f->value;
|
||||
if(f->scale > new_scale)
|
||||
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale / new_scale / 2) /
|
||||
(f->scale / new_scale);
|
||||
static inline int_least32_t minmea_rescale(const struct minmea_float *f, int_least32_t new_scale)
|
||||
{
|
||||
if (f->scale == 0)
|
||||
return 0;
|
||||
if (f->scale == new_scale)
|
||||
return f->value;
|
||||
if (f->scale > new_scale)
|
||||
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale/new_scale/2) / (f->scale/new_scale);
|
||||
else
|
||||
return f->value * (new_scale / f->scale);
|
||||
return f->value * (new_scale/f->scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a fixed-point value to a floating-point value.
|
||||
* Returns NaN for "unknown" values.
|
||||
*/
|
||||
static inline float minmea_tofloat(const struct minmea_float* f) {
|
||||
if(f->scale == 0) return NAN;
|
||||
return (float)f->value / (float)f->scale;
|
||||
static inline float minmea_tofloat(const struct minmea_float *f)
|
||||
{
|
||||
if (f->scale == 0)
|
||||
return NAN;
|
||||
return (float) f->value / (float) f->scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a raw coordinate to a floating point DD.DDD... value.
|
||||
* Returns NaN for "unknown" values.
|
||||
*/
|
||||
static inline float minmea_tocoord(const struct minmea_float* f) {
|
||||
if(f->scale == 0) return NAN;
|
||||
if(f->scale > (INT_LEAST32_MAX / 100)) return NAN;
|
||||
if(f->scale < (INT_LEAST32_MIN / 100)) return NAN;
|
||||
static inline float minmea_tocoord(const struct minmea_float *f)
|
||||
{
|
||||
if (f->scale == 0)
|
||||
return NAN;
|
||||
if (f->scale > (INT_LEAST32_MAX / 100))
|
||||
return NAN;
|
||||
if (f->scale < (INT_LEAST32_MIN / 100))
|
||||
return NAN;
|
||||
int_least32_t degrees = f->value / (f->scale * 100);
|
||||
int_least32_t minutes = f->value % (f->scale * 100);
|
||||
return (float)degrees + (float)minutes / (60 * f->scale);
|
||||
return (float) degrees + (float) minutes / (60 * f->scale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +283,7 @@ static inline float minmea_tocoord(const struct minmea_float* f) {
|
||||
* sentence data field.
|
||||
*/
|
||||
static inline bool minmea_isfield(char c) {
|
||||
return isprint((unsigned char)c) && c != ',' && c != '*';
|
||||
return isprint((unsigned char) c) && c != ',' && c != '*';
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
BIN
applications/plugins/gps_nmea_uart/ui.png
Normal file
BIN
applications/plugins/gps_nmea_uart/ui.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
BIN
applications/plugins/gps_nmea_uart/wiring.png
Normal file
BIN
applications/plugins/gps_nmea_uart/wiring.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
Reference in New Issue
Block a user