当前位置: 首页>>代码示例>>Python>>正文


Python Encoder.encode_payload方法代码示例

本文整理汇总了Python中makerbot_driver.Encoder.encode_payload方法的典型用法代码示例。如果您正苦于以下问题:Python Encoder.encode_payload方法的具体用法?Python Encoder.encode_payload怎么用?Python Encoder.encode_payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在makerbot_driver.Encoder的用法示例。


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

示例1: test_error_reporting

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
 def test_error_reporting(self):
   """Tests that StreamWriter records errors received correctly
   and stores those values in the TransmissionError Thrown.
   """
   expected_errors = [
       'CRCMismatchError',
       'CRCMismatchError',
       'CRCMismatchError',
       'GenericError',
       'GenericError',
       ]
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['CRC_MISMATCH'])
   for i in range(3):
     self.outputstream.write(Encoder.encode_payload(response_payload))
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['GENERIC_PACKET_ERROR'])
   for i in range(2):
     self.outputstream.write(Encoder.encode_payload(response_payload))
   self.outputstream.seek(0)
   payload = 'asdf'
   try:
     self.w.send_command(payload) 
   except errors.TransmissionError as e:
     self.assertEqual(expected_errors, e.value)
开发者ID:ricberw,项目名称:s3g,代码行数:27,代码来源:pi_test_StreamWriter.py

示例2: test_build_and_send_action_payload

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
  def test_build_and_send_action_payload(self):
    command = constants.host_action_command_dict['QUEUE_EXTENDED_POINT_NEW']
    point = [1, 2, 3, 4, 5]
    duration = 42
    relativeAxes = 0
    expected_payload = struct.pack(
      '<BiiiiiIB',
      command,
      point[0], point[1], point[2], point[3], point[4],
      duration,
      relativeAxes
    )

    response_payload = bytearray()
    response_payload.append(constants.response_code_dict['SUCCESS'])
    self.outputstream.write(Encoder.encode_payload(response_payload))
    self.outputstream.seek(0)

    payload = struct.pack(
      '<BiiiiiIB',
      command,
      point[0], point[1], point[2], point[3], point[4],
      duration,
      relativeAxes,
    )
    self.w.send_action_payload(payload)
    self.assertEquals(Encoder.encode_payload(expected_payload), self.inputstream.getvalue())
开发者ID:ricberw,项目名称:s3g,代码行数:29,代码来源:pi_test_StreamWriter.py

示例3: test_send_command

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
  def test_send_command(self):
    """
    Passing case: Preload the buffer with a correctly formatted expected response, and verigy that it works correctly
    """
    payload = 'abcde'

    response_payload = bytearray()
    response_payload.append(constants.response_code_dict['SUCCESS'])
    response_payload.extend('12345')
    self.outputstream.write(Encoder.encode_payload(response_payload))
    self.outputstream.seek(0)

    self.assertEqual(response_payload, self.w.send_command(payload))
    self.assertEqual(Encoder.encode_payload(payload), self.inputstream.getvalue())
开发者ID:ricberw,项目名称:s3g,代码行数:16,代码来源:pi_test_StreamWriter.py

示例4: test_send_packet_timeout

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
  def test_send_packet_timeout(self):
    """
    Time out when no data is received. The input stream should have max_rety_count copies of the
    payload packet in it.
    """
    payload = 'abcde'
    packet = Encoder.encode_payload(payload)
    expected_packet = Encoder.encode_payload(payload)

    self.assertRaises(errors.TransmissionError,self.w.send_packet, packet)

    self.inputstream.seek(0)
    for i in range (0, constants.max_retry_count):
      for byte in expected_packet:
        self.assertEquals(byte, ord(self.inputstream.read(1)))
开发者ID:dgs3,项目名称:s3g,代码行数:17,代码来源:test_StreamWriter.py

示例5: test_send_packet

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
    def test_send_packet(self):
        """
    Passing case: Preload the buffer with a correctly formatted expected response, and
    verify that it works correctly.
    """
        payload = "abcde"
        packet = Encoder.encode_payload(payload)
        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.extend("12345")
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        self.assertEquals(response_payload, self.w.send_packet(packet))
        self.assertEquals(Encoder.encode_payload(payload), self.inputstream.getvalue())
开发者ID:dgs3,项目名称:s3g,代码行数:17,代码来源:pi_test_StreamWriter.py

示例6: test_external_stop_works_precondition

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
 def test_external_stop_works_precondition(self):
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['SUCCESS'])
   self.outputstream.write(Encoder.encode_payload(response_payload))
   self.outputstream.seek(0)
   self.w.set_external_stop()
   self.assertRaises(errors.ExternalStopError, self.w.send_command, 'asdf')
开发者ID:ricberw,项目名称:s3g,代码行数:9,代码来源:pi_test_StreamWriter.py

示例7: test_build_and_send_query_payload

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
    def test_build_and_send_query_payload(self):
        cmd = constants.host_query_command_dict["GET_VERSION"]
        s3gVersion = 123
        botVersion = 456
        expected_payload = struct.pack("<bH", cmd, s3gVersion)

        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.extend(Encoder.encode_uint16(botVersion))
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        payload = struct.pack("<bH", cmd, s3gVersion)

        self.assertEquals(response_payload, self.w.send_query_payload(payload))
        self.assertEquals(Encoder.encode_payload(expected_payload), self.inputstream.getvalue())
开发者ID:dgs3,项目名称:s3g,代码行数:18,代码来源:pi_test_StreamWriter.py

示例8: test_build_and_send_query_payload_with_null_terminated_string

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
    def test_build_and_send_query_payload_with_null_terminated_string(self):
        cmd = constants.host_query_command_dict["GET_NEXT_FILENAME"]
        flag = 0x01
        payload = struct.pack("<BB", cmd, flag)
        filename = "asdf\x00"

        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.append(constants.sd_error_dict["SUCCESS"])
        response_payload.extend(filename)
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        payload = struct.pack("<bb", cmd, flag)
        self.assertEqual(response_payload, self.w.send_query_payload(payload))
        self.assertEqual(Encoder.encode_payload(payload), self.inputstream.getvalue())
开发者ID:dgs3,项目名称:s3g,代码行数:18,代码来源:pi_test_StreamWriter.py

示例9: test_send_packet_many_bad_responses

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
  def test_send_packet_many_bad_responses(self):
    """
    Passing case: test that the transmission can recover from one less than the alloted
    number of errors.
    """
    payload = 'abcde'
    packet = Encoder.encode_payload(payload)
    expected_packet = Encoder.encode_payload(payload)

    response_payload = bytearray()
    response_payload.append(constants.response_code_dict['SUCCESS'])
    response_payload.extend('12345')

    for i in range (0, constants.max_retry_count - 1):
      self.outputstream.write('a')
    self.outputstream.write(Encoder.encode_payload(response_payload))
    self.outputstream.seek(0)

    self.assertEquals(response_payload, self.w.send_packet(packet))

    self.inputstream.seek(0)
    for i in range (0, constants.max_retry_count - 1):
      for byte in expected_packet:
        self.assertEquals(byte, ord(self.inputstream.read(1)))
开发者ID:ricberw,项目名称:s3g,代码行数:26,代码来源:pi_test_StreamWriter.py

示例10: test_packet_crc

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
 def test_packet_crc(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert packet[6] == Encoder.CalculateCRC(payload);
开发者ID:dgs3,项目名称:s3g,代码行数:6,代码来源:pi_test_Packet.py

示例11: test_packet_length_field

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
 def test_packet_length_field(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert packet[1] == len(payload)
开发者ID:dgs3,项目名称:s3g,代码行数:6,代码来源:pi_test_Packet.py

示例12: test_packet_header

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
  def test_packet_header(self):
    payload = 'abcd'
    packet = Encoder.encode_payload(payload)

    assert packet[0] == constants.header
开发者ID:dgs3,项目名称:s3g,代码行数:7,代码来源:pi_test_Packet.py

示例13: test_packet_length

# 需要导入模块: from makerbot_driver import Encoder [as 别名]
# 或者: from makerbot_driver.Encoder import encode_payload [as 别名]
 def test_packet_length(self):
   payload = 'abcd'
   packet = Encoder.encode_payload(payload)
   assert len(packet) == len(payload) + 3
开发者ID:dgs3,项目名称:s3g,代码行数:6,代码来源:pi_test_Packet.py


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