You can subscribe to this list here.
| 2008 |
Jan
|
Feb
(58) |
Mar
(15) |
Apr
(23) |
May
(8) |
Jun
(92) |
Jul
(66) |
Aug
(6) |
Sep
(9) |
Oct
(44) |
Nov
(8) |
Dec
(1) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(10) |
Feb
(8) |
Mar
(2) |
Apr
(8) |
May
(19) |
Jun
(11) |
Jul
(8) |
Aug
(6) |
Sep
(5) |
Oct
(4) |
Nov
(26) |
Dec
(4) |
| 2010 |
Jan
(5) |
Feb
(3) |
Mar
(4) |
Apr
(3) |
May
(4) |
Jun
|
Jul
(1) |
Aug
(16) |
Sep
(7) |
Oct
(3) |
Nov
(7) |
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <bo...@us...> - 2008-10-21 07:03:41
|
Revision: 332
http://gearbox.svn.sourceforge.net/gearbox/?rev=332&view=rev
Author: borax00
Date: 2008-10-21 07:03:25 +0000 (Tue, 21 Oct 2008)
Log Message:
-----------
added a guard against infinite-loop caused by parsing parsing zero bytes.
Modified Paths:
--------------
gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp
Modified: gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp
===================================================================
--- gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp 2008-10-20 11:01:04 UTC (rev 331)
+++ gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.cpp 2008-10-21 07:03:25 UTC (rev 332)
@@ -224,6 +224,14 @@
throw;
}
+ if ( numBytesParsed == 0 )
+ {
+ stringstream ss;
+ ss << "SerialDeviceHandler: Zero bytes were parsed, but buffer contains "<<buffer_.size()<<" bytes! (gotMessage="<<gotMessage<<"). responseParser_ shouldn't do this to us.";
+ tracer_.warning( ss.str() );
+ numBytesParsed = 1;
+ }
+
removeParsedData( buffer_, numBytesParsed );
if ( gotMessage )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rum...@us...> - 2008-10-20 11:01:19
|
Revision: 331
http://gearbox.svn.sourceforge.net/gearbox/?rev=331&view=rev
Author: rumataxyz
Date: 2008-10-20 11:01:04 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
and yet another try
Modified Paths:
--------------
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:48:39 UTC (rev 330)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 11:01:04 UTC (rev 331)
@@ -107,7 +107,7 @@
errorByte = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBit = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
if(0 == faultBuf[errorByte] && (unsigned char)(1<<errorBit))
- faultBuf[errorByte] = faultBuf[errorByte] + ((unsigned char)1<<errorBit);
+ faultBuf[errorByte] = faultBuf[errorByte] + ((unsigned char)0x01<<errorBit);
else
faultBuf[errorByte] = faultBuf[errorByte] - (unsigned char)(1<<errorBit);
uint32_t tmpCrc;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rum...@us...> - 2008-10-20 10:48:49
|
Revision: 330
http://gearbox.svn.sourceforge.net/gearbox/?rev=330&view=rev
Author: rumataxyz
Date: 2008-10-20 10:48:39 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
another go at getting gcc to shut up
Modified Paths:
--------------
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:42:03 UTC (rev 329)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:48:39 UTC (rev 330)
@@ -107,7 +107,7 @@
errorByte = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBit = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
if(0 == faultBuf[errorByte] && (unsigned char)(1<<errorBit))
- faultBuf[errorByte] = faultBuf[errorByte] + (unsigned char)(1<<errorBit);
+ faultBuf[errorByte] = faultBuf[errorByte] + ((unsigned char)1<<errorBit);
else
faultBuf[errorByte] = faultBuf[errorByte] - (unsigned char)(1<<errorBit);
uint32_t tmpCrc;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rum...@us...> - 2008-10-20 10:42:15
|
Revision: 329
http://gearbox.svn.sourceforge.net/gearbox/?rev=329&view=rev
Author: rumataxyz
Date: 2008-10-20 10:42:03 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
broke down and did a cast to shut gcc up
Modified Paths:
--------------
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:24:39 UTC (rev 328)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:42:03 UTC (rev 329)
@@ -106,10 +106,10 @@
memcpy(faultBuf, buf, bufLen);
errorByte = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBit = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
- if(0 == faultBuf[errorByte] && (1u<<errorBit))
- faultBuf[errorByte] = faultBuf[errorByte] + (1u<<errorBit);
+ if(0 == faultBuf[errorByte] && (unsigned char)(1<<errorBit))
+ faultBuf[errorByte] = faultBuf[errorByte] + (unsigned char)(1<<errorBit);
else
- faultBuf[errorByte] = faultBuf[errorByte] - (1u<<errorBit);
+ faultBuf[errorByte] = faultBuf[errorByte] - (unsigned char)(1<<errorBit);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
singleRandomBitFlipFailNum++;
@@ -121,10 +121,10 @@
errorByteTwo = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBitTwo = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
}while (errorByte==errorByteTwo && errorBit==errorBitTwo);// make sure we don't flip the same bit twice
- if(0 == faultBuf[errorByteTwo] && (1u<<errorBitTwo))
- faultBuf[errorByteTwo] = faultBuf[errorByteTwo] + (1u<<errorBitTwo);
+ if(0 == faultBuf[errorByteTwo] && (unsigned char)(1<<errorBitTwo))
+ faultBuf[errorByteTwo] = faultBuf[errorByteTwo] + (unsigned char)(1<<errorBitTwo);
else
- faultBuf[errorByteTwo] = faultBuf[errorByteTwo] - (1u<<errorBitTwo);
+ faultBuf[errorByteTwo] = faultBuf[errorByteTwo] - (unsigned char)(1<<errorBitTwo);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
doubleRandomBitFlipFailNum++;
@@ -137,10 +137,10 @@
errorBitThree = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
}while ((errorByteThree==errorByte && errorBitThree==errorBit)
|| (errorByteThree==errorByteTwo && errorBitThree==errorBitTwo));// make sure we don't flip the same bit twice
- if(0 == faultBuf[errorByteThree] && (1u<<errorBitThree))
- faultBuf[errorByteThree] = faultBuf[errorByteThree] + (1u<<errorBitThree);
+ if(0 == faultBuf[errorByteThree] && (unsigned char)(1<<errorBitThree))
+ faultBuf[errorByteThree] = faultBuf[errorByteThree] + (unsigned char)(1<<errorBitThree);
else
- faultBuf[errorByteThree] = faultBuf[errorByteThree] - (1u<<errorBitThree);
+ faultBuf[errorByteThree] = faultBuf[errorByteThree] - (unsigned char)(1<<errorBitThree);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
tripleRandomBitFlipFailNum++;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rum...@us...> - 2008-10-20 10:24:47
|
Revision: 328
http://gearbox.svn.sourceforge.net/gearbox/?rev=328&view=rev
Author: rumataxyz
Date: 2008-10-20 10:24:39 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
changed how tracer is handled, minor build fixes, some changes to address the new build warnings
Modified Paths:
--------------
gearbox/trunk/submitted/gbxnovatelacfr/driver.cpp
gearbox/trunk/submitted/gbxnovatelacfr/driver.h
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/novatelmessages.h
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
gearbox/trunk/submitted/gbxnovatelacfr/test/example.cmake.in
Modified: gearbox/trunk/submitted/gbxnovatelacfr/driver.cpp
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/driver.cpp 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/driver.cpp 2008-10-20 10:24:39 UTC (rev 328)
@@ -96,20 +96,22 @@
Driver::Driver( const Config& cfg) :
baud_(115200),
config_(cfg),
- tracer_(new gbxutilacfr::TrivialTracer())
+ tracerInternal_(new gbxutilacfr::TrivialTracer()),
+ tracer_(*(tracerInternal_.get()))
{
- assert(0 != tracer_.get());
+ //assert(0 != tracer_.get());
configure();
return;
}
Driver::Driver( const Config& cfg,
- gbxutilacfr::Tracer* tracer) :
+ gbxutilacfr::Tracer &tracer) :
baud_(115200),
config_(cfg),
+ tracerInternal_(0),
tracer_(tracer)
{
- assert(0 != tracer_.get());
+ //assert(0 != tracer_.get());
configure();
return;
}
@@ -139,18 +141,18 @@
configureGps();
requestData();
serial_->flush();
- tracer_->info("Setup done, starting normal operation!");
+ tracer_.info("Setup done, starting normal operation!");
return;
}
Driver::~Driver() {
// just in case something is running... stops the novatel logging any messages
try{
- tracer_->info("Stopping NovatelSpan driver!");
+ tracer_.info("Stopping NovatelSpan driver!");
serial_->flush();
serial_->writeString( "unlogall\r\n" );
serial_->drain();
- tracer_->info("NovatelSpan driver stopped!");
+ tracer_.info("NovatelSpan driver stopped!");
}
catch(...){
//no throwing from destructors
@@ -173,7 +175,7 @@
int currentBaudrate = 0;
bool correctBaudrate = false;
- tracer_->info( "Trying to hook up to receiver at different Baudrates" );
+ tracer_.info( "Trying to hook up to receiver at different Baudrates" );
int maxTry = 4;
int successThresh = 4;
int timeOutMsec = 250;
@@ -194,7 +196,7 @@
<< currentBaudrate << "bps; "
<< "Resetting to configured speed: "
<< baud_ << "bps";
- tracer_->info(ss.str());
+ tracer_.info(ss.str());
char str[256];
sprintf( str,"com com1 %d n 8 1 n off on\r\n", baud_ );
serial_->writeString( str );
@@ -212,7 +214,7 @@
int timeOutMsec = 200;
if(config_.enableImu_){
- tracer_->info("Configuring IMU, switching INS ON!");
+ tracer_.info("Configuring IMU, switching INS ON!");
imuDecoder_.reset(gnua::createImuDecoder(config_.imuType_));
std::stringstream ss;
// tell the novatel what serial port the imu is attached to (com3 == aux)
@@ -240,10 +242,10 @@
}
//force the IMU to re-align at every startup
//put = serial_->writeString( "inscommand reset\r\n" );
- //tracer_->info("Reset IMU; Waiting 5 seconds before continuing!");
+ //tracer_.info("Reset IMU; Waiting 5 seconds before continuing!");
//sleep(5);
}else{
- tracer_->info("No IMU, switching INS OFF!");
+ tracer_.info("No IMU, switching INS OFF!");
challenge = "inscommand disable\r\n";
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -359,7 +361,7 @@
// CDGPS
if(config_.enableCDGPS_){
- tracer_->info("Turning on CDGPS!");
+ tracer_.info("Turning on CDGPS!");
challenge = ( "ASSIGNLBAND CDGPS 1547547 4800\r\n" );
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -370,7 +372,7 @@
// turn SBAS on/off (essentially global DGPS)
if(config_.enableSBAS_){
- tracer_->info("Turning on SBAS!");
+ tracer_.info("Turning on SBAS!");
challenge = ( "SBASCONTROL ENABLE Auto 0 ZEROTOTWO\r\n");
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -386,7 +388,7 @@
}
}
else{
- tracer_->info("Turning off SBAS!");
+ tracer_.info("Turning off SBAS!");
challenge = ( "SBASCONTROL DISABLE Auto 0 NONE\r\n");
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -397,7 +399,7 @@
// rtk
if(config_.enableRTK_){
- tracer_->info("Turning on RTK!");
+ tracer_.info("Turning on RTK!");
challenge = ( "com com2,9600,n,8,1,n,off,on\r\n" );
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -447,7 +449,7 @@
if(config_.enableGpsPos_){
std::stringstream ss;
ss << "Turning on GPS position at " << 1.0/config_.dtGpsPos_ << "Hz!";
- tracer_->info(ss.str().c_str());
+ tracer_.info(ss.str().c_str());
ss.str("");
ss << "log bestgpsposb ontime " << config_.dtGpsPos_ << "\r\n";
challenge = ss.str();
@@ -462,7 +464,7 @@
if(config_.enableGpsVel_){
std::stringstream ss;
ss << "Turning on GPS velocity at " << 1.0/config_.dtGpsVel_ << "Hz!";
- tracer_->info(ss.str().c_str());
+ tracer_.info(ss.str().c_str());
ss.str("");
ss << "log bestgpsvelb ontime " << config_.dtGpsVel_ << "\r\n";
challenge = ss.str();
@@ -480,7 +482,7 @@
if(config_.enableInsPva_){
std::stringstream ss;
ss << "Turning on INS position/velocity/orientation at " << 1.0/config_.dtInsPva_ << "Hz!";
- tracer_->info(ss.str().c_str());
+ tracer_.info(ss.str().c_str());
ss.str("");
ss << "log inspvasb ontime " << config_.dtInsPva_ << "\r\n";
challenge = ss.str();
@@ -496,7 +498,7 @@
// raw accelerometer and gyro data
if(config_.enableRawImu_){
- tracer_->info("Turning on raw imu data!");
+ tracer_.info("Turning on raw imu data!");
challenge = ( "log rawimusb onnew\r\n" );
if(false == gnua::sendCmdWaitForResponse(challenge, ack, errorResponse, *(serial_.get()), timeOutMsec)){
std::stringstream ss;
@@ -534,12 +536,19 @@
case gnua::RawImuSBLogType:
data = createExternalMsg(msg.rawImu, timeStamp, imuDecoder_.get());
break;
+ case gnua::InvalidLogType:
+ {
+ std::stringstream ss;
+ ss <<"Id invalid, looks like we didn't get anything from the receiver!" << std::endl;
+ throw ( gua::Exception(ERROR_INFO, ss.str()) );
+ }
+ break;
default:
{
std::stringstream ss;
ss <<"Got unexpected message type from receiver; id: " << msg.header.msgId << std::endl;
if(config_.ignoreUnknownMessages_){
- tracer_->warning(ss.str());
+ tracer_.warning(ss.str());
}else{
throw ( gua::Exception(ERROR_INFO, ss.str()) );
}
@@ -926,7 +935,7 @@
uint16_t
readNovatelMessage(union NovatelMessage &msg, struct timeval &timeStamp, gbxserialacfr::Serial *serial) {
- uint16_t id = -1;
+ uint16_t id = gnua::InvalidLogType;
msg.header.sb1 = 0;
// skip everything until we get the first sync byte
Modified: gearbox/trunk/submitted/gbxnovatelacfr/driver.h
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/driver.h 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/driver.h 2008-10-20 10:24:39 UTC (rev 328)
@@ -432,7 +432,7 @@
Driver( const Config &cfg);
//!@brief full control over tracing (e.g. to syslog)
//!@param tracer you need to provide this guy (via new), do NOT delete it, it will be deleted when your Driver object goes out of scope
- Driver( const Config &cfg, gbxutilacfr::Tracer* tracer);
+ Driver( const Config &cfg, gbxutilacfr::Tracer &tracer);
//!@}
~Driver();
@@ -464,7 +464,8 @@
int baud_;
Config config_;
- std::auto_ptr<gbxutilacfr::Tracer > tracer_;
+ std::auto_ptr<gbxutilacfr::Tracer> tracerInternal_;
+ gbxutilacfr::Tracer& tracer_;
};
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt 2008-10-20 10:24:39 UTC (rev 328)
@@ -13,7 +13,7 @@
# GBX_REQUIRE_VAR( build LIB ${lib_name} ICEUTIL_FOUND "libIceUtil not found" )
SET( dep_libs GbxUtilAcfr GbxSerialAcfr )
-GBX_REQUIRE_TARGETS( build LIB ${lib_name} ${int_libs} )
+GBX_REQUIRE_TARGETS( build LIB ${lib_name} ${dep_libs} )
IF( build )
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/novatelmessages.h
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/novatelmessages.h 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/novatelmessages.h 2008-10-20 10:24:39 UTC (rev 328)
@@ -14,7 +14,8 @@
RawImuSBLogType = 325,
BestGpsPosBLogType = 423,
BestGpsVelBLogType = 506,
- InsPvaSBLogType = 508
+ InsPvaSBLogType = 508,
+ InvalidLogType
};
#pragma pack(push,1)
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/test/crc32test.cpp 2008-10-20 10:24:39 UTC (rev 328)
@@ -106,10 +106,10 @@
memcpy(faultBuf, buf, bufLen);
errorByte = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBit = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
- if(0 == faultBuf[errorByte] && (1<<errorBit))
- faultBuf[errorByte] = faultBuf[errorByte] + (1<<errorBit);
+ if(0 == faultBuf[errorByte] && (1u<<errorBit))
+ faultBuf[errorByte] = faultBuf[errorByte] + (1u<<errorBit);
else
- faultBuf[errorByte] = faultBuf[errorByte] - (1<<errorBit);
+ faultBuf[errorByte] = faultBuf[errorByte] - (1u<<errorBit);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
singleRandomBitFlipFailNum++;
@@ -121,10 +121,10 @@
errorByteTwo = (int) ((double)faultBufLen * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
errorBitTwo = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
}while (errorByte==errorByteTwo && errorBit==errorBitTwo);// make sure we don't flip the same bit twice
- if(0 == faultBuf[errorByteTwo] && (1<<errorBitTwo))
- faultBuf[errorByteTwo] = faultBuf[errorByteTwo] + (1<<errorBitTwo);
+ if(0 == faultBuf[errorByteTwo] && (1u<<errorBitTwo))
+ faultBuf[errorByteTwo] = faultBuf[errorByteTwo] + (1u<<errorBitTwo);
else
- faultBuf[errorByteTwo] = faultBuf[errorByteTwo] - (1<<errorBitTwo);
+ faultBuf[errorByteTwo] = faultBuf[errorByteTwo] - (1u<<errorBitTwo);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
doubleRandomBitFlipFailNum++;
@@ -137,10 +137,10 @@
errorBitThree = (int) (8.0 * (rand_r(&randSeed) / (RAND_MAX + 1.0)));
}while ((errorByteThree==errorByte && errorBitThree==errorBit)
|| (errorByteThree==errorByteTwo && errorBitThree==errorBitTwo));// make sure we don't flip the same bit twice
- if(0 == faultBuf[errorByteThree] && (1<<errorBitThree))
- faultBuf[errorByteThree] = faultBuf[errorByteThree] + (1<<errorBitThree);
+ if(0 == faultBuf[errorByteThree] && (1u<<errorBitThree))
+ faultBuf[errorByteThree] = faultBuf[errorByteThree] + (1u<<errorBitThree);
else
- faultBuf[errorByteThree] = faultBuf[errorByteThree] - (1<<errorBitThree);
+ faultBuf[errorByteThree] = faultBuf[errorByteThree] - (1u<<errorBitThree);
uint32_t tmpCrc;
if(0 == (tmpCrc = gnua::crc(faultBuf, faultBufLen))){
tripleRandomBitFlipFailNum++;
Modified: gearbox/trunk/submitted/gbxnovatelacfr/test/example.cmake.in
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/test/example.cmake.in 2008-10-19 13:04:44 UTC (rev 327)
+++ gearbox/trunk/submitted/gbxnovatelacfr/test/example.cmake.in 2008-10-20 10:24:39 UTC (rev 328)
@@ -1,3 +1,5 @@
+CMAKE_MINIMUM_REQUIRED (VERSION 2.4)
+
PROJECT( gbxnovatelacfr_example )
INCLUDE_DIRECTORIES( @CMAKE_INSTALL_PREFIX@/include/gearbox )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rus...@us...> - 2008-10-19 13:04:52
|
Revision: 327
http://gearbox.svn.sourceforge.net/gearbox/?rev=327&view=rev
Author: russo2503v
Date: 2008-10-19 13:04:44 +0000 (Sun, 19 Oct 2008)
Log Message:
-----------
fixing conversion warnings
Modified Paths:
--------------
gearbox/trunk/src/gbxgarminacfr/nmea.cpp
gearbox/trunk/src/gbxutilacfr/test/mathtest.cpp
Modified: gearbox/trunk/src/gbxgarminacfr/nmea.cpp
===================================================================
--- gearbox/trunk/src/gbxgarminacfr/nmea.cpp 2008-10-16 08:57:34 UTC (rev 326)
+++ gearbox/trunk/src/gbxgarminacfr/nmea.cpp 2008-10-19 13:04:44 UTC (rev 327)
@@ -130,8 +130,8 @@
//save the high and low bytes of the checksum
//Make sure they are in upper case!
- chksum_HIB = toupper(*(++ptr));
- chksum_LOB = toupper(*(ptr + 1));
+ chksum_HIB = (char)toupper(*(++ptr));
+ chksum_LOB = (char)toupper(*(ptr + 1));
//invalidate the existing checksum
@@ -189,6 +189,10 @@
break;
}
+ // alexm: gcc-4.3 is very strict with the next line.
+ // not sure what to do about it yet.
+ // http://gcc.gnu.org/ml/gcc/2008-05/msg00363.html
+
// Keep the running XOR total
chkRunning ^= nextChar;
}
Modified: gearbox/trunk/src/gbxutilacfr/test/mathtest.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/test/mathtest.cpp 2008-10-16 08:57:34 UTC (rev 326)
+++ gearbox/trunk/src/gbxutilacfr/test/mathtest.cpp 2008-10-19 13:04:44 UTC (rev 327)
@@ -27,27 +27,27 @@
{
T angle;
- angle = -M_PI;
+ angle = (T)(-M_PI);
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
- angle = -M_PI+EPS;
+ angle = -(T)M_PI + (T)EPS;
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
- angle = -M_PI-EPS;
+ angle = -(T)M_PI - (T)EPS;
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
- angle = M_PI;
+ angle = (T)M_PI;
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
- angle = M_PI+EPS;
+ angle = (T)M_PI + (T)EPS;
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
- angle = M_PI-EPS;
+ angle = (T)M_PI - (T)EPS;
NORMALISE_ANGLE(angle);
assert( angle >= -M_PI && angle < M_PI );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2008-10-16 09:27:23
|
Revision: 326
http://gearbox.svn.sourceforge.net/gearbox/?rev=326&view=rev
Author: borax00
Date: 2008-10-16 08:57:34 +0000 (Thu, 16 Oct 2008)
Log Message:
-----------
fixed warn.
Modified Paths:
--------------
gearbox/trunk/src/gbxsickacfr/sickdefines.h
Modified: gearbox/trunk/src/gbxsickacfr/sickdefines.h
===================================================================
--- gearbox/trunk/src/gbxsickacfr/sickdefines.h 2008-10-16 06:14:30 UTC (rev 325)
+++ gearbox/trunk/src/gbxsickacfr/sickdefines.h 2008-10-16 08:57:34 UTC (rev 326)
@@ -65,7 +65,7 @@
//
// Acknowledgement types
//
- inline uChar ack( uChar command ) { return command + 0x80; }
+ inline uChar ack( uChar command ) { return (uChar)(command + 0x80); }
// Need to do this so they can be used in constant expressions (eg in switch stmts)
const uChar ACK_INIT_AND_RESET = CMD_INIT_AND_RESET + 0x80;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2008-10-16 06:14:35
|
Revision: 325
http://gearbox.svn.sourceforge.net/gearbox/?rev=325&view=rev
Author: borax00
Date: 2008-10-16 06:14:30 +0000 (Thu, 16 Oct 2008)
Log Message:
-----------
allowed different levels for trivialTracer.
Modified Paths:
--------------
gearbox/trunk/src/gbxgarminacfr/test/test.cpp
gearbox/trunk/src/gbxsickacfr/test/test.cpp
gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp
gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp
gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp
gearbox/trunk/src/gbxutilacfr/trivialtracer.h
Modified: gearbox/trunk/src/gbxgarminacfr/test/test.cpp
===================================================================
--- gearbox/trunk/src/gbxgarminacfr/test/test.cpp 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxgarminacfr/test/test.cpp 2008-10-16 06:14:30 UTC (rev 325)
@@ -66,9 +66,9 @@
cout << "Using configuration: " << config.toString() << endl;
// Instantiate objects to handle messages from the driver
- bool debug = true;
+ bool debug = 5;
if ( quiet )
- debug = false;
+ debug = 0;
gbxutilacfr::TrivialTracer tracer( debug );
gbxutilacfr::TrivialStatus status( tracer );
Modified: gearbox/trunk/src/gbxsickacfr/test/test.cpp
===================================================================
--- gearbox/trunk/src/gbxsickacfr/test/test.cpp 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxsickacfr/test/test.cpp 2008-10-16 06:14:30 UTC (rev 325)
@@ -31,7 +31,7 @@
int opt;
int baud = 38400;
string port = "/dev/ttyS0";
- bool debug = false;
+ bool debug = 0;
bool showScan = false;
// Get some options from the command line
@@ -46,7 +46,7 @@
baud = atoi( optarg );
break;
case 'v':
- debug = true;
+ debug = 5;
break;
case 's':
showScan = true;
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/longtest.cpp 2008-10-16 06:14:30 UTC (rev 325)
@@ -8,7 +8,7 @@
{
int opt;
std::string port = "/dev/ttyS0";
- bool debug = false;
+ int debug = 0;
// Get some options from the command line
while ((opt = getopt(argc, argv, "p:v")) != -1)
@@ -19,7 +19,7 @@
port = optarg;
break;
case 'v':
- debug = true;
+ debug = 5;
break;
default:
cout << "Usage: " << argv[0] << " [-p port] [-v(erbose)]" << endl
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/test/shorttest.cpp 2008-10-16 06:14:30 UTC (rev 325)
@@ -8,7 +8,7 @@
{
int opt;
std::string port = "/dev/ttyS0";
- bool debug = false;
+ int debug = 0;
// Get some options from the command line
while ((opt = getopt(argc, argv, "p:v")) != -1)
@@ -19,7 +19,7 @@
port = optarg;
break;
case 'v':
- debug = true;
+ debug = 5;
break;
default:
cout << "Usage: " << argv[0] << " [-p port] [-v(erbose)]" << endl
Modified: gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxutilacfr/trivialtracer.cpp 2008-10-16 06:14:30 UTC (rev 325)
@@ -10,17 +10,18 @@
#include "trivialtracer.h"
#include <iostream>
+#include <assert.h>
using namespace std;
namespace gbxutilacfr {
-TrivialTracer::TrivialTracer( bool debug, bool info, bool warn, bool error ) :
- debug_(debug),
- info_(info),
- warn_(warn),
- error_(error)
+TrivialTracer::TrivialTracer( int debug, int info, int warn, int error )
{
+ traceLevels_[Tracer::InfoTrace] = info;
+ traceLevels_[Tracer::WarningTrace] = warn;
+ traceLevels_[Tracer::ErrorTrace] = error;
+ traceLevels_[Tracer::DebugTrace] = debug;
}
void
@@ -32,35 +33,36 @@
void
TrivialTracer::info( const std::string &message, int level )
{
- if ( info_ )
+ if ( traceLevels_[Tracer::InfoTrace] >= level )
cout << "info: " << message << endl;
}
void
TrivialTracer::warning( const std::string &message, int level )
{
- if ( warn_ )
+ if ( traceLevels_[Tracer::WarningTrace] >= level )
cout << "warn: " << message << endl;
}
void
TrivialTracer::error( const std::string &message, int level )
{
- if ( error_ )
+ if ( traceLevels_[Tracer::ErrorTrace] >= level )
cout << "error: " << message << endl;
}
void
TrivialTracer::debug( const std::string &message, int level )
{
- if ( debug_ )
+ if ( traceLevels_[Tracer::DebugTrace] >= level )
cout << "debug: " << message << endl;
}
int
TrivialTracer::verbosity( TraceType traceType, DestinationType destType ) const
{
- return 10;
+ assert( traceType >= 0 && traceType <= Tracer::NumberOfTraceTypes );
+ return traceLevels_[traceType];
}
}
Modified: gearbox/trunk/src/gbxutilacfr/trivialtracer.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/trivialtracer.h 2008-10-16 05:24:14 UTC (rev 324)
+++ gearbox/trunk/src/gbxutilacfr/trivialtracer.h 2008-10-16 06:14:30 UTC (rev 325)
@@ -23,8 +23,15 @@
class TrivialTracer : public Tracer
{
public:
- TrivialTracer( bool debug=false, bool info=true, bool warn=true, bool error=true );
+ //!
+ //! Integers specify the tracing level: we'll print out all level at or below this.
+ //!
+ TrivialTracer( int debug=0,
+ int info=9,
+ int warn=9,
+ int error=9 );
+
virtual void print( const std::string &message );
virtual void info( const std::string &message, int level=1 );
virtual void warning( const std::string &message, int level=1 );
@@ -33,10 +40,8 @@
virtual int verbosity( TraceType traceType, DestinationType destType ) const;
private:
- bool debug_;
- bool info_;
- bool warn_;
- bool error_;
+
+ int traceLevels_[Tracer::NumberOfTraceTypes];
};
} // namespace
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2008-10-16 05:24:28
|
Revision: 324
http://gearbox.svn.sourceforge.net/gearbox/?rev=324&view=rev
Author: borax00
Date: 2008-10-16 05:24:14 +0000 (Thu, 16 Oct 2008)
Log Message:
-----------
added -Wconversion
Modified Paths:
--------------
gearbox/trunk/cmake/UseBasicRules.cmake
Modified: gearbox/trunk/cmake/UseBasicRules.cmake
===================================================================
--- gearbox/trunk/cmake/UseBasicRules.cmake 2008-10-15 09:10:21 UTC (rev 323)
+++ gearbox/trunk/cmake/UseBasicRules.cmake 2008-10-16 05:24:14 UTC (rev 324)
@@ -16,7 +16,7 @@
# Platform-specific compiler and linker flags
#
IF( NOT GBX_OS_WIN )
- ADD_DEFINITIONS( "-Wall" )
+ ADD_DEFINITIONS( "-Wall -Wconversion" )
ELSE ( NOT GBX_OS_WIN )
ADD_DEFINITIONS( "-Wall -D_CRT_SECURE_NO_DEPRECATE" )
ENDIF( NOT GBX_OS_WIN )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-10-15 09:10:32
|
Revision: 323
http://gearbox.svn.sourceforge.net/gearbox/?rev=323&view=rev
Author: gbiggs
Date: 2008-10-15 09:10:21 +0000 (Wed, 15 Oct 2008)
Log Message:
-----------
Added support for ReadUntil and ReadLine (char* version) to UDPPort.
Modified Paths:
--------------
gearbox/trunk/src/flexiport/tcpport.cpp
gearbox/trunk/src/flexiport/test/udp_example.cpp
gearbox/trunk/src/flexiport/udpport.cpp
gearbox/trunk/src/flexiport/udpport.h
Modified: gearbox/trunk/src/flexiport/tcpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-15 07:03:32 UTC (rev 322)
+++ gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-15 09:10:21 UTC (rev 323)
@@ -296,10 +296,10 @@
{
#if defined (WIN32)
numReceived = recv (_sock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
- count, 0); // No MSG_WAITALL on older versions of visual c, it seems
+ count - receivedBytes, 0); // No MSG_WAITALL on older versions of visual c, it seems
#else
numReceived = recv (_sock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
- count, MSG_WAITALL);
+ count - receivedBytes, MSG_WAITALL);
#endif
if (_debug >= 2)
cerr << "TCPPort::" << __func__ << "() Received " << numReceived << " bytes" << endl;
Modified: gearbox/trunk/src/flexiport/test/udp_example.cpp
===================================================================
--- gearbox/trunk/src/flexiport/test/udp_example.cpp 2008-10-15 07:03:32 UTC (rev 322)
+++ gearbox/trunk/src/flexiport/test/udp_example.cpp 2008-10-15 09:10:21 UTC (rev 323)
@@ -81,6 +81,10 @@
SLEEP (5);
cout << "Client sending 'Probably message #3.'" << endl;
port->WriteString ("Probably message #3.");
+ SLEEP (5);
+ cout << "Client sending 'Probably message #4\\n'" << endl;
+ char charMessage2[] = "Probably message #4\n";
+ port->Write (charMessage2, strlen (charMessage2) + 1);
cout << "Client waiting for parting message." << endl;
port->ReadString (stringMessage);
cout << "Client got parting message: \"" << stringMessage << '"' << endl;
@@ -131,6 +135,15 @@
cout << "Test failed." << endl;
return -1;
}
+ cout << "Server testing ReadUntil()" << endl;
+ int bytesReceived;
+ bytesReceived = port->ReadUntil (charBuffer, 32, 'e');
+ cout << "Server received \"" << charBuffer << "\" (" << bytesReceived << " bytes)" << endl;
+ if (strncmp (charBuffer, "Probably message #4\n", 20) != 0)
+ {
+ cout << "Test failed." << endl;
+ return -1;
+ }
cout << "Server sending back to client" << endl;
port->WriteString ("So long, and thanks for all the text.");
SLEEP (5);
Modified: gearbox/trunk/src/flexiport/udpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/udpport.cpp 2008-10-15 07:03:32 UTC (rev 322)
+++ gearbox/trunk/src/flexiport/udpport.cpp 2008-10-15 09:10:21 UTC (rev 323)
@@ -262,10 +262,10 @@
{
#if defined (WIN32)
numReceived = recv (_recvSock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
- count, 0); // No MSG_WAITALL on older versions of visual c, it seems
+ count - receivedBytes, 0); // No MSG_WAITALL on older versions of visual c, it seems
#else
numReceived = recv (_recvSock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
- count, MSG_WAITALL);
+ count - receivedBytes, MSG_WAITALL);
#endif
if (_debug >= 2)
cerr << "UDPPort::" << __func__ << "() Received " << numReceived << " bytes" << endl;
@@ -314,36 +314,86 @@
ssize_t UDPPort::ReadUntil (void * const buffer, size_t count, uint8_t terminator)
{
- throw PortException (string ("UDPPort::") + __func__ +
- string ("() This function does not work for datagram-oriented protocols."));
- return 0;
+ // For a datagram protocol, any read will remove the entire datagram from the socket buffer, no
+ // matter how much we actually ask for (although we will still get the amount we asked for in
+ // out buffer). This means we cannot read 1 byte at a time, because we would only get the first
+ // byte of each datagram. However, since reading any of a datagram removes the whole lot, we
+ // can just keep reading as much as possible until we see the terminator somewhere in a received
+ // chunk of data.
+ // This will be fixed if static buffers are introduced.
+
+ size_t numRead = 0;
+
+ CheckPort (true);
+
+ if (_debug >= 2)
+ {
+ cerr << "UDPPort::" << __func__ << "() Reading until '" << terminator << "' or " <<
+ count << " bytes." << endl;
+ }
+ while (numRead < count)
+ {
+ ssize_t result = 0;
+ if ((result = Read (reinterpret_cast<void*> (&reinterpret_cast<char*> (buffer)[numRead]), count - numRead)) < 0)
+ return -1; // Timeout
+ else if (result == 0)
+ {
+ // No data received and didn't timeout, so must be in non-blocking mode
+ if (IsBlocking ())
+ cerr << "UDPPort::" << __func__ << "() Got no data when in blocking mode." << endl;
+ return 0;
+ }
+ else
+ {
+ // Got data
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Read " << result << " bytes." << endl;
+ // Go through the data just received and check if any bytes match the terminator
+ bool foundTerminator = false;
+ // numKeep starts at 1 because we will keep at least one byte if the first is terminal
+ size_t numKeep = 1;
+ for (size_t ii = numRead; ii < numRead + result; ii++, numKeep++)
+ {
+ if (reinterpret_cast<uint8_t*>(buffer)[ii] == terminator)
+ {
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Got terminator character." << endl;
+ foundTerminator = true;
+ // We don't care about any data passed this point - as far as the application
+ // knows, it's as much garbage as real data, so don't waste time clearing it
+ break;
+ }
+ }
+ numRead += numKeep;
+ if (foundTerminator)
+ {
+ // Got the terminator so stop reading now
+ break;
+ }
+ }
+ }
+
+ return numRead;
}
ssize_t UDPPort::ReadStringUntil (std::string &buffer, char terminator)
{
throw PortException (string ("UDPPort::") + __func__ +
- string ("() This function does not work for datagram-oriented protocols."));
+ string ("() This function does not work for datagram protocols."));
return 0;
}
-ssize_t UDPPort::ReadLine (char * const buffer, size_t count)
-{
- throw PortException (string ("UDPPort::") + __func__ +
- string ("() This function does not work for datagram-oriented protocols."));
- return 0;
-}
-
ssize_t UDPPort::Skip (size_t count)
{
throw PortException (string ("UDPPort::") + __func__ +
- string ("() This function does not work for datagram-oriented protocols."));
+ string ("() This function does not work for datagram protocols."));
return 0;
}
ssize_t UDPPort::SkipUntil (uint8_t terminator, unsigned int count)
{
throw PortException (string ("UDPPort::") + __func__ +
- string ("() This function does not work for datagram-oriented protocols."));
+ string ("() This function does not work for datagram protocols."));
return 0;
}
Modified: gearbox/trunk/src/flexiport/udpport.h
===================================================================
--- gearbox/trunk/src/flexiport/udpport.h 2008-10-15 07:03:32 UTC (rev 322)
+++ gearbox/trunk/src/flexiport/udpport.h 2008-10-15 09:10:21 UTC (rev 323)
@@ -46,8 +46,8 @@
See the @ref Port class documentation for how to use the common API. Note that some parts of the API
do not apply due to the nature of the datagram-oriented protocol. Because each datagram is
individual and no merging is typically performed between datagrams, several flexiport functions do
-not work (they were designed for stream-oriented communications). These are @ref ReadUntil,
-@ref ReadStringUntil, @ref ReadLine, @ref Skip, and @ref SkipUntil. This will be (hopefully) be
+not work (they were designed for stream-oriented communications). These are @ref ReadStringUntil,
+@ref ReadLine (std::string version), @ref Skip, and @ref SkipUntil. This will be (hopefully) be
fixed soon.
TODO: Add support for configuring the destination address based on the first data received, to allow
@@ -90,8 +90,6 @@
ssize_t ReadUntil (void * const buffer, size_t count, uint8_t terminator);
/// @brief Read a string until the specified termination character is received.
ssize_t ReadStringUntil (std::string &buffer, char terminator);
- /// @brief Read a new-line terminated string of data.
- ssize_t ReadLine (char * const buffer, size_t count);
/// @brief Dump data until the specified number of bytes have been read.
ssize_t Skip (size_t count);
/** @brief Read and dump data until the specified termination character has been seen @ref
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-10-15 07:03:53
|
Revision: 322
http://gearbox.svn.sourceforge.net/gearbox/?rev=322&view=rev
Author: gbiggs
Date: 2008-10-15 07:03:32 +0000 (Wed, 15 Oct 2008)
Log Message:
-----------
Performance improvements
Modified Paths:
--------------
gearbox/trunk/src/flexiport/tcpport.cpp
gearbox/trunk/src/flexiport/test/tcp_example.cpp
gearbox/trunk/src/flexiport/test/udp_example.cpp
gearbox/trunk/src/flexiport/udpport.cpp
gearbox/trunk/src/flexiport/udpport.h
Modified: gearbox/trunk/src/flexiport/tcpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-15 05:54:06 UTC (rev 321)
+++ gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-15 07:03:32 UTC (rev 322)
@@ -832,7 +832,13 @@
TCPPort::WaitStatus TCPPort::WaitForDataOrTimeout (void)
{
if (IsDataAvailable ())
+ {
+ if (_debug >= 2)
+ cerr << "TCPPort::" << __func__ << "() Found data available immediately." << endl;
return DATA_AVAILABLE;
+ }
+ if (_debug >= 2)
+ cerr << "TCPPort::" << __func__ << "() No data available immediately, will wait." << endl;
fd_set fdSet;
struct timeval tv, *tvPtr = NULL;
@@ -868,7 +874,11 @@
// Checks if data is available right now
bool TCPPort::IsDataAvailable (void)
{
- // First peek at the buffer to see if there is anything waiting
+ if (_debug >= 3)
+ cerr << "TCPPort::" << __func__ << "() Checking if data is available immediately." << endl;
+
+ // First peek at the buffer to see if there is anything waiting. For an infinite timeout,
+ // this will block indefinitely until we get data.
char buffer;
ssize_t receivedBytes = 0;
#if defined (WIN32)
@@ -880,7 +890,7 @@
{
if (_debug >= 3)
cerr << "TCPPort::" << __func__ << "() Found data waiting." << endl;
- return DATA_AVAILABLE;
+ return true;
}
else if (receivedBytes < 0)
{
Modified: gearbox/trunk/src/flexiport/test/tcp_example.cpp
===================================================================
--- gearbox/trunk/src/flexiport/test/tcp_example.cpp 2008-10-15 05:54:06 UTC (rev 321)
+++ gearbox/trunk/src/flexiport/test/tcp_example.cpp 2008-10-15 07:03:32 UTC (rev 322)
@@ -4,17 +4,17 @@
* Copyright (c) 2008 Geoffrey Biggs
*
* flexiport flexible hardware data communications library.
- *
- * This distribution is licensed to you under the terms described in the LICENSE file included in
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
* this distribution.
*
* This work is a product of the National Institute of Advanced Industrial Science and Technology,
* Japan. Registration number: H20PRO-881
- *
+ *
* This file is part of flexiport.
*
* flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@@ -94,7 +94,7 @@
port->Write (charMessage3, strlen (charMessage3) + 1);
cout << "Client waiting for parting message." << endl;
port->ReadString (stringMessage);
- cout << "Client got parting message: \"" << stringMessage << '"' << endl;
+ cout << "Client got parting message: \"" << stringMessage << '"' << endl;
cout << "Client done." << endl;
return 0;
Modified: gearbox/trunk/src/flexiport/test/udp_example.cpp
===================================================================
--- gearbox/trunk/src/flexiport/test/udp_example.cpp 2008-10-15 05:54:06 UTC (rev 321)
+++ gearbox/trunk/src/flexiport/test/udp_example.cpp 2008-10-15 07:03:32 UTC (rev 322)
@@ -112,17 +112,6 @@
cout << "Test failed." << endl;
return -1;
}
-// cout << "Server testing ReadStringUntil()" << endl;
-// port->ReadStringUntil (stringBuffer, '\n');
-// cout << "Server received \"" << stringBuffer << '"' << endl;
-// if (stringBuffer != "Message #2\n")
-// {
-// cout << "Test failed." << endl;
-// return -1;
-// }
-// cout << "Server has " << port->BytesAvailable () << " bytes available immediatly." << endl;
-// cout << "Server clearing the trailing null byte from that last message." << endl;
-// port->Read (charBuffer, 1);
int bytesWaiting = port->BytesAvailableWait ();
cout << "Server has " << bytesWaiting << " bytes available after waiting." << endl;
cout << "Server testing ReadFull()" << endl;
@@ -133,16 +122,6 @@
cout << "Test failed." << endl;
return -1;
}
-// cout << "Server testing ReadUntil()" << endl;
-// port->ReadUntil (charBuffer, 32, '\n');
-// cout << "Server received \"" << charBuffer << '"' << endl;
-// if (strncmp (charBuffer, "Probably message #4\n", 20) != 0)
-// {
-// cout << "Test failed." << endl;
-// return -1;
-// }
-// cout << "Server clearing the trailing null byte from that last message." << endl;
-// port->Read (charBuffer, 1);
cout << "Server testing Read()" << endl;
memset (charBuffer, 0, sizeof (char) * 32);
port->Read (charBuffer, 32);
@@ -152,14 +131,6 @@
cout << "Test failed." << endl;
return -1;
}
-// cout << "Server testing ReadLine()" << endl;
-// port->ReadLine (stringBuffer);
-// cout << "Server received \"" << stringBuffer << '"' << endl;
-// if (stringBuffer != "Finally, message #6\n")
-// {
-// cout << "Test failed." << endl;
-// return -1;
-// }
cout << "Server sending back to client" << endl;
port->WriteString ("So long, and thanks for all the text.");
SLEEP (5);
Modified: gearbox/trunk/src/flexiport/udpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/udpport.cpp 2008-10-15 05:54:06 UTC (rev 321)
+++ gearbox/trunk/src/flexiport/udpport.cpp 2008-10-15 07:03:32 UTC (rev 322)
@@ -145,7 +145,7 @@
OpenSender ();
OpenReceiver ();
- SetPortBlockingFlag ();
+ SetSocketBlockingFlag ();
_open = true;
if (_debug >= 2)
@@ -178,16 +178,38 @@
if (_debug >= 2)
cerr << "UDPPort::" << __func__ << "() Going to read " << count << " bytes" << endl;
- if (_timeout._sec != -1)
+ if (_timeout._sec == -1)
{
- if (WaitForDataOrTimeout () == TIMED_OUT)
- return -1;
+ // Socket is blocking, so just read
+#if defined (WIN32)
+ receivedBytes = recv (_recvSock, reinterpret_cast<char*> (buffer), count, 0);
+#else
+ receivedBytes = recv (_recvSock, buffer, count, 0);
+#endif
}
+ else
+ {
+ // Socket is non-blocking, so try to read, see if we get any data (if there is none, this
+ // will return immediately, and is much faster than ioctl() and select() calls)
#if defined (WIN32)
- receivedBytes = recv (_recvSock, reinterpret_cast<char*> (buffer), count, 0);
+ receivedBytes = recv (_recvSock, reinterpret_cast<char*> (buffer), count, 0);
#else
- receivedBytes = recv (_recvSock, buffer, count, 0);
+ receivedBytes = recv (_recvSock, buffer, count, 0);
#endif
+ // Check if that call "timed out"
+ if (receivedBytes < 0 && ErrNo () == ERRNO_EAGAIN)
+ {
+ // No data was available, so wait for data or timeout, then read if data is available
+ if (WaitForDataOrTimeout () == TIMED_OUT)
+ return -1;
+#if defined (WIN32)
+ receivedBytes = recv (_recvSock, reinterpret_cast<char*> (buffer), count, 0);
+#else
+ receivedBytes = recv (_recvSock, buffer, count, 0);
+#endif
+ }
+ // If first call doesn't return a timeout, fall through to the result/error checking below
+ }
if (_debug >= 2)
cerr << "UDPPort::" << __func__ << "() Read " << receivedBytes << " bytes" << endl;
@@ -333,9 +355,6 @@
CheckPort (true);
- if (!IsDataAvailable ())
- return 0;
-
#if defined (WIN32)
unsigned long bytesAvailable = 0;
if (ioctlsocket (_recvSock, FIONREAD, &bytesAvailable) < 0)
@@ -513,7 +532,7 @@
void UDPPort::SetTimeout (Timeout timeout)
{
_timeout = timeout;
- SetPortBlockingFlag ();
+ SetSocketBlockingFlag ();
}
void UDPPort::SetCanRead (bool canRead)
@@ -847,6 +866,15 @@
// Checks if data is available, waiting for the timeout if none is available immediatly
UDPPort::WaitStatus UDPPort::WaitForDataOrTimeout (void)
{
+ if (IsDataAvailable ())
+ {
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Found data available immediately." << endl;
+ return DATA_AVAILABLE;
+ }
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() No data available immediately, will wait." << endl;
+
fd_set fdSet;
struct timeval tv, *tvPtr = NULL;
@@ -868,46 +896,65 @@
}
else if (result == 0)
{
- if (_debug >= 3)
+ if (_debug >= 2)
cerr << "UDPPort::" << __func__ << "() Timed out" << endl;
// Time out
return TIMED_OUT;
}
if (_debug >= 2)
- cerr << "UDPPort::" << __func__ << "() Found data waiting" << endl;
+ cerr << "UDPPort::" << __func__ << "() Found data after waiting" << endl;
return DATA_AVAILABLE;
}
// Checks if data is available right now
bool UDPPort::IsDataAvailable (void)
{
- fd_set fdSet;
- struct timeval tv;
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Checking if data is available immediately." << endl;
- FD_ZERO (&fdSet);
- FD_SET (_recvSock, &fdSet);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- int result = select (_recvSock + 1, &fdSet, NULL, NULL, &tv);
-
- if (result < 0)
+ // First peek at the buffer to see if there is anything waiting
+ char buffer;
+ ssize_t receivedBytes = 0;
+#if defined (WIN32)
+ receivedBytes = recv (_recvSock, &buffer, 1, MSG_PEEK);
+#else
+ receivedBytes = recv (_recvSock, reinterpret_cast<void*> (&buffer), 1, MSG_PEEK);
+#endif
+ if (receivedBytes > 0)
{
- stringstream ss;
- ss << "UDPPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
- StrError (ErrNo ());
- throw PortException (ss.str ());
+ if (_debug >= 3)
+ cerr << "TCPPort::" << __func__ << "() Found data waiting." << endl;
+ return DATA_AVAILABLE;
}
- else if (result == 0)
+ else if (receivedBytes < 0)
{
- if (_debug >= 3)
- cerr << "UDPPort::" << __func__ << "() Found no data waiting" << endl;
- // No data
- return false;
+ if (ErrNo () != ERRNO_EAGAIN)
+ {
+ // General error
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ // Else no data available yet
}
+ else // receivedBytes == 0
+ {
+ // Peer disconnected cleanly, do the same at this end
+ if (_debug >= 1)
+ cerr << "TCPPort::" << __func__ << "() Peer disconnected cleanly." << endl;
+ Close ();
+ if (_alwaysOpen)
+ {
+ if (_debug >= 1)
+ cerr << "TCPPort::" << __func__ << "() Trying to reconnect." << endl;
+ Open ();
+ }
+ // Fall through to return no data
+ }
if (_debug >= 3)
- cerr << "UDPPort::" << __func__ << "() Found data waiting" << endl;
- return true;
+ cerr << "TCPPort::" << __func__ << "() Found no data waiting." << endl;
+ return false;
}
// Checks it he port can be written to, waiting for the timeout if it can't be written immediatly
@@ -957,7 +1004,7 @@
throw PortException ("Cannot write to read-only port.");
}
-void UDPPort::SetPortBlockingFlag (void)
+void UDPPort::SetSocketBlockingFlag (void)
{
if (_timeout._sec == -1)
{
@@ -985,35 +1032,35 @@
int flags;
// Receive socket
- if ((flags = fcntl (_recvSock, F_GETFD)) < 0)
+ if ((flags = fcntl (_recvSock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_GETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_GETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
flags &= ~O_NONBLOCK;
- if (fcntl (_recvSock, F_SETFD, flags) < 0)
+ if (fcntl (_recvSock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_SETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_SETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
// Send socket
- if ((flags = fcntl (_sendSock, F_GETFD)) < 0)
+ if ((flags = fcntl (_sendSock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
flags &= ~O_NONBLOCK;
- if (fcntl (_sendSock, F_SETFD, flags) < 0)
+ if (fcntl (_sendSock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -1045,35 +1092,35 @@
int flags;
// Receive socket
- if ((flags = fcntl (_recvSock, F_GETFD)) < 0)
+ if ((flags = fcntl (_recvSock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ ss << "UDPPort::" << __func__ << "() fcntl(F_GETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
flags |= O_NONBLOCK;
- if (fcntl (_recvSock, F_SETFD, flags) < 0)
+ if (fcntl (_recvSock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ ss << "UDPPort::" << __func__ << "() fcntl(F_SETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
// Send socket
- if ((flags = fcntl (_sendSock, F_GETFD)) < 0)
+ if ((flags = fcntl (_sendSock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
flags |= O_NONBLOCK;
- if (fcntl (_sendSock, F_SETFD, flags) < 0)
+ if (fcntl (_sendSock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFD) error: (" << ErrNo () <<
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFL) error: (" << ErrNo () <<
") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
Modified: gearbox/trunk/src/flexiport/udpport.h
===================================================================
--- gearbox/trunk/src/flexiport/udpport.h 2008-10-15 05:54:06 UTC (rev 321)
+++ gearbox/trunk/src/flexiport/udpport.h 2008-10-15 07:03:32 UTC (rev 322)
@@ -140,7 +140,7 @@
WaitStatus WaitForDataOrTimeout (void);
bool IsDataAvailable (void);
WaitStatus WaitForWritableOrTimeout (void);
- void SetPortBlockingFlag (void);
+ void SetSocketBlockingFlag (void);
};
} // namespace flexiport
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-10-15 05:54:18
|
Revision: 321
http://gearbox.svn.sourceforge.net/gearbox/?rev=321&view=rev
Author: gbiggs
Date: 2008-10-15 05:54:06 +0000 (Wed, 15 Oct 2008)
Log Message:
-----------
Performance improvements
Modified Paths:
--------------
gearbox/trunk/src/flexiport/port.cpp
gearbox/trunk/src/flexiport/serialport.cpp
gearbox/trunk/src/flexiport/serialport.h
gearbox/trunk/src/flexiport/tcpport.cpp
gearbox/trunk/src/flexiport/tcpport.h
Modified: gearbox/trunk/src/flexiport/port.cpp
===================================================================
--- gearbox/trunk/src/flexiport/port.cpp 2008-10-14 05:29:27 UTC (rev 320)
+++ gearbox/trunk/src/flexiport/port.cpp 2008-10-15 05:54:06 UTC (rev 321)
@@ -82,7 +82,7 @@
if (bytesAvailable < 0)
return -1; // Timeout
else if (bytesAvailable == 0)
- return 0; // Nothing available
+ return -1; // Nothing available
if (_debug >= 2)
{
@@ -90,7 +90,7 @@
" bytes waiting to be read into a string" << endl;
}
- // Read this many characters into a string - include space for a NULL incase one doesn't
+ // Read this many characters into a string - include space for a NULL in case one doesn't
// come in the transmitted data.
charBuffer = new char[bytesAvailable + 1];
if ((numRead = Read (charBuffer, bytesAvailable)) < 0)
Modified: gearbox/trunk/src/flexiport/serialport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/serialport.cpp 2008-10-14 05:29:27 UTC (rev 320)
+++ gearbox/trunk/src/flexiport/serialport.cpp 2008-10-15 05:54:06 UTC (rev 321)
@@ -4,17 +4,17 @@
* Copyright (c) 2008 Geoffrey Biggs
*
* flexiport flexible hardware data communications library.
- *
- * This distribution is licensed to you under the terms described in the LICENSE file included in
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
* this distribution.
*
* This work is a product of the National Institute of Advanced Industrial Science and Technology,
* Japan. Registration number: H20PRO-881
- *
+ *
* This file is part of flexiport.
*
* flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@@ -293,7 +293,7 @@
StrError (ErrNo ());
throw PortException (ss.str ());
}
-
+
SetPortTimeout ();
#else
int flags = 0;
@@ -306,14 +306,14 @@
flags |= O_NOCTTY;
- // For simplicity set the port to non-blocking and use select() to wait for data based on the
+ // For simplicity set the port to non-blocking and use select() to wait for data based on the
// timeout.
flags |= O_NONBLOCK;
if ((_fd = open (_device.c_str (), flags)) < 0)
{
stringstream ss;
- ss << "Failed to open device " << _device << " with error: (" << ErrNo () << ") " <<
+ ss << "Failed to open device " << _device << " with error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -378,10 +378,28 @@
}
#else
ssize_t receivedBytes = 0;
- if (WaitForDataOrTimeout () == TIMED_OUT)
- return -1;
- receivedBytes = read (_fd, buffer, count);
+ if (_timeout._sec == -1)
+ {
+ // Port is blocking, so just read
+ receivedBytes = read (_fd, buffer, count);
+ }
+ else
+ {
+ // Port is non-blocking, so try to read, see if we get any data (if there is none, this will
+ // return immediately, and is much faster than ioctl() and select() calls)
+ receivedBytes = read (_fd, buffer, count);
+ // Check if that call "timed out"
+ if (receivedBytes < 0 && ErrNo () == EAGAIN)
+ {
+ // No data was available, so wait for data or timeout, then read if data is available
+ if (WaitForDataOrTimeout () == TIMED_OUT)
+ return -1;
+ receivedBytes = read (_fd, buffer, count);
+ }
+ // If first call doesn't return a timeout, fall through to the result/error checking below
+ }
+
if (_debug >= 2)
cerr << "SerialPort::" << __func__ << "() Read " << receivedBytes << " bytes" << endl;
@@ -389,11 +407,11 @@
{
if (ErrNo () == EAGAIN)
return -1; // Timed out
- else
+ else
{
// General error
stringstream ss;
- ss << "SerialPort::" << __func__ << "() recv() error: (" <<
+ ss << "SerialPort::" << __func__ << "() read() error: (" <<
ErrNo () << ") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -427,11 +445,11 @@
if (_debug >= 2)
{
- cerr << "SerialPort::" << __func__ << "() Going to read until have " << count <<
+ cerr << "SerialPort::" << __func__ << "() Going to read until have " << count <<
" bytes" << endl;
}
- // Set the timeout to infinite blocking
+ // Set the port to infinite blocking
SetTimeout (Timeout (-1, 0));
// Keep calling Read() until count bytes have been received or a timeout
while (receivedBytes < count)
@@ -455,15 +473,15 @@
// Restore the timeout
SetTimeout (oldTimeout);
stringstream ss;
- ss << "SerialPort::" << __func__ << "() Port closed while trying to read " <<
+ ss << "SerialPort::" << __func__ << "() Port closed while trying to read " <<
count << " bytes";
throw PortException (ss.str ());
}
// If it is open we can keep going, but with a warning
if (_debug >= 1)
{
- cerr << "WARNING: SerialPort::" << __func__ <<
- " Port closed during ReadFull operation; data may be missing/corrupted." <<
+ cerr << "WARNING: SerialPort::" << __func__ <<
+ " Port closed during ReadFull operation; data may be missing/corrupted." <<
endl;
}
}
@@ -488,19 +506,16 @@
if (!ClearCommError (_fd, &errorType, &comStat))
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() ClearCommError() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() ClearCommError() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
bytesAvailable = comStat.cbInQue;
#else
- if (!IsDataAvailable ())
- return 0;
-
if (ioctl (_fd, FIONREAD, &bytesAvailable) < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -537,11 +552,13 @@
bytesAvailable = BytesAvailable ();
}
#else
+ // WaitForDataOrTimeout() will do an initial check to see if there is data available immediately
+ // and only select() if there isn't
if (WaitForDataOrTimeout () == TIMED_OUT)
{
if (_debug >= 2)
{
- cerr << "SerialPort::" << __func__ <<
+ cerr << "SerialPort::" << __func__ <<
" Timed out waiting for data to check bytes available" << endl;
}
if (IsBlocking ())
@@ -553,7 +570,7 @@
if (ioctl (_fd, FIONREAD, &bytesAvailable) < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -616,7 +633,7 @@
{
// General error
stringstream ss;
- ss << "SerialPort::" << __func__ << "() write() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() write() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -635,7 +652,7 @@
if (!PurgeComm (_fd, PURGE_RXCLEAR | PURGE_TXCLEAR))
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() PurgeComm() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() PurgeComm() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -643,7 +660,7 @@
if (tcflush (_fd, TCIOFLUSH) < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcflush() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcflush() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -656,7 +673,7 @@
if (!FlushFileBuffers (_fd))
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() FlushFileBuffers() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() FlushFileBuffers() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -664,7 +681,7 @@
if (tcdrain (_fd) < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcdrain() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcdrain() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -695,7 +712,7 @@
status << "Odd" << endl;
break;
default:
- throw PortException (string ("SerialPort::") + __func__ +
+ throw PortException (string ("SerialPort::") + __func__ +
string (" Unknown parity setting."));
break;
}
@@ -708,16 +725,14 @@
void SerialPort::SetTimeout (Timeout timeout)
{
_timeout = timeout;
-#if defined (WIN32)
SetPortTimeout ();
-#endif
}
void SerialPort::SetCanRead (bool canRead)
{
if (IsOpen ())
{
- throw PortException (string ("SerialPort::") + __func__ +
+ throw PortException (string ("SerialPort::") + __func__ +
string (" Cannot change read capability of an open port."));
}
_canRead = canRead;
@@ -727,7 +742,7 @@
{
if (IsOpen ())
{
- throw PortException (string ("SerialPort::") + __func__ +
+ throw PortException (string ("SerialPort::") + __func__ +
string (" Cannot change write capability of an open port."));
}
_canWrite = canWrite;
@@ -742,7 +757,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() GetCommState() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() GetCommState() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -753,7 +768,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() SetCommState() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() SetCommState() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -764,7 +779,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcgetattr() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcgetattr() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -772,7 +787,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() cfsetispeed() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() cfsetispeed() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -781,7 +796,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() cfsetospeed() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() cfsetospeed() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -789,7 +804,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcsetattr() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcsetattr() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -857,52 +872,14 @@
return false;
}
-// Checks if data is available right now
-bool SerialPort::IsDataAvailable (void)
-{
-#if defined (WIN32)
- if (BytesAvailable () <= 0)
- {
- // No data
- if (_debug >= 3)
- cerr << "SerialPort::" << __func__ << "() Found no data waiting" << endl;
- return false;
- }
-#else
- fd_set fdSet;
- struct timeval tv;
-
- FD_ZERO (&fdSet);
- FD_SET (_fd, &fdSet);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- int result = select (_fd + 1, &fdSet, NULL, NULL, &tv);
-
- if (result < 0)
- {
- stringstream ss;
- ss << "SerialPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
- StrError (ErrNo ());
- throw PortException (ss.str ());
- }
- else if (result == 0)
- {
- if (_debug >= 3)
- cerr << "SerialPort::" << __func__ << "() Found no data waiting" << endl;
- // No data
- return false;
- }
-#endif
- if (_debug >= 3)
- cerr << "SerialPort::" << __func__ << "() Found data waiting" << endl;
- return true;
-}
-
#if !defined (WIN32)
-// Checks if data is available, waiting for the timeout if none is available immediatly
+// Checks if data is available, waiting for the timeout if none is available immediately
SerialPort::WaitStatus SerialPort::WaitForDataOrTimeout (void)
{
+ // Check if there is data available immediately before spending time on a select() call
+ if (BytesAvailable () > 0)
+ return DATA_AVAILABLE;
+
fd_set fdSet;
struct timeval tv, *tvPtr = NULL;
@@ -918,7 +895,7 @@
if (result < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -934,7 +911,7 @@
return DATA_AVAILABLE;
}
-// Checks it he port can be written to, waiting for the timeout if it can't be written immediatly
+// Checks if the port can be written to, waiting for the timeout if it can't be written immediately
SerialPort::WaitStatus SerialPort::WaitForWritableOrTimeout (void)
{
fd_set fdSet;
@@ -952,7 +929,7 @@
if (result < 0)
{
stringstream ss;
- ss << "SerialPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -991,7 +968,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() GetCommState() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() GetCommState() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -1044,7 +1021,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() SetCommState() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() SetCommState() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -1055,7 +1032,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcgetattr() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcgetattr() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -1125,7 +1102,7 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() tcsetattr() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() tcsetattr() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -1134,9 +1111,9 @@
SetBaudRate (_baud);
}
-#if defined (WIN32)
void SerialPort::SetPortTimeout (void)
{
+#if defined (WIN32)
COMMTIMEOUTS timeouts;
if (_timeout._sec == -1)
@@ -1171,11 +1148,37 @@
{
Close ();
stringstream ss;
- ss << "SerialPort::" << __func__ << "() SetCommTimeouts() error: (" << ErrNo () << ") " <<
+ ss << "SerialPort::" << __func__ << "() SetCommTimeouts() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
+#else
+ int flags;
+ if ((flags = fcntl (_fd, F_GETFL)) < 0)
+ {
+ stringstream ss;
+ ss << "SerialPort::" << __func__ << "() fcntl(F_GETFL) error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ if (_timeout._sec == -1)
+ {
+ // Block forever
+ flags &= ~O_NONBLOCK;
+ }
+ else
+ {
+ // Non-blocking operation
+ flags |= O_NONBLOCK;
+ }
+ if (fcntl (_fd, F_SETFL, flags) < 0)
+ {
+ stringstream ss;
+ ss << "SerialPort::" << __func__ << "() fcntl(F_SETFL) error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#endif
}
-#endif
} // namespace flexiport
Modified: gearbox/trunk/src/flexiport/serialport.h
===================================================================
--- gearbox/trunk/src/flexiport/serialport.h 2008-10-14 05:29:27 UTC (rev 320)
+++ gearbox/trunk/src/flexiport/serialport.h 2008-10-15 05:54:06 UTC (rev 321)
@@ -4,17 +4,17 @@
* Copyright (c) 2008 Geoffrey Biggs
*
* flexiport flexible hardware data communications library.
- *
- * This distribution is licensed to you under the terms described in the LICENSE file included in
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
* this distribution.
*
* This work is a product of the National Institute of Advanced Industrial Science and Technology,
* Japan. Registration number: H20PRO-881
- *
+ *
* This file is part of flexiport.
*
* flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@@ -139,9 +139,7 @@
WaitStatus WaitForWritableOrTimeout (void);
#endif
void SetPortSettings (void);
-#if defined (WIN32)
void SetPortTimeout (void);
-#endif
};
} // namespace flexiport
Modified: gearbox/trunk/src/flexiport/tcpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-14 05:29:27 UTC (rev 320)
+++ gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-15 05:54:06 UTC (rev 321)
@@ -159,7 +159,7 @@
Connect ();
}
- SetPortBlockingFlag ();
+ SetSocketBlockingFlag ();
_open = true;
if (_debug >= 2)
cerr << "TCPPort::" << __func__ << "() Port is open" << endl;
@@ -212,16 +212,38 @@
if (_debug >= 2)
cerr << "TCPPort::" << __func__ << "() Going to read " << count << " bytes" << endl;
- if (_timeout._sec != -1)
+ if (_timeout._sec == -1)
{
- if (WaitForDataOrTimeout () == TIMED_OUT)
- return -1;
+ // Socket is blocking, so just read
+#if defined (WIN32)
+ receivedBytes = recv (_sock, reinterpret_cast<char*> (buffer), count, 0);
+#else
+ receivedBytes = recv (_sock, buffer, count, 0);
+#endif
}
+ else
+ {
+ // Socket is non-blocking, so try to read, see if we get any data (if there is none, this
+ // will return immediately, and is much faster than ioctl() and select() calls)
#if defined (WIN32)
- receivedBytes = recv (_sock, reinterpret_cast<char*> (buffer), count, 0);
+ receivedBytes = recv (_sock, reinterpret_cast<char*> (buffer), count, 0);
#else
- receivedBytes = recv (_sock, buffer, count, 0);
+ receivedBytes = recv (_sock, buffer, count, 0);
#endif
+ // Check if that call "timed out"
+ if (receivedBytes < 0 && ErrNo () == ERRNO_EAGAIN)
+ {
+ // No data was available, so wait for data or timeout, then read if data is available
+ if (WaitForDataOrTimeout () == TIMED_OUT)
+ return -1;
+#if defined (WIN32)
+ receivedBytes = recv (_sock, reinterpret_cast<char*> (buffer), count, 0);
+#else
+ receivedBytes = recv (_sock, buffer, count, 0);
+#endif
+ }
+ // If first call doesn't return a timeout, fall through to the result/error checking below
+ }
if (_debug >= 2)
cerr << "TCPPort::" << __func__ << "() Read " << receivedBytes << " bytes" << endl;
@@ -328,13 +350,11 @@
{
// TODO:
// MSG_PEEK is apparently bad on Windows so we should drain what we can into a local buffer
- // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599
+ // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599.
+ // Unless the buffer is static in size this will affect performance and make real-time not work.
CheckPort (true);
- if (!IsDataAvailable ())
- return 0;
-
#if defined (WIN32)
unsigned long bytesAvailable = 0;
if (ioctlsocket (_sock, FIONREAD, &bytesAvailable) < 0)
@@ -376,7 +396,8 @@
// TODO:
// MSG_PEEK is apparently bad on Windows so we should drain what we can into a local buffer
- // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599
+ // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599.
+ // Unless the buffer is static in size this will affect performance and make real-time not work.
#if defined (WIN32)
unsigned long bytesAvailable = 0;
if (ioctlsocket (_sock, FIONREAD, &bytesAvailable) < 0)
@@ -505,7 +526,7 @@
void TCPPort::SetTimeout (Timeout timeout)
{
_timeout = timeout;
- SetPortBlockingFlag ();
+ SetSocketBlockingFlag ();
}
void TCPPort::SetCanRead (bool canRead)
@@ -810,6 +831,9 @@
// Checks if data is available, waiting for the timeout if none is available immediatly
TCPPort::WaitStatus TCPPort::WaitForDataOrTimeout (void)
{
+ if (IsDataAvailable ())
+ return DATA_AVAILABLE;
+
fd_set fdSet;
struct timeval tv, *tvPtr = NULL;
@@ -831,46 +855,62 @@
}
else if (result == 0)
{
- if (_debug >= 3)
- cerr << "TCPPort::" << __func__ << "() Timed out" << endl;
+ if (_debug >= 2)
+ cerr << "TCPPort::" << __func__ << "() Timed out." << endl;
// Time out
return TIMED_OUT;
}
if (_debug >= 2)
- cerr << "TCPPort::" << __func__ << "() Found data waiting" << endl;
+ cerr << "TCPPort::" << __func__ << "() Found data waiting." << endl;
return DATA_AVAILABLE;
}
// Checks if data is available right now
bool TCPPort::IsDataAvailable (void)
{
- fd_set fdSet;
- struct timeval tv;
-
- FD_ZERO (&fdSet);
- FD_SET (_sock, &fdSet);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- int result = select (_sock + 1, &fdSet, NULL, NULL, &tv);
-
- if (result < 0)
+ // First peek at the buffer to see if there is anything waiting
+ char buffer;
+ ssize_t receivedBytes = 0;
+#if defined (WIN32)
+ receivedBytes = recv (_sock, &buffer, 1, MSG_PEEK);
+#else
+ receivedBytes = recv (_sock, reinterpret_cast<void*> (&buffer), 1, MSG_PEEK);
+#endif
+ if (receivedBytes > 0)
{
- stringstream ss;
- ss << "TCPPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
- StrError (ErrNo ());
- throw PortException (ss.str ());
+ if (_debug >= 3)
+ cerr << "TCPPort::" << __func__ << "() Found data waiting." << endl;
+ return DATA_AVAILABLE;
}
- else if (result == 0)
+ else if (receivedBytes < 0)
{
- if (_debug >= 3)
- cerr << "TCPPort::" << __func__ << "() Found no data waiting" << endl;
- // No data
- return false;
+ if (ErrNo () != ERRNO_EAGAIN)
+ {
+ // General error
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ // Else no data available yet
}
+ else // receivedBytes == 0
+ {
+ // Peer disconnected cleanly, do the same at this end
+ if (_debug >= 1)
+ cerr << "TCPPort::" << __func__ << "() Peer disconnected cleanly." << endl;
+ Close ();
+ if (_alwaysOpen)
+ {
+ if (_debug >= 1)
+ cerr << "TCPPort::" << __func__ << "() Trying to reconnect." << endl;
+ Open ();
+ }
+ // Fall through to return no data
+ }
if (_debug >= 3)
- cerr << "TCPPort::" << __func__ << "() Found data waiting" << endl;
- return true;
+ cerr << "TCPPort::" << __func__ << "() Found no data waiting." << endl;
+ return false;
}
// Checks it he port can be written to, waiting for the timeout if it can't be written immediatly
@@ -920,7 +960,7 @@
throw PortException ("Cannot write to read-only port.");
}
-void TCPPort::SetPortBlockingFlag (void)
+void TCPPort::SetSocketBlockingFlag (void)
{
if (_timeout._sec == -1)
{
@@ -936,18 +976,18 @@
}
#else
int flags;
- if ((flags = fcntl (_sock, F_GETFD)) < 0)
+ if ((flags = fcntl (_sock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_GETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
flags &= ~O_NONBLOCK;
- if (fcntl (_sock, F_SETFD, flags) < 0)
+ if (fcntl (_sock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_SETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -967,18 +1007,18 @@
}
#else
int flags;
- if ((flags = fcntl (_sock, F_GETFD)) < 0)
+ if ((flags = fcntl (_sock, F_GETFL)) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_GETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
flags |= O_NONBLOCK;
- if (fcntl (_sock, F_SETFD, flags) < 0)
+ if (fcntl (_sock, F_SETFL, flags) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_SETFL) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
Modified: gearbox/trunk/src/flexiport/tcpport.h
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.h 2008-10-14 05:29:27 UTC (rev 320)
+++ gearbox/trunk/src/flexiport/tcpport.h 2008-10-15 05:54:06 UTC (rev 321)
@@ -112,7 +112,7 @@
WaitStatus WaitForDataOrTimeout (void);
bool IsDataAvailable (void);
WaitStatus WaitForWritableOrTimeout (void);
- void SetPortBlockingFlag (void);
+ void SetSocketBlockingFlag (void);
};
} // namespace flexiport
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-10-14 05:29:36
|
Revision: 320
http://gearbox.svn.sourceforge.net/gearbox/?rev=320&view=rev
Author: gbiggs
Date: 2008-10-14 05:29:27 +0000 (Tue, 14 Oct 2008)
Log Message:
-----------
Moved definition of GBX_DEFAULT_LIB_TYPE
Modified Paths:
--------------
gearbox/trunk/cmake/TargetUtils.cmake
gearbox/trunk/cmake/internal/Setup.cmake
Modified: gearbox/trunk/cmake/TargetUtils.cmake
===================================================================
--- gearbox/trunk/cmake/TargetUtils.cmake 2008-10-14 02:53:40 UTC (rev 319)
+++ gearbox/trunk/cmake/TargetUtils.cmake 2008-10-14 05:29:27 UTC (rev 320)
@@ -1,4 +1,10 @@
#
+# Default library type (shared or static).
+#
+SET( GBX_DEFAULT_LIB_TYPE "SHARED" CACHE STRING "Default library type (SHARED or STATIC)" )
+MARK_AS_ADVANCED( GBX_DEFAULT_LIB_TYPE )
+
+#
# Executables should add themselves by calling 'GBX_ADD_EXECUTABLE'
# instead of 'ADD_EXECUTABLE' in CMakeLists.txt.
# Usage is the same as ADD_EXECUTABLE, all parameters are passed to ADD_EXECUTABLE.
Modified: gearbox/trunk/cmake/internal/Setup.cmake
===================================================================
--- gearbox/trunk/cmake/internal/Setup.cmake 2008-10-14 02:53:40 UTC (rev 319)
+++ gearbox/trunk/cmake/internal/Setup.cmake 2008-10-14 05:29:27 UTC (rev 320)
@@ -55,12 +55,6 @@
OPTION( GBX_BUILD_TESTS "Enables compilation of all tests" ON )
#
-# Default library type (shared or static).
-#
-SET( GBX_DEFAULT_LIB_TYPE "SHARED" CACHE STRING "Default library type (SHARED or STATIC)" )
-MARK_AS_ADVANCED( GBX_DEFAULT_LIB_TYPE )
-
-#
# Look for low-level C headers, write defines to config.h
#
INCLUDE( ${GBX_CMAKE_DIR}/WriteConfigH.cmake )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-10-14 02:53:59
|
Revision: 319
http://gearbox.svn.sourceforge.net/gearbox/?rev=319&view=rev
Author: gbiggs
Date: 2008-10-14 02:53:40 +0000 (Tue, 14 Oct 2008)
Log Message:
-----------
Added first version of UDP support to flexiport.
Modified Paths:
--------------
gearbox/trunk/src/flexiport/CMakeLists.txt
gearbox/trunk/src/flexiport/flexiport.cpp
gearbox/trunk/src/flexiport/flexiport_config.h.in
gearbox/trunk/src/flexiport/tcpport.cpp
gearbox/trunk/src/flexiport/tcpport.h
gearbox/trunk/src/flexiport/test/CMakeLists.txt
gearbox/trunk/src/flexiport/test/example.cmake.in
gearbox/trunk/src/flexiport/test/example.readme
Added Paths:
-----------
gearbox/trunk/src/flexiport/test/udp_example.cpp
gearbox/trunk/src/flexiport/udpport.cpp
gearbox/trunk/src/flexiport/udpport.h
Modified: gearbox/trunk/src/flexiport/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/CMakeLists.txt 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/CMakeLists.txt 2008-10-14 02:53:40 UTC (rev 319)
@@ -9,8 +9,9 @@
OPTION (FLEXIPORT_INCLUDE_SERIAL "Include the serial port in FlexiPort" ON)
OPTION (FLEXIPORT_INCLUDE_TCP "Include the TCP network port in FlexiPort" ON)
+ OPTION (FLEXIPORT_INCLUDE_UDP "Include the UDP network port in FlexiPort" ON)
OPTION (FLEXIPORT_INCLUDE_LOGGING "Include the log reader/writer ports in FlexiPort" ON)
- MARK_AS_ADVANCED (FLEXIPORT_INCLUDE_SERIAL FLEXIPORT_INCLUDE_TCP)
+ MARK_AS_ADVANCED (FLEXIPORT_INCLUDE_SERIAL FLEXIPORT_INCLUDE_TCP FLEXIPORT_INCLUDE_UDP)
IF (GBX_OS_QNX)
SET (CMAKE_REQUIRED_LIBRARIES socket)
@@ -33,6 +34,10 @@
SET (hdrs ${hdrs} tcpport.h)
SET (srcs ${srcs} tcpport.cpp)
ENDIF (FLEXIPORT_INCLUDE_TCP)
+ IF (FLEXIPORT_INCLUDE_UDP)
+ SET (hdrs ${hdrs} udpport.h)
+ SET (srcs ${srcs} udpport.cpp)
+ ENDIF (FLEXIPORT_INCLUDE_UDP)
IF (FLEXIPORT_INCLUDE_LOGGING)
SET (hdrs ${hdrs} logwriterport.h logreaderport.h)
SET (srcs ${srcs} logwriterport.cpp logreaderport.cpp logfile.cpp)
Modified: gearbox/trunk/src/flexiport/flexiport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/flexiport.cpp 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/flexiport.cpp 2008-10-14 02:53:40 UTC (rev 319)
@@ -29,6 +29,7 @@
#include "port.h"
#include "serialport.h"
#include "tcpport.h"
+#include "udpport.h"
#include "logwriterport.h"
#include "logreaderport.h"
#include "flexiport_config.h"
@@ -109,6 +110,10 @@
if (type == "tcp")
return new TCPPort (options);
#endif // FLEXIPORT_INCLUDE_TCP
+#ifdef FLEXIPORT_INCLUDE_UDP
+ if (type == "udp")
+ return new UDPPort (options);
+#endif // FLEXIPORT_INCLUDE_UDP
#ifdef FLEXIPORT_INCLUDE_LOGGING
if (type == "logreader")
Modified: gearbox/trunk/src/flexiport/flexiport_config.h.in
===================================================================
--- gearbox/trunk/src/flexiport/flexiport_config.h.in 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/flexiport_config.h.in 2008-10-14 02:53:40 UTC (rev 319)
@@ -2,5 +2,6 @@
#cmakedefine FLEXIPORT_INCLUDE_SERIAL 1
#cmakedefine FLEXIPORT_INCLUDE_TCP 1
+#cmakedefine FLEXIPORT_INCLUDE_UDP 1
#cmakedefine FLEXIPORT_INCLUDE_LOGGING 1
#cmakedefine FLEXIPORT_HAVE_GETADDRINFO 1
\ No newline at end of file
Modified: gearbox/trunk/src/flexiport/tcpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/tcpport.cpp 2008-10-14 02:53:40 UTC (rev 319)
@@ -4,17 +4,17 @@
* Copyright (c) 2008 Geoffrey Biggs
*
* flexiport flexible hardware data communications library.
- *
- * This distribution is licensed to you under the terms described in the LICENSE file included in
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
* this distribution.
*
* This work is a product of the National Institute of Advanced Industrial Science and Technology,
* Japan. Registration number: H20PRO-881
- *
+ *
* This file is part of flexiport.
*
* flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@@ -156,7 +156,7 @@
// Connect to the given address
if (_debug >= 1)
cerr << "TCPPort::" << __func__ << "() Connecting" << endl;
-
+
Connect ();
}
SetPortBlockingFlag ();
@@ -230,11 +230,11 @@
{
if (ErrNo () == ERRNO_EAGAIN)
return -1; // Timed out
- else
+ else
{
// General error
stringstream ss;
- ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -266,7 +266,7 @@
if (_debug >= 2)
{
- cerr << "TCPPort::" << __func__ << "() Going to read until have " <<
+ cerr << "TCPPort::" << __func__ << "() Going to read until have " <<
count << " bytes" << endl;
}
@@ -289,11 +289,11 @@
throw PortException (string ("TCPPort::") + __func__ +
string ("() recv() timed out, probably shouldn't happen."));
}
- else
+ else
{
// General error
stringstream ss;
- ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -351,7 +351,7 @@
if (_debug >= 2)
{
- cerr << "TCPPort::" << __func__ << "() Found " << bytesAvailable <<
+ cerr << "TCPPort::" << __func__ << "() Found " << bytesAvailable <<
" bytes available" << endl;
}
return bytesAvailable;
@@ -386,14 +386,14 @@
#endif
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
if (_debug >= 2)
{
- cerr << "TCPPort::" << __func__ << "() Found " << bytesAvailable <<
+ cerr << "TCPPort::" << __func__ << "() Found " << bytesAvailable <<
" bytes available after waiting" << endl;
}
return bytesAvailable;
@@ -436,7 +436,7 @@
{
// General error
stringstream ss;
- ss << "TCPPort::" << __func__ << "() send() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() send() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -470,7 +470,7 @@
if (numRead < 0 && ErrNo () != ERRNO_EAGAIN)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -556,44 +556,74 @@
{
Close (); // To make sure
- _sock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ // If getaddrinfo() is available, much less stuff needs to be hard-coded or copied around.
+#if defined (FLEXIPORT_HAVE_GETADDRINFO)
+ struct addrinfo *res = NULL, hints;
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ int errorCode;
+ ostringstream portSS;
+ portSS << _port;
+ if ((errorCode = getaddrinfo (_ip.c_str (), portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ Close ();
+ stringstream ss;
#if defined (WIN32)
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+
+ _sock = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
+#if defined (WIN32)
if (_sock == INVALID_SOCKET)
#else
if (_sock < 0)
#endif
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
- sockaddr_in sockAddr;
- memset (&sockAddr, 0, sizeof (sockAddr));
-#if defined (FLEXIPORT_HAVE_GETADDRINFO)
- struct addrinfo *res = NULL, hints;
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- int errorCode;
- if ((errorCode = getaddrinfo (_ip.c_str (), NULL, &hints, &res)) != 0)
+ if (_debug >= 1)
+ cerr << "TCPPort::" << __func__ << "() Connecting to " << _ip << ":" << _port << "." << endl;
+ if (connect (_sock, res->ai_addr, res->ai_addrlen) < 0)
{
Close ();
stringstream ss;
+ ss << "Failed to connect to " << _ip << ": (" << ErrNo () << ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ freeaddrinfo (res);
+#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
+ // Do it the ugly old way.
+ sockaddr_in sockAddr;
+ memset (&sockAddr, 0, sizeof (sockAddr));
+
+ _sock = socket (PF_INET, SOCK_STREAM, 0);
#if defined (WIN32)
- ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
- StrError (ErrNo ());
+ if (_sock == INVALID_SOCKET)
#else
- ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
- gai_strerror (errorCode);
+ if (_sock < 0)
#endif
+ {
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
throw PortException (ss.str ());
}
- memcpy (&sockAddr, res[0].ai_addr, res[0].ai_addrlen);
- freeaddrinfo (res);
-#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
+
struct hostent *hp = NULL;
if ((hp = gethostbyname (_ip.c_str ())) == NULL)
{
@@ -602,7 +632,6 @@
}
memcpy (&sockAddr.sin_addr, hp->h_addr, hp->h_length);
sockAddr.sin_family = hp->h_addrtype;
-#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
sockAddr.sin_port = htons (_port);
if (_debug >= 1)
@@ -614,16 +643,84 @@
ss << "Failed to connect to " << _ip << ": (" << ErrNo () << ") " << StrError (ErrNo ());
throw PortException (ss.str ());
}
+#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
}
// Wait for a connection: used in listen mode
void TCPPort::WaitForConnection (void)
{
+ Close (); // To make sure
+
+#if defined (FLEXIPORT_HAVE_GETADDRINFO)
+ struct addrinfo *res = NULL, hints;
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+
+ ostringstream portSS;
+ portSS << _port;
+ int errorCode;
+ if (_ip == "*")
+ {
+ // Listen on all interfaces
+ if ((errorCode = getaddrinfo (NULL, portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ stringstream ss;
+#if defined (WIN32)
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+ }
+ else
+ {
+ // Listen on the specified interface only
+ if ((errorCode = getaddrinfo (_ip.c_str (), portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ stringstream ss;
+#if defined (WIN32)
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+ }
+
+ _listenSock = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
+#if defined (WIN32)
+ if (_listenSock == INVALID_SOCKET)
+#else
+ if (_listenSock < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ if (bind (_listenSock, res->ai_addr, res->ai_addrlen) < 0)
+ {
+ Close ();
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() bind() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ freeaddrinfo (res);
+#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
char hostName[HOST_NAME_MAX + 1] = {'\0'};
- struct hostent *hp = NULL;
+ struct hostent *hp = NULL;
- Close (); // To make sure
-
_listenSock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
#if defined (WIN32)
if (_listenSock == INVALID_SOCKET)
@@ -646,14 +743,14 @@
{
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() gethostname() error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() gethostname() error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
}
if ((hp = gethostbyname (hostName)) == NULL)
{
- throw PortException (string ("TCPPort::") + __func__ +
+ throw PortException (string ("TCPPort::") + __func__ +
string (" gethostbyname() error."));
}
sockAddr.sin_family = hp->h_addrtype;
@@ -662,36 +759,12 @@
else
{
// Listen on the specified interface only
-#if defined (FLEXIPORT_HAVE_GETADDRINFO)
- struct addrinfo *res = NULL, hints;
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- int errorCode;
- if ((errorCode = getaddrinfo (_ip.c_str (), NULL, &hints, &res)) != 0)
- {
- Close ();
- stringstream ss;
-#if defined (WIN32)
- ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
- StrError (ErrNo ());
-#else
- ss << "TCPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
- gai_strerror (errorCode);
-#endif
- throw PortException (ss.str ());
- }
- memcpy (&sockAddr, res[0].ai_addr, res[0].ai_addrlen);
- freeaddrinfo (res);
-#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
if ((hp = gethostbyname (_ip.c_str ())) == NULL)
{
throw PortException (string ("TCPPort::") + __func__ +
string (" gethostbyname() error."));
}
sockAddr.sin_family = hp->h_addrtype;
-#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
sockAddr.sin_port = htons (_port);
}
@@ -703,8 +776,11 @@
StrError (ErrNo ());
throw PortException (ss.str ());
}
+#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
+
+ // All the same from this point on
listen (_listenSock, 1);
-
+
if (_debug >= 1)
cerr << "TCPPort::" << __func__ << "() Waiting for a connection." << endl;
_sock = accept (_listenSock, NULL, NULL);
@@ -720,6 +796,15 @@
StrError (ErrNo ());
throw PortException (ss.str ());
}
+
+ // Done with the listening socket so close it
+ if (close (_listenSock) < 0)
+ {
+ stringstream ss;
+ ss << "TCPPort::" << __func__ << "() close(_listenSock) error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
}
// Checks if data is available, waiting for the timeout if none is available immediatly
@@ -854,7 +939,7 @@
if ((flags = fcntl (_sock, F_GETFD)) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -862,7 +947,7 @@
if (fcntl (_sock, F_SETFD, flags) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -885,7 +970,7 @@
if ((flags = fcntl (_sock, F_GETFD)) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
@@ -893,7 +978,7 @@
if (fcntl (_sock, F_SETFD, flags) < 0)
{
stringstream ss;
- ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ ss << "TCPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
StrError (ErrNo ());
throw PortException (ss.str ());
}
Modified: gearbox/trunk/src/flexiport/tcpport.h
===================================================================
--- gearbox/trunk/src/flexiport/tcpport.h 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/tcpport.h 2008-10-14 02:53:40 UTC (rev 319)
@@ -4,17 +4,17 @@
* Copyright (c) 2008 Geoffrey Biggs
*
* flexiport flexible hardware data communications library.
- *
- * This distribution is licensed to you under the terms described in the LICENSE file included in
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
* this distribution.
*
* This work is a product of the National Institute of Advanced Industrial Science and Technology,
* Japan. Registration number: H20PRO-881
- *
+ *
* This file is part of flexiport.
*
* flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
@@ -46,7 +46,7 @@
@par Options
- ip <string>
- - TCP IP address to connect to.
+ - IP address to connect to. If listen is true, set to "*" to listen on any interface.
- Default: 127.0.0.1
- port <integer>
- TCP port to connect to/listen on.
@@ -62,7 +62,7 @@
~TCPPort (void);
/** @brief Open the port.
-
+
For a listening port, this will call accept() and therefore cause the calling process to
block until an incoming connection. */
void Open (void);
@@ -103,7 +103,7 @@
bool _open;
void CheckPort (bool read);
-
+
bool ProcessOption (const std::string &option, const std::string &value);
void Connect (void);
Modified: gearbox/trunk/src/flexiport/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/test/CMakeLists.txt 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/test/CMakeLists.txt 2008-10-14 02:53:40 UTC (rev 319)
@@ -1,10 +1,13 @@
INCLUDE (${GBX_CMAKE_DIR}/UseBasicRules.cmake)
+GBX_ADD_EXECUTABLE (serial_example serial_example.cpp)
+TARGET_LINK_LIBRARIES (serial_example flexiport)
+
GBX_ADD_EXECUTABLE (tcp_example tcp_example.cpp)
TARGET_LINK_LIBRARIES (tcp_example flexiport)
-GBX_ADD_EXECUTABLE (serial_example serial_example.cpp)
-TARGET_LINK_LIBRARIES (serial_example flexiport)
+GBX_ADD_EXECUTABLE (udp_example udp_example.cpp)
+TARGET_LINK_LIBRARIES (udp_example flexiport)
GBX_ADD_EXAMPLE (flexiport/example example.cmake.in example.cmake
- tcp_example.cpp serial_example.cpp example.readme example.logr example.logw)
+ serial_example.cpp tcp_example.cpp udp_example.cpp example.readme example.logr example.logw)
Modified: gearbox/trunk/src/flexiport/test/example.cmake.in
===================================================================
--- gearbox/trunk/src/flexiport/test/example.cmake.in 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/test/example.cmake.in 2008-10-14 02:53:40 UTC (rev 319)
@@ -4,6 +4,13 @@
INCLUDE_DIRECTORIES (@CMAKE_INSTALL_PREFIX@)
+ADD_EXECUTABLE (flexiport_serial_example serial_example.cpp)
+TARGET_LINK_LIBRARIES (flexiport_serial_example flexiport)
+SET_TARGET_PROPERTIES (flexiport_serial_example PROPERTIES
+ LINK_FLAGS "-L@CMAKE_INSTALL_PREFIX@/lib/gearbox"
+ INSTALL_RPATH "${INSTALL_RPATH};@CMAKE_INSTALL_PREFIX@/lib/gearbox"
+ BUILD_WITH_INSTALL_RPATH TRUE)
+
ADD_EXECUTABLE (flexiport_tcp_example tcp_example.cpp)
TARGET_LINK_LIBRARIES (flexiport_tcp_example flexiport)
SET_TARGET_PROPERTIES (flexiport_tcp_example PROPERTIES
@@ -11,9 +18,9 @@
INSTALL_RPATH "${INSTALL_RPATH};@CMAKE_INSTALL_PREFIX@/lib/gearbox"
BUILD_WITH_INSTALL_RPATH TRUE)
-ADD_EXECUTABLE (flexiport_serial_example serial_example.cpp)
-TARGET_LINK_LIBRARIES (flexiport_serial_example flexiport)
-SET_TARGET_PROPERTIES (flexiport_serial_example PROPERTIES
+ADD_EXECUTABLE (flexiport_udp_example udp_example.cpp)
+TARGET_LINK_LIBRARIES (flexiport_udp_example flexiport)
+SET_TARGET_PROPERTIES (flexiport_udp_example PROPERTIES
LINK_FLAGS "-L@CMAKE_INSTALL_PREFIX@/lib/gearbox"
INSTALL_RPATH "${INSTALL_RPATH};@CMAKE_INSTALL_PREFIX@/lib/gearbox"
BUILD_WITH_INSTALL_RPATH TRUE)
Modified: gearbox/trunk/src/flexiport/test/example.readme
===================================================================
--- gearbox/trunk/src/flexiport/test/example.readme 2008-10-12 01:39:24 UTC (rev 318)
+++ gearbox/trunk/src/flexiport/test/example.readme 2008-10-14 02:53:40 UTC (rev 319)
@@ -46,6 +46,17 @@
tcp_example -o timeout=1,debug=3
+Running udp_example
+----------------------
+
+The udp_example is similar to the tcp_example, replacing the TCPPort object
+with a UDPPort object.
+
+You may specify additional options for the UDPPort objects using -o, such as
+a timeout. e.g.:
+
+udp_example -o timeout=1,debug=3
+
Note for Windows users
----------------------
Added: gearbox/trunk/src/flexiport/test/udp_example.cpp
===================================================================
--- gearbox/trunk/src/flexiport/test/udp_example.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/test/udp_example.cpp 2008-10-14 02:53:40 UTC (rev 319)
@@ -0,0 +1,232 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2008 Geoffrey Biggs
+ *
+ * flexiport flexible hardware data communications library.
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
+ * this distribution.
+ *
+ * This work is a product of the National Institute of Advanced Industrial Science and Technology,
+ * Japan. Registration number: H20PRO-881
+ *
+ * This file is part of flexiport.
+ *
+ * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with flexiport.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WIN32
+ #include <unistd.h>
+#endif
+
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string>
+#include <iostream>
+using namespace std;
+
+#include <flexiport/flexiport.h>
+#include <flexiport/port.h>
+
+#if defined (WIN32)
+ #include <Windows.h>
+#endif
+
+inline void SLEEP (int length)
+{
+#if defined (WIN32)
+ Sleep (length * 1000);
+#else
+ sleep (length);
+#endif
+}
+
+#if defined (WIN32)
+DWORD WINAPI DoChild (LPVOID param)
+{
+ string portOptions = *(reinterpret_cast<string*> (param));
+#else
+int DoChild (string portOptions)
+{
+#endif
+ cout << "Waiting a few seconds..." << endl;
+ SLEEP (5);
+ cout << "Creating client port" << endl;
+ flexiport::Port *port;
+
+ port = flexiport::CreatePort ("type=udp,dest_port=20000,recv_port=20001," + portOptions);
+ cout << port->GetStatus ();
+
+ cout << "Client opening port." << endl;
+ port->Open ();
+ cout << "Client port open. Testing sending data to server." << endl;
+ cout << "Client sending 'Message #1'" << endl;
+ string stringMessage = "Message #1";
+ port->WriteString (stringMessage);
+ SLEEP (5);
+ cout << "Client sending 'This is message #2\\n'" << endl;
+ char charMessage[] = "This is message #2\n";
+ port->Write (charMessage, strlen (charMessage) + 1);
+ SLEEP (5);
+ cout << "Client sending 'Probably message #3.'" << endl;
+ port->WriteString ("Probably message #3.");
+ cout << "Client waiting for parting message." << endl;
+ port->ReadString (stringMessage);
+ cout << "Client got parting message: \"" << stringMessage << '"' << endl;
+ cout << "Client done." << endl;
+
+ return 0;
+}
+
+int DoParent (string portOptions)
+{
+ string stringBuffer;
+ char charBuffer[32];
+ memset (charBuffer, 0, sizeof (char) * 32);
+
+ cout << "Creating server port" << endl;
+ flexiport::Port *port;
+
+ port = flexiport::CreatePort ("type=udp,dest_port=20001,recv_port=20000," + portOptions);
+ cout << port->GetStatus ();
+
+ cout << "Server opening port." << endl;
+ port->Open ();
+ cout << "Server port is open." << endl;
+ cout << "Server testing ReadString()" << endl;
+ port->ReadString (stringBuffer);
+ cout << "Server received \"" << stringBuffer << '"' << endl;
+ if (stringBuffer != "Message #1")
+ {
+ cout << "Test failed." << endl;
+ return -1;
+ }
+// cout << "Server testing ReadStringUntil()" << endl;
+// port->ReadStringUntil (stringBuffer, '\n');
+// cout << "Server received \"" << stringBuffer << '"' << endl;
+// if (stringBuffer != "Message #2\n")
+// {
+// cout << "Test failed." << endl;
+// return -1;
+// }
+// cout << "Server has " << port->BytesAvailable () << " bytes available immediatly." << endl;
+// cout << "Server clearing the trailing null byte from that last message." << endl;
+// port->Read (charBuffer, 1);
+ int bytesWaiting = port->BytesAvailableWait ();
+ cout << "Server has " << bytesWaiting << " bytes available after waiting." << endl;
+ cout << "Server testing ReadFull()" << endl;
+ port->ReadFull (charBuffer, bytesWaiting);
+ cout << "Server received \"" << charBuffer << '"' << endl;
+ if (strncmp (charBuffer, "This is message #2", 18) != 0)
+ {
+ cout << "Test failed." << endl;
+ return -1;
+ }
+// cout << "Server testing ReadUntil()" << endl;
+// port->ReadUntil (charBuffer, 32, '\n');
+// cout << "Server received \"" << charBuffer << '"' << endl;
+// if (strncmp (charBuffer, "Probably message #4\n", 20) != 0)
+// {
+// cout << "Test failed." << endl;
+// return -1;
+// }
+// cout << "Server clearing the trailing null byte from that last message." << endl;
+// port->Read (charBuffer, 1);
+ cout << "Server testing Read()" << endl;
+ memset (charBuffer, 0, sizeof (char) * 32);
+ port->Read (charBuffer, 32);
+ cout << "Server received \"" << charBuffer << '"' << endl;
+ if (strncmp (charBuffer, "Probably message #3.", 20) != 0)
+ {
+ cout << "Test failed." << endl;
+ return -1;
+ }
+// cout << "Server testing ReadLine()" << endl;
+// port->ReadLine (stringBuffer);
+// cout << "Server received \"" << stringBuffer << '"' << endl;
+// if (stringBuffer != "Finally, message #6\n")
+// {
+// cout << "Test failed." << endl;
+// return -1;
+// }
+ cout << "Server sending back to client" << endl;
+ port->WriteString ("So long, and thanks for all the text.");
+ SLEEP (5);
+
+ return 0;
+}
+
+int main (int argc, char **argv)
+{
+ string portOptions;
+
+#if defined (WIN32)
+ portOptions = "";
+#else
+ int opt;
+ // Get some options from the command line
+ while ((opt = getopt (argc, argv, "o:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'o':
+ portOptions = optarg;
+ break;
+ default:
+ cout << "Usage: " << argv[0] << " [-o portoptions]" << endl << endl;
+ cout << "-o options\tString of extra options for the port." << endl;
+ return 1;
+ }
+ }
+#endif
+
+ try
+ {
+ // Fork and create a listener and a connector process
+#if defined (WIN32)
+ if (!CreateThread (NULL, 0, DoChild, &portOptions, 0, NULL))
+ {
+ cerr << "Failed to create child thread." << endl;
+ return 1;
+ }
+ if (DoParent (portOptions) < 0)
+ return 1;
+#else
+ pid_t result;
+ result = fork ();
+ if (result < 0)
+ {
+ cerr << "Failed to fork: (" << errno << ") " << strerror (errno) << endl;
+ return -1;
+ }
+ else if (result == 0)
+ {
+ if (DoChild (portOptions) < 0)
+ return 1;
+ }
+ else
+ {
+ if (DoParent (portOptions) < 0)
+ return 1;
+ }
+#endif
+ }
+ catch (flexiport::PortException e)
+ {
+ cerr << "Caught exception: " << e.what () << endl;
+ return 1;
+ }
+
+ return 0;
+}
Added: gearbox/trunk/src/flexiport/udpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/udpport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/udpport.cpp 2008-10-14 02:53:40 UTC (rev 319)
@@ -0,0 +1,1084 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2008 Geoffrey Biggs
+ *
+ * flexiport flexible hardware data communications library.
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
+ * this distribution.
+ *
+ * This work is a product of the National Institute of Advanced Industrial Science and Technology,
+ * Japan. Registration number: H20PRO-881
+ *
+ * This file is part of flexiport.
+ *
+ * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with flexiport.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "flexiport.h"
+#include "udpport.h"
+#include "flexiport_config.h"
+
+#if defined (FLEXIPORT_HAVE_GETADDRINFO)
+ #include <sys/socket.h>
+ #include <netdb.h>
+#endif
+#include <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sstream>
+#include <iostream>
+using namespace std;
+
+#if defined (WIN32)
+ #include <winsock2.h>
+ #include <ws2tcpip.h>
+ #define __func__ __FUNCTION__
+#else
+ #include <unistd.h>
+ #include <errno.h>
+ #include <sys/socket.h>
+ #include <sys/ioctl.h>
+ #include <netdb.h>
+#endif
+
+#if !defined (HOST_NAME_MAX)
+ #define HOST_NAME_MAX 256
+#endif
+
+namespace flexiport
+{
+
+inline int ErrNo (void)
+{
+#if defined (WIN32)
+ return WSAGetLastError ();
+#else
+ return errno;
+#endif
+}
+
+inline string StrError (int errNo)
+{
+#if defined (WIN32)
+ LPVOID bufferPointer = NULL;
+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+ errNo, 0, reinterpret_cast<LPTSTR> (&bufferPointer), 0, NULL);
+ string result (reinterpret_cast<LPTSTR> (bufferPointer));
+ LocalFree (bufferPointer);
+ return result;
+#else
+ return string (strerror (errNo));
+#endif
+}
+
+#if defined (WIN32)
+ const int ERRNO_EAGAIN = WSAEWOULDBLOCK;
+#else
+ const int ERRNO_EAGAIN = EAGAIN;
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Constructor/destructor
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+UDPPort::UDPPort (map<string, string> options)
+#if defined (WIN32)
+ : Port (), _sendSock (INVALID_SOCKET), _recvSock (INVALID_SOCKET),
+#else
+ : Port (), _sendSock (-1), _recvSock (-1),
+#endif
+ _destIP ("127.0.0.1"), _destPort (20000), _recvIP ("*"), _recvPort (20000), _open (false)
+{
+ _type = "udp";
+ ProcessOptions (options);
+
+#if defined (WIN32)
+ // First instance, initialise Windows sockets API
+ WSADATA info;
+ int result;
+ if ((result = WSAStartup (MAKEWORD (2, 2), &info)) != 0)
+ {
+ stringstream ss;
+ ss << "Failed to initialise Windows sockets API with error " << result;
+ throw PortException (ss.str ());
+ }
+#endif
+
+ if (_alwaysOpen)
+ Open ();
+}
+
+UDPPort::~UDPPort (void)
+{
+ Close ();
+
+#if defined (WIN32)
+ // Clean up the Windows sockets API
+ if (WSACleanup () != 0)
+ {
+ stringstream ss;
+ ss << "Failed to clean up Windows sockets API with error " << WSAGetLastError ();
+ throw PortException (ss.str ());
+ }
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Port management
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void UDPPort::Open (void)
+{
+ if (_open)
+ throw PortException ("Attempt to open already-opened port.");
+
+ OpenSender ();
+ OpenReceiver ();
+ SetPortBlockingFlag ();
+
+ _open = true;
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Port is open" << endl;
+}
+
+void UDPPort::Close (void)
+{
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Closing port" << endl;
+
+ _open = false;
+ CloseSender ();
+ CloseReceiver ();
+
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Port closed" << endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Read functions
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ssize_t UDPPort::Read (void * const buffer, size_t count)
+{
+ ssize_t receivedBytes = 0;
+
+ CheckPort (true);
+
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Going to read " << count << " bytes" << endl;
+
+ if (_timeout._sec != -1)
+ {
+ if (WaitForDataOrTimeout () == TIMED_OUT)
+ return -1;
+ }
+#if defined (WIN32)
+ receivedBytes = recv (_recvSock, reinterpret_cast<char*> (buffer), count, 0);
+#else
+ receivedBytes = recv (_recvSock, buffer, count, 0);
+#endif
+
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Read " << receivedBytes << " bytes" << endl;
+
+ if (receivedBytes < 0)
+ {
+ if (ErrNo () == ERRNO_EAGAIN)
+ return -1; // Timed out
+ else
+ {
+ // General error
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ }
+ else if (receivedBytes == 0)
+ {
+ // Peer disconnected cleanly, do the same at this end
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Peer disconnected cleanly." << endl;
+ Close ();
+ if (_alwaysOpen)
+ {
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Trying to reconnect." << endl;
+ Open ();
+ }
+ return 0;
+ }
+
+ return receivedBytes;
+}
+
+ssize_t UDPPort::ReadFull (void * const buffer, size_t count)
+{
+ ssize_t numReceived = 0;
+ size_t receivedBytes = 0;
+
+ CheckPort (true);
+
+ if (_debug >= 2)
+ {
+ cerr << "UDPPort::" << __func__ << "() Going to read until have " <<
+ count << " bytes" << endl;
+ }
+
+ while (receivedBytes < count)
+ {
+#if defined (WIN32)
+ numReceived = recv (_recvSock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
+ count, 0); // No MSG_WAITALL on older versions of visual c, it seems
+#else
+ numReceived = recv (_recvSock, &(reinterpret_cast<char*> (buffer)[receivedBytes]),
+ count, MSG_WAITALL);
+#endif
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Received " << numReceived << " bytes" << endl;
+ if (numReceived < 0)
+ {
+ if (ErrNo () == ERRNO_EAGAIN)
+ {
+ // Timed out (which probably shouldn't happen)
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() recv() timed out, probably shouldn't happen."));
+ }
+ else
+ {
+ // General error
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ }
+ else if (numReceived == 0)
+ {
+ // Peer disconnected cleanly, do the same at this end
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Peer disconnected cleanly." << endl;
+ Close ();
+ if (_alwaysOpen)
+ {
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Trying to reconnect." << endl;
+ Open ();
+ // Can go around again after this - if it doesn't open successfully Open() will throw
+ }
+ else
+ {
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() Port closed during read operation."));
+ }
+ }
+ else
+ receivedBytes += numReceived;
+ }
+
+ return receivedBytes;
+}
+
+ssize_t UDPPort::ReadUntil (void * const buffer, size_t count, uint8_t terminator)
+{
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() This function does not work for datagram-oriented protocols."));
+ return 0;
+}
+
+ssize_t UDPPort::ReadStringUntil (std::string &buffer, char terminator)
+{
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() This function does not work for datagram-oriented protocols."));
+ return 0;
+}
+
+ssize_t UDPPort::ReadLine (char * const buffer, size_t count)
+{
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() This function does not work for datagram-oriented protocols."));
+ return 0;
+}
+
+ssize_t UDPPort::Skip (size_t count)
+{
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() This function does not work for datagram-oriented protocols."));
+ return 0;
+}
+
+ssize_t UDPPort::SkipUntil (uint8_t terminator, unsigned int count)
+{
+ throw PortException (string ("UDPPort::") + __func__ +
+ string ("() This function does not work for datagram-oriented protocols."));
+ return 0;
+}
+
+ssize_t UDPPort::BytesAvailable (void)
+{
+ // TODO:
+ // MSG_PEEK is apparently bad on Windows so we should drain what we can into a local buffer
+ // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599
+
+ CheckPort (true);
+
+ if (!IsDataAvailable ())
+ return 0;
+
+#if defined (WIN32)
+ unsigned long bytesAvailable = 0;
+ if (ioctlsocket (_recvSock, FIONREAD, &bytesAvailable) < 0)
+#else
+ ssize_t bytesAvailable = 0;
+ if (ioctl (_recvSock, FIONREAD, &bytesAvailable) < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ if (_debug >= 2)
+ {
+ cerr << "UDPPort::" << __func__ << "() Found " << bytesAvailable <<
+ " bytes available" << endl;
+ }
+ return bytesAvailable;
+}
+
+ssize_t UDPPort::BytesAvailableWait (void)
+{
+ CheckPort (true);
+
+ if (WaitForDataOrTimeout () == TIMED_OUT)
+ {
+ if (_debug >= 2)
+ {
+ cerr << "UDPPort::" << __func__ <<
+ " Timed out waiting for data to check bytes available" << endl;
+ }
+ if (IsBlocking ())
+ return -1; // Timeout in blocking mode
+ else
+ return 0; // No data in non-blocking mode
+ }
+
+ // TODO:
+ // MSG_PEEK is apparently bad on Windows so we should drain what we can into a local buffer
+ // instead, then use that first during read calls. See http://support.microsoft.com/kb/192599
+#if defined (WIN32)
+ unsigned long bytesAvailable = 0;
+ if (ioctlsocket (_recvSock, FIONREAD, &bytesAvailable) < 0)
+#else
+ ssize_t bytesAvailable = 0;
+ if (ioctl (_recvSock, FIONREAD, &bytesAvailable) < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctl() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ if (_debug >= 2)
+ {
+ cerr << "UDPPort::" << __func__ << "() Found " << bytesAvailable <<
+ " bytes available after waiting" << endl;
+ }
+ return bytesAvailable;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Write functions
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ssize_t UDPPort::Write (const void * const buffer, size_t count)
+{
+ ssize_t numSent = 0;
+
+ CheckPort (false);
+
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Writing " << count << " bytes" << endl;
+ if (_timeout._sec != -1)
+ {
+ if (WaitForWritableOrTimeout () == TIMED_OUT)
+ {
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Timed out waiting to send" << endl;
+ return -1;
+ }
+ }
+#if defined (WIN32)
+ if ((numSent = send (_sendSock, reinterpret_cast<const char*> (buffer), count, 0)) < 0)
+#else
+ if ((numSent = send (_sendSock, buffer, count, 0)) < 0)
+#endif
+ {
+ if (ErrNo () == ERRNO_EAGAIN)
+ {
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Timed out while in send()" << endl;
+ return -1; // Timed out
+ }
+ else
+ {
+ // General error
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() send() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ }
+
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Wrote " << numSent << " bytes" << endl;
+
+ return numSent;
+}
+
+void UDPPort::Flush (void)
+{
+ int numRead = 0;
+ char dump[128];
+
+ // Read data out of the socket into a dump until there's nothing left to read.
+ // Use MSG_DONTWAIT to avoid the timeout if one is set on Linux.
+ // It would be nice to use MSG_DONTWAIT on Windows, but MS didn't see fit to include that in
+ // their cramming of BSD sockets into Windows. Instead, check if data is available before
+ // calling recv.
+ do
+ {
+#if defined (WIN32)
+ if (!IsDataAvailable ())
+ break;
+ numRead = recv (_sendSock, dump, 128, 0);
+#else
+ numRead = recv (_sendSock, dump, 128, MSG_DONTWAIT);
+#endif
+ if (numRead < 0 && ErrNo () != ERRNO_EAGAIN)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() recv() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ } while (numRead > 0);
+
+ // We can't do anything about the write buffers.
+}
+
+void UDPPort::Drain (void)
+{
+ // Since we can't force the write buffer to send, we can't do anything here.
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Can't drain output buffer of TCP port." << endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Other public API functions
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+std::string UDPPort::GetStatus (void) const
+{
+ stringstream status;
+
+ status << "UDP-specific status:" << endl;
+ status << "Destination address: " << _destIP << ":" << _destPort << endl;
+// if (_ip == "*")
+// {
+// if (_destAddr == NULL)
+// status << "No auto-configured destination found yet." << endl;
+// else
+// status << "Auto-configured destination: " << endl;
+// }
+ status << "Listening address: " << _recvIP << ":" << _recvPort << endl;
+ status << (_open ? "Port is open" : "Port is closed") << endl;
+
+ return Port::GetStatus () + status.str ();
+}
+
+void UDPPort::SetTimeout (Timeout timeout)
+{
+ _timeout = timeout;
+ SetPortBlockingFlag ();
+}
+
+void UDPPort::SetCanRead (bool canRead)
+{
+ if (canRead)
+ OpenReceiver ();
+ else
+ CloseReceiver ();
+ _canRead = canRead;
+}
+
+void UDPPort::SetCanWrite (bool canWrite)
+{
+ if (canWrite)
+ OpenSender ();
+ else
+ CloseSender ();
+ _canWrite = canWrite;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Internal functions
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+bool UDPPort::ProcessOption (const std::string &option, const std::string &value)
+{
+ char c = '\0';
+
+ // Check if the parent class can handle this option
+ if (Port::ProcessOption (option, value))
+ return true;
+
+ if (option == "dest_ip")
+ {
+ _destIP = value;
+ return true;
+ }
+ else if (option == "dest_port")
+ {
+ istringstream is (value);
+ if (!(is >> _destPort) || is.get (c) || _destPort == 0)
+ throw PortException ("Bad destination port number: " + value);
+ return true;
+ }
+ else if (option == "recv_ip")
+ {
+ _recvIP = value;
+ return true;
+ }
+ else if (option == "recv_port")
+ {
+ istringstream is (value);
+ if (!(is >> _recvPort) || is.get (c) || _recvPort == 0)
+ throw PortException ("Bad receive port number: " + value);
+ return true;
+ }
+
+ return false;
+}
+
+// Open the socket for sending data
+void UDPPort::OpenSender (void)
+{
+ CloseSender (); // To make sure
+
+ // If getaddrinfo() is available, much less stuff needs to be hard-coded or copied around.
+#if defined (FLEXIPORT_HAVE_GETADDRINFO)
+ struct addrinfo *res = NULL, hints;
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+
+ int errorCode;
+ ostringstream portSS;
+ portSS << _destPort;
+ if ((errorCode = getaddrinfo (_destIP.c_str (), portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ CloseSender ();
+ stringstream ss;
+#if defined (WIN32)
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+
+ _sendSock = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
+#if defined (WIN32)
+ if (_sendSock == INVALID_SOCKET)
+#else
+ if (_sendSock < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ if (_debug >= 1)
+ {
+ cerr << "UDPPort::" << __func__ << "() Connecting to " << _destIP << ":" << _destPort <<
+ "." << endl;
+ }
+ if (connect (_sendSock, res->ai_addr, res->ai_addrlen) < 0)
+ {
+ CloseSender ();
+ stringstream ss;
+ ss << "Failed to connect to " << _destIP << ": (" << ErrNo () << ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ freeaddrinfo (res);
+#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
+ // Do it the ugly old way.
+ sockaddr_in sockAddr;
+ memset (&sockAddr, 0, sizeof (sockAddr));
+
+ _sendSock = socket (PF_INET, SOCK_DGRAM, 0);
+#if defined (WIN32)
+ if (_sendSock == INVALID_SOCKET)
+#else
+ if (_sendSock < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ struct hostent *hp = NULL;
+ if ((hp = gethostbyname (_destIP.c_str ())) == NULL)
+ {
+ CloseSender ();
+ throw PortException (string ("UDPPort::") + __func__ + string (" gethostbyname() error."));
+ }
+ memcpy (&sockAddr.sin_addr, hp->h_addr, hp->h_length);
+ sockAddr.sin_family = hp->h_addrtype;
+ sockAddr.sin_port = htons (_destPort);
+
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Connecting to " << _destIP << ":" << _port << "." << endl;
+ if (connect (_sendSock, reinterpret_cast<struct sockaddr*> (&sockAddr), sizeof (sockAddr)) < 0)
+ {
+ CloseSender ();
+ stringstream ss;
+ ss << "Failed to connect to " << _destIP << ": (" << ErrNo () << ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
+}
+
+// Close the socket for sending data
+void UDPPort::CloseSender (void)
+{
+#if defined (WIN32)
+ if (_sendSock != INVALID_SOCKET)
+ {
+ closesocket (_sendSock);
+ _sendSock = INVALID_SOCKET;
+ }
+#else
+ if (_sendSock >= 0)
+ {
+ close (_sendSock);
+ _sendSock = -1;
+ }
+#endif
+}
+
+// Open the socket for receiving data
+void UDPPort::OpenReceiver (void)
+{
+ CloseReceiver (); // To make sure
+
+#if defined (FLEXIPORT_HAVE_GETADDRINFO)
+ struct addrinfo *res = NULL, hints;
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_flags = AI_PASSIVE;
+
+ ostringstream portSS;
+ portSS << _recvPort;
+ int errorCode;
+ if (_recvIP == "*")
+ {
+ // Listen on all interfaces
+ if ((errorCode = getaddrinfo (NULL, portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ stringstream ss;
+#if defined (WIN32)
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+ }
+ else
+ {
+ // Listen on the specified interface only
+ if ((errorCode = getaddrinfo (_recvIP.c_str (), portSS.str ().c_str (), &hints, &res)) != 0)
+ {
+ stringstream ss;
+#if defined (WIN32)
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+#else
+ ss << "UDPPort::" << __func__ << "() getaddrinfo() error: (" << errorCode << ") " <<
+ gai_strerror (errorCode);
+#endif
+ throw PortException (ss.str ());
+ }
+ }
+
+ _recvSock = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
+#if defined (WIN32)
+ if (_recvSock == INVALID_SOCKET)
+#else
+ if (_recvSock < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ if (bind (_recvSock, res->ai_addr, res->ai_addrlen) < 0)
+ {
+ CloseReceiver ();
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() bind() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ freeaddrinfo (res);
+#else // defined (FLEXIPORT_HAVE_GETADDRINFO)
+ char hostName[HOST_NAME_MAX + 1] = {'\0'};
+ struct hostent *hp = NULL;
+
+ _recvSock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
+#if defined (WIN32)
+ if (_recvSock == INVALID_SOCKET)
+#else
+ if (_recvSock < 0)
+#endif
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() socket() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ sockaddr_in sockAddr;
+ memset (&sockAddr, 0, sizeof (sockAddr));
+ if (_recvIP == "*")
+ {
+ // Listen on all interfaces
+ if (gethostname (hostName, HOST_NAME_MAX) < 0)
+ {
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() gethostname() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ }
+ if ((hp = gethostbyname (hostName)) == NULL)
+ {
+ throw PortException (string ("UDPPort::") + __func__ +
+ string (" gethostbyname() error."));
+ }
+ sockAddr.sin_family = hp->h_addrtype;
+ sockAddr.sin_port = htons (_recvPort);
+ }
+ else
+ {
+ // Listen on the specified interface only
+ if ((hp = gethostbyname (_ip.c_str ())) == NULL)
+ {
+ throw PortException (string ("UDPPort::") + __func__ +
+ string (" gethostbyname() error."));
+ }
+ sockAddr.sin_family = hp->h_addrtype;
+ sockAddr.sin_port = htons (_recvPort);
+ }
+
+ if (bind (_recvSock, reinterpret_cast<struct sockaddr*> (&sockAddr), sizeof (sockAddr)) < 0)
+ {
+ CloseReceiver ();
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() bind() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#endif // defined (FLEXIPORT_HAVE_GETADDRINFO)
+
+ if (_debug >= 1)
+ cerr << "UDPPort::" << __func__ << "() Waiting for data." << endl;
+}
+
+// Close the socket for receiving data
+void UDPPort::CloseReceiver (void)
+{
+#if defined (WIN32)
+ if (_recvSock != INVALID_SOCKET)
+ {
+ closesocket (_recvSock);
+ _recvSock = INVALID_SOCKET;
+ }
+#else
+ if (_recvSock >= 0)
+ {
+ close (_recvSock);
+ _recvSock = -1;
+ }
+#endif
+}
+
+// Checks if data is available, waiting for the timeout if none is available immediatly
+UDPPort::WaitStatus UDPPort::WaitForDataOrTimeout (void)
+{
+ fd_set fdSet;
+ struct timeval tv, *tvPtr = NULL;
+
+ FD_ZERO (&fdSet);
+ FD_SET (_recvSock, &fdSet);
+ tv.tv_sec = _timeout._sec;
+ tv.tv_usec = _timeout._usec;
+ if (tv.tv_sec >= 0)
+ tvPtr = &tv;
+
+ int result = select (_recvSock + 1, &fdSet, NULL, NULL, tvPtr);
+
+ if (result < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ else if (result == 0)
+ {
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Timed out" << endl;
+ // Time out
+ return TIMED_OUT;
+ }
+ if (_debug >= 2)
+ cerr << "UDPPort::" << __func__ << "() Found data waiting" << endl;
+ return DATA_AVAILABLE;
+}
+
+// Checks if data is available right now
+bool UDPPort::IsDataAvailable (void)
+{
+ fd_set fdSet;
+ struct timeval tv;
+
+ FD_ZERO (&fdSet);
+ FD_SET (_recvSock, &fdSet);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ int result = select (_recvSock + 1, &fdSet, NULL, NULL, &tv);
+
+ if (result < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ else if (result == 0)
+ {
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Found no data waiting" << endl;
+ // No data
+ return false;
+ }
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Found data waiting" << endl;
+ return true;
+}
+
+// Checks it he port can be written to, waiting for the timeout if it can't be written immediatly
+UDPPort::WaitStatus UDPPort::WaitForWritableOrTimeout (void)
+{
+ fd_set fdSet;
+ struct timeval tv, *tvPtr = NULL;
+
+ FD_ZERO (&fdSet);
+ FD_SET (_sendSock, &fdSet);
+ tv.tv_sec = _timeout._sec;
+ tv.tv_usec = _timeout._usec;
+ if (tv.tv_sec >= 0)
+ tvPtr = &tv;
+
+ int result = select (_sendSock + 1, NULL, &fdSet, NULL, tvPtr);
+
+ if (result < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() select() error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ else if (result == 0)
+ {
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Timed out" << endl;
+ // Time out
+ return TIMED_OUT;
+ }
+ if (_debug >= 3)
+ cerr << "UDPPort::" << __func__ << "() Found space to write" << endl;
+ return CAN_WRITE;
+}
+
+// Check if the port is open and if permissions are set correctly for the desired operation
+void UDPPort::CheckPort (bool read)
+{
+ if (!_open)
+ throw PortException ("Port is not open.");
+
+ if (read && !_canRead)
+ throw PortException ("Cannot read from write-only port.");
+
+ if (!read && !_canWrite)
+ throw PortException ("Cannot write to read-only port.");
+}
+
+void UDPPort::SetPortBlockingFlag (void)
+{
+ if (_timeout._sec == -1)
+ {
+ // Disable the non-blocking flag of the socket
+#if defined (WIN32)
+ unsigned long setting = 0;
+ // Receive socket
+ if (ioctlsocket (_recvSock, FIONBIO, &setting) == SOCKET_ERROR)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctlsocket(_recvSock) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ // Send socket
+ if (ioctlsocket (_sendSock, FIONBIO, &setting) == SOCKET_ERROR)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctlsocket(_sendSock) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#else
+ int flags;
+
+ // Receive socket
+ if ((flags = fcntl (_recvSock, F_GETFD)) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_GETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ flags &= ~O_NONBLOCK;
+ if (fcntl (_recvSock, F_SETFD, flags) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_recvSock, F_SETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ // Send socket
+ if ((flags = fcntl (_sendSock, F_GETFD)) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ flags &= ~O_NONBLOCK;
+ if (fcntl (_sendSock, F_SETFD, flags) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#endif
+ }
+ else
+ {
+ // Set the socket to non-blocking, and we'll manage timeouts ourselves via select()
+#if defined (WIN32)
+ unsigned long setting = 1;
+ // Receive socket
+ if (ioctlsocket (_recvSock, FIONBIO, &setting) == SOCKET_ERROR)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctlsocket(_recvSock) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ // Send socket
+ if (ioctlsocket (_sendSock, FIONBIO, &setting) == SOCKET_ERROR)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() ioctlsocket(_sendSock) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#else
+ int flags;
+
+ // Receive socket
+ if ((flags = fcntl (_recvSock, F_GETFD)) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(F_GETFD) error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ flags |= O_NONBLOCK;
+ if (fcntl (_recvSock, F_SETFD, flags) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(F_SETFD) error: (" << ErrNo () << ") " <<
+ StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+
+ // Send socket
+ if ((flags = fcntl (_sendSock, F_GETFD)) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_GETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+ flags |= O_NONBLOCK;
+ if (fcntl (_sendSock, F_SETFD, flags) < 0)
+ {
+ stringstream ss;
+ ss << "UDPPort::" << __func__ << "() fcntl(_sendSock, F_SETFD) error: (" << ErrNo () <<
+ ") " << StrError (ErrNo ());
+ throw PortException (ss.str ());
+ }
+#endif
+ }
+}
+
+} // namespace flexiport
Added: gearbox/trunk/src/flexiport/udpport.h
===================================================================
--- gearbox/trunk/src/flexiport/udpport.h (rev 0)
+++ gearbox/trunk/src/flexiport/udpport.h 2008-10-14 02:53:40 UTC (rev 319)
@@ -0,0 +1,150 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2008 Geoffrey Biggs
+ *
+ * flexiport flexible hardware data communications library.
+ *
+ * This distribution is licensed to you under the terms described in the LICENSE file included in
+ * this distribution.
+ *
+ * This work is a product of the National Institute of Advanced Industrial Science and Technology,
+ * Japan. Registration number: H20PRO-881
+ *
+ * This file is part of flexiport.
+ *
+ * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
+ * Lesser General Public License as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with flexiport.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __UDPPORT_H
+#define __UDPPORT_H
+
+#include "port.h"
+
+#include <map>
+#include <string>
+
+/** @ingroup gbx_library_flexiport
+@{
+*/
+
+namespace flexiport
+{
+...
[truncated message content] |
|
From: <rus...@us...> - 2008-10-12 01:39:27
|
Revision: 318
http://gearbox.svn.sourceforge.net/gearbox/?rev=318&view=rev
Author: russo2503v
Date: 2008-10-12 01:39:24 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
finding newer versions
Modified Paths:
--------------
gearbox/trunk/cmake/FindIceUtil.cmake
Modified: gearbox/trunk/cmake/FindIceUtil.cmake
===================================================================
--- gearbox/trunk/cmake/FindIceUtil.cmake 2008-10-12 01:38:56 UTC (rev 317)
+++ gearbox/trunk/cmake/FindIceUtil.cmake 2008-10-12 01:39:24 UTC (rev 318)
@@ -22,8 +22,11 @@
# debian package installs Ice here
/usr/include/IceUtil
# Test standard installation points: newer versions first
+ /opt/Ice-4.0/include/IceUtil
+ /opt/Ice-3.6/include/IceUtil
+ /opt/Ice-3.5/include/IceUtil
+ /opt/Ice-3.4/include/IceUtil
/opt/Ice-3.3/include/IceUtil
- /opt/Ice-3.2/include/IceUtil
# some people may manually choose to install Ice here
/usr/local/include/IceUtil
# windows
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rus...@us...> - 2008-10-12 01:39:04
|
Revision: 317
http://gearbox.svn.sourceforge.net/gearbox/?rev=317&view=rev
Author: russo2503v
Date: 2008-10-12 01:38:56 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
docco
Modified Paths:
--------------
gearbox/trunk/src/gbxutilacfr/substatus.h
Modified: gearbox/trunk/src/gbxutilacfr/substatus.h
===================================================================
--- gearbox/trunk/src/gbxutilacfr/substatus.h 2008-10-05 09:58:28 UTC (rev 316)
+++ gearbox/trunk/src/gbxutilacfr/substatus.h 2008-10-12 01:38:56 UTC (rev 317)
@@ -27,7 +27,7 @@
//! implementation must be thread-safe.
//!
//!
-//! @sa SubStatus
+//! @sa Status
//!
class SubStatus
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2008-10-05 10:02:23
|
Revision: 316
http://gearbox.svn.sourceforge.net/gearbox/?rev=316&view=rev
Author: borax00
Date: 2008-10-05 09:58:28 +0000 (Sun, 05 Oct 2008)
Log Message:
-----------
fixed typo in dox.
Modified Paths:
--------------
gearbox/trunk/src/gbxutilacfr/doc.dox
Modified: gearbox/trunk/src/gbxutilacfr/doc.dox
===================================================================
--- gearbox/trunk/src/gbxutilacfr/doc.dox 2008-10-03 07:04:23 UTC (rev 315)
+++ gearbox/trunk/src/gbxutilacfr/doc.dox 2008-10-05 09:58:28 UTC (rev 316)
@@ -15,7 +15,7 @@
@defgroup gbx_library_gbxutilacfr GbxUtilAcfr
@brief ACFR utility functions and drivers
-Utility functions and objects used accross ACFR libraries and drivers. For a full list of classes and functions, see @ref gbxutilacfr.
+Utility functions and objects used accross ACFR libraries and drivers.
For a full list of classes and functions, see @ref gbxutilacfr.
@par Header file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2008-10-03 07:04:29
|
Revision: 315
http://gearbox.svn.sourceforge.net/gearbox/?rev=315&view=rev
Author: borax00
Date: 2008-10-03 07:04:23 +0000 (Fri, 03 Oct 2008)
Log Message:
-----------
Added Paths:
-----------
gearbox/tags/2008_10_03/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rus...@us...> - 2008-09-30 12:10:38
|
Revision: 314
http://gearbox.svn.sourceforge.net/gearbox/?rev=314&view=rev
Author: russo2503v
Date: 2008-09-30 12:10:21 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
without escaping the variable name, explicit strings were never matched and the default value was always used
Modified Paths:
--------------
gearbox/trunk/cmake/TargetUtils.cmake
Modified: gearbox/trunk/cmake/TargetUtils.cmake
===================================================================
--- gearbox/trunk/cmake/TargetUtils.cmake 2008-09-30 06:32:33 UTC (rev 313)
+++ gearbox/trunk/cmake/TargetUtils.cmake 2008-09-30 12:10:21 UTC (rev 314)
@@ -33,13 +33,13 @@
CMAKE_POLICY( SET CMP0003 NEW )
ENDIF( COMMAND cmake_policy )
- IF( type STREQUAL SHARED )
+ IF( ${type} STREQUAL SHARED )
SET( libType SHARED )
- ELSEIF( type STREQUAL STATIC )
+ ELSEIF( ${type} STREQUAL STATIC )
SET( libType STATIC )
- ELSE( type STREQUAL SHARED )
+ ELSE( ${type} STREQUAL SHARED )
SET( libType ${GBX_DEFAULT_LIB_TYPE} )
- ENDIF( type STREQUAL SHARED )
+ ENDIF( ${type} STREQUAL SHARED )
ADD_LIBRARY( ${name} ${libType} ${ARGN} )
# SET_TARGET_PROPERTIES( ${name} PROPERTIES
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-09-30 06:32:36
|
Revision: 313
http://gearbox.svn.sourceforge.net/gearbox/?rev=313&view=rev
Author: gbiggs
Date: 2008-09-30 06:32:33 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
Whoops.
Modified Paths:
--------------
gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt
Modified: gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt 2008-09-30 06:27:56 UTC (rev 312)
+++ gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt 2008-09-30 06:32:33 UTC (rev 313)
@@ -1,9 +1,6 @@
INCLUDE (${GBX_CMAKE_DIR}/UseBasicRules.cmake)
GBX_ADD_EXECUTABLE (hokuyo_aist_example example.cpp)
-IF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
- ADD_DEFINITIONS (-D
-ENDIF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
TARGET_LINK_LIBRARIES (hokuyo_aist_example hokuyo_aist flexiport)
GBX_ADD_EXAMPLE (hokuyo_aist example.cmake.in example.cmake
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-09-30 06:28:07
|
Revision: 312
http://gearbox.svn.sourceforge.net/gearbox/?rev=312&view=rev
Author: gbiggs
Date: 2008-09-30 06:27:56 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
Jumped through all the hoops necessary to fixed building of static libraries on Windows
Modified Paths:
--------------
gearbox/trunk/src/flexiport/CMakeLists.txt
gearbox/trunk/src/flexiport/doc.dox
gearbox/trunk/src/flexiport/flexiport.h
gearbox/trunk/src/flexiport/port.h
gearbox/trunk/src/flexiport/timeout.h
gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/doc.dox
gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt
Modified: gearbox/trunk/src/flexiport/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-30 06:27:56 UTC (rev 312)
@@ -39,9 +39,12 @@
ENDIF (FLEXIPORT_INCLUDE_LOGGING)
IF (WIN32)
- ADD_DEFINITIONS (-DFLEXIPORT_EXPORTS)
+ IF (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ ADD_DEFINITIONS (-DFLEXIPORT_EXPORTS)
+ ELSE (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ ADD_DEFINITIONS (-DFLEXIPORT_STATIC)
+ ENDIF (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
ENDIF (WIN32)
- ADD_DEFINITIONS (-DFLEXIPORT_EXPORTS)
GBX_ADD_LIBRARY (${libName} DEFAULT ${srcs})
GBX_ADD_PKGCONFIG (${libName} "FlexiPort generic comms library" "" "" "" "")
GBX_ADD_HEADERS (${libName} ${hdrs})
Modified: gearbox/trunk/src/flexiport/doc.dox
===================================================================
--- gearbox/trunk/src/flexiport/doc.dox 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/flexiport/doc.dox 2008-09-30 06:27:56 UTC (rev 312)
@@ -23,8 +23,12 @@
date without the original hardware present.
The @ref SerialPort and @ref TCPPort port types are cross-platform, usable on Linux, Mac OSX and
-Microsoft Windows.
+Microsoft Windows. If this library is compiled as static on Windows, you must define the
+@c FLEXIPORT_STATIC preprocessor variable when compiling code that includes port.h, flexiport.h or
+timeout.h.
+
+
For a full list of classes and functions, see @ref flexiport.
@par Header file
Modified: gearbox/trunk/src/flexiport/flexiport.h
===================================================================
--- gearbox/trunk/src/flexiport/flexiport.h 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/flexiport/flexiport.h 2008-09-30 06:27:56 UTC (rev 312)
@@ -32,7 +32,9 @@
#include <string>
#if defined (WIN32)
- #if defined (FLEXIPORT_EXPORTS)
+ #if defined (FLEXIPORT_STATIC)
+ #define FLEXIPORT_EXPORT
+ #elif defined (FLEXIPORT_EXPORTS)
#define FLEXIPORT_EXPORT __declspec (dllexport)
#else
#define FLEXIPORT_EXPORT __declspec (dllimport)
Modified: gearbox/trunk/src/flexiport/port.h
===================================================================
--- gearbox/trunk/src/flexiport/port.h 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/flexiport/port.h 2008-09-30 06:27:56 UTC (rev 312)
@@ -32,7 +32,9 @@
#include <map>
#if defined (WIN32)
- #if defined (FLEXIPORT_EXPORTS)
+ #if defined (FLEXIPORT_STATIC)
+ #define FLEXIPORT_EXPORT
+ #elif defined (FLEXIPORT_EXPORTS)
#define FLEXIPORT_EXPORT __declspec (dllexport)
#else
#define FLEXIPORT_EXPORT __declspec (dllimport)
Modified: gearbox/trunk/src/flexiport/timeout.h
===================================================================
--- gearbox/trunk/src/flexiport/timeout.h 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/flexiport/timeout.h 2008-09-30 06:27:56 UTC (rev 312)
@@ -29,7 +29,9 @@
#define __TIMEOUT_H
#if defined (WIN32)
- #if defined (FLEXIPORT_EXPORTS)
+ #if defined (FLEXIPORT_STATIC)
+ #define FLEXIPORT_EXPORT
+ #elif defined (FLEXIPORT_EXPORTS)
#define FLEXIPORT_EXPORT __declspec (dllexport)
#else
#define FLEXIPORT_EXPORT __declspec (dllimport)
Modified: gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-09-30 06:27:56 UTC (rev 312)
@@ -15,7 +15,11 @@
SET (srcs hokuyo_aist.cpp)
IF (WIN32)
- ADD_DEFINITIONS (-DHOKUYO_AIST_EXPORTS)
+ IF (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ ADD_DEFINITIONS (-DHOKUYO_AIST_EXPORTS)
+ ELSE (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ ADD_DEFINITIONS (-DHOKUYO_AIST_STATIC -DFLEXIPORT_STATIC)
+ ENDIF (GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
ENDIF (WIN32)
GBX_ADD_LIBRARY (${libName} DEFAULT ${srcs})
TARGET_LINK_LIBRARIES (${libName} ${reqLibs})
Modified: gearbox/trunk/src/hokuyo_aist/doc.dox
===================================================================
--- gearbox/trunk/src/hokuyo_aist/doc.dox 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/hokuyo_aist/doc.dox 2008-09-30 06:27:56 UTC (rev 312)
@@ -13,6 +13,9 @@
For a full list of classes and functions, see @ref hokuyo_aist.
+If this library is compiled as static on Windows, you must define the @c HOKUYO_AIST_STATIC
+preprocessor variable when compiling code that includes hokuyo_aist.h.
+
Header file:
@verbatim
#include <hokuyo_aist/hokuyo_aist.h>
Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
===================================================================
--- gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-09-30 06:27:56 UTC (rev 312)
@@ -34,7 +34,9 @@
#if defined (WIN32)
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
- #if defined (HOKUYO_AIST_EXPORTS)
+ #if defined (HOKUYO_AIST_STATIC)
+ #define HOKUYO_AIST_EXPORT
+ #elif defined (HOKUYO_AIST_EXPORTS)
#define HOKUYO_AIST_EXPORT __declspec (dllexport)
#else
#define HOKUYO_AIST_EXPORT __declspec (dllimport)
Modified: gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt 2008-09-30 04:00:05 UTC (rev 311)
+++ gearbox/trunk/src/hokuyo_aist/test/CMakeLists.txt 2008-09-30 06:27:56 UTC (rev 312)
@@ -1,6 +1,9 @@
INCLUDE (${GBX_CMAKE_DIR}/UseBasicRules.cmake)
GBX_ADD_EXECUTABLE (hokuyo_aist_example example.cpp)
+IF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ ADD_DEFINITIONS (-D
+ENDIF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
TARGET_LINK_LIBRARIES (hokuyo_aist_example hokuyo_aist flexiport)
GBX_ADD_EXAMPLE (hokuyo_aist example.cmake.in example.cmake
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-09-30 04:00:20
|
Revision: 311
http://gearbox.svn.sourceforge.net/gearbox/?rev=311&view=rev
Author: gbiggs
Date: 2008-09-30 04:00:05 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
Fixed the bad default install path for windows.
Modified Paths:
--------------
gearbox/trunk/cmake/SetupDirectories.cmake
Modified: gearbox/trunk/cmake/SetupDirectories.cmake
===================================================================
--- gearbox/trunk/cmake/SetupDirectories.cmake 2008-09-30 03:47:56 UTC (rev 310)
+++ gearbox/trunk/cmake/SetupDirectories.cmake 2008-09-30 04:00:05 UTC (rev 311)
@@ -24,7 +24,7 @@
IF( NOT GBX_OS_WIN )
SET( CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Installation directory" FORCE )
ELSE ( NOT GBX_OS_WIN )
- SET( CMAKE_INSTALL_PREFIX "C:\Program Files\${PROJECT_NAME}\Include" CACHE PATH "Installation directory" FORCE )
+ SET( CMAKE_INSTALL_PREFIX "C:\\Program Files\\${PROJECT_NAME}" CACHE PATH "Installation directory" FORCE )
ENDIF( NOT GBX_OS_WIN )
ENDIF( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-09-30 03:48:08
|
Revision: 310
http://gearbox.svn.sourceforge.net/gearbox/?rev=310&view=rev
Author: gbiggs
Date: 2008-09-30 03:47:56 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
Added flexiport python bindings (still a work in progress, off by default)
Modified Paths:
--------------
gearbox/trunk/src/flexiport/CMakeLists.txt
Added Paths:
-----------
gearbox/trunk/src/flexiport/python/
gearbox/trunk/src/flexiport/python/CMakeLists.txt
gearbox/trunk/src/flexiport/python/flexiport.cpp
gearbox/trunk/src/flexiport/python/logreaderport.cpp
gearbox/trunk/src/flexiport/python/logwriterport.cpp
gearbox/trunk/src/flexiport/python/port.cpp
gearbox/trunk/src/flexiport/python/serialport.cpp
gearbox/trunk/src/flexiport/python/tcpport.cpp
gearbox/trunk/src/flexiport/python/test/
gearbox/trunk/src/flexiport/python/test/CMakeLists.txt
gearbox/trunk/src/flexiport/python/test/serial_example.py
gearbox/trunk/src/flexiport/python/timeout.cpp
Modified: gearbox/trunk/src/flexiport/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
+++ gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-30 03:47:56 UTC (rev 310)
@@ -54,7 +54,7 @@
ADD_SUBDIRECTORY (test)
ENDIF (GBX_BUILD_TESTS)
- OPTION (FLEXIPORT_BUILD_BINDINGS "Build the Python bindings for Flexiport" ON)
+ OPTION (FLEXIPORT_BUILD_BINDINGS "Build the Python bindings for Flexiport" OFF)
IF (FLEXIPORT_BUILD_BINDINGS)
ADD_SUBDIRECTORY (python)
ENDIF (FLEXIPORT_BUILD_BINDINGS)
Added: gearbox/trunk/src/flexiport/python/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/python/CMakeLists.txt (rev 0)
+++ gearbox/trunk/src/flexiport/python/CMakeLists.txt 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,70 @@
+# Find the Python libraries and headers
+FIND_PACKAGE (PythonLibs)
+IF (NOT PYTHON_LIBRARIES)
+ MESSAGE (STATUS "Python libaries not found. Cannot build Python bindings for Flexiport.")
+ENDIF (NOT PYTHON_LIBRARIES)
+
+# Find Boost::Python
+# There is a new, much better, FindBoost.cmake in 2.6
+IF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+ OPTION (Boost_USE_STATIC_LIBS "Use the static versions of the Boost libraries" OFF)
+ MARK_AS_ADVANCED (Boost_USE_STATIC_LIBS)
+
+ SET (BOOST_COMPONENTS python)
+ FIND_PACKAGE (Boost COMPONENTS ${BOOST_COMPONENTS})
+ IF (Boost_FOUND)
+ INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
+ LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
+
+ IF (Boost_PYTHON_FOUND)
+ GET_FILENAME_COMPONENT (boostPythonLib ${Boost_PYTHON_LIBRARY} NAME_WE CACHE)
+ # Chop off the lib at the front, too, if present
+ STRING (REGEX REPLACE "^lib" "" boostPythonLib ${boostPythonLib})
+ MESSAGE (STATUS
+ "PlayerC++ client library will be built with Boost::Thread support.")
+ ELSE (Boost_PYTHON_FOUND)
+ MESSAGE (STATUS
+ "Boost::Python library was not found. Cannot build Python bindings for Flexiport.")
+ ENDIF (Boost_PYTHON_FOUND)
+ ELSE (Boost_FOUND)
+ MESSAGE (STATUS
+ "Boost libraries were not found. Cannot build Python bindings for Flexiport.")
+ ENDIF (Boost_FOUND)
+ELSE (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+ FIND_PACKAGE (Boost)
+ IF (Boost_FOUND)
+ # For 2.4, assume that if boost is found then boost::python is present
+ OPTION (Boost_USE_MULTITHREAD "Use the multithreaded versions of the Boost libraries" ON)
+ MARK_AS_ADVANCED (Boost_USE_MULTITHREAD)
+ IF (Boost_USE_MULTITHREAD)
+ SET (BOOST_LIB_SUFFIX "-mt" CACHE STRING "Boost library name suffix")
+ ELSE (Boost_USE_MULTITHREAD)
+ SET (BOOST_LIB_SUFFIX "" CACHE STRING "Boost library name suffix")
+ ENDIF (Boost_USE_MULTITHREAD)
+ MARK_AS_ADVANCED (BOOST_LIB_SUFFIX)
+
+ SET (boostPythonLib boost_python${BOOST_LIB_SUFFIX})
+ INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
+ LINK_DIRECTORIES (${Boost_LIBRARY_DIRS})
+ ELSE (Boost_FOUND)
+ MESSAGE (STATUS
+ "Boost libraries were not found. Cannot build Python bindings for Flexiport.")
+ ENDIF (Boost_FOUND)
+ENDIF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
+
+IF (PYTHON_LIBRARIES AND Boost_FOUND AND GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ MESSAGE (STATUS "Flexiport Python bindings will be built.")
+ SET (srcs flexiport.cpp logreaderport.cpp logwriterport.cpp port.cpp
+ serialport.cpp tcpport.cpp timeout.cpp)
+
+ SET (pyModuleTarget flexiportpy)
+ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/flexiport ${PYTHON_INCLUDE_PATH})
+ ADD_LIBRARY (${pyModuleTarget} MODULE ${srcs})
+ TARGET_LINK_LIBRARIES (${pyModuleTarget} flexiport ${boostPythonLib} ${PYTHON_LIBRARIES})
+ SET_TARGET_PROPERTIES (${pyModuleTarget} PROPERTIES PREFIX "" OUTPUT_NAME "flexiport")
+ INSTALL (TARGETS ${pyModuleTarget} LIBRARY DESTINATION lib/python/site-packages)
+
+ ADD_SUBDIRECTORY (test)
+ELSEIF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ MESSAGE (STATUS "Flexiport Python bindings will not be built - must build flexiport as a shared library.")
+ENDIF (PYTHON_LIBRARIES AND Boost_FOUND AND GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
\ No newline at end of file
Added: gearbox/trunk/src/flexiport/python/flexiport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/flexiport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/flexiport.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,49 @@
+#include <flexiport.h>
+#include <port.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+void TimeoutClassDef (void);
+void PortClassDef (void);
+void SerialPortClassDef (void);
+void TCPPortClassDef (void);
+void LogWriterPortClassDef (void);
+void LogReaderPortClassDef (void);
+
+class PortExceptionWrap : public PortException, public boost::python::wrapper<PortException>
+{
+ public:
+ const char* what (void) const throw ()
+ {
+ if (boost::python::override f = get_override ("what"))
+ return f ();
+ return PortException::what ();
+ }
+ const char* Defaultwhat (void) const throw ()
+ { return PortException::what (); }
+};
+
+Port* (*CreatePort1) (std::map<std::string, std::string>) = &CreatePort;
+Port* (*CreatePort2) (std::string) = &CreatePort;
+
+BOOST_PYTHON_MODULE (flexiport)
+{
+ using namespace boost::python;
+
+ class_<PortException> ("PortException", init<const char*> ())
+ .def (init<const std::string&> ())
+ .def ("what", &PortException::what, &PortExceptionWrap::Defaultwhat)
+ ;
+
+ def ("CreatePort", CreatePort1, return_value_policy<manage_new_object> ());
+ def ("CreatePort", CreatePort2, return_value_policy<manage_new_object> ());
+
+ TimeoutClassDef ();
+ PortClassDef ();
+ SerialPortClassDef ();
+ TCPPortClassDef ();
+ LogWriterPortClassDef ();
+ LogReaderPortClassDef ();
+}
Added: gearbox/trunk/src/flexiport/python/logreaderport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/logreaderport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/logreaderport.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,28 @@
+#include <logreaderport.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+void LogReaderPortClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<LogReaderPort, bases<Port>, boost::noncopyable> ("LogReaderPort",
+ init<std::map<std::string, std::string> > ())
+ .def ("Open", &LogReaderPort::Open)
+ .def ("Close", &LogReaderPort::Close)
+ .def ("Read", &LogReaderPort::Read)
+ .def ("ReadFull", &LogReaderPort::ReadFull)
+ .def ("BytesAvailable", &LogReaderPort::BytesAvailable)
+ .def ("BytesAvailableWait", &LogReaderPort::BytesAvailableWait)
+ .def ("Write", &LogReaderPort::Write)
+ .def ("Flush", &LogReaderPort::Flush)
+ .def ("Drain", &LogReaderPort::Drain)
+ .def ("GetStatus", &LogReaderPort::GetStatus)
+ .def ("SetTimeout", &LogReaderPort::SetTimeout)
+ .def ("SetCanRead", &LogReaderPort::SetCanRead)
+ .def ("SetCanWrite", &LogReaderPort::SetCanWrite)
+ .def ("IsOpen", &LogReaderPort::IsOpen)
+ ;
+}
Added: gearbox/trunk/src/flexiport/python/logwriterport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/logwriterport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/logwriterport.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,30 @@
+#include <logwriterport.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+void LogWriterPortClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<LogWriterPort, bases<Port>, boost::noncopyable> ("LogWriterPort",
+ init<std::map<std::string, std::string> > ())
+ .def ("Open", &LogWriterPort::Open)
+ .def ("Close", &LogWriterPort::Close)
+ .def ("Read", &LogWriterPort::Read)
+ .def ("ReadFull", &LogWriterPort::ReadFull)
+ .def ("Skip", &LogWriterPort::Skip)
+ .def ("SkipUntil", &LogWriterPort::SkipUntil)
+ .def ("BytesAvailable", &LogWriterPort::BytesAvailable)
+ .def ("BytesAvailableWait", &LogWriterPort::BytesAvailableWait)
+ .def ("Write", &LogWriterPort::Write)
+ .def ("Flush", &LogWriterPort::Flush)
+ .def ("Drain", &LogWriterPort::Drain)
+ .def ("GetStatus", &LogWriterPort::GetStatus)
+ .def ("SetTimeout", &LogWriterPort::SetTimeout)
+ .def ("SetCanRead", &LogWriterPort::SetCanRead)
+ .def ("SetCanWrite", &LogWriterPort::SetCanWrite)
+ .def ("IsOpen", &LogWriterPort::IsOpen)
+ ;
+}
Added: gearbox/trunk/src/flexiport/python/port.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/port.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/port.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,195 @@
+#include <port.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+class PortWrap: public Port, public boost::python::wrapper<Port>
+{
+ public:
+ void Open (void) { get_override ("Open") (); }
+ void Close (void) { get_override ("Close") (); }
+
+ ssize_t Read (void * const buffer, size_t count)
+ { return get_override ("Read") (buffer, count); }
+ ssize_t ReadFull (void * const buffer, size_t count)
+ { return get_override ("ReadFull") (buffer, count); }
+
+ ssize_t ReadString (std::string &buffer)
+ {
+ if (boost::python::override f = get_override ("ReadString"))
+ return f (buffer);
+ return Port::ReadString (buffer);
+ }
+ ssize_t DefaultReadString (std::string &buffer)
+ { return Port::ReadString (buffer); }
+
+ ssize_t ReadUntil (void * const buffer, size_t count, uint8_t terminator)
+ {
+ if (boost::python::override f = get_override ("ReadUntil"))
+ return f (buffer, count, terminator);
+ return Port::ReadUntil (buffer, count, terminator);
+ }
+ ssize_t DefaultReadUntil (void * const buffer, size_t count, uint8_t terminator)
+ { return Port::ReadUntil (buffer, count, terminator); }
+
+ ssize_t ReadStringUntil (std::string &buffer, char terminator)
+ {
+ if (boost::python::override f = get_override ("ReadStringUntil"))
+ return f (buffer, terminator);
+ return Port::ReadStringUntil (buffer, terminator);
+ }
+ ssize_t DefaultReadStringUntil (std::string &buffer, char terminator)
+ { return Port::ReadStringUntil (buffer, terminator); }
+
+ ssize_t ReadLine1 (char * const buffer, size_t count)
+ {
+ if (boost::python::override f = get_override ("ReadLine"))
+ return f (buffer, count);
+ return Port::ReadLine (buffer, count);
+ }
+ ssize_t DefaultReadLine1 (char * const buffer, size_t count)
+ { return Port::ReadLine (buffer, count); }
+
+ ssize_t ReadLine2 (std::string &buffer)
+ {
+ if (boost::python::override f = get_override ("ReadLine"))
+ return f (buffer);
+ return Port::ReadLine (buffer);
+ }
+ ssize_t DefaultReadLine2 (std::string &buffer)
+ { return Port::ReadLine (buffer); }
+
+ ssize_t Skip (size_t count)
+ {
+ if (boost::python::override f = get_override ("Skip"))
+ return f (count);
+ return Port::Skip (count);
+ }
+ ssize_t DefaultSkip (size_t count)
+ { return Port::Skip (count); }
+
+ ssize_t SkipUntil (uint8_t terminator, unsigned int count)
+ {
+ if (boost::python::override f = get_override ("SkipUntil"))
+ return f (terminator, count);
+ return Port::SkipUntil (terminator, count);
+ }
+ ssize_t DefaultSkipUntil (uint8_t terminator, unsigned int count)
+ { return Port::SkipUntil (terminator, count); }
+
+ ssize_t BytesAvailable (void) { return get_override ("BytesAvailable") (); }
+ ssize_t BytesAvailableWait (void) { return get_override ("BytesAvailableWait") (); }
+ ssize_t Write (const void * const buffer, size_t count)
+ { return get_override ("Write") (buffer, count); }
+
+ ssize_t WriteFull (const void * const buffer, size_t count)
+ {
+ if (boost::python::override f = get_override ("WriteFull"))
+ return f (buffer, count);
+ return Port::WriteFull (buffer, count);
+ }
+ ssize_t DefaultWriteFull (const void * const buffer, size_t count)
+ { return Port::WriteFull (buffer, count); }
+
+ ssize_t WriteString1 (const char * const buffer)
+ {
+ if (boost::python::override f = get_override ("WriteString"))
+ return f (buffer);
+ return Port::WriteString (buffer);
+ }
+ ssize_t DefaultWriteString1 (const char * const buffer)
+ { return Port::WriteString (buffer); }
+
+ ssize_t WriteString2 (const std::string &buffer)
+ {
+ if (boost::python::override f = get_override ("WriteString"))
+ return f (buffer);
+ return Port::WriteString (buffer);
+ }
+ ssize_t DefaultWriteString2 (const std::string &buffer)
+ { return Port::WriteString (buffer); }
+
+ void Flush (void) { get_override ("Flush") (); }
+ void Drain (void) { get_override ("Drain") (); }
+
+ std::string GetStatus (void) const
+ {
+ if (boost::python::override f = get_override ("GetStatus"))
+ return f ();
+ return Port::GetStatus ();
+ }
+ std::string DefaultGetStatus (void) const
+ { return Port::GetStatus (); }
+
+ void SetTimeout (Timeout timeout) { get_override ("SetTimeout") (timeout); }
+ Timeout GetTimeout (void) const
+ {
+ if (boost::python::override f = get_override ("GetTimeout"))
+ return f ();
+ return Port::GetTimeout ();
+ }
+ Timeout DefaultGetTimeout (void) const
+ { return Port::GetTimeout (); }
+
+ void SetCanRead (bool canRead) { get_override ("SetCanRead") (canRead); }
+ bool CanRead (void) const
+ {
+ if (boost::python::override f = get_override ("CanRead"))
+ return f ();
+ return Port::CanRead ();
+ }
+ bool DefaultCanRead (void) const
+ { return Port::CanRead (); }
+
+ void SetCanWrite (bool canWrite) { get_override ("SetCanWrite") (canWrite); }
+ bool CanWrite (void) const
+ {
+ if (boost::python::override f = get_override ("CanWrite"))
+ return f ();
+ return Port::CanWrite ();
+ }
+ bool DefaultCanWrite (void) const
+ { return Port::CanWrite (); }
+
+ bool IsOpen (void) const { return get_override ("IsOpen") (); }
+};
+
+void PortClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<PortWrap, boost::noncopyable> ("Port", no_init)
+ .def ("Open", pure_virtual (&Port::Open))
+ .def ("Close", pure_virtual (&Port::Close))
+ .def ("Read", pure_virtual (&Port::Read))
+ .def ("ReadFull", pure_virtual (&Port::ReadFull))
+ .def ("ReadString", &Port::ReadString, &PortWrap::DefaultReadString)
+ .def ("ReadUntil", &Port::ReadUntil, &PortWrap::DefaultReadUntil)
+ .def ("ReadStringUntil", &Port::ReadStringUntil, &PortWrap::ReadStringUntil)
+ // The boost::python docs show how to do overloaded functions, and how to do virtual
+ // functions, but not both at the same time... TODO: Figure this out later.
+// .def ("ReadLine", &PortWrap::ReadLine1, &PortWrap::DefaultReadLine1)
+// .def ("ReadLine", &PortWrap::ReadLine2, &PortWrap::DefaultReadLine2)
+ .def ("Skip", &Port::Skip, &PortWrap::DefaultSkip)
+ .def ("SkipUntil", &Port::SkipUntil, &PortWrap::DefaultSkipUntil)
+ .def ("BytesAvailable", pure_virtual (&Port::BytesAvailable))
+ .def ("BytesAvailableWait", pure_virtual (&Port::BytesAvailableWait))
+ .def ("Write", pure_virtual (&Port::Write))
+ .def ("WriteFull", &Port::WriteFull, &PortWrap::DefaultWriteFull)
+// .def ("WriteString", &PortWrap::WriteString1, &PortWrap::DefaultWriteString1)
+// .def ("WriteString", &PortWrap::WriteString2, &PortWrap::DefaultWriteString2)
+ .def ("Flush", pure_virtual (&Port::Flush))
+ .def ("Drain", pure_virtual (&Port::Drain))
+ .def ("GetStatus", &Port::GetStatus, &PortWrap::DefaultGetStatus)
+ .add_property ("portType", &Port::GetPortType)
+ .add_property ("debug", &Port::GetDebug, &Port::SetDebug)
+ .def ("GetTimeout", &Port::GetTimeout, &PortWrap::DefaultGetTimeout)
+ .def ("IsBlocking", &Port::IsBlocking)
+ .def ("SetCanRead", pure_virtual (&Port::SetCanRead))
+ .def ("CanRead", &Port::CanRead, &PortWrap::DefaultCanRead)
+ .def ("SetCanWrite", pure_virtual (&Port::SetCanWrite))
+ .def ("CanWrite", &Port::CanWrite, &PortWrap::DefaultCanWrite)
+ .def ("IsOpen", pure_virtual (&Port::IsOpen))
+ ;
+}
Added: gearbox/trunk/src/flexiport/python/serialport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/serialport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/serialport.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,30 @@
+#include <serialport.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+void SerialPortClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<SerialPort, bases<Port>, boost::noncopyable> ("SerialPort",
+ init<std::map<std::string, std::string> > ())
+ .def ("Open", &SerialPort::Open)
+ .def ("Close", &SerialPort::Close)
+ .def ("Read", &SerialPort::Read)
+ .def ("ReadFull", &SerialPort::ReadFull)
+ .def ("BytesAvailable", &SerialPort::BytesAvailable)
+ .def ("BytesAvailableWait", &SerialPort::BytesAvailableWait)
+ .def ("Write", &SerialPort::Write)
+ .def ("Flush", &SerialPort::Flush)
+ .def ("Drain", &SerialPort::Drain)
+ .def ("GetStatus", &SerialPort::GetStatus)
+ .def ("SetTimeout", &SerialPort::SetTimeout)
+ .def ("SetCanRead", &SerialPort::SetCanRead)
+ .def ("SetCanWrite", &SerialPort::SetCanWrite)
+ .def ("IsOpen", &SerialPort::IsOpen)
+ .def ("SetBaudRate", &SerialPort::SetBaudRate)
+ .def ("GetBaudRate", &SerialPort::GetBaudRate)
+ ;
+}
Added: gearbox/trunk/src/flexiport/python/tcpport.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/tcpport.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/tcpport.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,28 @@
+#include <tcpport.h>
+using namespace flexiport;
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+void TCPPortClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<TCPPort, bases<Port>, boost::noncopyable> ("TCPPort",
+ init<std::map<std::string, std::string> > ())
+ .def ("Open", &TCPPort::Open)
+ .def ("Close", &TCPPort::Close)
+ .def ("Read", &TCPPort::Read)
+ .def ("ReadFull", &TCPPort::ReadFull)
+ .def ("BytesAvailable", &TCPPort::BytesAvailable)
+ .def ("BytesAvailableWait", &TCPPort::BytesAvailableWait)
+ .def ("Write", &TCPPort::Write)
+ .def ("Flush", &TCPPort::Flush)
+ .def ("Drain", &TCPPort::Drain)
+ .def ("GetStatus", &TCPPort::GetStatus)
+ .def ("SetTimeout", &TCPPort::SetTimeout)
+ .def ("SetCanRead", &TCPPort::SetCanRead)
+ .def ("SetCanWrite", &TCPPort::SetCanWrite)
+ .def ("IsOpen", &TCPPort::IsOpen)
+ ;
+}
Added: gearbox/trunk/src/flexiport/python/test/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/python/test/CMakeLists.txt (rev 0)
+++ gearbox/trunk/src/flexiport/python/test/CMakeLists.txt 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1 @@
+INSTALL (FILES serial_example.py DESTINATION share/${PROJECT_NAME}/flexiport/example)
Added: gearbox/trunk/src/flexiport/python/test/serial_example.py
===================================================================
--- gearbox/trunk/src/flexiport/python/test/serial_example.py (rev 0)
+++ gearbox/trunk/src/flexiport/python/test/serial_example.py 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import flexiport, sys, time
+
+def Usage ():
+ print 'Usage: ' + sys.argv[0] + ' [-o portoptions]'
+ print '-o portoptions\tString of options for the port.'
+
+
+def main ():
+ portOptions = 'type=serial,device=/dev/ttyS0,timeout=1'
+
+ if len (sys.argv) == 3:
+ if sys.argv[1] == '-o':
+ portOptions = sys.argv[2]
+ else:
+ Usage ()
+ sys.exit (1)
+ elif len (sys.argv) != 1:
+ Usage ()
+ sys.exit (1)
+
+ try:
+ port = flexiport.CreatePort (portOptions)
+ port.Open ()
+ port.Flush ()
+ print port.GetStatus ()
+
+ print 'Writing data to port, should read same data back.'
+ #stringMessage = 'Message #1'
+ #print 'Writing "' + stringMessage + '" using WriteString()'
+ #if port.WriteString (stringMessage) != len (stringMessage):
+ #print 'Test failed: did not write enough bytes.'
+ #sys.exit (1)
+ #time.sleep (0.1)
+ #print 'Testing ReadString ()'
+ #if port.ReadString (stringBuffer) < 0:
+ #print 'Timeout: Test failed.'
+ #sys.exit (1)
+ #print 'Read back using ReadString(): "' + stringBuffer + '"'
+ #if stringBuffer != stringMessage:
+ #print 'Test failed.'
+ #sys.exit (1)
+
+ stringMessage = 'Message #2'
+ print 'Writing "' + stringMessage + '" plus NULL using Write()'
+ if port.Write (stringMessage, len (stringMessage) + 1) != len (stringMessage) + 1:
+ print 'Test failed: did not write enough bytes.'
+ sys.exit (1)
+ print 'Testing ReadStringUntil()'
+ if port.ReadStringUntil (stringBuffer, '\n') < 0:
+ print 'Timeout: Test failed.'
+ sys.exit (1)
+ print 'Received \"' + stringBuffer + '"'
+ if stringBuffer != stringMessage:
+ print 'Test failed.'
+ sys.exit (1)
+
+ port.Close ()
+ except flexiport.PortException, e:
+ print 'Caught exception: ' + e.what ()
+ sys.exit (1)
+
+
+if __name__ == '__main__':
+ main ()
Added: gearbox/trunk/src/flexiport/python/timeout.cpp
===================================================================
--- gearbox/trunk/src/flexiport/python/timeout.cpp (rev 0)
+++ gearbox/trunk/src/flexiport/python/timeout.cpp 2008-09-30 03:47:56 UTC (rev 310)
@@ -0,0 +1,22 @@
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+
+#include <timeout.h>
+using namespace flexiport;
+
+void TimeoutClassDef (void)
+{
+ using namespace boost::python;
+
+ class_<Timeout> ("Timeout", init<int, int> ())
+ .def (init<const Timeout&> ())
+
+ .def ("AsTimeval", &Timeout::AsTimeval)
+ .def ("FromTimeval", &Timeout::FromTimeval)
+ .def ("AsTimespec", &Timeout::AsTimespec)
+ .def ("FromTimespec", &Timeout::FromTimespec)
+
+ .def_readwrite ("_sec", &Timeout::_sec)
+ .def_readwrite ("_usec", &Timeout::_usec)
+ ;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gb...@us...> - 2008-09-30 03:40:45
|
Revision: 309
http://gearbox.svn.sourceforge.net/gearbox/?rev=309&view=rev
Author: gbiggs
Date: 2008-09-30 03:40:31 +0000 (Tue, 30 Sep 2008)
Log Message:
-----------
Added an option to switch between building shared or static libraries.
Modified Paths:
--------------
gearbox/trunk/cmake/FindIceUtil.cmake
gearbox/trunk/cmake/TargetUtils.cmake
gearbox/trunk/cmake/internal/Setup.cmake
gearbox/trunk/doc/buildsys.dox
gearbox/trunk/retired/urg_nz/CMakeLists.txt
gearbox/trunk/src/basicexample/CMakeLists.txt
gearbox/trunk/src/flexiport/CMakeLists.txt
gearbox/trunk/src/gbxadvancedexample/CMakeLists.txt
gearbox/trunk/src/gbxgarminacfr/CMakeLists.txt
gearbox/trunk/src/gbxserialacfr/CMakeLists.txt
gearbox/trunk/src/gbxserialacfr/lockfile/CMakeLists.txt
gearbox/trunk/src/gbxsickacfr/CMakeLists.txt
gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/CMakeLists.txt
gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/CMakeLists.txt
gearbox/trunk/src/gbxsmartbatteryacfr/CMakeLists.txt
gearbox/trunk/src/gbxutilacfr/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
gearbox/trunk/src/hokuyo_aist/doc.dox
gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt
gearbox/trunk/submitted/gbxnovatelacfr/CMakeLists.txt
gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt
Modified: gearbox/trunk/cmake/FindIceUtil.cmake
===================================================================
--- gearbox/trunk/cmake/FindIceUtil.cmake 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/cmake/FindIceUtil.cmake 2008-09-30 03:40:31 UTC (rev 309)
@@ -27,6 +27,7 @@
# some people may manually choose to install Ice here
/usr/local/include/IceUtil
# windows
+ C:/Ice-3.3.0-VC90/include/IceUtil
C:/Ice-3.3.0-VC80/include/IceUtil
C:/Ice-3.3.0/include/IceUtil
C:/Ice-3.2.1-VC80/include/IceUtil
Modified: gearbox/trunk/cmake/TargetUtils.cmake
===================================================================
--- gearbox/trunk/cmake/TargetUtils.cmake 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/cmake/TargetUtils.cmake 2008-09-30 03:40:31 UTC (rev 309)
@@ -4,9 +4,9 @@
# Usage is the same as ADD_EXECUTABLE, all parameters are passed to ADD_EXECUTABLE.
#
MACRO( GBX_ADD_EXECUTABLE name )
- if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
- endif(COMMAND cmake_policy)
+ IF( COMMAND cmake_policy )
+ CMAKE_POLICY( SET CMP0003 NEW )
+ ENDIF( COMMAND cmake_policy )
ADD_EXECUTABLE( ${name} ${ARGN} )
# SET_TARGET_PROPERTIES( ${name} PROPERTIES
@@ -17,28 +17,46 @@
LIST( APPEND templist ${name} )
# MESSAGE( STATUS "DEBUG: ${templist}" )
SET( EXE_LIST ${templist} CACHE INTERNAL "Global list of executables to build" FORCE )
- MESSAGE( STATUS "Planning to Build Executable: ${name}" )
+ MESSAGE( STATUS "Planning to build executable: ${name}" )
ENDMACRO( GBX_ADD_EXECUTABLE name )
#
# Libraries should add themselves by calling 'GBX_ADD_LIBRARY'
# instead of 'ADD_LIBRARY' in CMakeLists.txt.
-# Usage is the same as ADD_LIBRARY, all parameters are passed to ADD_LIBRARY.
+# The second parameter specifies the library type to build: SHARED, STATIC, or DEFAULT.
+# If the default is used, the library type will depend on the gearbox-wide value as set
+# by the user (or SHARED if the user hasn't changed it from the original setting).
+# All extra parameters are passed to ADD_LIBRARY as source files.
#
-MACRO( GBX_ADD_LIBRARY name )
- if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
- endif(COMMAND cmake_policy)
+MACRO( GBX_ADD_LIBRARY name type )
+ IF( COMMAND cmake_policy )
+ CMAKE_POLICY( SET CMP0003 NEW )
+ ENDIF( COMMAND cmake_policy )
- ADD_LIBRARY( ${name} ${ARGN} )
+ IF( type STREQUAL SHARED )
+ SET( libType SHARED )
+ ELSEIF( type STREQUAL STATIC )
+ SET( libType STATIC )
+ ELSE( type STREQUAL SHARED )
+ SET( libType ${GBX_DEFAULT_LIB_TYPE} )
+ ENDIF( type STREQUAL SHARED )
+
+ ADD_LIBRARY( ${name} ${libType} ${ARGN} )
# SET_TARGET_PROPERTIES( ${name} PROPERTIES
# INSTALL_RPATH "${INSTALL_RPATH};${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}"
# BUILD_WITH_INSTALL_RPATH TRUE )
- INSTALL( TARGETS ${name} LIBRARY DESTINATION lib/${PROJECT_NAME} )
+ INSTALL( TARGETS ${name} DESTINATION lib/${PROJECT_NAME} )
+
SET( templist ${LIB_LIST} )
LIST( APPEND templist ${name} )
SET( LIB_LIST ${templist} CACHE INTERNAL "Global list of libraries to build" FORCE )
- MESSAGE( STATUS "Planning to Build Library : ${name}" )
+
+ IF( libType STREQUAL SHARED )
+ SET( libTypeDesc "shared" )
+ ELSE( libType STREQUAL SHARED )
+ SET( libTypeDesc "static" )
+ ENDIF( libType STREQUAL SHARED )
+ MESSAGE( STATUS "Planning to build ${libTypeDesc} library: ${name}" )
ENDMACRO( GBX_ADD_LIBRARY name )
#
@@ -113,7 +131,7 @@
SET( templist ${ITEM_LIST} )
LIST( APPEND templist ${name} )
SET( ITEM_LIST ${templist} CACHE INTERNAL "Global list of special items to build" FORCE )
- MESSAGE( STATUS "Planning to Build Item : ${name}" )
+ MESSAGE( STATUS "Planning to build item: ${name}" )
ENDMACRO( GBX_ADD_ITEM name )
#
@@ -152,7 +170,7 @@
SET( templist ${TEST_LIST} )
LIST( APPEND templist ${name} )
SET( TEST_LIST ${templist} CACHE INTERNAL "Global list of (CTest) tests to build" FORCE )
-# MESSAGE( STATUS "Planning to Build Test : ${name}" )
+# MESSAGE( STATUS "Planning to build test: ${name}" )
ENDMACRO( GBX_ADD_TEST name executable )
#
@@ -163,7 +181,7 @@
LIST( APPEND templist ${name} )
# MESSAGE( STATUS "DEBUG: ${templist}" )
SET( EXE_NOT_LIST ${templist} CACHE INTERNAL "Global list of executables NOT to build" FORCE )
- MESSAGE( STATUS "Not planning to Build Executable : ${name} because ${reason}" )
+ MESSAGE( STATUS "Not planning to build executable: ${name} because ${reason}" )
ENDMACRO( GBX_NOT_ADD_EXECUTABLE name reason )
#
@@ -174,7 +192,7 @@
LIST( APPEND templist ${name} )
# MESSAGE( STATUS "DEBUG: ${templist}" )
SET( LIB_NOT_LIST ${templist} CACHE INTERNAL "Global list of libraries NOT to build" FORCE )
- MESSAGE( STATUS "Not planning to Build Library : ${name} because ${reason}" )
+ MESSAGE( STATUS "Not planning to build library: ${name} because ${reason}" )
ENDMACRO( GBX_NOT_ADD_LIBRARY name reason )
#
@@ -227,9 +245,10 @@
# IF( NOT ORCA_MOTHERSHIP )
# MESSAGE( STATUS "Using Orca version ${ORCA_VERSION}")
# ENDIF( NOT ORCA_MOTHERSHIP )
- MESSAGE( STATUS "Platform ${CMAKE_SYSTEM}")
- MESSAGE( STATUS "CMake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}-patch ${CMAKE_PATCH_VERSION}")
- MESSAGE( STATUS "Install dir ${CMAKE_INSTALL_PREFIX}")
+ MESSAGE( STATUS "Platform ${CMAKE_SYSTEM}")
+ MESSAGE( STATUS "CMake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}-patch ${CMAKE_PATCH_VERSION}")
+ MESSAGE( STATUS "Install dir ${CMAKE_INSTALL_PREFIX}")
+ MESSAGE( STATUS "Default library type ${GBX_DEFAULT_LIB_TYPE}")
SET( note " " )
LIST_REPORT( "Will build" "executables" ${note} "${EXE_LIST}" )
Modified: gearbox/trunk/cmake/internal/Setup.cmake
===================================================================
--- gearbox/trunk/cmake/internal/Setup.cmake 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/cmake/internal/Setup.cmake 2008-09-30 03:40:31 UTC (rev 309)
@@ -14,14 +14,14 @@
INCLUDE( ${GBX_CMAKE_DIR}/SetupVersion.cmake )
#
-# Project directories, including installation
+# Determine OS, and make os-specific choices
#
-INCLUDE( ${GBX_CMAKE_DIR}/SetupDirectories.cmake )
+INCLUDE( ${GBX_CMAKE_DIR}/SetupOs.cmake )
#
-# Determine OS, and make os-specefic choices
+# Project directories, including installation
#
-INCLUDE( ${GBX_CMAKE_DIR}/SetupOs.cmake )
+INCLUDE( ${GBX_CMAKE_DIR}/SetupDirectories.cmake )
#
# Set the build type (affects debugging symbols and optimization)
@@ -41,6 +41,7 @@
# (these are defaults. after the user modifies these in GUI they stay in cache)
#
OPTION( GBX_BUILD_LICENSE "Enables writing LICENCE file. For admins only." OFF )
+MARK_AS_ADVANCED( GBX_BUILD_LICENSE )
#
# check compiler type and version
@@ -54,6 +55,12 @@
OPTION( GBX_BUILD_TESTS "Enables compilation of all tests" ON )
#
+# Default library type (shared or static).
+#
+SET( GBX_DEFAULT_LIB_TYPE "SHARED" CACHE STRING "Default library type (SHARED or STATIC)" )
+MARK_AS_ADVANCED( GBX_DEFAULT_LIB_TYPE )
+
+#
# Look for low-level C headers, write defines to config.h
#
INCLUDE( ${GBX_CMAKE_DIR}/WriteConfigH.cmake )
Modified: gearbox/trunk/doc/buildsys.dox
===================================================================
--- gearbox/trunk/doc/buildsys.dox 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/doc/buildsys.dox 2008-09-30 03:40:31 UTC (rev 309)
@@ -55,7 +55,7 @@
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxadvanced ${hdrs} )
@@ -160,13 +160,13 @@
@endverbatim
@verbatim
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
@endverbatim
-Here we tell CMake to create rules for building a shared library and to specify dependencies. Now you can see why we bothered with defining variables. These commands are generic and can be easily used for other libraries.
+Here we tell CMake to create rules for building a library of the default type (shared or static) and to specify dependencies. Now you can see why we bothered with defining variables. These commands are generic and can be easily used for other libraries.
@c GBX_ADD_LIBRARY is a custom GearBox macro. It does several things:
-- Actually defines a library target (with a standard command @c ADD_LIBRARY ). In Linux, this will produce @c libGbxAdvanced.so
+- Actually defines a library target (with a standard command @c ADD_LIBRARY ). In Linux, this will produce @c libGbxAdvanced.so or @c libGbxAdvanced.a
- Specifies standard installation directory: @c [PREFIX]/lib/gearbox/
- Adds the name of the library to the global list of libraries which will be built (for feedback).
Modified: gearbox/trunk/retired/urg_nz/CMakeLists.txt
===================================================================
--- gearbox/trunk/retired/urg_nz/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/retired/urg_nz/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -13,7 +13,7 @@
SET( hdrs urg_nz.h )
SET( srcs urg_nz.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
GBX_ADD_PKGCONFIG( ${lib_name} ${lib_desc} "" "" "" "" )
GBX_ADD_HEADERS( ${lib_name} ${hdrs} )
Modified: gearbox/trunk/src/basicexample/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/basicexample/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/basicexample/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -11,7 +11,7 @@
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
GBX_ADD_HEADERS( basicexample ${hdrs} )
# the custom command above is equivalent to this
Modified: gearbox/trunk/src/flexiport/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/flexiport/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -42,7 +42,7 @@
ADD_DEFINITIONS (-DFLEXIPORT_EXPORTS)
ENDIF (WIN32)
ADD_DEFINITIONS (-DFLEXIPORT_EXPORTS)
- GBX_ADD_LIBRARY (${libName} SHARED ${srcs})
+ GBX_ADD_LIBRARY (${libName} DEFAULT ${srcs})
GBX_ADD_PKGCONFIG (${libName} "FlexiPort generic comms library" "" "" "" "")
GBX_ADD_HEADERS (${libName} ${hdrs})
IF (WIN32)
@@ -53,4 +53,9 @@
IF (GBX_BUILD_TESTS)
ADD_SUBDIRECTORY (test)
ENDIF (GBX_BUILD_TESTS)
+
+ OPTION (FLEXIPORT_BUILD_BINDINGS "Build the Python bindings for Flexiport" ON)
+ IF (FLEXIPORT_BUILD_BINDINGS)
+ ADD_SUBDIRECTORY (python)
+ ENDIF (FLEXIPORT_BUILD_BINDINGS)
ENDIF (build)
Modified: gearbox/trunk/src/gbxadvancedexample/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxadvancedexample/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxadvancedexample/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -15,7 +15,7 @@
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxadvancedexample ${hdrs} )
Modified: gearbox/trunk/src/gbxgarminacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxgarminacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxgarminacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -17,7 +17,7 @@
FILE( GLOB srcs *.cpp )
SET( dep_libs ${int_libs} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_PKGCONFIG( ${lib_name} "Garmin GPS driver" "" dep_libs "" "" )
Modified: gearbox/trunk/src/gbxserialacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxserialacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxserialacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -21,7 +21,7 @@
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_PKGCONFIG( ${lib_name} "C++ class wrapping a serial port." "" dep_libs "" "" )
Modified: gearbox/trunk/src/gbxserialacfr/lockfile/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxserialacfr/lockfile/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxserialacfr/lockfile/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -14,7 +14,7 @@
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxserialacfr/lockfile ${hdrs} )
Modified: gearbox/trunk/src/gbxsickacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxsickacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxsickacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -24,7 +24,7 @@
FILE( GLOB srcs *.cpp )
SET( dep_libs ${int_libs} ${private_libs} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_PKGCONFIG( ${lib_name} "Drives SICK hardware, directly connected to the computer." proj_libs int_libs "" "" )
Modified: gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -23,7 +23,7 @@
# for config.h
INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxsickacfr/gbxiceutilacfr ${hdrs} )
Modified: gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxsickacfr/gbxserialdeviceacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -18,7 +18,7 @@
FILE( GLOB srcs *.cpp )
SET( dep_libs ${int_libs} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxsickacfr/gbxserialdeviceacfr ${hdrs} )
Modified: gearbox/trunk/src/gbxsmartbatteryacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxsmartbatteryacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxsmartbatteryacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -16,7 +16,7 @@
FILE( GLOB srcs *.cpp )
SET( dep_libs ${int_libs} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxsmartbatteryacfr ${hdrs} )
Modified: gearbox/trunk/src/gbxutilacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/gbxutilacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/gbxutilacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -14,7 +14,7 @@
# for config.h
INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
GBX_ADD_HEADERS( gbxutilacfr ${hdrs} )
Modified: gearbox/trunk/src/hokuyo_aist/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/hokuyo_aist/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -17,7 +17,7 @@
IF (WIN32)
ADD_DEFINITIONS (-DHOKUYO_AIST_EXPORTS)
ENDIF (WIN32)
- GBX_ADD_LIBRARY (${libName} SHARED ${srcs})
+ GBX_ADD_LIBRARY (${libName} DEFAULT ${srcs})
TARGET_LINK_LIBRARIES (${libName} ${reqLibs})
GBX_ADD_PKGCONFIG (${libName} ${libDesc} ${reqLibs} "" "" "")
Modified: gearbox/trunk/src/hokuyo_aist/doc.dox
===================================================================
--- gearbox/trunk/src/hokuyo_aist/doc.dox 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/hokuyo_aist/doc.dox 2008-09-30 03:40:31 UTC (rev 309)
@@ -7,9 +7,9 @@
@brief Hokuyo URG laser scanner driver.
This library provides a driver for Hokuyo laser scanner devices using the SCIP protocol version 1 or
-2. It has been tested with the Hokuyo URG-04LX and UHG-08LX, but it should work with any scanner
-that conforms to these protocol versions, including the URG-04LX-F01 and UTM-30LX. For a full list
-of functions and classes, see @ref hokuyo_aist.
+2. It has been tested with the Hokuyo URG-04LX, UBG-04LX and UHG-08LX, but it should work with any
+scanner that conforms to these protocol versions, including the URG-04LX-F01 and UTM-30LX. For a
+full list of functions and classes, see @ref hokuyo_aist.
For a full list of classes and functions, see @ref hokuyo_aist.
Modified: gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h
===================================================================
--- gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/hokuyo_aist/hokuyo_aist.h 2008-09-30 03:40:31 UTC (rev 309)
@@ -358,8 +358,6 @@
without having to worry about allocating its data, whether it will change or not, while also
avoiding excessive allocations.
- Not available with the SCIP v1 protocol.
-
@param data Pointer to a @ref HokuyoData object to store the range readings in.
@param clusterCount The number of readings to cluster together into a single reading. The
minimum value from a cluster is returned as the range for that cluster.
@@ -371,8 +369,6 @@
/** @brief Get the latest scan data from the scanner.
- Not available with the SCIP v1 protocol.
-
@param data Pointer to a @ref HokuyoData object to store the range readings in.
@param startAngle The angle to get range readings from. Exclusive; if this falls between two
steps the step inside the angle will be returned, but the step outside won't.
Modified: gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt
===================================================================
--- gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/src/hokuyo_aist/python/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -52,7 +52,7 @@
ENDIF (Boost_FOUND)
ENDIF (CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
-IF (PYTHON_LIBRARIES AND Boost_FOUND)
+IF (PYTHON_LIBRARIES AND Boost_FOUND AND GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
MESSAGE (STATUS "Hokuyo_aist Python bindings will be built.")
SET (srcs hokuyo_aist.cpp)
@@ -64,4 +64,6 @@
INSTALL (TARGETS ${pyModuleTarget} LIBRARY DESTINATION lib/python/site-packages)
ADD_SUBDIRECTORY (test)
-ENDIF (PYTHON_LIBRARIES AND Boost_FOUND)
\ No newline at end of file
+ELSEIF (NOT GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
+ MESSAGE (STATUS "Hokuyo_aist Python bindings will not be built - must build hokuyo_aist as a shared library.")
+ENDIF (PYTHON_LIBRARIES AND Boost_FOUND AND GBX_DEFAULT_LIB_TYPE STREQUAL SHARED)
\ No newline at end of file
Modified: gearbox/trunk/submitted/gbxnovatelacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/submitted/gbxnovatelacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -24,7 +24,7 @@
FILE( GLOB srcs *.cpp )
SET( dep_libs ${int_libs} ${private_libs} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_PKGCONFIG( ${lib_name} "Drives NOVATEL hardware, directly connected to the computer." proj_libs int_libs "" "" )
Modified: gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt 2008-09-23 11:22:20 UTC (rev 308)
+++ gearbox/trunk/submitted/gbxnovatelacfr/gbxnovatelutilacfr/CMakeLists.txt 2008-09-30 03:40:31 UTC (rev 309)
@@ -25,7 +25,7 @@
# for config.h
INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} )
- GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
+ GBX_ADD_LIBRARY( ${lib_name} DEFAULT ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxnovatelacfr/gbxnovatelutilacfr ${hdrs} )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rus...@us...> - 2008-09-23 11:22:29
|
Revision: 308
http://gearbox.svn.sourceforge.net/gearbox/?rev=308&view=rev
Author: russo2503v
Date: 2008-09-23 11:22:20 +0000 (Tue, 23 Sep 2008)
Log Message:
-----------
better exception message
Modified Paths:
--------------
gearbox/trunk/src/gbxgarminacfr/driver.cpp
Modified: gearbox/trunk/src/gbxgarminacfr/driver.cpp
===================================================================
--- gearbox/trunk/src/gbxgarminacfr/driver.cpp 2008-09-13 06:01:24 UTC (rev 307)
+++ gearbox/trunk/src/gbxgarminacfr/driver.cpp 2008-09-23 11:22:20 UTC (rev 308)
@@ -359,7 +359,9 @@
continue;
}
else {
- throw gbxutilacfr::Exception( ERROR_INFO,"More than 3 sequential messages failed the checksum");
+ stringstream ss;
+ ss << "More than "<<nmeaFailChecksumMaxCount<<" sequential messages failed the checksum";
+ throw gbxutilacfr::Exception( ERROR_INFO, ss.str() );
}
}
nmeaFailChecksumCount = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|