30 #include "fsrobo_r_msgs/IOStates.h" 42 namespace io_state_relay_handler
47 ROS_WARN(
"IOStateRelayHandler::init!");
48 this->pub_io_states_ = this->node_.advertise<fsrobo_r_msgs::IOStates>(
"io_states", 1);
56 if (!state_msg.
init(in))
58 LOG_ERROR(
"Failed to initialize state message");
62 return internalCB(state_msg);
67 fsrobo_r_msgs::IOStates io_states;
72 std::vector<fsrobo_r_msgs::Digital> d_in_list;
73 for (
int i = 0; i < 16; i++) {
74 fsrobo_r_msgs::Digital
d;
76 d_in_list.push_back(d);
78 for (
int i = 0; i < 16; i++) {
79 fsrobo_r_msgs::Digital
d;
81 d_in_list.push_back(d);
84 std::vector<fsrobo_r_msgs::Digital> d_out_list;
85 for (
int i = 0; i < 16; i++) {
86 fsrobo_r_msgs::Digital
d;
88 d_out_list.push_back(d);
90 for (
int i = 0; i < 16; i++) {
91 fsrobo_r_msgs::Digital
d;
93 d_out_list.push_back(d);
96 std::vector<fsrobo_r_msgs::Analog> a_in_list;
97 for (
int i = 0; i < 2; i++) {
98 fsrobo_r_msgs::Analog a;
100 a_in_list.push_back(a);
103 io_states.digital_in_states = d_in_list;
104 io_states.digital_out_states = d_out_list;
105 io_states.analog_in_states = a_in_list;
107 this->pub_io_states_.publish(io_states);
110 if (CommTypes::SERVICE_REQUEST == in.
getCommType())
113 in.
toReply(reply, rtn ? ReplyTypes::SUCCESS : ReplyTypes::FAILURE);
114 this->getConnection()->sendMsg(reply);
120 void IOStateRelayHandler::createDigitalMessage(
int data,
int n,
int base_addr, fsrobo_r_msgs::Digital &d)
124 d.addr = base_addr + n;
125 d.state = (bool)(data & mask);
129 void IOStateRelayHandler::createAnalogMessage(
int data,
int n,
int base_ch, fsrobo_r_msgs::Analog &a)
131 const int data_mask = 0x0fff;
132 const int mode_mask = 0x3000;
134 int d = data >> (16 * n);
137 a.state = d & data_mask;
138 a.mode = (d & mode_mask) >> 12;
Class encapsulated robot status message generation methods (either to or from a industrial::simple_me...
industrial::shared_types::shared_int getAnalog(int idx)
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
industrial::shared_types::shared_int getDigital(int idx)
Initializes a full robot status message.
#define LOG_ERROR(format,...)
fsrobo_r_driver::simple_message::io_state::IOState state_
virtual bool toReply(industrial::simple_message::SimpleMessage &msg, industrial::simple_message::ReplyType reply)