Skip to content

Commit

Permalink
host: add usb1 bulk transfer backend
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed May 17, 2024
1 parent 5df4eb5 commit 4729370
Show file tree
Hide file tree
Showing 2 changed files with 544 additions and 4 deletions.
26 changes: 22 additions & 4 deletions host/pygreat/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,27 @@ class CommsBackend(object):

@classmethod
def from_device_uri(cls, **device_uri):
""" Creates a CommsBackend object apporpriate for the given device_uri. """
""" Creates a CommsBackend object appropriate for the given device_uri. """

#FIXME: implment this properly

from .comms_backends.usb import USBCommsBackend
#FIXME: implement this properly

# TODO: handle providing board "URIs", like "usb://1234abcd/?param=value",
# and automatic resolution to a backend?
# TODO: support more than USB

# Use the usb1 backend if this is a Cynthion.
# TODO use cynthion vendor/product id and interface protocol field
# TODO we should probably rather run through the backends and return
# the backend that can successfully match the device_identifiers
if 'idVendor' in device_uri and 'idProduct' in device_uri:
idVendor = device_uri['idVendor']
idProduct = device_uri['idProduct']
if idVendor == 0x1d50 and idProduct == 0x615b:
from .comms_backends.usb1 import USB1CommsBackend
return USB1CommsBackend(**device_uri)

# XXX: for now, just create a USB backend, as that's all we support
from .comms_backends.usb import USBCommsBackend
return USBCommsBackend(**device_uri)


Expand Down Expand Up @@ -579,6 +589,14 @@ def pack(cls, format_string, *args):
@classmethod
@memoize_with_lru_cache(maxsize=128)
def unpack(cls, format_string, raw_bytes):
try:
return cls._unpack(cls, format_string, raw_bytes)
except Exception as e:
import logging
logging.error(f"Failed to unpack struct from raw bytes: {len(raw_bytes)} bytes => {raw_bytes}")
raise e

def _unpack(cls, format_string, raw_bytes):
""" Extended version of struct.unpack() for libgreat communciations.
Accepts mostly the same arguments as struct.pack, with the following
Expand Down
Loading

0 comments on commit 4729370

Please sign in to comment.