def test_chunker(self): """ Test the chunker and verify the particles created. """ chunker = StringChunker(Protocol.sieve_function) self.assert_chunker_sample(chunker, SAMPLE_MNU_RESPONSE) self.assert_chunker_sample_with_noise(chunker, SAMPLE_MNU_RESPONSE) self.assert_chunker_fragmented_sample(chunker, SAMPLE_MNU_RESPONSE, 32) self.assert_chunker_combined_sample(chunker, SAMPLE_MNU_RESPONSE) self.assert_chunker_sample(chunker, SAMPLE_MET_RESPONSE) self.assert_chunker_sample_with_noise(chunker, SAMPLE_MET_RESPONSE) self.assert_chunker_fragmented_sample(chunker, SAMPLE_MET_RESPONSE, 32) self.assert_chunker_combined_sample(chunker, SAMPLE_MET_RESPONSE) self.assert_chunker_sample(chunker, SAMPLE_SAMPLE_RESPONSE) self.assert_chunker_sample_with_noise(chunker, SAMPLE_SAMPLE_RESPONSE) self.assert_chunker_fragmented_sample(chunker, SAMPLE_SAMPLE_RESPONSE, 32) self.assert_chunker_combined_sample(chunker, SAMPLE_SAMPLE_RESPONSE)
def __init__(self, prompts, newline, driver_event, connections=None): """ Constructor. @param prompts Enum class containing possible device prompts used for command response logic. @param newline The device newline. @driver_event The callback for asynchronous driver events. """ if not type(connections) is list: raise InstrumentProtocolException('Unable to instantiate multi connection protocol without connection list') self._param_dict2 = ProtocolParameterDict() # Construct superclass. WorkhorseProtocol.__init__(self, prompts, newline, driver_event) # Create multiple connection versions of the pieces of protocol involving data to/from the instrument self._linebuf = {connection: '' for connection in connections} self._promptbuf = {connection: '' for connection in connections} self._last_data_timestamp = {connection: None for connection in connections} self.connections = {connection: None for connection in connections} self.chunkers = {connection: StringChunker(self.sieve_function) for connection in connections}
def test_chunker(self): """ Tests the chunker """ chunker = StringChunker(Protocol.chunker_sieve_function) # test complete data structures self.assert_chunker_sample(chunker, velocity_sample()) self.assert_chunker_sample(chunker, system_sample()) self.assert_chunker_sample(chunker, velocity_header_sample()) # test fragmented data structures sample = velocity_sample() fragments = [sample[0:4], sample[4:10], sample[10:14], sample[14:]] self.assert_chunker_fragmented_sample(chunker, fragments, sample) sample = system_sample() fragments = [sample[0:5], sample[5:11], sample[11:15], sample[15:]] self.assert_chunker_fragmented_sample(chunker, fragments, sample) sample = velocity_header_sample() fragments = [sample[0:3], sample[3:11], sample[11:12], sample[12:]] self.assert_chunker_fragmented_sample(chunker, fragments, sample) # test combined data structures self.assert_chunker_combined_sample(chunker, velocity_sample(), system_sample(), velocity_header_sample()) self.assert_chunker_combined_sample(chunker, velocity_header_sample(), velocity_sample(), system_sample()) self.assert_chunker_combined_sample(chunker, velocity_header_sample(), head_config_sample(), system_sample()) # test data structures with noise self.assert_chunker_sample_with_noise(chunker, velocity_sample()) self.assert_chunker_sample_with_noise(chunker, system_sample()) self.assert_chunker_sample_with_noise(chunker, velocity_header_sample())
def __init__(self, config, stream_handle, state, sieve_fn, state_callback, publish_callback): """ @param config The configuration parameters to feed into the parser @param stream_handle An already open file-like filehandle @param state The location in the file to start parsing from. This reflects what has already been published. @param sieve_fn A sieve function that might be added to a handler to appropriate filter out the data @param state_callback The callback method from the agent driver (ultimately the agent) to call back when a state needs to be updated @param publish_callback The callback from the agent driver (and ultimately from the agent) where we send our sample particle to be published into ION """ self._chunker = StringChunker(sieve_fn) self._stream_handle = stream_handle self._state = state self._state_callback = state_callback self._publish_callback = publish_callback self._config = config #self._new_sequence = True # It was originally thought that we wanted to start a new sequence for every new file # But that has changed. If we want this behavior back then we need to change # this back to true self._new_sequence = False #build class from module and class name, then set the state if config.get("particle_module"): self._particle_module = __import__( config.get("particle_module"), fromlist=[config.get("particle_class")]) self._particle_class = getattr(self._particle_module, config.get("particle_class")) else: log.warn("No particle module specified in config")
def __init__(self, prompts, newline, driver_event): """ @param prompts A BaseEnum class containing instrument prompts. @param newline The SBE16 newline. @param driver_event Driver process event callback. """ CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # This driver does not process commands, the finite state machine and handlers are stubs self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) handlers = { ProtocolState.UNKNOWN: { (ProtocolEvent.ENTER, self._handler_state_change()), (ProtocolEvent.EXIT, self._handler_pass_through()), (ProtocolEvent.DISCOVER, self._handler_unknown_discover()), }, ProtocolState.COMMAND: { (ProtocolEvent.ENTER, self._handler_state_change()), (ProtocolEvent.EXIT, self._handler_pass_through()), (ProtocolEvent.GET, self._handler_pass_through()), }, } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) self._build_param_dict() self._build_command_dict() self._build_driver_dict() self._protocol_fsm.start(ProtocolState.UNKNOWN) self._chunker = StringChunker(self.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Construct protocol superclass. Pco2wProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # build the chunker self._chunker = StringChunker(Protocol.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.EXIT, self._handler_unknown_exit) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.EXIT, self._handler_autosample_exit) self._protocol_fsm.start(ProtocolState.UNKNOWN) self._chunker = StringChunker(Protocol.sieve_function) self._build_driver_dict() self._cmd_dict.add(Capability.DISCOVER, display_name='Discover')
def test_chunker(self): """ Test the chunker and verify the particles created. """ chunker = StringChunker(Protocol.sieve_function) self.assert_chunker_sample(chunker, self.VALID_SAMPLE_01) self.assert_chunker_sample_with_noise(chunker, self.VALID_SAMPLE_01) self.assert_chunker_fragmented_sample(chunker, self.VALID_SAMPLE_01) self.assert_chunker_combined_sample(chunker, self.VALID_SAMPLE_01) self.assert_chunker_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_sample_with_noise(chunker, self.VALID_SAMPLE_02) self.assert_chunker_fragmented_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_combined_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_sample_with_noise(chunker, self.VALID_SAMPLE_02) self.assert_chunker_fragmented_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_combined_sample(chunker, self.VALID_SAMPLE_02) self.assert_chunker_sample(chunker, self.VALID_STATUS_01) self.assert_chunker_sample_with_noise(chunker, self.VALID_STATUS_01) self.assert_chunker_fragmented_sample(chunker, self.VALID_STATUS_01) self.assert_chunker_combined_sample(chunker, self.VALID_STATUS_01)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_unknown_enter), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.INIT_PARAMS, self._handler_command_init_params), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.CLOCK_SYNC, self._handler_sync_clock), (ProtocolEvent.ACQUIRE_SAMPLE, self._handler_command_acquire), # (ProtocolEvent.ACQUIRE_STATUS, self._handler_command_status), (ProtocolEvent.CLEAR, self._handler_command_clear), (ProtocolEvent.GET, self._handler_get), (ProtocolEvent.SET, self._handler_command_set), ], ProtocolState.FLUSH: [ (ProtocolEvent.ENTER, self._handler_flush_enter), (ProtocolEvent.FLUSH, self._handler_flush_flush), (ProtocolEvent.PUMP_STATUS, self._handler_flush_pump_status), (ProtocolEvent.INSTRUMENT_FAILURE, self._handler_all_failure), ], ProtocolState.FILL: [ (ProtocolEvent.ENTER, self._handler_fill_enter), (ProtocolEvent.FILL, self._handler_fill_fill), (ProtocolEvent.PUMP_STATUS, self._handler_fill_pump_status), (ProtocolEvent.INSTRUMENT_FAILURE, self._handler_all_failure), ], ProtocolState.CLEAR: [ (ProtocolEvent.ENTER, self._handler_clear_enter), (ProtocolEvent.CLEAR, self._handler_clear_clear), (ProtocolEvent.PUMP_STATUS, self._handler_clear_pump_status), (ProtocolEvent.INSTRUMENT_FAILURE, self._handler_all_failure), ], ProtocolState.RECOVERY: [ (ProtocolEvent.ENTER, self._handler_recovery_enter), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct), ], } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Add build handlers for device commands - we are only using simple commands for cmd in McLaneCommand.list(): self._add_build_handler(cmd, self._build_command) # Add response handlers for device commands. # self._add_response_handler(McLaneCommand.BATTERY, self._parse_battery_response) # self._add_response_handler(McLaneCommand.CLOCK, self._parse_clock_response) # self._add_response_handler(McLaneCommand.PORT, self._parse_port_response) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() self._chunker = StringChunker(McLaneProtocol.sieve_function) self._add_scheduler_event(ScheduledJob.CLOCK_SYNC, ProtocolEvent.CLOCK_SYNC) # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) self._sent_cmds = None # TODO - reset next_port on mechanical refresh of the PPS filters - how is the driver notified? # TODO - need to persist state for next_port to save driver restart self.next_port = 1 # next available port self._second_attempt = False
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.GET, self._handler_command_get), (ProtocolEvent.SET, self._handler_command_set), (ProtocolEvent.START1, self._handler_command_start1), (ProtocolEvent.NAFREG, self._handler_command_nafreg), (ProtocolEvent.IONREG, self._handler_command_ionreg), (ProtocolEvent.POWEROFF, self._handler_command_poweroff), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.START1: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.START1_COMPLETE, self._handler_start1_complete), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.WAITING_TURBO: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.START2, self._handler_waiting_turbo_start2), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.START2: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.START2_COMPLETE, self._handler_start2_complete), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.WAITING_RGA: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.SAMPLE, self._handler_waiting_rga_sample), (ProtocolEvent.CALIBRATE, self._handler_waiting_rga_cal), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.SAMPLE: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.SAMPLE_COMPLETE, self._handler_sample_complete), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.CALIBRATE: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.CALIBRATE_COMPLETE, self._handler_cal_complete), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.STOPPING: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.REGEN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STANDBY, self._handler_stop), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STOP_DIRECT, self._handler_stop), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), ], ProtocolState.ERROR: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STANDBY, self._handler_error_standby), (ProtocolEvent.CLEAR, self._handler_stop), ], } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # response handlers for command in InstrumentCommand.list(): self._add_response_handler( command, functools.partial(self._generic_response_handler, command=command)) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() # Add build handlers for device commands. for command in InstrumentCommand.list(): if command == InstrumentCommand.SET_TELEGRAM_INTERVAL: self._add_build_handler(command, self._build_telegram_interval_command) elif command == InstrumentCommand.SAMPLE: self._add_build_handler(command, self._build_sample_command) elif command == InstrumentCommand.SET_MINUTE: self._add_build_handler(command, self._build_set_minute_command) else: self._add_build_handler(command, self._build_simple_command) # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(Protocol.sieve_function) self.resetting = False
def __init__(self, prompts, newline, driver_event): """ SBE43Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The SBE43 newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build SBE19 protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_unknown_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.COMMAND: [(ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.ACQUIRE_SAMPLE, self._handler_command_acquire_sample), (ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample), (ProtocolEvent.GET, self._handler_get), (ProtocolEvent.SET, self._handler_command_set), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.CLOCK_SYNC, self._handler_command_clock_sync_clock), (ProtocolEvent.ACQUIRE_STATUS, self._handler_command_acquire_status)], ProtocolState.ACQUIRING_SAMPLE: [ (ProtocolEvent.ENTER, self._handler_acquiring_sample_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.ACQUIRE_SAMPLE_ASYNC, self._handler_acquire_sample_async), ], ProtocolState.DIRECT_ACCESS: [(ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct)], ProtocolState.AUTOSAMPLE: [ (ProtocolEvent.ENTER, self._handler_autosample_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.GET, self._handler_get), (ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample), (ProtocolEvent.SCHEDULED_ACQUIRED_STATUS, self._handler_autosample_acquire_status), ] } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_driver_dict() self._build_command_dict() self._build_param_dict() # Add build handlers for device commands, only using simple command handler. for cmd in Command.list(): if cmd == Command.SET: self._add_build_handler(Command.SET, self._build_set_command) else: self._add_build_handler(cmd, self._build_simple_command) # Add response handlers for device commands. # these are here to ensure that correct responses to the commands are received before the next command is sent self._add_response_handler(Command.SET, self._parse_set_response) self._add_response_handler(Command.GET_SD, self._validate_GetSD_response) self._add_response_handler(Command.GET_HD, self._validate_GetHD_response) self._add_response_handler(Command.GET_CD, self._validate_GetCD_response) self._add_response_handler(Command.GET_CC, self._validate_GetCC_response) self._add_response_handler(Command.GET_EC, self._validate_GetEC_response) # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) self._chunker = StringChunker(self.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.EXIT, self._handler_unknown_exit) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.EXIT, self._handler_command_exit) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.EXIT, self._handler_autosample_exit) self._protocol_fsm.add_handler( ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXIT, self._handler_direct_access_exit) self._protocol_fsm.add_handler( ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) self._protocol_fsm.start(ProtocolState.UNKNOWN) self._chunker = StringChunker(Protocol.sieve_function) self._build_driver_dict()
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_unknown_enter), (ProtocolEvent.EXIT, self._handler_unknown_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.EXIT, self._handler_command_exit), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.ACQUIRE_SAMPLE, self._handler_sample), (ProtocolEvent.START_AUTOSAMPLE, self._handler_command_autosample), (ProtocolEvent.GET, self._handler_get), (ProtocolEvent.SET, self._handler_command_set), ], ProtocolState.AUTOSAMPLE: [ (ProtocolEvent.ENTER, self._handler_autosample_enter), (ProtocolEvent.ACQUIRE_SAMPLE, self._handler_sample), (ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop), (ProtocolEvent.EXIT, self._handler_autosample_exit), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_direct_access_exit), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct), ], } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Add build handlers for device commands - we are only using simple commands for cmd in Command.list(): self._add_build_handler(cmd, self._build_command) self._add_response_handler(cmd, self._check_command) self._add_build_handler(Command.SETUP, self._build_setup_command) self._add_response_handler(Command.READ_SETUP, self._read_setup_response_handler) # Add response handlers for device commands. # self._add_response_handler(Command.xyz, self._parse_xyz_response) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() self._chunker = StringChunker(Protocol.sieve_function) # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) self._sent_cmds = None self.initialize_scheduler() # unit identifiers - must match the setup command (SU31 - '1') self._units = ['1', '2', '3'] self._setup = None # set by the read setup command handler for comparison to see if the config needs reset
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_STATUS, self._handler_command_acquire_status) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.GET, self._handler_command_get) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_driver_dict() self._build_command_dict() self._build_param_dict() # Add sample handlers. # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(self.sieve_function)
def test_chunker(self): """ Test the chunker and verify the particles created. """ chunker = StringChunker(Protocol.sieve_function)
def __init__(self, menu, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. MenuInstrumentProtocol.__init__(self, menu, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.DISCOVER, self._handler_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.DISCOVER, self._handler_discover) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXIT, self._handler_direct_access_exit) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() # Add build handlers for device commands. self._add_build_handler(Command.BACK_MENU, self._build_menu_command) self._add_build_handler(Command.BLANK, self._build_solo_command) self._add_build_handler(Command.START_AUTOSAMPLE, self._build_menu_command) self._add_build_handler(Command.CHANGE_PARAM, self._build_menu_command) self._add_build_handler(Command.SHOW_PARAM, self._build_menu_command) self._add_build_handler(Command.SENSOR_POWER, self._build_menu_command) self._add_build_handler(Command.DIRECT_SET, self._build_direct_command) self._add_build_handler(Command.CHANGE_CYCLE_TIME, self._build_menu_command) self._add_build_handler(Command.CHANGE_VERBOSE, self._build_menu_command) self._add_build_handler(Command.CHANGE_METADATA_RESTART, self._build_menu_command) self._add_build_handler(Command.CHANGE_METADATA_POWERUP, self._build_menu_command) self._add_build_handler(Command.CHANGE_RES_SENSOR_POWER, self._build_menu_command) self._add_build_handler(Command.CHANGE_INST_AMP_POWER, self._build_menu_command) self._add_build_handler(Command.CHANGE_EH_ISOLATION_AMP_POWER, self._build_menu_command) self._add_build_handler(Command.CHANGE_HYDROGEN_POWER, self._build_menu_command) self._add_build_handler(Command.CHANGE_REFERENCE_TEMP_POWER, self._build_menu_command) # Add response handlers for device commands. #self._add_response_handler(Command.GET, self._parse_get_response) #self._add_response_handler(Command.SET, self._parse_get_response) self._add_response_handler(Command.BACK_MENU, self._parse_menu_change_response) self._add_response_handler(Command.BLANK, self._parse_menu_change_response) self._add_response_handler(Command.SHOW_PARAM, self._parse_show_param_response) self._add_response_handler(Command.CHANGE_CYCLE_TIME, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_VERBOSE, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_METADATA_RESTART, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_METADATA_POWERUP, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_RES_SENSOR_POWER, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_INST_AMP_POWER, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_EH_ISOLATION_AMP_POWER, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_HYDROGEN_POWER, self._parse_menu_change_response) self._add_response_handler(Command.CHANGE_REFERENCE_TEMP_POWER, self._parse_menu_change_response) self._add_response_handler(Command.DIRECT_SET, self._parse_menu_change_response) # Add sample handlers. # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(self.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.GET, self._handler_command_get), (ProtocolEvent.SET, self._handler_command_set), (ProtocolEvent.START_TURBO, self._handler_command_start_turbo), ], ProtocolState.SPINNING_UP: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.STOP_TURBO, self._handler_stop_turbo), (ProtocolEvent.AT_SPEED, self._handler_spinning_up_at_speed), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.AT_SPEED: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STOP_TURBO, self._handler_stop_turbo), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.ERROR, self._handler_error), ], ProtocolState.ERROR: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.STOP_TURBO, self._handler_stop_turbo), (ProtocolEvent.CLEAR, self._handler_clear), (ProtocolEvent.GET, self._handler_command_get), ], ProtocolState.SPINNING_DOWN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.STOPPED, self._handler_spinning_down_stopped), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), ], } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() # Add build and response handlers for device commands. for command in InstrumentCommand.list(): self._add_build_handler(command, self._generic_build_handler) self._add_response_handler(command, self._generic_response_handler) # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(Protocol.sieve_function) self._max_current_count = 0 self.initialize_scheduler()
def __init__(self, callback=None): CommandResponseInstrumentProtocol.__init__(self, Prompt, EOLN, callback) self._last_data_timestamp = None self._protocol_fsm = ThreadSafeFSM(SatlanticProtocolState, SatlanticProtocolEvent, SatlanticProtocolEvent.ENTER, SatlanticProtocolEvent.EXIT) self._protocol_fsm.add_handler(SatlanticProtocolState.UNKNOWN, SatlanticProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.UNKNOWN, SatlanticProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.ACQUIRE_STATUS, self._handler_command_acquire_status) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(SatlanticProtocolState.AUTOSAMPLE, SatlanticProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler( SatlanticProtocolState.AUTOSAMPLE, SatlanticProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler( SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) self._protocol_fsm.start(SatlanticProtocolState.UNKNOWN) self._add_response_handler(Command.GET, self._parse_get_response) self._add_response_handler(Command.SET, self._parse_set_response) self._add_response_handler(Command.INVALID, self._parse_invalid_response) self._param_dict.add( Parameter.MAX_RATE, r"Maximum\ Frame\ Rate:\ (\S+).*?\s*", lambda match: match.group(1), lambda sVal: '%s' % sVal, type=ParameterDictType.STRING, display_name="Max Rate", value_description= "valid values: 0=auto, 0.125, 0.25, 0.5, 1, 2, 4, 8, 10, 12", units=Units.HERTZ, default_value='0', startup_param=True, direct_access=True) self._param_dict.add(Parameter.INIT_AT, r"Initialize Automatic Telemetry: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Init AT", default_value=True, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._param_dict.add(Parameter.INIT_SM, r"Initialize Silent Mode: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Init SM", default_value=True, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._param_dict.add(Parameter.NET_MODE, r"Network Mode: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Net Mode", default_value=False, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._cmd_dict.add(SatlanticCapability.START_AUTOSAMPLE, display_name="Start Autosample") self._cmd_dict.add(SatlanticCapability.STOP_AUTOSAMPLE, display_name="Stop Autosample") self._cmd_dict.add(SatlanticCapability.ACQUIRE_STATUS, display_name="Acquire Status") self._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE, True) self._chunker = StringChunker(self.sieve_function)
def __init__(self, prompts, newline, driver_event): """ SBE43Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The SBE43 newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build SBE19 protocol state machine. self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.EXIT, self._handler_unknown_exit) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.EXIT, self._handler_command_exit) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_SAMPLE, self._handler_command_acquire_sample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET_CONFIGURATION, self._handler_command_get_configuration) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.CLOCK_SYNC, self._handler_command_clock_sync_clock) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_STATUS, self._handler_command_acquire_status) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.EXIT, self._handler_autosample_exit) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ACQUIRE_STATUS, self._handler_autosample_acquire_status) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.GET_CONFIGURATION, self._handler_autosample_get_configuration) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXIT, self._handler_direct_access_exit) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_driver_dict() self._build_command_dict() self._build_param_dict() # Add build handlers for device commands. self._add_build_handler(Command.DS, self._build_simple_command) self._add_build_handler(Command.GET_CD, self._build_simple_command) self._add_build_handler(Command.GET_SD, self._build_simple_command) self._add_build_handler(Command.GET_CC, self._build_simple_command) self._add_build_handler(Command.GET_EC, self._build_simple_command) self._add_build_handler(Command.RESET_EC, self._build_simple_command) self._add_build_handler(Command.GET_HD, self._build_simple_command) self._add_build_handler(Command.START_NOW, self._build_simple_command) self._add_build_handler(Command.STOP, self._build_simple_command) self._add_build_handler(Command.TS, self._build_simple_command) self._add_build_handler(Command.SET, self._build_set_command) # Add response handlers for device commands. # these are here to ensure that correct responses to the commands are received before the next command is sent self._add_response_handler(Command.DS, self._parse_dsdc_response) self._add_response_handler(Command.SET, self._parse_set_response) self._add_response_handler(Command.GET_SD, self._validate_GetSD_response) self._add_response_handler(Command.GET_HD, self._validate_GetHD_response) self._add_response_handler(Command.GET_CD, self._validate_GetCD_response) self._add_response_handler(Command.GET_CC, self._validate_GetCC_response) self._add_response_handler(Command.GET_EC, self._validate_GetEC_response) # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) self._chunker = StringChunker(self.sieve_function)
def __init__(self, driver_event): CommandResponseInstrumentProtocol.__init__(self, None, None, driver_event) self._chunker = StringChunker(self.sieve_function)
def __init__(self, callback=None): CommandResponseInstrumentProtocol.__init__(self, Prompt, EOLN, callback) self._last_data_timestamp = None self._protocol_fsm = ThreadSafeFSM(SatlanticProtocolState, SatlanticProtocolEvent, SatlanticProtocolEvent.ENTER, SatlanticProtocolEvent.EXIT) self._protocol_fsm.add_handler(SatlanticProtocolState.UNKNOWN, SatlanticProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.UNKNOWN, SatlanticProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.ACQUIRE_STATUS, self._handler_command_acquire_status) self._protocol_fsm.add_handler(SatlanticProtocolState.COMMAND, SatlanticProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(SatlanticProtocolState.AUTOSAMPLE, SatlanticProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.AUTOSAMPLE, SatlanticProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(SatlanticProtocolState.DIRECT_ACCESS, SatlanticProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) self._protocol_fsm.start(SatlanticProtocolState.UNKNOWN) self._add_response_handler(Command.GET, self._parse_get_response) self._add_response_handler(Command.SHOW_ALL, self._parse_getAll_response) self._add_response_handler(Command.SET, self._parse_set_response) self._add_response_handler(Command.INVALID, self._parse_invalid_response) self._param_dict.add(Parameter.MAX_RATE, r"Maximum\ Frame\ Rate:\ (\S+).*?\s*", lambda match: '0' if match.group(1) == 'AUTO' else match.group(1), lambda sVal: '%s' % sVal, type=ParameterDictType.STRING, display_name="Maximum Frame Rate", range={'auto': 0, '0.125': 0.125, '0.25': 0.25, '0.5': 0.5, '1': 1, '2': 2, '4': 4, '8': 8, '10': 10, '12': 12}, units=Units.HERTZ, description="Frame rate: (0=auto | 0.125 | 0.25 | 0.5 | 1 | 2 | 4 | 8 | 10 | 12)", default_value='0', startup_param=True, direct_access=True) self._param_dict.add(Parameter.INIT_AT, r"Initialize Automatic Telemetry: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Auto Telemetry", range={'True': True, 'False': False}, description="Enables auto telemetry: (true | false)", default_value=True, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._param_dict.add(Parameter.INIT_SM, r"Initialize Silent Mode: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Silent Mode", range={'True': True, 'False': False}, description="Enables silent mode: (true | false)", default_value=True, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._param_dict.add(Parameter.NET_MODE, r"Network Mode: (off|on)", lambda match: True if match.group(1) == 'on' else False, self._boolean_to_off_on, type=ParameterDictType.BOOL, display_name="Network Mode", range={'True': True, 'False': False}, description="Enables network operation: (true | false)", default_value=False, visibility=ParameterDictVisibility.IMMUTABLE, startup_param=True, direct_access=True) self._cmd_dict.add(SatlanticCapability.START_AUTOSAMPLE, display_name="Start Autosample") self._cmd_dict.add(SatlanticCapability.STOP_AUTOSAMPLE, display_name="Stop Autosample") self._cmd_dict.add(SatlanticCapability.ACQUIRE_STATUS, display_name="Acquire Status") self._cmd_dict.add(SatlanticCapability.DISCOVER, display_name='Discover') self._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE, True) self._chunker = StringChunker(self.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.EXIT, self._handler_unknown_exit) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.EXIT, self._handler_command_exit) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_SAMPLE, self._handler_acquire_sample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.CLOCK_SYNC, self._handler_command_sync_clock) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.FLASH_STATUS, self._handler_flash_status) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.EXIT, self._handler_autosample_exit) self._protocol_fsm.add_handler( ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ACQUIRE_SAMPLE, self._handler_acquire_sample) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.CLOCK_SYNC, self._handler_autosample_sync_clock) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.GET, self._handler_get) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.FLASH_STATUS, self._handler_flash_status) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status) # We setup a new state for clock sync because then we could use the state machine so the autosample scheduler # is disabled before we try to sync the clock. Otherwise there could be a race condition introduced when we # are syncing the clock and the scheduler requests a sample. self._protocol_fsm.add_handler(ProtocolState.SYNC_CLOCK, ProtocolEvent.ENTER, self._handler_sync_clock_enter) self._protocol_fsm.add_handler(ProtocolState.SYNC_CLOCK, ProtocolEvent.CLOCK_SYNC, self._handler_sync_clock_sync) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXIT, self._handler_direct_access_exit) self._protocol_fsm.add_handler( ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) # Add build handlers for device commands. self._add_build_handler(Command.GET_CLOCK, self._build_simple_command) self._add_build_handler(Command.SET_CLOCK, self._build_set_clock_command) self._add_build_handler(Command.D, self._build_simple_command) self._add_build_handler(Command.GO, self._build_simple_command) self._add_build_handler(Command.STOP, self._build_simple_command) self._add_build_handler(Command.FS, self._build_simple_command) self._add_build_handler(Command.STAT, self._build_simple_command) # Add response handlers for device commands. self._add_response_handler(Command.GET_CLOCK, self._parse_clock_response) self._add_response_handler(Command.SET_CLOCK, self._parse_clock_response) self._add_response_handler(Command.FS, self._parse_fs_response) self._add_response_handler(Command.STAT, self._parse_common_response) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() self._chunker = StringChunker(Protocol.sieve_function) self._add_scheduler_event(ScheduledJob.ACQUIRE_STATUS, ProtocolEvent.ACQUIRE_STATUS) self._add_scheduler_event(ScheduledJob.CLOCK_SYNC, ProtocolEvent.CLOCK_SYNC) # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.AUTOSAMPLE: [ (ProtocolEvent.ENTER, self._handler_autosample_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.GET, self._handler_command_get), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample), (ProtocolEvent.START_LEVELING, self._handler_start_leveling), (ProtocolEvent.STOP_LEVELING, self._handler_stop_leveling), (ProtocolEvent.NANO_TIME_SYNC, self._handler_time_sync), (ProtocolEvent.START_HEATER, self._handler_start_heater), (ProtocolEvent.STOP_HEATER, self._handler_stop_heater), (ProtocolEvent.LEVELING_TIMEOUT, self._handler_leveling_timeout), (ProtocolEvent.HEATER_TIMEOUT, self._handler_heater_timeout), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_command_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.GET, self._handler_command_get), (ProtocolEvent.SET, self._handler_command_set), (ProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status), (ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample), (ProtocolEvent.START_LEVELING, self._handler_start_leveling), (ProtocolEvent.STOP_LEVELING, self._handler_stop_leveling), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.NANO_TIME_SYNC, self._handler_time_sync), (ProtocolEvent.START_HEATER, self._handler_start_heater), (ProtocolEvent.STOP_HEATER, self._handler_stop_heater), (ProtocolEvent.LEVELING_TIMEOUT, self._handler_leveling_timeout), (ProtocolEvent.HEATER_TIMEOUT, self._handler_heater_timeout), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct), ], } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Construct the metadata dictionaries self._build_param_dict() self._build_command_dict() self._build_driver_dict() # Add build handlers for device commands. for command in InstrumentCommand.list(): if command in [ InstrumentCommand.NANO_SET_RATE, InstrumentCommand.HEAT ]: self._add_build_handler(command, self._build_command_with_value) else: self._add_build_handler(command, self._build_simple_command) # # Add response handlers for device commands. for command in InstrumentCommand.list(): self._add_response_handler(command, self._generic_response_handler) # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent to device to be filtered in responses for telnet DA self._sent_cmds = [] # create chunker self._chunker = StringChunker(Protocol.sieve_function) self._last_data_timestamp = 0 self.has_pps = True # set up scheduled event handling self.initialize_scheduler() self._add_scheduler_event(ScheduledJob.ACQUIRE_STATUS, ProtocolEvent.ACQUIRE_STATUS) self._add_scheduler_event(ScheduledJob.NANO_TIME_SYNC, ProtocolEvent.NANO_TIME_SYNC)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. handlers = { ProtocolState.UNKNOWN: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.DISCOVER, self._handler_unknown_discover), ], ProtocolState.COMMAND: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.START_DIRECT, self._handler_command_start_direct), (ProtocolEvent.GET, self._handler_command_get), (ProtocolEvent.SET, self._handler_command_set), (ProtocolEvent.START_SCAN, self._handler_command_start_scan), ], ProtocolState.DIRECT_ACCESS: [ (ProtocolEvent.ENTER, self._handler_direct_access_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct), (ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct), ], ProtocolState.SCAN: [ (ProtocolEvent.ENTER, self._handler_scan_enter), (ProtocolEvent.EXIT, self._handler_scan_exit), (ProtocolEvent.STOP_SCAN, self._handler_scan_stop_scan), (ProtocolEvent.TAKE_SCAN, self._handler_scan_take_scan), (ProtocolEvent.TIMEOUT, self._handler_scan_timeout), (ProtocolEvent.ERROR, self._handler_scan_error), ], ProtocolState.ERROR: [ (ProtocolEvent.ENTER, self._handler_generic_enter), (ProtocolEvent.EXIT, self._handler_generic_exit), (ProtocolEvent.CLEAR, self._handler_error_clear), (ProtocolEvent.GET, self._handler_command_get), ] } for state in handlers: for event, handler in handlers[state]: self._protocol_fsm.add_handler(state, event, handler) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_param_dict() self._build_command_dict() self._build_driver_dict() # Add build handlers for device commands. for command in InstrumentCommand.list(): self._add_build_handler(command, self._generic_build_handler) # Add response handlers for device commands. for command in InstrumentCommand.list(): self._add_response_handler(command, functools.partial(self._generic_response_handler, command=command)) # State state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(Protocol.sieve_function) self.initialize_scheduler() # all calls to do_cmd_resp should expect RESPONSE_REGEX and use TIMEOUT. Freeze these arguments... self._do_cmd_resp = functools.partial(self._do_cmd_resp, response_regex=RESPONSE_REGEX, timeout=TIMEOUT) # these variables are used to track scan time and completion status # for development and performance data self.scan_start_time = 0 self.in_scan = False
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Construct protocol superclass. CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Add event handlers for protocol state machine. self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.EXIT, self._handler_unknown_exit) self._protocol_fsm.add_handler(ProtocolState.UNKNOWN, ProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.EXIT, self._handler_command_exit) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.ACQUIRE_SAMPLE, self._handler_command_acquire_sample) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.GET, self._handler_command_get) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.EXIT, self._handler_autosample_exit) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.SCHEDULE_ACQUIRE_SAMPLE, self._handler_command_acquire_sample) self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE, ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXIT, self._handler_direct_access_exit) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(ProtocolState.DIRECT_ACCESS, ProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_driver_dict() self._build_command_dict() self._build_param_dict() # Add build handlers for device commands. self._add_build_handler(Command.GET_SAMPLE, self._build_simple_command) self._add_build_handler(Command.COMM_TEST, self._build_simple_command) # Add response handlers for device commands. # State state machine in COMMAND state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # commands sent to device to be filtered in responses for telnet DA self._sent_cmds = [] self._chunker = StringChunker(THSPHProtocol.sieve_function)
def __init__(self, prompts, newline, driver_event): NortekInstrumentProtocol.__init__(self, prompts, newline, driver_event) # create chunker for processing instrument samples. self._chunker = StringChunker(Protocol.chunker_sieve_function)
def setUp(self): """ Setup a chunker for use in tests """ self._chunker = StringChunker(UnitTestStringChunker.sieve_function)
def __init__(self, driver_event): super(PlaybackProtocol, self). __init__(None, None, driver_event) self.log_timestamp = None self._chunker = StringChunker(self.sieve_function)
def __init__(self, callback=None): CommandResponseInstrumentProtocol.__init__(self, Prompt, EOLN, callback) self._protocol_fsm = InstrumentFSM(PARProtocolState, PARProtocolEvent, PARProtocolEvent.ENTER, PARProtocolEvent.EXIT) self._protocol_fsm.add_handler(PARProtocolState.UNKNOWN, PARProtocolEvent.ENTER, self._handler_unknown_enter) self._protocol_fsm.add_handler(PARProtocolState.UNKNOWN, PARProtocolEvent.DISCOVER, self._handler_unknown_discover) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.ENTER, self._handler_command_enter) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.GET, self._handler_get) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.SET, self._handler_command_set) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.ACQUIRE_SAMPLE, self._handler_poll_acquire_sample) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.ACQUIRE_STATUS, self._handler_acquire_status) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.SCHEDULED_ACQUIRE_STATUS, self._handler_acquire_status) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample) self._protocol_fsm.add_handler(PARProtocolState.COMMAND, PARProtocolEvent.START_DIRECT, self._handler_command_start_direct) self._protocol_fsm.add_handler(PARProtocolState.AUTOSAMPLE, PARProtocolEvent.ENTER, self._handler_autosample_enter) self._protocol_fsm.add_handler(PARProtocolState.AUTOSAMPLE, PARProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample) self._protocol_fsm.add_handler(PARProtocolState.AUTOSAMPLE, PARProtocolEvent.SCHEDULED_ACQUIRE_STATUS, self._handler_autosample_acquire_status) self._protocol_fsm.add_handler(PARProtocolState.DIRECT_ACCESS, PARProtocolEvent.ENTER, self._handler_direct_access_enter) self._protocol_fsm.add_handler(PARProtocolState.DIRECT_ACCESS, PARProtocolEvent.EXECUTE_DIRECT, self._handler_direct_access_execute_direct) self._protocol_fsm.add_handler(PARProtocolState.DIRECT_ACCESS, PARProtocolEvent.STOP_DIRECT, self._handler_direct_access_stop_direct) self._protocol_fsm.start(PARProtocolState.UNKNOWN) self._add_response_handler(Command.GET, self._parse_get_response) self._add_response_handler(Command.SET, self._parse_set_response) self._add_response_handler(Command.SAMPLE, self._parse_response) # Construct the parameter dictionary containing device parameters, # current parameter values, and set formatting functions. self._build_cmd_dict() self._build_driver_dict() self._param_dict.add(Parameter.MAXRATE, MAXRATE_PATTERN, lambda match: float(match.group(1)), self._float_or_int_to_string, direct_access=True, startup_param=True, init_value=4, display_name='Max Rate', description='Maximum sampling rate (0 (Auto) | 0.125 | 0.5 | 1 | 2 | 4 | 8 | 10 | 12)', type=ParameterDictType.FLOAT, units=Units.HERTZ, visibility=ParameterDictVisibility.READ_WRITE) self._param_dict.add(Parameter.INSTRUMENT, HEADER_PATTERN, lambda match: match.group(1), str, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Instrument Type', description="", type=ParameterDictType.STRING, startup_param=True) self._param_dict.add(Parameter.SERIAL, HEADER_PATTERN, lambda match: match.group(1), str, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Serial Number', description="", type=ParameterDictType.STRING, startup_param=True) self._param_dict.add(Parameter.FIRMWARE, HEADER_PATTERN, lambda match: match.group(1), str, visibility=ParameterDictVisibility.IMMUTABLE, display_name='Firmware Version', description="", type=ParameterDictType.STRING, startup_param=True) self._param_dict.add(Parameter.ACQUIRE_STATUS_INTERVAL, INTERVAL_TIME_REGEX, lambda match: match.group(1), str, display_name="Acquire Status Interval", description='Interval for gathering status particles.', type=ParameterDictType.STRING, units=ParameterUnits.TIME_INTERVAL, visibility=ParameterDictVisibility.READ_WRITE, default_value='00:00:00', startup_param=True) self._chunker = StringChunker(SatlanticPARInstrumentProtocol.sieve_function)
def __init__(self, prompts, newline, driver_event): """ Protocol constructor. @param prompts A BaseEnum class containing instrument prompts. @param newline The newline. @param driver_event Driver process event callback. """ # Build protocol state machine. self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT) # Construct protocol superclass. Pco2wProtocol.__init__(self, prompts, newline, driver_event) # Build protocol state machine. self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.RUN_EXTERNAL_PUMP, self._handler_command_run_external_pump) # this state would be entered whenever a RUN_EXTERNAL_PUMP event # occurred while in the COMMAND state self._protocol_fsm.add_handler(ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.ENTER, self._execution_state_enter) self._protocol_fsm.add_handler(ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.EXIT, self._execution_state_exit) self._protocol_fsm.add_handler(ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.EXECUTE, self._handler_run_external_pump_execute) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.SUCCESS, self._execution_success_to_command_state) self._protocol_fsm.add_handler( ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.TIMEOUT, self._execution_timeout_to_command_state) ## Events to queue - intended for schedulable events occurring when a sample is being taken self._protocol_fsm.add_handler(ProtocolState.RUN_EXTERNAL_PUMP, ProtocolEvent.ACQUIRE_STATUS, self._handler_queue_acquire_status) # Add build handlers for device commands. ### primarily defined in base class self._add_build_handler(InstrumentCommand.PCO2WB_ACQUIRE_SAMPLE_DEV1, self._build_simple_command) # Add response handlers for device commands. ### primarily defined in base class self._add_response_handler( InstrumentCommand.PCO2WB_ACQUIRE_SAMPLE_DEV1, self._parse_response_sample_dev1) # Add sample handlers # Start state machine in UNKNOWN state. self._protocol_fsm.start(ProtocolState.UNKNOWN) # build the chunker self._chunker = StringChunker(Protocol.sieve_function) self._engineering_parameters.append(Parameter.EXTERNAL_PUMP_DELAY)