sdwire 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- backend/__init__.py +0 -0
- backend/detect.py +68 -0
- backend/device/sdwire.py +25 -0
- backend/device/sdwirec.py +40 -0
- backend/device/usb_device.py +33 -0
- backend/utils.py +56 -0
- sdwire/__init__.py +0 -0
- {sdwire-0.1.1.dist-info → sdwire-0.1.2.dist-info}/METADATA +1 -1
- sdwire-0.1.2.dist-info/RECORD +14 -0
- sdwire-0.1.2.dist-info/entry_points.txt +3 -0
- __init__.py +0 -1
- sdwire-0.1.1.dist-info/RECORD +0 -8
- sdwire-0.1.1.dist-info/entry_points.txt +0 -3
- /main.py → /sdwire/main.py +0 -0
- {sdwire-0.1.1.dist-info → sdwire-0.1.2.dist-info}/LICENSE +0 -0
- {sdwire-0.1.1.dist-info → sdwire-0.1.2.dist-info}/WHEEL +0 -0
backend/__init__.py
ADDED
File without changes
|
backend/detect.py
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
import logging
|
2
|
+
from typing import List
|
3
|
+
from adafruit_board_toolkit import circuitpython_serial as cpserial
|
4
|
+
from serial.tools.list_ports_common import ListPortInfo
|
5
|
+
|
6
|
+
import constants
|
7
|
+
from backend.device.sdwire import SDWire
|
8
|
+
from backend.device.sdwirec import SDWireC
|
9
|
+
from backend.device.usb_device import PortInfo
|
10
|
+
|
11
|
+
import usb.core
|
12
|
+
import usb.util
|
13
|
+
from usb.core import Device
|
14
|
+
|
15
|
+
log = logging.getLogger(__name__)
|
16
|
+
|
17
|
+
|
18
|
+
def get_sdwirec_devices() -> List[SDWireC]:
|
19
|
+
devices: List[Device] = usb.core.find(find_all=True)
|
20
|
+
if not devices:
|
21
|
+
log.info("no usb devices found while searching for SDWireC..")
|
22
|
+
return []
|
23
|
+
|
24
|
+
device_list = []
|
25
|
+
for device in devices:
|
26
|
+
product = None
|
27
|
+
serial = None
|
28
|
+
manufacturer = None
|
29
|
+
try:
|
30
|
+
product = device.product
|
31
|
+
serial = device.serial_number
|
32
|
+
manufacturer = device.manufacturer
|
33
|
+
except Exception as e:
|
34
|
+
log.debug(
|
35
|
+
"not able to get usb product, serial_number and manufacturer information, err: %s",
|
36
|
+
e,
|
37
|
+
)
|
38
|
+
|
39
|
+
# filter with product string to allow non Badger'd sdwire devices to be detected
|
40
|
+
if product == constants.SDWIREC_PRODUCT_STRING:
|
41
|
+
device_list.append(
|
42
|
+
SDWireC(port_info=PortInfo(None, product, manufacturer, serial, device))
|
43
|
+
)
|
44
|
+
|
45
|
+
return device_list
|
46
|
+
|
47
|
+
|
48
|
+
def get_sdwire_devices() -> List[SDWire]:
|
49
|
+
ports = cpserial.data_comports()
|
50
|
+
|
51
|
+
# Badgerd SDWire Gen2
|
52
|
+
# VID = 0x1209 PID = 0x2404
|
53
|
+
# Badgerd SDWireC
|
54
|
+
# VID = 0x04e8 PID = 0x6001
|
55
|
+
result = []
|
56
|
+
for p in ports:
|
57
|
+
if p.vid == constants.SDWIRE_GEN2_VID and p.pid == constants.SDWIRE_GEN2_PID:
|
58
|
+
result.append(
|
59
|
+
SDWire(
|
60
|
+
port_info=PortInfo(
|
61
|
+
p.device, p.product, p.manufacturer, p.serial_number, p
|
62
|
+
)
|
63
|
+
)
|
64
|
+
)
|
65
|
+
# Search for legacy SDWireC devices
|
66
|
+
legacy_devices = get_sdwirec_devices()
|
67
|
+
|
68
|
+
return result + legacy_devices
|
backend/device/sdwire.py
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
from serial import Serial
|
2
|
+
from backend.device.usb_device import USBDevice, PortInfo
|
3
|
+
|
4
|
+
|
5
|
+
class SDWire(USBDevice):
|
6
|
+
|
7
|
+
def __init__(self, port_info: PortInfo):
|
8
|
+
super().__init__(port_info)
|
9
|
+
|
10
|
+
@property
|
11
|
+
def serial_string(self) -> str:
|
12
|
+
return "sdwire_gen2_101"
|
13
|
+
|
14
|
+
def invoke(self, command: str) -> None:
|
15
|
+
with Serial(self.dev_string) as channel:
|
16
|
+
channel.timeout = 0.05
|
17
|
+
data = command.encode() + b"\n"
|
18
|
+
print(f"data={data}")
|
19
|
+
channel.write(data)
|
20
|
+
|
21
|
+
def __str__(self):
|
22
|
+
return f"{self.serial_string}\t\t[{self.product_string}::{self.manufacturer_string}]"
|
23
|
+
|
24
|
+
def __repr__(self):
|
25
|
+
return self.__str__()
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import logging
|
2
|
+
from pyftdi.ftdi import Ftdi
|
3
|
+
from serial import Serial
|
4
|
+
from backend.device.usb_device import USBDevice, PortInfo
|
5
|
+
|
6
|
+
log = logging.getLogger(__name__)
|
7
|
+
|
8
|
+
|
9
|
+
class SDWireC(USBDevice):
|
10
|
+
|
11
|
+
def __init__(self, port_info: PortInfo):
|
12
|
+
super().__init__(port_info)
|
13
|
+
|
14
|
+
def __str__(self):
|
15
|
+
return (
|
16
|
+
f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]"
|
17
|
+
)
|
18
|
+
|
19
|
+
def __repr__(self):
|
20
|
+
return self.__str__()
|
21
|
+
|
22
|
+
def switch_ts(self):
|
23
|
+
self._set_sdwire(1)
|
24
|
+
|
25
|
+
def switch_dut(self):
|
26
|
+
self._set_sdwire(0)
|
27
|
+
|
28
|
+
def _set_sdwire(self, target):
|
29
|
+
try:
|
30
|
+
ftdi = Ftdi()
|
31
|
+
ftdi.open_from_device(self.usb_device)
|
32
|
+
log.info(f"Set CBUS to 0x{0xF0 | target:02X}")
|
33
|
+
ftdi.set_bitmode(0xF0 | target, Ftdi.BitMode.CBUS)
|
34
|
+
ftdi.close()
|
35
|
+
except Exception as e:
|
36
|
+
import sys
|
37
|
+
|
38
|
+
log.debug("error while updating ftdi device", exc_info=1)
|
39
|
+
print("couldnt switch sdwire device")
|
40
|
+
sys.exit(1)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from collections import namedtuple
|
2
|
+
from serial.tools.list_ports_common import ListPortInfo
|
3
|
+
|
4
|
+
PortInfo = namedtuple(
|
5
|
+
"PortInfo", ("device", "product", "manufacturer", "serial", "usb_device")
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
class USBDevice:
|
10
|
+
__port_info = None
|
11
|
+
|
12
|
+
def __init__(self, port_info: PortInfo):
|
13
|
+
self.__port_info = port_info
|
14
|
+
|
15
|
+
@property
|
16
|
+
def usb_device(self):
|
17
|
+
return self.__port_info.usb_device
|
18
|
+
|
19
|
+
@property
|
20
|
+
def dev_string(self) -> str:
|
21
|
+
return self.__port_info.device
|
22
|
+
|
23
|
+
@property
|
24
|
+
def product_string(self) -> str:
|
25
|
+
return self.__port_info.product
|
26
|
+
|
27
|
+
@property
|
28
|
+
def manufacturer_string(self) -> str:
|
29
|
+
return self.__port_info.manufacturer
|
30
|
+
|
31
|
+
@property
|
32
|
+
def serial_string(self) -> str:
|
33
|
+
return self.__port_info.serial
|
backend/utils.py
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
import sys
|
2
|
+
import logging
|
3
|
+
import click
|
4
|
+
from backend.device.sdwire import SDWire
|
5
|
+
from backend.device.sdwirec import SDWireC
|
6
|
+
from backend import detect
|
7
|
+
|
8
|
+
log = logging.getLogger(__name__)
|
9
|
+
|
10
|
+
|
11
|
+
def handle_switch_host_command(ctx):
|
12
|
+
device = ctx.obj["device"]
|
13
|
+
if isinstance(device, SDWireC):
|
14
|
+
device.switch_ts()
|
15
|
+
|
16
|
+
|
17
|
+
def handle_switch_target_command(ctx):
|
18
|
+
device = ctx.obj["device"]
|
19
|
+
if isinstance(device, SDWireC):
|
20
|
+
device.switch_dut()
|
21
|
+
|
22
|
+
|
23
|
+
def handle_switch_off_command(ctx):
|
24
|
+
device = ctx.obj["device"]
|
25
|
+
if isinstance(device, SDWireC):
|
26
|
+
log.info("SDWireC or legacy sdwire devices dont have off functionality")
|
27
|
+
print("SDWireC dont have off functionality")
|
28
|
+
sys.exit(1)
|
29
|
+
|
30
|
+
|
31
|
+
def handle_switch_command(ctx, serial):
|
32
|
+
devices = detect.get_sdwire_devices()
|
33
|
+
|
34
|
+
if serial is None:
|
35
|
+
# check the devices
|
36
|
+
if len(devices) == 0:
|
37
|
+
raise click.UsageError("There is no sdwire device connected!")
|
38
|
+
if len(devices) > 1:
|
39
|
+
raise click.UsageError(
|
40
|
+
"There is more then 1 sdwire device connected, please use --serial|-s to specify!"
|
41
|
+
)
|
42
|
+
log.info("1 sdwire/sdwirec device detected")
|
43
|
+
ctx.obj["device"] = devices[0]
|
44
|
+
else:
|
45
|
+
for device in devices:
|
46
|
+
if device.serial_string == serial:
|
47
|
+
ctx.obj["device"] = device
|
48
|
+
break
|
49
|
+
else:
|
50
|
+
raise click.UsageError(
|
51
|
+
f"There is no such sdwire device connected with serial={serial}"
|
52
|
+
)
|
53
|
+
|
54
|
+
device = ctx.obj["device"]
|
55
|
+
if isinstance(device, SDWire):
|
56
|
+
device.invoke(" ".join(sys.argv[1:]))
|
sdwire/__init__.py
ADDED
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
sdwire/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
backend/detect.py,sha256=U1O5fbwEepFuCsxBl-MKhp1JBhQlKtBOiALxxcme5cg,2033
|
4
|
+
backend/device/sdwire.py,sha256=jNIbAqMk4cU2tRmYCYyb9lHZXFZqVb806z7STX-e6W4,689
|
5
|
+
backend/device/sdwirec.py,sha256=Uq2Y3XagHgZW6EPXmqoKiR93fV167mRmDTHIh0J6JqA,1049
|
6
|
+
backend/device/usb_device.py,sha256=6Mt24B22yTD4RdY24LgnRaVtbX60EPE2SAK-pN0ZESc,775
|
7
|
+
backend/utils.py,sha256=UXxO3eYHpYAjhp7p2CmQXORAC0_96ikXODUXRFg0LB0,1635
|
8
|
+
constants.py,sha256=Ip2d7ow5Nj0nO0OyHeiXuGJJcK33BGmTspLtNEduFAo,127
|
9
|
+
sdwire/main.py,sha256=adVUleGCnEEQp2MakaD1t3muaevxH8W74rpJGxuX98o,2135
|
10
|
+
sdwire-0.1.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
11
|
+
sdwire-0.1.2.dist-info/METADATA,sha256=2DBOL0aPLvHgVM8ovpbaq0l-ZIA2KiQ63bSYRKIQ_ek,1839
|
12
|
+
sdwire-0.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
+
sdwire-0.1.2.dist-info/entry_points.txt,sha256=pxy0zJKVcNWXPk5PtNjTLExOBpqFNth37wtdYdYRXCE,43
|
14
|
+
sdwire-0.1.2.dist-info/RECORD,,
|
__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
print(__file__)
|
sdwire-0.1.1.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
__init__.py,sha256=F67sqTglxRRS7eDtAnZ4JXt3DqT0l7tEvUMbM75n-Dg,16
|
2
|
-
constants.py,sha256=Ip2d7ow5Nj0nO0OyHeiXuGJJcK33BGmTspLtNEduFAo,127
|
3
|
-
main.py,sha256=adVUleGCnEEQp2MakaD1t3muaevxH8W74rpJGxuX98o,2135
|
4
|
-
sdwire-0.1.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
5
|
-
sdwire-0.1.1.dist-info/METADATA,sha256=8Pd6_omUvK9txgweNZsgVwVl2CJ6zArCaArsrOega6o,1839
|
6
|
-
sdwire-0.1.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
7
|
-
sdwire-0.1.1.dist-info/entry_points.txt,sha256=OCGskaVs56CWHqKFr0_vFxqMv039fWVeAizS8-TTcZ0,36
|
8
|
-
sdwire-0.1.1.dist-info/RECORD,,
|
/main.py → /sdwire/main.py
RENAMED
File without changes
|
File without changes
|
File without changes
|