![](/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
Diff: main.cpp
- Revision:
- 118:b93b17c50910
- Parent:
- 117:e9facba9db27
- Child:
- 119:ee6a53069455
diff -r e9facba9db27 -r b93b17c50910 main.cpp --- a/main.cpp Thu Apr 23 21:53:28 2015 +0000 +++ b/main.cpp Fri Apr 24 13:54:24 2015 +0000 @@ -735,6 +735,127 @@ int rcv = cb->sip_udp_incomming_pkg(); } } + + /* Tratamento dos pacotes de bootloader vindo do servidor */ + if( FD_ISSET( udp_bl_client.get_fd(), &fdSet ) ) { + if( udp_bl_client.receiveFrom( udp_bl_server, bl_recv_buffer, sizeof( bl_recv_buffer ) ) > 0 ) { + uint16_t cnt = 0; + if (debug_bootloader) { + pc.printf("\r\nPACOTE SRV->HDR {"); + for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { + if ((cnt % 30) == 0) { + pc.printf("\r\n "); + pc.printf(hex16(cnt)); + pc.printf(" : "); + } + pc.printf(hex8(bl_recv_buffer[cnt])); + pc.printf(", "); + } + pc.printf("\r\n}"); + } + bl_peer = ((uint8_t)bl_recv_buffer[0])*256 + (uint8_t)bl_recv_buffer[1]; + bl_send_buffer[0] = bl_recv_buffer[0]; + bl_send_buffer[1] = bl_recv_buffer[1]; + for (cnt = 2;cnt < UDP_BL_SIZE;cnt++) { + bl_send_buffer[cnt] = 0; + } + + if ((bl_ts == 0) and !(bl_start_flag)) { + bl_ts = ts->get_timeslice(); + } + + /* caso nao haja timeslice disponivel informar servidor */ + if ((bl_ts == 0) and !(bl_start_flag)) { + strncpy(bl_send_buffer + 2,"cbxdead\x00",8); + udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) ); + } else { + + /* pacote para verificar se o callbox esta disponivel */ + if (!(strncmp(bl_recv_buffer + 2,"avaiable?",9))) { + bl_start_flag = 1; + udp_bl_timer.start(); + udp_bl_timer.reset(); + strncpy(bl_send_buffer + 2,"cbxalive\x00",9); + if (debug_bootloader) { + pc.printf("\r\nPACOTE HDR->SRV {"); + for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { + if ((cnt % 30) == 0) { + pc.printf("\r\n "); + pc.printf(hex16(cnt)); + pc.printf(" : "); + } + pc.printf(hex8(bl_send_buffer[cnt])); + pc.printf(", "); + } + pc.printf("\r\n}"); + } + udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) ); + } + + /* pacote para indicar o termino do processo de atualizacao */ + else if (!(strncmp(bl_recv_buffer + 2,"finished",8))) { + bl_start_flag = 0; + if (bl_ts != 0) { + ts->return_timeslice( bl_ts ); + bl_ts = 0; + } + if (bl_cb != NULL) { + bl_cb->set_timeslice( 0 ); + set_status( bl_cb->status, cb_idle ); + bl_cb = NULL; + } + } + + /* pacotes a serem repassados para o callbox */ + else if (bl_start_flag) { + uint16_t bl_cnt = 0; + udp_bl_timer.reset(); + /* pacote de ERASE enviado para o cbx */ + /* neste momento a cabeceira sabe que o servidor se comunicou com o callbox */ + if (!(strncmp(bl_recv_buffer + 2,"\x45",1))) { + bl_cb = __find_CB__( v_cb, bl_peer ); + if (bl_cb != NULL) { + bl_cb->set_timeslice( bl_ts ); + set_status( bl_cb->status, cb_bootloader ); + } + } + /* pacote de OK enviado para o cbx */ + /* neste momento a cabeceira desaloca o timeslice do callbox */ + if (!(strncmp(bl_recv_buffer + 2,"\x4f\x00\x00\x00",4))) { + ts->return_timeslice( bl_ts ); + bl_ts = 0; + if (bl_cb != NULL) { + bl_cb->set_timeslice( 0 ); + } + } + bl_cbx_buffer[0] = bl_ts; + for (bl_cnt = 0; bl_cnt < BL_SIZE; bl_cnt++) { + bl_cbx_buffer[bl_cnt + 1] = bl_recv_buffer[bl_cnt + 2]; + } + if (debug_bootloader) { + pc.printf("\r\nPACOTE HDR->CBX {"); + for (cnt = 0;cnt < BL_SIZE + 1;cnt++) { + if ((cnt % 30) == 0) { + pc.printf("\r\n "); + pc.printf(hex16(cnt)); + pc.printf(" : "); + } + pc.printf(hex8(bl_cbx_buffer[cnt])); + pc.printf(", "); + } + pc.printf("\r\n}"); + } + if (bl_cb != NULL) { + bl_port = bl_cb->get_port(); + } else { + bl_port = bl_peer; + } + send2callboxes( __build_cb_package__( bl_peer, bl_port, __BOOTLOADER_CBX__,bl_cbx_buffer, 0, BL_SIZE + 1, write_buffer) ); + } + } + } + } + if( FD_ISSET( udp_wdt_client.get_fd(), &fdSet ) ) { char wake_msg[ 768 ]; Endpoint udp_wdt_server;