Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CAN transport flag to cmake / Upgrade splog version #296

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(UAGENT_FAST_PROFILE "Build FastMiddleware profile." ON)
option(UAGENT_CED_PROFILE "Build CedMiddleware profile." ON)
option(UAGENT_DISCOVERY_PROFILE "Build Discovery profile." ON)
option(UAGENT_P2P_PROFILE "Build P2P discovery profile." ON)
option(UAGENT_SOCKETCAN_PROFILE "Build Agent CAN FD transport." ON)
option(UAGENT_LOGGER_PROFILE "Build logger profile." ON)
option(UAGENT_SECURITY_PROFILE "Build security profile." OFF)
option(UAGENT_BUILD_EXECUTABLE "Build Micro XRCE-DDS Agent provided executable." ON)
Expand All @@ -54,6 +55,10 @@ if((CMAKE_SYSTEM_NAME STREQUAL "") AND (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Lin
set(UAGENT_P2P_PROFILE OFF)
endif()

if((CMAKE_SYSTEM_NAME STREQUAL "Darwin") OR (CMAKE_SYSTEM_NAME STREQUAL "Windows"))
set(UAGENT_SOCKETCAN_PROFILE OFF)
endif()

set(UAGENT_CONFIG_RELIABLE_STREAM_DEPTH 16 CACHE STRING "Reliable streams depth.")
set(UAGENT_CONFIG_BEST_EFFORT_STREAM_DEPTH 16 CACHE STRING "Best-effort streams depth.")
set(UAGENT_CONFIG_HEARTBEAT_PERIOD 200 CACHE STRING "Heartbeat period in milliseconds.")
Expand Down Expand Up @@ -97,8 +102,8 @@ if(UAGENT_FAST_PROFILE)
endif()

if(UAGENT_LOGGER_PROFILE)
set(_spdlog_version 1.4.2)
set(_spdlog_tag v1.4.2)
set(_spdlog_version 1.9.2)
set(_spdlog_tag v1.9.2)
list(APPEND _deps "spdlog\;${_spdlog_version}")
endif()

Expand Down Expand Up @@ -147,18 +152,18 @@ endforeach()
# Sources
###############################################################################
# Check platform.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(TRANSPORT_SRCS
src/cpp/transport/udp/UDPv4AgentLinux.cpp
src/cpp/transport/udp/UDPv6AgentLinux.cpp
src/cpp/transport/tcp/TCPv4AgentLinux.cpp
src/cpp/transport/tcp/TCPv6AgentLinux.cpp
src/cpp/transport/can/CanAgentLinux.cpp
src/cpp/transport/serial/SerialAgentLinux.cpp
src/cpp/transport/serial/TermiosAgentLinux.cpp
src/cpp/transport/serial/MultiSerialAgentLinux.cpp
src/cpp/transport/serial/MultiTermiosAgentLinux.cpp
src/cpp/transport/serial/PseudoTerminalAgentLinux.cpp
$<$<BOOL:${UAGENT_SOCKETCAN_PROFILE}>:src/cpp/transport/can/CanAgentLinux.cpp>
$<$<BOOL:${UAGENT_DISCOVERY_PROFILE}>:src/cpp/transport/discovery/DiscoveryServerLinux.cpp>
$<$<BOOL:${UAGENT_P2P_PROFILE}>:src/cpp/transport/p2p/AgentDiscovererLinux.cpp>
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if(UAGENT_LOGGER_PROFILE)
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH};${CMAKE_INSTALL_PREFIX}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}
${CROSS_CMAKE_ARGS}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
Expand Down
1 change: 1 addition & 0 deletions include/uxr/agent/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace uxr {
#ifdef UAGENT_CED_PROFILE
#cmakedefine UAGENT_P2P_PROFILE
#endif
#cmakedefine UAGENT_SOCKETCAN_PROFILE
#cmakedefine UAGENT_LOGGER_PROFILE

const uint16_t DISCOVERY_PORT = 7400;
Expand Down
2 changes: 2 additions & 0 deletions include/uxr/agent/transport/serial/baud_rate_table_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ speed_t getBaudRate(const char* baudrate_str)
{
rv = B230400;
}
#ifndef __APPLE__
else if (0 == strcmp(baudrate_str, "460800"))
{
rv = B460800;
Expand Down Expand Up @@ -148,6 +149,7 @@ speed_t getBaudRate(const char* baudrate_str)
{
rv = B4000000;
}
#endif // __APPLE__
else
{
speed_t custom_baud_rate = (speed_t)atoi(baudrate_str);
Expand Down
21 changes: 19 additions & 2 deletions include/uxr/agent/utils/ArgumentParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <type_traits>
#include <unordered_map>
#include <uxr/agent/transport/Server.hpp>
#include <uxr/agent/config.hpp>

#ifdef _WIN32
#include <uxr/agent/transport/udp/UDPv4AgentWindows.hpp>
Expand All @@ -33,12 +34,15 @@
#include <uxr/agent/transport/udp/UDPv6AgentLinux.hpp>
#include <uxr/agent/transport/tcp/TCPv4AgentLinux.hpp>
#include <uxr/agent/transport/tcp/TCPv6AgentLinux.hpp>
#include <uxr/agent/transport/can/CanAgentLinux.hpp>
#include <uxr/agent/transport/serial/TermiosAgentLinux.hpp>
#include <uxr/agent/transport/serial/MultiTermiosAgentLinux.hpp>
#include <uxr/agent/transport/serial/PseudoTerminalAgentLinux.hpp>
#include <uxr/agent/transport/serial/baud_rate_table_linux.h>

#ifdef UAGENT_SOCKETCAN_PROFILE
#include <uxr/agent/transport/can/CanAgentLinux.hpp>
#endif // UAGENT_SOCKETCAN_PROFILE

#include <termios.h>
#include <fcntl.h>
#include <sys/stat.h>
Expand All @@ -61,7 +65,9 @@ enum class TransportKind
TCP4,
TCP6,
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
CAN,
#endif // UAGENT_SOCKETCAN_PROFILE
SERIAL,
MULTISERIAL,
PSEUDOTERMINAL,
Expand Down Expand Up @@ -867,7 +873,7 @@ class MultiSerialArgs : public PseudoTerminalArgs<AgentType>
Argument<std::string> file_;
};


#ifdef UAGENT_SOCKETCAN_PROFILE
/*************************************************************************************************
* Specific arguments for CAN transports
*************************************************************************************************/
Expand Down Expand Up @@ -919,6 +925,7 @@ class CanArgs
Argument<std::string> dev_;
Argument<std::string> can_id_;
};
#endif // UAGENT_SOCKETCAN_PROFILE
#endif // _WIN32

/*************************************************************************************************
Expand All @@ -937,7 +944,9 @@ class ArgumentParser
, common_args_()
, ip_args_()
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
, can_args_()
#endif // UAGENT_SOCKETCAN_PROFILE
, serial_args_()
, multiserial_args_()
, pseudoterminal_args_()
Expand Down Expand Up @@ -971,11 +980,13 @@ class ArgumentParser
break;
}
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
case TransportKind::CAN:
{
result &= can_args_.parse(argc_, argv_);
break;
}
#endif // UAGENT_SOCKETCAN_PROFILE
case TransportKind::SERIAL:
{
result &= serial_args_.parse(argc_, argv_);
Expand Down Expand Up @@ -1081,8 +1092,10 @@ class ArgumentParser
ss << " * SERIAL (serial, multiserial, pseudoterminal)" << std::endl;
ss << pseudoterminal_args_.get_help();
ss << serial_args_.get_help();
#ifdef UAGENT_SOCKETCAN_PROFILE
ss << " * CAN FD (canfd)" << std::endl;
ss << can_args_.get_help();
#endif // UAGENT_SOCKETCAN_PROFILE
#endif // _WIN32
ss << std::endl;
// TODO(@jamoralp): Once documentation is updated with proper CLI section, add here an hyperlink to that section
Expand All @@ -1095,7 +1108,9 @@ class ArgumentParser
CommonArgs<AgentType> common_args_;
IPvXArgs<AgentType> ip_args_;
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
CanArgs<AgentType> can_args_;
#endif // UAGENT_SOCKETCAN_PROFILE
SerialArgs<AgentType> serial_args_;
MultiSerialArgs<AgentType> multiserial_args_;
PseudoTerminalArgs<AgentType> pseudoterminal_args_;
Expand Down Expand Up @@ -1162,6 +1177,7 @@ template<> inline bool ArgumentParser<PseudoTerminalAgent>::launch_agent()
return false;
}

#ifdef UAGENT_SOCKETCAN_PROFILE
template<> inline bool ArgumentParser<CanAgent>::launch_agent()
{
uint32_t can_id = strtoul(can_args_.can_id().c_str(), NULL, 16);
Expand All @@ -1179,6 +1195,7 @@ template<> inline bool ArgumentParser<CanAgent>::launch_agent()

return false;
}
#endif // UAGENT_SOCKETCAN_PROFILE
#endif // _WIN32

} // namespace parser
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/AgentInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <uxr/agent/config.hpp>
#include <uxr/agent/AgentInstance.hpp>
#include <uxr/agent/middleware/utils/Callbacks.hpp>

Expand Down Expand Up @@ -64,11 +65,13 @@ bool AgentInstance::create(
break;
}
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
case agent::TransportKind::CAN:
{
agent_thread_ = std::move(agent::create_agent_thread<CanAgent>(argc, argv, exit_signal, valid_transport));
break;
}
#endif // UAGENT_SOCKETCAN_PROFILE
case agent::TransportKind::SERIAL:
{
agent_thread_ = std::move(agent::create_agent_thread<TermiosAgent>(argc, argv, exit_signal, valid_transport));
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/utils/ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef UXR_AGENT_UTILS_ARGUMENTPARSER_CPP_
#define UXR_AGENT_UTILS_ARGUMENTPARSER_CPP_

#include <uxr/agent/config.hpp>
#include <uxr/agent/utils/ArgumentParser.hpp>

// TODO(jamoralp): move definitions of ArgumentParser.hpp into this file, to maintain code coherence.
Expand Down Expand Up @@ -53,7 +54,9 @@ eprosima::uxr::agent::TransportKind eprosima::uxr::agent::parser::utils::check_t
{"tcp4", eprosima::uxr::agent::TransportKind::TCP4},
{"tcp6", eprosima::uxr::agent::TransportKind::TCP6},
#ifndef _WIN32
#ifdef UAGENT_SOCKETCAN_PROFILE
{"canfd", eprosima::uxr::agent::TransportKind::CAN},
#endif // UAGENT_SOCKETCAN_PROFILE
{"serial", eprosima::uxr::agent::TransportKind::SERIAL},
{"multiserial", eprosima::uxr::agent::TransportKind::MULTISERIAL},
{"pseudoterminal", eprosima::uxr::agent::TransportKind::PSEUDOTERMINAL},
Expand Down