Esempio n. 1
0
 def _create_port_agent_packet(self, data_item):
     ts = ntplib.system_to_ntp_time(time.time())
     port_agent_packet = PortAgentPacket()
     port_agent_packet.attach_data(data_item)
     port_agent_packet.attach_timestamp(ts)
     port_agent_packet.pack_header()
     return port_agent_packet
Esempio n. 2
0
 def _create_port_agent_packet(self, data_item):
     ts = ntplib.system_to_ntp_time(time.time())
     port_agent_packet = PortAgentPacket()
     port_agent_packet.attach_data(data_item)
     port_agent_packet.attach_timestamp(ts)
     port_agent_packet.pack_header()
     return port_agent_packet
Esempio n. 3
0
    def send_port_agent_packet(protocol, data):
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        protocol.got_data(port_agent_packet)
        protocol.got_raw(port_agent_packet)
        log.debug('Sent port agent packet containing: %r', data)
    def send_port_agent_packet(protocol, data):
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        protocol.got_data(port_agent_packet)
        protocol.got_raw(port_agent_packet)
        log.debug('Sent port agent packet containing: %r', data)
Esempio n. 5
0
    def test_heat_on_response_with_data(self):
        """
        """
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)
        driver.set_test_mode(True)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        # Now configure the driver with the mock_port_agent, verifying
        # that the driver transitions to that state
        config = {'mock_port_agent': mock_port_agent}
        driver.configure(config=config)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        # Invoke the connect method of the driver: should connect to mock
        # port agent.  Verify that the connection FSM transitions to CONNECTED,
        # (which means that the FSM should now be reporting the ProtocolState).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)
        ts = ntplib.system_to_ntp_time(time.time())

        log.debug("HEAT ON command response: %s", VALID_SAMPLE_01)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(VALID_SAMPLE_01)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)

        log.debug("HEAT ON command response: %s", HEAT_ON_COMMAND_RESPONSE)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(HEAT_ON_COMMAND_RESPONSE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        self.assertTrue(
            driver._protocol._get_response(
                expected_prompt=TEST_HEAT_ON_DURATION_2))
Esempio n. 6
0
    def _send_port_agent_packet(self, driver, data):
        """
        Send a port agent packet via got_data
        @param driver Instrument Driver instance
        @param data data to send
        """
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
    def test_heat_on_response_with_data(self):
        """
        """
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)
        driver.set_test_mode(True)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        # Now configure the driver with the mock_port_agent, verifying
        # that the driver transitions to that state
        config = {'mock_port_agent' : mock_port_agent}
        driver.configure(config = config)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        # Invoke the connect method of the driver: should connect to mock
        # port agent.  Verify that the connection FSM transitions to CONNECTED,
        # (which means that the FSM should now be reporting the ProtocolState).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)
        ts = ntplib.system_to_ntp_time(time.time())

        log.debug("HEAT ON command response: %s", VALID_SAMPLE_01)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(VALID_SAMPLE_01)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)

        log.debug("HEAT ON command response: %s", HEAT_ON_COMMAND_RESPONSE)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(HEAT_ON_COMMAND_RESPONSE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        self.assertTrue(driver._protocol._get_response(expected_prompt = 
                                                       TEST_HEAT_ON_DURATION_2))
Esempio n. 8
0
    def _send_port_agent_packet(self, driver, data):
        """
        Send the supplied data to the driver in a port agent packet
        @param driver: instrument driver instance
        @param data: data to be sent
        """
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
Esempio n. 9
0
    def _send_port_agent_packet(self, driver, data):
        """
        Send the supplied data to the driver in a port agent packet
        @param driver: instrument driver instance
        @param data: data to be sent
        """
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        # sleep briefly, as some state changes happen asynchronously, this should give those
        # threads time to finish
        time.sleep(.01)
Esempio n. 10
0
    def _send_port_agent_packet(self, driver, data):
        """
        Send the supplied data to the driver in a port agent packet
        @param driver: instrument driver instance
        @param data: data to be sent
        """
        ts = ntplib.system_to_ntp_time(time.time())
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(data)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()

        # Push the response into the driver
        driver._protocol.got_data(port_agent_packet)
        # sleep briefly, as some state changes happen asynchronously, this should give those
        # threads time to finish
        time.sleep(.01)
    def test_status_01(self):
        """
        """
        mock_port_agent = Mock(spec=PortAgentClient)
        driver = InstrumentDriver(self._got_data_event_callback)
        driver.set_test_mode(True)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        # Now configure the driver with the mock_port_agent, verifying
        # that the driver transitions to that state
        config = {'mock_port_agent' : mock_port_agent}
        driver.configure(config = config)

        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        # Invoke the connect method of the driver: should connect to mock
        # port agent.  Verify that the connection FSM transitions to CONNECTED,
        # (which means that the FSM should now be reporting the ProtocolState).
        driver.connect()
        current_state = driver.get_resource_state()
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        # Force the instrument into a known state
        self.assert_force_state(driver, DriverProtocolState.COMMAND)
        ts = ntplib.system_to_ntp_time(time.time())

        log.debug("DUMP_STATUS: %s", DUMP_STATUS)
        # Create and populate the port agent packet.
        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data(DUMP_STATUS)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("HEAT,2013/06/19 23:04:37,-001,0000,0026" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("LILY,2013/06/19 23:04:38, -49.455,  34.009,193.91, 26.02,11.96,N9655" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,V,2013/06/19 23:04:38.000,13.987223,25.126694121" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("LILY,2013/06/19 23:04:39, -49.483,  33.959,193.85, 26.03,11.96,N9655" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,V,2013/06/19 23:04:39.000,13.987191,25.126709409" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("LILY,2013/06/19 23:04:40, -49.355,  33.956,193.79, 26.02,11.96,N9655" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,V,2013/06/19 23:04:40.000,13.987253,25.126725854" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("HEAT,2013/06/19 23:04:40,-001,0000,0026" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*APPLIED GEOMECHANICS Model MD900-T Firmware V5.2 SN-N3616 ID01" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,V,2013/06/19 21:46:54.000,13.990480,25.027793612" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        #driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: Vbias= 0.0000 0.0000 0.0000 0.0000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: Vgain= 0.0000 0.0000 0.0000 0.0000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: Vmin:  -2.50  -2.50   2.50   2.50" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: Vmax:   2.50   2.50   2.50   2.50" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: a0=    0.00000    0.00000    0.00000    0.00000    0.00000    0.00000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: a1=    0.00000    0.00000    0.00000    0.00000    0.00000    0.00000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: a2=    0.00000    0.00000    0.00000    0.00000    0.00000    0.00000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:54,*01: a3=    0.00000    0.00000    0.00000    0.00000    0.00000    0.00000" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:55,*01: Tcoef 0: Ks=           0 Kz=           0 Tcal=           0" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:55,*01: Tcoef 1: Ks=           0 Kz=           0 Tcal=           0" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:55,*01: N_SAMP= 460 Xzero=  0.00 Yzero=  0.00" + NEWLINE)
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 21:46:55,*01: TR-PASH-OFF E99-ON  SO-NMEA-SIM XY-EP  9600 baud FV-   " + NEWLINE)   
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)

        port_agent_packet = PortAgentPacket()
        port_agent_packet.attach_data("NANO,2013/06/19 22:04:55,*9900XY-DUMP-SETTINGS" + NEWLINE)   
        port_agent_packet.attach_timestamp(ts)
        port_agent_packet.pack_header()
        driver._protocol.got_data(port_agent_packet)