gnss2 2.0.0.0
gnss2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef GNSS2_H
29#define GNSS2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define GNSS2_RSP_START "$"
74#define GNSS2_RSP_DELIMITER ","
75#define GNSS2_RSP_END_SEQ "\r\n"
76#define GNSS2_RSP_GPGGA "$GPGGA"
77
82#define GNSS2_GPGGA_ELEMENT_SIZE 15
83#define GNSS2_GPGGA_TIME 1
84#define GNSS2_GPGGA_LATITUDE 2
85#define GNSS2_GPGGA_LATITUDE_SIDE 3
86#define GNSS2_GPGGA_LONGITUDE 4
87#define GNSS2_GPGGA_LONGITUDE_SIDE 5
88#define GNSS2_GPGGA_QUALITY_INDICATOR 6
89#define GNSS2_GPGGA_NUMBER_OF_SATELLITES 7
90#define GNSS2_GPGGA_H_DILUTION_OF_POS 8
91#define GNSS2_GPGGA_ALTITUDE 9
92#define GNSS2_GPGGA_ALTITUDE_UNIT 10
93#define GNSS2_GPGGA_GEOIDAL_SEPARATION 11
94#define GNSS2_GPGGA_GEOIDAL_SEPARATION_UNIT 12
95#define GNSS2_GPGGA_TIME_SINCE_LAST_DGPS 13
96#define GNSS2_GPGGA_DGPS_REFERENCE_STATION_ID 14
97
103#define GNSS2_DRV_TX_BUFFER_SIZE 100
104#define GNSS2_DRV_RX_BUFFER_SIZE 1000
105
106 // gnss2_cmd
107
122#define GNSS2_MAP_MIKROBUS( cfg, mikrobus ) \
123 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
124 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
125 cfg.fon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
126 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
127 cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
128
129 // gnss2_map
130 // gnss2
131
136typedef struct
137{
138 // Output pins
139 digital_out_t rst;
140
141 // Input pins
142 digital_in_t fon;
143 digital_in_t stb;
144
145 // Modules
146 uart_t uart;
148 // Buffers
149 char uart_rx_buffer[ GNSS2_DRV_RX_BUFFER_SIZE ];
150 char uart_tx_buffer[ GNSS2_DRV_TX_BUFFER_SIZE ];
152} gnss2_t;
153
158typedef struct
159{
160 // Communication gpio pins
161 pin_name_t rx_pin;
162 pin_name_t tx_pin;
164 // Additional gpio pins
165 pin_name_t rst;
166 pin_name_t fon;
167 pin_name_t stb;
168
169 // Static variable
170 uint32_t baud_rate;
172 uart_data_bits_t data_bit;
173 uart_parity_t parity_bit;
174 uart_stop_bits_t stop_bit;
177
182typedef enum
183{
185 GNSS2_ERROR = -1
186
188
205
219err_t gnss2_init ( gnss2_t *ctx, gnss2_cfg_t *cfg );
220
233err_t gnss2_generic_write ( gnss2_t *ctx, char *data_in, uint16_t len );
234
247err_t gnss2_generic_read ( gnss2_t *ctx, char *data_out, uint16_t len );
248
258
268void gnss2_set_rst_pin ( gnss2_t *ctx, uint8_t state );
269
278uint8_t gnss2_get_fon_pin ( gnss2_t *ctx );
279
288uint8_t gnss2_get_stb_pin ( gnss2_t *ctx );
289
301err_t gnss2_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
302
303#ifdef __cplusplus
304}
305#endif
306#endif // GNSS2_H
307
308 // gnss2
309
310// ------------------------------------------------------------------------ END
gnss2_return_value_t
GNSS 2 Click return value data.
Definition gnss2.h:183
@ GNSS2_OK
Definition gnss2.h:184
@ GNSS2_ERROR
Definition gnss2.h:185
#define GNSS2_DRV_TX_BUFFER_SIZE
GNSS 2 driver buffer size.
Definition gnss2.h:103
#define GNSS2_DRV_RX_BUFFER_SIZE
Definition gnss2.h:104
void gnss2_clear_ring_buffers(gnss2_t *ctx)
GNSS 2 clear ring buffers function.
err_t gnss2_init(gnss2_t *ctx, gnss2_cfg_t *cfg)
GNSS 2 initialization function.
err_t gnss2_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
GNSS 2 parse GPGGA function.
void gnss2_cfg_setup(gnss2_cfg_t *cfg)
GNSS 2 configuration object setup function.
uint8_t gnss2_get_fon_pin(gnss2_t *ctx)
GNSS 2 get FON pin function.
uint8_t gnss2_get_stb_pin(gnss2_t *ctx)
GNSS 2 get STB pin function.
err_t gnss2_generic_read(gnss2_t *ctx, char *data_out, uint16_t len)
GNSS 2 data reading function.
void gnss2_set_rst_pin(gnss2_t *ctx, uint8_t state)
GNSS 2 set RST pin function.
err_t gnss2_generic_write(gnss2_t *ctx, char *data_in, uint16_t len)
GNSS 2 data writing function.
GNSS 2 Click configuration object.
Definition gnss2.h:159
pin_name_t fon
Definition gnss2.h:166
uint32_t baud_rate
Definition gnss2.h:170
bool uart_blocking
Definition gnss2.h:171
uart_data_bits_t data_bit
Definition gnss2.h:172
pin_name_t tx_pin
Definition gnss2.h:162
pin_name_t rx_pin
Definition gnss2.h:161
uart_stop_bits_t stop_bit
Definition gnss2.h:174
uart_parity_t parity_bit
Definition gnss2.h:173
pin_name_t rst
Definition gnss2.h:165
pin_name_t stb
Definition gnss2.h:167
GNSS 2 Click context object.
Definition gnss2.h:137
digital_in_t fon
Definition gnss2.h:142
uart_t uart
Definition gnss2.h:146
digital_in_t stb
Definition gnss2.h:143
digital_out_t rst
Definition gnss2.h:139