Public Member Functions | Private Member Functions | Private Attributes | List of all members
Communication Class Reference

The Communication class provides access to microcontroller communication. More...

#include <communication.h>

Public Member Functions

 Communication (const std::string &configPath)
 Communication constructor. More...
 
void connect ()
 Tries to setup a connection to a serial devive with a certain device-tag and specified baudrate. More...
 
void disconnect ()
 Terminates a connection to a serial devive with a certain device-tag. More...
 
void enableDebugMessages (debugCallbackPtr debug)
 Enable pass through of every line in the input buffer. More...
 
void enableRawCommunication ()
 Enables the transmission of raw messages to the serial device. More...
 
void registerErrorCallback (debugCallbackPtr error)
 Register a callback to handle transmission/communication errors. More...
 
void registerSensorGroupCallback (const unsigned char &grpNumber, responseCallback cbPtr)
 Register a callback to handle sensor group messages from the serial device. More...
 
bool registerSensorGroups (const std::string &cmdName, unsigned int timeout=100000)
 Register all predefined sensor groups on the serial device. More...
 
void registerTextCallback (debugCallbackPtr text)
 Register a callback to handle plain text messages from the serial device. More...
 
bool sendCommand (const std::string &command, const Parameter::ParameterMap &inputParams, Parameter::ParameterMap &outputParams, unsigned int timeout=100000)
 Send a command to the servial device. More...
 
bool sendCommand (const std::string &command, const std::vector< std::string > &options, const Parameter::ParameterMap &inputParams, Parameter::ParameterMap &outputParams, unsigned int timeout=100000)
 Send a command to the servial device with additional options. More...
 
void sendRawMessage (const std::string &msg)
 Method to send a string directly to the serial device. More...
 
void startCommunication ()
 Start reading the serial input buffer and start parsing threads. More...
 
void stopCommunication ()
 Stop reading the serial input buffer and shutdown parsing threads. More...
 
 ~Communication ()
 Communication default destructor. More...
 

Private Member Functions

void configSerialInterface ()
 Configures the serial connection setup with the provided parameters. More...
 

Private Attributes

CommunicationConfig comCfg
 
std::unordered_map< std::string, std::shared_ptr< Command > > commands
 
std::condition_variable cv
 
ThreadDispatcherdispatcher
 
std::mutex mtx
 
bool rawCommunicationEnabled
 
ReadingThreadrxPolling
 
std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > sensorGroups
 
SensorGroupThreadsensorGroupThread
 
std::shared_ptr< SerialInterfaceParamsserialParams
 
std::shared_ptr< Syntaxsyntax
 

Detailed Description

The Communication class provides access to microcontroller communication.

An instance of this Class is needed to gain access to a connected serial device (e.g. microcontroller). Member functions of this class are used to open and close a connection, as well as sending commands and receiving responses and sensory data.

To instantiate an object of this class, a valid path to a config folder is required. The folder must contain the following files: channels.yml, command_options.yml, commands.yml, gerneral_syntax.yml, sensor_groups.yml, serial_interface_config.yml

Definition at line 36 of file communication.h.

Constructor & Destructor Documentation

Communication::Communication ( const std::string &  configPath)

Communication constructor.

Parameters
[in]configPathpath to the config folder containing all required config files
Exceptions
std::exception

Definition at line 9 of file communication.cpp.

Communication::~Communication ( )

Communication default destructor.

Definition at line 27 of file communication.cpp.

Member Function Documentation

void Communication::configSerialInterface ( )
private

Configures the serial connection setup with the provided parameters.

Exceptions
std::exception

Definition at line 34 of file communication.cpp.

void Communication::connect ( )

Tries to setup a connection to a serial devive with a certain device-tag and specified baudrate.

Exceptions
std::exception

Definition at line 44 of file communication.cpp.

void Communication::disconnect ( )

Terminates a connection to a serial devive with a certain device-tag.

Exceptions
std::exception

Definition at line 54 of file communication.cpp.

void Communication::enableDebugMessages ( debugCallbackPtr  debug)

Enable pass through of every line in the input buffer.

This will call the registered callback whenever there is a new line in the input buffer. The callback decides what to do with that information.

Parameters
[in]debugFunction pointer of the debug callback.
Exceptions
std::exception

Definition at line 60 of file communication.cpp.

void Communication::enableRawCommunication ( )

Enables the transmission of raw messages to the serial device.

Exceptions
std::exception

Definition at line 66 of file communication.cpp.

void Communication::registerErrorCallback ( debugCallbackPtr  error)

Register a callback to handle transmission/communication errors.

The registered function will be called whenever an error during transmission of an outgoing, or parsing of an incoming message occurs. The callback decides what to do with that information.

Parameters
[in]errorFunction pointer of the error callback.
Exceptions
std::exception

Definition at line 168 of file communication.cpp.

void Communication::registerSensorGroupCallback ( const unsigned char &  grpNumber,
responseCallback  cbPtr 
)

Register a callback to handle sensor group messages from the serial device.

The registered function will be called whenever a sensor message with the registred group number has been received from the serial device. The callback decides what to do with that information.

Parameters
[in]grpNumberThe group number is the unique identifier of a sensor group.
[in]cbPtrFunction pointer of the sensor group callback.
Exceptions
std::exception

Definition at line 181 of file communication.cpp.

bool Communication::registerSensorGroups ( const std::string &  cmdName,
unsigned int  timeout = 100000 
)

Register all predefined sensor groups on the serial device.

Parameters
[in]cmdNameunique identifier of the command that provides the functionality to create sensor groups on the serial device.
[in]timeouthow long to wait for a response in micro seconds (Default: 100000)
Exceptions
std::exception

Definition at line 140 of file communication.cpp.

void Communication::registerTextCallback ( debugCallbackPtr  text)

Register a callback to handle plain text messages from the serial device.

The registered function will be called whenever a plain text message has been received from the serial device. The callback decides what to do with that information.

Parameters
[in]textFunction pointer of the text callback.
Exceptions
std::exception

Definition at line 176 of file communication.cpp.

bool Communication::sendCommand ( const std::string &  command,
const Parameter::ParameterMap inputParams,
Parameter::ParameterMap outputParams,
unsigned int  timeout = 100000 
)

Send a command to the servial device.

Use this method to send a predefined command to the serial device. Parameters required in the command message need to be provided in the inputParams ParameterMap. Returned parameters from the response will be put in the provided outputParams ParameterMap.

Parameters
[in]commandunique identifier of the command
[in]inputParamsprovided input parameter values
[out]outputParamsreturned parameter values
[in]timeouthow long to wait for a response in micro seconds (Default: 100000)
Exceptions
std::exception

Definition at line 81 of file communication.cpp.

bool Communication::sendCommand ( const std::string &  command,
const std::vector< std::string > &  options,
const Parameter::ParameterMap inputParams,
Parameter::ParameterMap outputParams,
unsigned int  timeout = 100000 
)

Send a command to the servial device with additional options.

Use this method to send a predefined command to the serial device. By providing a list of unique command option identifiers this command may be modified according to these options. Parameters required in the command message need to be provided in the inputParams ParameterMap. Returned parameters from the response will be put in the provided outputParams ParameterMap.

Parameters
[in]commandunique identifier of the command
[in]optionslist of unique command option identifiers
[in]inputParamsprovided input parameter values
[out]outputParamsreturned parameter values
[in]timeouthow long to wait for a response in micro seconds (Default: 100000)
Exceptions
std::exception

Definition at line 110 of file communication.cpp.

void Communication::sendRawMessage ( const std::string &  msg)

Method to send a string directly to the serial device.

This will send the input string as is. If there is some kind of end-of-message-symbol required from the serial device, it will not be appended automatically.

Parameters
[in]msgInput string to be transmitted
Exceptions
std::exception

Definition at line 71 of file communication.cpp.

void Communication::startCommunication ( )

Start reading the serial input buffer and start parsing threads.

Exceptions
std::exception

Definition at line 50 of file communication.cpp.

void Communication::stopCommunication ( )

Stop reading the serial input buffer and shutdown parsing threads.

Exceptions
std::exception

Definition at line 52 of file communication.cpp.

Member Data Documentation

CommunicationConfig Communication::comCfg
private

Object that stores all given configuration parameters.

Definition at line 176 of file communication.h.

std::unordered_map<std::string, std::shared_ptr<Command> > Communication::commands
private

List of predefined Command objects

Definition at line 179 of file communication.h.

std::condition_variable Communication::cv
private

Condition variable.

Definition at line 186 of file communication.h.

ThreadDispatcher* Communication::dispatcher
private

Thread object that manages multi threaded functionality.

Definition at line 181 of file communication.h.

std::mutex Communication::mtx
mutableprivate

Mutex object.

Definition at line 185 of file communication.h.

bool Communication::rawCommunicationEnabled
private

is direct communication with the serial device enabled?

Definition at line 182 of file communication.h.

ReadingThread* Communication::rxPolling
private

Thread object which polls the serial input buffer.

Definition at line 183 of file communication.h.

std::unordered_map<unsigned char, std::shared_ptr<SensorGroup> > Communication::sensorGroups
private

List of predefined SensorGroup objects

Definition at line 180 of file communication.h.

SensorGroupThread* Communication::sensorGroupThread
private

Thread object which distributes sensor group messages.

Definition at line 184 of file communication.h.

std::shared_ptr<SerialInterfaceParams> Communication::serialParams
private

Object that stores serial connection parameters.

Definition at line 177 of file communication.h.

std::shared_ptr<Syntax> Communication::syntax
private

Object that stores syntax parameters.

Definition at line 178 of file communication.h.


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


pses_ucbridge
Author(s): Sebastian Ehmes
autogenerated on Sat Oct 28 2017 19:16:13