1
|
|
|
##!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
# These imports are for python3 compatability inside python2 |
5
|
|
|
from __future__ import absolute_import |
6
|
|
|
from __future__ import division |
7
|
|
|
from __future__ import print_function |
8
|
|
|
|
9
|
|
|
import time |
10
|
|
|
|
11
|
|
|
__author__ = 'Jeffrey Phillips Freeman (WI2ARD)' |
12
|
|
|
__maintainer__ = 'Jeffrey Phillips Freeman (WI2ARD)' |
13
|
|
|
__email__ = '[email protected]' |
14
|
|
|
__license__ = 'Apache License, Version 2.0' |
15
|
|
|
__copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' |
16
|
|
|
__credits__ = [] |
17
|
|
|
__version__ = '0.0.4' |
18
|
|
|
|
19
|
|
|
plugin = None |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
def start(config, port_map, aprsis): |
23
|
|
|
global plugin |
24
|
|
|
plugin = IdPlugin(config, port_map, aprsis) |
25
|
|
|
plugin.run() |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def handle_packet(frame, recv_port, recv_port_name): |
29
|
|
|
return |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
def stop(): |
33
|
|
View Code Duplication |
plugin.stop() |
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
class IdPlugin(object): |
37
|
|
|
|
38
|
|
|
def __init__(self, config, port_map, aprsis): |
39
|
|
|
self.port_map = port_map |
40
|
|
|
self.aprsis = aprsis |
41
|
|
|
self.running = False |
42
|
|
|
|
43
|
|
|
for section in config.sections(): |
44
|
|
|
if section.startswith('TNC '): |
45
|
|
|
tnc_name = section.split(' ')[1] |
46
|
|
|
for port_id in range(1, 1+int(config.get(section, 'port_count'))): |
47
|
|
|
port_name = tnc_name + '-' + str(port_id) |
48
|
|
|
port = port_map[port_name] |
49
|
|
|
port_section = 'PORT ' + port_name |
50
|
|
|
port['id_text'] = config.get(port_section, 'id_text') |
51
|
|
|
port['id_path'] = config.get(port_section, 'id_path') |
52
|
|
|
|
53
|
|
|
def stop(self): |
54
|
|
|
self.running = False |
55
|
|
|
|
56
|
|
|
def run(self): |
57
|
|
|
self.running = True |
58
|
|
|
|
59
|
|
|
# Don't do anything in the first 30 seconds |
60
|
|
|
last_trigger = time.time() |
61
|
|
|
while self.running and time.time() - last_trigger < 30: |
62
|
|
|
time.sleep(1) |
63
|
|
|
|
64
|
|
|
# run every 600 second |
65
|
|
|
last_trigger = time.time() |
66
|
|
|
while self.running: |
67
|
|
|
if time.time() - last_trigger >= 600: |
68
|
|
|
last_trigger = time.time() |
69
|
|
|
for port_name in self.port_map.keys(): |
70
|
|
|
port = self.port_map[port_name] |
71
|
|
|
|
72
|
|
|
id_frame = {'source': port['identifier'], 'destination': 'ID', 'path': port['id_path'].split(','), |
73
|
|
|
'text': port['id_text']} |
74
|
|
|
port['tnc'].write(id_frame, port['tnc_port']) |
75
|
|
|
else: |
76
|
|
|
time.sleep(1) |
77
|
|
|
|