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.5' |
||
18 | |||
19 | plugin = None |
||
20 | |||
21 | |||
22 | def start(config, port_map, aprsis): |
||
23 | global plugin |
||
24 | plugin = StatusPlugin(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() |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
34 | |||
35 | |||
36 | class StatusPlugin(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['status_text'] = config.get(port_section, 'status_text') |
||
51 | port['status_path'] = config.get(port_section, 'status_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 60 seconds |
||
60 | last_trigger = time.time() |
||
61 | while self.running and time.time() - last_trigger < 60: |
||
62 | time.sleep(1) |
||
63 | |||
64 | # run the id every 600 seconds |
||
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 | status_frame = { |
||
73 | 'source': port['identifier'], |
||
74 | 'destination': 'APRS', |
||
75 | 'path': port['status_path'].split(','), |
||
76 | 'text': port['status_text']} |
||
77 | port['tnc'].write(status_frame, port['tnc_port']) |
||
78 | else: |
||
79 | time.sleep(1) |
||
80 |