mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 21:28:36 -07:00
fmt
This commit is contained in:
@@ -4,23 +4,19 @@
|
|||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
EventTypeTick,
|
EventTypeTick,
|
||||||
EventTypeKey,
|
EventTypeKey,
|
||||||
} EventType;
|
} EventType;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
EventType type;
|
EventType type;
|
||||||
InputEvent input;
|
InputEvent input;
|
||||||
} PluginEvent;
|
} PluginEvent;
|
||||||
|
|
||||||
static void render_callback(Canvas* const canvas, void* context)
|
static void render_callback(Canvas* const canvas, void* context) {
|
||||||
{
|
|
||||||
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
const GpsUart* gps_uart = acquire_mutex((ValueMutex*)context, 25);
|
||||||
if (gps_uart == NULL)
|
if(gps_uart == NULL) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,27 +39,35 @@ static void render_callback(Canvas* const canvas, void* context)
|
|||||||
canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 21, 40, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
|
snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed);
|
||||||
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignBottom, buffer);
|
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));
|
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);
|
canvas_draw_str_aligned(canvas, 107, 40, AlignCenter, AlignBottom, buffer);
|
||||||
snprintf(buffer, 64, "%d", gps_uart->status.satellites_tracked);
|
snprintf(buffer, 64, "%d", gps_uart->status.satellites_tracked);
|
||||||
canvas_draw_str_aligned(canvas, 32, 62, AlignCenter, AlignBottom, buffer);
|
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,
|
snprintf(
|
||||||
|
buffer,
|
||||||
|
64,
|
||||||
|
"%02d:%02d:%02d UTC",
|
||||||
|
gps_uart->status.time_hours,
|
||||||
|
gps_uart->status.time_minutes,
|
||||||
gps_uart->status.time_seconds);
|
gps_uart->status.time_seconds);
|
||||||
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 96, 62, AlignCenter, AlignBottom, buffer);
|
||||||
|
|
||||||
release_mutex((ValueMutex*)context, gps_uart);
|
release_mutex((ValueMutex*)context, gps_uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue)
|
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||||
{
|
|
||||||
furi_assert(event_queue);
|
furi_assert(event_queue);
|
||||||
|
|
||||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t gps_app(void* p)
|
int32_t gps_app(void* p) {
|
||||||
{
|
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
|
||||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||||
@@ -71,8 +75,7 @@ int32_t gps_app(void* p)
|
|||||||
GpsUart* gps_uart = gps_uart_enable();
|
GpsUart* gps_uart = gps_uart_enable();
|
||||||
|
|
||||||
ValueMutex gps_uart_mutex;
|
ValueMutex gps_uart_mutex;
|
||||||
if (!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart)))
|
if(!init_mutex(&gps_uart_mutex, gps_uart, sizeof(GpsUart))) {
|
||||||
{
|
|
||||||
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
FURI_LOG_E("GPS", "cannot create mutex\r\n");
|
||||||
free(gps_uart);
|
free(gps_uart);
|
||||||
return 255;
|
return 255;
|
||||||
@@ -88,21 +91,16 @@ int32_t gps_app(void* p)
|
|||||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||||
|
|
||||||
PluginEvent event;
|
PluginEvent event;
|
||||||
for (bool processing = true; processing;)
|
for(bool processing = true; processing;) {
|
||||||
{
|
|
||||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
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)
|
if(event_status == FuriStatusOk) {
|
||||||
{
|
|
||||||
// press events
|
// press events
|
||||||
if (event.type == EventTypeKey)
|
if(event.type == EventTypeKey) {
|
||||||
{
|
if(event.input.type == InputTypePress) {
|
||||||
if (event.input.type == InputTypePress)
|
switch(event.input.key) {
|
||||||
{
|
|
||||||
switch (event.input.key)
|
|
||||||
{
|
|
||||||
case InputKeyUp:
|
case InputKeyUp:
|
||||||
case InputKeyDown:
|
case InputKeyDown:
|
||||||
case InputKeyRight:
|
case InputKeyRight:
|
||||||
@@ -115,9 +113,7 @@ int32_t gps_app(void* p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
FURI_LOG_D("GPS", "FuriMessageQueue: event timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,48 +3,39 @@
|
|||||||
#include "minmea.h"
|
#include "minmea.h"
|
||||||
#include "gps_uart.h"
|
#include "gps_uart.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
WorkerEvtStop = (1 << 0),
|
WorkerEvtStop = (1 << 0),
|
||||||
WorkerEvtRxDone = (1 << 1),
|
WorkerEvtRxDone = (1 << 1),
|
||||||
} WorkerEvtFlags;
|
} WorkerEvtFlags;
|
||||||
|
|
||||||
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
||||||
|
|
||||||
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context)
|
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||||
{
|
|
||||||
GpsUart* gps_uart = (GpsUart*)context;
|
GpsUart* gps_uart = (GpsUart*)context;
|
||||||
|
|
||||||
if (ev == UartIrqEventRXNE)
|
if(ev == UartIrqEventRXNE) {
|
||||||
{
|
|
||||||
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
|
||||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_serial_init(GpsUart* gps_uart)
|
static void gps_uart_serial_init(GpsUart* gps_uart) {
|
||||||
{
|
|
||||||
furi_hal_console_disable();
|
furi_hal_console_disable();
|
||||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
|
||||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
furi_hal_uart_set_br(FuriHalUartIdUSART1, GPS_BAUDRATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_serial_deinit(GpsUart* gps_uart)
|
static void gps_uart_serial_deinit(GpsUart* gps_uart) {
|
||||||
{
|
|
||||||
UNUSED(gps_uart);
|
UNUSED(gps_uart);
|
||||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||||
furi_hal_console_enable();
|
furi_hal_console_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
|
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
|
||||||
{
|
switch(minmea_sentence_id(line, false)) {
|
||||||
switch (minmea_sentence_id(line, false))
|
case MINMEA_SENTENCE_RMC: {
|
||||||
{
|
|
||||||
case MINMEA_SENTENCE_RMC:
|
|
||||||
{
|
|
||||||
struct minmea_sentence_rmc frame;
|
struct minmea_sentence_rmc frame;
|
||||||
if (minmea_parse_rmc(&frame, line))
|
if(minmea_parse_rmc(&frame, line)) {
|
||||||
{
|
|
||||||
gps_uart->status.valid = frame.valid;
|
gps_uart->status.valid = frame.valid;
|
||||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||||
@@ -58,11 +49,9 @@ static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MINMEA_SENTENCE_GGA:
|
case MINMEA_SENTENCE_GGA: {
|
||||||
{
|
|
||||||
struct minmea_sentence_gga frame;
|
struct minmea_sentence_gga frame;
|
||||||
if (minmea_parse_gga(&frame, line))
|
if(minmea_parse_gga(&frame, line)) {
|
||||||
{
|
|
||||||
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
gps_uart->status.latitude = minmea_tocoord(&frame.latitude);
|
||||||
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
gps_uart->status.longitude = minmea_tocoord(&frame.longitude);
|
||||||
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
gps_uart->status.altitude = minmea_tofloat(&frame.altitude);
|
||||||
@@ -82,8 +71,7 @@ static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t gps_uart_worker(void* context)
|
static int32_t gps_uart_worker(void* context) {
|
||||||
{
|
|
||||||
GpsUart* gps_uart = (GpsUart*)context;
|
GpsUart* gps_uart = (GpsUart*)context;
|
||||||
|
|
||||||
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
|
||||||
@@ -91,51 +79,43 @@ static int32_t gps_uart_worker(void* context)
|
|||||||
|
|
||||||
gps_uart_serial_init(gps_uart);
|
gps_uart_serial_init(gps_uart);
|
||||||
|
|
||||||
while (1)
|
while(1) {
|
||||||
{
|
|
||||||
uint32_t events =
|
uint32_t events =
|
||||||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||||
furi_check((events & FuriFlagError) == 0);
|
furi_check((events & FuriFlagError) == 0);
|
||||||
|
|
||||||
if (events & WorkerEvtStop)
|
if(events & WorkerEvtStop) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & WorkerEvtRxDone)
|
if(events & WorkerEvtRxDone) {
|
||||||
{
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
do
|
do {
|
||||||
{
|
len = furi_stream_buffer_receive(
|
||||||
len = furi_stream_buffer_receive(gps_uart->rx_stream, gps_uart->rx_buf + rx_offset, RX_BUF_SIZE - 1 - rx_offset,
|
gps_uart->rx_stream,
|
||||||
|
gps_uart->rx_buf + rx_offset,
|
||||||
|
RX_BUF_SIZE - 1 - rx_offset,
|
||||||
0);
|
0);
|
||||||
if (len > 0)
|
if(len > 0) {
|
||||||
{
|
|
||||||
rx_offset += len;
|
rx_offset += len;
|
||||||
gps_uart->rx_buf[rx_offset] = '\0';
|
gps_uart->rx_buf[rx_offset] = '\0';
|
||||||
|
|
||||||
char* line_current = (char*)gps_uart->rx_buf;
|
char* line_current = (char*)gps_uart->rx_buf;
|
||||||
while (1)
|
while(1) {
|
||||||
{
|
while(*line_current == '\0' &&
|
||||||
while (*line_current == '\0' && line_current < (char *)gps_uart->rx_buf + rx_offset - 1)
|
line_current < (char*)gps_uart->rx_buf + rx_offset - 1) {
|
||||||
{
|
|
||||||
line_current++;
|
line_current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* newline = strchr(line_current, '\n');
|
char* newline = strchr(line_current, '\n');
|
||||||
if (newline)
|
if(newline) {
|
||||||
{
|
|
||||||
*newline = '\0';
|
*newline = '\0';
|
||||||
gps_uart_parse_nmea(gps_uart, line_current);
|
gps_uart_parse_nmea(gps_uart, line_current);
|
||||||
line_current = newline + 1;
|
line_current = newline + 1;
|
||||||
}
|
} else {
|
||||||
else
|
if(line_current > (char*)gps_uart->rx_buf) {
|
||||||
{
|
|
||||||
if (line_current > (char *)gps_uart->rx_buf)
|
|
||||||
{
|
|
||||||
rx_offset = 0;
|
rx_offset = 0;
|
||||||
while (*line_current)
|
while(*line_current) {
|
||||||
{
|
|
||||||
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
gps_uart->rx_buf[rx_offset++] = *(line_current++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,8 +123,7 @@ static int32_t gps_uart_worker(void* context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while(len > 0);
|
||||||
while (len > 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +133,7 @@ static int32_t gps_uart_worker(void* context)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpsUart* gps_uart_enable()
|
GpsUart* gps_uart_enable() {
|
||||||
{
|
|
||||||
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
GpsUart* gps_uart = malloc(sizeof(GpsUart));
|
||||||
|
|
||||||
gps_uart->status.valid = false;
|
gps_uart->status.valid = false;
|
||||||
@@ -183,8 +161,7 @@ GpsUart* gps_uart_enable()
|
|||||||
return gps_uart;
|
return gps_uart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gps_uart_disable(GpsUart* gps_uart)
|
void gps_uart_disable(GpsUart* gps_uart) {
|
||||||
{
|
|
||||||
furi_assert(gps_uart);
|
furi_assert(gps_uart);
|
||||||
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtStop);
|
||||||
furi_thread_join(gps_uart->thread);
|
furi_thread_join(gps_uart->thread);
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
#define GPS_BAUDRATE 9600
|
#define GPS_BAUDRATE 9600
|
||||||
#define RX_BUF_SIZE 1024
|
#define RX_BUF_SIZE 1024
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
bool valid;
|
bool valid;
|
||||||
float latitude;
|
float latitude;
|
||||||
float longitude;
|
float longitude;
|
||||||
@@ -22,8 +21,7 @@ typedef struct
|
|||||||
int time_seconds;
|
int time_seconds;
|
||||||
} GpsStatus;
|
} GpsStatus;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
FuriThread* thread;
|
FuriThread* thread;
|
||||||
FuriStreamBuffer* rx_stream;
|
FuriStreamBuffer* rx_stream;
|
||||||
uint8_t rx_buf[RX_BUF_SIZE];
|
uint8_t rx_buf[RX_BUF_SIZE];
|
||||||
|
|||||||
@@ -14,39 +14,30 @@
|
|||||||
|
|
||||||
#define boolstr(s) ((s) ? "true" : "false")
|
#define boolstr(s) ((s) ? "true" : "false")
|
||||||
|
|
||||||
static int hex2int(char c)
|
static int hex2int(char c) {
|
||||||
{
|
if(c >= '0' && c <= '9') return c - '0';
|
||||||
if (c >= '0' && c <= '9')
|
if(c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||||
return c - '0';
|
if(c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||||
if (c >= 'A' && c <= 'F')
|
|
||||||
return c - 'A' + 10;
|
|
||||||
if (c >= 'a' && c <= 'f')
|
|
||||||
return c - 'a' + 10;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t minmea_checksum(const char *sentence)
|
uint8_t minmea_checksum(const char* sentence) {
|
||||||
{
|
|
||||||
// Support senteces with or without the starting dollar sign.
|
// Support senteces with or without the starting dollar sign.
|
||||||
if (*sentence == '$')
|
if(*sentence == '$') sentence++;
|
||||||
sentence++;
|
|
||||||
|
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
|
|
||||||
// The optional checksum is an XOR of all bytes between "$" and "*".
|
// The optional checksum is an XOR of all bytes between "$" and "*".
|
||||||
while (*sentence && *sentence != '*')
|
while(*sentence && *sentence != '*') checksum ^= *sentence++;
|
||||||
checksum ^= *sentence++;
|
|
||||||
|
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_check(const char *sentence, bool strict)
|
bool minmea_check(const char* sentence, bool strict) {
|
||||||
{
|
|
||||||
uint8_t checksum = 0x00;
|
uint8_t checksum = 0x00;
|
||||||
|
|
||||||
// A valid sentence starts with "$".
|
// A valid sentence starts with "$".
|
||||||
if (*sentence++ != '$')
|
if(*sentence++ != '$') return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
// The optional checksum is an XOR of all bytes between "$" and "*".
|
// The optional checksum is an XOR of all bytes between "$" and "*".
|
||||||
while(*sentence && *sentence != '*' && isprint((unsigned char)*sentence))
|
while(*sentence && *sentence != '*' && isprint((unsigned char)*sentence))
|
||||||
@@ -57,16 +48,13 @@ bool minmea_check(const char *sentence, bool strict)
|
|||||||
// Extract checksum.
|
// Extract checksum.
|
||||||
sentence++;
|
sentence++;
|
||||||
int upper = hex2int(*sentence++);
|
int upper = hex2int(*sentence++);
|
||||||
if (upper == -1)
|
if(upper == -1) return false;
|
||||||
return false;
|
|
||||||
int lower = hex2int(*sentence++);
|
int lower = hex2int(*sentence++);
|
||||||
if (lower == -1)
|
if(lower == -1) return false;
|
||||||
return false;
|
|
||||||
int expected = upper << 4 | lower;
|
int expected = upper << 4 | lower;
|
||||||
|
|
||||||
// Check for checksum mismatch.
|
// Check for checksum mismatch.
|
||||||
if (checksum != expected)
|
if(checksum != expected) return false;
|
||||||
return false;
|
|
||||||
} else if(strict) {
|
} else if(strict) {
|
||||||
// Discard non-checksummed frames in strict mode.
|
// Discard non-checksummed frames in strict mode.
|
||||||
return false;
|
return false;
|
||||||
@@ -84,13 +72,11 @@ bool minmea_check(const char *sentence, bool strict)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_scan(const char *sentence, const char *format, ...)
|
bool minmea_scan(const char* sentence, const char* format, ...) {
|
||||||
{
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
bool optional = false;
|
bool optional = false;
|
||||||
|
|
||||||
if (sentence == NULL)
|
if(sentence == NULL) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
@@ -99,8 +85,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
#define next_field() \
|
#define next_field() \
|
||||||
do { \
|
do { \
|
||||||
/* Progress to the next field. */ \
|
/* Progress to the next field. */ \
|
||||||
while (minmea_isfield(*sentence)) \
|
while(minmea_isfield(*sentence)) sentence++; \
|
||||||
sentence++; \
|
|
||||||
/* Make sure there is a field there. */ \
|
/* Make sure there is a field there. */ \
|
||||||
if(*sentence == ',') { \
|
if(*sentence == ',') { \
|
||||||
sentence++; \
|
sentence++; \
|
||||||
@@ -128,8 +113,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
case 'c': { // Single character field (char).
|
case 'c': { // Single character field (char).
|
||||||
char value = '\0';
|
char value = '\0';
|
||||||
|
|
||||||
if (field && minmea_isfield(*field))
|
if(field && minmea_isfield(*field)) value = *field;
|
||||||
value = *field;
|
|
||||||
|
|
||||||
*va_arg(ap, char*) = value;
|
*va_arg(ap, char*) = value;
|
||||||
} break;
|
} break;
|
||||||
@@ -168,8 +152,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
sign = -1;
|
sign = -1;
|
||||||
} else if(isdigit((unsigned char)*field)) {
|
} else if(isdigit((unsigned char)*field)) {
|
||||||
int digit = *field - '0';
|
int digit = *field - '0';
|
||||||
if (value == -1)
|
if(value == -1) value = 0;
|
||||||
value = 0;
|
|
||||||
if(value > (INT_LEAST32_MAX - digit) / 10) {
|
if(value > (INT_LEAST32_MAX - digit) / 10) {
|
||||||
/* we ran out of bits, what do we do? */
|
/* we ran out of bits, what do we do? */
|
||||||
if(scale) {
|
if(scale) {
|
||||||
@@ -181,15 +164,13 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = (10 * value) + digit;
|
value = (10 * value) + digit;
|
||||||
if (scale)
|
if(scale) scale *= 10;
|
||||||
scale *= 10;
|
|
||||||
} else if(*field == '.' && scale == 0) {
|
} else if(*field == '.' && scale == 0) {
|
||||||
scale = 1;
|
scale = 1;
|
||||||
} else if(*field == ' ') {
|
} else if(*field == ' ') {
|
||||||
/* Allow spaces at the start of the field. Not NMEA
|
/* Allow spaces at the start of the field. Not NMEA
|
||||||
* conformant, but some modules do this. */
|
* conformant, but some modules do this. */
|
||||||
if (sign != 0 || value != -1 || scale != 0)
|
if(sign != 0 || value != -1 || scale != 0) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
} else {
|
} else {
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
}
|
}
|
||||||
@@ -197,8 +178,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sign || scale) && value == -1)
|
if((sign || scale) && value == -1) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
if(value == -1) {
|
if(value == -1) {
|
||||||
/* No digits were scanned. */
|
/* No digits were scanned. */
|
||||||
@@ -208,8 +188,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
/* No decimal point. */
|
/* No decimal point. */
|
||||||
scale = 1;
|
scale = 1;
|
||||||
}
|
}
|
||||||
if (sign)
|
if(sign) value *= sign;
|
||||||
value *= sign;
|
|
||||||
|
|
||||||
*va_arg(ap, struct minmea_float*) = (struct minmea_float){value, scale};
|
*va_arg(ap, struct minmea_float*) = (struct minmea_float){value, scale};
|
||||||
} break;
|
} break;
|
||||||
@@ -220,8 +199,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
if(field) {
|
if(field) {
|
||||||
char* endptr;
|
char* endptr;
|
||||||
value = strtol(field, &endptr, 10);
|
value = strtol(field, &endptr, 10);
|
||||||
if (minmea_isfield(*endptr))
|
if(minmea_isfield(*endptr)) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*va_arg(ap, int*) = value;
|
*va_arg(ap, int*) = value;
|
||||||
@@ -231,8 +209,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
char* buf = va_arg(ap, char*);
|
char* buf = va_arg(ap, char*);
|
||||||
|
|
||||||
if(field) {
|
if(field) {
|
||||||
while (minmea_isfield(*field))
|
while(minmea_isfield(*field)) *buf++ = *field++;
|
||||||
*buf++ = *field++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
@@ -240,14 +217,11 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
|
|
||||||
case 't': { // NMEA talker+sentence identifier (char *).
|
case 't': { // NMEA talker+sentence identifier (char *).
|
||||||
// This field is always mandatory.
|
// This field is always mandatory.
|
||||||
if (!field)
|
if(!field) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
if (field[0] != '$')
|
if(field[0] != '$') goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
for(int f = 0; f < 5; f++)
|
for(int f = 0; f < 5; f++)
|
||||||
if (!minmea_isfield(field[1+f]))
|
if(!minmea_isfield(field[1 + f])) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
char* buf = va_arg(ap, char*);
|
char* buf = va_arg(ap, char*);
|
||||||
memcpy(buf, field + 1, 5);
|
memcpy(buf, field + 1, 5);
|
||||||
@@ -262,8 +236,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
if(field && minmea_isfield(*field)) {
|
if(field && minmea_isfield(*field)) {
|
||||||
// Always six digits.
|
// Always six digits.
|
||||||
for(int f = 0; f < 6; f++)
|
for(int f = 0; f < 6; f++)
|
||||||
if (!isdigit((unsigned char) field[f]))
|
if(!isdigit((unsigned char)field[f])) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
char dArr[] = {field[0], field[1], '\0'};
|
char dArr[] = {field[0], field[1], '\0'};
|
||||||
char mArr[] = {field[2], field[3], '\0'};
|
char mArr[] = {field[2], field[3], '\0'};
|
||||||
@@ -286,8 +259,7 @@ bool minmea_scan(const char *sentence, const char *format, ...)
|
|||||||
if(field && minmea_isfield(*field)) {
|
if(field && minmea_isfield(*field)) {
|
||||||
// Minimum required: integer time.
|
// Minimum required: integer time.
|
||||||
for(int f = 0; f < 6; f++)
|
for(int f = 0; f < 6; f++)
|
||||||
if (!isdigit((unsigned char) field[f]))
|
if(!isdigit((unsigned char)field[f])) goto parse_error;
|
||||||
goto parse_error;
|
|
||||||
|
|
||||||
char hArr[] = {field[0], field[1], '\0'};
|
char hArr[] = {field[0], field[1], '\0'};
|
||||||
char iArr[] = {field[2], field[3], '\0'};
|
char iArr[] = {field[2], field[3], '\0'};
|
||||||
@@ -335,11 +307,9 @@ parse_error:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_talker_id(char talker[3], const char *sentence)
|
bool minmea_talker_id(char talker[3], const char* sentence) {
|
||||||
{
|
|
||||||
char type[6];
|
char type[6];
|
||||||
if (!minmea_scan(sentence, "t", type))
|
if(!minmea_scan(sentence, "t", type)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
talker[0] = type[0];
|
talker[0] = type[0];
|
||||||
talker[1] = type[1];
|
talker[1] = type[1];
|
||||||
@@ -348,42 +318,31 @@ bool minmea_talker_id(char talker[3], const char *sentence)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict)
|
enum minmea_sentence_id minmea_sentence_id(const char* sentence, bool strict) {
|
||||||
{
|
if(!minmea_check(sentence, strict)) return MINMEA_INVALID;
|
||||||
if (!minmea_check(sentence, strict))
|
|
||||||
return MINMEA_INVALID;
|
|
||||||
|
|
||||||
char type[6];
|
char type[6];
|
||||||
if (!minmea_scan(sentence, "t", type))
|
if(!minmea_scan(sentence, "t", type)) return MINMEA_INVALID;
|
||||||
return MINMEA_INVALID;
|
|
||||||
|
|
||||||
if (!strcmp(type+2, "GBS"))
|
if(!strcmp(type + 2, "GBS")) return MINMEA_SENTENCE_GBS;
|
||||||
return MINMEA_SENTENCE_GBS;
|
if(!strcmp(type + 2, "GGA")) return MINMEA_SENTENCE_GGA;
|
||||||
if (!strcmp(type+2, "GGA"))
|
if(!strcmp(type + 2, "GLL")) return MINMEA_SENTENCE_GLL;
|
||||||
return MINMEA_SENTENCE_GGA;
|
if(!strcmp(type + 2, "GSA")) return MINMEA_SENTENCE_GSA;
|
||||||
if (!strcmp(type+2, "GLL"))
|
if(!strcmp(type + 2, "GST")) return MINMEA_SENTENCE_GST;
|
||||||
return MINMEA_SENTENCE_GLL;
|
if(!strcmp(type + 2, "GSV")) return MINMEA_SENTENCE_GSV;
|
||||||
if (!strcmp(type+2, "GSA"))
|
if(!strcmp(type + 2, "RMC")) return MINMEA_SENTENCE_RMC;
|
||||||
return MINMEA_SENTENCE_GSA;
|
if(!strcmp(type + 2, "VTG")) return MINMEA_SENTENCE_VTG;
|
||||||
if (!strcmp(type+2, "GST"))
|
if(!strcmp(type + 2, "ZDA")) return MINMEA_SENTENCE_ZDA;
|
||||||
return MINMEA_SENTENCE_GST;
|
|
||||||
if (!strcmp(type+2, "GSV"))
|
|
||||||
return MINMEA_SENTENCE_GSV;
|
|
||||||
if (!strcmp(type+2, "RMC"))
|
|
||||||
return MINMEA_SENTENCE_RMC;
|
|
||||||
if (!strcmp(type+2, "VTG"))
|
|
||||||
return MINMEA_SENTENCE_VTG;
|
|
||||||
if (!strcmp(type+2, "ZDA"))
|
|
||||||
return MINMEA_SENTENCE_ZDA;
|
|
||||||
|
|
||||||
return MINMEA_UNKNOWN;
|
return MINMEA_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gbs(struct minmea_sentence_gbs *frame, const char *sentence)
|
bool minmea_parse_gbs(struct minmea_sentence_gbs* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GNGBS,170556.00,3.0,2.9,8.3,,,,*5C
|
// $GNGBS,170556.00,3.0,2.9,8.3,,,,*5C
|
||||||
char type[6];
|
char type[6];
|
||||||
if (!minmea_scan(sentence, "tTfffifff",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tTfffifff",
|
||||||
type,
|
type,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&frame->err_latitude,
|
&frame->err_latitude,
|
||||||
@@ -392,36 +351,37 @@ bool minmea_parse_gbs(struct minmea_sentence_gbs *frame, const char *sentence)
|
|||||||
&frame->svid,
|
&frame->svid,
|
||||||
&frame->prob,
|
&frame->prob,
|
||||||
&frame->bias,
|
&frame->bias,
|
||||||
&frame->stddev
|
&frame->stddev))
|
||||||
))
|
|
||||||
return false;
|
|
||||||
if (strcmp(type+2, "GBS"))
|
|
||||||
return false;
|
return false;
|
||||||
|
if(strcmp(type + 2, "GBS")) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence)
|
bool minmea_parse_rmc(struct minmea_sentence_rmc* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62
|
// $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62
|
||||||
char type[6];
|
char type[6];
|
||||||
char validity;
|
char validity;
|
||||||
int latitude_direction;
|
int latitude_direction;
|
||||||
int longitude_direction;
|
int longitude_direction;
|
||||||
int variation_direction;
|
int variation_direction;
|
||||||
if (!minmea_scan(sentence, "tTcfdfdffDfd",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tTcfdfdffDfd",
|
||||||
type,
|
type,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&validity,
|
&validity,
|
||||||
&frame->latitude, &latitude_direction,
|
&frame->latitude,
|
||||||
&frame->longitude, &longitude_direction,
|
&latitude_direction,
|
||||||
|
&frame->longitude,
|
||||||
|
&longitude_direction,
|
||||||
&frame->speed,
|
&frame->speed,
|
||||||
&frame->course,
|
&frame->course,
|
||||||
&frame->date,
|
&frame->date,
|
||||||
&frame->variation, &variation_direction))
|
&frame->variation,
|
||||||
return false;
|
&variation_direction))
|
||||||
if (strcmp(type+2, "RMC"))
|
|
||||||
return false;
|
return false;
|
||||||
|
if(strcmp(type + 2, "RMC")) return false;
|
||||||
|
|
||||||
frame->valid = (validity == 'A');
|
frame->valid = (validity == 'A');
|
||||||
frame->latitude.value *= latitude_direction;
|
frame->latitude.value *= latitude_direction;
|
||||||
@@ -431,27 +391,31 @@ bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence)
|
bool minmea_parse_gga(struct minmea_sentence_gga* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
|
// $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
|
||||||
char type[6];
|
char type[6];
|
||||||
int latitude_direction;
|
int latitude_direction;
|
||||||
int longitude_direction;
|
int longitude_direction;
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "tTfdfdiiffcfcf_",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tTfdfdiiffcfcf_",
|
||||||
type,
|
type,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&frame->latitude, &latitude_direction,
|
&frame->latitude,
|
||||||
&frame->longitude, &longitude_direction,
|
&latitude_direction,
|
||||||
|
&frame->longitude,
|
||||||
|
&longitude_direction,
|
||||||
&frame->fix_quality,
|
&frame->fix_quality,
|
||||||
&frame->satellites_tracked,
|
&frame->satellites_tracked,
|
||||||
&frame->hdop,
|
&frame->hdop,
|
||||||
&frame->altitude, &frame->altitude_units,
|
&frame->altitude,
|
||||||
&frame->height, &frame->height_units,
|
&frame->altitude_units,
|
||||||
|
&frame->height,
|
||||||
|
&frame->height_units,
|
||||||
&frame->dgps_age))
|
&frame->dgps_age))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "GGA"))
|
if(strcmp(type + 2, "GGA")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
frame->latitude.value *= latitude_direction;
|
frame->latitude.value *= latitude_direction;
|
||||||
frame->longitude.value *= longitude_direction;
|
frame->longitude.value *= longitude_direction;
|
||||||
@@ -459,12 +423,13 @@ bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence)
|
bool minmea_parse_gsa(struct minmea_sentence_gsa* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
|
// $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
|
||||||
char type[6];
|
char type[6];
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "tciiiiiiiiiiiiifff",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tciiiiiiiiiiiiifff",
|
||||||
type,
|
type,
|
||||||
&frame->mode,
|
&frame->mode,
|
||||||
&frame->fix_type,
|
&frame->fix_type,
|
||||||
@@ -484,29 +449,30 @@ bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence)
|
|||||||
&frame->hdop,
|
&frame->hdop,
|
||||||
&frame->vdop))
|
&frame->vdop))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "GSA"))
|
if(strcmp(type + 2, "GSA")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence)
|
bool minmea_parse_gll(struct minmea_sentence_gll* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41$;
|
// $GPGLL,3723.2475,N,12158.3416,W,161229.487,A,A*41$;
|
||||||
char type[6];
|
char type[6];
|
||||||
int latitude_direction;
|
int latitude_direction;
|
||||||
int longitude_direction;
|
int longitude_direction;
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "tfdfdTc;c",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tfdfdTc;c",
|
||||||
type,
|
type,
|
||||||
&frame->latitude, &latitude_direction,
|
&frame->latitude,
|
||||||
&frame->longitude, &longitude_direction,
|
&latitude_direction,
|
||||||
|
&frame->longitude,
|
||||||
|
&longitude_direction,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&frame->status,
|
&frame->status,
|
||||||
&frame->mode))
|
&frame->mode))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "GLL"))
|
if(strcmp(type + 2, "GLL")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
frame->latitude.value *= latitude_direction;
|
frame->latitude.value *= latitude_direction;
|
||||||
frame->longitude.value *= longitude_direction;
|
frame->longitude.value *= longitude_direction;
|
||||||
@@ -514,12 +480,13 @@ bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence)
|
bool minmea_parse_gst(struct minmea_sentence_gst* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58
|
// $GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58
|
||||||
char type[6];
|
char type[6];
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "tTfffffff",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tTfffffff",
|
||||||
type,
|
type,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&frame->rms_deviation,
|
&frame->rms_deviation,
|
||||||
@@ -530,14 +497,12 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence)
|
|||||||
&frame->longitude_error_deviation,
|
&frame->longitude_error_deviation,
|
||||||
&frame->altitude_error_deviation))
|
&frame->altitude_error_deviation))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "GST"))
|
if(strcmp(type + 2, "GST")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence)
|
bool minmea_parse_gsv(struct minmea_sentence_gsv* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74
|
// $GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74
|
||||||
// $GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D
|
// $GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D
|
||||||
// $GPGSV,4,2,11,08,51,203,30,09,45,215,28*75
|
// $GPGSV,4,2,11,08,51,203,30,09,45,215,28*75
|
||||||
@@ -545,7 +510,9 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence)
|
|||||||
// $GPGSV,4,4,13*7B
|
// $GPGSV,4,4,13*7B
|
||||||
char type[6];
|
char type[6];
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "tiii;iiiiiiiiiiiiiiii",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tiii;iiiiiiiiiiiiiiii",
|
||||||
type,
|
type,
|
||||||
&frame->total_msgs,
|
&frame->total_msgs,
|
||||||
&frame->msg_nr,
|
&frame->msg_nr,
|
||||||
@@ -565,18 +532,15 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence)
|
|||||||
&frame->sats[3].nr,
|
&frame->sats[3].nr,
|
||||||
&frame->sats[3].elevation,
|
&frame->sats[3].elevation,
|
||||||
&frame->sats[3].azimuth,
|
&frame->sats[3].azimuth,
|
||||||
&frame->sats[3].snr
|
&frame->sats[3].snr)) {
|
||||||
)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(type+2, "GSV"))
|
if(strcmp(type + 2, "GSV")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence)
|
bool minmea_parse_vtg(struct minmea_sentence_vtg* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48
|
// $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48
|
||||||
// $GPVTG,156.1,T,140.9,M,0.0,N,0.0,K*41
|
// $GPVTG,156.1,T,140.9,M,0.0,N,0.0,K*41
|
||||||
// $GPVTG,096.5,T,083.5,M,0.0,N,0.0,K,D*22
|
// $GPVTG,096.5,T,083.5,M,0.0,N,0.0,K,D*22
|
||||||
@@ -584,7 +548,9 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence)
|
|||||||
char type[6];
|
char type[6];
|
||||||
char c_true, c_magnetic, c_knots, c_kph, c_faa_mode;
|
char c_true, c_magnetic, c_knots, c_kph, c_faa_mode;
|
||||||
|
|
||||||
if (!minmea_scan(sentence, "t;fcfcfcfcc",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"t;fcfcfcfcc",
|
||||||
type,
|
type,
|
||||||
&frame->true_track_degrees,
|
&frame->true_track_degrees,
|
||||||
&c_true,
|
&c_true,
|
||||||
@@ -596,28 +562,24 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence)
|
|||||||
&c_kph,
|
&c_kph,
|
||||||
&c_faa_mode))
|
&c_faa_mode))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "VTG"))
|
if(strcmp(type + 2, "VTG")) return false;
|
||||||
return false;
|
|
||||||
// values are only valid with the accompanying characters
|
// values are only valid with the accompanying characters
|
||||||
if (c_true != 'T')
|
if(c_true != 'T') frame->true_track_degrees.scale = 0;
|
||||||
frame->true_track_degrees.scale = 0;
|
if(c_magnetic != 'M') frame->magnetic_track_degrees.scale = 0;
|
||||||
if (c_magnetic != 'M')
|
if(c_knots != 'N') frame->speed_knots.scale = 0;
|
||||||
frame->magnetic_track_degrees.scale = 0;
|
if(c_kph != 'K') frame->speed_kph.scale = 0;
|
||||||
if (c_knots != 'N')
|
|
||||||
frame->speed_knots.scale = 0;
|
|
||||||
if (c_kph != 'K')
|
|
||||||
frame->speed_kph.scale = 0;
|
|
||||||
frame->faa_mode = (enum minmea_faa_mode)c_faa_mode;
|
frame->faa_mode = (enum minmea_faa_mode)c_faa_mode;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence)
|
bool minmea_parse_zda(struct minmea_sentence_zda* frame, const char* sentence) {
|
||||||
{
|
|
||||||
// $GPZDA,201530.00,04,07,2002,00,00*60
|
// $GPZDA,201530.00,04,07,2002,00,00*60
|
||||||
char type[6];
|
char type[6];
|
||||||
|
|
||||||
if(!minmea_scan(sentence, "tTiiiii",
|
if(!minmea_scan(
|
||||||
|
sentence,
|
||||||
|
"tTiiiii",
|
||||||
type,
|
type,
|
||||||
&frame->time,
|
&frame->time,
|
||||||
&frame->date.day,
|
&frame->date.day,
|
||||||
@@ -626,22 +588,20 @@ bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence)
|
|||||||
&frame->hour_offset,
|
&frame->hour_offset,
|
||||||
&frame->minute_offset))
|
&frame->minute_offset))
|
||||||
return false;
|
return false;
|
||||||
if (strcmp(type+2, "ZDA"))
|
if(strcmp(type + 2, "ZDA")) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
// check offsets
|
// check offsets
|
||||||
if (abs(frame->hour_offset) > 13 ||
|
if(abs(frame->hour_offset) > 13 || frame->minute_offset > 59 || frame->minute_offset < 0)
|
||||||
frame->minute_offset > 59 ||
|
|
||||||
frame->minute_offset < 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int minmea_getdatetime(struct tm *tm, const struct minmea_date *date, const struct minmea_time *time_)
|
int minmea_getdatetime(
|
||||||
{
|
struct tm* tm,
|
||||||
if (date->year == -1 || time_->hours == -1)
|
const struct minmea_date* date,
|
||||||
return -1;
|
const struct minmea_time* time_) {
|
||||||
|
if(date->year == -1 || time_->hours == -1) return -1;
|
||||||
|
|
||||||
memset(tm, 0, sizeof(*tm));
|
memset(tm, 0, sizeof(*tm));
|
||||||
if(date->year < 80) {
|
if(date->year < 80) {
|
||||||
@@ -660,11 +620,12 @@ int minmea_getdatetime(struct tm *tm, const struct minmea_date *date, const stru
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
if (minmea_getdatetime(&tm, date, time_))
|
if(minmea_getdatetime(&tm, date, time_)) return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
time_t timestamp = mktime(&tm); /* See README.md if your system lacks timegm(). */
|
time_t timestamp = mktime(&tm); /* See README.md if your system lacks timegm(). */
|
||||||
if(timestamp != (time_t)-1) {
|
if(timestamp != (time_t)-1) {
|
||||||
|
|||||||
@@ -87,8 +87,10 @@ struct minmea_sentence_gga {
|
|||||||
int fix_quality;
|
int fix_quality;
|
||||||
int satellites_tracked;
|
int satellites_tracked;
|
||||||
struct minmea_float hdop;
|
struct minmea_float hdop;
|
||||||
struct minmea_float altitude; char altitude_units;
|
struct minmea_float altitude;
|
||||||
struct minmea_float height; char height_units;
|
char altitude_units;
|
||||||
|
struct minmea_float height;
|
||||||
|
char height_units;
|
||||||
struct minmea_float dgps_age;
|
struct minmea_float dgps_age;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -228,24 +230,28 @@ bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence);
|
|||||||
/**
|
/**
|
||||||
* Convert GPS UTC date/time representation to a UNIX calendar time.
|
* 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.
|
* 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.
|
* 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)
|
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 == 0)
|
if(f->scale == new_scale) return f->value;
|
||||||
return 0;
|
|
||||||
if (f->scale == new_scale)
|
|
||||||
return f->value;
|
|
||||||
if(f->scale > new_scale)
|
if(f->scale > new_scale)
|
||||||
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale/new_scale/2) / (f->scale/new_scale);
|
return (f->value + ((f->value > 0) - (f->value < 0)) * f->scale / new_scale / 2) /
|
||||||
|
(f->scale / new_scale);
|
||||||
else
|
else
|
||||||
return f->value * (new_scale / f->scale);
|
return f->value * (new_scale / f->scale);
|
||||||
}
|
}
|
||||||
@@ -254,10 +260,8 @@ static inline int_least32_t minmea_rescale(const struct minmea_float *f, int_lea
|
|||||||
* Convert a fixed-point value to a floating-point value.
|
* Convert a fixed-point value to a floating-point value.
|
||||||
* Returns NaN for "unknown" values.
|
* Returns NaN for "unknown" values.
|
||||||
*/
|
*/
|
||||||
static inline float minmea_tofloat(const struct minmea_float *f)
|
static inline float minmea_tofloat(const struct minmea_float* f) {
|
||||||
{
|
if(f->scale == 0) return NAN;
|
||||||
if (f->scale == 0)
|
|
||||||
return NAN;
|
|
||||||
return (float)f->value / (float)f->scale;
|
return (float)f->value / (float)f->scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,14 +269,10 @@ static inline float minmea_tofloat(const struct minmea_float *f)
|
|||||||
* Convert a raw coordinate to a floating point DD.DDD... value.
|
* Convert a raw coordinate to a floating point DD.DDD... value.
|
||||||
* Returns NaN for "unknown" values.
|
* Returns NaN for "unknown" values.
|
||||||
*/
|
*/
|
||||||
static inline float minmea_tocoord(const struct minmea_float *f)
|
static inline float minmea_tocoord(const struct minmea_float* f) {
|
||||||
{
|
if(f->scale == 0) return NAN;
|
||||||
if (f->scale == 0)
|
if(f->scale > (INT_LEAST32_MAX / 100)) return NAN;
|
||||||
return NAN;
|
if(f->scale < (INT_LEAST32_MIN / 100)) 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 degrees = f->value / (f->scale * 100);
|
||||||
int_least32_t minutes = 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);
|
||||||
|
|||||||
@@ -105,9 +105,9 @@ bool snake_game_init_game_from_file(SnakeState* const snake_state) {
|
|||||||
}
|
}
|
||||||
furi_string_free(file_type);
|
furi_string_free(file_type);
|
||||||
|
|
||||||
|
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
snake_state->highscore = (flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE, &temp, 1)) ? temp : 0;
|
snake_state->highscore =
|
||||||
|
(flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_HIGHSCORE, &temp, 1)) ? temp : 0;
|
||||||
flipper_format_rewind(file);
|
flipper_format_rewind(file);
|
||||||
|
|
||||||
if(!flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_KEY_LEN, &temp, 1)) {
|
if(!flipper_format_read_uint32(file, SNAKE_GAME_CONFIG_KEY_LEN, &temp, 1)) {
|
||||||
|
|||||||
@@ -242,7 +242,6 @@ static void snake_game_game_over(SnakeState* const snake_state, NotificationApp*
|
|||||||
}
|
}
|
||||||
|
|
||||||
notification_message_block(notification, &sequence_fail);
|
notification_message_block(notification, &sequence_fail);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -302,8 +301,7 @@ int32_t snake_game_app(void* p) {
|
|||||||
SnakeState* snake_state = malloc(sizeof(SnakeState));
|
SnakeState* snake_state = malloc(sizeof(SnakeState));
|
||||||
snake_state->isNewHighscore = false;
|
snake_state->isNewHighscore = false;
|
||||||
snake_state->highscore = 0;
|
snake_state->highscore = 0;
|
||||||
if(!snake_game_init_game_from_file(snake_state))
|
if(!snake_game_init_game_from_file(snake_state)) snake_game_init_game(snake_state);
|
||||||
snake_game_init_game(snake_state);
|
|
||||||
|
|
||||||
ValueMutex state_mutex;
|
ValueMutex state_mutex;
|
||||||
if(!init_mutex(&state_mutex, snake_state, sizeof(SnakeState))) {
|
if(!init_mutex(&state_mutex, snake_state, sizeof(SnakeState))) {
|
||||||
@@ -376,8 +374,7 @@ int32_t snake_game_app(void* p) {
|
|||||||
release_mutex(&state_mutex, snake_state);
|
release_mutex(&state_mutex, snake_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(snake_state->isNewHighscore)
|
if(snake_state->isNewHighscore) snake_game_save_score_to_file(snake_state->highscore);
|
||||||
snake_game_save_score_to_file(snake_state->highscore);
|
|
||||||
// Wait for all notifications to be played and return backlight to normal state
|
// Wait for all notifications to be played and return backlight to normal state
|
||||||
notification_message_block(notification, &sequence_display_backlight_enforce_auto);
|
notification_message_block(notification, &sequence_display_backlight_enforce_auto);
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,13 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
|
|||||||
if(plugin_state->crypto_verify_data == NULL) {
|
if(plugin_state->crypto_verify_data == NULL) {
|
||||||
DialogMessage* message = dialog_message_alloc();
|
DialogMessage* message = dialog_message_alloc();
|
||||||
dialog_message_set_buttons(message, "No", NULL, "Yes");
|
dialog_message_set_buttons(message, "No", NULL, "Yes");
|
||||||
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
|
dialog_message_set_text(
|
||||||
|
message,
|
||||||
|
"Would you like to setup PIN?",
|
||||||
|
SCREEN_WIDTH_CENTER,
|
||||||
|
SCREEN_HEIGHT_CENTER,
|
||||||
|
AlignCenter,
|
||||||
|
AlignCenter);
|
||||||
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
|
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
|
||||||
dialog_message_free(message);
|
dialog_message_free(message);
|
||||||
if(dialog_result == DialogMessageButtonRight) {
|
if(dialog_result == DialogMessageButtonRight) {
|
||||||
@@ -68,10 +74,18 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
|
|||||||
if(totp_crypto_verify_key(plugin_state)) {
|
if(totp_crypto_verify_key(plugin_state)) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
|
FURI_LOG_E(
|
||||||
|
LOGGING_TAG,
|
||||||
|
"Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
|
||||||
DialogMessage* message = dialog_message_alloc();
|
DialogMessage* message = dialog_message_alloc();
|
||||||
dialog_message_set_buttons(message, "Exit", NULL, NULL);
|
dialog_message_set_buttons(message, "Exit", NULL, NULL);
|
||||||
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter);
|
dialog_message_set_text(
|
||||||
|
message,
|
||||||
|
"Digital signature verification failed",
|
||||||
|
SCREEN_WIDTH_CENTER,
|
||||||
|
SCREEN_HEIGHT_CENTER,
|
||||||
|
AlignCenter,
|
||||||
|
AlignCenter);
|
||||||
dialog_message_show(plugin_state->dialogs, message);
|
dialog_message_show(plugin_state->dialogs, message);
|
||||||
dialog_message_free(message);
|
dialog_message_free(message);
|
||||||
return false;
|
return false;
|
||||||
@@ -148,7 +162,9 @@ int32_t totp_app() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processing = totp_scene_director_handle_event(&event, plugin_state);
|
processing = totp_scene_director_handle_event(&event, plugin_state);
|
||||||
} else if (plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
|
} else if(
|
||||||
|
plugin_state->pin_set && plugin_state->current_scene != TotpSceneAuthentication &&
|
||||||
|
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
|
||||||
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user