• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python instrument_protocol.CommandResponseInstrumentProtocol类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol的典型用法代码示例。如果您正苦于以下问题:Python CommandResponseInstrumentProtocol类的具体用法?Python CommandResponseInstrumentProtocol怎么用?Python CommandResponseInstrumentProtocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CommandResponseInstrumentProtocol类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: got_data

 def got_data(self, data):
     """
     Callback for receiving new data from the device.
     """
     if self.get_current_state() == ProtocolStates.DIRECT_ACCESS:
         # direct access mode
         if len(data) > 0:
             log.debug("mavs4InstrumentProtocol._got_data(): <" + data + ">") 
             if self._driver_event:
                 self._driver_event(DriverAsyncEvent.DIRECT_ACCESS, data)
                 # TODO: what about logging this as an event?
         return
     
     if len(data)>0:
         # Call the superclass to update line and prompt buffers.
         CommandResponseInstrumentProtocol.got_data(self, data)
 
         # If in streaming mode, process the buffer for samples to publish.
         cur_state = self.get_current_state()
         if cur_state == ProtocolStates.AUTOSAMPLE:
             if INSTRUMENT_NEWLINE in self._linebuf:
                 lines = self._linebuf.split(INSTRUMENT_NEWLINE)
                 self._linebuf = lines[-1]
                 for line in lines:
                     self._extract_sample(line)                    
开发者ID:newbrough,项目名称:marine-integrations,代码行数:25,代码来源:driver.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.
        """
        CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event)

        self._protocol_fsm = InstrumentFSM(ProtocolState,
                                           ProtocolEvent,
                                           ProtocolEvent.ENTER,
                                           ProtocolEvent.EXIT)

        handlers = {
            ProtocolState.UNKNOWN: [
                (ProtocolEvent.ENTER, self._handler_unknown_enter),
                (ProtocolEvent.EXIT, self._handler_unknown_exit)
            ],
        }

        for state in handlers:
            for event, handler in handlers[state]:
                self._protocol_fsm.add_handler(state, event, handler)

        # State state machine in UNKNOWN state.
        self._protocol_fsm.start(ProtocolState.UNKNOWN)

        # create chunker for processing instrument samples.
        self._chunker = StringChunker(self.sieve_function)
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:30,代码来源:driver.py


示例3: got_data

 def got_data(self, data):
     """
     Callback for receiving new data from the device.
     """
     if self.get_current_state() == SBE37ProtocolState.DIRECT_ACCESS:
         # direct access mode
         if len(data) > 0:
             #mi_logger.debug("SBE37Protocol._got_data(): <" + data + ">") 
             # check for echoed commands from instrument (TODO: this should only be done for telnet?)
             if len(self._sent_cmds) > 0:
                 # there are sent commands that need to have there echoes filtered out
                 oldest_sent_cmd = self._sent_cmds[0]
                 if string.count(data, oldest_sent_cmd) > 0:
                     # found a command echo, so remove it from data and delete the command form list
                     data = string.replace(data, oldest_sent_cmd, "", 1) 
                     self._sent_cmds.pop(0)            
             if len(data) > 0 and self._driver_event:
                 self._driver_event(DriverAsyncEvent.DIRECT_ACCESS, data)
                 # TODO: what about logging this as an event?
         return
     
     if len(data)>0:
         # Call the superclass to update line and prompt buffers.
         CommandResponseInstrumentProtocol.got_data(self, data)
 
         # If in streaming mode, process the buffer for samples to publish.
         cur_state = self.get_current_state()
         if cur_state == SBE37ProtocolState.AUTOSAMPLE:
             if SBE37_NEWLINE in self._linebuf:
                 lines = self._linebuf.split(SBE37_NEWLINE)
                 self._linebuf = lines[-1]
                 for line in lines:
                     self._extract_sample(line)                    
开发者ID:newbrough,项目名称:marine-integrations,代码行数:33,代码来源:driver.py


示例4: __init__

 def __init__(self, prompts, newline, driver_event):
     """
     Protocol constructor.
     @param prompts A BaseEnum class containing instrument prompts.
     @param newline The sbe26plus newline.
     @param driver_event Driver process event callback.
     """
     # Construct protocol superclass.
     CommandResponseInstrumentProtocol.__init__(self, prompts, newline, driver_event)
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:9,代码来源:driver.py


示例5: __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 = 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.UNKNOWN, ProtocolEvent.START_DIRECT, self._handler_command_start_direct)

        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.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_autosample_start)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.INIT_PARAMS, self._handler_command_init_params)

        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)

        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.

        # Add response handlers for device commands.

        # 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(Protocol.sieve_function)

        self._payload_cache = {}
开发者ID:cwingard,项目名称:mi-instrument,代码行数:56,代码来源: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 = 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.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.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.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_start_autosample)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.HEAT_ON, self._handler_command_heat_on)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND, ProtocolEvent.HEAT_OFF, self._handler_command_heat_off)

        # 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(InstrumentCommand.HEAT_ON, self._build_heat_on_command)
        self._add_build_handler(InstrumentCommand.HEAT_OFF, self._build_heat_off_command)

        # Add response handlers for device commands.
        self._add_response_handler(InstrumentCommand.HEAT_ON, self._parse_heat_on_off_resp)
        self._add_response_handler(InstrumentCommand.HEAT_OFF, self._parse_heat_on_off_resp)

        # 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(Protocol.sieve_function)

        self._heat_duration = DEFAULT_HEAT_DURATION
开发者ID:StevenMyerson,项目名称:marine-integrations,代码行数:55,代码来源: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.
        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


示例8: __init__

    def __init__(self, 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, None, None, driver_event)

        # create chunker for processing instrument samples.
        self._chunker = StringChunker(self.sieve_function)
开发者ID:oceanobservatories,项目名称:mi-instrument,代码行数:11,代码来源: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.
        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


示例10: got_data

    def got_data(self, data):
        """
        Callback for receiving new data from the device.
        """
        # Call the superclass to update line and promp buffers.
        CommandResponseInstrumentProtocol.got_data(self, data)

        # If in streaming mode, process the buffer for samples to publish.
        cur_state = self.get_current_state()
        if cur_state == SBE16ProtocolState.AUTOSAMPLE:
            if SBE16_NEWLINE in self._linebuf:
                lines = self._linebuf.split(SBE16_NEWLINE)
                self._linebuf = lines[-1]
                for line in lines:
                    self._extract_sample(line)                    
开发者ID:tgiguere,项目名称:marine-integrations,代码行数:15,代码来源: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.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


示例12: 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


示例13: _got_data

 def _got_data(self, data):
     """ The comms object fires this when data is received
     
     @param data The chunk of data that was received
     """
     CommandResponseInstrumentProtocol._got_data(self, data)
     
     # If we are streaming, process the line buffer for samples, but it
     # could have header stuff come out if you just got a break!
     if self._protocol_fsm.get_current_state() == PARProtocolState.AUTOSAMPLE_MODE:
         if self.eoln in self._linebuf:
             lines = self._linebuf.split(self.eoln)
             for line in lines:
                 if sample_regex.match(line):
                     self._last_data_timestamp = time.time()
                     self._driver_event(DriverAsyncEvent.SAMPLE, line)
                     self._linebuf = self._linebuf.replace(line+self.eoln, "") # been processed
开发者ID:newbrough,项目名称:marine-integrations,代码行数:17,代码来源:driver.py


示例14: test_get_prompts

    def test_get_prompts(self):
        """
        ensure prompts are returned sorted by length
        """
        prompts = ['aa', 'bbb', 'c', 'dddd']
        expected = ['dddd', 'bbb', 'aa', 'c']
        class Prompts(BaseEnum):
            A = 'aa'
            B = 'bbb'
            C = 'c'
            D = 'dddd'

        self.protocol = CommandResponseInstrumentProtocol(prompts, '\r\n', self.event_callback)
        self.assertEqual(self.protocol._get_prompts(), expected)

        self.protocol = CommandResponseInstrumentProtocol(Prompts, '\r\n', self.event_callback)
        self.assertEqual(self.protocol._get_prompts(), expected)
开发者ID:aplmmilcic,项目名称:mi-instrument,代码行数:17,代码来源:test_instrument_protocol.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.
        """
        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()
        self._cmd_dict.add(Capability.DISCOVER, display_name='Discover')
开发者ID:r-swilderd,项目名称:mi-instrument,代码行数:44,代码来源:driver.py


示例16: __init__

    def __init__(self, callback=None):
        CommandResponseInstrumentProtocol.__init__(self, Prompt, EOLN, callback)

        # TODO probably promote this convenience to super-class?
        # _timeout: Default timeout value for operations accepting an
        # optional timeout argument
        self._timeout = 30

        self._last_data_timestamp = None
        self.eoln = EOLN

        self._protocol_fsm = InstrumentFSM(ProtocolState, ProtocolEvent,
                                           None, None)

        # UNKNOWN
        self._protocol_fsm.add_handler(ProtocolState.UNKNOWN,
                                       ProtocolEvent.INITIALIZE,
                                       self._handler_initialize)

        # COMMAND_MODE
        self._protocol_fsm.add_handler(ProtocolState.COMMAND_MODE,
                                       ProtocolEvent.GET_LAST_ENSEMBLE,
                                       self._handler_command_get_latest_sample)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND_MODE,
                                       ProtocolEvent.GET_METADATA,
                                       self._handler_command_get_metadata)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND_MODE,
                                       ProtocolEvent.RUN_RECORDER_TESTS,
                                       self._handler_command_run_recorder_tests)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND_MODE,
                                       ProtocolEvent.RUN_ALL_TESTS,
                                       self._handler_command_run_all_tests)
        self._protocol_fsm.add_handler(ProtocolState.COMMAND_MODE,
                                       ProtocolEvent.START_AUTOSAMPLE,
                                       self._handler_command_autosample)

        # AUTOSAMPLE_MODE
        self._protocol_fsm.add_handler(ProtocolState.AUTOSAMPLE_MODE,
                                       ProtocolEvent.STOP_AUTOSAMPLE,
                                       self._handler_autosample_stop)

        self._protocol_fsm.start(ProtocolState.UNKNOWN)
开发者ID:newbrough,项目名称:marine-integrations,代码行数:42,代码来源:driver.py


示例17: __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


示例18: got_data

    def got_data(self, paPacket):
        """
        Callback for receiving new data from the device.
        """
        length = paPacket.get_data_size()
        data = paPacket.get_data()
        tempLength = len(data)

        if length > 0:
            
            # Call the superclass to update line and prompt buffers.
            CommandResponseInstrumentProtocol.got_data(self, data)

            # If in streaming mode, process the buffer for samples to publish.
            cur_state = self.get_current_state()
            if cur_state == SBE16ProtocolState.AUTOSAMPLE:
                if SBE16_NEWLINE in self._linebuf:
                    lines = self._linebuf.split(SBE16_NEWLINE)
                    self._linebuf = lines[-1]
                    for line in lines:
                        sample = self._extract_sample(SBE16DataParticle, SAMPLE_REGEX,
                                             line)
开发者ID:swarbhanu,项目名称:marine-integrations,代码行数:22,代码来源:driver.py


示例19: got_data

    def got_data(self, paPacket):
        """ 
        Callback for receiving new data from the device.
        The port agent object fires this when data is received
        @param paPacket The packet of data that was received
        """
        paLength = paPacket.get_data_size()
        paData = paPacket.get_data()

        if self.get_current_state() == PARProtocolState.DIRECT_ACCESS:
            # direct access mode
            if paLength > 0:
                log.debug("SatlanticPARInstrumentProtocol.got_data(): <" + paData + ">")
                if self._driver_event:
                    self._driver_event(DriverAsyncEvent.DIRECT_ACCESS, paData)
                    # TODO: what about logging this as an event?
            return

        if paLength > 0:
            CommandResponseInstrumentProtocol.got_data(self, paData)

            # If we are streaming, process the line buffer for samples, but it
            # could have header stuff come out if you just got a break!
            if (
                self._protocol_fsm.get_current_state() == PARProtocolState.AUTOSAMPLE
                or self._protocol_fsm.get_current_state() == PARProtocolState.POLL
            ):
                if self.eoln in self._linebuf:
                    lines = self._linebuf.split(self.eoln)
                    for line in lines:
                        if SAMPLE_REGEX.match(line):
                            self._last_data_timestamp = time.time()

                            # construct and publish data particles
                            self._extract_sample(SatlanticPARDataParticle, SAMPLE_REGEX, line)

                            self._linebuf = self._linebuf.replace(line + self.eoln, "")  # been processed
开发者ID:swarbhanu,项目名称:marine-integrations,代码行数:37,代码来源:driver.py


示例20: __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



注:本文中的mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python port_agent_client.PortAgentClient类代码示例发布时间:2022-05-27
下一篇:
Python instrument_fsm.ThreadSafeFSM类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap