From 8d659a6aa934300334f3a2248703807c1605643f Mon Sep 17 00:00:00 2001 From: Simon Alibert Date: Sat, 15 Mar 2025 22:26:47 +0100 Subject: [PATCH] Update mock SDKs --- tests/mocks/mock_dynamixel_sdk.py | 31 ++++++++++++++++++++++++++++-- tests/mocks/mock_scservo_sdk.py | 32 +++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/tests/mocks/mock_dynamixel_sdk.py b/tests/mocks/mock_dynamixel_sdk.py index a4d36bd90..6212285ee 100644 --- a/tests/mocks/mock_dynamixel_sdk.py +++ b/tests/mocks/mock_dynamixel_sdk.py @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Mocked classes and functions from dynamixel_sdk to allow for continuous integration -and testing code logic that requires hardware and devices (e.g. robot arms, cameras) +# ruff: noqa: N802, E741 + +""" +Mocked classes and functions from dynamixel_sdk to allow for testing DynamixelMotorsBus code. Warning: These mocked versions are minimalist. They do not exactly mock every behaviors from the original classes and functions (e.g. return types might be None instead of boolean). @@ -43,6 +45,31 @@ def get_default_motor_values(motor_index): } +# Macro for Control Table Value +def DXL_MAKEWORD(a, b): + return (a & 0xFF) | ((b & 0xFF) << 8) + + +def DXL_MAKEDWORD(a, b): + return (a & 0xFFFF) | (b & 0xFFFF) << 16 + + +def DXL_LOWORD(l): + return l & 0xFFFF + + +def DXL_HIWORD(l): + return (l >> 16) & 0xFFFF + + +def DXL_LOBYTE(w): + return w & 0xFF + + +def DXL_HIBYTE(w): + return (w >> 8) & 0xFF + + class PortHandler: def __init__(self, port): self.port = port diff --git a/tests/mocks/mock_scservo_sdk.py b/tests/mocks/mock_scservo_sdk.py index 5bbb758d2..21a3652bc 100644 --- a/tests/mocks/mock_scservo_sdk.py +++ b/tests/mocks/mock_scservo_sdk.py @@ -11,8 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Mocked classes and functions from dynamixel_sdk to allow for continuous integration -and testing code logic that requires hardware and devices (e.g. robot arms, cameras) + +# ruff: noqa: N802, E741 + +""" +Mocked classes and functions from scservo_sdk to allow for testing FeetechMotorsBus code. Warning: These mocked versions are minimalist. They do not exactly mock every behaviors from the original classes and functions (e.g. return types might be None instead of boolean). @@ -52,6 +55,31 @@ def get_default_motor_values(motor_index): } +# Macro for Control Table Value +def SCS_MAKEWORD(a, b): + return (a & 0xFF) | ((b & 0xFF) << 8) + + +def SCS_MAKEDWORD(a, b): + return (a & 0xFFFF) | (b & 0xFFFF) << 16 + + +def SCS_LOWORD(l): + return l & 0xFFFF + + +def SCS_HIWORD(l): + return (l >> 16) & 0xFFFF + + +def SCS_LOBYTE(w): + return w & 0xFF + + +def SCS_HIBYTE(w): + return (w >> 8) & 0xFF + + class PortHandler: def __init__(self, port): self.port = port