Main Page | Data Structures | File List | Data Fields | Globals

AVRGSM_FILES/AVRGSM_api.c File Reference


Detailed Description

Atmel Corporation

Revision
1.2
Date
Wednesday, January 26, 2005 10:43:44 UTC

Definition in file AVRGSM_api.c.

#include <inavr.h>
#include "AVRGSM_com.h"
#include "AVRGSM_zip.h"
#include "AVRGSM_header.h"
#include "AVRGSM_tools.h"
#include "AVRGSM_api.h"

Include dependency graph for AVRGSM_api.c:

Include dependency graph

Go to the source code of this file.

Functions

int API_check_acknowledge (void)
 Function prototype.

int API_deletemsg (int index)
 Delete a message from a given index.

int API_modem_init (void)
 Used to setup the connected GSM modem.

int API_readmsg (int ind)
 Read message from a given index.

int API_sendmsg (unsigned char *msg)
 Send message.


Variables

const unsigned char __flash AT_CMGD [] = "AT+CMGD="
 Delete message at index.

const unsigned char __flash AT_CMGR [] = "AT+CMGR="
 Read from index.

const unsigned char __flash AT_CMGS [] = "AT+CMGS="
 Send mmessage.

const unsigned char __flash AT_CNMI [] = "AT+CNMI=1,1,,,1\r\n"
 Identification of new sms.

const unsigned char __flash AT_CPMS [] = "AT+CPMS=\"ME\",\"ME\",\"ME\"\r\n"
 Preferred storage.

const unsigned char __flash ATE0 [] = "ATE0\r\n"
 Echo off.

const unsigned char __flash CRLF [] = "\r\n"
 Carrige return Line feed.

unsigned char msgbuff [161]
 Message buffer for coded and decoded messages.

int rx_ack
 Extern flag from AVRSMS_com.c.


Function Documentation

int API_check_acknowledge void   ) 
 

Function prototype.

This function is very important. It checks if an acknowledge has been received from the phone. A counting loop is also included to avoid waiting for a acknowledge that never arrives.

Parameters:
void 
Return values:
1 Success, correct acknowledge
0 Error, returned "ERROR" or timed out

Local variables

Definition at line 278 of file AVRGSM_api.c.

References COM_rx_off(), COM_rx_reset(), and rx_ack.

Referenced by API_deletemsg(), API_modem_init(), API_readmsg(), and API_sendmsg().

00279 { 00280 00282 static unsigned int i, ii; 00283 00284 for( i = 0; ( rx_ack == 0 ) && ( i < 65535 ); i++ ) //Wait loop 00285 { 00286 for( ii = 0; ii < 10; ii++ ) 00287 { 00288 ; 00289 } 00290 } 00291 00292 if( rx_ack > 0 ) //Everything worked out fine...rx turned off 00293 { 00294 rx_ack = 0; //Reset flag 00295 return 1; 00296 } 00297 00298 else //A timeout could result from no acknowledge, wrong acknowledge or buffer overrun 00299 { 00300 COM_rx_off( ); //Receiver off 00301 COM_rx_reset( ); //Reset buffer and interrupt routine 00302 return 0; //Timed out, or wrong acknowledge from phone 00303 } 00304 }

Here is the call graph for this function:

int API_deletemsg int  index  ) 
 

Delete a message from a given index.

This function will use the "AT+CMGD" command to delete the message @ index

Parameters:
index index to delete from
Return values:
1 Success
0 Error

Definition at line 125 of file AVRGSM_api.c.

References API_check_acknowledge(), AT_CMGD, COM_put_integer(), COM_putsf(), COM_rx_on(), COM_rx_reset(), COM_setSearchString(), CRLF, and OK_.

Referenced by ST_delete_msg().

00126 { 00127 00128 COM_rx_reset( ); //Reset system 00129 COM_setSearchString( OK_ ); //Set OK to be search string 00130 COM_putsf( AT_CMGD ); //Delete message 00131 COM_put_integer( index ); //@index 00132 COM_putsf( CRLF ); //CR+LF 00133 COM_rx_on( ); //Receiver on 00134 00135 if( API_check_acknowledge( ) > 0 ) //Delete = OK 00136 { 00137 return 1; 00138 } 00139 00140 else //Delete != OK 00141 { 00142 return 0; 00143 } 00144 }

Here is the call graph for this function:

int API_modem_init void   ) 
 

Used to setup the connected GSM modem.

This function will send AT-Commands to the phone. These commands will setup the phone to: -Use correct storage, AT+CPMS -Indicate new message, AT+CNMI -Turn echo off, ATE0

Parameters:
void 
Return values:
1 Success
0 Error with echo off
-1 Error with preferred storage
-2 Error with indication

Definition at line 73 of file AVRGSM_api.c.

References API_check_acknowledge(), AT_CNMI, AT_CPMS, ATE0, COM_putsf(), COM_rx_on(), COM_rx_reset(), COM_setSearchString(), and OK_.

Referenced by ST_init_phone().

00074 { 00075 00076 COM_rx_reset( ); //Reset system 00077 COM_setSearchString( OK_ ); //Set OK to be search string 00078 COM_putsf( ATE0 ); //Send turn echo off 00079 COM_rx_on( ); //Receiver on 00080 00081 if( API_check_acknowledge( ) > 0 ) //Echo off = OK 00082 { 00083 COM_putsf(AT_CPMS); //Send preferred storage 00084 COM_rx_on( ); //Receiver on 00085 00086 if( API_check_acknowledge( ) > 0 ) //Preferred storage = OK 00087 { 00088 COM_putsf(AT_CNMI); //Send preferred indication of new messages 00089 COM_rx_on( ); //Receiver on 00090 00091 if( API_check_acknowledge( ) > 0 ) //Preferred indication = OK 00092 { 00093 return 1; 00094 } 00095 00096 else //Preferred indication != OK 00097 { 00098 return -2; 00099 } 00100 } 00101 00102 else //Preferred storage != OK 00103 { 00104 return -1; 00105 } 00106 } 00107 00108 else //Echo off != OK 00109 { 00110 return 0; 00111 } 00112 }

Here is the call graph for this function:

int API_readmsg int  ind  ) 
 

Read message from a given index.

This function is used to read a newly arrived message from a given index. The message is decoded, and stored in the msgbuff.

Parameters:
ind index to read message from
Return values:
i Length of new message
0 Error, No acknowledge from phone

Local variables

Definition at line 232 of file AVRGSM_api.c.

References API_check_acknowledge(), AT_CMGR, COM_put_integer(), COM_putsf(), COM_rx_on(), COM_rx_reset(), COM_setSearchString(), CRLF, msgbuff, OK_, TOOLS__decodeCMGR(), and ZIP_decompress().

Referenced by ST_read().

00233 { 00234 00236 unsigned char *encodedmsg; //Pointer to encoded message 00237 int i; 00238 00239 //Init 00240 encodedmsg = '\0'; 00241 i = 0; 00242 00243 COM_rx_reset( ); //Reset system 00244 COM_setSearchString( OK_ ); //Set OK to be search string 00245 COM_putsf( AT_CMGR ); //Read message 00246 COM_put_integer( ind ); //@index 00247 COM_putsf( CRLF ); //CR+LF 00248 COM_rx_on( ); //Receiver on, wait for acknowledge 00249 00250 if( API_check_acknowledge() > 0 ) //Read = OK 00251 { 00252 encodedmsg = TOOLS__decodeCMGR( ind ); //Get encoded message from the data returned from the phone 00253 i = ZIP_decompress( encodedmsg, msgbuff ); //Decompress this message 00254 00255 //COM_puts( msgbuff ); //Could be used during test, where the GSM modem is switched with a terminal application 00256 00257 return i; 00258 } 00259 00260 else //Read != OK 00261 { 00262 return 0; 00263 } 00264 }

Here is the call graph for this function:

int API_sendmsg unsigned char *  msg  ) 
 

Send message.

This function will take your user defined message, encode this text, add the header information found in AVRSMS_header.h. If successful, the message will be forwarded to the connected GSM modem

Parameters:
*msg unsigned char pointer user defined message
Return values:
1 Success, message sent
0 Error doing compression
-1 No "> " from phone
-2 No message sent acknowledge

Local variables

Definition at line 160 of file AVRGSM_api.c.

References API_check_acknowledge(), AT_CMGS, COM_put_integer(), COM_putchar(), COM_puts(), COM_putsf(), COM_rx_on(), COM_rx_reset(), COM_setSearchString(), CRLF, HEADER_LEN, msgbuff, OK_, PDU_HEADER, READY_, ZIP_compress(), and ZIP_itoh().

Referenced by ST_send().

00161 { 00162 00164 int payload_len, len; //Total length of message, and length of user text 00165 unsigned char payload_len_c[3], jump; 00166 00167 //Init 00168 payload_len = len = 0; 00169 payload_len_c[0] = jump = '\0'; 00170 00171 //If necessary turn interrupts off 00172 if( ( payload_len = ZIP_compress( msg, &jump, msgbuff) ) == 0 ) //Convert user text to pdu format 00173 { 00174 return 0; //Something wrong happend during compression 00175 } 00176 00177 //Compression ok 00178 else 00179 { 00180 ZIP_itoh(payload_len, &payload_len_c[0]); //Convert Integer payload to hex in string format 00181 len = HEADER_LEN + payload_len - jump; //Calculate overall length 00182 00183 COM_rx_reset( ); //Clear rx_buff 00184 COM_setSearchString( READY_ ); //Set "> " to be search string 00185 COM_putsf( AT_CMGS ); //Send message 00186 COM_put_integer( len ); //append length 00187 COM_putsf( CRLF ); //CR+LF 00188 COM_rx_on( ); //Receiver on 00189 00190 //Append payload 00191 if( API_check_acknowledge() > 0 ) //Wait for acknowledge = "> " 00192 { 00193 COM_rx_reset( ); //Clear rx_buff 00194 COM_setSearchString( OK_ ); //Set "OK" to be search string 00195 COM_putsf( PDU_HEADER ); 00196 COM_puts( payload_len_c ); 00197 COM_puts( msgbuff ); 00198 COM_putchar( 26 ); 00199 COM_rx_on( ); //Receiver on 00200 00201 if( API_check_acknowledge() > 0 ) //Acknowledge = OK 00202 { 00203 return 1; 00204 } 00205 00206 else //Acknowledge != OK 00207 { 00208 return -2; 00209 } 00210 00211 } 00212 00213 else //Acknowledge != "> " 00214 { 00215 return -1; 00216 } 00217 } 00218 }

Here is the call graph for this function:


Variable Documentation

const unsigned char __flash AT_CMGD[] = "AT+CMGD="
 

Delete message at index.

Definition at line 48 of file AVRGSM_api.c.

Referenced by API_deletemsg().

const unsigned char __flash AT_CMGR[] = "AT+CMGR="
 

Read from index.

Definition at line 49 of file AVRGSM_api.c.

Referenced by API_readmsg().

const unsigned char __flash AT_CMGS[] = "AT+CMGS="
 

Send mmessage.

Definition at line 50 of file AVRGSM_api.c.

Referenced by API_sendmsg().

const unsigned char __flash AT_CNMI[] = "AT+CNMI=1,1,,,1\r\n"
 

Identification of new sms.

Definition at line 46 of file AVRGSM_api.c.

Referenced by API_modem_init().

const unsigned char __flash AT_CPMS[] = "AT+CPMS=\"ME\",\"ME\",\"ME\"\r\n"
 

Preferred storage.

Definition at line 47 of file AVRGSM_api.c.

Referenced by API_modem_init().

const unsigned char __flash ATE0[] = "ATE0\r\n"
 

Echo off.

Definition at line 45 of file AVRGSM_api.c.

Referenced by API_modem_init().

const unsigned char __flash CRLF[] = "\r\n"
 

Carrige return Line feed.

Definition at line 51 of file AVRGSM_api.c.

Referenced by API_deletemsg(), API_readmsg(), and API_sendmsg().

unsigned char msgbuff[161]
 

Message buffer for coded and decoded messages.

Definition at line 42 of file AVRGSM_api.c.

Referenced by API_readmsg(), API_sendmsg(), and ST_read().

int rx_ack
 

Extern flag from AVRSMS_com.c.

Definition at line 39 of file AVRGSM_api.c.

Referenced by API_check_acknowledge(), COM_rx_reset(), main(), and USART0_RX_interrupt().


Generated on Tue Nov 1 16:21:40 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7