From 8660ac89a3e0a5046b48f78c0a1d0e33ba7aaf28 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 17 May 2024 09:13:14 -0400 Subject: [PATCH 1/3] Added TransportDirection parameter definition. --- .../messages/configuration.py | 30 +++++++++++ .../fusion_engine/messages/configuration.h | 51 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/python/fusion_engine_client/messages/configuration.py b/python/fusion_engine_client/messages/configuration.py index 376e815d..78b7a15b 100644 --- a/python/fusion_engine_client/messages/configuration.py +++ b/python/fusion_engine_client/messages/configuration.py @@ -54,6 +54,7 @@ class InterfaceConfigType(IntEnum): REMOTE_ADDRESS = 3 PORT = 4 ENABLED = 5 + DIRECTION = 6 class Direction(IntEnum): @@ -165,6 +166,12 @@ class TransportType(IntEnum): ALL = 255 +class TransportDirection(IntEnum): + INVALID = 0 + SERVER = 1 + CLIENT = 2 + + class UpdateAction(IntEnum): REPLACE = 0 @@ -414,6 +421,16 @@ class BoolVal(NamedTuple): "value" / Flag, ) + # Enum helpers. + @staticmethod + def _define_enum_classes(enum_type, construct_type=Int8ul): + class EnumVal(NamedTuple): + value: enum_type = list(enum_type)[0] + construct = AutoEnum(construct_type, enum_type) + return EnumVal, construct + + TransportDirectionVal, TransportDirectionConstruct = _define_enum_classes(TransportDirection, Int8ul) + class StringVal(NamedTuple): """! @brief String value specifier. @@ -907,6 +924,7 @@ class HeadingBias(_conf_gen.HeadingBias): """ pass + @_conf_gen.create_interface_config_class(InterfaceConfigType.BAUD_RATE, _conf_gen.UInt32Construct) class InterfaceBaudRateConfig(_conf_gen.IntegerVal): """! @@ -914,6 +932,7 @@ class InterfaceBaudRateConfig(_conf_gen.IntegerVal): """ pass + @_conf_gen.create_interface_config_class(InterfaceConfigType.PORT, _conf_gen.UInt16Construct) class InterfacePortConfig(_conf_gen.IntegerVal): """! @@ -921,6 +940,7 @@ class InterfacePortConfig(_conf_gen.IntegerVal): """ pass + @_conf_gen.create_interface_config_class(InterfaceConfigType.REMOTE_ADDRESS, _conf_gen.StringConstruct(64)) class InterfaceRemoteAddressConfig(_conf_gen.StringVal): """! @@ -928,6 +948,7 @@ class InterfaceRemoteAddressConfig(_conf_gen.StringVal): """ pass + @_conf_gen.create_interface_config_class(InterfaceConfigType.ENABLED, _conf_gen.BoolConstruct) class InterfaceEnabledConfig(_conf_gen.BoolVal): """! @@ -935,6 +956,15 @@ class InterfaceEnabledConfig(_conf_gen.BoolVal): """ pass + +@_conf_gen.create_interface_config_class(InterfaceConfigType.DIRECTION, _conf_gen.TransportDirectionConstruct) +class InterfaceDirectionConfig(_conf_gen.TransportDirectionVal): + """! + @brief Interface transport direction (client/server) configuration settings. + """ + pass + + @_conf_gen.create_interface_config_class(InterfaceConfigType.OUTPUT_DIAGNOSTICS_MESSAGES, _conf_gen.BoolConstruct) class InterfaceDiagnosticMessagesEnabled(_conf_gen.BoolVal): """! diff --git a/src/point_one/fusion_engine/messages/configuration.h b/src/point_one/fusion_engine/messages/configuration.h index c5a9e833..368ddaac 100644 --- a/src/point_one/fusion_engine/messages/configuration.h +++ b/src/point_one/fusion_engine/messages/configuration.h @@ -405,6 +405,13 @@ enum class InterfaceConfigType : uint8_t { * Payload format: `bool` */ ENABLED = 5, + + /** + * Set the interface direction (client/server). + * + * Payload format: @ref TransportDirection + */ + DIRECTION = 6, }; /** @@ -435,6 +442,9 @@ P1_CONSTEXPR_FUNC const char* to_string(InterfaceConfigType type) { case InterfaceConfigType::ENABLED: return "Interface Enabled"; + case InterfaceConfigType::DIRECTION: + return "Transport Direction"; + default: return "Unrecognized Configuration"; } @@ -1630,6 +1640,47 @@ inline p1_ostream& operator<<(p1_ostream& stream, TransportType val) { return stream; } +/** + * @brief The direction (client/server) for an individual interface. + */ +enum class TransportDirection : uint8_t { + INVALID = 0, + /** A server listening for one or more incoming remote connections. */ + SERVER = 1, + /** A client connecting to a specified remote server. */ + CLIENT = 2, +}; + +/** + * @brief Get a human-friendly string name for the specified @ref + * TransportDirection. + * @ingroup config_and_ctrl_messages + * + * @param val The enum to get the string name for. + * + * @return The corresponding string name. + */ +P1_CONSTEXPR_FUNC const char* to_string(TransportDirection val) { + switch (val) { + case TransportDirection::INVALID: + return "INVALID"; + case TransportDirection::SERVER: + return "SERVER"; + case TransportDirection::CLIENT: + return "CLIENT"; + } + return "Unrecognized"; +} + +/** + * @brief @ref TransportDirection stream operator. + * @ingroup config_and_ctrl_messages + */ +inline p1_ostream& operator<<(p1_ostream& stream, TransportDirection val) { + stream << to_string(val) << " (" << (int)val << ")"; + return stream; +} + /** * @brief Identifies an I/O interface. * From cf7976a5a1900e483572679b908c3052df5949a5 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 17 May 2024 09:35:40 -0400 Subject: [PATCH 2/3] Corrected interface enable documentation - valid for all. --- src/point_one/fusion_engine/messages/configuration.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/point_one/fusion_engine/messages/configuration.h b/src/point_one/fusion_engine/messages/configuration.h index 368ddaac..7b405296 100644 --- a/src/point_one/fusion_engine/messages/configuration.h +++ b/src/point_one/fusion_engine/messages/configuration.h @@ -398,9 +398,7 @@ enum class InterfaceConfigType : uint8_t { /** * Enable/disable the interface. * - * Valid for: - * - @ref TransportType::TCP_CLIENT - * - @ref TransportType::UDP_CLIENT + * Valid for all @ref TransportType values. * * Payload format: `bool` */ From 443d3d82c2db3592e509d845fece0c9e7df77929 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 17 May 2024 09:37:42 -0400 Subject: [PATCH 3/3] Added UNIX domain socket configuration support. --- .../messages/configuration.py | 18 ++++ .../fusion_engine/messages/configuration.h | 97 +++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/python/fusion_engine_client/messages/configuration.py b/python/fusion_engine_client/messages/configuration.py index 78b7a15b..d9903dcf 100644 --- a/python/fusion_engine_client/messages/configuration.py +++ b/python/fusion_engine_client/messages/configuration.py @@ -55,6 +55,7 @@ class InterfaceConfigType(IntEnum): PORT = 4 ENABLED = 5 DIRECTION = 6 + SOCKET_TYPE = 7 class Direction(IntEnum): @@ -160,6 +161,7 @@ class TransportType(IntEnum): UDP_CLIENT = 5 UDP_SERVER = 6 WEBSOCKET_SERVER = 7 + UNIX = 8 ## Set/get the configuration for the interface on which the command was received. CURRENT = 254 ## Set/get the configuration for the all I/O interfaces. @@ -172,6 +174,13 @@ class TransportDirection(IntEnum): CLIENT = 2 +class SocketType(IntEnum): + INVALID = 0 + STREAM = 1 + DATAGRAM = 2 + SEQPACKET = 3 + + class UpdateAction(IntEnum): REPLACE = 0 @@ -430,6 +439,7 @@ class EnumVal(NamedTuple): return EnumVal, construct TransportDirectionVal, TransportDirectionConstruct = _define_enum_classes(TransportDirection, Int8ul) + SocketTypeVal, SocketTypeConstruct = _define_enum_classes(SocketType, Int8ul) class StringVal(NamedTuple): """! @@ -965,6 +975,14 @@ class InterfaceDirectionConfig(_conf_gen.TransportDirectionVal): pass +@_conf_gen.create_interface_config_class(InterfaceConfigType.SOCKET_TYPE, _conf_gen.SocketTypeConstruct) +class InterfaceSocketTypeConfig(_conf_gen.SocketTypeVal): + """! + @brief UNIX domain socket type configuration (stream, datagram, sequence). + """ + pass + + @_conf_gen.create_interface_config_class(InterfaceConfigType.OUTPUT_DIAGNOSTICS_MESSAGES, _conf_gen.BoolConstruct) class InterfaceDiagnosticMessagesEnabled(_conf_gen.BoolVal): """! diff --git a/src/point_one/fusion_engine/messages/configuration.h b/src/point_one/fusion_engine/messages/configuration.h index 7b405296..51344644 100644 --- a/src/point_one/fusion_engine/messages/configuration.h +++ b/src/point_one/fusion_engine/messages/configuration.h @@ -373,9 +373,13 @@ enum class InterfaceConfigType : uint8_t { /** * Configure the network address for a client to connect to. * + * For UNIX domain sockets, this string represents the path to the local + * socket file. + * * Valid for: * - @ref TransportType::TCP_CLIENT * - @ref TransportType::UDP_CLIENT + * - @ref TransportType::UNIX * * Payload format: `char[64]` containing a NULL terminated string. */ @@ -407,9 +411,22 @@ enum class InterfaceConfigType : uint8_t { /** * Set the interface direction (client/server). * + * Valid for: + * - @ref TransportType::UNIX + * * Payload format: @ref TransportDirection */ DIRECTION = 6, + + /** + * Set the UNIX domain socket type (streaming/datagram/sequenced). + * + * Valid for: + * - @ref TransportType::UNIX + * + * Payload format: @ref SocketType + */ + SOCKET_TYPE = 7, }; /** @@ -443,6 +460,9 @@ P1_CONSTEXPR_FUNC const char* to_string(InterfaceConfigType type) { case InterfaceConfigType::DIRECTION: return "Transport Direction"; + case InterfaceConfigType::SOCKET_TYPE: + return "Socket Type"; + default: return "Unrecognized Configuration"; } @@ -1585,6 +1605,27 @@ enum class TransportType : uint8_t { UDP_SERVER = 6, /** An interface that will communicate with connected clients. */ WEBSOCKET_SERVER = 7, + /** + * A UNIX domain socket client or server. + * + * UNIX domain socket connections may be configured as either client that + * connects to an existing server, or a server that listens for one or more + * incoming client connections. UNIX domain sockets may operate in one of + * three possible modes: + * - A connection-oriented streaming mode where packet boundaries are not + * preserved (similar to TCP) + * - Datagram mode where packet boundaries are preserved but connections + * between the client and server are not maintained, and the interface sends + * output to an optional configured file (similar to UDP) + * - Sequenced packet mode, which is connection-oriented (like TCP) but also + * preserves message boundaries (like UDP) and guarantees in-order delivery + * + * For a UNIX domain socket, you must specify: + * - The @ref TransportDirection (client or server) + * - The @ref SocketType (streaming, datagram, or sequenced) + * - The path to a socket file to connect to (client) or create (server) + */ + UNIX = 8, /** * Set/get the configuration for the interface on which the command was * received. @@ -1621,6 +1662,8 @@ P1_CONSTEXPR_FUNC const char* to_string(TransportType val) { return "UDP Server"; case TransportType::WEBSOCKET_SERVER: return "Websocket Server"; + case TransportType::UNIX: + return "UNIX"; case TransportType::CURRENT: return "Current"; case TransportType::ALL: @@ -1679,6 +1722,60 @@ inline p1_ostream& operator<<(p1_ostream& stream, TransportDirection val) { return stream; } +/** + * @brief The socket type specifying how data is transmitted for UNIX domain + * sockets. + */ +enum class SocketType : uint8_t { + INVALID = 0, + /** + * Operate in connection-oriented streaming mode and do not preserve message + * boundaries (similar to TCP). + */ + STREAM = 1, + /** + * Operate in datagram mode, preserving message boundaries but not maintaining + * client connections (similar to UDP). + */ + DATAGRAM = 2, + /** + * Operate in sequenced packet mode, which is both connection-oriented and + * preserves message boundaries. + */ + SEQPACKET = 3, +}; + +/** + * @brief Get a human-friendly string name for the specified @ref SocketType. + * @ingroup config_and_ctrl_messages + * + * @param val The enum to get the string name for. + * + * @return The corresponding string name. + */ +P1_CONSTEXPR_FUNC const char* to_string(SocketType val) { + switch (val) { + case SocketType::INVALID: + return "INVALID"; + case SocketType::STREAM: + return "STREAM"; + case SocketType::DATAGRAM: + return "DATAGRAM"; + case SocketType::SEQPACKET: + return "SEQPACKET"; + } + return "Unrecognized"; +} + +/** + * @brief @ref SocketType stream operator. + * @ingroup config_and_ctrl_messages + */ +inline p1_ostream& operator<<(p1_ostream& stream, SocketType val) { + stream << to_string(val) << " (" << (int)val << ")"; + return stream; +} + /** * @brief Identifies an I/O interface. *