openrvdas.logger.transforms.sealog_control_transform
The transform processes a Sealog event and depending on the event's value, submits a set_active_mode command to OpenRVDAS.
How to setup the Sealog event template: Button Name: OpenRVDAS Ctrl Event Value: OPENRVDAS System template: yes Only available to admins: yes Option #1: - name: mode - type: dropdown - dropdown options: off, port, underway - required: yes
How to setup the logger:
readers:
- class: SealogReader
module: logger.readers.sealog_reader
kwargs:
uri: 'wss://
1#!/usr/bin/env python3 2""" The transform processes a Sealog event and depending on the event's value, 3submits a set_active_mode command to OpenRVDAS. 4 5How to setup the Sealog event template: 6 Button Name: OpenRVDAS Ctrl 7 Event Value: OPENRVDAS 8 System template: yes 9 Only available to admins: yes 10 Option #1: 11 - name: mode 12 - type: dropdown 13 - dropdown options: off, port, underway 14 - required: yes 15 16How to setup the logger: 17 readers: 18 - class: SealogReader 19 module: logger.readers.sealog_reader 20 kwargs: 21 uri: 'wss://<sealog_server_ip>:<port>/ws' 22 transforms: 23 - class: SealogControlTransform 24 module: logger.transforms.sealog_control_transform 25 kwargs: 26 event_value: OPENRVDAS 27 event_option_name: mode 28 writers: 29 - class: LoggerManagerWriter 30 module: logger.writers.logger_manager_writer 31 kwargs: 32 database: django 33 allowed_prefixes: 34 - 'set_active_mode ' 35""" 36import logging 37 38from typing import Union 39from logger.utils.das_record import DASRecord # noqa: E402 40from logger.utils.sealog_event import SealogEvent, to_event # noqa: E402 41from logger.transforms.transform import Transform # noqa: E402 42 43 44################################################################################ 45class SealogControlTransform(Transform): 46 """ 47 OpenRVDAS transfor that processes SealogEvents, DASRecords and/or json 48 strings to determine if the event correlated to an OpenRVDAS mode change. 49 If the event does correlate to a mode change the transform returns the 50 appropiate logger_manager command str. 51 """ 52 def __init__(self, event_value, event_option_name, 53 event_author=None, **kwargs): 54 """ 55 event_value: only process events with this event_value 56 57 event_option_name: event option containing the desired OpenRVDAS mode 58 59 event_author: optionally accept only events by a specific author 60 """ 61 super().__init__(**kwargs) # processes 'quiet' and type hints 62 63 self.event_value = event_value 64 self.event_author = event_author 65 self.event_option_name = event_option_name 66 67 self.command = "set_active_mode" 68 69 ############################ 70 def transform(self, record: Union[DASRecord, SealogEvent, str]) -> str: 71 """ 72 Accept a DASRecord, SealogEvent or json str. Process the record and 73 determine if it matches the requirements for requesting an OpenRVDAS 74 mode change. 75 """ 76 # See if it's something we can process, and if not, try digesting 77 if not self.can_process_record(record): # inherited from BaseModule() 78 return self.digest_record(record) # inherited from BaseModule() 79 80 try: 81 event = to_event(record) 82 except Exception as err: 83 logging.warning("Unable to parse record to Sealog event") 84 logging.info("Error: %s", err) 85 return None 86 87 # Optionally match event author 88 if self.event_author and self.event_author != event.event_author: 89 return None 90 91 # If the event value matches, look for the event_option 92 if event.event_value == self.event_value: 93 for event_option in event.event_options: 94 95 # If new mode found, return the command string 96 if event_option.get('event_option_name') == self.event_option_name: 97 cmd_str = f'{self.command} {event_option.get("event_option_value")}' 98 logging.info('Submitting command to OpenRVDAS: "%s"', cmd_str) 99 return cmd_str 100 101 return None
46class SealogControlTransform(Transform): 47 """ 48 OpenRVDAS transfor that processes SealogEvents, DASRecords and/or json 49 strings to determine if the event correlated to an OpenRVDAS mode change. 50 If the event does correlate to a mode change the transform returns the 51 appropiate logger_manager command str. 52 """ 53 def __init__(self, event_value, event_option_name, 54 event_author=None, **kwargs): 55 """ 56 event_value: only process events with this event_value 57 58 event_option_name: event option containing the desired OpenRVDAS mode 59 60 event_author: optionally accept only events by a specific author 61 """ 62 super().__init__(**kwargs) # processes 'quiet' and type hints 63 64 self.event_value = event_value 65 self.event_author = event_author 66 self.event_option_name = event_option_name 67 68 self.command = "set_active_mode" 69 70 ############################ 71 def transform(self, record: Union[DASRecord, SealogEvent, str]) -> str: 72 """ 73 Accept a DASRecord, SealogEvent or json str. Process the record and 74 determine if it matches the requirements for requesting an OpenRVDAS 75 mode change. 76 """ 77 # See if it's something we can process, and if not, try digesting 78 if not self.can_process_record(record): # inherited from BaseModule() 79 return self.digest_record(record) # inherited from BaseModule() 80 81 try: 82 event = to_event(record) 83 except Exception as err: 84 logging.warning("Unable to parse record to Sealog event") 85 logging.info("Error: %s", err) 86 return None 87 88 # Optionally match event author 89 if self.event_author and self.event_author != event.event_author: 90 return None 91 92 # If the event value matches, look for the event_option 93 if event.event_value == self.event_value: 94 for event_option in event.event_options: 95 96 # If new mode found, return the command string 97 if event_option.get('event_option_name') == self.event_option_name: 98 cmd_str = f'{self.command} {event_option.get("event_option_value")}' 99 logging.info('Submitting command to OpenRVDAS: "%s"', cmd_str) 100 return cmd_str 101 102 return None
OpenRVDAS transfor that processes SealogEvents, DASRecords and/or json strings to determine if the event correlated to an OpenRVDAS mode change. If the event does correlate to a mode change the transform returns the appropiate logger_manager command str.
53 def __init__(self, event_value, event_option_name, 54 event_author=None, **kwargs): 55 """ 56 event_value: only process events with this event_value 57 58 event_option_name: event option containing the desired OpenRVDAS mode 59 60 event_author: optionally accept only events by a specific author 61 """ 62 super().__init__(**kwargs) # processes 'quiet' and type hints 63 64 self.event_value = event_value 65 self.event_author = event_author 66 self.event_option_name = event_option_name 67 68 self.command = "set_active_mode"
event_value: only process events with this event_value
event_option_name: event option containing the desired OpenRVDAS mode
event_author: optionally accept only events by a specific author
71 def transform(self, record: Union[DASRecord, SealogEvent, str]) -> str: 72 """ 73 Accept a DASRecord, SealogEvent or json str. Process the record and 74 determine if it matches the requirements for requesting an OpenRVDAS 75 mode change. 76 """ 77 # See if it's something we can process, and if not, try digesting 78 if not self.can_process_record(record): # inherited from BaseModule() 79 return self.digest_record(record) # inherited from BaseModule() 80 81 try: 82 event = to_event(record) 83 except Exception as err: 84 logging.warning("Unable to parse record to Sealog event") 85 logging.info("Error: %s", err) 86 return None 87 88 # Optionally match event author 89 if self.event_author and self.event_author != event.event_author: 90 return None 91 92 # If the event value matches, look for the event_option 93 if event.event_value == self.event_value: 94 for event_option in event.event_options: 95 96 # If new mode found, return the command string 97 if event_option.get('event_option_name') == self.event_option_name: 98 cmd_str = f'{self.command} {event_option.get("event_option_value")}' 99 logging.info('Submitting command to OpenRVDAS: "%s"', cmd_str) 100 return cmd_str 101 102 return None
Accept a DASRecord, SealogEvent or json str. Process the record and determine if it matches the requirements for requesting an OpenRVDAS mode change.