![](/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@119:ee6a53069455, 2015-04-30 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 30 15:42:41 2015 +0000
- Revision:
- 119:ee6a53069455
- Parent:
- 117:e9facba9db27
- Child:
- 121:ee02790d00b7
funcionalidade - clock "ogro" - implementada
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 | 119:ee6a53069455 | 9 | int 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 | 119:ee6a53069455 | 41 | |
klauss | 119:ee6a53069455 | 42 | return ( 0 ); |
klauss | 81:3656f00ab3db | 43 | } |
Cola | 20:2d6ab23956e5 | 44 | |
klauss | 119:ee6a53069455 | 45 | uint8_t * parse_vz_pkg( int * ext, int * port, volatile uint8_t * type, uint8_t * cb_buffer ){ |
klauss | 0:4d17cd9c8f9d | 46 | uint8_t p_lsb, p_msb; |
klauss | 0:4d17cd9c8f9d | 47 | uint8_t e_lsb, e_msb; |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 81:3656f00ab3db | 49 | if( ( ext && port && type && cb_buffer ) == NULL ) return( NULL ); |
klauss | 114:472502b31a12 | 50 | |
klauss | 119:ee6a53069455 | 51 | //tratamento dos pacotes do tipo flood logo na chegada |
klauss | 119:ee6a53069455 | 52 | { |
klauss | 119:ee6a53069455 | 53 | if( cb_buffer[ 6 ] == FLOOD ){ |
klauss | 119:ee6a53069455 | 54 | flood_counter++; |
klauss | 119:ee6a53069455 | 55 | static uint8_t flood_cnt = 0; |
klauss | 119:ee6a53069455 | 56 | static uint8_t first_run_flag = 0; |
klauss | 119:ee6a53069455 | 57 | static Timer t; |
klauss | 119:ee6a53069455 | 58 | if (first_run_flag == 0) { |
klauss | 119:ee6a53069455 | 59 | flood_cnt = cb_buffer[0]; |
klauss | 119:ee6a53069455 | 60 | first_run_flag++; |
klauss | 119:ee6a53069455 | 61 | t.start(); |
klauss | 119:ee6a53069455 | 62 | } else { |
klauss | 119:ee6a53069455 | 63 | if (cb_buffer[0] == 0x00){ |
klauss | 119:ee6a53069455 | 64 | if( debug_uart3 ) pc.printf("%d", t.read_us()); |
klauss | 119:ee6a53069455 | 65 | if( tcp_session && !udp_query ){ |
klauss | 48:195c97f12e8e | 66 | char tmp[ 16 ]; |
klauss | 119:ee6a53069455 | 67 | sprintf( tmp, "%d", t.read_us() ); |
klauss | 48:195c97f12e8e | 68 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 48:195c97f12e8e | 69 | } |
klauss | 48:195c97f12e8e | 70 | } |
klauss | 119:ee6a53069455 | 71 | flood_cnt++; |
klauss | 119:ee6a53069455 | 72 | while (flood_cnt != cb_buffer[0]) { |
klauss | 119:ee6a53069455 | 73 | if( debug_uart3 ) pc.printf("0"); |
klauss | 119:ee6a53069455 | 74 | flood_cnt++; |
klauss | 119:ee6a53069455 | 75 | if( tcp_session && !udp_query ){ |
klauss | 119:ee6a53069455 | 76 | tcp_client.send_all( "0", strlen( "0" ) ); |
klauss | 119:ee6a53069455 | 77 | } |
klauss | 119:ee6a53069455 | 78 | } |
klauss | 119:ee6a53069455 | 79 | int i; |
klauss | 119:ee6a53069455 | 80 | int ok = 1; |
klauss | 119:ee6a53069455 | 81 | uint8_t cmp; |
klauss | 119:ee6a53069455 | 82 | for (i=0, cmp=cb_buffer[0]; (i<300) && (ok==1); i++, cmp++) { |
klauss | 119:ee6a53069455 | 83 | if (i != 6) { |
klauss | 119:ee6a53069455 | 84 | if (cb_buffer[i] != cmp) ok = 0; |
klauss | 119:ee6a53069455 | 85 | } |
klauss | 119:ee6a53069455 | 86 | } |
klauss | 119:ee6a53069455 | 87 | if( ok ){ |
klauss | 119:ee6a53069455 | 88 | if( debug_uart3 ) pc.printf("+"); |
klauss | 119:ee6a53069455 | 89 | if( tcp_session && !udp_query ){ |
klauss | 119:ee6a53069455 | 90 | tcp_client.send_all( "+", strlen( "+" ) ); |
klauss | 119:ee6a53069455 | 91 | } |
klauss | 119:ee6a53069455 | 92 | }else{ |
klauss | 119:ee6a53069455 | 93 | if( debug_uart3 ) pc.printf("%02x",cb_buffer[0] ); |
klauss | 119:ee6a53069455 | 94 | if( debug_uart3 ) pc.printf("#"); |
klauss | 119:ee6a53069455 | 95 | if( debug_uart3 ) pc.printf("\n\r"); |
klauss | 119:ee6a53069455 | 96 | if( tcp_session && !udp_query ){ |
klauss | 119:ee6a53069455 | 97 | char tmp[ 16 ]; |
klauss | 119:ee6a53069455 | 98 | sprintf( tmp, "%02x#\n\r", cb_buffer[ 0 ] ); |
klauss | 119:ee6a53069455 | 99 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 119:ee6a53069455 | 100 | } |
klauss | 119:ee6a53069455 | 101 | for( int i = 0; i < 300 ; i++ ){ |
klauss | 119:ee6a53069455 | 102 | if( debug_uart3 ) pc.printf("%x", cb_buffer[ i ]); |
klauss | 119:ee6a53069455 | 103 | if( tcp_session && !udp_query ){ |
klauss | 119:ee6a53069455 | 104 | char tmp[ 16 ]; |
klauss | 119:ee6a53069455 | 105 | sprintf( tmp, "%x", cb_buffer[ i ] ); |
klauss | 119:ee6a53069455 | 106 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 119:ee6a53069455 | 107 | } |
klauss | 119:ee6a53069455 | 108 | } |
klauss | 119:ee6a53069455 | 109 | } |
Cola | 21:0bd688722e81 | 110 | } |
klauss | 119:ee6a53069455 | 111 | return( NULL ); |
Cola | 21:0bd688722e81 | 112 | } |
klauss | 119:ee6a53069455 | 113 | }//fim tratamento do flood |
Cola | 21:0bd688722e81 | 114 | |
klauss | 0:4d17cd9c8f9d | 115 | uint16_t cc = ( uint16_t )cb_buffer[ 4 ] << 8 | cb_buffer[ 5 ]; |
klauss | 0:4d17cd9c8f9d | 116 | |
klauss | 119:ee6a53069455 | 117 | uint16_t cc_calculated = vz_checksum( cb_buffer, CB_BUFFER_SIZE ); |
klauss | 78:1353744f01e1 | 118 | |
klauss | 78:1353744f01e1 | 119 | if( cc != cc_calculated ){ |
klauss | 78:1353744f01e1 | 120 | if( debug_cks_err ) send_msg( "Received PKG, but -- CKS ERROR: %d ( %d )", cc_calculated, cc ); |
klauss | 78:1353744f01e1 | 121 | |
klauss | 78:1353744f01e1 | 122 | if( cc_calculated == 30975 && cc == 0 ){ |
klauss | 78:1353744f01e1 | 123 | pkg_zero++; |
klauss | 78:1353744f01e1 | 124 | }else{ |
Cola | 20:2d6ab23956e5 | 125 | pkg_ckserr++; |
klauss | 78:1353744f01e1 | 126 | } |
klauss | 78:1353744f01e1 | 127 | return( NULL ); |
klauss | 0:4d17cd9c8f9d | 128 | }else{ |
Cola | 20:2d6ab23956e5 | 129 | pkg_cksok++; |
klauss | 0:4d17cd9c8f9d | 130 | e_msb = cb_buffer[ 0 ]; |
klauss | 0:4d17cd9c8f9d | 131 | e_lsb = cb_buffer[ 1 ]; |
klauss | 0:4d17cd9c8f9d | 132 | *ext = e_msb << 8 | e_lsb; |
klauss | 79:9bc12aa305a9 | 133 | |
klauss | 81:3656f00ab3db | 134 | //restriçao de controle para cbx malucos |
klauss | 81:3656f00ab3db | 135 | if( *ext < begin || *ext > end ){ |
klauss | 81:3656f00ab3db | 136 | if( debug_out_of_range ) send_msg("Trying from %d", *ext ); |
klauss | 79:9bc12aa305a9 | 137 | out_of_range++; |
klauss | 79:9bc12aa305a9 | 138 | return( NULL ); |
klauss | 79:9bc12aa305a9 | 139 | } |
klauss | 81:3656f00ab3db | 140 | |
klauss | 0:4d17cd9c8f9d | 141 | p_msb = cb_buffer[ 2 ]; |
klauss | 0:4d17cd9c8f9d | 142 | p_lsb = cb_buffer[ 3 ]; |
klauss | 0:4d17cd9c8f9d | 143 | *port = p_msb << 8 | p_lsb; |
klauss | 0:4d17cd9c8f9d | 144 | |
klauss | 98:43b45f26b430 | 145 | if( debug_port_match ) if( *ext == *port ) debug_msg("%u:%u", *ext, *port ); |
klauss | 98:43b45f26b430 | 146 | |
klauss | 0:4d17cd9c8f9d | 147 | *type = cb_buffer[ 6 ]; |
klauss | 0:4d17cd9c8f9d | 148 | |
klauss | 119:ee6a53069455 | 149 | if( ( ( *port < BASE_PORT ) || ( *port >= ( BASE_PORT + MAX_CB_IN_A_BRANCH ) ) && ( *type == TELEMETRY ) ) ) return NULL; |
klauss | 119:ee6a53069455 | 150 | |
klauss | 119:ee6a53069455 | 151 | return( cb_buffer + VZ_HEADER_OFFSET ); |
klauss | 0:4d17cd9c8f9d | 152 | } |
klauss | 0:4d17cd9c8f9d | 153 | } |
klauss | 119:ee6a53069455 | 154 | 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 | 119:ee6a53069455 | 155 | //checa se o fuffer de src e dst dos dados estao alocados |
klauss | 119:ee6a53069455 | 156 | if( ( cb_buffer == NULL ) || ( pkg == NULL ) ) return NULL; |
klauss | 119:ee6a53069455 | 157 | |
klauss | 119:ee6a53069455 | 158 | //apaga as posicoes de memoria onde serah montado o pacote |
klauss | 119:ee6a53069455 | 159 | for( register int i = 0; i < CB_BUFFER_SIZE; i++ ) pkg[ i ] = 0; |
klauss | 119:ee6a53069455 | 160 | |
klauss | 119:ee6a53069455 | 161 | //coloca ramal ( MSB ), ramal ( LSB ), porta ( MSB ), porta ( LSB ) e tipo nas posicoes destino |
klauss | 0:4d17cd9c8f9d | 162 | pkg[ 0 ] = ( uint8_t )( ( ext & 0xFF00 ) >> 8 ); |
klauss | 0:4d17cd9c8f9d | 163 | pkg[ 1 ] = ( uint8_t )( ext & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 164 | pkg[ 2 ] = ( uint8_t )( ( port & 0xFF00 ) >> 8 ); |
klauss | 0:4d17cd9c8f9d | 165 | pkg[ 3 ] = ( uint8_t )( port & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 166 | |
klauss | 0:4d17cd9c8f9d | 167 | pkg[ 6 ] = type; |
klauss | 0:4d17cd9c8f9d | 168 | |
klauss | 119:ee6a53069455 | 169 | //preenche os dados de acordo com o tipo do pacote transmitido |
klauss | 119:ee6a53069455 | 170 | size_t fill = VZ_HEADER_OFFSET; |
klauss | 119:ee6a53069455 | 171 | switch( type ) |
klauss | 119:ee6a53069455 | 172 | { |
klauss | 119:ee6a53069455 | 173 | case AUDIO :{ |
klauss | 119:ee6a53069455 | 174 | for( register int i = VZ_HEADER_OFFSET; i < length + VZ_HEADER_OFFSET; i++ ) |
klauss | 119:ee6a53069455 | 175 | pkg[ i ] = ( uint8_t )cb_buffer[ i - VZ_HEADER_OFFSET ]; |
klauss | 119:ee6a53069455 | 176 | |
klauss | 119:ee6a53069455 | 177 | fill = length + VZ_HEADER_OFFSET; |
klauss | 119:ee6a53069455 | 178 | break; |
klauss | 119:ee6a53069455 | 179 | } |
klauss | 119:ee6a53069455 | 180 | case INVITE :{ |
klauss | 119:ee6a53069455 | 181 | pkg[ 7 ] = seq_num; |
klauss | 119:ee6a53069455 | 182 | print_clock( pkg + 8 ); |
klauss | 119:ee6a53069455 | 183 | pkg[ TIMESLICE_PLACE ] = cb_buffer[ TIMESLICE_PLACE ]; |
klauss | 119:ee6a53069455 | 184 | fill = TIMESLICE_PLACE + 1; |
klauss | 119:ee6a53069455 | 185 | break; |
klauss | 119:ee6a53069455 | 186 | } |
klauss | 92:92df17f538a8 | 187 | |
klauss | 119:ee6a53069455 | 188 | case REGISTRY :{ |
klauss | 119:ee6a53069455 | 189 | pkg[ 7 ] = seq_num; |
klauss | 119:ee6a53069455 | 190 | print_clock( pkg + 8 ); |
klauss | 119:ee6a53069455 | 191 | fill = VZ_HEADER_OFFSET + CLOCK_SYNC_SIZE + SEQ_NUM_SIZE; |
klauss | 119:ee6a53069455 | 192 | break; |
klauss | 119:ee6a53069455 | 193 | } |
klauss | 119:ee6a53069455 | 194 | case BOOT :{ |
klauss | 119:ee6a53069455 | 195 | pkg[ 7 ] = seq_num; |
klauss | 119:ee6a53069455 | 196 | print_clock( pkg + 8 ); |
klauss | 119:ee6a53069455 | 197 | fill = VZ_HEADER_OFFSET + CLOCK_SYNC_SIZE + SEQ_NUM_SIZE; |
klauss | 119:ee6a53069455 | 198 | break; |
klauss | 119:ee6a53069455 | 199 | } |
klauss | 119:ee6a53069455 | 200 | case CB_BYE :{ |
klauss | 119:ee6a53069455 | 201 | pkg[ 7 ] = seq_num; |
klauss | 119:ee6a53069455 | 202 | print_clock( pkg + 8 ); |
klauss | 119:ee6a53069455 | 203 | pkg[ TIMESLICE_PLACE ] = cb_buffer[ TIMESLICE_PLACE ]; |
klauss | 119:ee6a53069455 | 204 | fill = TIMESLICE_PLACE + 1; |
klauss | 119:ee6a53069455 | 205 | break; |
klauss | 119:ee6a53069455 | 206 | } |
klauss | 119:ee6a53069455 | 207 | case PROMPT :{ |
klauss | 119:ee6a53069455 | 208 | strcpy( ( char * )( pkg + VZ_HEADER_OFFSET ), cb_buffer ); |
klauss | 119:ee6a53069455 | 209 | fill = strlen( cb_buffer ) + VZ_HEADER_OFFSET; |
klauss | 119:ee6a53069455 | 210 | break; |
klauss | 119:ee6a53069455 | 211 | } |
klauss | 119:ee6a53069455 | 212 | case TELEMETRY :{ |
klauss | 119:ee6a53069455 | 213 | pkg[ 7 ] = seq_num; |
klauss | 119:ee6a53069455 | 214 | print_clock( pkg + 8 ); |
klauss | 119:ee6a53069455 | 215 | //FIXME a header manda pacotes de tele pro cbx ? |
klauss | 119:ee6a53069455 | 216 | pkg[ TIMESLICE_PLACE ] = cb_buffer[ TIMESLICE_PLACE ]; |
klauss | 119:ee6a53069455 | 217 | fill = TIMESLICE_PLACE + 1; |
klauss | 119:ee6a53069455 | 218 | break; |
klauss | 119:ee6a53069455 | 219 | } |
klauss | 119:ee6a53069455 | 220 | case BOOTLOADER_CBX :{ |
klauss | 119:ee6a53069455 | 221 | xmemcpy((pkg + 7),(uint8_t *)cb_buffer,length); |
klauss | 119:ee6a53069455 | 222 | fill = VZ_HEADER_OFFSET + length; |
klauss | 119:ee6a53069455 | 223 | break; |
klauss | 119:ee6a53069455 | 224 | } |
klauss | 119:ee6a53069455 | 225 | }//fim switch |
klauss | 0:4d17cd9c8f9d | 226 | |
klauss | 119:ee6a53069455 | 227 | //preenche o final do pacote com 0 |
klauss | 119:ee6a53069455 | 228 | for( register uint16_t i = fill; i < CB_BUFFER_SIZE; i++ ) pkg[ i ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 229 | |
klauss | 119:ee6a53069455 | 230 | //colocando o terminador de pacotes estabelecido pelo protocolo |
klauss | 119:ee6a53069455 | 231 | pkg[ CB_BUFFER_SIZE - 4 ] = 0x5a; |
klauss | 119:ee6a53069455 | 232 | pkg[ CB_BUFFER_SIZE - 3 ] = 0x56; |
klauss | 119:ee6a53069455 | 233 | pkg[ CB_BUFFER_SIZE - 2 ] = 0x5a; |
klauss | 119:ee6a53069455 | 234 | pkg[ CB_BUFFER_SIZE - 1 ] = 0xe1; |
klauss | 100:09a23fcd3bdf | 235 | |
klauss | 119:ee6a53069455 | 236 | //calcula e preenche o checksum |
klauss | 119:ee6a53069455 | 237 | uint16_t cc = vz_checksum( pkg, CB_BUFFER_SIZE ); |
klauss | 0:4d17cd9c8f9d | 238 | pkg[ 4 ] =( uint8_t )( ( cc & 0xFF00 ) >> 8) ; |
klauss | 0:4d17cd9c8f9d | 239 | pkg[ 5 ] =( uint8_t )( cc & 0x00FF ); |
klauss | 0:4d17cd9c8f9d | 240 | |
klauss | 119:ee6a53069455 | 241 | //enable/disable de exibicao de pacotes prontos para envio |
klauss | 119:ee6a53069455 | 242 | if( debug_show_cpld ) { |
klauss | 119:ee6a53069455 | 243 | char str[ 1024 ]; |
klauss | 119:ee6a53069455 | 244 | strcpy( str, "TX :: \n\r " ); |
klauss | 119:ee6a53069455 | 245 | for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { |
klauss | 119:ee6a53069455 | 246 | char tmp[ 16 ]; |
klauss | 119:ee6a53069455 | 247 | strcat( str, itoa( pkg[ i ], tmp, 16 ) ); |
klauss | 119:ee6a53069455 | 248 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 119:ee6a53069455 | 249 | |
klauss | 119:ee6a53069455 | 250 | else strcat( str, " " ); |
klauss | 119:ee6a53069455 | 251 | } |
klauss | 119:ee6a53069455 | 252 | send_msg( "%s", str ); |
klauss | 119:ee6a53069455 | 253 | } |
klauss | 119:ee6a53069455 | 254 | |
klauss | 119:ee6a53069455 | 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 | 119:ee6a53069455 | 259 | uint16_t vz_checksum ( uint8_t * buffer, size_t length ) |
klauss | 119:ee6a53069455 | 260 | { |
klauss | 70:714c33487aae | 261 | if( !buffer ) return( 0 ); |
klauss | 0:4d17cd9c8f9d | 262 | uint16_t cc = 0x00; |
klauss | 0:4d17cd9c8f9d | 263 | buffer[ 4 ] = buffer[ 5 ] = 0x5a; |
klauss | 0:4d17cd9c8f9d | 264 | for( register int i = 0; i < length; i++ ){ |
klauss | 0:4d17cd9c8f9d | 265 | cc += buffer[ i ]; |
klauss | 0:4d17cd9c8f9d | 266 | if( cc & BIT15 ){ |
klauss | 0:4d17cd9c8f9d | 267 | cc <<= 1; |
klauss | 0:4d17cd9c8f9d | 268 | cc |= BIT0; |
klauss | 0:4d17cd9c8f9d | 269 | }else{ cc <<= BIT0; } |
klauss | 0:4d17cd9c8f9d | 270 | } |
klauss | 0:4d17cd9c8f9d | 271 | cc ^= 0xffff; |
klauss | 0:4d17cd9c8f9d | 272 | return cc; |
klauss | 0:4d17cd9c8f9d | 273 | } |