74 throw std::runtime_error(
"Raw communication mode not enabled!");
76 std::string send = msg;
86 if(
commands.find(command)==
commands.end())
throw std::out_of_range(
"Command: "+command+
" does not exist!");
87 ros::Time t = ros::Time::now();
89 std::unique_lock<std::mutex> lck(
mtx);
92 commands[command]->generateCommand(inputParams, cmd);
94 cmd = cmd +
syntax->endOfFrame;
96 cv.wait_for(lck, std::chrono::microseconds(timeout));
102 if (
commands[command]->verifyResponse(inputParams, response, outputParams))
111 const std::vector<std::string>& options,
114 unsigned int timeout)
116 if(
commands.find(command)==
commands.end())
throw std::out_of_range(
"Command: "+command+
" does not exist!");
117 ros::Time t = ros::Time::now();
119 std::unique_lock<std::mutex> lck(
mtx);
121 std::string response;
122 commands[command]->generateCommand(inputParams,options, cmd);
124 cmd = cmd +
syntax->endOfFrame;
126 cv.wait_for(lck, std::chrono::microseconds(timeout));
132 if (
commands[command]->verifyResponse(inputParams, options, response, outputParams))
141 unsigned int timeout)
143 if(
commands.find(cmdName)==
commands.end())
throw std::out_of_range(
"Command: "+cmdName+
" does not exist!");
148 std::unique_lock<std::mutex> lck(
mtx);
150 std::string response;
151 grp.second->createSensorGroupCommand(*
commands[cmdName], cmd);
153 cmd = cmd +
syntax->endOfFrame;
155 cv.wait_for(lck, std::chrono::microseconds(timeout));
162 if (!grp.second->verifyResponseOnComand(*
commands[cmdName], response))
172 grp.second->registerErrorCallback(error);
Header file for the Communication class.
const bool IsResponseQueueEmpty() const
Is there a response in the response queue?
std::unordered_map< std::string, std::shared_ptr< Command > > commands
void startCommunication()
Start reading the serial input buffer and start parsing threads.
bool registerSensorGroups(const std::string &cmdName, unsigned int timeout=100000)
Register all predefined sensor groups on the serial device.
static SerialInterface & instance()
Returns a singleton auf this class.
boost::function< void(SensorGroup *)> responseCallback
void enableRawCommunication()
Enables the transmission of raw messages to the serial device.
void sendRawMessage(const std::string &msg)
Method to send a string directly to the serial device.
The ThreadDispatcher class coordinates other communication threads and handles start up and shut down...
void stopCommunication()
Stop reading the serial input buffer and shutdown parsing threads.
void connect()
Tries to setup a connection to a serial devive with a certain device-tag and specified baudrate...
std::condition_variable cv
SensorGroupThread * sensorGroupThread
The ReadingThread class implements threadded polling of the serial input buffer.
void enableDebugMessages(debugCallbackPtr debug)
Enable pass through of every line in the input buffer.
The Parameter::ParameterMap class provides a map functionality for Parameter::Parameter objects conta...
bool sendCommand(const std::string &command, const Parameter::ParameterMap &inputParams, Parameter::ParameterMap &outputParams, unsigned int timeout=100000)
Send a command to the servial device.
void registerErrorCallback(debugCallbackPtr error)
Register a callback to handle transmission/communication errors.
void registerErrorCallback(debugCallbackPtr error)
Register a callback to handle transmission/communication errors.
void disconnect()
Terminates a connection to a serial devive with a certain device-tag.
void configSerialInterface()
Configures the serial connection setup with the provided parameters.
void enableDebugMessages(debugCallbackPtr debug)
Enable pass through of every line in the input buffer.
void setSerialTimeout(unsigned int serialTimeout)
Setter for the serial timeout.
ReadingThread * rxPolling
void setMaxLineLength(unsigned int maxLineLength)
Setter for the maximum line length.
void registerTextCallback(debugCallbackPtr text)
Register a callback to handle plain text messages from the serial device.
void registerSensorGroupCallback(const unsigned char &grpNumber, responseCallback cbPtr)
Register a callback to handle sensor group messages from the serial device.
void disconnect()
try to close the connection to the serial device
void setCommunicationCondVar(std::condition_variable *condVar)
Register the condition variable of the Communication object in order to wakeup a waiting command resp...
void setReadingThread(ReadingThread *rxThread)
Register ReadingThread with the thread dispatcher.
void startThread()
Start dispatching thread, SensorGroupThread and ReadingThread.
const std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > & getSensorGroups() const
SensorGroup map object getter.
void setBaudRate(unsigned int baudRate)
Setter for the baudrate, which defines the bandwith of the communication.
const std::shared_ptr< SerialInterfaceParams > getSerialInterfaceParams() const
SerialInterfaceParams object getter.
~Communication()
Communication default destructor.
void setDeviceTag(const std::string &deviceTag)
Setter for the device tag, which is an identifier a the connected serial device.
void connect()
try to open a connection to the serial device
void stopThread()
Stop dispatching thread, SensorGroupThread and ReadingThread.
void setSerialDevicesFolder(const std::string &serialDevicesFolder)
Setter for the path to the devices folder.
boost::function< void(const std::string &)> debugCallbackPtr
const std::shared_ptr< Syntax > getSyntax() const
Syntax object getter.
void setSensorGroupThread(SensorGroupThread *grpThread)
Register SensorGroupThread with the thread dispatcher.
CommunicationConfig comCfg
The CommunicationConfig class parses config files and provides configuration parameters to a Communca...
void send(std::string &message)
try to send a message to the serial device
void setCommunicationWakeUp(bool wakeUp)
Set wether there is a command response thread waiting or not.
ThreadDispatcher * dispatcher
std::shared_ptr< SerialInterfaceParams > serialParams
std::shared_ptr< Syntax > syntax
The SerialInterface class provides an interface to a connected serial device.
std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > sensorGroups
void enableRawCommunication()
Enables the transmission of raw messages to the serial device.
void dequeueResponse(std::string &response)
Pop a received command response from the response queue.
The SensorGroupThread class implements functionality to extract the group identifier of an incoming s...
const std::unordered_map< std::string, std::shared_ptr< Command > > & getCommands() const
Command map getter.
Communication(const std::string &configPath)
Communication constructor.
bool rawCommunicationEnabled
void registerTextCallback(debugCallbackPtr text)
Register a callback to handle plain text messages from the serial device.