Revision: 6975
http://playerstage.svn.sourceforge.net/playerstage/?rev=6975&view=rev
Author: thjc
Date: 2008-08-21 22:07:55 +0000 (Thu, 21 Aug 2008)
Log Message:
-----------
Updated Serial Stream to use file watcher
Modified Paths:
--------------
code/player/branches/release-2-1-patches/server/drivers/opaque/serialstream.cc
Modified:
code/player/branches/release-2-1-patches/server/drivers/opaque/serialstream.cc
===================================================================
---
code/player/branches/release-2-1-patches/server/drivers/opaque/serialstream.cc
2008-08-21 12:54:20 UTC (rev 6974)
+++
code/player/branches/release-2-1-patches/server/drivers/opaque/serialstream.cc
2008-08-21 22:07:55 UTC (rev 6975)
@@ -23,11 +23,11 @@
/** @ingroup drivers Drivers */
/** @{ */
/*
- *
+ *
The serialstream driver reads form a serial port continuously and publishes
the data.
Currently this is usable with the SickS3000 driver and the Nav200 driver. This
driver does
no interpretation of data output, merely reading it and publishing it, or, if
it is sent a
-data command it will write whatever it recieves onto the serial port
+data command it will write whatever it recieves onto the serial port
@par Compile-time dependencies
@@ -45,7 +45,7 @@
- PLAYER_LASER_REQ_GET_GEOM
- PLAYER_LASER_REQ_GET_CONFIG
-
+
@par Configuration file options
- port (string)
@@ -61,9 +61,9 @@
- buffer_size (integer
- The size of the buffer to be used when reading, this is the maximum that
can be read in one read command
- Default 4096
-
[EMAIL PROTECTED] Example
[EMAIL PROTECTED] Example
+
@verbatim
driver
(
@@ -85,8 +85,8 @@
*/
/** @} */
-
+
// ONLY if you need something that was #define'd as a result of configure
// (e.g., HAVE_CFMAKERAW), then #include <config.h>, like so:
/*
@@ -146,7 +146,7 @@
// Must implement the following methods.
virtual int Setup();
virtual int Shutdown();
-
+
// This method will be invoked on each incoming message
virtual int ProcessMessage(QueuePointer &resp_queue,
player_msghdr * hdr,
@@ -167,35 +167,35 @@
// Close the terminal
// Returns 0 on success
virtual int CloseTerm();
-
+
// Set the io flags.
// Just a little helper function that sets the parity and so on.
void UpdateFlags();
-
+
// Set the terminal speed
// Valid values are 9600, 19200, 38400, 115200
// Returns 0 on success
virtual int ChangeTermSpeed(int speed);
-
+
protected:
//int transfer_rate; // Desired rate for operation
int current_rate;
-
+
// Name of device used to communicate with the laser
//const char *device_name;
-
+
uint8_t * rx_buffer;
//unsigned int rx_buffer_size;
-
+
struct termios oldtio;
-
+
// opaque device file descriptor
- int opaque_fd;
-
+ int opaque_fd;
+
// Properties
IntProperty buffer_size, transfer_rate;
StringProperty port, parity;
-
+
// This is the data we store and send
player_opaque_data_t mData;
@@ -236,7 +236,7 @@
this->RegisterProperty ("port", &this->port, cf, section);
this->RegisterProperty ("transfer_rate", &this->transfer_rate, cf,
section);
this->RegisterProperty ("parity", &this->parity, cf, section);
-
+
rx_buffer = new uint8_t[buffer_size];
assert(rx_buffer);
@@ -276,7 +276,7 @@
{
// Stop and join the driver thread
StopThread();
-
+
CloseTerm();
PLAYER_MSG0(2, "Opaque Driver Shutdown");
@@ -287,7 +287,7 @@
int SerialStream::ProcessMessage(QueuePointer & resp_queue,
player_msghdr* hdr,
void* data)
-{
+{
// Process messages here. Send a response if necessary, using
Publish().
// If you handle the message successfully, return 0. Otherwise,
// return -1, and a NACK will be sent for you, if a response is
required.
@@ -299,8 +299,8 @@
PLAYER_MSG1(2, "%s", req.key);
if (strcmp("transfer_rate", req.key) == 0)
{
- res = ChangeTermSpeed(req.value);
-
+ res = ChangeTermSpeed(req.value);
+
// Check the error code
if (res == 0)
{
@@ -352,7 +352,7 @@
{
fprintf(stderr,"Error restoring file mode (%d - %s),
disabling\n",errno,strerror(errno));
}
-
+
return (0);
}
@@ -369,7 +369,7 @@
for(;;)
{
// test if we are supposed to cancel
- pthread_testcancel();
+ Wait(1);
// Process incoming messages. SerialStream::ProcessMessage() is
// called on each message.
@@ -377,9 +377,6 @@
// Reads the data from the serial port and then publishes it
ReadData();
-
- // Sleep (you might, for example, block on a read() instead)
- usleep(100000);
}
}
@@ -396,20 +393,22 @@
port.GetValue(), strerror(errno));
return -1;
}
-
+
// save the current io settings
tcgetattr(opaque_fd, &oldtio);
-
+
// set up new settings
UpdateFlags();
if (ChangeTermSpeed(transfer_rate))
return -1;
-
+
// Make sure queue is empty
tcflush(this->opaque_fd, TCIOFLUSH);
usleep(1000);
tcflush(opaque_fd, TCIFLUSH);
-
+
+ AddFileWatch(opaque_fd);
+
return 0;
}
@@ -434,7 +433,7 @@
newtio.c_cflag |= PARENB | PARODD;
else
PLAYER_WARN("Invalid parity. Defaulting to none.");
-
+
tcsetattr(opaque_fd, TCSANOW, &newtio);
tcflush(opaque_fd, TCIOFLUSH);
}
@@ -477,13 +476,13 @@
case B115200:
if( tcgetattr( this->opaque_fd, &term ) < 0 )
RETURN_ERROR(1, "unable to get device attributes");
-
+
//cfmakeraw( &term );
if(cfsetispeed( &term, term_speed ) < 0 || cfsetospeed( &term,
term_speed ) < 0)
{
RETURN_ERROR(1, "failed to set serial baud rate");
}
-
+
if( tcsetattr( this->opaque_fd, TCSAFLUSH, &term ) < 0 )
RETURN_ERROR(1, "unable to set device attributes");
break;
@@ -502,6 +501,8 @@
//
int SerialStream::CloseTerm()
{
+ RemoveFileWatch(opaque_fd);
+
::close(this->opaque_fd);
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit