From 2014015421eba00e0da64713e10e7973b4cf3de7 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 22 Sep 2020 20:06:07 +0100 Subject: [PATCH] Ident config option --- bridge_master.py | 38 +++++++++++++++++++++++++++++++++++--- config.py | 3 ++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index c344fa2..f2ce455 100755 --- a/bridge_master.py +++ b/bridge_master.py @@ -36,6 +36,7 @@ import sys from bitarray import bitarray from time import time,sleep import importlib.util +import re # Twisted is pretty important, so I keep it separate from twisted.internet.protocol import Factory, Protocol @@ -55,9 +56,6 @@ from mk_voice import pkt_gen #Read voices from read_ambe import readAMBE -#regex -import re - # Stuff for socket reporting import pickle # REMOVE LATER from datetime import datetime @@ -263,6 +261,34 @@ def stream_trimmer_loop(): else: logger.error('(%s) Attemped to remove OpenBridge Stream ID %s not in the Stream ID list: %s', system, int_id(stream_id), [id for id in systems[system].STATUS]) +def ident(): + for system in systems: + if CONFIG['SYSTEMS'][system]['VOICE_IDENT'] == True: + #We only care about slot 2 - idents go out on slot 2 + _slot = systems[system].STATUS[2] + #If slot is idle for RX and TX + if (_slot['RX_TYPE'] == HBPF_SLT_VTERM) and (_slot['TX_TYPE'] == HBPF_SLT_VTERM): + #_stream_id = hex_str_4(1234567) + logger.info('(%s) Sending voice ident',system) + _say = [words['silence']] + _systemcs = re.sub(r'\W+', '', system) + _systemcs.upper() + for character in _systemcs: + _say.append(words[character]) + _say.append(words['silence']) + speech = pkt_gen(bytes_3(16777215), bytes_3(16777215), bytes_4(16777215), 1, _say) + + sleep(1) + while True: + try: + pkt = next(speech) + except StopIteration: + break + #Packet every 60ms + sleep(0.058) + systems[system].send_system(pkt) + + class routerOBP(OPENBRIDGE): def __init__(self, _name, _config, _report): @@ -1063,5 +1089,11 @@ if __name__ == '__main__': stream_trimmer_task = task.LoopingCall(stream_trimmer_loop) stream_trimmer = stream_trimmer_task.start(5) stream_trimmer.addErrback(loopingErrHandle) + + # Ident + ident_task = task.LoopingCall(ident) + ident = ident_task.start(900) + ident.addErrback(loopingErrHandle) + reactor.run() diff --git a/config.py b/config.py index bbea43e..965f142 100755 --- a/config.py +++ b/config.py @@ -261,7 +261,8 @@ def build_config(_config_file): 'TG1_ACL': config.get(section, 'TGID_TS1_ACL'), 'TG2_ACL': config.get(section, 'TGID_TS2_ACL'), 'DEFAULT_UA_TIMER': config.getint(section, 'DEFAULT_UA_TIMER'), - 'SINGLE_MODE': config.getboolean(section, 'SINGLE_MODE') + 'SINGLE_MODE': config.getboolean(section, 'SINGLE_MODE'), + 'VOICE_IDENT': config.getboolean(section, 'VOICE_IDENT') }}) CONFIG['SYSTEMS'][section].update({'PEERS': {}})