55 namespace message_manager
61 MessageManager::MessageManager()
63 this->num_handlers_ = 0;
64 for (
unsigned int i = 0; i < this->getMaxNumHandlers(); i++)
66 this->handlers_[i] = NULL;
68 this->comms_hndlr_ = NULL;
71 MessageManager::~MessageManager()
80 LOG_INFO(
"Initializing message manager with default comms fault handler");
83 if (NULL != connection)
85 this->getDefaultCommsFaultHandler().init(connection);
91 LOG_ERROR(
"NULL connection passed into manager init");
102 LOG_INFO(
"Initializing message manager");
104 if (NULL != connection && NULL != fault_handler)
106 this->setConnection(connection);
107 this->getPingHandler().init(connection);
108 this->setCommsFaultHandler(fault_handler);
110 if (this->add(&this->getPingHandler()))
117 LOG_WARN(
"Failed to add ping handler, manager won't respond to pings");
123 LOG_ERROR(
"NULL connection or NULL fault handler passed into manager init");
132 void MessageManager::spinOnce()
137 if(!this->getConnection()->isConnected())
139 this->getCommsFaultHandler()->connectionFailCB();
142 if (this->getConnection()->receiveMsg(msg))
158 this->getConnection()->sendMsg(fail);
159 LOG_WARN(
"Unhandled message type encounters, sending failure reply");
166 LOG_ERROR(
"Failed to receive incoming message");
167 this->getCommsFaultHandler()->sendFailCB();
175 if (ms_per_clock <= 0)
176 ms_per_clock = mpGetRtc();
178 mpTaskDelay(sec * 1000 / ms_per_clock);
184 void MessageManager::spin()
186 LOG_INFO(
"Entering message manager spin loop");
196 if (!this->getConnection()->isConnected())
213 if (this->getMaxNumHandlers() > this->getNumHandlers())
215 this->handlers_[this->getNumHandlers()] = handler;
216 this->setNumHandlers(this->getNumHandlers() + 1);
222 LOG_ERROR(
"Max number of handlers exceeded");
226 else if (allow_replace)
228 this->handlers_[idx] = handler;
246 int idx = getHandlerIdx(msg_type);
251 return this->handlers_[idx];
254 int MessageManager::getHandlerIdx(
int msg_type)
259 for (
unsigned int i = 0; i < this->getMaxNumHandlers(); i++)
261 temp = this->handlers_[i];
262 if (NULL == temp)
break;
Interface definition for communications fault handler. Defines the type of communcations faults that ...
void init(const M_string &remappings)
Interface definition for message handlers. The interface defines the callback function that should ex...
Defines an interface and common methods for sending simple messages (see simple_message). This interface makes a bare minimum of assumptions:
#define LOG_WARN(format,...)
bool callback(industrial::simple_message::SimpleMessage &in)
Callback function that should be executed when a message arrives DO NOT OVERRIDE THIS FUNCTION...
This class defines a simple messaging protocol for communicating with an industrial robot controller...
#define LOG_COMM(format,...)
int getMessageType()
Gets message type(see StandardMsgType)
#define LOG_ERROR(format,...)
#define LOG_INFO(format,...)
int getMsgType()
Gets message type that callback expects.
#define LOG_DEBUG(format,...)
bool init(int msgType, int commType, int replyCode, industrial::byte_array::ByteArray &data)
Initializes a fully populated simple message.
ROSCPP_DECL void spinOnce()
int getCommType()
Gets message type(see CommType)