Example #1
0
    def __init__(self):
        # Logging
        logging.basicConfig(filename=self.log_file, level=self.log_level, filemode='w',
                            format='%(asctime)s %(levelname)s: %(message)s')

        self.logger = logging.getLogger("coreemu_feed")

        self.session_id = core_utils.get_session_id()
        self.node_name = core_utils.get_node_name()
        self.nem_id = core_utils.get_nem_id(node_name=self.node_name, session_id=self.session_id)
        self.node_number = core_utils.get_node_number(node_name=self.node_name, session_id=self.session_id)

        self.db = None # MySQLdb.connect(self.tracksrv_dbhost, self.tracksrv_dbuser, self.tracksrv_dbpass, self.tracksrv_dbname)

        self._init_transponder()
Example #2
0
    def __init__(self, config="adsbin.cfg", store_msgs=False):
        # Logging
        logging.basicConfig(filename=self.log_file,
                            level=self.log_level,
                            filemode='w',
                            format='%(asctime)s %(levelname)s: %(message)s')

        self.store_rec_msgs = store_msgs

        # List of destination to which received messages will be forwarded to.
        self.forwarders = []

        # Id
        self.id = None

        # DB connection with general purposes
        self.db = MySQLdb.connect(self.db_host, self.db_user, self.db_pass,
                                  self.db_name)

        if os.path.exists(config):
            conf = ConfigParser.ConfigParser()
            conf.read(config)

            self.id = conf.get("General", "id")

            # Reading destinations to forward received messages
            for dst in conf.get("General", "destinations").split():
                items = conf.items(dst)
                d = {}

                for i in items:
                    d[i[0]] = i[1]

                if d["type"] == "dump1090":
                    f = Dump1090Forwarder(items=d)
                    f.set_timeout(0.5)
                    self.forwarders.append(f)
                elif d["type"] == "database":
                    f = DatabseForwarder(sensor_id=self.id, items=d)
                    self.forwarders.append(f)
                elif d["type"] == "asterix":
                    # Enable Asterix Server
                    self.asterix_server = True

                    # Asterix parameters
                    self.asterix_sic = int(d["sic"])
                    self.asterix_rx_port = 15000
                    self.asterix_tx_port = int(d["port"])
                    self.asterix_dst = d["server"]

                    # Forwards to local Asterix Server, which is listening on localhost:15000
                    d["server"] = "127.0.0.1"
                    d["port"] = self.asterix_rx_port

                    # Create forwarder
                    f = AsterixForwarder(items=d)
                    self.forwarders.append(f)
        else:
            self.id = core_utils.get_node_name()

        # Discover self location
        cursor = self.db.cursor()
        cursor.execute(
            "SELECT B.id from node A, nem B where A.id=B.node_id and A.name='%s'"
            % self.id)
        result = cursor.fetchone()

        if result is not None:
            self.nemid = int(result[0])

            location = emane_utils.get_nem_location(self.nemid)

            self.latitude = location['latitude']
            self.longitude = location['longitude']
            self.altitude = location['altitude']
Example #3
0
import time

from atn import core_utils

node_name = core_utils.get_node_name()
session_id = core_utils.get_session_id()

t = time.time()
print "NEM ID (1): %d (%f s)" % (core_utils.get_nem_id(), time.time() - t)
t = time.time()
print "NEM ID (2): %d (%f s)" % (core_utils.get_nem_id(node_name=node_name),
                                 time.time() - t)
t = time.time()
print "NEM ID (3): %d (%f s)" % (core_utils.get_nem_id(session_id=session_id),
                                 time.time() - t)
t = time.time()
print "NEM ID (4): %d (%f s)" % (core_utils.get_nem_id(
    node_name=node_name, session_id=session_id), time.time() - t)

t = time.time()
print "NODE ID (1): %d (%f s)" % (core_utils.get_node_number(),
                                  time.time() - t)
t = time.time()
print "NODE ID (2): %d (%f s)" % (core_utils.get_node_number(
    node_name=node_name), time.time() - t)
t = time.time()
print "NODE ID (3): %d (%f s)" % (core_utils.get_node_number(
    session_id=session_id), time.time() - t)
t = time.time()
print "NODE ID (4): %d (%f s)" % (core_utils.get_node_number(
    node_name=node_name, session_id=session_id), time.time() - t)