예제 #1
0
 def test_escape(self):
     self.assertEqual(
         encode.ui_frame(0x3e, b'\x7d'),
         FLAG + b'\x7d\x5d\x03\x7d\x5d' + _fcs(b'\x7d\x03\x7d') + FLAG)
     self.assertEqual(
         encode.ui_frame(0x3e, b'A\x7e\x7dBC'),
         FLAG + b'\x7d\x5d\x03A\x7d\x5e\x7d\x5dBC' +
         _fcs(b'\x7d\x03A\x7e\x7dBC') + FLAG)
예제 #2
0
파일: rpc.py 프로젝트: jbampton/pigweed
def channel_output(writer: Callable[[bytes], Any],
                   address: int = DEFAULT_ADDRESS,
                   delay_s: float = 0) -> Callable[[bytes], None]:
    """Returns a function that can be used as a channel output for pw_rpc."""

    if delay_s:

        def slow_write(data: bytes) -> None:
            """Slows down writes in case unbuffered serial is in use."""
            for byte in data:
                time.sleep(delay_s)
                writer(bytes([byte]))

        return lambda data: slow_write(encode.ui_frame(address, data))

    def write_hdlc(data: bytes):
        frame = encode.ui_frame(address, data)
        _LOG.debug('Write %2d B: %s', len(frame), frame)
        writer(frame)

    return write_hdlc
예제 #3
0
 def test_multibyte_address(self):
     self.assertEqual(encode.ui_frame(128, b'123456789'),
                      FLAG + _with_fcs(b'\x00\x03\x03123456789') + FLAG)
예제 #4
0
 def test_multibyte(self):
     self.assertEqual(encode.ui_frame(0, b'123456789'),
                      FLAG + _with_fcs(b'\x01\x03123456789') + FLAG)
예제 #5
0
 def test_1byte(self):
     self.assertEqual(encode.ui_frame(0, b'A'),
                      FLAG + _with_fcs(b'\x01\x03A') + FLAG)
예제 #6
0
 def test_empty(self):
     self.assertEqual(encode.ui_frame(0, b''),
                      FLAG + _with_fcs(b'\x01\x03') + FLAG)
     self.assertEqual(encode.ui_frame(0x1a, b''),
                      FLAG + _with_fcs(b'\x35\x03') + FLAG)
예제 #7
0
파일: rpc.py 프로젝트: jbampton/pigweed
 def write_hdlc(data: bytes):
     frame = encode.ui_frame(address, data)
     _LOG.debug('Write %2d B: %s', len(frame), frame)
     writer(frame)