AT_CODEC_ERROR_CODE host_open( void ) { static bool_t init_ok = FALSE; if( func_ptrs.open != NULL ) return func_ptrs.open(); if( !init_ok ) { COM_CONFIG_SOCKET_AT(&at_socket, VP_COM_CLIENT, AT_PORT, wifi_ardrone_ip); at_socket.protocol = VP_COM_UDP; if(VP_FAILED(vp_com_init(COM_AT()))) { PRINT ("Failed to init AT\n"); vp_com_shutdown( COM_AT() ); return AT_CODEC_OPEN_ERROR; } if(VP_FAILED(vp_com_open(COM_AT(), &at_socket, &atcodec_read, &atcodec_write))) { PRINT ("Failed to open AT\n"); return AT_CODEC_OPEN_ERROR; } // set send_buffer to a low value to limit latency int32_t sendbuf = AT_MUTEX_SNDBUF_SIZE; if ( setsockopt((int32_t)at_socket.priv, SOL_SOCKET, SO_SNDBUF, &sendbuf, sizeof(sendbuf)) ) { PRINT ("Error setting SND_BUF for AT socket\n"); } int opt = IPTOS_PREC_NETCONTROL; int res = setsockopt((int)at_socket.priv, IPPROTO_IP, IP_TOS, &opt, (socklen_t)sizeof(opt)); if (res) { perror("AT stage - setting Live video socket IP Type Of Service : "); } else { printf ("Set IP_TOS ok\n"); } init_ok = TRUE; } return AT_CODEC_OPEN_OK; }
AT_CODEC_ERROR_CODE host_close( void ) { if( func_ptrs.close != NULL ) return func_ptrs.close(); vp_com_close(COM_AT(), &at_socket); return AT_CODEC_CLOSE_OK; }
AT_CODEC_ERROR_CODE host_open( void ) { static bool_t init_ok = FALSE; if( func_ptrs.open != NULL ) return func_ptrs.open(); if( !init_ok ) { COM_CONFIG_SOCKET_AT(&at_socket, VP_COM_CLIENT, 0, wifi_ardrone_ip); at_socket.protocol = VP_COM_UDP; at_socket.remotePort = AT_PORT; if(VP_FAILED(vp_com_init(COM_AT()))) { PRINT ("Failed to init AT\n"); vp_com_shutdown( COM_AT() ); return AT_CODEC_OPEN_ERROR; } if(VP_FAILED(vp_com_open(COM_AT(), &at_socket, &atcodec_read, &atcodec_write))) { PRINT ("Failed to open AT\n"); return AT_CODEC_OPEN_ERROR; } // set send_buffer to a low value to limit latency int32_t sendbuf = AT_MUTEX_SNDBUF_SIZE; if ( setsockopt((int32_t)at_socket.priv, SOL_SOCKET, SO_SNDBUF, &sendbuf, sizeof(sendbuf)) ) { PRINT ("Error setting SND_BUF for AT socket\n"); } /* * On android, with IP_TOS set, certain devices can't connect to AR.Drone 1 * So we just disable this functionnality to avoid these cases. */ #ifdef USE_ANDROID if (IS_ARDRONE2) { #endif int opt = IPTOS_PREC_NETCONTROL; int res = setsockopt((int)at_socket.priv, IPPROTO_IP, IP_TOS, &opt, (socklen_t)sizeof(opt)); if (res) { perror("AT stage - setting Live video socket IP Type Of Service : "); } else { printf ("Set IP_TOS ok\n"); } #ifdef USE_ANDROID } #endif init_ok = TRUE; } return AT_CODEC_OPEN_OK; }