mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 12:47:47 +00:00
[otci] support ADB connection for OTCI (#8088)
This commit is contained in:
@@ -35,7 +35,9 @@ from .otci import \
|
||||
connect_cli_serial, \
|
||||
connect_ncp_sim, \
|
||||
connect_cmd_handler, \
|
||||
connect_otbr_ssh
|
||||
connect_otbr_ssh, \
|
||||
connect_otbr_adb
|
||||
|
||||
from .types import Rloc16, ChildId, NetifIdentifier
|
||||
|
||||
_connectors = [
|
||||
@@ -43,6 +45,7 @@ _connectors = [
|
||||
'connect_cli_serial',
|
||||
'connect_ncp_sim',
|
||||
'connect_otbr_ssh',
|
||||
'connect_otbr_adb',
|
||||
'connect_cmd_handler',
|
||||
]
|
||||
|
||||
|
||||
@@ -282,3 +282,46 @@ class OtbrSshCommandRunner(OTCommandHandler):
|
||||
|
||||
def set_line_read_callback(self, callback: Optional[Callable[[str], Any]]):
|
||||
self.__line_read_callback = callback
|
||||
|
||||
|
||||
class OtbrAdbCommandRunner(OTCommandHandler):
|
||||
|
||||
def __init__(self, host, port):
|
||||
from adb_shell.adb_device import AdbDeviceTcp
|
||||
|
||||
self.__host = host
|
||||
self.__port = port
|
||||
self.__adb = AdbDeviceTcp(host, port, default_transport_timeout_s=9.0)
|
||||
|
||||
self.__line_read_callback = None
|
||||
self.__adb.connect(rsa_keys=None, auth_timeout_s=0.1)
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.__host}:{self.__port}'
|
||||
|
||||
def execute_command(self, cmd: str, timeout: float) -> List[str]:
|
||||
sh_cmd = f'ot-ctl {cmd}'
|
||||
|
||||
output = self.shell(sh_cmd, timeout=timeout)
|
||||
|
||||
if self.__line_read_callback is not None:
|
||||
for line in output:
|
||||
self.__line_read_callback(line)
|
||||
|
||||
if cmd in ('reset', 'factoryreset'):
|
||||
self.wait(3)
|
||||
|
||||
return output
|
||||
|
||||
def shell(self, cmd: str, timeout: float) -> List[str]:
|
||||
return self.__adb.shell(cmd, timeout_s=timeout).splitlines()
|
||||
|
||||
def close(self):
|
||||
self.__adb.close()
|
||||
|
||||
def wait(self, duration: float) -> List[str]:
|
||||
time.sleep(duration)
|
||||
return []
|
||||
|
||||
def set_line_read_callback(self, callback: Optional[Callable[[str], Any]]):
|
||||
self.__line_read_callback = callback
|
||||
|
||||
@@ -33,7 +33,7 @@ from collections import Counter
|
||||
from typing import Callable, List, Collection, Union, Tuple, Optional, Dict, Pattern, Any
|
||||
|
||||
from . import connectors
|
||||
from .command_handlers import OTCommandHandler, OtCliCommandRunner, OtbrSshCommandRunner
|
||||
from .command_handlers import OTCommandHandler, OtCliCommandRunner, OtbrSshCommandRunner, OtbrAdbCommandRunner
|
||||
from .connectors import Simulator
|
||||
from .errors import UnexpectedCommandOutput, ExpectLineTimeoutError, CommandError, InvalidArgumentsError
|
||||
from .types import ChildId, Rloc16, Ip6Addr, ThreadState, PartitionId, DeviceMode, RouterId, SecurityPolicy, Ip6Prefix, \
|
||||
@@ -2487,5 +2487,10 @@ def connect_otbr_ssh(host: str, port: int = 22, username='pi', password='raspber
|
||||
return OTCI(cmd_handler)
|
||||
|
||||
|
||||
def connect_otbr_adb(host: str, port: int = 5555):
|
||||
cmd_handler = OtbrAdbCommandRunner(host, port)
|
||||
return OTCI(cmd_handler)
|
||||
|
||||
|
||||
def connect_cmd_handler(cmd_handler: OTCommandHandler) -> OTCI:
|
||||
return OTCI(cmd_handler)
|
||||
|
||||
+1
-1
@@ -46,5 +46,5 @@ setuptools.setup(
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
python_requires='>=3.6',
|
||||
install_requires=['pySerial', 'paramiko', 'pyspinel'],
|
||||
install_requires=['pySerial', 'paramiko', 'pyspinel', 'adb-shell'],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user