def test_if_current_time_is_parsed_correctly(self):
        pac = PacketParser(raw_packet=self.raw_mqtt_packet)
        pac.parse_packet()
        target_time = datetime(2020, 12, 15, 13, 32, 30)

        self.assertAlmostEqual(target_time,
                               pac.current_time,
                               delta=timedelta(seconds=1))
    def test_parse_raw_packet(self):
        pac = PacketParser(raw_packet=self.raw_mqtt_packet)
        pac.parse_raw_payload(self.test_raw_payload)

        self.assertEqual(16688, pac.current_alt)
        self.assertEqual(8, pac.num_sats)
        self.assertAlmostEqual(-0.209712, pac.current_long, delta=0.00001)
        self.assertAlmostEqual(51.530170, pac.current_lat, delta=0.00001)
示例#3
0
文件: soquete.py 项目: Laski/tdc
 def receive(self, timeout=None):
     should_stop = False
     if timeout is not None and timeout > 0:
         self.socket.settimeout(timeout)
     else:
         self.socket.settimeout(None)
     while not should_stop:
         packet_bytes, _ = self.socket.recvfrom(self.MAX_SIZE)
         packet = PacketParser().parse_from(packet_bytes)
         if self.is_for_me(packet):
             should_stop = True
     return packet
    def manage_incoming_packet(self, incoming_pkt: str):
        """
        Save a flight prediction from the exact point the balloon was last seen
        :param incoming_pkt:
        :return: None
        """
        # parse packet
        parsed_pkt = PacketParser(
            incoming_pkt
        )  # TODO: figure out how to fake the parsed packet with current time.

        try:
            logging.debug("parsing incoming packet" + str(incoming_pkt))

            parsed_pkt.parse_packet()

        except ValueError:
            logging.exception("Value error")
            return
        except KeyError:
            logging.exception("Not the right type of message")
            return

        # Track only ICSPACE23
        if parsed_pkt.device_id != REQUIRED_DEVICE_ID_TO_TRACK:
            logging.exception("Wrong flight")
            return

        elevation = get_altitude(longitude_deg=parsed_pkt.current_long,
                                 latitude_deg=parsed_pkt.current_lat,
                                 when=parsed_pkt.current_time)
        logging.info("Solar elevation is at {0} degrees.".format(elevation))

        filename = self.pm.gen_filename("prediction_at")
        self.pm.predict_and_save(parsed_pkt.current_time,
                                 parsed_pkt.current_alt,
                                 parsed_pkt.current_long,
                                 parsed_pkt.current_lat, filename)

        self.pp.plot_and_save(data_dump_location / filename)
    def test_if_can_parse_junk_packet(self):
        pac = PacketParser(raw_packet=self.junk_mqtt_packet)

        self.assertRaises(ValueError, pac.parse_packet)
    def test_if_current_device_id_is_parsed_correctly(self):
        pac = PacketParser(raw_packet=self.raw_mqtt_packet)
        pac.parse_packet()

        self.assertEqual("icspace23", pac.device_id)
    def test_if_current_alt_is_parsed_correctly(self):
        pac = PacketParser(raw_packet=self.raw_mqtt_packet)
        pac.parse_packet()

        self.assertAlmostEqual(83, pac.current_alt, delta=0.00001)
    def test_if_current_long_is_parsed_correctly(self):
        pac = PacketParser(raw_packet=self.raw_mqtt_packet)
        pac.parse_packet()

        self.assertAlmostEqual(1.350021004, pac.current_long, delta=0.00001)