mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
feat(ble): wire BLE UART bridge CLI
This commit is contained in:
68
tools/ble/ble_uart_bridge/main.py
Normal file
68
tools/ble/ble_uart_bridge/main.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from src import run_connection_check
|
||||
from src import run_console
|
||||
from src import run_daemon
|
||||
from src import run_daemon_send
|
||||
from src import run_daemon_status
|
||||
from src import run_list_devices
|
||||
from src.console import ConsoleEncoding
|
||||
from src.console import ConsoleTerminator
|
||||
from typer import Option
|
||||
from typer import Typer
|
||||
|
||||
# CLI app singleton
|
||||
app = Typer()
|
||||
|
||||
|
||||
# Core service
|
||||
@app.command()
|
||||
def list_devices() -> None:
|
||||
run_list_devices()
|
||||
|
||||
|
||||
@app.command()
|
||||
def connection_check(device_id: str) -> None:
|
||||
run_connection_check(device_id)
|
||||
|
||||
|
||||
# Console
|
||||
@app.command()
|
||||
def console(
|
||||
device_id: str,
|
||||
terminator: ConsoleTerminator = Option(ConsoleTerminator.lf, help='Line terminator for text mode'),
|
||||
encoding: ConsoleEncoding = Option(ConsoleEncoding.text, help='Console encoding'),
|
||||
with_response: bool = Option(False, help='Use BLE write-with-response for TX data'),
|
||||
) -> None:
|
||||
run_console(device_id, terminator=terminator, encoding=encoding, with_response=with_response)
|
||||
|
||||
|
||||
# Daemon
|
||||
@app.command()
|
||||
def daemon(device_id: str, host: str = '127.0.0.1', port: int = 8888) -> None:
|
||||
run_daemon(device_id, host, port)
|
||||
|
||||
|
||||
@app.command()
|
||||
def daemon_status(host: str = '127.0.0.1', port: int = 8888) -> None:
|
||||
run_daemon_status(host=host, port=port)
|
||||
|
||||
|
||||
@app.command()
|
||||
def daemon_send(
|
||||
data: str,
|
||||
op: str = Option('raw', help='Operation name in the JSONL request envelope'),
|
||||
json_payload: bool = Option(False, '--json', help='Parse DATA as JSON instead of sending it as a string'),
|
||||
timeout: float = 10.0,
|
||||
host: str = '127.0.0.1',
|
||||
port: int = 8888,
|
||||
) -> None:
|
||||
run_daemon_send(data=data, op=op, json_payload=json_payload, timeout=timeout, host=host, port=port)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
app()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
17
tools/ble/ble_uart_bridge/src/__init__.py
Normal file
17
tools/ble/ble_uart_bridge/src/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from .console import run_console
|
||||
from .core import run_connection_check
|
||||
from .core import run_list_devices
|
||||
from .daemon import run_daemon
|
||||
from .daemon import run_daemon_send
|
||||
from .daemon import run_daemon_status
|
||||
|
||||
__all__ = [
|
||||
'run_connection_check',
|
||||
'run_list_devices',
|
||||
'run_daemon',
|
||||
'run_daemon_send',
|
||||
'run_daemon_status',
|
||||
'run_console',
|
||||
]
|
||||
Reference in New Issue
Block a user