Connection_Impl_Base
Connection_Impl_Base
Connection_Impl

An Abstract Base Class for various connection types.

Functions
~Connection_Impl_Base
virtual ~Connection_Impl_Base()

Destroys the Connection_Impl_Base object

establishConnection
virtual void establishConnection() = 0

Initializes and opens the current connection.

description
virtual std::string description() = 0

Gets a description of the connection as a string

Returns

A description of the connection

disconnect
virtual void disconnect() = 0

Closes the current connection.

reconnect
virtual void reconnect() = 0

Reopens a connection that has been disconnected.

registerParser
virtual void registerParser(
std::function<void(DataBuffer&)> parseFunction
) = 0

Registers a function to handle the parsing of data when it is read in.

Parameters
parseFunction
std::function<void(DataBuffer&)>

The function to call to parse data that is read in.

Exceptions
unregisterParser
virtual void unregisterParser() = 0

Unregisters the function to handle the parsing of data when it is read in

throwIfError
virtual void throwIfError() = 0

Throws an exception if a connection error has occurred.

Exceptions
write
virtual void write(
const ByteStream &data
) = 0

Writes bytes to the port via the BoostCommunication object.

Parameters
data
const ByteStream&

the bytes that will be written to the port.

Exceptions
write
virtual void write(
const Bytes &bytes
) = 0

Writes the given bytes to the port via the BoostCommunication object.

Parameters
bytes
const Bytes&

The bytes to write.

Exceptions
clearBuffer
virtual void clearBuffer() = 0

Resets the read buffer.

byteReadPos
virtual std::size_t byteReadPos() const = 0

Gets the read position from the byte buffer.

byteAppendPos
virtual std::size_t byteAppendPos() const = 0

Gets the append position from the byte buffer.

rawByteMode
virtual void rawByteMode(
bool enable
) = 0

Puts the connection into "Raw Byte Mode."  "Raw Byte Mode" stops the data from being sent/parsed from any attached devices (BaseStation, InertialNode, etc.)  and instead sends all data into a raw circular data buffer that can be accessed by calling getRawBytes on this Connection object.  Disabling this mode will start sending all data back to the previous attached device, if still available.

Parameters
enable
bool

whether to enable raw byte mode (true), or disable raw byte mode (false).

Exceptions
getRawBytes
virtual void getRawBytes(
Bytes &bytes,
uint32 timeout 0,
uint32 maxBytes 0
) = 0

Gets all of the raw bytes that are available that have been collected when the Connection is in "Raw Byte Mode."  If the Connection has not been put into "Raw Byte Mode" by calling rawByteMode, no data can be retrieved from this function.

Parameters
bytes

A Bytes vector to hold the result.

timeout
uint32

the timeout, in milliseconds, to wait for the data if necessary (default of 0).

maxBytes
uint32

The maximum number of bytes to return. If this is 0 (default), all bytes will be returned.

Connection_Impl
public
Connection_Impl_Base
template <typename Comm_Object>
Connection_Impl

An Abstract Base Class for various connection types.  This class uses a template for the Comm Object and contains default functionality for connection types.

See Also

SerialConnection

Functions
~Connection_Impl
virtual ~Connection_Impl()

Destroys the Connection_Impl object

Variables
m_comm
std::unique_ptr< BoostCommunication<Comm_Object> > m_comm

A BoostCommunication object used for actual read/write operations.

m_ioService
std::unique_ptr<boost::asio::io_service> m_ioService

The boost::asio::io_service object.

m_ioPort
std::unique_ptr<Comm_Object> m_ioPort

The actual boost communication object (ex. boost::asio::serial_port, tcp::socket, etc.)

m_readThread
std::unique_ptr<std::thread> m_readThread

The thread used to run the operation of reading in bytes from the BaseStation.

m_established
bool m_established

true if the connection has been established, false otherwise.

m_parseFunction
std::function<void(
DataBuffer&
)> m_parseFunction

The function to call to parse data that is read in.

m_rawByteBuffer
boost::circular_buffer_space_optimized<uint8> m_rawByteBuffer

The circular buffer to store data when in "Raw Byte Mode."

m_rawByteBufferCondition
std::condition_variable m_rawByteBufferCondition

Allows the raw byte buffer to know when data has been added.

m_connectionError
bool m_connectionError

true if an error has occurred with the connection, false otherwise.

m_errorCode
int m_errorCode

The error code of the connection error, if there was a connection error.

m_errorMsg
std::string m_errorMsg

The error message of the connection error, if there was a connection error.

m_rawByteMode
bool m_rawByteMode

true if the connection is in "Raw Byte Mode", false otherwise.

m_rawDataMutex
std::mutex m_rawDataMutex

The mutex used to access the "Raw Byte Mode" buffer.

Functions
establishConnection
virtual void establishConnection() = 0

Initializes and opens the current connection.

description
virtual std::string description() = 0

Gets a description of the connection as a string.

Returns

A description of the connection.

disconnect
virtual void disconnect() override

Closes the current connection.

reconnect
virtual void reconnect() override

Reopens a connection that has been disconnected.

registerParser
virtual void registerParser(
std::function<void(DataBuffer&)> parseFunction
) final

Registers a function to handle the parsing of data when it is read in.

Parameters
parseFunction
std::function<void(DataBuffer&)>

The function to call to parse data that is read in.

Exceptions
unregisterParser
virtual void unregisterParser() final

Unregisters the function to handle the parsing of data when it is read in.

throwIfError
virtual void throwIfError() final

Throws an exception if a connection error has occurred.

Exceptions
write
virtual void write(
const ByteStream &data
) final

Writes bytes to the port via the BoostCommunication object.

Parameters
data
const ByteStream&

the bytes that will be written to the port.

Exceptions
write
virtual void write(
const Bytes &bytes
) final

Writes the given bytes to the port via the BoostCommunication object.

Parameters
bytes
const Bytes&

The bytes to write.

Exceptions
clearBuffer
virtual void clearBuffer() final

Clears the read buffer.

byteReadPos
virtual std::size_t byteReadPos() const final

Gets the read position from the byte buffer.

byteAppendPos
virtual std::size_t byteAppendPos() const final

Gets the append position from the byte buffer.

startIoThread
void startIoThread()

Starts the main thread for reading in all the data and handling write commands

stopIoThread
void stopIoThread()

Stops the main thread, canceling all reading and writing

rawByteMode
virtual void rawByteMode(
bool enable
) final

Puts the connection into "Raw Byte Mode."  "Raw Byte Mode" stops the data from being sent/parsed from any attached devices (BaseStation, InertialNode, etc.)  and instead sends all data into a raw circular data buffer that can be accessed by calling getRawBytes on this Connection object.  Disabling this mode will start sending all data back to the previous attached device, if still available.

Parameters
enable
bool

whether to enable raw byte mode (true), or disable raw byte mode (false).

Exceptions
getRawBytes
virtual void getRawBytes(
Bytes &bytes,
uint32 timeout 0,
uint32 maxBytes 0
) final

Gets all of the raw bytes that are available that have been collected when the Connection is in "Raw Byte Mode."  If the Connection has not been put into "Raw Byte Mode" by calling rawByteMode, no data can be retrieved from this function.

Parameters
bytes

A Bytes vector to hold the result.

timeout
uint32

the timeout, in milliseconds, to wait for the data if necessary (default of 0).

maxBytes
uint32

The maximum number of bytes to return. If this is 0 (default), all bytes will be returned.

collectRawData
void collectRawData(
DataBuffer &data
)

The function to be sent to the communication object to parse data for "Raw Byte Mode."

Parameters
data

The DataBuffer that contains all of the data that was read in from the connection.