Skip to content

Commit

Permalink
Merge pull request #151 from robamu-org/update-tree-commanding-types
Browse files Browse the repository at this point in the history
Update tree commanding types
  • Loading branch information
robamu authored Apr 23, 2024
2 parents 1f6837a + 4a88306 commit fd4accd
Show file tree
Hide file tree
Showing 32 changed files with 286 additions and 317 deletions.
23 changes: 18 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,32 @@ Starting from v4.0.0, this project adheres to [Semantic Versioning](http://semve

# [unreleased]

# [v8.0.0rc2] 2024-04-22
# [v8.0.0rc2] 2024-04-23

## Fixed

- TCP client implementation re-worked to be thread-safe. Also added more graceful shut-down
handling. Consequently, the thread spawned by the TCP client is not daemonic anymore.
- Bumped `spacepackets` to release range >=0.24, <0.25.
- Bumped `cfdp-py` to v0.1.1.

## Changed

- Renamed `DefaultProcedureParams` to `TreeCommandingParams`.
- Renamed `TcParams` to `CommandingParams`.
- Renamed `DefaultProcedureInfo` to `TreeCommandingProcedure`.
- Renamed `add_default_procedure_arguments` to `add_tree_commanding_arguments`.
- Renamed `TcProcedureType.DEFAULT` to `TcProcedureType.TREE_COMMANDING`.
- Replaced `TelemetryListT` by `List[bytes]`.
- Renamed `TcpSpacePacketsComIF` to `TcpSpacePacketsClient`.
- Renamed `UdpComIF` to `UdpClient`.

## Removed

- `CoreServiceList` enumeration.
- `DEFAULT_APID` and `DEBUG_MODE` globals.

## Fixed

- TCP client implementation re-worked to be thread-safe. Also added more graceful shut-down
handling. Consequently, the thread spawned by the TCP client is not daemonic anymore.

# [v8.0.0rc1] 2024-01-24

## Fixed
Expand Down
16 changes: 9 additions & 7 deletions examples/app/tmtcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
TcProcedureType,
TcQueueEntryType,
)
from tmtccmd.util import FileSeqCountProvider, ObjectIdDictT, PusFileSeqCountProvider
from tmtccmd.util import ObjectIdDictT
from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider

_LOGGER = logging.getLogger()

Expand Down Expand Up @@ -234,14 +235,14 @@ def send_cb(self, send_params: SendCbParams):
_LOGGER.info(log_entry.log_str)

def queue_finished_cb(self, helper: ProcedureWrapper):
if helper.proc_type == TcProcedureType.DEFAULT:
def_proc = helper.to_def_procedure()
if helper.proc_type == TcProcedureType.TREE_COMMANDING:
def_proc = helper.to_tree_commanding_procedure()
_LOGGER.info(f"Queue handling finished for command {def_proc.cmd_path}")

def feed_cb(self, helper: ProcedureWrapper, wrapper: FeedWrapper):
self.queue_helper.queue_wrapper = wrapper.queue_wrapper
if helper.proc_type == TcProcedureType.DEFAULT:
def_proc = helper.to_def_procedure()
if helper.proc_type == TcProcedureType.TREE_COMMANDING:
def_proc = helper.to_tree_commanding_procedure()
cmd_path = def_proc.cmd_path
assert cmd_path is not None
# Path starts with / so the first entry of the list will be an empty string. We cut
Expand Down Expand Up @@ -278,8 +279,8 @@ def main(): # noqa: C901
else:
post_args_wrapper.set_params_with_prompts(proc_wrapper)
params.apid = EXAMPLE_PUS_APID
if params.app_params.print_tree:
perform_tree_printout(params.app_params, hook_obj.get_command_definitions())
if params.tc_params.print_tree:
perform_tree_printout(params.tc_params, hook_obj.get_command_definitions())
sys.exit(0)
setup_args = SetupWrapper(
hook_obj=hook_obj, setup_params=params, proc_param_wrapper=proc_wrapper
Expand Down Expand Up @@ -327,6 +328,7 @@ def main(): # noqa: C901
elif state.request == BackendRequest.CALL_NEXT:
pass
except KeyboardInterrupt:
tmtc_backend.close_com_if()
sys.exit(0)


Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dependencies = [
"Deprecated~=1.2",
"pyserial~=3.5",
"dle-encoder~=0.2.3",
"spacepackets~=0.23.0",
"cfdp-py~=0.1.0"
"spacepackets>=0.24.0, <0.25",
"cfdp-py~=0.1.1",
# "spacepackets @ git+https://github.com/us-irs/spacepackets-py@main"
]

Expand All @@ -56,7 +56,7 @@ test = [
[tool.setuptools.packages]
find = {}

[tool.ruff]
[tool.ruff.lint]
ignore = ["E501"]
[tool.ruff.extend-per-file-ignores]
[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["F401"]
2 changes: 1 addition & 1 deletion release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The steps shown here are for Ubuntu/MacOS.
with date and new `unreleased`section.
4. Run tests with `pytest .`
5. Run auto-formatter with `black .`
6. Run linter with `ruff .`
6. Run linter with `ruff check .`
7. Wait for CI/CD results. This also runs the tests on different
operating systems

Expand Down
2 changes: 1 addition & 1 deletion tests/com/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_dummy_if(self):
dummy_com_if.initialize()
self.assertTrue(dummy_com_if.initialized)
self.assertFalse(dummy_com_if.data_available())
dummy_com_if.send(PusTelecommand(service=17, subservice=1).pack())
dummy_com_if.send(PusTelecommand(apid=0x02, service=17, subservice=1).pack())
self.assertTrue(dummy_com_if.data_available())
replies = dummy_com_if.receive()
# Full verification set (acceptance, start and completion) and ping reply
Expand Down
2 changes: 1 addition & 1 deletion tests/com/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self) -> None:
self.base_data = bytes([0, 1, 2, 3])
self.ping_cmd = PusTelecommand(service=17, subservice=1, apid=0x22)
self.ping_reply = PusTelemetry(
service=17, subservice=2, apid=0x22, time_provider=None
service=17, subservice=2, apid=0x22, timestamp=bytes()
)
self.tcp_client = TcpSpacePacketsClient(
"tcp",
Expand Down
50 changes: 25 additions & 25 deletions tests/config/test_args_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from tmtccmd import CoreModeConverter, CoreModeList
from tmtccmd.config import CfdpParams
from tmtccmd.config.args import (
AppParams,
DefaultProcedureParams,
CommandingParams,
TreeCommandingParams,
SetupParams,
args_to_all_params_tmtc,
cfdp_args_to_cfdp_params,
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_basic(self):
self.assertEqual(self.params.tc_params.delay, 0)
self.assertEqual(self.params.backend_params.mode, "")
self.assertEqual(self.params.backend_params.com_if_id, "")
def_params = DefaultProcedureParams(None)
def_params = TreeCommandingParams(None)
args_to_all_params_tmtc(
pargs=self.pargs,
params=self.params,
Expand All @@ -78,7 +78,7 @@ def test_basic(self):
def test_delay_set(self):
self.simple_pargs_cli_set()
self.pargs.delay = 2.0
def_params = DefaultProcedureParams(None)
def_params = TreeCommandingParams(None)
args_to_all_params_tmtc(
pargs=self.pargs,
params=self.params,
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_cfdp_conversion_acked(self):

def test_auto_listener_mode(self):
self.auto_listener_cli_set()
def_params = DefaultProcedureParams(None)
def_params = TreeCommandingParams(None)
args_to_all_params_tmtc(
pargs=self.pargs,
params=self.params,
Expand All @@ -138,7 +138,7 @@ def test_auto_listener_mode(self):
def test_tree_printout_conversion_default(self):
self.base_cli_set()
self.pargs.print_tree = []
def_params = DefaultProcedureParams(None)
def_params = TreeCommandingParams(None)
args_to_all_params_tmtc(
pargs=self.pargs,
params=self.params,
Expand All @@ -147,14 +147,14 @@ def test_tree_printout_conversion_default(self):
def_tmtc_params=def_params,
assign_com_if=False,
)
self.assertTrue(self.params.app_params.print_tree)
self.assertTrue(self.params.app_params.tree_print_with_description)
self.assertIsNone(self.params.app_params.tree_print_max_depth)
self.assertTrue(self.params.tc_params.print_tree)
self.assertTrue(self.params.tc_params.tree_print_with_description)
self.assertIsNone(self.params.tc_params.tree_print_max_depth)

def test_tree_printout_conversion_with_custom_args(self):
self.base_cli_set()
self.pargs.print_tree = ["b", "2"]
def_params = DefaultProcedureParams(None)
def_params = TreeCommandingParams(None)
args_to_all_params_tmtc(
pargs=self.pargs,
params=self.params,
Expand All @@ -163,16 +163,16 @@ def test_tree_printout_conversion_with_custom_args(self):
def_tmtc_params=def_params,
assign_com_if=False,
)
self.assertTrue(self.params.app_params.print_tree)
self.assertFalse(self.params.app_params.tree_print_with_description)
self.assertEqual(self.params.app_params.tree_print_max_depth, 2)
self.assertTrue(self.params.tc_params.print_tree)
self.assertFalse(self.params.tc_params.tree_print_with_description)
self.assertEqual(self.params.tc_params.tree_print_max_depth, 2)

@patch("builtins.print")
def test_tree_printout_0(self, print_mock: MagicMock):
root_node_only = CmdTreeNode.root_node()
app_params = AppParams()
app_params.print_tree = True
perform_tree_printout(app_params, root_node_only)
tc_params = CommandingParams()
tc_params.print_tree = True
perform_tree_printout(tc_params, root_node_only)
self.assertEqual(len(print_mock.call_args_list), 2)
self.assertEqual(
print_mock.call_args_list[0],
Expand All @@ -185,10 +185,10 @@ def test_tree_printout_0(self, print_mock: MagicMock):
@patch("builtins.print")
def test_tree_printout_1(self, print_mock: MagicMock):
root_node_only = CmdTreeNode.root_node()
app_params = AppParams()
app_params.print_tree = True
app_params.tree_print_with_description = False
perform_tree_printout(app_params, root_node_only)
tc_params = CommandingParams()
tc_params.print_tree = True
tc_params.tree_print_with_description = False
perform_tree_printout(tc_params, root_node_only)
self.assertEqual(len(print_mock.call_args_list), 2)
self.assertEqual(
print_mock.call_args_list[0],
Expand All @@ -200,11 +200,11 @@ def test_tree_printout_1(self, print_mock: MagicMock):
def test_tree_printout_2(self, print_mock: MagicMock):
root_node_only = CmdTreeNode.root_node()
root_node_only.add_child(CmdTreeNode("acs", "ACS Subsystem"))
app_params = AppParams()
app_params.print_tree = True
app_params.tree_print_with_description = False
app_params.tree_print_max_depth = 0
perform_tree_printout(app_params, root_node_only)
tc_params = CommandingParams()
tc_params.print_tree = True
tc_params.tree_print_with_description = False
tc_params.tree_print_max_depth = 0
perform_tree_printout(tc_params, root_node_only)
self.assertEqual(len(print_mock.call_args_list), 2)
self.assertEqual(
print_mock.call_args_list[0],
Expand Down
11 changes: 6 additions & 5 deletions tests/config/test_args_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
add_tmtc_mode_arguments,
add_generic_arguments,
add_default_com_if_arguments,
add_default_procedure_arguments,
add_tree_commanding_arguments,
)


Expand All @@ -29,14 +29,15 @@ def test_valid_argument_1(self):
self.assertEqual(args.mode, "one-q")

def test_def_proc_argument_empty(self):
add_default_procedure_arguments(self.arg_parser)
add_tree_commanding_arguments(self.arg_parser)
args = self.arg_parser.parse_args([])
self.assertIsNone(args.cmd_path)

def test_def_proc_argument_valid(self):
add_default_procedure_arguments(self.arg_parser)
add_tree_commanding_arguments(self.arg_parser)
args = self.arg_parser.parse_args(["-p", "/PING"])
self.assertEqual(args.cmd_path, "/PING")
self.assertEqual(args.print_tree, None)

def test_generic_arguments_empty(self):
add_generic_arguments(self.arg_parser)
Expand All @@ -61,7 +62,7 @@ def test_com_if_arguments_valid(self):
self.assertEqual(args.com_if, "udp")

def test_tree_print_args_0(self):
add_default_procedure_arguments(self.arg_parser)
add_tree_commanding_arguments(self.arg_parser)
args = self.arg_parser.parse_args(["-T"])
self.assertEqual(args.print_tree, [])
args = self.arg_parser.parse_args(["--print-tree"])
Expand All @@ -70,6 +71,6 @@ def test_tree_print_args_0(self):
self.assertEqual(args.print_tree, [])

def test_tree_print_args_1(self):
add_default_procedure_arguments(self.arg_parser)
add_tree_commanding_arguments(self.arg_parser)
args = self.arg_parser.parse_args(["-T", "b", "2"])
self.assertEqual(args.print_tree, ["b", "2"])
2 changes: 1 addition & 1 deletion tests/tc/test_srv20.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.boolean_param = create_scalar_boolean_parameter(
object_id=self.obj_id, domain_id=1, unique_id=5, parameter=True
)
self.tc = create_load_param_cmd(self.boolean_param)
self.tc = create_load_param_cmd(0x05, self.boolean_param)

def test_basic(self):
# 12 bytes of generic parameter header + 1 byte parameter itself
Expand Down
Loading

0 comments on commit fd4accd

Please sign in to comment.