Programmatic interface for reboot, stow, unstow

Per discussion in issue #52, add a few dish control functions to the starlink_grpc module for possible use by other projects.
This commit is contained in:
sparky8512 2022-08-17 15:01:53 -07:00
parent 48aebd6289
commit 8a0f44bfa6

View file

@ -1,9 +1,10 @@
"""Helpers for grpc communication with a Starlink user terminal. """Helpers for grpc communication with a Starlink user terminal.
This module contains functions for getting the history and status data and This module contains functions for getting the history and status data and
either return it as-is or parsed for some specific statistics. either return it as-is or parsed for some specific statistics, as well as a
handful of functions related to dish control.
Those functions return data grouped into sets, as follows. The history and status functions return data grouped into sets, as follows.
Note: Note:
Functions that return field names may indicate which fields hold sequences Functions that return field names may indicate which fields hold sequences
@ -1245,3 +1246,57 @@ def obstruction_map(context=None):
cols = map_data.num_cols cols = map_data.num_cols
return tuple((map_data.snr[i:i + cols]) for i in range(0, cols * map_data.num_rows, cols)) return tuple((map_data.snr[i:i + cols]) for i in range(0, cols * map_data.num_rows, cols))
def reboot(context=None):
"""Request dish reboot operation.
Args:
context (ChannelContext): Optionally provide a channel for reuse
across repeated calls. If an existing channel is reused, the RPC
call will be retried at most once, since connectivity may have
been lost and restored in the time since it was last used.
Raises:
GrpcError: Communication or service error.
"""
def grpc_call(channel):
if imports_pending:
resolve_imports(channel)
stub = device_pb2_grpc.DeviceStub(channel)
stub.Handle(device_pb2.Request(reboot={}), timeout=REQUEST_TIMEOUT)
# response is empty message in this case, so just ignore it
return 0
try:
call_with_channel(grpc_call, context=context)
except grpc.RpcError as e:
raise GrpcError(e)
def set_stow_state(unstow=False, context=None):
"""Request dish stow or unstow operation.
Args:
unstow (bool): If True, request an unstow operation, otherwise a stow
operation will be requested.
context (ChannelContext): Optionally provide a channel for reuse
across repeated calls. If an existing channel is reused, the RPC
call will be retried at most once, since connectivity may have
been lost and restored in the time since it was last used.
Raises:
GrpcError: Communication or service error.
"""
def grpc_call(channel):
if imports_pending:
resolve_imports(channel)
stub = device_pb2_grpc.DeviceStub(channel)
stub.Handle(device_pb2.Request(dish_stow={"unstow": unstow}), timeout=REQUEST_TIMEOUT)
# response is empty message in this case, so just ignore it
return 0
try:
call_with_channel(grpc_call, context=context)
except grpc.RpcError as e:
raise GrpcError(e)