mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-09 14:27:02 +08:00
feat: add help command and LLA parameter support in set_device_ip tool
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include <orbbec_camera/ob_camera_node_driver.h>
|
||||
#include <orbbec_camera/utils.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -23,7 +24,33 @@ bool parseIpString(const std::string &ip_str, uint8_t ip[4]) {
|
||||
return i == 4;
|
||||
}
|
||||
|
||||
void printHelp() {
|
||||
std::cout << "Usage:\n"
|
||||
<< " ros2 run orbbec_camera set_device_ip --ros-args [params]\n\n"
|
||||
<< "Parameters:\n"
|
||||
<< " -p old_ip:=<ip> Current device IP (default: 192.168.1.10)\n"
|
||||
<< " -p port:=<port> Device port (default: 8090)\n"
|
||||
<< " -p dhcp:=<bool> Enable DHCP (default: false)\n"
|
||||
<< " -p lla:=<bool> Enable LLA (default: false)\n"
|
||||
<< " -p new_ip:=<ip> New static IP (default: 192.168.1.200)\n"
|
||||
<< " -p mask:=<ip> Subnet mask (default: 255.255.255.0)\n"
|
||||
<< " -p gateway:=<ip> Gateway (default: 192.168.1.1)\n\n"
|
||||
<< "Examples:\n"
|
||||
<< " ros2 run orbbec_camera set_device_ip --ros-args "
|
||||
"-p old_ip:=192.168.1.10 -p new_ip:=192.168.1.200\n"
|
||||
<< " ros2 run orbbec_camera set_device_ip --ros-args "
|
||||
"-p old_ip:=192.168.1.10 -p dhcp:=true\n";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string arg(argv[i]);
|
||||
if (arg == "-h" || arg == "--help") {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
rclcpp::init(argc, argv);
|
||||
auto node = std::make_shared<rclcpp::Node>("set_device_ip");
|
||||
auto logger = node->get_logger();
|
||||
@@ -31,6 +58,7 @@ int main(int argc, char **argv) {
|
||||
std::string device_ip_str = node->declare_parameter<std::string>("old_ip", "192.168.1.10");
|
||||
int port = node->declare_parameter<int>("port", 8090);
|
||||
bool dhcp = node->declare_parameter<bool>("dhcp", false);
|
||||
bool lla = node->declare_parameter<bool>("lla", false);
|
||||
std::string new_ip_str = node->declare_parameter<std::string>("new_ip", "192.168.1.200");
|
||||
std::string mask_str = node->declare_parameter<std::string>("mask", "255.255.255.0");
|
||||
std::string gateway_str = node->declare_parameter<std::string>("gateway", "192.168.1.1");
|
||||
@@ -61,6 +89,13 @@ int main(int argc, char **argv) {
|
||||
device->setStructuredData(OB_STRUCT_DEVICE_IP_ADDR_CONFIG,
|
||||
reinterpret_cast<const uint8_t *>(&ip_config), sizeof(ip_config));
|
||||
|
||||
if (device->isPropertySupported(OB_PROP_DEVICE_NETWORK_LLA_BOOL, OB_PERMISSION_READ_WRITE)) {
|
||||
device->setBoolProperty(OB_PROP_DEVICE_NETWORK_LLA_BOOL, lla);
|
||||
RCLCPP_INFO(logger, "LLA mode %s.", lla ? "enabled" : "disabled");
|
||||
} else {
|
||||
RCLCPP_WARN(logger, "LLA property is not supported on this device.");
|
||||
}
|
||||
|
||||
RCLCPP_INFO(logger, "IP configuration applied successfully.");
|
||||
if (dhcp) {
|
||||
RCLCPP_INFO(logger, "DHCP mode enabled.");
|
||||
@@ -83,4 +118,4 @@ int main(int argc, char **argv) {
|
||||
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user