From dce9cfe5155caed840111282b74957bd6e9ecc6a Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Tue, 25 Jun 2024 15:16:36 -0400 Subject: [PATCH] Added Python InterfaceConfigType.ALL_PARAMETERS support. --- python/examples/send_command.py | 3 + .../messages/configuration.py | 103 ++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/python/examples/send_command.py b/python/examples/send_command.py index 37505105..ef7a5787 100755 --- a/python/examples/send_command.py +++ b/python/examples/send_command.py @@ -72,6 +72,9 @@ # interface=InterfaceID(TransportType.TCP, 0)) # message = GetConfigMessage(InterfaceDiagnosticMessagesEnabled, # interface=InterfaceID(TransportType.TCP, 0)) + # message = SetConfigMessage( + # TCPConfig(direction=TransportDirection.CLIENT, remote_address='remote-hostname', port=1234), + # interface=InterfaceID(TransportType.TCP, 1)) # message = FaultControlMessage(payload=FaultControlMessage.EnableGNSS(False)) # Connect to the device. diff --git a/python/fusion_engine_client/messages/configuration.py b/python/fusion_engine_client/messages/configuration.py index 0171a359..2addaa92 100644 --- a/python/fusion_engine_client/messages/configuration.py +++ b/python/fusion_engine_client/messages/configuration.py @@ -57,6 +57,7 @@ class InterfaceConfigType(IntEnum): ENABLED = 5 DIRECTION = 6 SOCKET_TYPE = 7 + ALL_PARAMETERS = 8 class Direction(IntEnum): @@ -1004,6 +1005,9 @@ class InvalidConfig(_conf_gen.Empty): # SetConfigMessage( # InterfaceDiagnosticMessagesEnabled(True), # interface=InterfaceID(TransportType.TCP, 0)) +# SetConfigMessage( +# TCPConfig(direction=TransportDirection.CLIENT, remote_address='remote-hostname', port=1234), +# interface=InterfaceID(TransportType.TCP, 1)) # # GetConfigMessage( # InterfaceDiagnosticMessagesEnabled, @@ -1069,6 +1073,105 @@ class InterfaceDiagnosticMessagesEnabled(_conf_gen.BoolVal): pass +_TCPConfigConstruct = Struct( + "enabled" / Flag, + "direction" / AutoEnum(Int8ul, TransportDirection), + "port"/ Int16ul, + "remote_address" / PaddedString(64, 'utf8'), +) + + +@_conf_gen.create_interface_config_class(InterfaceConfigType.ALL_PARAMETERS, _TCPConfigConstruct, + transport_type=TransportType.TCP) +class TCPConfig(NamedTuple): + """! + @brief TCP client/server configuration settings. + """ + enabled: bool = True + direction: TransportDirection = TransportDirection.SERVER + port: int = 0 + remote_address: str = '' + + +_UDPConfigConstruct = Struct( + "enabled" / Flag, + Padding(1), + "port"/ Int16ul, + "remote_address" / PaddedString(64, 'utf8'), +) + + +@_conf_gen.create_interface_config_class(InterfaceConfigType.ALL_PARAMETERS, _UDPConfigConstruct, + transport_type=TransportType.UDP) +class UDPConfig(NamedTuple): + """! + @brief UDP interface configuration settings. + """ + enabled: bool = True + port: int = 0 + remote_address: str = '' + + +_WebsocketConfigConstruct = Struct( + "enabled" / Flag, + "direction" / AutoEnum(Int8ul, TransportDirection), + "port"/ Int16ul, + "remote_address" / PaddedString(64, 'utf8'), +) + + +@_conf_gen.create_interface_config_class(InterfaceConfigType.ALL_PARAMETERS, _WebsocketConfigConstruct, + transport_type=TransportType.WEBSOCKET) +class WebsocketConfig(NamedTuple): + """! + @brief WebSocket client/server configuration settings. + """ + enabled: bool = True + direction: TransportDirection = TransportDirection.SERVER + port: int = 0 + remote_address: str = '' + + +_UNIXSocketConfigConstruct = Struct( + "enabled" / Flag, + "direction" / AutoEnum(Int8ul, TransportDirection), + "socket_type" / AutoEnum(Int8ul, SocketType), + Padding(1), + "path" / PaddedString(64, 'utf8'), +) + + +@_conf_gen.create_interface_config_class(InterfaceConfigType.ALL_PARAMETERS, _UNIXSocketConfigConstruct, + transport_type=TransportType.UNIX) +class UNIXSocketConfig(NamedTuple): + """! + @brief UNIX domain socket client/server configuration settings. + """ + enabled: bool = True + direction: TransportDirection = TransportDirection.SERVER + socket_type: SocketType = SocketType.STREAM + path: str = '' + + +_SerialConfigConstruct = Struct( + "enabled" / Flag, + Padding(3), + "baud_rate" / Int32ul, + "path" / PaddedString(64, 'utf8'), +) + + +@_conf_gen.create_interface_config_class(InterfaceConfigType.ALL_PARAMETERS, _SerialConfigConstruct, + transport_type=TransportType.SERIAL) +class SerialConfig(NamedTuple): + """! + @brief Serial port (UART) configuration settings. + """ + enabled: bool = True + baud_rate: int = 0 + path: str = '' + + class InterfaceConfigSubmessage(NamedTuple): interface: InterfaceID = InterfaceID() subtype: InterfaceConfigType = InterfaceConfigType.INVALID