gnss5  2.0.0.0
gnss5.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 GNSS5_H
29 #define GNSS5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define GNSS5_RSP_START "$"
60 #define GNSS5_RSP_DELIMITER ","
61 #define GNSS5_RSP_END_SEQ "\r\n"
62 #define GNSS5_RSP_GNGGA "$GNGGA"
63 
68 #define GNSS5_GNGGA_ELEMENT_SIZE 15
69 #define GNSS5_GNGGA_TIME 1
70 #define GNSS5_GNGGA_LATITUDE 2
71 #define GNSS5_GNGGA_LATITUDE_SIDE 3
72 #define GNSS5_GNGGA_LONGITUDE 4
73 #define GNSS5_GNGGA_LONGITUDE_SIDE 5
74 #define GNSS5_GNGGA_QUALITY_INDICATOR 6
75 #define GNSS5_GNGGA_NUMBER_OF_SATELLITES 7
76 #define GNSS5_GNGGA_H_DILUTION_OF_POS 8
77 #define GNSS5_GNGGA_ALTITUDE 9
78 #define GNSS5_GNGGA_ALTITUDE_UNIT 10
79 #define GNSS5_GNGGA_GEOIDAL_SEPARATION 11
80 #define GNSS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
81 #define GNSS5_GNGGA_TIME_SINCE_LAST_DGPS 13
82 #define GNSS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
83 
89 #define GNSS5_DRV_TX_BUFFER_SIZE 100
90 #define GNSS5_DRV_RX_BUFFER_SIZE 1000
91  // gnss5_cmd
93 
108 #define GNSS5_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
110  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
111  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.exi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
113  cfg.pps = MIKROBUS( mikrobus, MIKROBUS_INT )
114  // gnss5_map // gnss5
117 
122 typedef struct
123 {
124  // Output pins
125  digital_out_t rst;
126 
127  // Input pins
128  digital_in_t exi;
129  digital_in_t pps;
130 
131  // Modules
132  uart_t uart;
134  // Buffers
135  char uart_rx_buffer[ GNSS5_DRV_RX_BUFFER_SIZE ];
136  char uart_tx_buffer[ GNSS5_DRV_TX_BUFFER_SIZE ];
138 } gnss5_t;
139 
144 typedef struct
145 {
146  // Communication gpio pins
147  pin_name_t rx_pin;
148  pin_name_t tx_pin;
150  // Additional gpio pins
151  pin_name_t rst;
152  pin_name_t exi;
153  pin_name_t pps;
154 
155  // Static variable
156  uint32_t baud_rate;
158  uart_data_bits_t data_bit;
159  uart_parity_t parity_bit;
160  uart_stop_bits_t stop_bit;
162 } gnss5_cfg_t;
163 
168 typedef enum
169 {
170  GNSS5_OK = 0,
171  GNSS5_ERROR = -1
172 
174 
191 
205 err_t gnss5_init ( gnss5_t *ctx, gnss5_cfg_t *cfg );
206 
219 err_t gnss5_generic_write ( gnss5_t *ctx, char *data_in, uint16_t len );
220 
233 err_t gnss5_generic_read ( gnss5_t *ctx, char *data_out, uint16_t len );
234 
244 
254 void gnss5_set_rst_pin ( gnss5_t *ctx, uint8_t state );
255 
264 uint8_t gnss5_get_exi_pin ( gnss5_t *ctx );
265 
274 uint8_t gnss5_get_pps_pin ( gnss5_t *ctx );
275 
287 err_t gnss5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 #endif // GNSS5_H
293  // gnss5
295 
296 // ------------------------------------------------------------------------ END
gnss5_parse_gngga
err_t gnss5_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GNSS 5 parse GNGGA function.
gnss5_get_pps_pin
uint8_t gnss5_get_pps_pin(gnss5_t *ctx)
GNSS 5 get PPS pin function.
GNSS5_OK
@ GNSS5_OK
Definition: gnss5.h:170
GNSS5_DRV_TX_BUFFER_SIZE
#define GNSS5_DRV_TX_BUFFER_SIZE
GNSS 5 driver buffer size.
Definition: gnss5.h:89
gnss5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss5.h:160
gnss5_cfg_setup
void gnss5_cfg_setup(gnss5_cfg_t *cfg)
GNSS 5 configuration object setup function.
gnss5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss5.h:159
gnss5_t::rst
digital_out_t rst
Definition: gnss5.h:125
gnss5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss5.h:158
gnss5_generic_read
err_t gnss5_generic_read(gnss5_t *ctx, char *data_out, uint16_t len)
GNSS 5 data reading function.
GNSS5_DRV_RX_BUFFER_SIZE
#define GNSS5_DRV_RX_BUFFER_SIZE
Definition: gnss5.h:90
gnss5_init
err_t gnss5_init(gnss5_t *ctx, gnss5_cfg_t *cfg)
GNSS 5 initialization function.
gnss5_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss5.h:157
GNSS5_ERROR
@ GNSS5_ERROR
Definition: gnss5.h:171
gnss5_t
GNSS 5 Click context object.
Definition: gnss5.h:123
gnss5_cfg_t::pps
pin_name_t pps
Definition: gnss5.h:153
gnss5_t::exi
digital_in_t exi
Definition: gnss5.h:128
gnss5_t::uart
uart_t uart
Definition: gnss5.h:132
gnss5_get_exi_pin
uint8_t gnss5_get_exi_pin(gnss5_t *ctx)
GNSS 5 get EXI pin function.
gnss5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gnss5.h:148
gnss5_cfg_t::rst
pin_name_t rst
Definition: gnss5.h:151
gnss5_clear_ring_buffers
void gnss5_clear_ring_buffers(gnss5_t *ctx)
GNSS 5 clear ring buffers function.
gnss5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss5.h:147
gnss5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss5.h:156
gnss5_cfg_t::exi
pin_name_t exi
Definition: gnss5.h:152
gnss5_cfg_t
GNSS 5 Click configuration object.
Definition: gnss5.h:145
gnss5_t::pps
digital_in_t pps
Definition: gnss5.h:129
gnss5_set_rst_pin
void gnss5_set_rst_pin(gnss5_t *ctx, uint8_t state)
GNSS 5 set RST pin function.
gnss5_return_value_t
gnss5_return_value_t
GNSS 5 Click return value data.
Definition: gnss5.h:169
gnss5_generic_write
err_t gnss5_generic_write(gnss5_t *ctx, char *data_in, uint16_t len)
GNSS 5 data writing function.