Esempio n. 1
0
 def forward_packet(self, writer, packet, raw_packet):
     """Forward packet from client to RFLink."""
     peer = writer.get_extra_info('peername')
     log.debug(' %s:%s: forwarding data: %s', peer[0], peer[1], packet)
     if 'command' in packet:
         packet_id = serialize_packet_id(packet)
         command = packet['command']
         ack = yield from self.protocol.send_command_ack(packet_id, command)
         if ack:
             writer.write("20;00;OK;".encode() + CRLF)
         for _ in range(DEFAULT_SIGNAL_REPETITIONS - 1):
             yield from self.protocol.send_command_ack(packet_id, command)
     else:
         self.protocol.send_raw_packet(raw_packet)
Esempio n. 2
0
def test_packet_parsing(packet, expect):
    """Packet should be broken up into their primitives."""
    result = decode_packet(packet)

    for key, value in expect.items():
        assert result[key] == value

    # make sure each packet is serialized without failure
    packet_id = serialize_packet_id(result)

    # and deserialize it again
    packet_identifiers = deserialize_packet_id(packet_id)

    original = set(result.items())
    transserialized = set(packet_identifiers.items())
    assert transserialized.issubset(original)