GPS tracker code documentation
 All Classes Files Functions Variables Macros Pages
sim808.h
Go to the documentation of this file.
1 
7 #ifndef SIM808_H
8 #define SIM808_H
9 
10 #include <stdint.h>
11 #include "main.h"
12 
13 #define AT_uart huart1
14 #define debug_uart huart2
15 
16 #define DEBUG_MODE 1
17 /* Error codes */
18 #define FAIL 0
19 #define SUCCESS 1
20 #define TRUE 1
21 #define FALSE 0
22 
23 #define GREEN_LED GPIO_PIN_13
24 
25 
26 #define RX_WAIT 200 /* After sending AT command, wait RX_WAIT ms to ensure that the reply is receeived in the buffer */
27 #define RX_TIMEOUT 1000
28 #define TX_TIMEOUT 100
29 #define BAUD_RATE 38400 /* BAUD_RATE=38400 => it take 26 ms to send 100 bytes */
30 #define RX_BUFFER_LENGTH 256
31 #define SIM_UART huart2
32 #define DEBUG_UART huart1
33 #define TCP_CONNECT_TIMEOUT 5 /* value in second */
34 #define GPS_COORDINATES_LENGTH 23
35 
36 
37 
38 
39 
48 typedef struct {
49  USART_TypeDef * AT_uart_instance; /*send AT commands through this UART.*/
50  USART_TypeDef * debug_uart_instance;
51  GPIO_TypeDef * power_on_gpio;
52  uint16_t power_on_pin;
53  GPIO_TypeDef * reset_gpio;
54  uint16_t reset_pin;
55  GPIO_TypeDef * status_gpio;
56  uint16_t status_pin;
58 
59 
60 
68 uint8_t sim_init(SIM808_typedef * sim);
69 
75 uint8_t sim_power_off(SIM808_typedef * sim);
76 
81 void system_reset(SIM808_typedef * sim);
82 
83 
93 uint8_t send_AT_cmd(const char * cmd, const char * expected_reply, uint8_t save_reply, char * cmd_reply, uint32_t rx_timeout);
94 
100 uint8_t send_serial_data(uint8_t * data, uint8_t length, char * cmd_reply, uint32_t rx_wait);
101 
106 void send_debug(const char * debug_msg);
107 
108 
109 void send_raw_debug(uint8_t * debug_dump,uint8_t length);
110 uint8_t is_subarray_present(const uint8_t *array, size_t array_len, const uint8_t *subarray, size_t subarray_len);
111 #endif
uint8_t sim_init(SIM808_typedef *sim)
it initialises the SIM808_typedef struct members and powers on the module. initializes the UARTs and ...
Definition: sim808.c:57
uint16_t status_pin
Definition: sim808.h:56
uint8_t is_subarray_present(const uint8_t *array, size_t array_len, const uint8_t *subarray, size_t subarray_len)
Definition: sim808.c:262
GPIO_TypeDef * status_gpio
Definition: sim808.h:55
uint16_t power_on_pin
Definition: sim808.h:52
GPIO_TypeDef * reset_gpio
Definition: sim808.h:53
void system_reset(SIM808_typedef *sim)
power_off the module and reset the MCU
Definition: sim808.c:213
void send_raw_debug(uint8_t *debug_dump, uint8_t length)
Definition: sim808.c:30
uint16_t reset_pin
Definition: sim808.h:54
uint8_t send_AT_cmd(const char *cmd, const char *expected_reply, uint8_t save_reply, char *cmd_reply, uint32_t rx_timeout)
sends a cmd to the module, if the parameter save_reply == 1 then it copies the reply into the paramet...
Definition: sim808.c:220
is used to abstract the SIM808 hardware interface. It will decouple the functions from the hardware (...
Definition: sim808.h:48
uint8_t send_serial_data(uint8_t *data, uint8_t length, char *cmd_reply, uint32_t rx_timeout)
sends raw serial data to the SIM808 module through the AT_uart peripheral. Then it deletes the receiv...
Definition: sim808.c:286
USART_TypeDef * AT_uart_instance
Definition: sim808.h:49
void send_debug(const char *debug_msg)
sends a debug message through the debug UART
Definition: sim808.c:22
GPIO_TypeDef * power_on_gpio
Definition: sim808.h:51
uint8_t sim_power_off(SIM808_typedef *sim)
power_off the module.
Definition: sim808.c:180
USART_TypeDef * debug_uart_instance
Definition: sim808.h:50