Skip to content

Commit

Permalink
feat(hesai_hw_interface): use dependency-injected logger, get rid of …
Browse files Browse the repository at this point in the history
…RCLCPP dependency (#232)

* chore(hesai_hw_interfaces): switch to the new loggers::Logger class, remove rclcpp dependency 🎉

Signed-off-by: Max SCHMELLER <[email protected]>

* chore(hesai): use angle brackets for out-of-package import

Signed-off-by: Max SCHMELLER <[email protected]>

* ci(pre-commit): autofix

* chore(hesai_hw_interface): pass logger shared_ptr by constref

Signed-off-by: Max SCHMELLER <[email protected]>

---------

Signed-off-by: Max SCHMELLER <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
mojomex and pre-commit-ci[bot] authored Nov 26, 2024
1 parent 77b4c6c commit 3d42cd0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Have to define macros to silence warnings about deprecated headers being used by
// boost/property_tree/ in some versions of boost.
// See: https://github.com/boostorg/property_tree/issues/51
#include "nebula_common/nebula_status.hpp"
#include <nebula_common/nebula_status.hpp>

#include <boost/version.hpp>

Expand All @@ -28,15 +28,15 @@
#if (BOOST_VERSION / 100 == 1074) // Boost 1.74
#define BOOST_ALLOW_DEPRECATED_HEADERS
#endif
#include "boost_tcp_driver/http_client_driver.hpp"
#include "boost_tcp_driver/tcp_driver.hpp"
#include "boost_udp_driver/udp_driver.hpp"
#include "nebula_common/hesai/hesai_common.hpp"
#include "nebula_common/hesai/hesai_status.hpp"
#include "nebula_common/util/expected.hpp"
#include "nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp"

#include <rclcpp/rclcpp.hpp>
#include <boost_tcp_driver/http_client_driver.hpp>
#include <boost_tcp_driver/tcp_driver.hpp>
#include <boost_udp_driver/udp_driver.hpp>
#include <nebula_common/hesai/hesai_common.hpp>
#include <nebula_common/hesai/hesai_status.hpp>
#include <nebula_common/loggers/logger.hpp>
#include <nebula_common/util/expected.hpp>

#include <boost/algorithm/string.hpp>
#include <boost/property_tree/json_parser.hpp>
Expand Down Expand Up @@ -136,6 +136,7 @@ class HesaiHwInterface

using ptc_cmd_result_t = nebula::util::expected<std::vector<uint8_t>, ptc_error_t>;

std::shared_ptr<loggers::Logger> logger_;
std::unique_ptr<::drivers::common::IoContext> cloud_io_context_;
std::shared_ptr<boost::asio::io_context> m_owned_ctx;
std::unique_ptr<::drivers::udp_driver::UdpDriver> cloud_udp_driver_;
Expand Down Expand Up @@ -165,20 +166,6 @@ class HesaiHwInterface
/// @param str Received string
void str_cb(const std::string & str);

std::shared_ptr<rclcpp::Logger> parent_node_logger;
/// @brief Printing the string to RCLCPP_INFO_STREAM
/// @param info Target string
void PrintInfo(std::string info);
/// @brief Printing the string to RCLCPP_ERROR_STREAM
/// @param error Target string
void PrintError(std::string error);
/// @brief Printing the string to RCLCPP_DEBUG_STREAM
/// @param debug Target string
void PrintDebug(std::string debug);
/// @brief Printing the bytes to RCLCPP_DEBUG_STREAM
/// @param bytes Target byte vector
void PrintDebug(const std::vector<uint8_t> & bytes);

/// @brief Convert an error code to a human-readable string
/// @param error_code The error code, containing the sensor's error code (if any), along with
/// flags such as TCP_ERROR_UNRELATED_RESPONSE etc.
Expand All @@ -202,7 +189,7 @@ class HesaiHwInterface

public:
/// @brief Constructor
HesaiHwInterface();
explicit HesaiHwInterface(const std::shared_ptr<loggers::Logger> & logger);
/// @brief Destructor
~HesaiHwInterface();
/// @brief Initializing tcp_driver for TCP communication
Expand Down Expand Up @@ -460,10 +447,6 @@ class HesaiHwInterface
/// @brief Whether to use HTTP for getting LidarMonitor
/// @return Use HTTP
bool UseHttpGetLidarMonitor();

/// @brief Setting rclcpp::Logger
/// @param node Logger
void SetLogger(std::shared_ptr<rclcpp::Logger> node);
};
} // namespace nebula::drivers

Expand Down
Loading

0 comments on commit 3d42cd0

Please sign in to comment.