当前位置: 首页>>代码示例>>C++>>正文


C++ scoped_ptr::readscan方法代码示例

本文整理汇总了C++中boost::scoped_ptr::readscan方法的典型用法代码示例。如果您正苦于以下问题:C++ scoped_ptr::readscan方法的具体用法?C++ scoped_ptr::readscan怎么用?C++ scoped_ptr::readscan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::scoped_ptr的用法示例。


在下文中一共展示了scoped_ptr::readscan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
            }   
        }
        else if( options.exists( "--get" ) )
        {
            std::vector< std::string > v = comma::split( options.value< std::string >( "--get" ), ',' );
            sick::ibeo::commands::get command;
            sick::ibeo::commands::get::response response;
            std::string comma;
            for( std::size_t i = 0; ok && i < v.size(); ++i, ok = ok && response.ok() )
            {
                if( v[i] == "address" ) { command.index = sick::ibeo::commands::set::ip_address; }
                else if( v[i] == "port" ) { command.index = sick::ibeo::commands::set::tcp_port; }
                else { COMMA_THROW( comma::exception, "expected parameter, got " << v[i] ); }
                response = protocol->write( command );
                if( response.ok() ) { std::cout << comma << response << std::endl; }
                comma = ",";
                clear_fault();
            }
        }
        else if( options.exists( "--get-status" ) )
        {
            sick::ibeo::commands::get_status::response response = protocol->write( sick::ibeo::commands::get_status() );
            ok = response.ok();
            if( ok ) { std::cout << response << std::endl; }
            clear_fault();
        }
        else if( options.exists( "--start" ) )
        {
            ok = protocol->write( sick::ibeo::commands::start() ).ok();
            clear_fault();
        }
        else if( options.exists( "--stop" ) )
        {
            ok = protocol->write( sick::ibeo::commands::stop() ).ok();
            clear_fault();
        }
        else
        {
            std::string publisher_name;
            boost::shared_ptr< comma::io::publisher > publisher;
            if( options.exists( "--publish" ) ) 
            { 
                publisher_name = options.value< std::string >( "--publish" ); 
                bool blocking = options.exists( "--no-discard" );
                bool flush = !options.exists( "--no-flush" );
                publisher = boost::shared_ptr< comma::io::publisher >( new comma::io::publisher( publisher_name, comma::io::mode::binary, blocking, flush ) );
                if( verbose ) { 
                    std::cerr << "sick-ldmrs-stream: will be publishing on " << publisher_name << ( blocking? ", blocking enabled": "" ) << ( flush? ", flush enabled": "" ) << std::endl; 
                }
            }
            update_timestamp( true );
            if( verbose ) { std::cerr << "sick-ldmrs-stream: starting scanning..." << std::endl; }
            if( !protocol->write( sick::ibeo::commands::start() ).ok() ) { COMMA_THROW( comma::exception, "failed to start scanning" ); }
            if( verbose ) { std::cerr << "sick-ldmrs-stream: started scanning" << std::endl; }
            bool first = true;
            comma::signal_flag is_shutdown;
#ifdef WIN32
            _setmode( _fileno( stdout ), _O_BINARY ); 
#endif
            while( !is_shutdown )
            {
                update_timestamp();
                clear_fault();
                const sick::ibeo::scan_packet* scan;
                try { scan = protocol->readscan(); }
                catch( sick::ibeo::protocol::faultException& ex ) { continue; }
                if( scan == NULL ) { break; }
                if( verbose && first ) { std::cerr << "sick-ldmrs-stream: got first scan" << std::endl; first = false; }
                if( !scan->packet_header.valid() ) { COMMA_THROW( comma::exception, "invalid scan" ); }
                if( options.exists( "--publish" ) )
                {
                    publisher->write( scan->data(), sick::ibeo::header::size + scan->packet_header.payload_size() );
                }
                else 
                {
                    std::cout.write( scan->data(), sick::ibeo::header::size + scan->packet_header.payload_size() ); 
                }
                if( verbose && ( scan->packet_scan.scan_header.measurement_number() % 10 == 0 ) )
                {
                    std::cerr << "sick-ldmrs-stream: got " << scan->packet_scan.scan_header.measurement_number() << " scans              \r";
                }
            }
            if( is_shutdown ) { std::cerr << "sick-ldmrs-stream: caught signal" << std::endl; }
        }
        if( ok ) { if( verbose ) { std::cerr << "sick-ldmrs-stream: done" << std::endl; } }
        else { std::cerr << "sick-ldmrs-stream: failed" << std::endl; }
        if( stream ) { stream->close(); }
        return ok ? 0 : -1;
    }
    catch( std::exception& ex )
    {
        std::cerr << "sick-ldmrs-stream: " << ex.what() << std::endl;
    }
    catch( ... )
    {
        std::cerr << "sick-ldmrs-stream: unknown exception" << std::endl;
    }
    if( stream ) { stream->close(); }
    usage();
}
开发者ID:WangFei-DUT,项目名称:snark,代码行数:101,代码来源:sick-ldmrs-stream.cpp


注:本文中的boost::scoped_ptr::readscan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。