Exemplo n.º 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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def test_multibyte_address(self):
     self.assertEqual(encode.ui_frame(128, b'123456789'),
                      FLAG + _with_fcs(b'\x00\x03\x03123456789') + FLAG)
Exemplo n.º 4
0
 def test_multibyte(self):
     self.assertEqual(encode.ui_frame(0, b'123456789'),
                      FLAG + _with_fcs(b'\x01\x03123456789') + FLAG)
Exemplo n.º 5
0
 def test_1byte(self):
     self.assertEqual(encode.ui_frame(0, b'A'),
                      FLAG + _with_fcs(b'\x01\x03A') + FLAG)
Exemplo n.º 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)
Exemplo n.º 7
0
 def write_hdlc(data: bytes):
     frame = encode.ui_frame(address, data)
     _LOG.debug('Write %2d B: %s', len(frame), frame)
     writer(frame)