gnss 2.0.0.0
gnss.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 GNSS_H
29#define GNSS_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 GNSS_RSP_START "$"
74#define GNSS_RSP_DELIMITER ","
75#define GNSS_RSP_END_SEQ "\r\n"
76#define GNSS_RSP_GPGGA "$GPGGA"
77
82#define GNSS_GPGGA_ELEMENT_SIZE 15
83#define GNSS_GPGGA_TIME 1
84#define GNSS_GPGGA_LATITUDE 2
85#define GNSS_GPGGA_LATITUDE_SIDE 3
86#define GNSS_GPGGA_LONGITUDE 4
87#define GNSS_GPGGA_LONGITUDE_SIDE 5
88#define GNSS_GPGGA_QUALITY_INDICATOR 6
89#define GNSS_GPGGA_NUMBER_OF_SATELLITES 7
90#define GNSS_GPGGA_H_DILUTION_OF_POS 8
91#define GNSS_GPGGA_ALTITUDE 9
92#define GNSS_GPGGA_ALTITUDE_UNIT 10
93#define GNSS_GPGGA_GEOIDAL_SEPARATION 11
94#define GNSS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
95#define GNSS_GPGGA_TIME_SINCE_LAST_DGPS 13
96#define GNSS_GPGGA_DGPS_REFERENCE_STATION_ID 14
97
103#define GNSS_DRV_TX_BUFFER_SIZE 100
104#define GNSS_DRV_RX_BUFFER_SIZE 1000
105
106 // gnss_cmd
107
122#define GNSS_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_CS ); \
126 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
127
128 // gnss_map
129 // gnss
130
135typedef struct
136{
137 // Output pins
138 digital_out_t rst;
139 digital_out_t fon;
140
141 // Modules
142 uart_t uart;
144 // Buffers
145 char uart_rx_buffer[ GNSS_DRV_RX_BUFFER_SIZE ];
146 char uart_tx_buffer[ GNSS_DRV_TX_BUFFER_SIZE ];
148} gnss_t;
149
154typedef struct
155{
156 // Communication gpio pins
157 pin_name_t rx_pin;
158 pin_name_t tx_pin;
160 // Additional gpio pins
161 pin_name_t rst;
162 pin_name_t fon;
163
164 // Static variable
165 uint32_t baud_rate;
167 uart_data_bits_t data_bit;
168 uart_parity_t parity_bit;
169 uart_stop_bits_t stop_bit;
171} gnss_cfg_t;
172
177typedef enum
178{
180 GNSS_ERROR = -1
181
183
200
214err_t gnss_init ( gnss_t *ctx, gnss_cfg_t *cfg );
215
228err_t gnss_generic_write ( gnss_t *ctx, char *data_in, uint16_t len );
229
242err_t gnss_generic_read ( gnss_t *ctx, char *data_out, uint16_t len );
243
253
263void gnss_set_rst_pin ( gnss_t *ctx, uint8_t state );
264
274void gnss_set_fon_pin ( gnss_t *ctx, uint8_t state );
275
287err_t gnss_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
288
289#ifdef __cplusplus
290}
291#endif
292#endif // GNSS_H
293
294 // gnss
295
296// ------------------------------------------------------------------------ END
gnss_return_value_t
GNSS Click return value data.
Definition gnss.h:178
@ GNSS_OK
Definition gnss.h:179
@ GNSS_ERROR
Definition gnss.h:180
#define GNSS_DRV_RX_BUFFER_SIZE
Definition gnss.h:104
#define GNSS_DRV_TX_BUFFER_SIZE
GNSS driver buffer size.
Definition gnss.h:103
void gnss_clear_ring_buffers(gnss_t *ctx)
GNSS clear ring buffers function.
void gnss_set_fon_pin(gnss_t *ctx, uint8_t state)
GNSS set FON pin function.
err_t gnss_init(gnss_t *ctx, gnss_cfg_t *cfg)
GNSS initialization function.
err_t gnss_generic_read(gnss_t *ctx, char *data_out, uint16_t len)
GNSS data reading function.
void gnss_set_rst_pin(gnss_t *ctx, uint8_t state)
GNSS set RST pin function.
err_t gnss_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
GNSS parse GPGGA function.
err_t gnss_generic_write(gnss_t *ctx, char *data_in, uint16_t len)
GNSS data writing function.
void gnss_cfg_setup(gnss_cfg_t *cfg)
GNSS configuration object setup function.
GNSS Click configuration object.
Definition gnss.h:155
pin_name_t fon
Definition gnss.h:162
uint32_t baud_rate
Definition gnss.h:165
bool uart_blocking
Definition gnss.h:166
uart_data_bits_t data_bit
Definition gnss.h:167
pin_name_t tx_pin
Definition gnss.h:158
pin_name_t rx_pin
Definition gnss.h:157
uart_stop_bits_t stop_bit
Definition gnss.h:169
uart_parity_t parity_bit
Definition gnss.h:168
pin_name_t rst
Definition gnss.h:161
GNSS Click context object.
Definition gnss.h:136
uart_t uart
Definition gnss.h:142
digital_out_t fon
Definition gnss.h:139
digital_out_t rst
Definition gnss.h:138