mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
refactoring
This commit is contained in:
parent
a8a075c203
commit
fef625aee5
@ -47,6 +47,7 @@ class _SerialPhyConnection(BasePhyConnection):
|
|||||||
|
|
||||||
def send(self, request: bytes) -> bytes:
|
def send(self, request: bytes) -> bytes:
|
||||||
assert len(request) == 8
|
assert len(request) == 8
|
||||||
|
assert request[0] == 0x33
|
||||||
if self.__tty.in_waiting:
|
if self.__tty.in_waiting:
|
||||||
self.__tty.read_all()
|
self.__tty.read_all()
|
||||||
assert self.__tty.write(request) == 8
|
assert self.__tty.write(request) == 8
|
||||||
@ -76,24 +77,21 @@ class _SerialPhy(BasePhy):
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
class Plugin(BaseMcuHid):
|
class Plugin(BaseMcuHid):
|
||||||
def __init__(
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
self,
|
phy_kwargs: Dict = {key: kwargs.pop(key) for key in self.__get_phy_options()}
|
||||||
device_path: str,
|
super().__init__(phy=_SerialPhy(**phy_kwargs), **kwargs)
|
||||||
speed: int,
|
|
||||||
read_timeout: float,
|
|
||||||
**kwargs: Any,
|
|
||||||
) -> None:
|
|
||||||
|
|
||||||
super().__init__(
|
|
||||||
phy=_SerialPhy(device_path, speed, read_timeout),
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_plugin_options(cls) -> Dict:
|
def get_plugin_options(cls) -> Dict:
|
||||||
|
return {
|
||||||
|
**cls.__get_phy_options(),
|
||||||
|
**BaseMcuHid.get_plugin_options(),
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __get_phy_options(cls) -> Dict:
|
||||||
return {
|
return {
|
||||||
"device": Option("", type=valid_abs_path, unpack_as="device_path"),
|
"device": Option("", type=valid_abs_path, unpack_as="device_path"),
|
||||||
"speed": Option(115200, type=valid_tty_speed),
|
"speed": Option(115200, type=valid_tty_speed),
|
||||||
"read_timeout": Option(2.0, type=valid_float_f01),
|
"read_timeout": Option(2.0, type=valid_float_f01),
|
||||||
**BaseMcuHid.get_plugin_options(),
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user