mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-04 12:07:46 +08:00
add get verion api
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "orbbec_camera/ob_camera_node.h"
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "orbbec_camera/utils.h"
|
||||
@@ -111,6 +112,12 @@ void OBCameraNode::setupCameraCtrlServices() {
|
||||
std::shared_ptr<GetDeviceInfo::Response> response) {
|
||||
getDeviceInfoCallback(request_header, request, response);
|
||||
});
|
||||
get_api_version_srv_ = node_->create_service<GetString>(
|
||||
"get_api_version", [this](const std::shared_ptr<rmw_request_id_t> request_header,
|
||||
const std::shared_ptr<GetString::Request> request,
|
||||
std::shared_ptr<GetString::Response> response) {
|
||||
getApiVersion(request_header, request, response);
|
||||
});
|
||||
}
|
||||
|
||||
void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>& request,
|
||||
@@ -405,4 +412,27 @@ void OBCameraNode::getDeviceInfoCallback(const std::shared_ptr<rmw_request_id_t>
|
||||
response->message = "unknown error";
|
||||
}
|
||||
}
|
||||
void OBCameraNode::getApiVersion(const std::shared_ptr<rmw_request_id_t>& request_header,
|
||||
const std::shared_ptr<GetString::Request>& request,
|
||||
std::shared_ptr<GetString::Response>& response) {
|
||||
try {
|
||||
auto device_info = device_->getDeviceInfo();
|
||||
nlohmann::json data;
|
||||
data["firmware_version"] = device_info->firmwareVersion();
|
||||
data["supported_min_sdk_version"] = device_info->supportedMinSdkVersion();
|
||||
data["ros_sdk_version"] = OB_ROS_VERSION_STR;
|
||||
data["ob_sdk_version"] = getObSDKVersion();
|
||||
response->data = data.dump(2);
|
||||
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
|
||||
|
||||
@@ -139,8 +139,16 @@ orbbec_camera_msgs::msg::Extrinsics obExtrinsicsToMsg(const OBD2CTransform &extr
|
||||
rclcpp::Time frameTimeStampToROSTime(uint64_t ms) {
|
||||
auto total = static_cast<uint64_t>(ms * 1e6);
|
||||
uint64_t sec = total / 1000000000;
|
||||
uint64_t nano_sec = total % 1000000000;
|
||||
uint64_t nano_sec = total % 1000000000;
|
||||
rclcpp::Time stamp(sec, nano_sec);
|
||||
return stamp;
|
||||
}
|
||||
std::string getObSDKVersion() {
|
||||
int major = ob::Version::getMajor();
|
||||
int minor = ob::Version::getMinor();
|
||||
int patch = ob::Version::getPatch();
|
||||
std::string version = std::to_string(major) + std::to_string(minor) + std::to_string(patch);
|
||||
return version;
|
||||
}
|
||||
|
||||
} // namespace orbbec_camera
|
||||
|
||||
Reference in New Issue
Block a user