ait.core.server.plugins.openmct module¶
AIT Plugin for OpenMCT Telemetry service
The ait.core.servers.plugins.openmct module provides an a web service that implements the service API for the OpenMCT framework for realtime and, eventually, historical telemetry from AIT.
-
class
ait.core.server.plugins.openmct.AITOpenMctPlugin(inputs, outputs, zmq_args=None, datastore='ait.core.db.InfluxDBBackend', **kwargs)¶ Bases:
ait.core.server.plugin.PluginThis is the implementation of the AIT plugin for interaction with OpenMCT framework. Telemetry dispatched from AIT server/broker is passed along to OpenMct in the expected format.
-
__init__(inputs, outputs, zmq_args=None, datastore='ait.core.db.InfluxDBBackend', **kwargs)¶ - Params:
inputs: names of inbound streams plugin receives data from outputs: names of outbound streams plugin sends its data to zmq_args: dict containing the follow keys:
zmq_context zmq_proxy_xsub_url zmq_proxy_xpub_urlDefaults to empty dict. Default values assigned during instantiation of parent class.
datastore: path to database backend to use **kwargs: (optional) Dependent on requirements of child class.
-
broadcast_message(message)¶ Broadcast OpenMCT packet to web-socket clients :param openmct_pkt: Instance of OpenMCT packet to be emitted :return:
-
broadcast_packet(openmct_pkt)¶ Attempt to broadcast OpenMCT packet to web-socket clients, the managed web-socket themselves determine if the Packet will be emitted. :param openmct_pkt: Instance of OpenMCT packet to be emitted :return: True if packet was emitted by at least one web-socket,
False otherwise.
-
cleanup()¶ Clean-up the webservers
-
static
datetime_jsonifier(obj)¶ Required for JSONifying datetime objects
-
dbg_message(msg)¶
-
static
get_browser_name(browser)¶
-
get_historical_tlm(mct_pkt_id)¶ Handling of historical queries. Time range is retrieved from bottle request query. :param mct_pkt_id_part: OpenMCT id part (single entry or comma-separated list) :return: JSON string representing list of result dicts
-
get_historical_tlm_for_packet_fields(ait_pkt_id, ait_field_names, start_millis, end_millis)¶ Perform a historical query for a particular AIT packet type :param ait_pkt_id: AIT Packet definition Id :param ait_field_names: List of field names to include, use None to include all fields :param start_millis: Start time, milliseconds since UNIX epoch :param end_millis: End time, milliseconds since UNIX epoch :return: List of OpenMct measurements that satisfy query
-
get_historical_tlm_for_range(mct_pkt_ids, start_epoch_ms, end_epoch_ms)¶ Perform a historical query of a list of OpenMCT telemetry ids between the start and end time (as milliseconds since Epoch) :param mct_pkt_ids: List or openMct telemetry ids :param start_epoch_ms: Start time :param end_epoch_ms: End time :return: List of result dicts, where each entry contains {timestamp, id, value}.
-
get_realtime_tlm()¶ Handles realtime packet dispatch via websocket layers
-
get_realtime_tlm_original_dumb()¶ Handles realtime packet dispatch via websocket layers
-
get_tlm_dict_json()¶ Returns the OpenMCT-formatted dictionary
-
get_tlm_dict_raw_json()¶ Returns the AIT-formatted dictionary
-
init()¶ Initialize the web-server state
-
load_database(**kwargs)¶ If necessary database configuration is available, this method will create, connect and return a database connection. If configuration is not available, then None is returned.
Returns: Database instance or None
-
manage_web_socket(mws)¶ Adds mws instance to managed set (for receiving telemetry), and then continuously checks web socket for new messages, which may affect its state. When web-socket is considered closed, it is removed from the managed set and this method returns :param mws: Managed web-socket instance
-
static
managed_web_socket_recv(mws)¶ Attempts to read message from the websocket with timeout. :param mws: Managed web-socket instance :return: Message retrieved from underlying-websocket, or None
-
static
managed_web_socket_send(mws, message)¶ Sends message to underlying web-socket :param mws: Managed web-socket instance :param message: Message to be sent
-
mimic_tlm(ait_tlm_pkt_name, ait_tlm_pkt_fill=None)¶ Used for debugging, creates an instance of a packet based on packet name, and fills it with zero data. Special case for ‘1553_HS_Packet’ which will get random number data fills. If HTTP Request query includes a value for ‘repeat’, then this will continue emitting telemetry.
-
poll_telemetry()¶ Polls the telemetry queue for next available telem entry. If found, it is broadcast to all of the managed web-sockets, where they decide if they are interested in the telemetry. If nothing on queue, then empty probe messag is sent. :return: True if real telemetry emitted, False otherwise.
-
poll_telemetry_periodically()¶
-
poll_websocket(mws)¶ Polls instance of web-socket for message :return True if message was processed, False otherwise
-
poll_websocket_periodically_while_alive(mws)¶
-
poll_websockets()¶ - Polls set of maintained web-sockets to test for:
- web-socket is considered closed, in which case its removed from internal set;
- web-socket has message available that affects its state.
-
process(input_data, topic=None)¶ Process received input message.
This plugin should be configured to only receive telemetry.
Received messaged is expected to be a tuple of the form produced by AITPacketHandler.
-
process_websocket_mesg(mws, message)¶ Processes message received from a web-socket. Handles the following directives: close, subscribe, unsubscribe :param mws: Managed web-socket instance associated with message :param message: Web-socket message
-
send_socket_pkt_mesg(mws, pkt_id, mct_pkt)¶ Attempts to send socket message if managed web-socket is alive and accepts the message by inspecting the pkt_id value :param mws: Managed web-socket :param pkt_id: Packet ID associated with message :param mct_pkt: OpenMCT telem packet :return: True if message sent to web-socket, False otherwise
-
start_browser(url, name=None)¶
-
wait()¶
-
DEFAULT_DATABASE_ENABLED= False¶
-
DEFAULT_DEBUG= False¶
-
DEFAULT_DEBUG_MAX_LEN= 512¶
-
DEFAULT_PORT= 8082¶
-
DEFAULT_TELEM_CHECK_SLEEP_SECS= 2¶
-
DEFAULT_TELEM_QUEUE_TIMEOUT_SECS= 10¶
-
DEFAULT_WEBSOCKET_CHECK_SLEEP_SECS= 2¶
-
DEFAULT_WS_EMPTY_MESSAGE= '{}'¶
-
DEFAULT_WS_RECV_TIMEOUT_SECS= 0.1¶
-
-
class
ait.core.server.plugins.openmct.DictUtils¶ Bases:
objectEncapsulates dictionary utilities, primarily for translating between AIT and OpenMCT dictionaries and packets
-
static
create_mct_fieldmap(ait_pkt_fld_def)¶ Constructs an OpenMCT field declaration struct from an AIT packet definition
-
static
create_mct_pkt_id(ait_pkt_id, ait_field_id)¶
-
static
create_uid_pkt_map(ait_dict)¶ Creates a dictionary from packet def UID to package definition
-
static
format_tlmdict_for_openmct(ait_tlm_dict)¶ Formats the AIT telemetry dictionary as an OpenMCT telemetry dictionary
-
static
format_tlmpkt_for_openmct(ait_pkt)¶ Formats an AIT telemetry packet instance as an OpenMCT telemetry packet structure
-
static
parse_mct_pkt_id(mct_pkt_id)¶
-
static
-
class
ait.core.server.plugins.openmct.ManagedWebSocket(web_socket, client_ip=None)¶ Bases:
objectA data structure to maintain state for OpenMCT websockets
-
__init__(web_socket, client_ip=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
accepts_packet(pkt_id)¶ Returns True if pkt_id is considered subscribed to by this websocket If pkt_id is PACKET_ID_WILDCARD, it will be automatically accepted :param pkt_id: AIT Packet name :return: True if packet id is accepted, False otherwise
-
create_subscribed_packet(omc_packet)¶ Returns a modified OpenMCT packet that contains only fields for which the web-socket is subscribed :param omc_packet: Full OpenMCT packet with all fields :return: New modified packet if any match in fields, else None
-
set_error()¶ Sets error flag
-
subscribe_field(openmct_field_id)¶ Adds a subscription to an OpenMCT field :param openmct_field_id: OpenMCT Field id
-
unsubscribe_field(openmct_field_id)¶ Removes a subscription to an OpenMCT field :param openmct_field_id: OpenMCT Field id
-
PACKET_ID_WILDCARD= '*'¶
-
id_counter= 0¶
-
is_alive¶ Returns True if web-socket is active, False otherwise :return: Managed web-socket state
-