# 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/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/net.py
# class MonitoringListener(object):
# class MonitoringConnector(object):
#     def __init__(self, host, port, factory, logger=glogger, description=None):
#     def start(self):
#     def _start(self):
#     def _new_client(self, r, w):
#     def _close(self):
#     def start_client(self, r, w):
#     def monitor_client(self, client):
#     def close(self):
#     def wait_closed(self):
#     def __init__(self, host, port, reconnect_interval, factory):
#     def start(self):
#     def reconnect(self):
#     def close(self):
#     def wait_closed(self):


import asyncio
import logging
import time
import math
import functools
import socket
import numpy
from mlat import constants, geodesy
from mlat.server import util, net
        peer = writer.get_extra_info('peername')
        self.host = peer[0]
        self.port = peer[1]
        self.logger = util.TaggingLogger(logging.getLogger("basestation"),
                                         {'tag': '{host}:{port}'.format(host=self.host,
                                                                        port=self.port)})
        self.reader = reader
        self.writer = writer
        self.coordinator = coordinator
        self.use_kalman_data = use_kalman_data
        self.heartbeat_interval = heartbeat_interval
        self.last_output = time.monotonic()
        self.heartbeat_task = asyncio.async(self.send_heartbeats())
        self.reader_task = asyncio.async(self.read_until_eof())

        self.logger.info("Connection established")
        self.coordinator.add_output_handler(self.write_result)

    def close(self):
        if not self.writer:
            return  # already closed

        self.logger.info("Connection lost")
        self.coordinator.remove_output_handler(self.write_result)
        self.heartbeat_task.cancel()
        self.writer.close()
        self.writer = None

    @asyncio.coroutine
    def wait_closed(self):

# 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/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/net.py
# class MonitoringListener(object):
# class MonitoringConnector(object):
#     def __init__(self, host, port, factory, logger=glogger, description=None):
#     def start(self):
#     def _start(self):
#     def _new_client(self, r, w):
#     def _close(self):
#     def start_client(self, r, w):
#     def monitor_client(self, client):
#     def close(self):
#     def wait_closed(self):
#     def __init__(self, host, port, reconnect_interval, factory):
#     def start(self):
#     def reconnect(self):
#     def close(self):
#     def wait_closed(self):


# Path: mlat/server/output.py
import asyncio
import logging
import time
import math
import functools
import socket
import numpy
from mlat import constants, geodesy
from mlat.server import util, net

        peer = writer.get_extra_info('peername')
        self.host = peer[0]
        self.port = peer[1]
        self.logger = util.TaggingLogger(logging.getLogger("basestation"),
                                         {'tag': '{host}:{port}'.format(host=self.host,
                                                                        port=self.port)})
        self.reader = reader
        self.writer = writer
        self.coordinator = coordinator
        self.use_kalman_data = use_kalman_data
        self.heartbeat_interval = heartbeat_interval
        self.last_output = time.monotonic()
        self.heartbeat_task = asyncio.async(self.send_heartbeats())
        self.reader_task = asyncio.async(self.read_until_eof())

        self.logger.info("Connection established")
        self.coordinator.add_output_handler(self.write_result)

    def close(self):
        if not self.writer:
            return  # already closed

        self.logger.info("Connection lost")
        self.coordinator.remove_output_handler(self.write_result)
        self.heartbeat_task.cancel()
        self.writer.close()
        self.writer = None

    @asyncio.coroutine
    def wait_closed(self):

        yield from util.safe_wait([self.heartbeat_task, self.reader_task])