X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=utils%2Ffgpanel%2FFGPanelProtocol.cxx;h=d11c1c61533402cb95fe48b60454b18109828fe9;hb=44ed1f293da8ddda59a140fea98a522d70e9fe33;hp=7efc849ed31144fdb505bf0d2a5c6eefa3776813;hpb=60b6dcdae39b5f5dd9813780a0a0a923e9e98974;p=flightgear.git diff --git a/utils/fgpanel/FGPanelProtocol.cxx b/utils/fgpanel/FGPanelProtocol.cxx index 7efc849ed..d11c1c615 100644 --- a/utils/fgpanel/FGPanelProtocol.cxx +++ b/utils/fgpanel/FGPanelProtocol.cxx @@ -32,10 +32,13 @@ #include #include +using namespace std; + class PropertySetter { public: PropertySetter( SGPropertyNode_ptr node ) : _node(node) {} virtual void setValue( const char * value ) = 0; + virtual ~PropertySetter() {}; protected: SGPropertyNode_ptr _node; }; @@ -123,15 +126,25 @@ FGPanelProtocol::~FGPanelProtocol() void FGPanelProtocol::update( double dt ) { - char buf[8192]; + char buf[2][8192]; if( io == NULL ) return; - int length = io->readline( buf, sizeof(buf)-1 ); - buf[sizeof(buf)-1] = 0; - if ( length > 0 ) { - vector tokens = simgear::strutils::split( buf, "," ); + // read all available lines, keep last one + int Page = 0; + bool HaveData = false; + while ( io->readline( buf[Page], sizeof(buf[Page])-1 ) > 0 ) + { + HaveData = true; + Page ^= 1; + } + + if ( HaveData ) { + // process most recent line of data + Page ^= 1; + buf[Page][sizeof(buf[Page])-1] = 0; + vector tokens = simgear::strutils::split( buf[Page], "," ); for( vector::size_type i = 0; i < tokens.size(); i++ ) { if( i < propertySetterVector.size() ) propertySetterVector[i]->setValue( tokens[i].c_str() );