From 88a791ee7ba523cea03bdb39aed40073d5015fb8 Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Thu, 24 Dec 2020 11:36:38 -0800 Subject: [PATCH] improve APRS per master config --- bridge.py | 4 +++- bridge_all.py | 4 +++- config.py | 2 +- hblink-SAMPLE.cfg | 2 +- hblink.py | 28 +++++++++++++++------------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bridge.py b/bridge.py index 93babb8..de52fa1 100755 --- a/bridge.py +++ b/bridge.py @@ -42,7 +42,7 @@ from twisted.protocols.basic import NetstringReceiver from twisted.internet import reactor, task # Things we import from the main hblink module -from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, mk_aliases +from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, mk_aliases, aprs_upload from dmr_utils3.utils import bytes_3, int_id, get_alias from dmr_utils3 import decode, bptc, const import config @@ -1183,6 +1183,8 @@ if __name__ == '__main__': logger.info('(REPORT) TCP Socket reporting not configured') # HBlink instance creation + # Run aprs_upload loop + aprs_upload() logger.info('(GLOBAL) HBlink \'bridge.py\' -- SYSTEM STARTING...') for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: diff --git a/bridge_all.py b/bridge_all.py index 0b36036..010e4d3 100755 --- a/bridge_all.py +++ b/bridge_all.py @@ -46,7 +46,7 @@ from twisted.protocols.basic import NetstringReceiver from twisted.internet import reactor, task # Things we import from the main hblink module -from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases, acl_check +from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases, acl_check, aprs_upload from dmr_utils3.utils import bytes_3, int_id, get_alias from dmr_utils3 import decode, bptc, const import config @@ -281,6 +281,8 @@ if __name__ == '__main__': report_server = config_reports(CONFIG, reportFactory) # HBlink instance creation + # Run aprs_upload loop + aprs_upload() logger.info('HBlink \'bridge_all.py\' -- SYSTEM STARTING...') for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: diff --git a/config.py b/config.py index 5109050..6a61943 100644 --- a/config.py +++ b/config.py @@ -280,7 +280,7 @@ def build_config(_config_file): CONFIG['SYSTEMS'].update({section: { 'MODE': config.get(section, 'MODE'), 'ENABLED': config.getboolean(section, 'ENABLED'), - 'APRS_ENABLED': config.getboolean(section, 'APRS_ENABLED'), + 'APRS': config.getboolean(section, 'APRS'), 'REPEAT': config.getboolean(section, 'REPEAT'), 'MAX_PEERS': config.getint(section, 'MAX_PEERS'), 'IP': gethostbyname(config.get(section, 'IP')), diff --git a/hblink-SAMPLE.cfg b/hblink-SAMPLE.cfg index e983a57..3ba0206 100644 --- a/hblink-SAMPLE.cfg +++ b/hblink-SAMPLE.cfg @@ -167,7 +167,7 @@ TGID_ACL: PERMIT:ALL [MASTER-1] MODE: MASTER ENABLED: True -APRS_ENABLED: False +APRS: False REPEAT: True MAX_PEERS: 10 EXPORT_AMBE: False diff --git a/hblink.py b/hblink.py index 1877b6e..15486ad 100644 --- a/hblink.py +++ b/hblink.py @@ -74,10 +74,12 @@ systems = {} open("nom_aprs","w").close -file_config=config.build_config('hblink.cfg') +#file_config=config.build_config('hblink.cfg') + +CONFIG = '' def sendAprs(): - AIS = aprslib.IS(str(file_config['APRS']['CALLSIGN']), passwd=aprslib.passcode(str(file_config['APRS']['CALLSIGN'])), host=str(file_config['APRS']['SERVER']), port=14580) + AIS = aprslib.IS(str(CONFIG['APRS']['CALLSIGN']), passwd=aprslib.passcode(str(CONFIG['APRS']['CALLSIGN'])), host=str(CONFIG['APRS']['SERVER']), port=14580) AIS.connect() f = open('nom_aprs', 'r') lines = f.readlines() @@ -141,16 +143,14 @@ def sendAprs(): rx_utile = dati[2][0:3]+'.'+dati[2][3:] tx_utile = dati[3][0:3]+'.'+dati[3][3:] - if self._config['APRS']['ENABLED']: - AIS.sendall(str(dati[0])+">APRS,TCPIP*,qAC,"+str(file_config['APRS']['CALLSIGN'])+":!"+str(lat_utile)[:-2]+lat_verso+"/"+str(lon_utile)[:-1]+lon_verso+"r"+str(file_config['APRS']['MESSAGE'])+' RX: '+str(rx_utile)+' TX: '+str(tx_utile)) - logging.info('APRS INVIATO/APRS Sent') - else: - pass - -if file_config['APRS']['ENABLED']: - if int(file_config['APRS']['REPORT_INTERVAL']) >= 10: + AIS.sendall(str(dati[0])+">APRS,TCPIP*,qAC,"+str(CONFIG['APRS']['CALLSIGN'])+":!"+str(lat_utile)[:-2]+lat_verso+"/"+str(lon_utile)[:-1]+lon_verso+"r"+str(CONFIG['APRS']['MESSAGE'])+' RX: '+str(rx_utile)+' TX: '+str(tx_utile)) + logging.info('APRS INVIATO/APRS Sent') + +def aprs_upload(): + if CONFIG['APRS']['ENABLED']: + if int(CONFIG['APRS']['REPORT_INTERVAL']) >= 10: l=task.LoopingCall(sendAprs) - l.start(int(file_config['APRS']['REPORT_INTERVAL'])*60) + l.start(int(CONFIG['APRS']['REPORT_INTERVAL'])*60) else: l=task.LoopingCall(sendAprs) l.start(15*60) @@ -568,7 +568,7 @@ class HBSYSTEM(DatagramProtocol): and self._peers[_peer_id]['SOCKADDR'] == _sockaddr: logger.info('(%s) Peer is closing down: %s (%s)', self._system, self._peers[_peer_id]['CALLSIGN'], int_id(_peer_id)) self.transport.write(b''.join([MSTNAK, _peer_id]), _sockaddr) - if self._CONFIG['APRS']['ENABLED']: + if self._CONFIG['SYSTEMS'][self._system]['APRS']: #if self._config['APRS_ENABLED'] == True: fn = 'nom_aprs' f = open(fn) @@ -612,7 +612,7 @@ class HBSYSTEM(DatagramProtocol): lista_blocco=['ysf', 'xlx', 'nxdn', 'dstar', 'echolink','p25', 'svx', 'l1nk'] #if self._CONFIG['SYSTEMS']['APRS_ENABLED']['ENABLED'] and self._CONFIG['APRS']['ENABLED'] and not str(_this_peer['CALLSIGN'].decode('UTF-8')).replace(' ', '').isalpha() : # Check if master has APRS enabled instead of global. - if self._CONFIG['APRS']['ENABLED'] and not str(_this_peer['CALLSIGN'].decode('UTF-8')).replace(' ', '').isalpha() : + if self._CONFIG['SYSTEMS'][self._system]['APRS'] and not str(_this_peer['CALLSIGN'].decode('UTF-8')).replace(' ', '').isalpha() : file = open("nom_aprs","r") linee = file.readlines() file.close() @@ -962,6 +962,8 @@ if __name__ == '__main__': logger.info('(REPORT) TCP Socket reporting not configured') # HBlink instance creation + # Run aprs_upload loop + aprs_upload() logger.info('(GLOBAL) HBlink \'HBlink.py\' -- SYSTEM STARTING...') for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: