Ejemplo n.º 1
0
def test_dump1090_stream() -> None:
    decoder = ModeS_Decoder.from_dump1090("LFBO")
    time.sleep(15)
    decoder.stop()

    t = decoder.traffic

    assert t is not None
    assert len(t) != 0
Ejemplo n.º 2
0
def test_dump1090_bin():
    filename = Path(__file__).parent.parent / "data" / "sample_dump1090.bin"

    time_0 = pd.Timestamp("2020-02-12 10:07Z")
    decoder = ModeS_Decoder.from_binary(
        filename, "LFBO", time_fmt="dump1090", time_0=time_0
    )
    t = decoder.traffic

    assert len(t) != 0
Ejemplo n.º 3
0
    def openDump1090(self) -> None:
        reference, ok = QInputDialog.getText(self, "dump1090 reference",
                                             "Reference airport:")

        if ok:
            self.open_dropdown.setItemText(1, f"dump1090 ({reference})")
            self.decoder = ModeS_Decoder.from_dump1090(reference)
            refresh_time = config.getint("decoders",
                                         "refresh_time",
                                         fallback=30)
            self.updateTraffic = UpdateTraffic(self, refresh_time)
            self.updateTraffic.start()
Ejemplo n.º 4
0
 def on_open(self, index: int, *args, **kwargs) -> None:
     if self.decoder is not None and self.updateTraffic is not None:
         self.updateTraffic.terminate()
         self.decoder.stop()
     if index == 0:
         self.openFile()
     elif index == 1:
         self.openDump1090()
     else:
         address = config.get("decoders", self.open_options[index])
         host_port, reference = address.split("/")
         host, port = host_port.split(":")
         self.decoder = ModeS_Decoder.from_address(host, int(port),
                                                   reference)
         refresh_time = config.getint("decoders",
                                      "refresh_time",
                                      fallback=30)
         self.updateTraffic = UpdateTraffic(self, refresh_time)
         self.updateTraffic.start()
Ejemplo n.º 5
0
def main(args_list: List[str]) -> None:

    parser = argparse.ArgumentParser(
        prog="traffic dump", description=description
    )
    parser.add_argument(
        "-o",
        "--output",
        dest="output",
        type=Path,
        default="output.pkl",
        help="destination file (default: output.pkl)",
    )
    parser.add_argument(
        "-v",
        dest="verbose",
        action="count",
        default=0,
        help="display logging messages",
    )
    parser.add_argument(
        "reference", help="configuration name or IATA/ICAO code for dump1090"
    )

    args = parser.parse_args(args_list)

    logger = logging.getLogger()
    if args.verbose == 1:
        logger.setLevel(logging.INFO)
    elif args.verbose >= 2:
        logger.setLevel(logging.DEBUG)

    from traffic import config
    from traffic.data import ModeS_Decoder

    now = datetime.now(timezone.utc)
    filename = Path(now.strftime(args.output.as_posix()))

    try:
        address = config.get("decoders", args.reference)
        host_port, reference = address.split("/")
        host, port = host_port.split(":")
        decoder = ModeS_Decoder.from_address(
            host, int(port), reference, filename.with_suffix(".csv").as_posix()
        )
    except Exception:
        logging.info("fallback to dump1090")
        decoder = ModeS_Decoder.from_dump1090(
            args.reference, filename.with_suffix(".csv").as_posix()
        )

    def signal_handler(sig: Any, frame: Any) -> NoReturn:
        logging.info("Interruption signal caught")
        t = decoder.traffic
        if t is not None:
            pkl_file = filename.with_suffix(".pkl")
            t.to_pickle(os.path.expanduser(pkl_file))
            logging.info(f"Traffic saved to {pkl_file}")
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler)
    logging.info("Press Ctrl+C to quit")

    while True:
        continue