![](/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
vz_protocol.cpp@105:a930035b6556, 2015-03-10 (annotated)
- Committer:
- klauss
- Date:
- Tue Mar 10 18:10:57 2015 +0000
- Revision:
- 105:a930035b6556
- Parent:
- 102:98c7155e8bea
- Child:
- 109:a5b8264ffbbc
sprint 0;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "vz_protocol.h" |
klauss | 72:895ca792c647 | 2 | |
klauss | 78:1353744f01e1 | 3 | uint32_t pkg_ckserr = 0; |
klauss | 78:1353744f01e1 | 4 | uint32_t pkg_zero = 0; |
klauss | 78:1353744f01e1 | 5 | uint32_t pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 6 | int begin = 0; |
klauss | 81:3656f00ab3db | 7 | int end = 0; |
klauss | 81:3656f00ab3db | 8 | |
klauss | 81:3656f00ab3db | 9 | void init_ranges( void ){ |
klauss | 81:3656f00ab3db | 10 | FILE * begin_ext = fopen( "/qspi/minext.txt", "r" ); |
klauss | 81:3656f00ab3db | 11 | if( begin_ext == NULL ){ |
klauss | 81:3656f00ab3db | 12 | if( debug_out_of_range ) debug_msg("Failed to open /qspi/minext.txt" ); |
klauss | 81:3656f00ab3db | 13 | begin = MIN_EXT; |
klauss | 81:3656f00ab3db | 14 | }else{ |
klauss | 81:3656f00ab3db | 15 | char inner_tmp[ 20 ]; |
klauss | 81:3656f00ab3db | 16 | if( fread( (void *)inner_tmp, 1, 20, begin_ext ) > 0 ){ |
klauss | 81:3656f00ab3db | 17 | begin = atoi( inner_tmp ); |
klauss | 81:3656f00ab3db | 18 | if( debug_out_of_range ) debug_msg("Ext Min %d", begin ); |
klauss | 81:3656f00ab3db | 19 | }else{ |
klauss | 81:3656f00ab3db | 20 | if( debug_out_of_range ) debug_msg("Failed to read /qspi/minext.txt" ); |
klauss | 81:3656f00ab3db | 21 | begin = MIN_EXT; |
klauss | 81:3656f00ab3db | 22 | } |
klauss | 81:3656f00ab3db | 23 | } |
klauss | 81:3656f00ab3db | 24 | fclose( begin_ext ); |
klauss | 81:3656f00ab3db | 25 | |
klauss | 81:3656f00ab3db | 26 | FILE * end_ext = fopen( "/qspi/maxext.txt", "r" ); |
klauss | 81:3656f00ab3db | 27 | if( end_ext == NULL ){ |
klauss | 81:3656f00ab3db | 28 | if( debug_out_of_range ) debug_msg("Failed to open /qspi/maxext.txt" ); |
klauss | 81:3656f00ab3db | 29 | end = MAX_EXT; |
klauss | 81:3656f00ab3db | 30 | }else{ |
klauss | 81:3656f00ab3db | 31 | char inner_tmp[ 20 ]; |
klauss | 81:3656f00ab3db | 32 | if( fread( (void *)inner_tmp, 1, 20, end_ext ) > 0 ){ |
klauss | 81:3656f00ab3db | 33 | end = atoi( inner_tmp ); |
klauss | 81:3656f00ab3db | 34 | if( debug_out_of_range ) debug_msg("Ext Min %d", end ); |
klauss | 81:3656f00ab3db | 35 | }else{ |
klauss | 81:3656f00ab3db | 36 | if( debug_out_of_range ) debug_msg("Failed to read /qspi/maxext.txt" ); |
klauss | 81:3656f00ab3db | 37 | begin = MAX_EXT; |
klauss | 81:3656f00ab3db | 38 | } |
klauss | 81:3656f00ab3db | 39 | } |
klauss | 89:0fe315117b00 | 40 | fclose( end_ext ); |
klauss | 81:3656f00ab3db | 41 | } |
Cola | 20:2d6ab23956e5 | 42 | |
klauss | 105:a930035b6556 | 43 | uint8_t * parse_vz_pkg( int * ext, int * port, volatile uint8_t * type, uint8_t * cb_buffer ){ |
klauss | 0:4d17cd9c8f9d | 44 | uint8_t p_lsb, p_msb; |
klauss | 0:4d17cd9c8f9d | 45 | uint8_t e_lsb, e_msb; |
klauss | 0:4d17cd9c8f9d | 46 | |
klauss | 81:3656f00ab3db | 47 | if( ( ext && port && type && cb_buffer ) == NULL ) return( NULL ); |
klauss | 105:a930035b6556 | 48 | |
klauss | 105:a930035b6556 | 49 | //tratamento dos pacotes do tipo flood logo na chegada |
klauss | 105:a930035b6556 | 50 | { |
klauss | 105:a930035b6556 | 51 | if( cb_buffer[ 6 ] == __FLOOD__ ){ |
klauss | 105:a930035b6556 | 52 | flood_counter++; |
klauss | 105:a930035b6556 | 53 | static uint8_t flood_cnt = 0; |
klauss | 105:a930035b6556 | 54 | static uint8_t first_run_flag = 0; |
klauss | 105:a930035b6556 | 55 | static Timer t; |
klauss | 105:a930035b6556 | 56 | if (first_run_flag == 0) { |
klauss | 105:a930035b6556 | 57 | flood_cnt = cb_buffer[0]; |
klauss | 105:a930035b6556 | 58 | first_run_flag++; |
klauss | 105:a930035b6556 | 59 | t.start(); |
klauss | 105:a930035b6556 | 60 | } else { |
klauss | 105:a930035b6556 | 61 | if (cb_buffer[0] == 0x00){ |
klauss | 105:a930035b6556 | 62 | if( debug_uart3 ) pc.printf("%d", t.read_us()); |
klauss | 105:a930035b6556 | 63 | if( tcp_session && !udp_query ){ |
klauss | 48:195c97f12e8e | 64 | char tmp[ 16 ]; |
klauss | 105:a930035b6556 | 65 | sprintf( tmp, "%d", t.read_us() ); |
klauss | 48:195c97f12e8e | 66 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 48:195c97f12e8e | 67 | } |
klauss | 48:195c97f12e8e | 68 | } |
klauss | 105:a930035b6556 | 69 | flood_cnt++; |
klauss | 105:a930035b6556 | 70 | while (flood_cnt != cb_buffer[0]) { |
klauss | 105:a930035b6556 | 71 | if( debug_uart3 ) pc.printf("0"); |
klauss | 105:a930035b6556 | 72 | flood_cnt++; |
klauss | 105:a930035b6556 | 73 | if( tcp_session && !udp_query ){ |
klauss | 105:a930035b6556 | 74 | tcp_client.send_all( "0", strlen( "0" ) ); |
klauss | 105:a930035b6556 | 75 | } |
klauss | 105:a930035b6556 | 76 | } |
klauss | 105:a930035b6556 | 77 | int i; |
klauss | 105:a930035b6556 | 78 | int ok = 1; |
klauss | 105:a930035b6556 | 79 | uint8_t cmp; |
klauss | 105:a930035b6556 | 80 | for (i=0, cmp=cb_buffer[0]; (i<300) && (ok==1); i++, cmp++) { |
klauss | 105:a930035b6556 | 81 | if (i != 6) { |
klauss | 105:a930035b6556 | 82 | if (cb_buffer[i] != cmp) ok = 0; |
klauss | 105:a930035b6556 | 83 | } |
klauss | 105:a930035b6556 | 84 | } |
klauss | 105:a930035b6556 | 85 | if( ok ){ |
klauss | 105:a930035b6556 | 86 | if( debug_uart3 ) pc.printf("+"); |
klauss | 105:a930035b6556 | 87 | if( tcp_session && !udp_query ){ |
klauss | 105:a930035b6556 | 88 | tcp_client.send_all( "+", strlen( "+" ) ); |
klauss | 105:a930035b6556 | 89 | } |
klauss | 105:a930035b6556 | 90 | }else{ |
klauss | 105:a930035b6556 | 91 | if( debug_uart3 ) pc.printf("%02x",cb_buffer[0] ); |
klauss | 105:a930035b6556 | 92 | if( debug_uart3 ) pc.printf("#"); |
klauss | 105:a930035b6556 | 93 | if( debug_uart3 ) pc.printf("\n\r"); |
klauss | 105:a930035b6556 | 94 | if( tcp_session && !udp_query ){ |
klauss | 105:a930035b6556 | 95 | char tmp[ 16 ]; |
klauss | 105:a930035b6556 | 96 | sprintf( tmp, "%02x#\n\r", cb_buffer[ 0 ] ); |
klauss | 105:a930035b6556 | 97 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 105:a930035b6556 | 98 | } |
klauss | 105:a930035b6556 | 99 | for( int i = 0; i < 300 ; i++ ){ |
klauss | 105:a930035b6556 | 100 | if( debug_uart3 ) pc.printf("%x", cb_buffer[ i ]); |
klauss | 105:a930035b6556 | 101 | if( tcp_session && !udp_query ){ |
klauss | 105:a930035b6556 | 102 | char tmp[ 16 ]; |
klauss | 105:a930035b6556 | 103 | sprintf( tmp, "%x", cb_buffer[ i ] ); |
klauss | 105:a930035b6556 | 104 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 105:a930035b6556 | 105 | } |
klauss | 105:a930035b6556 | 106 | } |
klauss | 105:a930035b6556 | 107 | } |
Cola | 21:0bd688722e81 | 108 | } |
klauss | 105:a930035b6556 | 109 | return( NULL ); |
Cola | 21:0bd688722e81 | 110 | } |
klauss | 105:a930035b6556 | 111 | }//fim tratamento do flood |
Cola | 21:0bd688722e81 | 112 | |
klauss | 0:4d17cd9c8f9d | 113 | uint16_t cc = ( uint16_t )cb_buffer[ 4 ] << 8 | cb_buffer[ 5 ]; |
klauss | 0:4d17cd9c8f9d | 114 | |
klauss | 105:a930035b6556 | 115 | uint16_t cc_calculated = __checksum__( cb_buffer, CB_BUFFER_SIZE ); |
klauss | 78:1353744f01e1 | 116 | |
klauss | 78:1353744f01e1 | 117 | if( cc != cc_calculated ){ |
klauss | 78:1353744f01e1 | 118 | if( debug_cks_err ) send_msg( "Received PKG, but -- CKS ERROR: %d ( %d )", cc_calculated, cc ); |
klauss | 78:1353744f01e1 | 119 | |
klauss | 78:1353744f01e1 | 120 | if( cc_calculated == 30975 && cc == 0 ){ |
klauss | 78:1353744f01e1 | 121 | pkg_zero++; |
klauss | 78:1353744f01e1 | 122 | }else{ |
Cola | 20:2d6ab23956e5 | 123 | pkg_ckserr++; |
klauss | 78:1353744f01e1 | 124 | } |
klauss | 78:1353744f01e1 | 125 | return( NULL ); |
klauss | 0:4d17cd9c8f9d | 126 | }else{ |
Cola | 20:2d6ab23956e5 | 127 | pkg_cksok++; |
klauss | 0:4d17cd9c8f9d | 128 | e_msb = cb_buffer[ 0 ]; |
klauss | 0:4d17cd9c8f9d | 129 | e_lsb = cb_buffer[ 1 ]; |
klauss | 0:4d17cd9c8f9d | 130 | *ext = e_msb << 8 | e_lsb; |
klauss | 79:9bc12aa305a9 | 131 | |
klauss | 81:3656f00ab3db | 132 | //restriçao de controle para cbx malucos |
klauss | 81:3656f00ab3db | 133 | if( *ext < begin || *ext > end ){ |
klauss | 81:3656f00ab3db | 134 | if( debug_out_of_range ) send_msg("Trying from %d", *ext ); |
klauss | 79:9bc12aa305a9 | 135 | out_of_range++; |
klauss | 79:9bc12aa305a9 | 136 | return( NULL ); |
klauss | 79:9bc12aa305a9 | 137 | } |
klauss | 81:3656f00ab3db | 138 | |
klauss | 0:4d17cd9c8f9d | 139 | p_msb = cb_buffer[ 2 ]; |
klauss | 0:4d17cd9c8f9d | 140 | p_lsb = cb_buffer[ 3 ]; |
klauss | 0:4d17cd9c8f9d | 141 | *port = p_msb << 8 | p_lsb; |
klauss | 0:4d17cd9c8f9d | 142 | |
klauss | 98:43b45f26b430 | 143 | if( debug_port_match ) if( *ext == *port ) debug_msg("%u:%u", *ext, *port ); |
klauss | 98:43b45f26b430 | 144 | |
klauss | 0:4d17cd9c8f9d | 145 | *type = cb_buffer[ 6 ]; |
klauss | 98:43b45f26b430 | 146 | |
klauss | 98:43b45f26b430 | 147 | if( ( ( *port < 5000 ) || ( *port >= ( 5000 + __MAX_CB_IN_A_BRANCH__ ) ) && ( *type == __TELEMETRY__ ) ) ) return NULL; |
klauss | 0:4d17cd9c8f9d | 148 | |
klauss | 0:4d17cd9c8f9d | 149 | return( cb_buffer + __VZ_HEADER_OFFSET__ ); |
klauss | 0:4d17cd9c8f9d | 150 | } |
klauss | 0:4d17cd9c8f9d | 151 | } |
klauss | 105:a930035b6556 | 152 | uint8_t * build_cb_package( int ext, int port, uint8_t type, char * cb_buffer, uint8_t seq_num, int length, uint8_t * pkg ){ |
klauss | 105:a930035b6556 | 153 | //checa se o fuffer de src e dst dos dados estao alocados |
klauss | 105:a930035b6556 | 154 | if( ( cb_buffer == NULL ) || ( pkg == NULL ) ) return NULL; |
klauss | 105:a930035b6556 | 155 | |
klauss | 105:a930035b6556 | 156 | //apaga as posicoes de memoria onde serah montado o pacote |
klauss | 105:a930035b6556 | 157 | for( register int i = 0; i < CB_BUFFER_SIZE; i++ ) pkg[ i ] = 0; |
klauss | 105:a930035b6556 | 158 | |
klauss | 105:a930035b6556 | 159 | //coloca ramal ( MSB ), ramal ( LSB ), porta ( MSB ), porta ( LSB ) e tipo nas posicoes destino |
klauss | 0:4d17cd9c8f9d | 160 | pkg[ 0 ] = ( uint8_t )( ( ext & 0xFF00 ) >> 8 ); |
klauss | 0:4d17cd9c8f9d | 161 | pkg[ 1 ] = ( uint8_t )( ext & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 162 | pkg[ 2 ] = ( uint8_t )( ( port & 0xFF00 ) >> 8 ); |
klauss | 0:4d17cd9c8f9d | 163 | pkg[ 3 ] = ( uint8_t )( port & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 164 | |
klauss | 0:4d17cd9c8f9d | 165 | pkg[ 6 ] = type; |
klauss | 0:4d17cd9c8f9d | 166 | |
klauss | 105:a930035b6556 | 167 | //preenche os dados de acordo com o tipo do pacote transmitido |
klauss | 105:a930035b6556 | 168 | size_t fill = __VZ_HEADER_OFFSET__; |
klauss | 105:a930035b6556 | 169 | switch( type ) |
klauss | 105:a930035b6556 | 170 | { |
klauss | 105:a930035b6556 | 171 | case __AUDIO__ :{ |
klauss | 105:a930035b6556 | 172 | for( register int i = __VZ_HEADER_OFFSET__; i < length + __VZ_HEADER_OFFSET__; i++ ) |
klauss | 105:a930035b6556 | 173 | pkg[ i ] = ( uint8_t )cb_buffer[ i - __VZ_HEADER_OFFSET__ ]; |
klauss | 105:a930035b6556 | 174 | |
klauss | 105:a930035b6556 | 175 | fill = length + __VZ_HEADER_OFFSET__; |
klauss | 105:a930035b6556 | 176 | break; |
klauss | 105:a930035b6556 | 177 | } |
klauss | 105:a930035b6556 | 178 | case __INVITE__ :{ |
klauss | 105:a930035b6556 | 179 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 180 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 181 | pkg[ __TIMESLICE_PLACE__ ] = cb_buffer[ __TIMESLICE_PLACE__ ]; |
klauss | 105:a930035b6556 | 182 | fill = __TIMESLICE_PLACE__ + 1; |
klauss | 105:a930035b6556 | 183 | break; |
klauss | 105:a930035b6556 | 184 | } |
klauss | 92:92df17f538a8 | 185 | |
klauss | 105:a930035b6556 | 186 | case __REGISTRY__ :{ |
klauss | 105:a930035b6556 | 187 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 188 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 189 | fill = __VZ_HEADER_OFFSET__ + __CLOCK_SYNC_SIZE__ + __SEQ_NUM_SIZE__; |
klauss | 105:a930035b6556 | 190 | break; |
klauss | 105:a930035b6556 | 191 | } |
klauss | 105:a930035b6556 | 192 | case __BOOT__ :{ |
klauss | 105:a930035b6556 | 193 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 194 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 195 | fill = __VZ_HEADER_OFFSET__ + __CLOCK_SYNC_SIZE__ + __SEQ_NUM_SIZE__; |
klauss | 105:a930035b6556 | 196 | break; |
klauss | 105:a930035b6556 | 197 | } |
klauss | 105:a930035b6556 | 198 | case __CB_BYE__ :{ |
klauss | 105:a930035b6556 | 199 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 200 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 201 | pkg[ __TIMESLICE_PLACE__ ] = cb_buffer[ __TIMESLICE_PLACE__ ]; |
klauss | 105:a930035b6556 | 202 | fill = __TIMESLICE_PLACE__ + 1; |
klauss | 105:a930035b6556 | 203 | break; |
klauss | 105:a930035b6556 | 204 | } |
klauss | 105:a930035b6556 | 205 | case __PROMPT__ :{ |
klauss | 105:a930035b6556 | 206 | strcpy( ( char * )( pkg + __VZ_HEADER_OFFSET__ ), cb_buffer ); |
klauss | 105:a930035b6556 | 207 | fill = strlen( cb_buffer ) + __VZ_HEADER_OFFSET__; |
klauss | 105:a930035b6556 | 208 | break; |
klauss | 105:a930035b6556 | 209 | } |
klauss | 105:a930035b6556 | 210 | case __TELEMETRY__ :{ |
klauss | 105:a930035b6556 | 211 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 212 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 213 | //FIXME a header manda pacotes de tele pro cbx ? |
klauss | 105:a930035b6556 | 214 | pkg[ __TIMESLICE_PLACE__ ] = cb_buffer[ __TIMESLICE_PLACE__ ]; |
klauss | 105:a930035b6556 | 215 | fill = __TIMESLICE_PLACE__ + 1; |
klauss | 105:a930035b6556 | 216 | break; |
klauss | 105:a930035b6556 | 217 | } |
klauss | 105:a930035b6556 | 218 | case __BOOTLOADER_CBX__ :{ |
klauss | 105:a930035b6556 | 219 | pkg[ 7 ] = seq_num; |
klauss | 105:a930035b6556 | 220 | __print_clock__( pkg + 8 ); |
klauss | 105:a930035b6556 | 221 | fill = __VZ_HEADER_OFFSET__ + __CLOCK_SYNC_SIZE__ + __SEQ_NUM_SIZE__; |
klauss | 105:a930035b6556 | 222 | break; |
klauss | 105:a930035b6556 | 223 | } |
klauss | 105:a930035b6556 | 224 | }//fim switch |
klauss | 0:4d17cd9c8f9d | 225 | |
klauss | 105:a930035b6556 | 226 | //preenche o final do pacote com 0 |
klauss | 105:a930035b6556 | 227 | for( register uint16_t i = fill; i < CB_BUFFER_SIZE; i++ ) pkg[ i ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 228 | |
klauss | 105:a930035b6556 | 229 | //colocando o terminador de pacotes estabelecido pelo protocolo |
klauss | 105:a930035b6556 | 230 | pkg[ CB_BUFFER_SIZE - 4 ] = 0x5a; |
klauss | 105:a930035b6556 | 231 | pkg[ CB_BUFFER_SIZE - 3 ] = 0x56; |
klauss | 105:a930035b6556 | 232 | pkg[ CB_BUFFER_SIZE - 2 ] = 0x5a; |
klauss | 105:a930035b6556 | 233 | pkg[ CB_BUFFER_SIZE - 1 ] = 0xe1; |
klauss | 100:09a23fcd3bdf | 234 | |
klauss | 105:a930035b6556 | 235 | //calcula e preenche o checksum |
klauss | 105:a930035b6556 | 236 | uint16_t cc = __checksum__( pkg, CB_BUFFER_SIZE ); |
klauss | 0:4d17cd9c8f9d | 237 | pkg[ 4 ] =( uint8_t )( ( cc & 0xFF00 ) >> 8) ; |
klauss | 0:4d17cd9c8f9d | 238 | pkg[ 5 ] =( uint8_t )( cc & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 239 | |
klauss | 105:a930035b6556 | 240 | //enable/disable de exibicao de pacotes prontos para envio |
klauss | 105:a930035b6556 | 241 | if( debug_show_cpld ) { |
klauss | 105:a930035b6556 | 242 | char str[ 1024 ]; |
klauss | 105:a930035b6556 | 243 | strcpy( str, "TX :: \n\r " ); |
klauss | 105:a930035b6556 | 244 | for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { |
klauss | 105:a930035b6556 | 245 | char tmp[ 16 ]; |
klauss | 105:a930035b6556 | 246 | strcat( str, itoa( pkg[ i ], tmp, 16 ) ); |
klauss | 105:a930035b6556 | 247 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 105:a930035b6556 | 248 | |
klauss | 105:a930035b6556 | 249 | else strcat( str, " " ); |
klauss | 105:a930035b6556 | 250 | } |
klauss | 105:a930035b6556 | 251 | send_msg( "%s", str ); |
klauss | 105:a930035b6556 | 252 | //rx = false; |
klauss | 105:a930035b6556 | 253 | } |
klauss | 105:a930035b6556 | 254 | |
klauss | 105:a930035b6556 | 255 | //retorna o ultimo paramentro recebido com o pacote montado. |
klauss | 0:4d17cd9c8f9d | 256 | return pkg; |
klauss | 0:4d17cd9c8f9d | 257 | } |
klauss | 0:4d17cd9c8f9d | 258 | |
klauss | 0:4d17cd9c8f9d | 259 | uint16_t __checksum__( uint8_t * buffer, size_t length ){ |
klauss | 70:714c33487aae | 260 | if( !buffer ) return( 0 ); |
klauss | 0:4d17cd9c8f9d | 261 | uint16_t cc = 0x00; |
klauss | 0:4d17cd9c8f9d | 262 | buffer[ 4 ] = buffer[ 5 ] = 0x5a; |
klauss | 0:4d17cd9c8f9d | 263 | for( register int i = 0; i < length; i++ ){ |
klauss | 0:4d17cd9c8f9d | 264 | cc += buffer[ i ]; |
klauss | 0:4d17cd9c8f9d | 265 | if( cc & BIT15 ){ |
klauss | 0:4d17cd9c8f9d | 266 | cc <<= 1; |
klauss | 0:4d17cd9c8f9d | 267 | cc |= BIT0; |
klauss | 0:4d17cd9c8f9d | 268 | }else{ cc <<= BIT0; } |
klauss | 0:4d17cd9c8f9d | 269 | } |
klauss | 0:4d17cd9c8f9d | 270 | cc ^= 0xffff; |
klauss | 0:4d17cd9c8f9d | 271 | return cc; |
klauss | 0:4d17cd9c8f9d | 272 | } |
klauss | 0:4d17cd9c8f9d | 273 | |
klauss | 102:98c7155e8bea | 274 | void __print_clock__( uint8_t * buffer ){ |
klauss | 102:98c7155e8bea | 275 | //if( !buffer ) return; |
klauss | 102:98c7155e8bea | 276 | |
klauss | 102:98c7155e8bea | 277 | //int ntp_result = ntp.setTime( "200.192.232.8", 123, 3 ); |
klauss | 102:98c7155e8bea | 278 | //led2 = !led2; |
klauss | 102:98c7155e8bea | 279 | //struct tm ts; |
klauss | 102:98c7155e8bea | 280 | //int ntp_result = ntp.setTime( "200.192.232.8" ); |
klauss | 102:98c7155e8bea | 281 | //int ntp_result = ntp.setTime( "200.192.232.8", 123, 3 ); |
klauss | 102:98c7155e8bea | 282 | //if( ntp_result == 0 ){ |
klauss | 102:98c7155e8bea | 283 | // time_t seconds; |
klauss | 102:98c7155e8bea | 284 | // seconds = time(NULL); |
klauss | 102:98c7155e8bea | 285 | // time( &seconds ); |
klauss | 102:98c7155e8bea | 286 | // ts = *localtime( &seconds ); |
klauss | 102:98c7155e8bea | 287 | //} |
klauss | 102:98c7155e8bea | 288 | |
klauss | 102:98c7155e8bea | 289 | //int ano = ts.tm_year + 1900; |
klauss | 102:98c7155e8bea | 290 | //int mes = ts.tm_mon + 1; |
klauss | 102:98c7155e8bea | 291 | //int dia = ts.tm_mday; |
klauss | 102:98c7155e8bea | 292 | //int hora = ts.tm_hour - 3; |
klauss | 102:98c7155e8bea | 293 | //int min = ts.tm_min; |
klauss | 102:98c7155e8bea | 294 | //int sec = ts.tm_sec; |
klauss | 0:4d17cd9c8f9d | 295 | |
klauss | 102:98c7155e8bea | 296 | //buffer[ 0 ] = ano / 1000; |
klauss | 102:98c7155e8bea | 297 | //ano -= buffer[ 0 ] * 1000; |
klauss | 102:98c7155e8bea | 298 | //buffer[ 1 ] = ano / 100; |
klauss | 102:98c7155e8bea | 299 | //ano -= buffer[ 1 ]* 100; |
klauss | 102:98c7155e8bea | 300 | //buffer[ 2 ] = ano / 10; |
klauss | 102:98c7155e8bea | 301 | //ano -= buffer[ 2 ] * 10; |
klauss | 102:98c7155e8bea | 302 | //buffer[ 3 ] = ano; |
klauss | 102:98c7155e8bea | 303 | //buffer[ 4 ] = mes / 10; |
klauss | 102:98c7155e8bea | 304 | //buffer[ 5 ] = mes % 10; |
klauss | 102:98c7155e8bea | 305 | //buffer[ 6 ] = dia / 10; |
klauss | 102:98c7155e8bea | 306 | //buffer[ 7 ] = dia % 10; |
klauss | 102:98c7155e8bea | 307 | //buffer[ 8 ] = hora / 10; |
klauss | 102:98c7155e8bea | 308 | //buffer[ 9 ] = hora % 10; |
klauss | 102:98c7155e8bea | 309 | //buffer[ 10 ] = min / 10; |
klauss | 102:98c7155e8bea | 310 | //buffer[ 11 ] = min % 10; |
klauss | 102:98c7155e8bea | 311 | //buffer[ 12 ] = sec / 10; |
klauss | 102:98c7155e8bea | 312 | //buffer[ 13 ] = sec % 10; |
klauss | 102:98c7155e8bea | 313 | |
klauss | 102:98c7155e8bea | 314 | /* convertendo pro ascii do nro */ |
klauss | 102:98c7155e8bea | 315 | for( register int i = 0; i < 14; i++ ) buffer[ i ] = 0xab; |
klauss | 102:98c7155e8bea | 316 | //led4 = !led4; |
klauss | 0:4d17cd9c8f9d | 317 | } |