Example #1
0
int main( int ac, char** av )
{
    try
    {
        comma::command_line_options options( ac, av );
        if( options.exists( "--help,-h" ) ) { usage(); }
        outputRaw = options.exists( "--output-raw" );
        rate = options.optional< float >( "--rate" );

        scan_rate = options.optional< double >( "--scan-rate" );

        if( options.exists( "--publish" ) )
        {
            std::string how = options.value< std::string >( "--publish" );
            if( comma::split( how, ':' )[0] == "udp" ) // quick and dirty
            {
                udp_port = boost::lexical_cast< unsigned short >( comma::split( how, ':' )[1] );
                publisher_udp_service.reset( new boost::asio::io_service() );
                publisher_udp_socket.reset( new boost::asio::ip::udp::socket ( *publisher_udp_service, boost::asio::ip::udp::v4() ) );
                boost::system::error_code error;
                publisher_udp_socket->set_option( boost::asio::ip::udp::socket::broadcast( true ), error );
                if( error ) { std::cerr << "velodyne-thin: failed to set broadcast option on port " << udp_port << std::endl; return 1; }
                publisher_udp_socket->set_option( boost::asio::ip::udp::socket::reuse_address( true ), error );
                if( error ) { std::cerr << "velodyne-thin: failed to set reuse address option on port " << udp_port << std::endl; return 1; }
                udp_destination = boost::asio::ip::udp::endpoint( boost::asio::ip::address_v4::broadcast(), udp_port );
            }
            else
            {
                publisher.reset( new comma::io::publisher( how, comma::io::mode::binary ) );
            }
        }
        options.assert_mutually_exclusive( "--focus,--region,--subtract-by-age,--subtract-max-range,--subtract" );
        if( options.exists( "--focus,--region,--subtract-by-age,--subtract-max-range,--subtract" ) )
        {
            db = velodyne::db( options.value< std::string >( "--db", "/usr/local/etc/db.xml" ) );
        }
        if( options.exists( "--focus,--region" ) )
        {
            focus.reset( make_focus( options.value< std::string >( "--focus,--region" ), rate ? *rate : 1.0 ) );
            std::cerr << "velodyne-thin: rate in focus: " << focus->rate_in_focus() << "; rate out of focus: " << focus->rate_out_of_focus() << "; coverage: " << focus->coverage() << std::endl;
        }
        verbose = options.exists( "--verbose,-v" );
        #ifdef WIN32
        _setmode( _fileno( stdin ), _O_BINARY );
        _setmode( _fileno( stdout ), _O_BINARY );
        #endif
        options.assert_mutually_exclusive( "--pcap,--udp-port,--proprietary,-q" );
        boost::optional< unsigned short > port = options.optional< unsigned short >( "--udp-port" );
        if( port ) { run( new snark::udp_reader( *port ) ); }
        else if( options.exists( "--pcap" ) ) { run( new snark::pcap_reader ); }
        else if( options.exists( "--proprietary,-q" ) )
        {
            run( new snark::proprietary_reader );
        }
        else
        {
            run( new snark::stream_reader );
        }
        return 0;
    }
    catch( std::exception& ex ) { std::cerr << "velodyne-thin: " << ex.what() << std::endl; }
    catch( ... ) { std::cerr << "velodyne-thin: unknown exception" << std::endl; }
    usage();
}