From 1692ea8b88f22fae8b13daecebaa9990b859df54 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:32:30 +0200 Subject: [PATCH 01/22] Output callsign into the logs --- hblink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hblink.py b/hblink.py index 6b11bb1..c65d031 100755 --- a/hblink.py +++ b/hblink.py @@ -344,7 +344,7 @@ class HBMASTER(DatagramProtocol): _this_client['PACKAGE_ID'] = _data[264:304] self.send_client(_radio_id, 'RPTACK'+_radio_id) - logger.info('(%s) Client %s has sent repeater configuration', self._master, _this_client['RADIO_ID']) + logger.info('(%s) Client %s (%s) has sent repeater configuration', self._master, _this_cient['cALLSIGN'], _this_client['RADIO_ID']) else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Client info from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) @@ -537,4 +537,4 @@ if __name__ == '__main__': reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) - reactor.run() \ No newline at end of file + reactor.run() From 0baf8401a6988cd4c92f484247863a7db67b17f9 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:33:47 +0200 Subject: [PATCH 02/22] Correct typo :-/ --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index c65d031..2f6893d 100755 --- a/hblink.py +++ b/hblink.py @@ -344,7 +344,7 @@ class HBMASTER(DatagramProtocol): _this_client['PACKAGE_ID'] = _data[264:304] self.send_client(_radio_id, 'RPTACK'+_radio_id) - logger.info('(%s) Client %s (%s) has sent repeater configuration', self._master, _this_cient['cALLSIGN'], _this_client['RADIO_ID']) + logger.info('(%s) Client %s (%s) has sent repeater configuration', self._master, _this_client['cALLSIGN'], _this_client['RADIO_ID']) else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Client info from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) From cf11002b8781046fc820b7ab0857c2990eaf45e8 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:34:36 +0200 Subject: [PATCH 03/22] Correct typo No 2 :-( --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 2f6893d..ec518af 100755 --- a/hblink.py +++ b/hblink.py @@ -344,7 +344,7 @@ class HBMASTER(DatagramProtocol): _this_client['PACKAGE_ID'] = _data[264:304] self.send_client(_radio_id, 'RPTACK'+_radio_id) - logger.info('(%s) Client %s (%s) has sent repeater configuration', self._master, _this_client['cALLSIGN'], _this_client['RADIO_ID']) + logger.info('(%s) Client %s (%s) has sent repeater configuration', self._master, _this_client['CALLSIGN'], _this_client['RADIO_ID']) else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Client info from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) From 43290268ffd4c2317ddb5cc080e47adc7afc2de9 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:37:27 +0200 Subject: [PATCH 04/22] Add callsign to deregistration message --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index ec518af..f8376dc 100755 --- a/hblink.py +++ b/hblink.py @@ -84,7 +84,7 @@ def handler(_signal, _frame): if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER': for client in CONFIG['SYSTEMS'][system]['CLIENTS']: this_system.send_client(client, 'MSTCL'+client) - logger.info('(%s) Sending De-Registration to Client: %s', system, CONFIG['SYSTEMS'][system]['CLIENTS'][client]['RADIO_ID']) + logger.info('(%s) Sending De-Registration to Client: %s (%s)', system, CONFIG['SYSTEMS'][system]['CLIENTS'][client]['CALLSIGN'], CONFIG['SYSTEMS'][system]['CLIENTS'][client]['RADIO_ID']) elif CONFIG['SYSTEMS'][system]['MODE'] == 'CLIENT': this_system.send_master('RPTCL'+CONFIG['SYSTEMS'][system]['RADIO_ID']) logger.info('(%s) De-Registering From the Master', system) From 587c419316c990f27dd259eee0bdc3de8bcad755 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:41:37 +0200 Subject: [PATCH 05/22] Add callsign to timeout message --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index f8376dc..b127961 100755 --- a/hblink.py +++ b/hblink.py @@ -183,7 +183,7 @@ class HBMASTER(DatagramProtocol): _this_client = self._clients[client] # Check to see if any of the clients have been quiet (no ping) longer than allowed if _this_client['LAST_PING']+CONFIG['GLOBAL']['PING_TIME']*CONFIG['GLOBAL']['MAX_MISSED'] < time(): - logger.info('(%s) Client %s has timed out', self._master, _this_client['RADIO_ID']) + logger.info('(%s) Client %s (%s) has timed out', self._master, _this_client['CALLSIGN'], _this_client['RADIO_ID']) # Remove any timed out clients from the configuration del CONFIG['SYSTEMS'][self._master]['CLIENTS'][client] From f3b65b7042ad7673726e3f754fd26dd95cb36cc9 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:49:16 +0200 Subject: [PATCH 06/22] Add callsign to close message --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index b127961..52585bb 100755 --- a/hblink.py +++ b/hblink.py @@ -316,7 +316,7 @@ class HBMASTER(DatagramProtocol): and self._clients[_radio_id]['CONNECTION'] == 'YES' \ and self._clients[_radio_id]['IP'] == _host \ and self._clients[_radio_id]['PORT'] == _port: - logger.info('(%s) Client is closing down: %s', self._master, int_id(_radio_id)) + logger.info('(%s) Client is closing down: %s (%s)', self._master, _self.clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) self.transport.write('MSTNAK'+_radio_id, (_host, _port)) del self._clients[_radio_id] else: From 252b15d7527daeb33f90c5bdba4770de16d1fb51 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:53:38 +0200 Subject: [PATCH 07/22] Remove underscore --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 52585bb..70291fa 100755 --- a/hblink.py +++ b/hblink.py @@ -316,7 +316,7 @@ class HBMASTER(DatagramProtocol): and self._clients[_radio_id]['CONNECTION'] == 'YES' \ and self._clients[_radio_id]['IP'] == _host \ and self._clients[_radio_id]['PORT'] == _port: - logger.info('(%s) Client is closing down: %s (%s)', self._master, _self.clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) + logger.info('(%s) Client is closing down: %s (%s)', self._master, self.clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) self.transport.write('MSTNAK'+_radio_id, (_host, _port)) del self._clients[_radio_id] else: From 5848a1a7ead49d54a2048a75cfed409d81edb1e5 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 17:55:26 +0200 Subject: [PATCH 08/22] Move underscore to correct position --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 70291fa..33658c2 100755 --- a/hblink.py +++ b/hblink.py @@ -316,7 +316,7 @@ class HBMASTER(DatagramProtocol): and self._clients[_radio_id]['CONNECTION'] == 'YES' \ and self._clients[_radio_id]['IP'] == _host \ and self._clients[_radio_id]['PORT'] == _port: - logger.info('(%s) Client is closing down: %s (%s)', self._master, self.clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) + logger.info('(%s) Client is closing down: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) self.transport.write('MSTNAK'+_radio_id, (_host, _port)) del self._clients[_radio_id] else: From 4418bbc1fbba7101931d0488b65c109ced7582ab Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:00:41 +0200 Subject: [PATCH 09/22] Add output of callsign to ping messages --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 33658c2..8e109aa 100755 --- a/hblink.py +++ b/hblink.py @@ -357,7 +357,7 @@ class HBMASTER(DatagramProtocol): and self._clients[_radio_id]['PORT'] == _port: self._clients[_radio_id]['LAST_PING'] = time() self.send_client(_radio_id, 'MSTPONG'+_radio_id) - logger.debug('(%s) Received and answered RPTPING from client %s', self._master, int_id(_radio_id)) + logger.debug('(%s) Received and answered RPTPING from client %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Client info from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) From 0987e2478e89842549844d187abe7650d59478a3 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:03:52 +0200 Subject: [PATCH 10/22] Add callsign to repeat messages --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 8e109aa..e35ecd8 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s', self._master, int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 0f95fae240c41372fa6aa39c5dc752f9aef644aa Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:05:31 +0200 Subject: [PATCH 11/22] Wrong variable used :) --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index e35ecd8..7d60245 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[_radio_id]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From fe4a8a01d48b76c930381cad8deba2c99e80e8eb Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:06:46 +0200 Subject: [PATCH 12/22] Obviously I used a wrong variable. See if this works ... --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 7d60245..bfcaaf4 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[_radio_id]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 54d3a962ca69663c1a0a2df86ffbbb4ebb3e5e66 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:09:59 +0200 Subject: [PATCH 13/22] Use integer indices --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index bfcaaf4..4d8bc69 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[int_id(_client)]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From aa135c0e6bc4b9cb6a9d9f830b8b93ae44d3fcc7 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:18:10 +0200 Subject: [PATCH 14/22] Testing integer boundaries --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 4d8bc69..92f163a 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[int_id(_client)]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[1]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From a8d1559073db247cd5521cf7ef642e44aab1d2a8 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:20:59 +0200 Subject: [PATCH 15/22] Revert "Testing integer boundaries" This reverts commit aa135c0e6bc4b9cb6a9d9f830b8b93ae44d3fcc7. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 92f163a..4d8bc69 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[1]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[int_id(_client)]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From f30c5797061f25b165a5e3058d81ec2a5209534a Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:21:38 +0200 Subject: [PATCH 16/22] Revert "Use integer indices" This reverts commit 54d3a962ca69663c1a0a2df86ffbbb4ebb3e5e66. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 4d8bc69..bfcaaf4 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[int_id(_client)]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From dcef33f8b16c7fa156a1af6d711464bafad44d47 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:21:50 +0200 Subject: [PATCH 17/22] Revert "Obviously I used a wrong variable. See if this works ..." This reverts commit fe4a8a01d48b76c930381cad8deba2c99e80e8eb. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index bfcaaf4..7d60245 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[_radio_id]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 472fc2a3eb830e340925045dd94caa6c13d85759 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:22:00 +0200 Subject: [PATCH 18/22] Revert "Wrong variable used :)" This reverts commit 0f95fae240c41372fa6aa39c5dc752f9aef644aa. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 7d60245..e35ecd8 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, _client[_radio_id]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 0195f773d2d1c1b0267eae5e464f12fa1bfa144a Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 18:22:12 +0200 Subject: [PATCH 19/22] Revert "Add callsign to repeat messages" This reverts commit 0987e2478e89842549844d187abe7650d59478a3. --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index e35ecd8..8e109aa 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s', self._master, int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 59d15e95a7eb134c37156ffe8fdc474b8edc4e18 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 21:19:30 +0200 Subject: [PATCH 20/22] Add callsign output to repeater messages --- hblink.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hblink.py b/hblink.py index 8e109aa..d20ca77 100755 --- a/hblink.py +++ b/hblink.py @@ -246,7 +246,7 @@ class HBMASTER(DatagramProtocol): for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) - logger.debug('(%s) Packet repeated to client: %s', self._master, int_id(_client)) + logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_client]['CALLSIGN'], int_id(_client)) # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) From 87f62477528c158432ca6c5320d2fb782231ec3c Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 21:33:47 +0200 Subject: [PATCH 21/22] Remove whitespace in empty lines --- hblink.py | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/hblink.py b/hblink.py index d20ca77..c51ce31 100755 --- a/hblink.py +++ b/hblink.py @@ -78,7 +78,7 @@ logger.debug('Logging system started, anything from here on gets logged') # Shut ourselves down gracefully by disconnecting from the masters and clients. def handler(_signal, _frame): logger.info('*** HBLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal)) - + for system in systems: this_system = systems[system] if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER': @@ -113,7 +113,7 @@ def hex_str_4(_int_id): return hex(_int_id)[2:].rjust(8,'0').decode('hex') except TypeError: logger.error('hex_str_4: invalid integer length') - + # Convert a hex string to an int (radio ID, etc.) def int_id(_hex_string): return int(h(_hex_string), 16) @@ -126,7 +126,7 @@ class AMBE: _sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) _exp_ip = CONFIG['AMBE']['EXPORT_IP'] _exp_port = CONFIG['AMBE']['EXPORT_PORT'] - + def parseAMBE(self, _client, _data): _seq = int_id(_data[4:5]) _srcID = int_id(_data[5:8]) @@ -163,7 +163,7 @@ class HBMASTER(DatagramProtocol): self._system = self._master self._config = CONFIG['SYSTEMS'][self._master] self._clients = CONFIG['SYSTEMS'][self._master]['CLIENTS'] - + # Configure for AMBE audio export if enabled if self._config['EXPORT_AMBE']: self._ambe = AMBE() @@ -171,12 +171,12 @@ class HBMASTER(DatagramProtocol): # If we didn't get called correctly, log it and quit. logger.error('(%s) HBMASTER was not called with an argument. Terminating', self._master) sys.exit() - + def startProtocol(self): # Set up periodic loop for tracking pings from clients. Run every 'PING_TIME' seconds self._master_maintenance = task.LoopingCall(self.master_maintenance_loop) self._master_maintenance_loop = self._master_maintenance.start(CONFIG['GLOBAL']['PING_TIME']) - + def master_maintenance_loop(self): logger.debug('(%s) Master maintenance loop started', self._master) for client in self._clients: @@ -186,33 +186,33 @@ class HBMASTER(DatagramProtocol): logger.info('(%s) Client %s (%s) has timed out', self._master, _this_client['CALLSIGN'], _this_client['RADIO_ID']) # Remove any timed out clients from the configuration del CONFIG['SYSTEMS'][self._master]['CLIENTS'][client] - + def send_clients(self, _packet): for _client in self._clients: self.send_client(_client, _packet) #logger.debug('(%s) Packet sent to client %s', self._master, self._clients[_client]['RADIO_ID']) - + def send_client(self, _client, _packet): _ip = self._clients[_client]['IP'] _port = self._clients[_client]['PORT'] self.transport.write(_packet, (_ip, _port)) # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! #logger.debug('(%s) TX Packet to %s on port %s: %s', self._clients[_client]['RADIO_ID'], self._clients[_client]['IP'], self._clients[_client]['PORT'], h(_packet)) - + # Alias for other programs to use a common name to send a packet # regardless of the system type (MASTER or CLIENT) send_system = send_clients - + def dmrd_received(self, _radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data): pass def datagramReceived(self, _data, (_host, _port)): # Keep This Line Commented Unless HEAVILY Debugging! #logger.debug('(%s) RX packet from %s:%s -- %s', self._master, _host, _port, h(_data)) - + # Extract the command, which is various length, all but one 4 significant characters -- RPTCL _command = _data[:4] - + if _command == 'DMRD': # DMRData -- encapsulated DMR data frame _radio_id = _data[11:15] if _radio_id in self._clients \ @@ -236,21 +236,21 @@ class HBMASTER(DatagramProtocol): _frame_type = 'none' _stream_id = _data[16:20] #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._master, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) - + # If AMBE audio exporting is configured... if self._config['EXPORT_AMBE']: self._ambe.parseAMBE(self._master, _data) - + # The basic purpose of a master is to repeat to the clients if self._config['REPEAT'] == True: for _client in self._clients: if _client != _radio_id: self.send_client(_client, _data) logger.debug('(%s) Packet repeated to client: %s (%s)', self._master, self._clients[_client]['CALLSIGN'], int_id(_client)) - + # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) - + elif _command == 'RPTL': # RPTLogin -- a repeater wants to login _radio_id = _data[4:8] if _radio_id: # Future check here for valid Radio ID @@ -285,7 +285,7 @@ class HBMASTER(DatagramProtocol): else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Invalid Login from Radio ID: %s', self._master, int_id(_radio_id)) - + elif _command == 'RPTK': # Repeater has answered our login challenge _radio_id = _data[4:8] if _radio_id in self._clients \ @@ -308,7 +308,7 @@ class HBMASTER(DatagramProtocol): else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Login challenge from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) - + elif _command == 'RPTC': # Repeater is sending it's configuraiton OR disconnecting if _data[:5] == 'RPTCL': # Disconnect command _radio_id = _data[5:9] @@ -361,10 +361,10 @@ class HBMASTER(DatagramProtocol): else: self.transport.write('MSTNAK'+_radio_id, (_host, _port)) logger.warning('(%s) Client info from Radio ID that has not logged in: %s', self._master, int_id(_radio_id)) - + else: logger.error('(%s) Unrecognized command from: %s. Packet: %s', self._master, int_id(_radio_id), h(_data)) - + #************************************************ # HB CLIENT CLASS #************************************************ @@ -377,7 +377,7 @@ class HBCLIENT(DatagramProtocol): self._system = self._client self._config = CONFIG['SYSTEMS'][self._client] self._stats = self._config['STATS'] - + # Configure for AMBE audio export if enabled if self._config['EXPORT_AMBE']: self._ambe = AMBE() @@ -390,7 +390,7 @@ class HBCLIENT(DatagramProtocol): # Set up periodic loop for sending pings to the master. Run every 'PING_TIME' seconds self._client_maintenance = task.LoopingCall(self.client_maintenance_loop) self._client_maintenance_loop = self._client_maintenance.start(CONFIG['GLOBAL']['PING_TIME']) - + def client_maintenance_loop(self): logger.debug('(%s) Client maintenance loop started', self._client) # If we're not connected, zero out the stats and send a login request RPTL @@ -405,23 +405,23 @@ class HBCLIENT(DatagramProtocol): self.send_master('RPTPING'+self._config['RADIO_ID']) self._stats['PINGS_SENT'] += 1 logger.debug('(%s) RPTPING Sent to Master. Pings Since Connected: %s', self._client, self._stats['PINGS_SENT']) - + def send_master(self, _packet): self.transport.write(_packet, (self._config['MASTER_IP'], self._config['MASTER_PORT'])) # KEEP THE FOLLOWING COMMENTED OUT UNLESS YOU'RE DEBUGGING DEEPLY!!!! #logger.debug('(%s) TX Packet to %s:%s -- %s', self._client, self._config['MASTER_IP'], self._config['MASTER_PORT'], h(_packet)) - + # Alias for other programs to use a common name to send a packet # regardless of the system type (MASTER or CLIENT) send_system = send_master - + def dmrd_received(self, _radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data): pass - + def datagramReceived(self, _data, (_host, _port)): # Keep This Line Commented Unless HEAVILY Debugging! # logger.debug('(%s) RX packet from %s:%s -- %s', self._client, _host, _port, h(_data)) - + # Validate that we receveived this packet from the master - security check! if self._config['MASTER_IP'] == _host and self._config['MASTER_PORT'] == _port: # Extract the command, which is various length, but only 4 significant characters @@ -445,22 +445,22 @@ class HBCLIENT(DatagramProtocol): else: _frame_type = 'none' _stream_id = _data[16:20] - + #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._client, h(_seq), int_id(_rf_src), int_id(_dst_id)) - + # If AMBE audio exporting is configured... if self._config['EXPORT_AMBE']: self._ambe.parseAMBE(self._client, _data) - + # Userland actions -- typically this is the function you subclass for an application self.dmrd_received(_radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _stream_id, _data) - + elif _command == 'MSTN': # Actually MSTNAK -- a NACK from the master _radio_id = _data[4:8] if _radio_id == self._config['RADIO_ID']: # Validate the source and intended target logger.warning('(%s) MSTNAK Received', self._client) self._stats['CONNECTION'] = 'NO' # Disconnect ourselves and re-register - + elif _command == 'RPTA': # Actually RPTACK -- an ACK from the master # Depending on the state, an RPTACK means different things, in each clause, we check and/or set the state if self._stats['CONNECTION'] == 'RTPL_SENT': # If we've sent a login request... @@ -470,7 +470,7 @@ class HBCLIENT(DatagramProtocol): _pass_hash = a(_pass_hash) self.send_master('RPTK'+self._config['RADIO_ID']+_pass_hash) self._stats['CONNECTION'] = 'AUTHENTICATED' - + elif self._stats['CONNECTION'] == 'AUTHENTICATED': # If we've sent the login challenge... if _data[6:10] == self._config['RADIO_ID']: logger.info('(%s) Repeater Authentication Accepted', self._client) @@ -489,14 +489,14 @@ class HBCLIENT(DatagramProtocol): self._config['URL']+\ self._config['SOFTWARE_ID']+\ self._config['PACKAGE_ID'] - + self.send_master('RPTC'+_config_packet) self._stats['CONNECTION'] = 'CONFIG-SENT' logger.info('(%s) Repeater Configuration Sent', self._client) else: self._stats['CONNECTION'] = 'NO' logger.error('(%s) Master ACK Contained wrong ID - Connection Reset', self._client) - + elif self._stats['CONNECTION'] == 'CONFIG-SENT': # If we've sent out configuration to the master if _data[6:10] == self._config['RADIO_ID']: logger.info('(%s) Repeater Configuration Accepted', self._client) @@ -505,17 +505,17 @@ class HBCLIENT(DatagramProtocol): else: self._stats['CONNECTION'] = 'NO' logger.error('(%s) Master ACK Contained wrong ID - Connection Reset', self._client) - + elif _command == 'MSTP': # Actually MSTPONG -- a reply to RPTPING (send by client) if _data [7:11] == self._config['RADIO_ID']: self._stats['PINGS_ACKD'] += 1 logger.debug('(%s) MSTPONG Received. Pongs Since Connected: %s', self._client, self._stats['PINGS_ACKD']) - + elif _command == 'MSTC': # Actually MSTCL -- notify us the master is closing down if _data[5:9] == self._config['RADIO_ID']: self._stats['CONNECTION'] = 'NO' logger.info('(%s) MSTCL Recieved', self._client) - + else: logger.error('(%s) Received an invalid command in packet: %s', self._client, h(_data)) @@ -526,7 +526,7 @@ class HBCLIENT(DatagramProtocol): if __name__ == '__main__': logger.info('HBlink \'HBlink.py\' (c) 2016 N0MJS & the K0USY Group - SYSTEM STARTING...') - + # HBlink instance creation for system in CONFIG['SYSTEMS']: if CONFIG['SYSTEMS'][system]['ENABLED']: @@ -536,5 +536,5 @@ if __name__ == '__main__': systems[system] = HBCLIENT(system) reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system]) - + reactor.run() From d903d46bd06af08359e06ee67ca624955fe2cf17 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 1 Sep 2016 21:36:31 +0200 Subject: [PATCH 22/22] Remove trailing spaces --- hblink.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hblink.py b/hblink.py index c51ce31..e6ec727 100755 --- a/hblink.py +++ b/hblink.py @@ -184,7 +184,7 @@ class HBMASTER(DatagramProtocol): # Check to see if any of the clients have been quiet (no ping) longer than allowed if _this_client['LAST_PING']+CONFIG['GLOBAL']['PING_TIME']*CONFIG['GLOBAL']['MAX_MISSED'] < time(): logger.info('(%s) Client %s (%s) has timed out', self._master, _this_client['CALLSIGN'], _this_client['RADIO_ID']) - # Remove any timed out clients from the configuration + # Remove any timed out clients from the configuration del CONFIG['SYSTEMS'][self._master]['CLIENTS'][client] def send_clients(self, _packet): @@ -208,7 +208,7 @@ class HBMASTER(DatagramProtocol): def datagramReceived(self, _data, (_host, _port)): # Keep This Line Commented Unless HEAVILY Debugging! - #logger.debug('(%s) RX packet from %s:%s -- %s', self._master, _host, _port, h(_data)) + #logger.debug('(%s) RX packet from %s:%s -- %s', self._master, _host, _port, h(_data)) # Extract the command, which is various length, all but one 4 significant characters -- RPTCL _command = _data[:4] @@ -237,7 +237,7 @@ class HBMASTER(DatagramProtocol): _stream_id = _data[16:20] #logger.debug('(%s) DMRD - Seqence: %s, RF Source: %s, Destination ID: %s', self._master, int_id(_seq), int_id(_rf_src), int_id(_dst_id)) - # If AMBE audio exporting is configured... + # If AMBE audio exporting is configured... if self._config['EXPORT_AMBE']: self._ambe.parseAMBE(self._master, _data) @@ -319,7 +319,7 @@ class HBMASTER(DatagramProtocol): logger.info('(%s) Client is closing down: %s (%s)', self._master, self._clients[_radio_id]['CALLSIGN'], int_id(_radio_id)) self.transport.write('MSTNAK'+_radio_id, (_host, _port)) del self._clients[_radio_id] - else: + else: _radio_id = _data[4:8] # Configure Command if _radio_id in self._clients \ and self._clients[_radio_id]['CONNECTION'] == 'WAITING_CONFIG' \ @@ -367,7 +367,7 @@ class HBMASTER(DatagramProtocol): #************************************************ # HB CLIENT CLASS -#************************************************ +#************************************************ class HBCLIENT(DatagramProtocol): @@ -378,13 +378,13 @@ class HBCLIENT(DatagramProtocol): self._config = CONFIG['SYSTEMS'][self._client] self._stats = self._config['STATS'] - # Configure for AMBE audio export if enabled + # Configure for AMBE audio export if enabled if self._config['EXPORT_AMBE']: self._ambe = AMBE() else: # If we didn't get called correctly, log it! logger.error('(%s) HBCLIENT was not called with an argument. Terminating', self._client) - sys.exit() + sys.exit() def startProtocol(self): # Set up periodic loop for sending pings to the master. Run every 'PING_TIME' seconds @@ -425,7 +425,7 @@ class HBCLIENT(DatagramProtocol): # Validate that we receveived this packet from the master - security check! if self._config['MASTER_IP'] == _host and self._config['MASTER_PORT'] == _port: # Extract the command, which is various length, but only 4 significant characters - _command = _data[:4] + _command = _data[:4] if _command == 'DMRD': # DMRData -- encapsulated DMR data frame _radio_id = _data[11:15] if _radio_id == self._config['RADIO_ID']: # Validate the source and intended target @@ -533,7 +533,7 @@ if __name__ == '__main__': if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER': systems[system] = HBMASTER(system) elif CONFIG['SYSTEMS'][system]['MODE'] == 'CLIENT': - systems[system] = HBCLIENT(system) + systems[system] = HBCLIENT(system) reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP']) logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system])