Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Revision 68:b54993674190, committed 2014-11-07
- Comitter:
- klauss
- Date:
- Fri Nov 07 17:57:55 2014 +0000
- Parent:
- 67:cdedc64d9921
- Child:
- 69:65665afbad5d
- Commit message:
- corre??es no tratamento dos pacotes de telemetria.
Changed in this revision
--- a/bootloader_cbx_handler.h Thu Oct 30 19:26:41 2014 +0000
+++ b/bootloader_cbx_handler.h Fri Nov 07 17:57:55 2014 +0000
@@ -22,163 +22,4 @@
int bl_handler( void );
int bl_cbx_reply_to_eth( int ext, char * data );
-/*
-int is_start_pkg( uint8_t * data ){
- //seq_num must to be 0s
- if( !data ) return -1;
-
- for( register int i = __VZ_HEADER_OFFSET__; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 );
-
- return( 1 );
-}
-
-int is_stop_pkg( uint8_t * data ){
- //seq_num must to be 0s
- if( !data ) return -1;
-
- for( register int i = __VZ_HEADER_OFFSET__; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 );
-
- return( 1 );
-}
-
-int is_time_to_stop( uint8_t * data ){
- static int count = 0;
- if( !data ) return( 0 );
-
- if( is_stop_pkg( data ) == 1 ) count++;
-
- else count = 0;
-
- if( count == 10 ) return( 1 );
-
- else return( 0 );
-}
-
-*/
-
-
-/*
-char * listen_bl_socket( char * buffer, int *length ){
- static UDPSocket server;
- server.set_blocking( false, 2 );
- server.bind( UDP_BOOTLOADER_PORT );
- Endpoint client;
- //bool valid_reboot = false;
- uint8_t * data = NULL;
- static int bl_ext;
- static int bl_port;
- //static uint8_t type;
- static Timer t;
- //static uint8_t status = udp_idle;
- //static uint8_t seq_num = 0;
- //OBS sizeof( buffer ) == 4 ????
- //length = server.receiveFrom( client, buffer, sizeof( buffer ) );
- *length = server.receiveFrom( client, buffer, __PROMPT_ETH_BUFFER_SIZE__ );
-
- if( *length == -1 ){
- int ret = server.bind( UDP_BOOTLOADER_PORT );
-
- if( ret == -1 ){
- server.close();
- server.bind( UDP_BOOTLOADER_PORT );
- }
- }
-
- if( *length > 0){
- buffer[ *length ] = '\0';
- buffer[ strlen( buffer ) - 1 ] = '\0';
- t.start();
- bl_timer.reset();
-
- return( NULL );
- }
-
- //data = __parse_vz_pkg__( &bl_ext, &bl_port, __BOOT_LOADER__, (uint8_t *)buffer );
-
- if( !data ){
- debug_msg("UDP pks parse failed");
- server.sendTo( client, buffer, sizeof( buffer ) );
- return( NULL );
- }
- */
-
- /*
- if( status == udp_idle ){
- data[ 0 ] |= BIT7;
- strcpy( (char *)&data[ 1 ], "Received listen request" );
- server.sendTo( client, buffer, sizeof( buffer ) );
- status = udp_waiting_start_pkg;
- }
- */
-
- /*
- if( status == udp_waiting_start_pkg ){
- static int count = 0;
- if( is_start_pkg( data ) == 1 )
- if( count++ == __START_PKG_COUNT__ ) status = udp_listen;
-
- else{
- count = 0;
- status = udp_idle;
- }
- }
- */
- /*
- if( status == udp_listen ){
- debug_msg( "Received start pkgs" ); // mandar msg pro server
- if( t.read() < 60 ){
- server.set_blocking( true, 10 );
- t.reset();
- do{
- wdt.kick();
- *length = server.receiveFrom( client, buffer, sizeof( buffer ) );
- //data = __parse_vz_pkg__( &bl_ext, &_blport, &type, (uint8_t *)buffer );
- if( data ){
- if( !( is_start_pkg( data ) ) ) break;
- }else{
- debug_msg("UDP pks parse failed");
- // reenvia pkg dizendo que podemos comecar com a transacao de dados
- }
- }while( t.read() < 60 );
-
- if( t.read() < 60 ){
- //tratar o primeiro pkg depois dos zeros aqui
- //a ideia é ir recebendo e colocando no arquivo "se for pra header" ou mandar
- //pro cb depois,
- if( !( ext || port ) ){ // pkg pra header
- debug_msg("criando arquivo");
- }else{
- debug_msg("Mandando pkg pro cb");
- }
- //FIXME mudar essa condicao de parada
- while( !( is_time_to_stop( data ) == 1 ) ){
- wdt.kick();
- *length = server.receiveFrom( client, buffer, sizeof( buffer ) );
- if( ( data[ 0 ] - seq_num ) != 1 ){
- //perdi algum pacote
- //solicitar re-envio mandando o ultimo seq_num recebido talvez ...
- continue;
- }else{
- debug_msg("+(%d,%d)-%s+", ext, port, data );
- }
- }
- //pensar em como validar os pacotes recebidos, cks ... e o que mais ?
- //se validado os pkgs, dar reset com os dados no arquivo bla, caso contrario, ignorar ...
- //if( valid_reboot ) NVIC_SystemReset();
-
- //else{
- // server.set_blocking( false, 1 );
- // t.stop();
- // t.reset();
- // debug_msg("Nao Resetando ... ");
- //}
-
- }
- }
- }else return( buffer );
- *length = 0;
- return( NULL );
- //return( NULL );
-}
-*/
#endif
\ No newline at end of file
--- a/main.cpp Thu Oct 30 19:26:41 2014 +0000
+++ b/main.cpp Fri Nov 07 17:57:55 2014 +0000
@@ -18,7 +18,7 @@
init_fsystem();
- // pensar melhor em como saber se estou conectado na eth
+ //FIXMEj pensar melhor em como saber se estou conectado na eth
//int eth_status = __init_eth__( ð );
int eth_status = __init_eth__();
@@ -94,15 +94,20 @@
reset_leds();
udp_timer.start();
- send_msg("Ready");
- uint8_t before = t.read();
+
+ init_telemetry_handler();
+
static uint8_t count = 0;
int bl_ret = init_bl_handler();
if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret );
+ uint8_t before = t.read();
+
+ send_msg("Ready");
+
/*------------------------------------------------ main loop -------------------------------------------------------------------------*/
while( true ){
- //FIXME colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ...
+ //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ...
prompt_process( NULL );
wdt.kick();
@@ -278,8 +283,8 @@
}
if( t.read() > 5 ){
- static int test_ext = 5010;
- static int test_port = 5010;
+ //static int test_ext = 5010;
+ //static int test_port = 5010;
//send_msg("from_eth = %s - tcp_session = %s", ( from_eth ) ? "true" : "false", ( tcp_session ) ? "true" : "false" );
if( debug_alive ){
send_msg("Registred %d CBx", v_cb->size() );
@@ -318,9 +323,21 @@
if( main_test ){
data = buffer;
- ext = test_ext++ + ( ( test_ext % 2 ) ? 100 : 50 );
- port = test_port++;
- type = __REGISTRY__;
+ //ext = test_ext++ + ( ( test_ext % 2 ) ? 100 : 50 );
+ //port = test_port++;
+ //type = __REGISTRY__;
+ type = __TELEMETRY__;
+ ext = 5108;
+ port = 5008;
+ uint8_t var = 0xAA;
+ for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__; i++ ){
+ data[ i ] = var++;
+ if( var == 0xFF ) var = 0xAA;
+ }
+ for( register uint16_t i = __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__; i < __CB_BUFFER_SIZE__; i++ ){
+ data[ i ] = 0x00;
+ }
+ main_test = false;
}
/*
@@ -391,7 +408,7 @@
set_status( cb->status, cb_trying );
if( debug_main ) debug_msg("Request invite cbx status :: %d", cb->status );
- //FIXME essa logica deve estar la embaixo, fora do switch maior, a ideia eh
+ //FIXMEj essa logica deve estar la embaixo, fora do switch maior, a ideia eh
// quando receber um pedido de invite, apenas manda o invite pro server
// dai rodar, ver se alguem mandou alguma coisa e voltar a tratar com o
// * ver se ja esta tudo ok, a ideia é fazer esse pedido de invite funcionar
@@ -579,7 +596,7 @@
}
__send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__,
( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
- //FIXME talvez eu nao precise dessa linha mudar o set_status( cb->sip->status, sip_idle ); pra ver o que acontece
+ //FIXMEj talvez eu nao precise dessa linha mudar o set_status( cb->sip->status, sip_idle ); pra ver o que acontece
//cb->reset_sip();
set_status( cb->sip->status, sip_idle );
cb->re_start_timer();
--- a/utils.cpp Thu Oct 30 19:26:41 2014 +0000
+++ b/utils.cpp Fri Nov 07 17:57:55 2014 +0000
@@ -4,6 +4,9 @@
EthernetInterface eth;
uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ];
+UDPSocket t_sock;
+Endpoint t_server;
+
void reverse( char str[], int length ){
int start = 0;
int end = length -1;
@@ -66,7 +69,8 @@
}
if( debug_file ) debug_msg("Eth ip %s", buff_ip );
}else{
- if( debug_file ) if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" );
+ //if( debug_file ) if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" );
+ if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" );
strncpy( buff_ip, __MY_IP__, 20 );
}
}
@@ -228,11 +232,19 @@
strcat( aux, " " );
//strncat( aux, (char * )data, __TELEMETRY_SIZE__ );
-
+ /*
+ pc.printf("\n\r 1. ");
+ uint8_t count = 2;
+ for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){
+ if( i > 0 && !( i % 15 ) ) pc.printf("\n\r%2i. ", count++ );
+ pc.printf("%3x ", data[ i ] );
+ }
+ pc.printf("\n\r");
+ */
+ //pulando o byte de id ( sequence number )
+ data += __SEQ_NUM_SIZE__;
//pulando os bytes do clock
data += __CLOCK_SYNC_SIZE__;
- //pulando o byte de id ( sequence number )
- data += __SEQ_NUM_SIZE__;
uint8_t offset = strlen( aux );
@@ -240,6 +252,16 @@
for( register uint16_t i = __TELEMETRY_SIZE__ + offset; i < __CB_BUFFER_SIZE__; i++ ) aux[ i ] = 0;
+ int sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
+ if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
+
+ if( sent == -1 ){
+ re_start_telemetry();
+ sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
+
+ if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
+ }
+
if( debug_telemetry ){
pc.printf("\n\r 1. ");
uint8_t count = 2;
@@ -249,24 +271,24 @@
}
pc.printf("\n\r");
- if( tcp_session ) tcp_client.send_all( ( char *)aux, __CB_BUFFER_SIZE__ );
+ char msg_to_eth[ 1024 ];
+ strcpy( msg_to_eth, tmp );
+ strcat( msg_to_eth, " " );
+ for( register uint16_t i = 0; i < __TELEMETRY_SIZE__; i++ ){
+ strcat( msg_to_eth, itoa( data[ i ], tmp, 16 ) );
+ strcat( msg_to_eth, " " );
+ }
+ for( register uint16_t i = __TELEMETRY_SIZE__; i < __CB_BUFFER_SIZE__ - 1; i++ ){
+ strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
+ strcat( msg_to_eth, " " );
+ }
+ strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
+
+ if( tcp_session ){
+ int debug_sent = tcp_client.send_all( msg_to_eth, strlen( msg_to_eth ) );
+ if( debug_telemetry ) send_msg("%d - bytes enviados pro prompt-eth", debug_sent );
+ }
}
-
- UDPSocket t_sock;
- Endpoint t_server;
-
- int adr = t_server.set_address( __TELEMETRY_SERVER_IP__ , __TELEMETRY_SERVER_PORT__ );
- if( debug_telemetry ) send_msg("Valor de retorno adr -- %d", adr );
- t_sock.set_blocking( false, 1 );
-
- int bind = t_sock.bind( __TELEMETRY_HEADER_PORT__ );
- if( debug_telemetry ) send_msg("Valor de retorno bind -- %d", bind );
-
- int ret = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
- if( debug_telemetry ) send_msg("Valor de retorno sent-- %d", ret );
-
- int close = t_sock.close();
- if( debug_telemetry ) send_msg("Valor de retorno close-- %d", close );
}
void __send_to_cb__( uint8_t * buffer ){
@@ -274,5 +296,62 @@
xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ );
send2callboxes();
}
+void init_telemetry_handler( void ){
+ //FIXME isso deveria ler do arquivo e nao do define.
+
+ char buff_ip[ 16 ] = "";
+ char buff_port[ 8 ] = "";
+ int telemetry_port = 0;
+
+ FILE *fp = fopen( "/qspi/telemetry_ip.txt", "r");
+ if( fp == NULL ){
+ if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
+ strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );
+ }else{
+ int read = fread( buff_ip, 1, 512, fp );
+ if( read > 0 ){
+ for( int i = 0; i < read; i++ )
+ if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){
+ buff_ip[ i ] = '\0';
+ break;
+ }
+ if( debug_file ) debug_msg("Telemetry server ip %s", buff_ip );
+ }else{
+ if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
+ strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );
+ }
+ }
+ fclose( fp );
+
+ fp = fopen( "/qspi/telemetry_port.txt", "r");
+ if( fp == NULL ) {
+ if( debug_sip ) debug_msg("Failed to open /qspi/telemetry_port.txt" );
+ telemetry_port = __TELEMETRY_SERVER_PORT__;
+ } else {
+ if( fread( (void *)buff_port, 1, 32, fp ) > 0 ) {
+ telemetry_port = atoi( buff_port );
+ if( debug_sip ) debug_msg("Telemetry server port %d", buff_port );
+ } else {
+ if( debug_sip ) debug_msg("Failed to read /qspi/telemetry_port.txt" );
+ telemetry_port = __TELEMETRY_SERVER_PORT__;
+ }
+ }
+ fclose( fp );
+
+ //int addr = t_server.set_address( __TELEMETRY_SERVER_IP__ , __TELEMETRY_SERVER_PORT__ );
+ int addr = t_server.set_address( buff_ip , telemetry_port );
+ if( debug_telemetry ) send_msg(" Valor de retorno set_address -- %d ", addr );
+ t_sock.set_blocking( false, 1 );
+
+ int bind = t_sock.bind( __TELEMETRY_HEADER_PORT__ );
+ if( debug_telemetry ) send_msg(" Valor de retorno bind -- %d ", bind );
+}
+
+void re_start_telemetry( void ){
+ int close = t_sock.close();
+ if( debug_telemetry ) send_msg(" Valor de retorno close-- %d ", close );
+
+ init_telemetry_handler();
+}
int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); }
\ No newline at end of file
--- a/utils.h Thu Oct 30 19:26:41 2014 +0000
+++ b/utils.h Fri Nov 07 17:57:55 2014 +0000
@@ -27,6 +27,8 @@
extern DigitalOut led3;
extern DigitalOut led4;
extern EthernetInterface eth;
+extern UDPSocket t_sock;
+extern Endpoint t_server;
#define set_status(a,b) _set_status(a,b)
#define _set_status(a,b){ \
if( a != b ) if( debug_sip )debug_msg("Anterior %d -- Atual %d", a, b ); \
@@ -48,4 +50,7 @@
void __send_to_cb__( uint8_t * buffer );
int ls_comp( const void * a, const void * b );
+void init_telemetry_handler( void );
+void re_start_telemetry( void );
+
#endif
\ No newline at end of file
--- a/vz_protocol.h Thu Oct 30 19:26:41 2014 +0000
+++ b/vz_protocol.h Fri Nov 07 17:57:55 2014 +0000
@@ -31,6 +31,7 @@
//#define __TELEMETRY_SERVER_IP__ "192.168.120.163"
#define __TELEMETRY_SERVER_IP__ "192.168.120.144"
+//#define __TELEMETRY_SERVER_IP__ "192.168.120.200"
#define __TELEMETRY_SERVER_PORT__ 9192
#define __TELEMETRY_HEADER_PORT__ 9321
