Skip to content

Commit

Permalink
dfu.Command refactored as dfu.Request
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy committed May 13, 2024
1 parent 087e564 commit 8d839b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions pydfuutil/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def to_string(self):
return _status_to_string(self)


class Command(IntEnum):
class Request(IntEnum):
"""Dfu commands"""
DETACH = 0
DNLOAD = 1
Expand Down Expand Up @@ -271,7 +271,7 @@ def _detach(device: usb.core.Device, interface: int, timeout: int) -> bytes:
bmRequestType=usb.util.ENDPOINT_OUT
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.DETACH,
bRequest=Request.DETACH,
wValue=timeout,
wIndex=interface,
data_or_wLength=None,
Expand Down Expand Up @@ -302,7 +302,7 @@ def _download(device: usb.core.Device,
bmRequestType=usb.util.ENDPOINT_OUT
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.DNLOAD,
bRequest=Request.DNLOAD,
wValue=transaction,
wIndex=interface,
data_or_wLength=data_or_length,
Expand Down Expand Up @@ -334,7 +334,7 @@ def _upload(device: usb.core.Device,
bmRequestType=usb.util.ENDPOINT_IN
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.UPLOAD,
bRequest=Request.UPLOAD,
wValue=transaction,
wIndex=interface,
data_or_wLength=data_or_length,
Expand Down Expand Up @@ -363,7 +363,7 @@ def _get_status(device: usb.core.Device, interface: int) -> StatusRetVal:
bmRequestType=usb.util.ENDPOINT_IN
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.GETSTATUS,
bRequest=Request.GETSTATUS,
wValue=0,
wIndex=interface,
data_or_wLength=length,
Expand Down Expand Up @@ -394,7 +394,7 @@ def _clear_status(device: usb.core.Device, interface: int) -> int:
bmRequestType=usb.util.ENDPOINT_OUT
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.CLRSTATUS,
bRequest=Request.CLRSTATUS,
wValue=0,
wIndex=interface,
data_or_wLength=None,
Expand All @@ -420,7 +420,7 @@ def _get_state(device: usb.core.Device, interface: int) -> [State, int]:
bmRequestType=usb.util.ENDPOINT_IN
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.GETSTATE,
bRequest=Request.GETSTATE,
wValue=0,
wIndex=interface,
data_or_wLength=length,
Expand Down Expand Up @@ -450,7 +450,7 @@ def _abort(device: usb.core.Device, interface: int) -> int:
bmRequestType=usb.util.ENDPOINT_OUT
| usb.util.CTRL_TYPE_CLASS
| usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=Command.ABORT,
bRequest=Request.ABORT,
wValue=0,
wIndex=interface,
data_or_wLength=None,
Expand Down Expand Up @@ -545,7 +545,7 @@ def _abort_to_idle(dif: DfuIf):
DEBUG_LEVEL: int = 0

__all__ = (
"Command",
"Request",
"Status",
"State",
"StatusRetVal",
Expand Down
4 changes: 2 additions & 2 deletions pydfuutil/dfuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def upload(dif: dfu.DfuIf, data: bytes, transaction: int) -> int:
bmRequestType=usb.util.ENDPOINT_IN |
usb.util.CTRL_TYPE_CLASS |
usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=dfu.Command.UPLOAD,
bRequest=dfu.Request.UPLOAD,
wValue=transaction,
wIndex=dif.interface,
data_or_wLength=data,
Expand All @@ -172,7 +172,7 @@ def download(dif: dfu.DfuIf, data: bytes, transaction: int) -> int:
bmRequestType=usb.util.ENDPOINT_OUT |
usb.util.CTRL_TYPE_CLASS |
usb.util.CTRL_RECIPIENT_INTERFACE,
bRequest=dfu.Command.DNLOAD,
bRequest=dfu.Request.DNLOAD,
wValue=transaction,
wIndex=dif.interface,
data_or_wLength=data,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_detach(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0x21 | 0x01,
bRequest=dfu.Command.DETACH, # Assuming Command.DETACH is 23
bRequest=dfu.Request.DETACH, # Assuming Request.DETACH is 23
wValue=timeout,
wIndex=interface,
data_or_wLength=None,
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_upload(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0xa1,
bRequest=dfu.Command.UPLOAD, # Assuming Command.UPLOAD
bRequest=dfu.Request.UPLOAD, # Assuming Request.UPLOAD
wValue=transaction,
wIndex=interface,
data_or_wLength=data,
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_dwnload(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0x21,
bRequest=dfu.Command.DNLOAD, # Assuming Command.DNLOAD
bRequest=dfu.Request.DNLOAD, # Assuming Request.DNLOAD
wValue=transaction,
wIndex=interface,
data_or_wLength=data,
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_get_status(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0xa1,
bRequest=dfu.Command.GETSTATUS, # Assuming Command.GETSTATUS
bRequest=dfu.Request.GETSTATUS, # Assuming Request.GETSTATUS
wValue=transaction,
wIndex=interface,
data_or_wLength=length,
Expand All @@ -148,7 +148,7 @@ def test_clear_status(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0x21,
bRequest=dfu.Command.CLRSTATUS, # Assuming Command.CLRSTATUS
bRequest=dfu.Request.CLRSTATUS, # Assuming Request.CLRSTATUS
wValue=transaction,
wIndex=interface,
data_or_wLength=None,
Expand All @@ -175,7 +175,7 @@ def test_abort(self, mock_find):
# Assertions
mock_device.ctrl_transfer.assert_called_once_with(
bmRequestType=0x21,
bRequest=dfu.Command.ABORT, # Assuming Command.ABORT
bRequest=dfu.Request.ABORT, # Assuming Request.ABORT
wValue=transaction,
wIndex=interface,
data_or_wLength=None,
Expand Down

0 comments on commit 8d839b1

Please sign in to comment.