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

AVRGSM_FILES/AVRGSM_zip.h File Reference


Detailed Description

Atmel Corporation

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

Definition in file AVRGSM_zip.h.

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

Included by dependency graph

Go to the source code of this file.

Defines

#define hex_nmbr   "0123456789ABCDEF"
 Flash string container, look up table.

#define MESSAGE_ENCODED_SIZE   70
 Size of SMS payload.

#define MESSAGE_LENGTH   80
 Max allowed text in SMS.


Functions

int ZIP_atoi (unsigned char *a)
 Converting ascii char string to int.

int ZIP_compress (unsigned char *in, unsigned char *discarded, unsigned char ret[])
 ZIP_compress will take a user defined text code it into the PDU format.

int ZIP_decompress (unsigned char *compressed, unsigned char *decompressed)
 ZIP_decompress will decode a message in PDU format into a readable string.

int ZIP_htoi (unsigned char hex)
 Convert hex to int.

void ZIP_itoh (int n, unsigned char *ret)
 Converting int [0->255] to hex value.


Define Documentation

#define hex_nmbr   "0123456789ABCDEF"
 

Flash string container, look up table.

Definition at line 27 of file AVRGSM_zip.h.

#define MESSAGE_ENCODED_SIZE   70
 

Size of SMS payload.

Definition at line 25 of file AVRGSM_zip.h.

#define MESSAGE_LENGTH   80
 

Max allowed text in SMS.

Definition at line 26 of file AVRGSM_zip.h.

Referenced by ZIP_compress().


Function Documentation

int ZIP_atoi unsigned char *  a  ) 
 

Converting ascii char string to int.

Note:
Will return value as int.
Parameters:
*a ASCII string to be converted.
n Return Integer.
Return values:
int integer value

Definition at line 140 of file AVRGSM_zip.c.

Referenced by TOOLS_decodeCMTI().

00141 { 00142 00143 int i, n; //Help variables 00144 00145 n = 0; //Init 00146 00147 for( i=0; ( a[ i ] >= '0' ) && ( a[ i ] <= '9' ); ++i ) //Running through string converting from ascii to integer 00148 { 00149 n = 10*n + ( a[ i ] - '0' ); //Adding value to return Integer 00150 } 00151 00152 return n; 00153 }

int ZIP_compress unsigned char *  in,
unsigned char *  discarded,
unsigned char  ret[]
 

ZIP_compress will take a user defined text code it into the PDU format.

Parameters:
*in Pointer to user defined text
*discarded Number of discarded chars, used later to calculate message length
ret[] return array for the encoded message
Return values:
i Length of read string

Local variables

Definition at line 40 of file AVRGSM_zip.c.

References hex_lookup, mask, MESSAGE_LENGTH, and power.

Referenced by API_sendmsg().

00041 { 00042 00044 int i,ii,iii; 00045 unsigned char encode_c, now_c, next_c; 00046 00047 //Initialization 00048 *discarded = 0; 00049 00050 for( i = ii = iii = 0; ( in[i] != '\0' ) && ( i < MESSAGE_LENGTH ); ) //Run through whole string 00051 { 00052 now_c = in[ i++ ]; //This char 00053 next_c = in[ i ]; //Next potentially '\0' 00054 00055 //Last char? 00056 if( next_c == '\0' ) 00057 { 00058 next_c = 0; 00059 } 00060 00061 encode_c = ( now_c >> ii )+ ( mask[ ii ] & next_c )*power[ ii ]; 00062 ret[ iii++ ] = hex_lookup[ ( encode_c >> 4 ) & 0x0F ]; //Insert first hex part 00063 ret[ iii++ ] = hex_lookup[ ( encode_c & 0x0F ) ]; //Insert last hex part 00064 00065 if( ii == 6 ) //We have read a chunk of 7 chars, the next one will be discarded 00066 { 00067 ii = 0; 00068 i++; 00069 (*discarded)++; 00070 } 00071 00072 else 00073 { 00074 ii++; 00075 } 00076 } 00077 00078 ret[iii] = '\0'; 00079 00080 return i; 00081 }

int ZIP_decompress unsigned char *  compressed,
unsigned char *  decompressed
 

ZIP_decompress will decode a message in PDU format into a readable string.

Parameters:
*compressed PDU encoded text
*decompressed Pointer to return array
Return values:
iii Number of decoded chars

Local variables

Definition at line 91 of file AVRGSM_zip.c.

References mask, and ZIP_htoi().

Referenced by API_readmsg().

00092 { 00093 00095 int i,ii,iii; //String index 00096 unsigned char rest_c, ans_c ,dec_c , this_c, next_c; //Read and temorary variables 00097 00098 for( i = ii = iii = rest_c = 0; (this_c = compressed[i++]) != '\0'; ) //Run through complete string 00099 { 00100 //Read: 00101 next_c = compressed[i++]; //Read from in buffer in AVR_SMS_com.c 00102 00103 //Convert: 00104 dec_c = 16 * ZIP_htoi( this_c ) + ZIP_htoi( next_c ); //Decimal value of the two chars 00105 ans_c = dec_c & mask[6 - ii]; //Mask out the correct bits 00106 ans_c <<= ii; //Left shift proper correct of times 00107 decompressed[iii++] = ans_c + rest_c; //Store 00108 00109 rest_c = (dec_c & ~mask[6 - ii]) >> ( 7 - ii ); //Saving up for next time 00110 00111 if( ii == 6) //Do carry 00112 { 00113 ii = 0; 00114 decompressed[ iii++ ] = rest_c; 00115 rest_c = 0; 00116 } 00117 00118 else 00119 { 00120 ii++; 00121 } 00122 00123 } 00124 00125 decompressed[ iii ] = '\0'; //Terminate string in a proper manner 00126 return iii; //Return length 00127 }

Here is the call graph for this function:

int ZIP_htoi unsigned char  hex  ) 
 

Convert hex to int.

This function will take a hex in char format and return int value

Parameters:
hex Hex value to convert
Return values:
int Integer representation of hex-value

Definition at line 164 of file AVRGSM_zip.c.

Referenced by TOOLS__decodeCMGR(), and ZIP_decompress().

00165 { 00166 00167 if( ( hex >= 'A' ) && ( hex <= 'F' ) ) //Test if hex is A-->F? 00168 { 00169 return hex - 'A' + 10; 00170 } 00171 else //Must have something else then:0-->9 00172 { 00173 return hex - '0'; 00174 } 00175 }

void ZIP_itoh int  n,
unsigned char *  ret
 

Converting int [0->255] to hex value.

Note:
Will return hex value as string.
Parameters:
n Integer value to be decoded.
ret Return array.

Definition at line 187 of file AVRGSM_zip.c.

References hex_lookup.

Referenced by API_sendmsg().

00188 { 00189 00190 ret[ 0 ] = hex_lookup[ ( n >> 4 ) & 0x0F ]; 00191 ret[ 1 ] = hex_lookup[ ( n & 0x0F ) ]; 00192 ret[ 2 ] = '\0'; 00193 }


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