From b4d3ec9d51a3403fffb6d9c44beaa7014f7306cf Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Wed, 20 Oct 2021 11:04:27 -0500 Subject: [PATCH] Refactor base interface for easier testing --- pycoax/coax/interface.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pycoax/coax/interface.py b/pycoax/coax/interface.py index 6c682b8..5ae3b95 100644 --- a/pycoax/coax/interface.py +++ b/pycoax/coax/interface.py @@ -16,11 +16,7 @@ class Interface: """Execute one or more commands.""" (normalized_commands, has_multiple_commands) = _normalize_commands(commands) - (outbound_frames, response_lengths) = _pack_outbound_frames(normalized_commands) - - inbound_frames = self._transmit_receive(outbound_frames, response_lengths, timeout) - - responses = _unpack_inbound_frames(inbound_frames, normalized_commands) + responses = self._execute(normalized_commands, timeout) if has_multiple_commands: return responses @@ -32,6 +28,15 @@ class Interface: return response + def _execute(self, commands, timeout): + (outbound_frames, response_lengths) = _pack_outbound_frames(commands) + + inbound_frames = self._transmit_receive(outbound_frames, response_lengths, timeout) + + responses = _unpack_inbound_frames(inbound_frames, commands) + + return responses + def _transmit_receive(self, outbound_frames, response_lengths, timeout): raise NotImplementedError