16 bool PFInterface::init(std::shared_ptr<HandleInfo> info, std::shared_ptr<ScanConfig> config,
17 std::shared_ptr<ScanParameters> params,
const std::string& topic,
const std::string& frame_id,
18 const uint16_t num_layers)
33 ROS_ERROR(
"Unable to communicate with device. Please check the IP address");
37 if (opi.protocol_name !=
"pfsdp")
43 if (!
handle_version(opi.version_major, opi.version_minor, opi.device_family, topic, frame_id, num_layers))
58 transport_ = std::make_unique<UDPTransport>(info->hostname, info->port);
61 ROS_ERROR(
"Unable to establish UDP connection");
71 transport_ = std::make_unique<TCPTransport>(info->hostname);
78 ROS_ERROR(
"Unable to establish TCP connection");
88 if (
info_->handle.empty())
90 ROS_ERROR(
"Could not acquire communication handle");
111 text =
"Uninitialized";
113 text =
"Initialized";
120 ROS_INFO(
"Device state changed to %s", text.c_str());
129 std::shared_ptr<std::condition_variable> net_cv,
bool& net_fail)
179 float feed_time = std::min(duration, 60.0
f) / 2.0f;
191 ROS_INFO(
"Shutting down pipeline!");
197 std::cout <<
"handling connection failure" << std::endl;
199 std::cout <<
"terminated" << std::endl;
202 std::cout <<
"trying to reconnect..." << std::endl;
203 std::this_thread::sleep_for(std::chrono::milliseconds(500));
209 const std::string& frame_id,
const uint16_t num_layers)
211 std::string expected_dev =
"";
212 if (device_family == 1 || device_family == 3 || device_family == 6)
214 expected_dev =
"R2000";
219 else if (device_family == 5 || device_family == 7)
221 expected_dev =
"R2300";
224 if (device_family == 5)
227 reader_ = std::shared_ptr<PFPacketReader>(
230 else if (device_family == 7)
245 if (product_name.find(expected_dev) != std::string::npos)
254 std::shared_ptr<std::condition_variable> net_cv,
bool& net_fail)
256 std::shared_ptr<Parser<PFPacket>>
parser;
257 std::shared_ptr<Writer<PFPacket>> writer;
260 ROS_DEBUG(
"PacketType is: %s", packet_type.c_str());
261 if (packet_type ==
"A")
265 else if (packet_type ==
"B")
269 else if (packet_type ==
"C")
276 if (packet_type ==
"C1")
void start_watchdog_timer(float duration)
std::shared_ptr< Reader< PFPacket > > reader_
void change_state(PFState state)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ros::Timer watchdog_timer_
PFParser< PFR2000Packet_B > PFR2000_B_Parser
std::shared_ptr< ScanConfig > config_
void feed_watchdog(const ros::TimerEvent &e)
PFParser< PFR2300Packet_C1 > PFR2300_C1_Parser
bool start_transmission(std::shared_ptr< std::mutex > net_mtx, std::shared_ptr< std::condition_variable > net_cv, bool &net_fail)
std::shared_ptr< ScanParameters > params_
PFParser< PFR2000Packet_A > PFR2000_A_Parser
bool can_change_state(PFState state)
std::shared_ptr< HandleInfo > info_
PFParser< PFR2000Packet_C > PFR2000_C_Parser
std::unique_ptr< Transport > transport_
PipelinePtr get_pipeline(const std::string &packet_type, std::shared_ptr< std::mutex > net_mtx, std::shared_ptr< std::condition_variable > net_cv, bool &net_fail)
static const int HANDLE_TYPE_TCP
void connection_failure_cb()
bool handle_version(int major_version, int minor_version, int device_family, const std::string &topic, const std::string &frame_id, const uint16_t num_layers)
static const int HANDLE_TYPE_UDP
std::shared_ptr< PFSDPBase > protocol_interface_