diff --git a/bridge_master.py b/bridge_master.py index 617bbb4..eb64630 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1268,9 +1268,8 @@ def _ttsConversionDone(_ambe_path, _tts_num, _file, _tg, _timeslot, _lang, _mode logger.warning('(%s) No AMBE file available for TTS announcement %s', _label, _file) return - logger.info('(%s) Playing TTS file: %s to TG %s TS%s (mode: %s, lang: %s)', _label, _file, _tg, _timeslot, _mode, _lang) + logger.info('(%s) Playing TTS file: %s to TG %s (both TS, mode: %s, lang: %s)', _label, _file, _tg, _mode, _lang) - _slot_index = 2 if _timeslot == 2 else 1 _dst_id = bytes_3(_tg) _source_id = bytes_3(5000) _peer_id = CONFIG['GLOBAL']['SERVER_ID'] @@ -1294,6 +1293,8 @@ def _ttsConversionDone(_ambe_path, _tts_num, _file, _tg, _timeslot, _lang, _mode logger.debug('(%s) AMBE file loaded, %s words', _label, len(_say)) + _tg_str = str(_tg) + _excluded = ['ECHO', 'D-APRS'] _targets = [] @@ -1322,28 +1323,48 @@ def _ttsConversionDone(_ambe_path, _tts_num, _file, _tg, _timeslot, _lang, _mode if _sn not in systems: continue - _slot = systems[_sn].STATUS[_slot_index] - if (_slot['RX_TYPE'] != HBPF_SLT_VTERM) or (_slot['TX_TYPE'] != HBPF_SLT_VTERM): - logger.debug('(%s) System %s busy, skipping', _label, _sn) + _active_slots = [] + if _tg_str in BRIDGES: + for _be in BRIDGES[_tg_str]: + if _be['SYSTEM'] == _sn and _be['ACTIVE'] and _be['TS'] not in _active_slots: + _active_slots.append(_be['TS']) + + if not _active_slots: continue - _targets.append({ - 'sys_obj': systems[_sn], - 'name': _sn, - 'slot': _slot - }) + for _ts in _active_slots: + _slot_index = 2 if _ts == 2 else 1 + _slot = systems[_sn].STATUS[_slot_index] + if (_slot['RX_TYPE'] != HBPF_SLT_VTERM) or (_slot['TX_TYPE'] != HBPF_SLT_VTERM): + logger.debug('(%s) System %s TS%s busy, skipping', _label, _sn, _ts) + continue + + _targets.append({ + 'sys_obj': systems[_sn], + 'name': _sn, + 'slot': _slot, + 'ts': _ts + }) + logger.debug('(%s) System %s added for TG %s TS%s', _label, _sn, _tg, _ts) if not _targets: _tts_running[_tts_num] = False - logger.info('(%s) No systems with connected peers to send to', _label) + logger.info('(%s) No systems with active bridge for TG %s to send to', _label, _tg) return - _pkts = list(pkt_gen(_source_id, _dst_id, _peer_id, _slot_index - 1, _say)) - _sys_names = ', '.join([t['name'] for t in _targets[:5]]) - if len(_targets) > 5: - _sys_names += ', ... +{}'.format(len(_targets) - 5) - logger.info('(%s) Broadcasting %s packets to %s systems simultaneously: %s', _label, len(_pkts), len(_targets), _sys_names) - reactor.callLater(1.0, _ttsSendBroadcast, _targets, _pkts, 0, _source_id, _dst_id, _tg, _timeslot, _tts_num) + _pkts_by_ts = { + 1: list(pkt_gen(_source_id, _dst_id, _peer_id, 0, _say)), + 2: list(pkt_gen(_source_id, _dst_id, _peer_id, 1, _say)), + } + + _ts1_count = sum(1 for t in _targets if t['ts'] == 1) + _ts2_count = sum(1 for t in _targets if t['ts'] == 2) + _sys_names = ', '.join(['{}/TS{}'.format(t['name'], t['ts']) for t in _targets[:8]]) + if len(_targets) > 8: + _sys_names += ', ... +{}'.format(len(_targets) - 8) + logger.info('(%s) Broadcasting %s packets to %s targets (TS1:%s TS2:%s): %s', + _label, len(_pkts_by_ts[1]), len(_targets), _ts1_count, _ts2_count, _sys_names) + reactor.callLater(1.0, _ttsSendBroadcast, _targets, _pkts_by_ts, 0, _source_id, _dst_id, _tg, 0, _tts_num) def _ttsConversionError(failure, _tts_num, _label): @@ -1351,12 +1372,13 @@ def _ttsConversionError(failure, _tts_num, _label): _tts_running[_tts_num] = False logger.error('(%s) Error en conversion TTS: %s', _label, failure.getErrorMessage()) -def _ttsSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, _tts_num=1, _next_time=None): +def _ttsSendBroadcast(_targets, _pkts_by_ts, _pkt_idx, _source_id, _dst_id, _tg, _ts_unused, _tts_num=1, _next_time=None): global _tts_running _label = 'TTS-{}'.format(_tts_num) - if _pkt_idx >= len(_pkts): + _total_pkts = len(_pkts_by_ts[1]) + if _pkt_idx >= _total_pkts: for _t in _targets: try: for _sid in list(_t['sys_obj'].STATUS.keys()): @@ -1365,17 +1387,18 @@ def _ttsSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, except: pass _tts_running[_tts_num] = False - logger.info('(%s) Broadcast complete: %s packets sent to %s systems', _label, len(_pkts), len(_targets)) + logger.info('(%s) Broadcast complete: %s packets sent to %s targets', _label, _total_pkts, len(_targets)) return _now = time() - pkt = _pkts[_pkt_idx] - _stream_id = pkt[16:20] for _t in _targets: try: _sys_obj = _t['sys_obj'] _slot = _t['slot'] + _t_ts = _t['ts'] + pkt = _pkts_by_ts[_t_ts][_pkt_idx] + _stream_id = pkt[16:20] if _stream_id not in _sys_obj.STATUS: _sys_obj.STATUS[_stream_id] = { 'START': _now, @@ -1388,11 +1411,11 @@ def _ttsSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, else: _sys_obj.STATUS[_stream_id]['LAST'] = _now _slot['TX_TIME'] = _now - _fc = _sendFilteredByTG(_sys_obj, pkt, _tg, _ts, _label, _pkt_idx) + _fc = _sendFilteredByTG(_sys_obj, pkt, _tg, _t_ts, _label, _pkt_idx) if _pkt_idx == 0 and _fc == 0: - logger.debug('(%s) TG %s TS%s not active on %s, skipping', _label, _tg, _ts, _t['name']) + logger.debug('(%s) TG %s TS%s not active on %s, skipping', _label, _tg, _t_ts, _t['name']) except Exception as e: - logger.error('(%s) Error sending packet %s to %s: %s', _label, _pkt_idx, _t['name'], e) + logger.error('(%s) Error sending packet %s to %s/TS%s: %s', _label, _pkt_idx, _t['name'], _t.get('ts', '?'), e) _elapsed = time() - _now if _next_time is None: @@ -1402,9 +1425,9 @@ def _ttsSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, _delay = max(0.001, _next_time - time()) if _pkt_idx < 3: - logger.debug('(%s) Packet %s/%s broadcast to %s systems (proc: %.1fms, delay: %.1fms)', _label, _pkt_idx + 1, len(_pkts), len(_targets), _elapsed * 1000, _delay * 1000) + logger.debug('(%s) Packet %s/%s broadcast to %s targets (proc: %.1fms, delay: %.1fms)', _label, _pkt_idx + 1, _total_pkts, len(_targets), _elapsed * 1000, _delay * 1000) - reactor.callLater(_delay, _ttsSendBroadcast, _targets, _pkts, _pkt_idx + 1, _source_id, _dst_id, _tg, _ts, _tts_num, _next_time) + reactor.callLater(_delay, _ttsSendBroadcast, _targets, _pkts_by_ts, _pkt_idx + 1, _source_id, _dst_id, _tg, _ts_unused, _tts_num, _next_time) def bridge_reset(): logger.debug('(BRIDGERESET) Running bridge resetter')