rec::robotino::com::Com Class Reference

Represents a communication device. More...

#include <Com.h>

List of all members.

Public Types

enum  Error {
  NoError, ErrorConnectionRefused, ErrorSocketSend, ErrorSocketRead,
  ErrorImageServerCreate, ErrorImageServerBind, ErrorTimeout, ErrorConnectionBusy,
  ErrorClientCreate, ErrorHostNotFound, ErrorUndefined, ErrorWinsock2Initialization,
  ErrorAlreadyConnected
}
 Communication errors. More...
enum  ConnectionState {
  NotConnected = 0, HostLookupState = 1, Connecting = 2, Connected = 3,
  ClosingState = 6
}
 State of connection. More...

Public Member Functions

 Com (bool useQueuedCallback=false)
ComId id () const
void connect (bool isBlocking=true)
void disconnect ()
bool isConnected () const
void setAddress (const char *address)
const char * address () const
void setImageServerPort (unsigned int port=8080)
unsigned int imageServerPort () const
ConnectionState connectionState () const
bool isPassiveMode () const
bool waitForUpdate (unsigned int timeout=200)
void setMinimumUpdateCycleTime (unsigned int msecs)
rec::iocontrol::remotestate::SensorState sensorState ()
void setSetState (const rec::iocontrol::remotestate::SetState &setState)
void processEvents ()
bool hasPendingEvents () const
virtual void errorEvent (Error error, const char *errorString)
virtual void connectedEvent ()
virtual void connectionClosedEvent ()
virtual void connectionStateChangedEvent (ConnectionState newState, ConnectionState oldState)
virtual void updateEvent ()
virtual void modeChangedEvent (bool isPassiveMode)


Detailed Description

Represents a communication device.

Member Enumeration Documentation

Communication errors.

  • NoError no error
  • ErrorConnectionRefused if the connection was refused
  • ErrorSocketSend if a send to the socket failed
  • ErrorSocketRead if a read from the socket failed
  • ErrorImageServerCreate if the creation of the image server failed
  • ErrorImageServerBind if the image server could not bind to the imagePort()
  • ErrorTimeout if Robotino did not send something for more than timeout() milliseconds
  • ErrorConnectionBusy if Robotino is already connected to someone else
  • ErrorClientCreate if the creation of the client socket fails
  • ErrorHostNotFound if a DNS lookup fails
  • ErrorUndefined undefined error
  • ErrorWinsock2Initialization only on Win32 systems if winsock2 could not be initialised

State of connection.

  • NotConnected No connection to Robotino established
  • Connecting Connection setup in progress
  • Connected Connection successfully established


Constructor & Destructor Documentation

rec::robotino::com::Com::Com ( bool  useQueuedCallback = false  ) 

Parameters:
useQueuedCallback If set to false, event functions are called directly from the internal thread of this Com object. Especially in GUI application it is usefull to set useQueuedCallback to true to ensure that event functions are called when calling processEvents().
See also:
processEvents, errorEvent, connectedEvent, connectionClosedEvent, connectionStateChangedEvent, updateEvent, modeChangedEvent, Camera::imageReceivedEvent, Info::infoReceivedEvent


Member Function Documentation

ComId rec::robotino::com::Com::id (  )  const

The unique identifier of this communication object.

Returns:
The identifier.
Exceptions:
nothing. 

void rec::robotino::com::Com::connect ( bool  isBlocking = true  ) 

Connects to the server. This function blocks until the connection is established or an error occurs.

Parameters:
isBlocking If true, this function blocks until the connection is established or an error occurs. Otherwise the function is non blocking and you have to watch for error or connected callbacks.
Exceptions:
In blocking mode a ComException is thrown if the client couldn't connect. In non blocking mode throws nothing.

void rec::robotino::com::Com::disconnect (  ) 

Disconnects from the server and disables autoupdating.

Exceptions:
nothing. 

bool rec::robotino::com::Com::isConnected (  )  const

Test wether the client is connected to the server.

Returns:
TRUE if connected, FALSE otherwise.
Exceptions:
nothing. 

void rec::robotino::com::Com::setAddress ( const char *  address  ) 

Sets the address of the server.

Parameters:
address The address of the server e.g. "172.26.1.1" or "127.0.0.1" To connect to Robotino Sim you also have to specify the server port. The first simulated Robotino listens at port 8080. The address is then "127.0.0.1:8080". Without port specification port 80 (Robotino's default port) is used.
See also:
address
Exceptions:
nothing. 

const char* rec::robotino::com::Com::address (  )  const

Returns the currently active server address.

Returns:
Address set with setAddress
See also:
setAddress
Exceptions:
nothing. 

void rec::robotino::com::Com::setImageServerPort ( unsigned int  port = 8080  ) 

Sets the destination port of the image streamer. Does nothing if we're already connected to a server.

Parameters:
port The destination port of the image streamer e.g. 8080
Exceptions:
nothing. 

unsigned int rec::robotino::com::Com::imageServerPort (  )  const

Retrieve the port number the local UDP server receiving images is connected to. This might be different to the port number set by setImageServerPort if the port is not free. This might happen because you are running more than one instance of Com (in order to drive more than one Robotino) or after destroying a Com object and then creating a new Com object giving the OS not enough time to free the port.

Returns:
Image server port number
See also:
setImageServerPort
Exceptions:
nothing 

ConnectionState rec::robotino::com::Com::connectionState (  )  const

Returns:
The current state of connection

bool rec::robotino::com::Com::isPassiveMode (  )  const

Returns:
Returns true, if this is a connection in passive mode. Passive mode means that you can read Robotino's sensors. But you do not have access to Robotino's actors.
See also:
modeChangedEvent()

bool rec::robotino::com::Com::waitForUpdate ( unsigned int  timeout = 200  ) 

Wait until new sensor readings are available.

Parameters:
timeout The time in milliseconds after which this operation should timeout. If timeout is 0, this does never timeout.
Returns:
Returns true if new sensor readings became available while calling this function. Returns false if the operation lasts for more than timeout milliseconds. Also returns false if the connection is closed (either by an error or by calling disconnect).

void rec::robotino::com::Com::setMinimumUpdateCycleTime ( unsigned int  msecs  ) 

Set the minimum cycle time of the internal thread communicating with Robotino.

Parameters:
msecs The minimum cycle time in milliseconds. A smaler value will lead to a faster update of sensor readings, but will also increase the CPU load. A larger value will lead to slower update of sensor readings but also saves CPU time. The default value is 30. This is a good value when running programms directly on Robotino. If you have a fast CPU you might set this value to 0 to get the fastest communication possible. Values larger than 100 will be interpreted as 100.

void rec::robotino::com::Com::processEvents (  ) 

Call this function from your GUI thread when the Com object was constructed with useQueuedCallback set to true. All callback functions are called from here if callback events are pending. If useQueuedCallback was false when constructing the Com object this function has no effect.

Exceptions:
nothing 

bool rec::robotino::com::Com::hasPendingEvents (  )  const

Check if there are pending callback events. This function will alwasy return false if the Com object was constructed with useQueuedCallback set to false.

Returns:
Returns true if there are pending events, i.e. a call to processEvents will result in calling at least one callback function.
Exceptions:
nothing 
See also:
processEvents

virtual void rec::robotino::com::Com::errorEvent ( Error  error,
const char *  errorString 
) [virtual]

This function is called on errors. Note: This function is called from outside the applications main thread. This is extremely important particularly with regard to GUI applications.

Parameters:
error The error which caused this event.
errorString A human readable error description.
Exceptions:
nothing. 

virtual void rec::robotino::com::Com::connectedEvent (  )  [virtual]

This function is called if a connection to Robotino has been established. Note: This function is called from outside the applications main thread. This is extremely important particularly with regard to GUI applications.

Exceptions:
nothing. 

virtual void rec::robotino::com::Com::connectionClosedEvent (  )  [virtual]

This function is called if a connection is closed. Note: This function is called from outside the applications main thread. This is extremely important particularly with regard to GUI applications.

Exceptions:
nothing. 

virtual void rec::robotino::com::Com::connectionStateChangedEvent ( ConnectionState  newState,
ConnectionState  oldState 
) [virtual]

This function is called whenever the connection state changes

Parameters:
newState The new connection state
oldState The previous connection state

virtual void rec::robotino::com::Com::updateEvent (  )  [virtual]

This function is called whenever sensor readings have been updated

virtual void rec::robotino::com::Com::modeChangedEvent ( bool  isPassiveMode  )  [virtual]

This function is called whenever the mode of connection changes from passive to active or vice versa.

Parameters:
isPassiveMode True if the mode changed to passive mode. False otherwise.


The documentation for this class was generated from the following file:

Generated on Thu Dec 30 08:47:33 2010 for rec_robotino_com_c by  doxygen 1.5.5