gsmgps 2.0.0.0
gsmgps.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef GSMGPS_H
36#define GSMGPS_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define GSMGPS_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
81#define GSMGPS_RETVAL uint8_t
88#define GSMGPS_NEMA_GPGGA 1
89#define GSMGPS_NEMA_GPGLL 3
90#define GSMGPS_NEMA_GPGGA_NUM_ELEMENT 15
91#define GSMGPS_NEMA_GPGLL_NUM_ELEMENT 5
98#define GSMGPS_GPGGA_TIME 1
99#define GSMGPS_GPGGA_LATITUDE 2
100#define GSMGPS_GPGGA_LATITUDE_SIDE 3
101#define GSMGPS_GPGGA_LONGITUDE 4
102#define GSMGPS_GPGGA_LONGITUDE_SIDE 5
103#define GSMGPS_GPGGA_QUALITY_INDICATOR 6
104#define GSMGPS_GPGGA_NUMBER_OF_SATELLITES 7
105#define GSMGPS_GPGGA_H_DILUTION_OF_POS 8
106#define GSMGPS_GPGGA_ALTITUDE 9
107#define GSMGPS_GPGGA_ALTITUDE_UNIT 10
108#define GSMGPS_GPGGA_GEOIDAL_SEPARATION 11
109#define GSMGPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
110#define GSMGPS_GPGGA_TIME_SINCE_LAST_DGPS 13
111#define GSMGPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
118#define GSMGPS_GPGLL_LATITUDE 1
119#define GSMGPS_GPGLL_LATITUDE_SIDE 2
120#define GSMGPS_GPGLL_LONGITUDE 3
121#define GSMGPS_GPGLL_LONGITUDE_SIDE 4
128#define GSMGPS_ERROR_COMMAND_OR_ELEMENT 0xFF
129#define GSMGPS_ERROR_START_OR_END_COMMAND 0x8F
130#define GSMGPS_ERROR_NEXT_ELEMENT 0x4F
131#define GSMGPS_ERROR_CURRENT_ELEMENT 0x2F
132#define GSMGPS_NO_ERROR 0x00
139#define GSMGPS_MODULE_POWER_ON 1
140#define GSMGPS_MODULE_POWER_OFF 0
147#define GSMGPS_CMD_AT "AT"
148#define GSMGPS_CMD_ATI "ATI"
149#define GSMGPS_CMD_CGMR "AT+CGMR"
150
151#define GSMGPS_CMD_CFUN "AT+CFUN"
152#define GSMGPS_CMD_CREG "AT+CREG"
153#define GSMGPS_CMD_CGDCONT "AT+CGDCONT"
154#define GSMGPS_CMD_CIMI "AT+CIMI"
155#define GSMGPS_CMD_CGATT "AT+CGATT"
156#define GSMGPS_CMD_CSQ "AT+CSQ"
157#define GSMGPS_CMD_COPS "AT+COPS"
158#define GSMGPS_CMD_CMGS "AT+CMGS"
159#define GSMGPS_CMD_CMGF "AT+CMGF"
160#define GSMGPS_CMD_CGNSPWR "AT+CGNSPWR"
161#define GSMGPS_CMD_CGPSINF "AT+CGPSINF"
168#define DRV_RX_BUFFER_SIZE 256
169#define DRV_TX_BUFFER_SIZE 256
172 // End group macro
173// --------------------------------------------------------------- PUBLIC TYPES
181typedef struct
182{
183 // Output pins
184
185 digital_out_t pwk;
186 digital_out_t rts;
187
188 // Input pins
189
190 digital_in_t sta;
191 digital_in_t ri;
192 digital_in_t cts;
193
194 // Modules
195
196 uart_t uart;
197
198 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
199 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
200
201} gsmgps_t;
202
206typedef struct
207{
208 // Communication gpio pins
209
210 pin_name_t rx_pin;
211 pin_name_t tx_pin;
212
213 // Additional gpio pins
214
215 pin_name_t sta;
216 pin_name_t pwk;
217 pin_name_t rts;
218 pin_name_t ri;
219 pin_name_t cts;
220
221 // static variable
222
223 uint32_t baud_rate; // Clock speed.
225 uart_data_bits_t data_bit; // Data bits.
226 uart_parity_t parity_bit; // Parity bit.
227 uart_stop_bits_t stop_bit; // Stop bits.
228
230
235typedef enum
236{
238 GSMGPS_ERROR = -1
239
241
245typedef uint8_t gsmgps_error_t;
246
247 // End types group
248// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
249
255#ifdef __cplusplus
256extern "C"{
257#endif
258
268
277
283void gsmgps_module_power ( gsmgps_t *ctx, uint8_t state );
284
291void gsmgps_generic_write ( gsmgps_t *ctx, char *data_buf, uint16_t len );
292
300int32_t gsmgps_generic_read ( gsmgps_t *ctx, char *data_buf, uint16_t max_len );
301
310void gsmgps_set_rts ( gsmgps_t *ctx, uint8_t state );
311
320uint8_t gsmgps_get_cts ( gsmgps_t *ctx );
321
331void gsmgps_send_cmd ( gsmgps_t *ctx, char *cmd );
332
343void gsmgps_send_cmd_with_parameter ( gsmgps_t *ctx, char *at_cmd_buf, char *param_buf );
344
354void gsmgps_send_cmd_check ( gsmgps_t *ctx, char *at_cmd_buf );
355
365void gsmgps_send_cmd_parameter_check ( gsmgps_t *ctx, char *at_cmd_buf );
366
376void gsmgps_set_sim_apn ( gsmgps_t *ctx, char *sim_apn );
377
388void gsmgps_send_sms_text ( gsmgps_t *ctx, char *phone_number, char *sms_text );
389
403err_t gsmgps_send_sms_pdu ( gsmgps_t *ctx, char *service_center_number,
404 char *phone_number, char *sms_text );
405
415(
416 char *rsp, uint8_t command,
417 uint8_t element, char *parser_buf
418);
419
420#ifdef __cplusplus
421}
422#endif
423#endif // _GSMGPS_H_
424
425 // End public_function group
427
428// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition gsmgps.h:168
#define DRV_TX_BUFFER_SIZE
Definition gsmgps.h:169
#define GSMGPS_RETVAL
Definition gsmgps.h:81
void gsmgps_set_sim_apn(gsmgps_t *ctx, char *sim_apn)
Set sim card APN.
uint8_t gsmgps_get_cts(gsmgps_t *ctx)
CTS Pin Get function.
void gsmgps_module_power(gsmgps_t *ctx, uint8_t state)
Power ON/OFF the module.
void gsmgps_generic_write(gsmgps_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void gsmgps_send_cmd_parameter_check(gsmgps_t *ctx, char *at_cmd_buf)
Check the command parameters.
GSMGPS_RETVAL gsmgps_init(gsmgps_t *ctx, gsmgps_cfg_t *cfg)
Initialization function.
gsmgps_error_t gsmgps_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
int32_t gsmgps_generic_read(gsmgps_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void gsmgps_send_sms_text(gsmgps_t *ctx, char *phone_number, char *sms_text)
GSM-GPS send SMS in text mode.
void gsmgps_send_cmd_with_parameter(gsmgps_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
err_t gsmgps_send_sms_pdu(gsmgps_t *ctx, char *service_center_number, char *phone_number, char *sms_text)
GSM-GPS send SMS in PDU mode.
void gsmgps_send_cmd(gsmgps_t *ctx, char *cmd)
Send command function.
void gsmgps_send_cmd_check(gsmgps_t *ctx, char *at_cmd_buf)
Check the sent command.
void gsmgps_set_rts(gsmgps_t *ctx, uint8_t state)
Sets state of the RTS pin.
void gsmgps_cfg_setup(gsmgps_cfg_t *cfg)
Config Object Initialization function.
gsmgps_return_value_t
GSM-GPS Click return value data.
Definition gsmgps.h:236
uint8_t gsmgps_error_t
Error type.
Definition gsmgps.h:245
@ GSMGPS_ERROR
Definition gsmgps.h:238
@ GSMGPS_OK
Definition gsmgps.h:237
Click configuration structure definition.
Definition gsmgps.h:207
pin_name_t sta
Definition gsmgps.h:215
pin_name_t rts
Definition gsmgps.h:217
uint32_t baud_rate
Definition gsmgps.h:223
pin_name_t pwk
Definition gsmgps.h:216
pin_name_t cts
Definition gsmgps.h:219
bool uart_blocking
Definition gsmgps.h:224
pin_name_t ri
Definition gsmgps.h:218
uart_data_bits_t data_bit
Definition gsmgps.h:225
pin_name_t tx_pin
Definition gsmgps.h:211
pin_name_t rx_pin
Definition gsmgps.h:210
uart_stop_bits_t stop_bit
Definition gsmgps.h:227
uart_parity_t parity_bit
Definition gsmgps.h:226
Click ctx object definition.
Definition gsmgps.h:182
digital_in_t sta
Definition gsmgps.h:190
digital_out_t rts
Definition gsmgps.h:186
digital_in_t ri
Definition gsmgps.h:191
uart_t uart
Definition gsmgps.h:196
digital_in_t cts
Definition gsmgps.h:192
digital_out_t pwk
Definition gsmgps.h:185