本文整理汇总了Python中mi.core.instrument.instrument_fsm.ThreadSafeFSM类的典型用法代码示例。如果您正苦于以下问题:Python ThreadSafeFSM类的具体用法?Python ThreadSafeFSM怎么用?Python ThreadSafeFSM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadSafeFSM类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
"""
"""
self.prompts = [">"]
self.newline = "\n"
self.callback_result = None
self._trigger_count = 0
self._events = []
self.protocol = CommandResponseInstrumentProtocol(self.prompts,
self.newline,
self.event_callback)
self.protocol_fsm = ThreadSafeFSM(self.TestState, self.TestEvent,
self.TestEvent.ENTER, self.TestEvent.EXIT)
self.protocol_fsm.add_handler(self.TestState.TEST, self.TestEvent.TEST, lambda x : x)
self.protocol._add_build_handler(self.TestEvent.TEST, self._build_simple_command)
self.protocol._add_response_handler(self.TestEvent.TEST, self._parse_test_response)
self.protocol._connection = Mock()
self.protocol._connection.send = lambda x : self.protocol.add_to_buffer("%s >->" % x)
self.protocol.get_current_state = Mock(return_value=self.TestState.TEST)
self.protocol._send_wakeup = lambda: self.protocol.add_to_buffer("wakeup response >->")
self.protocol._wakeup = functools.partial(self.protocol._wakeup, delay=0)
开发者ID:danmergens,项目名称:mi-instrument,代码行数:25,代码来源:test_instrument_protocol.py
示例2: __init__
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)
开发者ID:NickAlmonte,项目名称:marine-integrations,代码行数:60,代码来源:driver.py
示例3: _construct_fsm
def _construct_fsm(self, states=PlatformDriverState,
events=PlatformDriverEvent,
enter_event=PlatformDriverEvent.ENTER,
exit_event=PlatformDriverEvent.EXIT):
"""
Constructs the FSM for the driver. The preparations here are mostly
related with the UNCONFIGURED, DISCONNECTED, and CONNECTED state
transitions, with some common handlers for the CONNECTED state.
Subclasses can override to indicate specific parameters and add new
handlers (typically for the CONNECTED state).
"""
log.debug("constructing base platform driver FSM")
self._fsm = ThreadSafeFSM(states, events, enter_event, exit_event)
for state in PlatformDriverState.list():
self._fsm.add_handler(state, enter_event, self._common_state_enter)
self._fsm.add_handler(state, exit_event, self._common_state_exit)
# UNCONFIGURED state event handlers:
self._fsm.add_handler(PlatformDriverState.UNCONFIGURED, PlatformDriverEvent.CONFIGURE, self._handler_unconfigured_configure)
# DISCONNECTED state event handlers:
self._fsm.add_handler(PlatformDriverState.DISCONNECTED, PlatformDriverEvent.CONNECT, self._handler_disconnected_connect)
self._fsm.add_handler(PlatformDriverState.DISCONNECTED, PlatformDriverEvent.DISCONNECT, self._handler_disconnected_disconnect)
# CONNECTED state event handlers:
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.DISCONNECT, self._handler_connected_disconnect)
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.CONNECTION_LOST, self._handler_connected_connection_lost)
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.PING, self._handler_connected_ping)
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.GET, self._handler_connected_get)
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.SET, self._handler_connected_set)
self._fsm.add_handler(PlatformDriverState.CONNECTED, PlatformDriverEvent.EXECUTE, self._handler_connected_execute)
开发者ID:aplmmilcic,项目名称:mi-instrument,代码行数:34,代码来源:platform_driver.py
示例4: __init__
def __init__(self, driver_event):
super(Protocol, self).__init__(driver_event)
self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent, ProtocolEvent.ENTER, ProtocolEvent.EXIT)
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.GET, self._handler_get),
(ProtocolEvent.SET, self._handler_set),
(ProtocolEvent.START_AUTOSAMPLE, self._handler_command_start_autosample),
),
ProtocolState.AUTOSAMPLE: (
(ProtocolEvent.ENTER, self._handler_autosample_enter),
(ProtocolEvent.EXIT, self._handler_autosample_exit),
(ProtocolEvent.GET, self._handler_get),
(ProtocolEvent.FLUSH, self._flush),
(ProtocolEvent.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample),
),
ProtocolState.STOPPING: (
(ProtocolEvent.ENTER, self._handler_stopping_enter),
(ProtocolEvent.EXIT, self._handler_stopping_exit),
(ProtocolEvent.FLUSH, self._flush),
),
ProtocolState.WRITE_ERROR: (
(ProtocolEvent.ENTER, self._handler_write_error_enter),
(ProtocolEvent.EXIT, self._handler_write_error_exit),
(ProtocolEvent.CLEAR_WRITE_ERROR, self._handler_clear_write_error),
),
}
for state in handlers:
for event, handler in handlers[state]:
self._protocol_fsm.add_handler(state, event, handler)
# Build dictionaries for driver schema
self._build_param_dict()
self._build_command_dict()
self._build_driver_dict()
# State state machine in UNKNOWN state.
self._protocol_fsm.start(ProtocolState.UNKNOWN)
self._logs = {}
self._filled_logs = []
self._pickle_cache = []
# persistent store, cannot initialize until startup config has been applied
# since we need the address for postgres
self._persistent_store = None
# lock for flush actions to prevent writing or altering the data files
# during flush
self._lock = Lock()
self._pktid = 0
开发者ID:cwingard,项目名称:mi-instrument,代码行数:59,代码来源:driver.py
示例5: __init__
def __init__(self, event_callback):
"""
Constructor for singly connected instrument drivers.
@param event_callback Callback to the driver process to send asynchronous
driver events back to the agent.
"""
InstrumentDriver.__init__(self, event_callback)
# The only and only instrument connection.
# Exists in the connected state.
self._connection = None
# The one and only instrument protocol.
self._protocol = None
# Build connection state machine.
self._connection_fsm = ThreadSafeFSM(DriverConnectionState,
DriverEvent,
DriverEvent.ENTER,
DriverEvent.EXIT)
# Add handlers for all events.
self._connection_fsm.add_handler(DriverConnectionState.UNCONFIGURED, DriverEvent.ENTER, self._handler_unconfigured_enter)
self._connection_fsm.add_handler(DriverConnectionState.UNCONFIGURED, DriverEvent.EXIT, self._handler_unconfigured_exit)
self._connection_fsm.add_handler(DriverConnectionState.UNCONFIGURED, DriverEvent.INITIALIZE, self._handler_unconfigured_initialize)
self._connection_fsm.add_handler(DriverConnectionState.UNCONFIGURED, DriverEvent.CONFIGURE, self._handler_unconfigured_configure)
self._connection_fsm.add_handler(DriverConnectionState.DISCONNECTED, DriverEvent.ENTER, self._handler_disconnected_enter)
self._connection_fsm.add_handler(DriverConnectionState.DISCONNECTED, DriverEvent.EXIT, self._handler_disconnected_exit)
self._connection_fsm.add_handler(DriverConnectionState.DISCONNECTED, DriverEvent.INITIALIZE, self._handler_disconnected_initialize)
self._connection_fsm.add_handler(DriverConnectionState.DISCONNECTED, DriverEvent.CONFIGURE, self._handler_disconnected_configure)
self._connection_fsm.add_handler(DriverConnectionState.DISCONNECTED, DriverEvent.CONNECT, self._handler_disconnected_connect)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.ENTER, self._handler_connected_enter)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.EXIT, self._handler_connected_exit)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.DISCONNECT, self._handler_connected_disconnect)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.CONNECTION_LOST, self._handler_connected_connection_lost)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.DISCOVER, self._handler_connected_protocol_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.GET, self._handler_connected_protocol_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.SET, self._handler_connected_protocol_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.EXECUTE, self._handler_connected_protocol_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.FORCE_STATE, self._handler_connected_protocol_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.START_DIRECT, self._handler_connected_start_direct_event)
self._connection_fsm.add_handler(DriverConnectionState.CONNECTED, DriverEvent.STOP_DIRECT, self._handler_connected_stop_direct_event)
# Start state machine.
self._connection_fsm.start(DriverConnectionState.UNCONFIGURED)
self._pre_da_config = {}
self._startup_config = {}
# Idempotency flag for lost connections.
# This set to false when a connection is established to
# allow for lost callback to become activated.
self._connection_lost = True
开发者ID:lukecampbell,项目名称:marine-integrations,代码行数:54,代码来源:instrument_driver.py
示例6: __init__
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)
log.info('processing particles with %d workers', POOL_SIZE)
self._process_particles = True
self._pending_particles = deque()
self._processing_pool = multiprocessing.Pool(POOL_SIZE)
self._particles_thread = Thread(target=self.particles_thread)
self._particles_thread.setDaemon(True)
self._particles_thread.start()
开发者ID:danmergens,项目名称:mi-instrument,代码行数:54,代码来源:driver.py
示例7: __init__
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.STOP_AUTOSAMPLE, self._handler_autosample_stop_autosample),
(ProtocolEvent.VERY_LONG_COMMAND, self._very_long_command),
],
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.START_AUTOSAMPLE, self._handler_command_start_autosample),
(ProtocolEvent.VERY_LONG_COMMAND, self._very_long_command),
],
}
for state in handlers:
for event, handler in handlers[state]:
self._protocol_fsm.add_handler(state, event, handler)
# Construct the metadata dictionaries
self._build_command_dict()
self._build_driver_dict()
# Start state machine in UNKNOWN state.
self._protocol_fsm.start(ProtocolState.UNKNOWN)
# set up scheduled event handling
self.initialize_scheduler()
self._schedulers = []
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:51,代码来源:driver.py
示例8: __init__
def __init__(self, driver_event):
super(Protocol, self).__init__(driver_event)
self._protocol_fsm = ThreadSafeFSM(ProtocolState, ProtocolEvent,
ProtocolEvent.ENTER, ProtocolEvent.EXIT)
handlers = {
ProtocolState.UNKNOWN: (
(ProtocolEvent.ENTER, self._handler_unknown_enter),
(ProtocolEvent.EXIT, self._handler_unknown_exit),
(ProtocolEvent.DISCOVER, self._handler_unknown_discover),
),
ProtocolState.AUTOSAMPLE: (
(ProtocolEvent.ENTER, self._handler_autosample_enter),
(ProtocolEvent.EXIT, self._handler_autosample_exit),
(ProtocolEvent.GET, self._handler_get),
(ProtocolEvent.FLUSH, self._flush),
(ProtocolEvent.CONFIG_ERROR, self._handler_config_error),
),
ProtocolState.WRITE_ERROR: (
(ProtocolEvent.ENTER, self._handler_error_enter),
(ProtocolEvent.EXIT, self._handler_error_exit),
),
ProtocolState.CONFIG_ERROR: (
(ProtocolEvent.ENTER, self._handler_error_enter),
(ProtocolEvent.EXIT, self._handler_error_exit),
)
}
for state in handlers:
for event, handler in handlers[state]:
self._protocol_fsm.add_handler(state, event, handler)
# Build dictionaries for driver schema
self._build_param_dict()
self._build_command_dict()
self._build_driver_dict()
# State state machine in UNKNOWN state.
self._protocol_fsm.start(ProtocolState.UNKNOWN)
self._logs = {}
self._filled_logs = []
self._pickle_cache = []
self._persistent_store = None
# lock for flush actions to prevent writing or altering the data files
# during flush
self._lock = Lock()
self._pktid = None
开发者ID:danmergens,项目名称:mi-instrument,代码行数:49,代码来源:driver.py
示例9: __init__
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.START_DIRECT, self._handler_command_start_direct)
self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.CLOCK_SYNC, self._handler_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.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.BATTERY, self._build_simple_command)
# Add response handlers for device commands.
self._add_response_handler(Command.BATTERY, self._parse_battery_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.CLOCK_SYNC, ProtocolEvent.CLOCK_SYNC)
# Start state machine in UNKNOWN state.
self._protocol_fsm.start(ProtocolState.UNKNOWN)
开发者ID:ateranishi,项目名称:marine-integrations,代码行数:48,代码来源:driver.py
示例10: __init__
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)
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:21,代码来源:driver.py
示例11: __init__
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)
# 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 = []
开发者ID:renegelinas,项目名称:mi-instrument,代码行数:39,代码来源:driver.py
示例12: __init__
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)
开发者ID:oceanobservatories,项目名称:mi-instrument,代码行数:36,代码来源:driver.py
示例13: __init__
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 = ThreadSafeFSM(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')
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:24,代码来源:driver.py
示例14: __init__
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)
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:77,代码来源:driver.py
示例15: __init__
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
开发者ID:cwingard,项目名称:mi-instrument,代码行数:75,代码来源:driver.py
示例16: PlatformDriver
#.........这里部分代码省略.........
try:
result = self.ping()
return None, result
except PlatformConnectionException as e:
return self._connection_lost(PlatformDriverEvent.PING, args, kwargs, e)
def _handler_connected_get(self, *args, **kwargs):
"""
"""
if log.isEnabledFor(logging.TRACE): # pragma: no cover
log.trace("%r/%s args=%s kwargs=%s" % (
self._platform_id, self.get_driver_state(),
str(args), str(kwargs)))
try:
result = self.get(*args, **kwargs)
return None, result
except PlatformConnectionException as e:
return self._connection_lost(PlatformDriverEvent.GET, args, kwargs, e)
def _handler_connected_set(self, *args, **kwargs):
"""
"""
if log.isEnabledFor(logging.TRACE): # pragma: no cover
log.trace("%r/%s args=%s kwargs=%s" % (
self._platform_id, self.get_driver_state(),
str(args), str(kwargs)))
if not self.supports_set_operation():
raise FSMError('Unsupported operation: %s' % PlatformDriverEvent.SET)
attrs = kwargs.get('attrs', None)
if attrs is None:
raise FSMError('set_attribute_values: missing attrs argument')
try:
result = self.set_attribute_values(attrs)
return None, result
except PlatformConnectionException as e:
return self._connection_lost(PlatformDriverEvent.SET, args, kwargs, e)
def _handler_connected_execute(self, *args, **kwargs):
"""
"""
if log.isEnabledFor(logging.TRACE): # pragma: no cover
log.trace("%r/%s args=%s kwargs=%s" % (
self._platform_id, self.get_driver_state(),
str(args), str(kwargs)))
if len(args) == 0:
raise FSMError('execute_resource: missing resource_cmd argument')
try:
result = self.execute(*args, **kwargs)
return None, result
except PlatformConnectionException as e:
return self._connection_lost(PlatformDriverEvent.EXECUTE, args, kwargs, e)
##############################################################
# Platform driver FSM setup
##############################################################
def _construct_fsm(self, states=PlatformDriverState,
events=PlatformDriverEvent,
enter_event=PlatformDriverEvent.ENTER,
exit_event=PlatformDriverEvent.EXIT):
"""
Constructs the FSM for the driver. The preparations here are mostly
related with the UNCONFIGURED, DISCONNECTED, and CONNECTED state
transitions, with some common handlers for the CONNECTED state.
Subclasses can override to indicate specific parameters and add new
handlers (typically for the CONNECTED state).
"""
log.debug("constructing base platform driver FSM")
self._fsm = ThreadSafeFSM(states, events, enter_event, exit_event)
for state in PlatformDriverState.list():
self._fsm.add_handler(state, enter_event, self._common_state_enter)
self._fsm.add_handler(state, exit_event, self._common_state_exit)
# UNCONFIGURED state event handlers:
self._fsm.add_handler(PlatformDriverState.UNCONFIGURED, PlatformDriverEvent.CONFIGURE, self._handler_unconfigured_configure)
# DISCONNECTED state event handlers:
self._fsm.add_handler(PlatformDriverState.DISCONNECTED, PlatformDriverEvent.CONNECT, self._handler_disconnected_connect)
self._fsm.add_handler(PlatformDr
|
请发表评论