11 const std::unordered_map<
unsigned char, std::shared_ptr<SensorGroup>>&
13 : dispatcher(dispatcher), syntax(syntax), sensorGroups(sensorGroups)
44 std::string msg, original;
50 if (std::count(msg.begin(), msg.end(),
'#') == 1)
52 msg.erase(boost::remove_if(
53 msg, boost::is_any_of(
syntax->channelGrpMsgPrefix)),
62 error(
"Received sensor group id unknown: " +
63 std::to_string(grpNum));
74 catch (std::exception& e)
77 error(
"An exception occured while processing a group message.\n " 79 std::string(e.what()) +
"\n Message was: " + original);
84 msg.erase(boost::remove_if(
85 msg, boost::is_any_of(
syntax->channelGrpMsgPrefix)),
88 int indx = msg.find(
syntax->answerOnCmdPrefix);
89 if (indx == std::string::npos)
93 boost::trim_left(msg);
96 std::vector<std::string> split;
97 boost::split(split, msg, boost::is_any_of(
" "));
100 if (split[0].size() < 1)
102 unsigned char grpNum = 0;
105 grpNum = std::stoul(split[0]);
107 catch (std::exception& e)
110 error(
"Received sensor group id unreadable: " + split[0]);
113 int startIdx = split[0].size();
118 error(
"Received sensor group id unknown: " +
119 std::to_string(grpNum));
122 msg = msg.substr(startIdx, std::string::npos);
131 catch (std::exception& e)
134 error(
"An exception occured while processing a group message.\n " 136 std::string(e.what()) +
"\n Message was: " + original);
SensorGroupThread(std::shared_ptr< Syntax > syntax, ThreadDispatcher *dispatcher, const std::unordered_map< unsigned char, std::shared_ptr< SensorGroup >> &sensorGroups)
SensorGroupThread constructor.
Header file for the SensorGroupThread class.
The ThreadDispatcher class coordinates other communication threads and handles start up and shut down...
boost::function< void(const std::string &)> errorCallbackPtr
void sleep()
Locks the current worker thread until wakeUp() is called.
void workerFunction()
Worker function, responsible for parsing sensor messages and calling the correct sensor group process...
ThreadDispatcher * dispatcher
std::shared_ptr< Syntax > syntax
void stopThread()
Stop parsing incoming sensor group messages.
void registerErrorCallback(errorCallbackPtr error)
Register an error callback that can be called to treat occuing communication and parsing errors...
const bool IsMessageQueueEmpty() const
Is there a message in the message queue?
void wakeUp()
Unlocks the current worker thread.
std::unordered_map< unsigned char, std::shared_ptr< SensorGroup > > sensorGroups
long base64_decode(const std::string &in, const unsigned int startByteIndex, const unsigned int endByteIndex, const unsigned int size, bool isSigned)
Function decodes a Base64 string and returns the decoded string (or only parts of it) up to a maximum...
void startThread()
Start parsing incoming sensor group messages.
void dequeueSensorGroupMessage(std::string &response)
Pop a received sensor group message from the message queue.