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