![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
utils.cpp@122:480c44b0e205, 2015-05-11 (annotated)
- Committer:
- klauss
- Date:
- Mon May 11 15:16:36 2015 +0000
- Revision:
- 122:480c44b0e205
- Parent:
- 121:ee02790d00b7
- Child:
- 124:c1b6c893e1c3
E00 - Limitar em 1500 o show_sip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 122:480c44b0e205 | 1 | #include "utils.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 117:e9facba9db27 | 3 | static char itoh[16]; |
klauss | 117:e9facba9db27 | 4 | char hexbuf[10]; |
klauss | 117:e9facba9db27 | 5 | |
klauss | 119:ee6a53069455 | 6 | int hex_init(void) { |
klauss | 117:e9facba9db27 | 7 | itoh[0] = '0'; itoh[1] = '1'; itoh[2] = '2'; itoh[3] = '3'; |
klauss | 117:e9facba9db27 | 8 | itoh[4] = '4'; itoh[5] = '5'; itoh[6] = '6'; itoh[7] = '7'; |
klauss | 117:e9facba9db27 | 9 | itoh[8] = '8'; itoh[9] = '9'; itoh[10] = 'a'; itoh[11] = 'b'; |
klauss | 117:e9facba9db27 | 10 | itoh[12] = 'c'; itoh[13] = 'd'; itoh[14] = 'e'; itoh[15] = 'f'; |
klauss | 119:ee6a53069455 | 11 | return ( 0 ); |
klauss | 117:e9facba9db27 | 12 | } |
klauss | 117:e9facba9db27 | 13 | |
klauss | 117:e9facba9db27 | 14 | char * hex8 (uint8_t i) { |
klauss | 117:e9facba9db27 | 15 | hexbuf[0] = itoh[(i>>4) & 0x0f]; |
klauss | 117:e9facba9db27 | 16 | hexbuf[1] = itoh[i & 0x0f]; |
klauss | 117:e9facba9db27 | 17 | hexbuf[2] = 0; |
klauss | 117:e9facba9db27 | 18 | return hexbuf; |
klauss | 117:e9facba9db27 | 19 | } |
klauss | 117:e9facba9db27 | 20 | |
klauss | 117:e9facba9db27 | 21 | char * hex16 (uint16_t i) { |
klauss | 117:e9facba9db27 | 22 | hexbuf[0] = itoh[(i>>12) & 0x0f]; |
klauss | 117:e9facba9db27 | 23 | hexbuf[1] = itoh[(i>>8) & 0x0f]; |
klauss | 117:e9facba9db27 | 24 | hexbuf[2] = itoh[(i>>4) & 0x0f]; |
klauss | 117:e9facba9db27 | 25 | hexbuf[3] = itoh[i & 0x0f]; |
klauss | 117:e9facba9db27 | 26 | hexbuf[4] = 0; |
klauss | 117:e9facba9db27 | 27 | return hexbuf; |
klauss | 117:e9facba9db27 | 28 | } |
klauss | 117:e9facba9db27 | 29 | |
klauss | 74:81c47fff88a5 | 30 | int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); } |
klauss | 68:b54993674190 | 31 | |
klauss | 74:81c47fff88a5 | 32 | int convert_ext_to_port( int ext ){ |
klauss | 74:81c47fff88a5 | 33 | if( ext < 1000 ) return ext; |
klauss | 74:81c47fff88a5 | 34 | |
klauss | 74:81c47fff88a5 | 35 | else{ |
klauss | 74:81c47fff88a5 | 36 | int aux = 0; |
klauss | 74:81c47fff88a5 | 37 | aux = ( ext / 1000 ) * 1000; |
klauss | 74:81c47fff88a5 | 38 | ext -= aux; |
klauss | 74:81c47fff88a5 | 39 | aux += ext % 100; |
klauss | 74:81c47fff88a5 | 40 | return( aux ); |
klauss | 74:81c47fff88a5 | 41 | } |
klauss | 0:4d17cd9c8f9d | 42 | } |
klauss | 0:4d17cd9c8f9d | 43 | |
klauss | 74:81c47fff88a5 | 44 | void xstrcpy(uint8_t * dest, const uint8_t * src ){ |
klauss | 74:81c47fff88a5 | 45 | while (*src) *dest++ = *src++; |
klauss | 74:81c47fff88a5 | 46 | *dest = 0; |
klauss | 0:4d17cd9c8f9d | 47 | } |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 78:1353744f01e1 | 49 | void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size ){ |
klauss | 74:81c47fff88a5 | 50 | while (size--) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 51 | } |
klauss | 0:4d17cd9c8f9d | 52 | |
klauss | 74:81c47fff88a5 | 53 | void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size){ |
klauss | 74:81c47fff88a5 | 54 | size >>= 2; |
klauss | 74:81c47fff88a5 | 55 | while (size--) *dest++ = *src++; |
klauss | 78:1353744f01e1 | 56 | } |
klauss | 78:1353744f01e1 | 57 | |
klauss | 78:1353744f01e1 | 58 | uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2){ |
klauss | 78:1353744f01e1 | 59 | while (*s1) { |
klauss | 78:1353744f01e1 | 60 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 78:1353744f01e1 | 61 | } |
klauss | 78:1353744f01e1 | 62 | if ( *s2 == 0 ) |
klauss | 78:1353744f01e1 | 63 | return 1; /* matches */ |
klauss | 78:1353744f01e1 | 64 | else |
klauss | 78:1353744f01e1 | 65 | return 0; /* does not match */ |
klauss | 81:3656f00ab3db | 66 | } |
klauss | 81:3656f00ab3db | 67 | |
klauss | 81:3656f00ab3db | 68 | uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size){ |
klauss | 81:3656f00ab3db | 69 | while (size--) { |
klauss | 81:3656f00ab3db | 70 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 81:3656f00ab3db | 71 | } |
klauss | 81:3656f00ab3db | 72 | return 1; /* matches */ |
klauss | 74:81c47fff88a5 | 73 | } |