From: <bo...@us...> - 2008-03-19 07:59:14
|
Revision: 104 http://gearbox.svn.sourceforge.net/gearbox/?rev=104&view=rev Author: borax00 Date: 2008-03-19 00:59:12 -0700 (Wed, 19 Mar 2008) Log Message: ----------- fixed write-has-to-wait-for-read problem. Modified Paths: -------------- gearbox/trunk/src/gbxserialacfr/serial.cpp gearbox/trunk/src/gbxserialacfr/serial.h gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.h Modified: gearbox/trunk/src/gbxserialacfr/serial.cpp =================================================================== --- gearbox/trunk/src/gbxserialacfr/serial.cpp 2008-03-19 00:16:15 UTC (rev 103) +++ gearbox/trunk/src/gbxserialacfr/serial.cpp 2008-03-19 07:59:12 UTC (rev 104) @@ -597,7 +597,6 @@ { got += ret; } - else if (timeoutsEnabled() && (errno == EAGAIN) ) { if ( waitForDataOrTimeout() == TIMED_OUT ) @@ -642,7 +641,7 @@ char nextChar = 0; do { - //Check for buf overrun Must leave room for NULL terminator + // Check for buf overrun Must leave room for NULL terminator if ( dataPtr >= bufPtr + (count - 1) ) { stringstream ss; @@ -664,12 +663,12 @@ { continue; }else{ - *dataPtr = 0x00; //Timed out. terminate string just incase it's used anyway + *dataPtr = 0x00; // Timed out. terminate string just incase it's used anyway return -1; } } - //If we get here then it was a more serious error + // If we get here then it was a more serious error stringstream ss; ss << "Serial::"<<__func__<<"(): "<<strerror(errno); throw SerialException( ss.str() ); @@ -682,8 +681,6 @@ // Return the number of chars not including the NULL return ( (int) (dataPtr - bufPtr) ); - - //TODO: Duncan! I think that this should cope with any <CR><LF> pair gracefully! } Modified: gearbox/trunk/src/gbxserialacfr/serial.h =================================================================== --- gearbox/trunk/src/gbxserialacfr/serial.h 2008-03-19 00:16:15 UTC (rev 103) +++ gearbox/trunk/src/gbxserialacfr/serial.h 2008-03-19 07:59:12 UTC (rev 104) @@ -38,8 +38,6 @@ //! - 8 data bits //! - no handshaking //! -//! Warning: this thing is _NOT_ thread-safe. -//! //! @author Matthew Ridley, Alex Brooks //! class Serial : public Uncopyable @@ -173,7 +171,7 @@ int portFd_; Timeout timeout_; - + int debugLevel_; lockfile::LockFile *lockFile_; Modified: gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp =================================================================== --- gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp 2008-03-19 00:16:15 UTC (rev 103) +++ gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp 2008-03-19 07:59:12 UTC (rev 104) @@ -51,8 +51,6 @@ serial_(serialPort), responseParser_(responseParser), responseBuffer_(-1,gbxiceutilacfr::BufferTypeCircular), - isMessageWaitingToBeSent_(false), - baudRateChangePending_(false), unparsedBytesWarnThreshold_(unparsedBytesWarnThreshold), tracer_(tracer), status_(status) @@ -73,31 +71,19 @@ void SerialDeviceHandler::setBaudRate( int baudRate ) { - stringstream ss; ss << "SerialDeviceHandler: baud rate change requested: " << baudRate; - tracer_.debug( ss.str() ); - - IceUtil::Mutex::Lock lock(mutex_); - - assert( !baudRateChangePending_ ); - - baudRateChangePending_ = true; - newBaudRate_ = baudRate; + tracer_.debug( "SerialDeviceHandler: Changing baud rate and flushing." ); + serial_.setBaudRate( baudRate ); + // TODO: AlexB: not entirely sure if these are + // necessary, they should either be removed or + // added to the setBaudRate function. + serial_.flush(); + serial_.drain(); } void SerialDeviceHandler::send( const char *commandBytes, int numCommandBytes ) { - IceUtil::Mutex::Lock lock(mutex_); - - if ( isMessageWaitingToBeSent_ ) - { - stringstream ss; - ss << "SerialDeviceHandler::send(): there's a message already waiting to be sent!"; - throw gbxutilacfr::Exception( ERROR_INFO, ss.str() ); - } - isMessageWaitingToBeSent_ = true; - toSend_.resize(numCommandBytes); - memcpy( &(toSend_[0]), commandBytes, numCommandBytes*sizeof(char) ); + serial_.write( commandBytes, numCommandBytes ); } void @@ -112,41 +98,6 @@ try { - // Check for house-keeping jobs first - try - { - IceUtil::Mutex::Lock lock(mutex_); - - if ( baudRateChangePending_ ) - { - tracer_.debug( "SerialDeviceHandler: Changing baud rate and flushing." ); - baudRateChangePending_ = false; - serial_.setBaudRate( newBaudRate_ ); - // TODO: AlexB: not entirely sure if these are - // necessary, they should either be removed or - // added to the setBaudRate function. - serial_.flush(); - serial_.drain(); - } - - if ( isMessageWaitingToBeSent_ ) - { - stringstream ss; - ss<<"SerialDeviceHandler: sending: " << toHexString(toSend_); - tracer_.debug( ss.str() ); - - isMessageWaitingToBeSent_ = false; - serial_.write( &(toSend_[0]), toSend_.size() ); - } - } - catch ( std::exception &e ) - { - stringstream ss; - ss << "SerialDeviceHandler: During house-keeping jobs: " << e.what(); - tracer_.error( ss.str() ); - throw; - } - // Wait for data to arrive, put it in our buffer_ try { if ( getDataFromSerial() ) Modified: gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.h =================================================================== --- gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.h 2008-03-19 00:16:15 UTC (rev 103) +++ gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.h 2008-03-19 07:59:12 UTC (rev 104) @@ -125,8 +125,6 @@ // Returns: true if statusOK, false it something bad happened bool processBuffer( const int &timeStampSec, int &timeStampUsec ); - IceUtil::Mutex mutex_; - gbxserialacfr::Serial &serial_; // Knows how to parse for responses @@ -138,13 +136,6 @@ // Thread-safe store of responses from the device gbxiceutilacfr::Buffer<TimedResponse> responseBuffer_; - // Stuff waiting to be sent - bool isMessageWaitingToBeSent_; - std::vector<char> toSend_; - - bool baudRateChangePending_; - int newBaudRate_; - int unparsedBytesWarnThreshold_; gbxutilacfr::Tracer& tracer_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |