# Path: mlat/geodesy.py
# WGS84_A = 6378137.0
# WGS84_F = 1.0/298.257223563
# WGS84_B = WGS84_A * (1 - WGS84_F)
# WGS84_ECC_SQ = 1 - WGS84_B * WGS84_B / (WGS84_A * WGS84_A)
# WGS84_ECC = math.sqrt(WGS84_ECC_SQ)
# SPHERICAL_R = 6371e3
#     N = WGS84_A / math.sqrt(1 - WGS84_ECC_SQ * math.sin(lat)**2)
# def llh2ecef(llh):
# def ecef2llh(ecef):
# def greatcircle(p0, p1):
# def ecef_distance(p0, p1):
# 
# Path: mlat/profile.py
# def trackcpu(f, **kwargs):
# def dump_cpu_profiles(tofile=None):
# def trackcpu(f, name=None, **kwargs):
#     def cpu_measurement_wrapper(*args, **kwargs):
# def dump_cpu_profiles(tofile=sys.stderr):
# 
# Path: mlat/server/tracker.py
# class TrackedAircraft(object):
# class Tracker(object):
#     def __init__(self, icao, allow_mlat):
#     def interesting(self):
#     def __lt__(self, other):
#     def __init__(self, partition):
#     def in_local_partition(self, icao):
#     def add(self, receiver, icao_set):
#     def remove(self, receiver, icao_set):
#     def remove_all(self, receiver):
#     def update_interest(self, receiver):
# 
# Path: mlat/server/clocksync.py
# class Clock(object):
# class ClockPairing(object):
#     def __init__(self, epoch, freq, max_freq_error, jitter):
# def make_clock(clock_type):
#     def __init__(self, base, peer):
#     def is_new(self, base_ts):
#     def variance(self):
#     def error(self):
#     def valid(self):
#     def update(self, address, base_ts, peer_ts, base_interval, peer_interval):
#     def _prune_old_data(self, latest_base_ts):
#     def _update_drift(self, address, base_interval, peer_interval):
#     def _update_offset(self, address, base_ts, peer_ts, prediction_error):
#     def predict_peer(self, base_ts):
#     def predict_base(self, peer_ts):
#     def __str__(self):
#     KP = 0.05
#     KI = 0.01
# 
# Path: mlat/server/clocktrack.py
# class SyncPoint(object):
# class ClockTracker(object):
#     def __init__(self, address, posA, posB, interval):
#     def __init__(self):
#     def _cleanup(self):
#     def receiver_clock_reset(self, receiver):
#     def receiver_disconnect(self, receiver):
#     def receiver_sync(self, receiver,
#                       even_time, odd_time,
#                       even_message, odd_message):
#     def _add_to_existing_syncpoint(self, syncpoint, r0, t0A, t0B):
#     def _cleanup_syncpoint(self, key, syncpoint):
#     def _do_sync(self, address, posA, posB, r0, t0A, t0B, r1, t1A, t1B):
#     def dump_receiver_state(self, receiver):
# 
# Path: mlat/server/mlattrack.py
# class MessageGroup:
# class MlatTracker(object):
#     def __init__(self, message, first_seen):
#     def __init__(self, coordinator, blacklist_filename=None, pseudorange_filename=None):
#     def read_blacklist(self):
#     def reopen_pseudoranges(self):
#     def receiver_mlat(self, receiver, timestamp, message, utc):
#     def _resolve(self, group):
# def _cluster_timestamps(component, min_receivers):
# 
# Path: mlat/server/util.py
# def fuzzy(t):
# def safe_wait(coros_or_futures, **kwargs):
#     def process(self, msg, kwargs):
# def setproctitle(title):
# class TaggingLogger(logging.LoggerAdapter):


import signal
import asyncio
import json
import logging
import time
from contextlib import closing
from mlat import geodesy, profile, constants
from mlat.server import tracker, clocksync, clocktrack, mlattrack, util

        self._compute_interstation_distances(receiver)

        self.receivers[receiver.uuid] = receiver
        return receiver

    def _compute_interstation_distances(self, receiver):
        """compute inter-station distances for a receiver"""

        for other_receiver in self.receivers.values():
            if other_receiver is receiver:
                distance = 0
            else:
                distance = geodesy.ecef_distance(receiver.position, other_receiver.position)
            receiver.distance[other_receiver] = distance
            other_receiver.distance[receiver] = distance

    @profile.trackcpu
    def receiver_location_update(self, receiver, position_llh):
        """Note that a given receiver has moved."""
        receiver.position_llh = position_llh
        receiver.position = geodesy.llh2ecef(position_llh)

        self._compute_interstation_distances(receiver)

    @profile.trackcpu
    def receiver_disconnect(self, receiver):
        """Notes that the given receiver has disconnected."""

        receiver.dead = True

# Path: mlat/geodesy.py
# WGS84_A = 6378137.0
# WGS84_F = 1.0/298.257223563
# WGS84_B = WGS84_A * (1 - WGS84_F)
# WGS84_ECC_SQ = 1 - WGS84_B * WGS84_B / (WGS84_A * WGS84_A)
# WGS84_ECC = math.sqrt(WGS84_ECC_SQ)
# SPHERICAL_R = 6371e3
#     N = WGS84_A / math.sqrt(1 - WGS84_ECC_SQ * math.sin(lat)**2)
# def llh2ecef(llh):
# def ecef2llh(ecef):
# def greatcircle(p0, p1):
# def ecef_distance(p0, p1):
# 
# Path: mlat/profile.py
# def trackcpu(f, **kwargs):
# def dump_cpu_profiles(tofile=None):
# def trackcpu(f, name=None, **kwargs):
#     def cpu_measurement_wrapper(*args, **kwargs):
# def dump_cpu_profiles(tofile=sys.stderr):
# 
# Path: mlat/server/tracker.py
# class TrackedAircraft(object):
# class Tracker(object):
#     def __init__(self, icao, allow_mlat):
#     def interesting(self):
#     def __lt__(self, other):
#     def __init__(self, partition):
#     def in_local_partition(self, icao):
#     def add(self, receiver, icao_set):
#     def remove(self, receiver, icao_set):
#     def remove_all(self, receiver):
#     def update_interest(self, receiver):
# 
# Path: mlat/server/clocksync.py
# class Clock(object):
# class ClockPairing(object):
#     def __init__(self, epoch, freq, max_freq_error, jitter):
# def make_clock(clock_type):
#     def __init__(self, base, peer):
#     def is_new(self, base_ts):
#     def variance(self):
#     def error(self):
#     def valid(self):
#     def update(self, address, base_ts, peer_ts, base_interval, peer_interval):
#     def _prune_old_data(self, latest_base_ts):
#     def _update_drift(self, address, base_interval, peer_interval):
#     def _update_offset(self, address, base_ts, peer_ts, prediction_error):
#     def predict_peer(self, base_ts):
#     def predict_base(self, peer_ts):
#     def __str__(self):
#     KP = 0.05
#     KI = 0.01
# 
# Path: mlat/server/clocktrack.py
# class SyncPoint(object):
# class ClockTracker(object):
#     def __init__(self, address, posA, posB, interval):
#     def __init__(self):
#     def _cleanup(self):
#     def receiver_clock_reset(self, receiver):
#     def receiver_disconnect(self, receiver):
#     def receiver_sync(self, receiver,
#                       even_time, odd_time,
#                       even_message, odd_message):
#     def _add_to_existing_syncpoint(self, syncpoint, r0, t0A, t0B):
#     def _cleanup_syncpoint(self, key, syncpoint):
#     def _do_sync(self, address, posA, posB, r0, t0A, t0B, r1, t1A, t1B):
#     def dump_receiver_state(self, receiver):
# 
# Path: mlat/server/mlattrack.py
# class MessageGroup:
# class MlatTracker(object):
#     def __init__(self, message, first_seen):
#     def __init__(self, coordinator, blacklist_filename=None, pseudorange_filename=None):
#     def read_blacklist(self):
#     def reopen_pseudoranges(self):
#     def receiver_mlat(self, receiver, timestamp, message, utc):
#     def _resolve(self, group):
# def _cluster_timestamps(component, min_receivers):
# 
# Path: mlat/server/util.py
# def fuzzy(t):
# def safe_wait(coros_or_futures, **kwargs):
#     def process(self, msg, kwargs):
# def setproctitle(title):
# class TaggingLogger(logging.LoggerAdapter):


# Path: mlat/server/coordinator.py
import signal
import asyncio
import json
import logging
import time
from contextlib import closing
from mlat import geodesy, profile, constants
from mlat.server import tracker, clocksync, clocktrack, mlattrack, util


        self._compute_interstation_distances(receiver)

        self.receivers[receiver.uuid] = receiver
        return receiver

    def _compute_interstation_distances(self, receiver):
        """compute inter-station distances for a receiver"""

        for other_receiver in self.receivers.values():
            if other_receiver is receiver:
                distance = 0
            else:
                distance = geodesy.ecef_distance(receiver.position, other_receiver.position)
            receiver.distance[other_receiver] = distance
            other_receiver.distance[receiver] = distance

    @profile.trackcpu
    def receiver_location_update(self, receiver, position_llh):
        """Note that a given receiver has moved."""
        receiver.position_llh = position_llh
        receiver.position = geodesy.llh2ecef(position_llh)

        self._compute_interstation_distances(receiver)

    @profile.trackcpu
    def receiver_disconnect(self, receiver):
        """Notes that the given receiver has disconnected."""

        receiver.dead = True

        self.tracker.remove_all(receiver)