Skip to content

Commit

Permalink
temp: includes #231, #232, #233, #234, #235
Browse files Browse the repository at this point in the history
Signed-off-by: Max SCHMELLER <[email protected]>
  • Loading branch information
mojomex committed Nov 26, 2024
1 parent 47efeed commit e4512d8
Show file tree
Hide file tree
Showing 20 changed files with 1,307 additions and 236 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"nproc",
"nsec",
"ntoa",
"OVFL",
"pandar",
"PANDAR",
"PANDARAT",
Expand Down
55 changes: 55 additions & 0 deletions nebula_common/include/nebula_common/loggers/console_logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "nebula_common/loggers/logger.hpp"

#include <cstdio>
#include <iostream>
#include <memory>
#include <ostream>
#include <string>
#include <utility>

namespace nebula::drivers::loggers
{

class ConsoleLogger : public Logger
{
public:
explicit ConsoleLogger(std::string name) : name_(std::move(name)) {}

void debug(const std::string & message) override { print_tagged(std::cout, "DEBUG", message); }
void info(const std::string & message) override { print_tagged(std::cout, "INFO", message); }
void warn(const std::string & message) override { print_tagged(std::cerr, "WARN", message); }
void error(const std::string & message) override { print_tagged(std::cerr, "ERROR", message); }

std::shared_ptr<Logger> child(const std::string & name) override
{
return std::make_shared<ConsoleLogger>(name_ + "." + name);
}

private:
std::string name_;

void print_tagged(std::ostream & os, const std::string & severity, const std::string & message)
{
// In multithreaded logging, building the string first (... + ...) and then shifting to the
// stream will ensure that no other logger outputs between string fragments
os << ("[" + name_ + "][" + severity + "] " + message) << std::endl;
}
};

} // namespace nebula::drivers::loggers
49 changes: 49 additions & 0 deletions nebula_common/include/nebula_common/loggers/logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>
#include <sstream>
#include <string>

#define NEBULA_LOG_STREAM(log_func, stream_args) \
{ \
std::stringstream ss{}; \
ss << stream_args; \
log_func(ss.str()); \
}

namespace nebula::drivers::loggers
{

class Logger
{
public:
Logger() = default;
Logger(const Logger &) = default;
Logger(Logger &&) = delete;
Logger & operator=(const Logger &) = default;
Logger & operator=(Logger &&) = delete;
virtual ~Logger() = default;

virtual void debug(const std::string & message) = 0;
virtual void info(const std::string & message) = 0;
virtual void warn(const std::string & message) = 0;
virtual void error(const std::string & message) = 0;

virtual std::shared_ptr<Logger> child(const std::string & name) = 0;
};

} // namespace nebula::drivers::loggers
1 change: 1 addition & 0 deletions nebula_common/include/nebula_common/util/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include <exception>
#include <stdexcept>
#include <string>
#include <variant>

Expand Down
38 changes: 32 additions & 6 deletions nebula_hw_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.14)
project(nebula_hw_interfaces)

# Default to C++17
if (NOT CMAKE_CXX_STANDARD)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif ()
endif()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wunused-function)
endif ()
endif()

find_package(ament_cmake_auto REQUIRED)
find_package(boost_tcp_driver)
Expand Down Expand Up @@ -53,7 +53,6 @@ target_link_libraries(nebula_hw_interfaces_velodyne PUBLIC
${boost_tcp_driver_LIBRARIES}
${boost_udp_driver_LIBRARIES}
${velodyne_msgs_TARGETS}

)
target_include_directories(nebula_hw_interfaces_velodyne PUBLIC
${boost_udp_driver_INCLUDE_DIRS}
Expand All @@ -68,7 +67,6 @@ target_link_libraries(nebula_hw_interfaces_robosense PUBLIC
${boost_tcp_driver_LIBRARIES}
${boost_udp_driver_LIBRARIES}
${robosense_msgs_TARGETS}

)
target_include_directories(nebula_hw_interfaces_robosense PUBLIC
${boost_udp_driver_INCLUDE_DIRS}
Expand Down Expand Up @@ -100,6 +98,34 @@ install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)

ament_add_gtest(test_udp
test/common/test_udp.cpp
)

target_include_directories(test_udp PUBLIC
${nebula_common_INCLUDE_DIRS}
include
test)

ament_add_gmock(hesai_test_ptc
test/hesai/test_ptc.cpp
)

target_include_directories(hesai_test_ptc PUBLIC
${nebula_common_INCLUDE_DIRS}
${nebula_hw_interfaces_hesai_INCLUDE_DIRS}
${boost_tcp_driver_INCLUDE_DIRS}
${boost_udp_driver_INCLUDE_DIRS}
include
test)

target_link_libraries(hesai_test_ptc
nebula_hw_interfaces_hesai
)
endif()

ament_export_include_directories("include/${PROJECT_NAME}")
Expand Down
Loading

0 comments on commit e4512d8

Please sign in to comment.