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

AVRGSM_FILES/AVRGSM_zip.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation. 00022 //Include 00023 #include"AVRGSM_zip.h" 00024 00026 const unsigned char __flash hex_lookup[] = hex_nmbr; 00027 const unsigned char __flash mask[7] = {1,3,7,15,31,63,127}; 00028 const unsigned char __flash power[7] = {128,64,32,16,8,4,2}; 00029 00030 00040 int ZIP_compress( unsigned char *in, unsigned char *discarded, unsigned char ret[] ) 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 } 00082 00083 00091 int ZIP_decompress( unsigned char *compressed, unsigned char *decompressed ) 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 } 00128 00129 00140 int ZIP_atoi( unsigned char *a ) 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 } 00154 00155 00164 int ZIP_htoi( unsigned char hex ) 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 } 00176 00177 00187 void ZIP_itoh( int n, unsigned char *ret ) 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:39 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7