2019-09-12 20:53:42 +00:00
|
|
|
from flask import current_app
|
2019-02-25 19:00:51 +00:00
|
|
|
from flask.cli import AppGroup
|
|
|
|
import click
|
|
|
|
|
|
|
|
from ogn.client import AprsClient
|
2019-08-31 08:14:41 +00:00
|
|
|
from app.gateway.bulkimport import ContinuousDbFeeder
|
2019-02-25 19:00:51 +00:00
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
user_cli = AppGroup("gateway")
|
2019-02-25 19:00:51 +00:00
|
|
|
user_cli.help = "Connection to APRS servers."
|
|
|
|
|
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
@user_cli.command("run")
|
|
|
|
def run(aprs_user="anon-dev"):
|
2019-02-25 19:00:51 +00:00
|
|
|
"""Run the aprs client."""
|
|
|
|
|
2019-03-04 21:14:13 +00:00
|
|
|
saver = ContinuousDbFeeder()
|
2019-02-25 19:00:51 +00:00
|
|
|
|
|
|
|
# User input validation
|
|
|
|
if len(aprs_user) < 3 or len(aprs_user) > 9:
|
2019-08-31 08:14:41 +00:00
|
|
|
print("aprs_user must be a string of 3-9 characters.")
|
2019-02-25 19:00:51 +00:00
|
|
|
return
|
|
|
|
|
2019-09-12 20:53:42 +00:00
|
|
|
current_app.logger.warning("Start ogn gateway")
|
2019-02-25 19:00:51 +00:00
|
|
|
client = AprsClient(aprs_user)
|
|
|
|
client.connect()
|
|
|
|
|
|
|
|
try:
|
2019-03-04 21:14:13 +00:00
|
|
|
client.run(callback=saver.add, autoreconnect=True)
|
2019-02-25 19:00:51 +00:00
|
|
|
except KeyboardInterrupt:
|
2019-09-12 20:53:42 +00:00
|
|
|
current_app.logger.warning("\nStop ogn gateway")
|
2019-02-25 19:00:51 +00:00
|
|
|
|
|
|
|
saver.flush()
|
|
|
|
client.disconnect()
|