Skip to content

Commit

Permalink
Pigweed Console default timeout (#11402)
Browse files Browse the repository at this point in the history
- Set a default timeout for unary RPCs to 5 seconds.
- Add all RPCs to the console sentence completer, under the existing
  channel_client variable.
- Add a hidden by default host log window (useful for Python debugging).
  • Loading branch information
AnthonyDiGirolamo authored and pull[bot] committed Dec 23, 2021
1 parent 1817532 commit 1454904
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions examples/common/pigweed/rpc_console/py/chip_rpc/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
import serial # type: ignore
import re
import pw_cli.log
from pw_console.console_app import embed
from pw_console import PwConsoleEmbed
from pw_console.__main__ import create_temp_log_file
from pw_hdlc.rpc import HdlcRpcClient, default_channels
from pw_rpc import callback_client
from pw_rpc.console_tools.console import ClientInfo, flattened_rpc_completions


# Protos
from attributes_service import attributes_service_pb2
Expand Down Expand Up @@ -111,6 +114,10 @@ def _start_ipython_terminal(client: HdlcRpcClient) -> None:
LOG=_DEVICE_LOG,
)

client_info = ClientInfo('channel_client',
client.client.channel(1).rpcs, client.client)
completions = flattened_rpc_completions([client_info])

welcome_message = cleandoc("""
Welcome to the CHIP RPC Console!
Expand All @@ -122,12 +129,25 @@ def _start_ipython_terminal(client: HdlcRpcClient) -> None:
LOG.warning('Message appears console log window.')
""")

embed(global_vars=local_variables,
local_vars=None,
loggers=[_DEVICE_LOG],
repl_startup_message=welcome_message,
help_text=__doc__,
app_title="CHIP Console")
interactive_console = PwConsoleEmbed(
global_vars=local_variables,
local_vars=None,
loggers={
'Device Logs': [_DEVICE_LOG],
'Host Logs': [logging.getLogger()],
},
repl_startup_message=welcome_message,
help_text=__doc__,
app_title="CHIP Console",
)
interactive_console.hide_windows('Host Logs')
interactive_console.add_sentence_completer(completions)

# Setup Python logger propagation
interactive_console.setup_python_logging()
# Don't send device logs to the root logger.
_DEVICE_LOG.propagate = False
interactive_console.embed()


class SocketClientImpl:
Expand Down Expand Up @@ -200,9 +220,16 @@ def read(): return serial_device.read(8192)
_LOG.exception('Failed to initialize socket at %s', socket_addr)
return 1

callback_client_impl = callback_client.Impl(
default_unary_timeout_s=5.0,
default_stream_timeout_s=None,
)

_start_ipython_terminal(
HdlcRpcClient(read, PROTOS, default_channels(write),
lambda data: write_to_output(data, output)))
lambda data: write_to_output(data, output),
client_impl=callback_client_impl)
)
return 0


Expand Down

0 comments on commit 1454904

Please sign in to comment.