27 #include <boost/bind.hpp>
28 #include <console_bridge/console.h>
40 using namespace boost::asio;
41 using boost::asio::ip::udp;
46 using serialization::BufferReader;
47 using serialization::BufferWriter;
49 IOScanner::IOScanner(io_service& io_service,
string hostname)
50 : socket_(io_service), hostname_(hostname)
52 CONSOLE_BRIDGE_logInform(
"Opening UDP socket... ");
56 boost::asio::placeholders::error,
57 boost::asio::placeholders::bytes_transferred));
58 CONSOLE_BRIDGE_logInform(
"done.");
63 CONSOLE_BRIDGE_logInform(
"Sending List Identity Request... ");
65 udp::resolver::query q(udp::v4(),
hostname_,
"44818");
66 udp::endpoint receiver_endpoint = *r.resolve(q);
73 CONSOLE_BRIDGE_logInform(
"done.");
77 std::size_t num_bytes)
81 CONSOLE_BRIDGE_logError(
"Error receiving list identity response message");
92 CONSOLE_BRIDGE_logWarn(
"Packet received with %zu bytes, but only %zu bytes used", num_bytes, r.
getByteCount());
97 CONSOLE_BRIDGE_logError(
"Reply received with wrong command. Expected %u, received %u",
EIP_CMD_LIST_IDENTITY,
107 CONSOLE_BRIDGE_logWarn(
"Non-zero status received: %zu", pkt.
getHeader().
status);
111 CONSOLE_BRIDGE_logWarn(
"Non-zero sender context received: %zu, %zu", pkt.
getHeader().
context[0],
116 CONSOLE_BRIDGE_logWarn(
"Non-zero options received: %zu", pkt.
getHeader().
options);
124 CONSOLE_BRIDGE_logError(
"No items in list identity payload!");
129 CONSOLE_BRIDGE_logWarn(
"More than one item in list identity payload %u", payload.
getItemCount());
134 CONSOLE_BRIDGE_logError(
"Error: Payload response received with the wrong item type. Expected: %zu, received %zu",
140 payload.
getItems().at(0).getDataAs(
id);
142 CONSOLE_BRIDGE_logInform(
"=== Received ID Message ===");
143 CONSOLE_BRIDGE_logInform(
"Encapsulation Protocol Version: %d", (
int)
id.encap_protocol_version);
144 CONSOLE_BRIDGE_logInform(
"Address: %d : %d", inet_ntoa(
id.sockaddr.sin_addr), ntohs(
id.sockaddr.sin_port));
145 CONSOLE_BRIDGE_logInform(
"Vendor ID: %d", (
int)
id.vendor_id);
146 CONSOLE_BRIDGE_logInform(
"Device Type: %d", (
int)
id.device_type);
147 CONSOLE_BRIDGE_logInform(
"Product Code: %d", (
int)
id.product_code);
148 CONSOLE_BRIDGE_logInform(
"Revision: %d.%d", (
int)
id.revision[0], (
int)
id.revision[1]);
149 CONSOLE_BRIDGE_logInform(
"Status: %d", (
int)
id.status);
150 CONSOLE_BRIDGE_logInform(
"Serial Number: %d", (
int)
id.serial_number);
151 CONSOLE_BRIDGE_logInform(
"Product Name: %s",
id.product_name.c_str());
152 CONSOLE_BRIDGE_logInform(
"State: %d", (
int)
id.state);
154 catch (std::length_error e)
156 printf(
"ERROR: Packet too short for identity response\n");
163 CONSOLE_BRIDGE_logInform(
"Waiting for responses.");