add get device info srv

This commit is contained in:
Joe Dong
2022-06-07 21:21:43 +08:00
parent 2e1adc25e4
commit a9e3342d2c
7 changed files with 52 additions and 12 deletions
+29
View File
@@ -93,6 +93,12 @@ void OBCameraNode::setupCameraCtrlServices() {
std::shared_ptr<SetInt32::Response> response) {
setWhiteBalanceCallback(request_header, request, response);
});
get_device_srv_ = node_->create_service<GetDeviceInfo>(
"get_device_info", [this](const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<GetDeviceInfo::Request> request,
std::shared_ptr<GetDeviceInfo::Response> response) {
getDeviceInfoCallback(request_header, request, response);
});
}
void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>& request,
@@ -364,4 +370,27 @@ void OBCameraNode::getExposureCallback(const std::shared_ptr<GetInt32::Request>&
response->message = "unknown error";
}
}
void OBCameraNode::getDeviceInfoCallback(const std::shared_ptr<rmw_request_id_t>& request_header,
const std::shared_ptr<GetDeviceInfo::Request>& request,
std::shared_ptr<GetDeviceInfo::Response>& response) {
try {
auto device_info = device_->getDeviceInfo();
response->info.name = device_info->name();
response->info.pid = device_info->pid();
response->info.vid = device_info->vid();
response->info.serial_number = device_info->serialNumber();
response->info.firmware_version = device_info->firmwareVersion();
response->info.supported_min_sdk_version = device_info->supportedMinSdkVersion();
response->success = true;
} catch (const ob::Error& e) {
response->success = false;
response->message = e.getMessage();
} catch (const std::exception& e) {
response->success = false;
response->message = e.what();
} catch (...) {
response->success = false;
response->message = "unknown error";
}
}
} // namespace orbbec_camera
+8 -6
View File
@@ -94,13 +94,15 @@ void OBCameraNodeFactory::getDevice(const std::shared_ptr<ob::DeviceList> &list)
auto dev = list->getDevice(i);
if (dev != nullptr) {
device_ = dev;
RCLCPP_INFO_STREAM(logger_, "get device name " << dev->getDeviceInfo()->name());
RCLCPP_INFO_STREAM(logger_, "get device pid " << dev->getDeviceInfo()->pid());
RCLCPP_INFO_STREAM(logger_, "get device vid " << dev->getDeviceInfo()->vid());
RCLCPP_INFO_STREAM(logger_, "device name " << dev->getDeviceInfo()->name());
RCLCPP_INFO_STREAM(logger_, "device pid " << dev->getDeviceInfo()->pid());
RCLCPP_INFO_STREAM(logger_, "device vid " << dev->getDeviceInfo()->vid());
RCLCPP_INFO_STREAM(logger_, "device serial_name " << dev->getDeviceInfo()->serialNumber());
RCLCPP_INFO_STREAM(logger_,
"get device serial_name " << dev->getDeviceInfo()->serialNumber());
RCLCPP_INFO_STREAM(logger_,
"get device firmware version " << dev->getDeviceInfo()->firmwareVersion());
"device firmware version " << dev->getDeviceInfo()->firmwareVersion());
RCLCPP_INFO_STREAM(logger_, "device supported min sdk version "
<< dev->getDeviceInfo()->supportedMinSdkVersion());
RCLCPP_INFO_STREAM(logger_, "device hardware version " << dev->getDeviceInfo()->hardwareVersion());
}
}
}