00001
00024
00025 #include <stdint.h>
00026 #include <stdbool.h>
00027
00028 #include "compiler.h"
00029 #include "utilities.h"
00030
00031
00032
00033
00034
00035
00036
00047 bool stringCompare( const uint8_t *str, const uint8_t __flash *fstr ){
00048
00049
00050 while( !( ( *str == END_OF_STRING ) || ( *fstr == END_OF_STRING ) ) ){
00051
00052
00053 if( *str != *fstr ){
00054
00055 break;
00056 }
00057
00058 str++;
00059 fstr++;
00060 }
00061
00062
00063 if( ( ( *str == END_OF_STRING ) && ( *fstr == END_OF_STRING ) ) ){
00064
00065 return true;
00066 }
00067
00068
00069 else{
00070
00071 return false;
00072 }
00073 }
00074
00085 bool htoi8( uint8_t *hex, uint8_t *ret ){
00086
00087 uint8_t i = 0x00;
00088 uint8_t radix = 1;
00089 *ret = 0x00;
00090
00091
00092 while( *hex != '\0' ){
00093
00094
00095
00096 if( !( ( ( *hex >= '0' ) && ( *hex <= '9' ) ) ||
00097 ( ( *hex >= 'A' ) && ( *hex <= 'F' ) ) ) ){
00098
00099 return false;
00100 }
00101
00102 hex++;
00103 i++;
00104 }
00105
00106
00107 if( i <= 0x02 ){
00108
00109 hex--;
00110
00111
00112 for( ; i > 0; i-- ){
00113
00114
00115 if( ( *hex >= '0' ) && ( *hex <= '9' ) ){
00116
00117 *ret += radix * ( *hex - '0' );
00118 }
00119
00120
00121 else{
00122
00123 *ret += radix * ( *hex - 'A' + 10 );
00124 }
00125
00126 hex--;
00127 radix = radix << 4;
00128 }
00129
00130 return true;
00131 }
00132
00133
00134 else{
00135
00136 return false;
00137 }
00138 }
00139
00150 bool htoi16( uint8_t *hex, uint16_t *ret ){
00151
00152 uint8_t i = 0x00;
00153 uint16_t radix = 1;
00154 *ret = 0x0000;
00155
00156
00157 while( *hex != '\0' ){
00158
00159
00160
00161 if( !( ( ( *hex >= '0' ) && ( *hex <= '9' ) ) ||
00162 ( ( *hex >= 'A' ) && ( *hex <= 'F' ) ) ) ){
00163
00164 return false;
00165 }
00166
00167 hex++;
00168 i++;
00169 }
00170
00171
00172 if( i <= 0x04 ){
00173
00174 hex--;
00175
00176
00177 for( ; i > 0; i-- ){
00178
00179
00180 if( ( *hex >= '0' ) && ( *hex <= '9' ) ){
00181
00182 *ret += radix * ( *hex - '0' );
00183 }
00184
00185
00186 else{
00187
00188 *ret += radix * ( *hex - 'A' + 10 );
00189 }
00190
00191 hex--;
00192 radix = radix << 4;
00193 }
00194
00195 return true;
00196 }
00197
00198
00199 else{
00200
00201 return false;
00202 }
00203 }