![](/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@124:c1b6c893e1c3, 2015-05-13 (annotated)
- Committer:
- klauss
- Date:
- Wed May 13 14:25:57 2015 +0000
- Revision:
- 124:c1b6c893e1c3
- Parent:
- 122:480c44b0e205
- Child:
- 135:2f4290590e51
wip__
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 | 124:c1b6c893e1c3 | 30 | int ls_comp ( const void * a, const void * b ) |
klauss | 124:c1b6c893e1c3 | 31 | { |
klauss | 124:c1b6c893e1c3 | 32 | if ( reverse_list ) return( *( int * )b - *( int * )a ); |
klauss | 124:c1b6c893e1c3 | 33 | |
klauss | 124:c1b6c893e1c3 | 34 | else return( *( int * )a - *( int * )b ); |
klauss | 124:c1b6c893e1c3 | 35 | |
klauss | 124:c1b6c893e1c3 | 36 | } |
klauss | 124:c1b6c893e1c3 | 37 | |
klauss | 124:c1b6c893e1c3 | 38 | int wake_comp ( const void * a, const void * b ) |
klauss | 124:c1b6c893e1c3 | 39 | { |
klauss | 124:c1b6c893e1c3 | 40 | return( *( int * )a - *( int * )b ); |
klauss | 124:c1b6c893e1c3 | 41 | } |
klauss | 68:b54993674190 | 42 | |
klauss | 74:81c47fff88a5 | 43 | int convert_ext_to_port( int ext ){ |
klauss | 74:81c47fff88a5 | 44 | if( ext < 1000 ) return ext; |
klauss | 74:81c47fff88a5 | 45 | |
klauss | 74:81c47fff88a5 | 46 | else{ |
klauss | 74:81c47fff88a5 | 47 | int aux = 0; |
klauss | 74:81c47fff88a5 | 48 | aux = ( ext / 1000 ) * 1000; |
klauss | 74:81c47fff88a5 | 49 | ext -= aux; |
klauss | 74:81c47fff88a5 | 50 | aux += ext % 100; |
klauss | 74:81c47fff88a5 | 51 | return( aux ); |
klauss | 74:81c47fff88a5 | 52 | } |
klauss | 0:4d17cd9c8f9d | 53 | } |
klauss | 0:4d17cd9c8f9d | 54 | |
klauss | 74:81c47fff88a5 | 55 | void xstrcpy(uint8_t * dest, const uint8_t * src ){ |
klauss | 74:81c47fff88a5 | 56 | while (*src) *dest++ = *src++; |
klauss | 74:81c47fff88a5 | 57 | *dest = 0; |
klauss | 0:4d17cd9c8f9d | 58 | } |
klauss | 0:4d17cd9c8f9d | 59 | |
klauss | 78:1353744f01e1 | 60 | void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size ){ |
klauss | 74:81c47fff88a5 | 61 | while (size--) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 62 | } |
klauss | 0:4d17cd9c8f9d | 63 | |
klauss | 74:81c47fff88a5 | 64 | void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size){ |
klauss | 74:81c47fff88a5 | 65 | size >>= 2; |
klauss | 74:81c47fff88a5 | 66 | while (size--) *dest++ = *src++; |
klauss | 78:1353744f01e1 | 67 | } |
klauss | 78:1353744f01e1 | 68 | |
klauss | 78:1353744f01e1 | 69 | uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2){ |
klauss | 78:1353744f01e1 | 70 | while (*s1) { |
klauss | 78:1353744f01e1 | 71 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 78:1353744f01e1 | 72 | } |
klauss | 78:1353744f01e1 | 73 | if ( *s2 == 0 ) |
klauss | 78:1353744f01e1 | 74 | return 1; /* matches */ |
klauss | 78:1353744f01e1 | 75 | else |
klauss | 78:1353744f01e1 | 76 | return 0; /* does not match */ |
klauss | 81:3656f00ab3db | 77 | } |
klauss | 81:3656f00ab3db | 78 | |
klauss | 81:3656f00ab3db | 79 | uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size){ |
klauss | 81:3656f00ab3db | 80 | while (size--) { |
klauss | 81:3656f00ab3db | 81 | if (*s1++ != *s2++) return 0; /* does not match */ |
klauss | 81:3656f00ab3db | 82 | } |
klauss | 81:3656f00ab3db | 83 | return 1; /* matches */ |
klauss | 74:81c47fff88a5 | 84 | } |