gps3  2.0.0.0
gps3.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 GPS3_H
29 #define GPS3_H
30 
31 #ifdef __cplusplus
32 extern "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 GPS3_RSP_START "$"
74 #define GPS3_RSP_DELIMITER ","
75 #define GPS3_RSP_END_SEQ "\r\n"
76 #define GPS3_RSP_GPGGA "$GPGGA"
77 
82 #define GPS3_GPGGA_ELEMENT_SIZE 15
83 #define GPS3_GPGGA_TIME 1
84 #define GPS3_GPGGA_LATITUDE 2
85 #define GPS3_GPGGA_LATITUDE_SIDE 3
86 #define GPS3_GPGGA_LONGITUDE 4
87 #define GPS3_GPGGA_LONGITUDE_SIDE 5
88 #define GPS3_GPGGA_QUALITY_INDICATOR 6
89 #define GPS3_GPGGA_NUMBER_OF_SATELLITES 7
90 #define GPS3_GPGGA_H_DILUTION_OF_POS 8
91 #define GPS3_GPGGA_ALTITUDE 9
92 #define GPS3_GPGGA_ALTITUDE_UNIT 10
93 #define GPS3_GPGGA_GEOIDAL_SEPARATION 11
94 #define GPS3_GPGGA_GEOIDAL_SEPARATION_UNIT 12
95 #define GPS3_GPGGA_TIME_SINCE_LAST_DGPS 13
96 #define GPS3_GPGGA_DGPS_REFERENCE_STATION_ID 14
97 
103 #define GPS3_DRV_TX_BUFFER_SIZE 100
104 #define GPS3_DRV_RX_BUFFER_SIZE 1000
105  // gps3_cmd
107 
122 #define GPS3_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
124  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
125  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
126  // gps3_map // gps3
129 
134 typedef struct
135 {
136  // Output pins
137  digital_out_t rst;
138 
139  // Modules
140  uart_t uart;
142  // Buffers
143  char uart_rx_buffer[ GPS3_DRV_RX_BUFFER_SIZE ];
144  char uart_tx_buffer[ GPS3_DRV_TX_BUFFER_SIZE ];
146 } gps3_t;
147 
152 typedef struct
153 {
154  // Communication gpio pins
155  pin_name_t rx_pin;
156  pin_name_t tx_pin;
158  // Additional gpio pins
159  pin_name_t rst;
160 
161  // Static variable
162  uint32_t baud_rate;
164  uart_data_bits_t data_bit;
165  uart_parity_t parity_bit;
166  uart_stop_bits_t stop_bit;
168 } gps3_cfg_t;
169 
174 typedef enum
175 {
176  GPS3_OK = 0,
177  GPS3_ERROR = -1
178 
180 
197 
211 err_t gps3_init ( gps3_t *ctx, gps3_cfg_t *cfg );
212 
225 err_t gps3_generic_write ( gps3_t *ctx, char *data_in, uint16_t len );
226 
239 err_t gps3_generic_read ( gps3_t *ctx, char *data_out, uint16_t len );
240 
250 
260 void gps3_set_rst_pin ( gps3_t *ctx, uint8_t state );
261 
273 err_t gps3_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // GPS3_H
279  // gps3
281 
282 // ------------------------------------------------------------------------ END
gps3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps3.h:166
gps3_cfg_setup
void gps3_cfg_setup(gps3_cfg_t *cfg)
GPS 3 configuration object setup function.
gps3_t::rst
digital_out_t rst
Definition: gps3.h:137
gps3_generic_read
err_t gps3_generic_read(gps3_t *ctx, char *data_out, uint16_t len)
GPS 3 data reading function.
gps3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps3.h:165
gps3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps3.h:164
gps3_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps3.h:162
gps3_clear_ring_buffers
void gps3_clear_ring_buffers(gps3_t *ctx)
GPS 3 clear ring buffers function.
gps3_set_rst_pin
void gps3_set_rst_pin(gps3_t *ctx, uint8_t state)
GPS 3 set RST pin function.
gps3_cfg_t::rst
pin_name_t rst
Definition: gps3.h:159
gps3_generic_write
err_t gps3_generic_write(gps3_t *ctx, char *data_in, uint16_t len)
GPS 3 data writing function.
gps3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps3.h:156
gps3_init
err_t gps3_init(gps3_t *ctx, gps3_cfg_t *cfg)
GPS 3 initialization function.
gps3_t
GPS 3 Click context object.
Definition: gps3.h:135
gps3_return_value_t
gps3_return_value_t
GPS 3 Click return value data.
Definition: gps3.h:175
GPS3_DRV_TX_BUFFER_SIZE
#define GPS3_DRV_TX_BUFFER_SIZE
GPS 3 driver buffer size.
Definition: gps3.h:103
GPS3_OK
@ GPS3_OK
Definition: gps3.h:176
gps3_parse_gpgga
err_t gps3_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
GPS 3 parse GPGGA function.
gps3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps3.h:155
gps3_cfg_t::uart_blocking
bool uart_blocking
Definition: gps3.h:163
GPS3_DRV_RX_BUFFER_SIZE
#define GPS3_DRV_RX_BUFFER_SIZE
Definition: gps3.h:104
gps3_t::uart
uart_t uart
Definition: gps3.h:140
GPS3_ERROR
@ GPS3_ERROR
Definition: gps3.h:177
gps3_cfg_t
GPS 3 Click configuration object.
Definition: gps3.h:153