sdwire 0.2.2__tar.gz → 0.2.4__tar.gz
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.
- {sdwire-0.2.2 → sdwire-0.2.4}/PKG-INFO +3 -4
- {sdwire-0.2.2 → sdwire-0.2.4}/pyproject.toml +3 -4
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/detect.py +17 -14
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/device/sdwire.py +13 -2
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/device/sdwirec.py +17 -4
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/device/usb_device.py +3 -1
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/utils.py +5 -3
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/main.py +6 -10
- {sdwire-0.2.2 → sdwire-0.2.4}/LICENSE +0 -0
- {sdwire-0.2.2 → sdwire-0.2.4}/README.md +0 -0
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/__init__.py +0 -0
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/backend/__init__.py +0 -0
- {sdwire-0.2.2 → sdwire-0.2.4}/sdwire/constants.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sdwire
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.4
|
4
4
|
Summary: CLI application to interact with Badgerd SDWire devices
|
5
5
|
License: GPL-3
|
6
6
|
Author: Talha Can Havadar
|
@@ -9,11 +9,10 @@ Requires-Python: >=3.12,<4.0
|
|
9
9
|
Classifier: License :: Other/Proprietary License
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
12
|
-
Requires-Dist: adafruit-board-toolkit (>=1.1.1,<2.0.0)
|
13
12
|
Requires-Dist: click (>=8.1.7,<9.0.0)
|
14
|
-
Requires-Dist: pyftdi (>=0.
|
13
|
+
Requires-Dist: pyftdi (>=0.56.0,<0.57.0)
|
14
|
+
Requires-Dist: pyudev (>=0.24.3,<0.25.0)
|
15
15
|
Requires-Dist: pyusb (>=1.2.1,<2.0.0)
|
16
|
-
Requires-Dist: semver (>=3.0.2,<4.0.0)
|
17
16
|
Description-Content-Type: text/markdown
|
18
17
|
|
19
18
|
# CLI for Badgerd SDWire Devices
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "sdwire"
|
3
|
-
version = "0.2.
|
3
|
+
version = "0.2.4"
|
4
4
|
description = "CLI application to interact with Badgerd SDWire devices"
|
5
5
|
authors = ["Talha Can Havadar <havadartalha@gmail.com>"]
|
6
6
|
license = "GPL-3"
|
@@ -10,10 +10,9 @@ packages = [{ include = "sdwire" }]
|
|
10
10
|
[tool.poetry.dependencies]
|
11
11
|
python = "^3.12"
|
12
12
|
click = "^8.1.7"
|
13
|
-
adafruit-board-toolkit = "^1.1.1"
|
14
|
-
semver = "^3.0.2"
|
15
13
|
pyusb = "^1.2.1"
|
16
|
-
pyftdi = "^0.
|
14
|
+
pyftdi = "^0.56.0"
|
15
|
+
pyudev = "^0.24.3"
|
17
16
|
|
18
17
|
|
19
18
|
[tool.poetry.group.dev.dependencies]
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import logging
|
2
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
3
|
|
6
4
|
from sdwire import constants
|
7
5
|
from .device.sdwire import SDWire, SDWIRE_GENERATION_SDWIRE3
|
8
6
|
from .device.sdwirec import SDWireC
|
9
7
|
from .device.usb_device import PortInfo
|
10
8
|
|
9
|
+
import pyudev
|
11
10
|
import usb.core
|
12
11
|
import usb.util
|
13
12
|
from usb.core import Device
|
@@ -46,30 +45,31 @@ def get_sdwirec_devices() -> List[SDWireC]:
|
|
46
45
|
|
47
46
|
|
48
47
|
def get_sdwire_devices() -> List[SDWire]:
|
49
|
-
|
50
48
|
# Badgerd SDWire3
|
51
49
|
# VID = 0bda PID = 0316
|
52
50
|
# Badgerd SDWireC
|
53
51
|
# VID = 0x04e8 PID = 0x6001
|
54
52
|
result = []
|
55
|
-
devices: List[Device] =
|
53
|
+
devices: List[Device] = pyudev.Context().list_devices(
|
54
|
+
subsystem="usb",
|
55
|
+
ID_VENDOR_ID=f"{constants.SDWIRE3_VID:04x}",
|
56
|
+
ID_MODEL_ID=f"{constants.SDWIRE3_PID:04x}",
|
57
|
+
)
|
56
58
|
if not devices:
|
57
59
|
log.info("no usb devices found while searching for SDWire..")
|
58
60
|
return []
|
59
61
|
|
60
|
-
device_list = []
|
61
62
|
for device in devices:
|
62
63
|
product = None
|
63
64
|
serial = None
|
64
|
-
|
65
|
+
bus = None
|
66
|
+
address = None
|
65
67
|
try:
|
66
|
-
product = device.
|
67
|
-
vendor = device.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
)
|
72
|
-
manufacturer = device.manufacturer
|
68
|
+
product = int(f"0x{device.get('ID_MODEL_ID')}", 16)
|
69
|
+
vendor = int(f"0x{device.get('ID_VENDOR_ID')}", 16)
|
70
|
+
bus = int(device.get("BUSNUM"))
|
71
|
+
address = int(device.get("DEVNUM"))
|
72
|
+
serial = f"{device.get('ID_USB_SERIAL_SHORT')}:{bus}.{address}"
|
73
73
|
except Exception as e:
|
74
74
|
log.debug(
|
75
75
|
"not able to get usb product, serial_number and manufacturer information, err: %s",
|
@@ -77,9 +77,12 @@ def get_sdwire_devices() -> List[SDWire]:
|
|
77
77
|
)
|
78
78
|
|
79
79
|
if product == constants.SDWIRE3_PID and vendor == constants.SDWIRE3_VID:
|
80
|
+
usb_device: List[Device] = usb.core.find(
|
81
|
+
idVendor=vendor, idProduct=product, bus=bus, address=address
|
82
|
+
)
|
80
83
|
result.append(
|
81
84
|
SDWire(
|
82
|
-
port_info=PortInfo(device, product, vendor, serial,
|
85
|
+
port_info=PortInfo(device, product, vendor, serial, usb_device),
|
83
86
|
generation=SDWIRE_GENERATION_SDWIRE3,
|
84
87
|
)
|
85
88
|
)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import logging
|
2
|
-
from serial import Serial
|
3
2
|
from .usb_device import USBDevice, PortInfo
|
4
3
|
|
5
4
|
log = logging.getLogger(__name__)
|
@@ -8,10 +7,18 @@ SDWIRE_GENERATION_SDWIRE3 = 2
|
|
8
7
|
|
9
8
|
|
10
9
|
class SDWire(USBDevice):
|
10
|
+
__block_dev = None
|
11
11
|
|
12
12
|
def __init__(self, port_info: PortInfo, generation: int):
|
13
13
|
super().__init__(port_info)
|
14
14
|
self.generation = generation
|
15
|
+
for sibling in self.dev_string.parent.children:
|
16
|
+
if (
|
17
|
+
self.dev_string.device_path != sibling.device_path
|
18
|
+
and sibling.device_type == "disk"
|
19
|
+
):
|
20
|
+
self.__block_dev = f"/dev/{sibling.device_path.split('/')[-1]}"
|
21
|
+
break
|
15
22
|
|
16
23
|
def switch_ts(self):
|
17
24
|
try:
|
@@ -33,8 +40,12 @@ class SDWire(USBDevice):
|
|
33
40
|
e,
|
34
41
|
)
|
35
42
|
|
43
|
+
@property
|
44
|
+
def block_dev(self):
|
45
|
+
return self.__block_dev
|
46
|
+
|
36
47
|
def __str__(self):
|
37
|
-
return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]"
|
48
|
+
return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{self.block_dev}"
|
38
49
|
|
39
50
|
def __repr__(self):
|
40
51
|
return self.__str__()
|
@@ -1,24 +1,37 @@
|
|
1
1
|
import logging
|
2
2
|
from pyftdi.ftdi import Ftdi
|
3
|
-
from serial import Serial
|
4
3
|
from .usb_device import USBDevice, PortInfo
|
5
4
|
|
6
5
|
log = logging.getLogger(__name__)
|
7
6
|
|
8
7
|
|
9
8
|
class SDWireC(USBDevice):
|
9
|
+
__block_dev = None
|
10
10
|
|
11
11
|
def __init__(self, port_info: PortInfo):
|
12
12
|
super().__init__(port_info)
|
13
|
+
for d in self._pyudev_context.list_devices(ID_MODEL="sd-wire"):
|
14
|
+
d_serial = d.get("ID_USB_SERIAL_SHORT", None)
|
15
|
+
if d_serial is not None and d_serial == self.serial_string:
|
16
|
+
for sibling in d.parent.children:
|
17
|
+
if (
|
18
|
+
d.device_path != sibling.device_path
|
19
|
+
and sibling.device_type == "disk"
|
20
|
+
):
|
21
|
+
self.__block_dev = f"/dev/{sibling.device_path.split('/')[-1]}"
|
22
|
+
break
|
23
|
+
break
|
13
24
|
|
14
25
|
def __str__(self):
|
15
|
-
return
|
16
|
-
f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]"
|
17
|
-
)
|
26
|
+
return f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]\t{self.block_dev}"
|
18
27
|
|
19
28
|
def __repr__(self):
|
20
29
|
return self.__str__()
|
21
30
|
|
31
|
+
@property
|
32
|
+
def block_dev(self):
|
33
|
+
return self.__block_dev
|
34
|
+
|
22
35
|
def switch_ts(self):
|
23
36
|
self._set_sdwire(1)
|
24
37
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from collections import namedtuple
|
2
|
-
|
2
|
+
import pyudev
|
3
3
|
|
4
4
|
PortInfo = namedtuple(
|
5
5
|
"PortInfo", ("device", "product", "manufacturer", "serial", "usb_device")
|
@@ -8,9 +8,11 @@ PortInfo = namedtuple(
|
|
8
8
|
|
9
9
|
class USBDevice:
|
10
10
|
__port_info = None
|
11
|
+
_pyudev_context = None
|
11
12
|
|
12
13
|
def __init__(self, port_info: PortInfo):
|
13
14
|
self.__port_info = port_info
|
15
|
+
self._pyudev_context = pyudev.Context()
|
14
16
|
|
15
17
|
@property
|
16
18
|
def usb_device(self):
|
@@ -20,9 +20,11 @@ def handle_switch_target_command(ctx):
|
|
20
20
|
|
21
21
|
def handle_switch_off_command(ctx):
|
22
22
|
device = ctx.obj["device"]
|
23
|
-
if isinstance(device, SDWireC):
|
24
|
-
log.info(
|
25
|
-
|
23
|
+
if isinstance(device, SDWireC) or isinstance(device, SDWire):
|
24
|
+
log.info(
|
25
|
+
"SDWire3, SDWireC or legacy sdwire devices dont have off functionality"
|
26
|
+
)
|
27
|
+
print("SDWireC and SDWire3 dont have off functionality implemented")
|
26
28
|
sys.exit(1)
|
27
29
|
|
28
30
|
|
@@ -1,19 +1,20 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
+
import logging
|
2
3
|
import click
|
3
4
|
from .backend import utils
|
4
5
|
from .backend import detect
|
5
|
-
from .backend.device.sdwire import SDWire
|
6
6
|
|
7
7
|
|
8
8
|
@click.group()
|
9
|
-
|
10
|
-
|
9
|
+
@click.option("--debug", required=False, is_flag=True, help="Enable debug output")
|
10
|
+
def main(debug=None):
|
11
|
+
if debug:
|
12
|
+
logging.basicConfig(level=logging.DEBUG)
|
11
13
|
|
12
14
|
|
13
15
|
@main.command()
|
14
16
|
def list():
|
15
|
-
|
16
|
-
print(f"Serial\t\t\tProduct Info")
|
17
|
+
print("Serial\t\t\tProduct Info\t\tBlock Dev")
|
17
18
|
for sdwire in detect.get_sdwire_devices():
|
18
19
|
print(sdwire)
|
19
20
|
|
@@ -88,10 +89,5 @@ def off(ctx: click.Context):
|
|
88
89
|
utils.handle_switch_off_command(ctx)
|
89
90
|
|
90
91
|
|
91
|
-
# investigate further to use click in circuitpython
|
92
|
-
# def invoke():
|
93
|
-
# main.main("switch ts".split(), "sdwire", "_SDWIRE_COMPLETE")
|
94
|
-
|
95
|
-
|
96
92
|
if __name__ == "__main__":
|
97
93
|
main()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|