Skip to content

Commit

Permalink
Default to ZMQ with --no-zmq to fallback on TTS (#174)
Browse files Browse the repository at this point in the history
* Default to ZMQ, with --no-zmq to fallback on TTS

* "default" to True

* Revert back to exit()
  • Loading branch information
thomas-bc authored May 6, 2024
1 parent 9c5f4f5 commit f983bb6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
60 changes: 21 additions & 39 deletions src/fprime_gds/executables/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,8 @@
from fprime_gds.executables.utils import find_app, find_dict, get_artifacts_root
from fprime_gds.plugin.definitions import PluginType
from fprime_gds.plugin.system import Plugins
from fprime_gds.common.zmq_transport import ZmqClient

# Optional import: ZeroMQ. Requires package: pyzmq
try:
import zmq

from fprime_gds.common.zmq_transport import ZmqClient
except ImportError:
zmq = None
ZmqClient = None

# Optional import: Serial Adapter. Requires package: SerialAdapter
try:
from fprime_gds.common.communication.adapters.uart import SerialAdapter
except ImportError:
SerialAdapter = None

GUIS = ["none", "html"]

Expand Down Expand Up @@ -197,7 +184,6 @@ def parse_args(
sys.exit(-1)
except Exception as exc:
print(f"[ERROR] {exc}", file=sys.stderr)
raise
sys.exit(-1)
return args_ns, parser

Expand Down Expand Up @@ -578,40 +564,37 @@ class MiddleWareParser(ParserBase):

def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
"""Return arguments necessary to run a and connect to the GDS middleware"""
# May use ZMQ transportation layer if zmq package is available
zmq_arguments = {}
if zmq is not None and ZmqClient is not None:
zmq_arguments = {
("--zmq",): {
"dest": "zmq",
"action": "store_true",
"help": "Switch to using the ZMQ transportation layer",
"default": False,
},
("--zmq-transport",): {
"dest": "zmq_transport",
"nargs": 2,
"help": "Pair of URls used with --zmq to setup ZeroMQ transportation [default: %(default)s]",
"default": [
"ipc:///tmp/fprime-server-in",
"ipc:///tmp/fprime-server-out",
],
"metavar": ("serverInUrl", "serverOutUrl"),
},
}
zmq_arguments = {
("--no-zmq",): {
"dest": "zmq",
"action": "store_false",
"help": "Disable ZMQ transportation layer, falling back to TCP socket server.",
"default": True,
},
("--zmq-transport",): {
"dest": "zmq_transport",
"nargs": 2,
"help": "Pair of URls used with --zmq to setup ZeroMQ transportation [default: %(default)s]",
"default": [
"ipc:///tmp/fprime-server-in",
"ipc:///tmp/fprime-server-out",
],
"metavar": ("serverInUrl", "serverOutUrl"),
},
}
tts_arguments = {
("--tts-port",): {
"dest": "tts_port",
"action": "store",
"type": int,
"help": "Set the threaded TCP socket server port [default: %(default)s]",
"help": "Set the threaded TCP socket server port when ZMQ is not used [default: %(default)s]",
"default": 50050,
},
("--tts-addr",): {
"dest": "tts_addr",
"action": "store",
"type": str,
"help": "Set the threaded TCP socket server address [default: %(default)s]",
"help": "Set the threaded TCP socket server address when ZMQ is not used [default: %(default)s]",
"default": "0.0.0.0",
},
}
Expand All @@ -626,7 +609,6 @@ def handle_arguments(self, args, **kwargs):
:return: args namespace
"""
is_client = kwargs.get("client", False)
args.zmq = getattr(args, "zmq", False)
tts_connection_address = (
args.tts_addr.replace("0.0.0.0", "127.0.0.1")
if is_client
Expand Down
13 changes: 3 additions & 10 deletions src/fprime_gds/executables/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@
import logging
import signal
import sys

from pathlib import Path

# Required adapters built on standard tools
try:
from fprime_gds.common.zmq_transport import ZmqGround
except ImportError:
ZmqGround = None
import fprime_gds.common.communication.adapters.base
import fprime_gds.common.communication.adapters.ip
import fprime_gds.common.communication.ground
import fprime_gds.common.logger
import fprime_gds.executables.cli
from fprime_gds.common.communication.updown import Downlinker, Uplinker
from fprime_gds.common.zmq_transport import ZmqGround

# Uses non-standard PIP package pyserial, so test the waters before getting a hard-import crash
try:
Expand Down Expand Up @@ -68,11 +64,8 @@ def main():
sys.exit(-1)

# Create the handling components for either side of this script, adapter for hardware, and ground for the GDS side
if args.zmq and ZmqGround is None:
print("[ERROR] ZeroMQ is not available. Install pyzmq.", file=sys.stderr)
sys.exit(-1)
elif args.zmq:
ground = fprime_gds.common.zmq_transport.ZmqGround(args.zmq_transport)
if args.zmq:
ground = ZmqGround(args.zmq_transport)
else:
ground = fprime_gds.common.communication.ground.TCPGround(
args.tts_addr, args.tts_port
Expand Down
2 changes: 1 addition & 1 deletion test/fprime_gds/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def start_up(request):
extra_plugins, flags = request.param

command_arguments = ["fprime-gds", "-n", "--dictionary", str( parent_path / "sample" / "dictionary.xml"),
"--zmq", "--zmq-transport", "ipc:///tmp/fprime-test-in", "ipc:///tmp/fprime-test-out",
"--zmq-transport", "ipc:///tmp/fprime-test-in", "ipc:///tmp/fprime-test-out",
"-g", "none"] + flags

# Update the environment to side-load python
Expand Down

0 comments on commit f983bb6

Please sign in to comment.