Open Storm
Functions | Variables
modem.c File Reference

Implements functions for connecting to the cellular network, and sending/receiving packets. More...

#include <device.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "modem.h"
#include "strlib.h"
#include "extern.h"
Include dependency graph for modem.c:

Functions

 CY_ISR_PROTO (Telit_isr_rx)
 
void uart_string_reset ()
 Reset modem_received_buffer, clear RX buffer, and reset string index. More...
 
uint8 modem_startup (int *conn_attempts)
 Startup sequence to power on the modem, start modem components and prepare for sending/receiving messages over the network. More...
 
uint8 modem_shutdown ()
 Shutdown sequence to stop/power down modem components. More...
 
void modem_start ()
 Initialize modem.
 
void modem_stop ()
 Deinitialize modem.
 
uint8 at_write_command (char *uart_string, char *expected_response, uint32 uart_timeout)
 Write AT command to cell module. More...
 
uint8 modem_power_on ()
 Powers on the modem. More...
 
uint8 modem_power_off ()
 Powers off the modem. More...
 
uint8 modem_reset ()
 Resets the modem. More...
 
uint8 modem_setup ()
 Initialize configurations for the modem. More...
 
uint8 modem_connect ()
 Establish modem connection with internet. More...
 
uint8 modem_disconnect ()
 Close modem connection to network. More...
 
uint8 modem_check_network ()
 Network Registration Report. Function wrapper for AT+CREG command. More...
 
uint8 modem_get_meid (char *meid)
 Mobile Equipment Identifier. Function wrapper for AT::MEID command. More...
 
uint8 modem_check_signal_quality (int *rssi, int *fer)
 Signal Quality Check. Function wrapper for AT+CSQ command. More...
 
int modem_get_socket_status ()
 Socket Status. Function wrapper for AT::SS command. More...
 
uint8 modem_set_flow_control (uint8 param)
 Set Flow Control. Set command controls the RS232 flow control behaviour. More...
 
uint8 modem_set_error_reports (uint8 param)
 Report Mobile Equipment Error. Set command enables/disables the report of result code. More...
 
uint8 modem_pdp_context_toggle (uint8 activate_pdp)
 Context Activation. Execution command is used to activate or deactivate the specified PDP context. More...
 
uint8 modem_socket_dial (char *socket_dial_str, char *endpoint, int port, int construct_new, int ssl_enabled)
 Opens a remote connection via socket. More...
 
uint8 modem_socket_close (int ssl_enabled)
 Closes the socket on the modem. More...
 
void construct_generic_request (char *send_str, char *body, char *host, char *route, int port, char *method, char *connection_type, char *extra_headers, int extra_len, char *http_protocol)
 Constructs a generic HTTP request. More...
 
int send_chunked_request (char *send_str, char *chunk, int chunk_len, char *send_cmd, char *ring_cmd, char *term_char)
 Breaks request string into packets and sends them. More...
 
int read_response (char message[], char *recv_cmd, char *ring_cmd, uint8 get_response, int max_loops, int max_message_size)
 Reads a HTTP response with a chunked of fixed-length transfer encoding over multiple modem buffers. More...
 
uint8 modem_send_recv (char *send_str, char *response, uint8 get_response, int ssl_enabled)
 TODO. More...
 
 CY_ISR (Telit_isr_rx)
 

Variables

int iter = 0
 
uint8 modem_state
 
uint8 lock_acquired = 0u
 
uint8 ready = 0u
 
uint16 uart_string_index = 0u
 
uint32 feed_id
 
char modem_received_buffer [MODEM_BUFFER_LENGTH] = {'\0'}
 
char request_chunk [CHUNK_SIZE] = {'\0'}
 
char * modem_apn = "epc.tmobile.com"
 

Detailed Description

Implements functions for connecting to the cellular network, and sending/receiving packets.

Author
Brandon Wong, Matt Bartos and Ivan Mondragon
Version
TODO
Date
2017-06-01

Function Documentation

uint8 at_write_command ( char *  uart_string,
char *  expected_response,
uint32  uart_timeout 
)

Write AT command to cell module.

Parameters
uart_stringAT command to write to buffer
expected_responseSubstring that is expected in the response
uart_timeoutTimeout in milliseconds
Returns
1u if expected response is found; 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

void construct_generic_request ( char *  send_str,
char *  body,
char *  host,
char *  route,
int  port,
char *  method,
char *  connection_type,
char *  extra_headers,
int  extra_len,
char *  http_protocol 
)

Constructs a generic HTTP request.

Parameters
send_strBuffer to store generated HTTP request.
bodyHTTP Body.
hostHost.
routeRoute.
portPort.
methodHTTP Method.
connection_typeHTTP Connection.
extra_headersAny extra HTTP headers.
extra_lenLength of the extra headers.
http_protocolHTTP protocol.

Here is the caller graph for this function:

uint8 modem_check_network ( )

Network Registration Report. Function wrapper for AT+CREG command.

Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_check_signal_quality ( int *  rssi,
int *  fer 
)

Signal Quality Check. Function wrapper for AT+CSQ command.

Parameters
rssiAn int* where rssi is to be stored.
ferAn int* where fer is to be stored.
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

uint8 modem_connect ( )

Establish modem connection with internet.

Returns
Modem state. {OFF, IDLE, READY}

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_disconnect ( )

Close modem connection to network.

Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_get_meid ( char *  meid)

Mobile Equipment Identifier. Function wrapper for AT::MEID command.

Parameters
meidString of size large enough to store an meid of 14 characters. In other words, sizeof(meid) > 14.
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

int modem_get_socket_status ( )

Socket Status. Function wrapper for AT::SS command.

Returns
Socket status on success. 0 or -1 on failure, where 0 means failure to parse the uart received string.

Here is the call graph for this function:

uint8 modem_pdp_context_toggle ( uint8  activate_pdp)

Context Activation. Execution command is used to activate or deactivate the specified PDP context.

Parameters
activate_pdpenable flag:
  • 0 = deactivate the context
  • 1 = activate the context
Returns
1u on successful toggle, 0u otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_power_off ( )

Powers off the modem.

Returns
1u on success.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_power_on ( )

Powers on the modem.

Returns
Modem state {OFF, IDLE, READY} or 0u on failure to power on.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_reset ( )

Resets the modem.

Returns
Modem state. {OFF, IDLE, READY}

Here is the caller graph for this function:

uint8 modem_send_recv ( char *  send_str,
char *  response,
uint8  get_response,
int  ssl_enabled 
)

TODO.

Parameters
send_str
response
get_response
ssl_enabled
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_set_error_reports ( uint8  param)

Report Mobile Equipment Error. Set command enables/disables the report of result code.

Parameters
paramenable flag:
  • 0 : disable +CME ERROR:<err> reports, use only ERROR report.
  • 1 : enable +CME ERROR:<err> reports, with <err> in numeric format
  • 2 : enable +CME ERROR: <err> reports, with <err> in verbose format
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_set_flow_control ( uint8  param)

Set Flow Control. Set command controls the RS232 flow control behaviour.

Parameters
paramOne of the following ints:
  • 0 = no flow control
  • 1 = hardware mono-directional flow control (only CTS active)
  • 2 = software mono-directional flow control (XON/XOFF)
  • 3 = hardware bi-directional flow control (both RTS/CTS active) (factory default)
  • 4 = software bi-directional with filtering (XON/XOFF)
  • 5 = pass through: software bi-directional without filtering (XON/XOF
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_setup ( )

Initialize configurations for the modem.

Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_shutdown ( )

Shutdown sequence to stop/power down modem components.

Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

uint8 modem_socket_close ( int  ssl_enabled)

Closes the socket on the modem.

Parameters
ssl_enabledNeeds to know if ssl is enabled to close the socket properly.
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_socket_dial ( char *  socket_dial_str,
char *  endpoint,
int  port,
int  construct_new,
int  ssl_enabled 
)

Opens a remote connection via socket.

Parameters
socket_dial_str
endpointEndpoint
portPort
construct_newContruct new socket dial string flag
ssl_enabledSSL enabled flag
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8 modem_startup ( int *  conn_attempts)

Startup sequence to power on the modem, start modem components and prepare for sending/receiving messages over the network.

Parameters
conn_attemptsBuffer to store the number of attempted connections
Returns
Modem status.

Here is the call graph for this function:

Here is the caller graph for this function:

int read_response ( char  message[],
char *  recv_cmd,
char *  ring_cmd,
uint8  get_response,
int  max_loops,
int  max_message_size 
)

Reads a HTTP response with a chunked of fixed-length transfer encoding over multiple modem buffers.

Parameters
messageThe message buffer to write to
recv_cmdThe Telit receive command to use: AT::SRECV=1,<BYTES> or AT::SSLRECV=1,<BYTES>
ring_cmdThe Telit ring URC to seek: SRING: 1 or SSLRING: 1
get_response1u if the response is to be downloaded to the response buffer; 0u otherwise
max_loopsThe maximum number of times to loop; used as a safeguard
max_message_sizeThe maximum size of the message
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

int send_chunked_request ( char *  send_str,
char *  chunk,
int  chunk_len,
char *  send_cmd,
char *  ring_cmd,
char *  term_char 
)

Breaks request string into packets and sends them.

Parameters
send_strThe request string to be sent
chunkEmpty buffer for holding string chunks
chenk_lenThe size of the chunks to send
send_cmdThe AT command used to send data: SSEND, SSENDEXT or SSLSEND
ring_cmdThe ring command to look for: SRING or SSLRING
term_charThe termination character to use: '\032' for Telit
Returns
1u on success, 0u otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

void uart_string_reset ( )

Reset modem_received_buffer, clear RX buffer, and reset string index.

Returns
NULL

Here is the caller graph for this function: