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

AVRGSM_FILES/AVRGSM_api.h File Reference


Detailed Description

Atmel Corporation

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

Definition in file AVRGSM_api.h.

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

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.


Function Documentation

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:


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