2015-11-30 14:03:38 +00:00
|
|
|
import logging
|
2015-11-19 22:17:12 +00:00
|
|
|
|
2015-11-29 20:59:34 +00:00
|
|
|
from ogn.gateway.client import ognGateway
|
2016-01-29 04:25:35 +00:00
|
|
|
from ogn.commands.dbutils import session
|
2015-11-15 08:10:46 +00:00
|
|
|
|
|
|
|
from manager import Manager
|
2016-01-28 19:29:08 +00:00
|
|
|
|
2015-11-15 08:10:46 +00:00
|
|
|
manager = Manager()
|
|
|
|
|
2015-11-30 14:03:38 +00:00
|
|
|
logging_formatstr = '%(asctime)s - %(levelname).4s - %(name)s - %(message)s'
|
|
|
|
log_levels = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']
|
2015-11-29 20:51:23 +00:00
|
|
|
|
2015-11-15 11:10:20 +00:00
|
|
|
|
2015-11-15 08:10:46 +00:00
|
|
|
@manager.command
|
2015-11-30 14:03:38 +00:00
|
|
|
def run(aprs_user='anon-dev', logfile='main.log', loglevel='INFO'):
|
2015-11-15 08:10:46 +00:00
|
|
|
"""Run the aprs client."""
|
2015-11-29 20:51:23 +00:00
|
|
|
|
2015-11-30 14:03:38 +00:00
|
|
|
# User input validation
|
2015-11-22 20:11:55 +00:00
|
|
|
if len(aprs_user) < 3 or len(aprs_user) > 9:
|
2015-11-30 14:03:38 +00:00
|
|
|
print('aprs_user must be a string of 3-9 characters.')
|
2015-11-22 20:11:55 +00:00
|
|
|
return
|
2015-11-30 14:03:38 +00:00
|
|
|
if loglevel not in log_levels:
|
|
|
|
print('loglevel must be an element of {}.'.format(log_levels))
|
|
|
|
return
|
|
|
|
|
|
|
|
# Enable logging
|
|
|
|
log_handlers = [logging.StreamHandler()]
|
|
|
|
if logfile:
|
|
|
|
log_handlers.append(logging.FileHandler(logfile))
|
|
|
|
logging.basicConfig(format=logging_formatstr, level=loglevel, handlers=log_handlers)
|
|
|
|
|
2015-11-30 14:11:10 +00:00
|
|
|
print('Start ogn gateway')
|
|
|
|
gateway = ognGateway(aprs_user)
|
|
|
|
gateway.connect()
|
|
|
|
|
|
|
|
def process_beacon(beacon):
|
|
|
|
session.add(beacon)
|
|
|
|
session.commit()
|
|
|
|
|
|
|
|
try:
|
|
|
|
gateway.run(callback=process_beacon, autoreconnect=True)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('\nStop ogn gateway')
|
|
|
|
|
|
|
|
gateway.disconnect()
|
|
|
|
logging.shutdown()
|