def test_parse_packet(self): addr, data = parse_lora_packet(b'4|alive\r\n') self.assertEqual(addr, [4]) self.assertEqual(data, b'alive') addr, data = parse_lora_packet(b'4|1|2|pose(1, 2, 3)\r\n') self.assertEqual(addr, [4, 1, 2]) self.assertEqual(data, b'pose(1, 2, 3)')
def test_3rd_party_packet(self): # there are internal debug messages and also 3rd party packets, which we definetely # do not want to re-transmmit and process # In particular there was a bug that missing '|' generated empty addr list self.assertIsNone(parse_lora_packet(b'dhcps: send_off')[0]) self.assertIsNone(parse_lora_packet(b'0|data')[0]) self.assertIsNone(parse_lora_packet(b'7|data')[0]) self.assertIsNone(parse_lora_packet(b'42|data')[0]) # validate all addresses in chain self.assertIsNone(parse_lora_packet(b'4|7|data')[0])
def test_invalid_packet(self): addr, data = parse_lora_packet(b'|pose(1, 2, 3)\r\n') self.assertIsNone(addr) self.assertEqual(data, b'|pose(1, 2, 3)\r\n')