-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
nmea.h
151 lines (127 loc) · 3.83 KB
/
nmea.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef _NMEA_H
#define _NMEA_H
/*
* Author: Nima Askari
* WebSite: https://www.github.com/NimaLTD
* Instagram: https://www.instagram.com/github.NimaLTD
* LinkedIn: https://www.linkedin.com/in/NimaLTD
* Youtube: https://www.youtube.com/channel/UCUhY7qY1klJm1d2kulr9ckw
*/
/*
* Version: 2.0.1
*
* History:
*
* (2.0.1): Fix receiving data
* (2.0.0): Rewrite again. Support NONE-RTOS, RTOS V1 and RTOS V2. Supports GPS,COMPASS,SOUNDER
*/
#include "main.h"
#include "nmea_config.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if _NMEA_USE_FREERTOS != 0
#define nmea_delay(x) osDelay(x)
#include "cmsis_os.h"
#else
#define nmea_delay(x) HAL_Delay(x)
#endif
typedef struct
{
uint16_t satellite : 1;
uint16_t time : 1;
uint16_t date : 1;
uint16_t latitude : 1;
uint16_t longitude : 1;
uint16_t precision : 1;
uint16_t altitude : 1;
uint16_t speed_knots : 1;
uint16_t course : 1;
} gnss_valid_t;
typedef struct
{
gnss_valid_t valid;
uint8_t satellite;
uint8_t time_h;
uint8_t time_m;
uint8_t time_s;
uint8_t date_y;
uint8_t date_m;
uint8_t date_d;
float latitude_tmp;
float longitude_tmp;
float latitude_deg;
float longitude_deg;
float precision_m;
float altitude_m;
float speed_knots;
float course_deg;
} gnss_t;
typedef struct
{
uint8_t true_compass : 1;
uint8_t mag_compass : 1;
} compass_valid_t;
typedef struct
{
compass_valid_t valid;
float true_course_deg;
float mag_course_deg;
} compass_t;
typedef struct
{
uint8_t depth : 1;
uint8_t depth_offset : 1;
uint8_t temp : 1;
} sounder_valid_t;
typedef struct
{
sounder_valid_t valid;
float depth_m;
float depth_offset_m;
float temp_c;
} sounder_t;
typedef struct
{
USART_TypeDef *usart;
uint32_t buf_time;
char *buf;
uint16_t buf_index;
uint16_t buf_size;
bool lock;
bool available;
gnss_t gnss;
compass_t compass;
sounder_t sounder;
} nmea_t;
//##################################################################################
// ALL
bool nmea_init(nmea_t *nmea, USART_TypeDef *usart, uint16_t buf_size);
void nmea_loop(nmea_t *nmea);
void nmea_callback(nmea_t *nmea);
bool nmea_available(nmea_t *nmea);
void nmea_available_reset(nmea_t *nmea);
// GNSS
bool nmea_gnss_time_h(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_time_m(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_time_s(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_date_y(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_date_m(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_date_d(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_satellite(nmea_t *nmea, uint8_t *data);
bool nmea_gnss_speed_kph(nmea_t *nmea, float *data);
bool nmea_gnss_speed_knots(nmea_t *nmea, float *data);
bool nmea_gnss_precision_m(nmea_t *nmea, float *data);
bool nmea_gnss_course_deg(nmea_t *nmea, float *data);
bool nmea_gnss_latitude_deg(nmea_t *nmea, float *data);
bool nmea_gnss_longitude_deg(nmea_t *nmea, float *data);
bool nmea_gnss_altitude_m(nmea_t *nmea, float *data);
// COMPASS
bool nmea_compass_true_course_deg(nmea_t *nmea, float *data);
bool nmea_compass_mag_course_deg(nmea_t *nmea, float *data);
// SOUNDER
bool nmea_sounder_depth_m(nmea_t *nmea, float *data);
bool nmea_sounder_depth_offset_m(nmea_t *nmea, float *data);
bool nmea_sounder_temp_c(nmea_t *nmea, float *data);
#endif