GPS tracker code documentation
 All Classes Files Functions Variables Macros Pages
Classes | Macros | Functions
sim808.h File Reference

Prototypes of functions that communicate with the SIM808 module and control it and definition of related parameters. More...

#include <stdint.h>
#include "main.h"
Include dependency graph for sim808.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SIM808_typedef
 is used to abstract the SIM808 hardware interface. It will decouple the functions from the hardware (uart+pins) used to interface with the module. The UART peripheral used to send AT commands to the module and the UART used to send Debug messages and the pins used to power on, reset and check status of the module are combined together in this struct. This struct will be passed to all the functions that perform actions on the module. More...
 

Macros

#define AT_uart   huart1
 
#define debug_uart   huart2
 
#define DEBUG_MODE   1
 
#define FAIL   0
 
#define SUCCESS   1
 
#define TRUE   1
 
#define FALSE   0
 
#define GREEN_LED   GPIO_PIN_13
 
#define RX_WAIT   200 /* After sending AT command, wait RX_WAIT ms to ensure that the reply is receeived in the buffer */
 
#define RX_TIMEOUT   1000
 
#define TX_TIMEOUT   100
 
#define BAUD_RATE   38400 /* BAUD_RATE=38400 => it take 26 ms to send 100 bytes */
 
#define RX_BUFFER_LENGTH   256
 
#define SIM_UART   huart2
 
#define DEBUG_UART   huart1
 
#define TCP_CONNECT_TIMEOUT   5 /* value in second */
 
#define GPS_COORDINATES_LENGTH   23
 

Functions

uint8_t sim_init (SIM808_typedef *sim)
 it initialises the SIM808_typedef struct members and powers on the module. initializes the UARTs and the GPIOs used to power on, reset and check the status of the module. Which UART peripheral is used for what is specified in the parameter SIM808_typedef members: AT_uart and debug_uart. More...
 
uint8_t sim_power_off (SIM808_typedef *sim)
 power_off the module. More...
 
void system_reset (SIM808_typedef *sim)
 power_off the module and reset the MCU More...
 
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 parameter cmd_reply. More...
 
uint8_t send_serial_data (uint8_t *data, uint8_t length, char *cmd_reply, uint32_t rx_wait)
 sends raw serial data to the SIM808 module through the AT_uart peripheral. Then it deletes the receive buffer. More...
 
void send_debug (const char *debug_msg)
 sends a debug message through the debug UART More...
 
void send_raw_debug (uint8_t *debug_dump, uint8_t length)
 
uint8_t is_subarray_present (const uint8_t *array, size_t array_len, const uint8_t *subarray, size_t subarray_len)
 

Detailed Description

Prototypes of functions that communicate with the SIM808 module and control it and definition of related parameters.

Author
Mohamed Boubaker
Bug:
issue #9

Macro Definition Documentation

#define AT_uart   huart1
#define BAUD_RATE   38400 /* BAUD_RATE=38400 => it take 26 ms to send 100 bytes */
#define DEBUG_MODE   1
#define debug_uart   huart2
#define DEBUG_UART   huart1
#define FAIL   0
#define FALSE   0
#define GPS_COORDINATES_LENGTH   23
#define GREEN_LED   GPIO_PIN_13
#define RX_BUFFER_LENGTH   256
#define RX_TIMEOUT   1000
#define RX_WAIT   200 /* After sending AT command, wait RX_WAIT ms to ensure that the reply is receeived in the buffer */
#define SIM_UART   huart2
#define SUCCESS   1
#define TCP_CONNECT_TIMEOUT   5 /* value in second */
#define TRUE   1
#define TX_TIMEOUT   100

Function Documentation

uint8_t is_subarray_present ( const uint8_t *  array,
size_t  array_len,
const uint8_t *  subarray,
size_t  subarray_len 
)

Here is the caller graph for this function:

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 parameter cmd_reply.

Parameters
cmdis the AT command to be sent
expected_replyis used to determine if the outcome of the function is SUCCESS or FAIL.
save_replyif set to 1, then the reply from the module gets copied into cmd_reply.
cmd_replyis an array where to modules reply is copied.
rx_timeoutthe maximum amount of time the function will wait for the module to receive a reply.
Returns
SUCCESS if the module replies withing timeout and the reply includes the expected_reply, FAIL otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

void send_debug ( const char *  debug_msg)

sends a debug message through the debug UART

Parameters
debug_messageis the debug message.

Here is the caller graph for this function:

void send_raw_debug ( uint8_t *  debug_dump,
uint8_t  length 
)

Here is the caller graph for this function:

uint8_t send_serial_data ( uint8_t *  data,
uint8_t  length,
char *  cmd_reply,
uint32_t  rx_wait 
)

sends raw serial data to the SIM808 module through the AT_uart peripheral. Then it deletes the receive buffer.

Parameters
cmdcontains the command
rx_waitwaiting time before exit. To make sure the reply is received.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t sim_init ( SIM808_typedef sim)

it initialises the SIM808_typedef struct members and powers on the module. initializes the UARTs and the GPIOs used to power on, reset and check the status of the module. Which UART peripheral is used for what is specified in the parameter SIM808_typedef members: AT_uart and debug_uart.

Parameters
simis the definition of the sim808 hardware
Returns
SUCCESS if module is ready for use, FAIL otherwise

Here is the call graph for this function:

uint8_t sim_power_off ( SIM808_typedef sim)

power_off the module.

Parameters
simis the definition of the sim808 hardware
Returns
SUCCESS if module is ready for use, FAIL otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

void system_reset ( SIM808_typedef sim)

power_off the module and reset the MCU

Parameters
simis the definition of the sim808 hardware

Here is the call graph for this function: