def create_stream_subscription(self, stream, on_data, timeout=60): """ Create a new stream subscription. :param str stream: The name of the stream. :param on_data: Function that gets called with :class:`.StreamData` updates. :param float timeout: The amount of seconds to wait for the request to complete. :return: Future that can be used to manage the background websocket subscription :rtype: .WebSocketSubscriptionFuture """ options = rest_pb2.StreamSubscribeRequest() options.stream = stream manager = WebSocketSubscriptionManager(self._client, resource='stream', options=options) # Represent subscription as a future subscription = WebSocketSubscriptionFuture(manager) wrapped_callback = functools.partial(_wrap_callback_parse_stream_data, subscription, on_data) manager.open(wrapped_callback, instance=self._instance) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_cop1_subscription(self, on_data, timeout=60): """ Create a new subscription for receiving status of the COP1 link. This method returns a future, then returns immediately. Stop the subscription by canceling the future. :param on_data: Function that gets called on each :class:`.Cop1Status`. :type on_data: Optional[Callable[.Cop1Status]) :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float] :return: Future that can be used to manage the background websocket subscription. :rtype: .Cop1Subscription """ options = cop1_pb2.SubscribeStatusRequest() options.instance = self._instance options.link = self._link manager = WebSocketSubscriptionManager(self.ctx, topic="cop1", options=options) # Represent subscription as a future subscription = Cop1Subscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_cop1_status, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_alarm_subscription(self, on_data=None, timeout=60): """ Create a new alarm subscription. :param on_data: (Optional) Function that gets called with :class:`.AlarmUpdate` updates. :param float timeout: The amount of seconds to wait for the request to complete. :return: A Future that can be used to manage the background websocket subscription. :rtype: .AlarmSubscription """ options = alarms_service_pb2.SubscribeAlarmsRequest() options.instance = self._instance options.processor = self._processor manager = WebSocketSubscriptionManager(self.ctx, topic="alarms") # Represent subscription as a future subscription = AlarmSubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_alarm_data, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_command_history_subscription(self, on_data=None, timeout=60): """ Create a new command history subscription. :param on_data: (Optional) Function that gets called with :class:`.CommandHistory` updates. :param timeout: The amount of seconds to wait for the request to complete. :type timeout: float :return: Future that can be used to manage the background websocket subscription :rtype: .CommandHistorySubscription """ options = commands_service_pb2.SubscribeCommandsRequest() options.instance = self._instance options.processor = self._processor options.ignorePastCommands = True manager = WebSocketSubscriptionManager( self.ctx, topic="commands", options=options ) # Represent subscription as a future subscription = CommandHistorySubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_cmdhist_data, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_alarm_subscription(self, on_data=None, timeout=60): """ Create a new alarm subscription. :param on_data: Function that gets called with :class:`.AlarmEvent` updates. :param float timeout: The amount of seconds to wait for the request to complete. :return: A Future that can be used to manage the background websocket subscription. :rtype: .AlarmSubscription """ manager = WebSocketSubscriptionManager(self._client, resource='alarms') # Represent subscription as a future subscription = AlarmSubscription(manager) wrapped_callback = functools.partial(_wrap_callback_parse_alarm_data, subscription, on_data) manager.open(wrapped_callback, instance=self._instance, processor=self._processor) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_transfer_subscription(self, on_data=None, timeout=60): """ Create a new transfer subscription. :param on_data: (Optional) Function that gets called with :class:`.TransferInfo` updates. :param timeout: The amount of seconds to wait for the request to complete. :type timeout: float :return: Future that can be used to manage the background websocket subscription :rtype: .TransferSubscription """ options = cfdp_pb2.SubscribeTransfersRequest() options.instance = self._instance manager = WebSocketSubscriptionManager(self.ctx, topic="cfdp-transfers", options=options) # Represent subscription as a future subscription = TransferSubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_transfer_data, subscription, on_data) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_event_subscription(self, instance, on_data, timeout=60): """ Create a new subscription for receiving events of an instance. This method returns a future, then returns immediately. Stop the subscription by canceling the future. :param str instance: A Yamcs instance name :param on_data: Function that gets called on each :class:`.Event`. :type on_data: Optional[Callable[.Event]) :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float] :return: Future that can be used to manage the background websocket subscription. :rtype: .WebSocketSubscriptionFuture """ manager = WebSocketSubscriptionManager(self, resource='events') # Represent subscription as a future subscription = WebSocketSubscriptionFuture(manager) wrapped_callback = functools.partial( _wrap_callback_parse_event, on_data) manager.open(wrapped_callback, instance) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_parameter_subscription( self, parameters, on_data=None, abort_on_invalid=True, update_on_expiration=False, send_from_cache=True, timeout=60, ): """ Create a new parameter subscription. :param str[] parameters: Parameter names (or aliases). :param on_data: (Optional) Function that gets called with :class:`.ParameterData` updates. :param bool abort_on_invalid: If ``True`` an error is generated when invalid parameters are specified. :param bool update_on_expiration: If ``True`` an update is received when a parameter value has become expired. This update holds the same value as the last known valid value, but with status set to ``EXPIRED``. :param bool send_from_cache: If ``True`` the last processed parameter value is sent from parameter cache. When ``False`` only newly processed parameters are received. :param float timeout: The amount of seconds to wait for the request to complete. :return: A Future that can be used to manage the background websocket subscription. :rtype: .ParameterSubscription """ options = processing_pb2.SubscribeParametersRequest() options.instance = self._instance options.processor = self._processor options.abortOnInvalid = abort_on_invalid options.updateOnExpiration = update_on_expiration options.sendFromCache = send_from_cache options.id.extend(_build_named_object_ids(parameters)) manager = WebSocketSubscriptionManager( self.ctx, topic="parameters", options=options ) # Represent subscription as a future subscription = ParameterSubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_parameter_data, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_packet_subscription(self, on_data, stream="tm_realtime", timeout=60): """ Create a new packet subscription. .. versionadded:: 1.6.6 :param on_data: Function that gets called with :class:`.Packet` updates. :type on_data: Optional[Callable[.Packet]] :param stream: Stream to subscribe to. :type stream: str :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float] :return: A Future that can be used to manage the background websocket subscription. :rtype: .WebSocketSubscriptionFuture """ options = packets_service_pb2.SubscribePacketsRequest() options.instance = self._instance # TODO remove stream default to tm_realtime within a few releases. # (processor option only added as of Yamcs 5.5.x) # if stream: options.stream = stream # else: # options.processor = self._processor manager = WebSocketSubscriptionManager(self.ctx, topic="packets", options=options) # Represent subscription as a future subscription = WebSocketSubscriptionFuture(manager) wrapped_callback = functools.partial(_wrap_callback_parse_packet_data, on_data) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_container_subscription(self, containers, on_data=None, timeout=60): """ Create a new container subscription. .. versionadded:: 1.7.0 Compatible with Yamcs 5.5.0 onwards :param containers: Container names. :type containers: Union[str, str[]] :param on_data: Function that gets called with :class:`.ContainerData` updates. :type on_data: Optional[Callable[.ContainerData]] :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float] :return: A Future that can be used to manage the background websocket subscription. :rtype: .ContainerSubscription """ options = packets_service_pb2.SubscribeContainersRequest() options.instance = self._instance options.processor = self._processor if isinstance(containers, str): options.names.extend([containers]) else: options.names.extend(containers) manager = WebSocketSubscriptionManager(self.ctx, topic="containers", options=options) # Represent subscription as a future subscription = ContainerSubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_container_data, subscription, on_data) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_command_connection(self, on_data=None, timeout=60): """ Creates a connection for issuing multiple commands and following up on their acknowledgment progress. .. note:: This is a convenience method that merges the functionalities of :meth:`create_command_history_subscription` with those of :meth:`issue_command`. :param on_data: Function that gets called with :class:`.CommandHistory` updates. Only commands issued from this connection are reported. :param timeout: The amount of seconds to wait for the request to complete. :type timeout: float :return: Future that can be used to manage the background websocket subscription :rtype: .CommandConnection """ options = commands_service_pb2.SubscribeCommandsRequest() options.instance = self._instance options.processor = self._processor options.ignorePastCommands = True manager = WebSocketSubscriptionManager( self.ctx, topic="commands", options=options ) # Represent subscription as a future subscription = CommandConnection(manager, self) wrapped_callback = functools.partial( _wrap_callback_parse_cmdhist_data, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_command_history_subscription(self, issued_command=None, on_data=None, timeout=60): """ Create a new command history subscription. :param issued_command: (Optional) Previously issued commands. If not provided updates from any command are received. :type issued_command: .IssuedCommand[] :param on_data: Function that gets called with :class:`.CommandHistory` updates. :param timeout: The amount of seconds to wait for the request to complete. :type timeout: float :return: Future that can be used to manage the background websocket subscription :rtype: .CommandHistorySubscription """ options = websocket_pb2.CommandHistorySubscriptionRequest() options.ignorePastCommands = True if issued_command: options.commandId.extend(_build_command_ids(issued_command)) manager = WebSocketSubscriptionManager(self._client, resource='cmdhistory', options=options) # Represent subscription as a future subscription = CommandHistorySubscription(manager) wrapped_callback = functools.partial(_wrap_callback_parse_cmdhist_data, subscription, on_data) manager.open(wrapped_callback, instance=self._instance, processor=self._processor) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_transfer_subscription(self, on_data=None, timeout=60): options = filetransfer_pb2.SubscribeTransfersRequest() options.instance = self._instance options.serviceName = self._service manager = WebSocketSubscriptionManager(self.ctx, topic="file-transfers", options=options) # Represent subscription as a future subscription = TransferSubscription(manager, self) wrapped_callback = functools.partial( _wrap_callback_parse_transfer_data, subscription, on_data) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_time_subscription(self, instance, on_data=None, timeout=60): """ Create a new subscription for receiving time updates of an instance. Time updates are emitted at 1Hz. This method returns a future, then returns immediately. Stop the subscription by canceling the future. :param str instance: A Yamcs instance name :param on_data: Function that gets called with :class:`~datetime.datetime` updates. :type on_data: Optional[Callable[~datetime.datetime]) :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float]j :return: Future that can be used to manage the background websocket subscription. :rtype: .TimeSubscription """ options = time_service_pb2.SubscribeTimeRequest() options.instance = instance manager = WebSocketSubscriptionManager(self, topic="time", options=options) # Represent subscription as a future subscription = TimeSubscription(manager) wrapped_callback = functools.partial(_wrap_callback_parse_time_info, subscription, on_data) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription
def create_link_subscription(self, instance, on_data=None, timeout=60): """ Create a new subscription for receiving data link updates of an instance. This method returns a future, then returns immediately. Stop the subscription by canceling the future. :param str instance: A Yamcs instance name. :param on_data: Function that gets called with :class:`.LinkEvent` updates. :type on_data: Optional[Callable[.LinkEvent]) :param timeout: The amount of seconds to wait for the request to complete. :type timeout: Optional[float] :return: Future that can be used to manage the background websocket subscription. :rtype: .LinkSubscription """ options = yamcsManagement_pb2.SubscribeLinksRequest() options.instance = instance manager = WebSocketSubscriptionManager(self.ctx, topic="links", options=options) # Represent subscription as a future subscription = LinkSubscription(manager) wrapped_callback = functools.partial( _wrap_callback_parse_link_event, subscription, on_data ) manager.open(wrapped_callback) # Wait until a reply or exception is received subscription.reply(timeout=timeout) return subscription