Skip to content

Commit

Permalink
Added UNIX domain socket configuration settings. (#313)
Browse files Browse the repository at this point in the history
# New Features
- Added UNIX domain socket configuration settings
  • Loading branch information
adamshapiro0 authored May 17, 2024
2 parents c9ee320 + 443d3d8 commit cf5d305
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 3 deletions.
48 changes: 48 additions & 0 deletions python/fusion_engine_client/messages/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class InterfaceConfigType(IntEnum):
REMOTE_ADDRESS = 3
PORT = 4
ENABLED = 5
DIRECTION = 6
SOCKET_TYPE = 7


class Direction(IntEnum):
Expand Down Expand Up @@ -159,12 +161,26 @@ 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.
ALL = 255


class TransportDirection(IntEnum):
INVALID = 0
SERVER = 1
CLIENT = 2


class SocketType(IntEnum):
INVALID = 0
STREAM = 1
DATAGRAM = 2
SEQPACKET = 3


class UpdateAction(IntEnum):
REPLACE = 0

Expand Down Expand Up @@ -414,6 +430,17 @@ 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)
SocketTypeVal, SocketTypeConstruct = _define_enum_classes(SocketType, Int8ul)

class StringVal(NamedTuple):
"""!
@brief String value specifier.
Expand Down Expand Up @@ -907,34 +934,55 @@ class HeadingBias(_conf_gen.HeadingBias):
"""
pass


@_conf_gen.create_interface_config_class(InterfaceConfigType.BAUD_RATE, _conf_gen.UInt32Construct)
class InterfaceBaudRateConfig(_conf_gen.IntegerVal):
"""!
@brief Interface baud configuration settings.
"""
pass


@_conf_gen.create_interface_config_class(InterfaceConfigType.PORT, _conf_gen.UInt16Construct)
class InterfacePortConfig(_conf_gen.IntegerVal):
"""!
@brief Interface network port configuration settings.
"""
pass


@_conf_gen.create_interface_config_class(InterfaceConfigType.REMOTE_ADDRESS, _conf_gen.StringConstruct(64))
class InterfaceRemoteAddressConfig(_conf_gen.StringVal):
"""!
@brief Configure the network address for a client to connect to.
"""
pass


@_conf_gen.create_interface_config_class(InterfaceConfigType.ENABLED, _conf_gen.BoolConstruct)
class InterfaceEnabledConfig(_conf_gen.BoolVal):
"""!
@brief Interface enabled/disabled configuration settings.
"""
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.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):
"""!
Expand Down
152 changes: 149 additions & 3 deletions src/point_one/fusion_engine/messages/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -398,13 +402,31 @@ 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`
*/
ENABLED = 5,

/**
* 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,
};

/**
Expand Down Expand Up @@ -435,6 +457,12 @@ P1_CONSTEXPR_FUNC const char* to_string(InterfaceConfigType type) {
case InterfaceConfigType::ENABLED:
return "Interface Enabled";

case InterfaceConfigType::DIRECTION:
return "Transport Direction";

case InterfaceConfigType::SOCKET_TYPE:
return "Socket Type";

default:
return "Unrecognized Configuration";
}
Expand Down Expand Up @@ -1577,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.
Expand Down Expand Up @@ -1613,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:
Expand All @@ -1630,6 +1681,101 @@ 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 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.
*
Expand Down

0 comments on commit cf5d305

Please sign in to comment.