voicemail/announcement server WIP

This commit is contained in:
KF7EEL 2022-10-02 06:26:47 -07:00
parent c80b6bc265
commit d01380340f
1 changed files with 141 additions and 1 deletions

View File

@ -38,6 +38,13 @@ import config
import log
import const
from binascii import b2a_hex as ahex
import random
import ast
import os
# The module needs logging logging, but handlers, etc. are controlled by the parent
import logging
logger = logging.getLogger(__name__)
@ -54,6 +61,35 @@ __maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
__status__ = 'pre-alpha'
def write_file(lst, dmr_id):
# with open('playback_test/' + str(random.randint(1,99)) + '.seq', 'w') as peer_file:
# try:
# data = ast.literal_eval(os.popen('playback_test/' + str(dmr_id) + '.dict').read())
# except:
# data = []
# pass
# new_lst = data + lst
new_lst = lst
with open('playback_test/' + str(dmr_id) + '.data', 'w') as peer_file:
peer_file.write(str(new_lst))
peer_file.close()
def play(dmr_id):
# data = os.popen('cat playback_test/' + str(seq_file) + '.seq').read()
data = ast.literal_eval(os.popen('cat playback_test/' + str(dmr_id) + '.data').read())
print(data)
# print(data)
with open('playback_test/' + str(dmr_id) + '.data', 'w') as peer_file:
peer_file.write(str([]))
peer_file.close()
return data
DST_DICT = {}
REC_DICT = {}
PLAY_DICT = {}
# Module gobal varaibles
class playback(HBSYSTEM):
@ -116,7 +152,93 @@ class playback(HBSYSTEM):
pkt_time = time()
dmrpkt = _data[20:53]
_bits = _data[15]
if _call_type == 'group':
print(self.STATUS)
try:
REC_DICT[int_id(_rf_src)]
except:
REC_DICT[int_id(_rf_src)] = False
if _call_type == 'unit':
print('unit')
if int_id(_dst_id) == 91:
REC_DICT[int_id(_rf_src)] = True
elif int_id(_dst_id) == 90:
_play_seq = play(int_id(_rf_src))
for i in _play_seq:
self.send_system(i)
sleep(0.06)
_play_seq = []
# # # Is this is a new call stream?
# if (_stream_id != self.STATUS[_slot]['RX_STREAM_ID']):
# self.STATUS['RX_START'] = pkt_time
# self.STATUS[_slot]['RX_STREAM_ID'] = _stream_id
# return
if (_stream_id not in self.STATUS):
# This is a new call stream
self.STATUS[_stream_id] = {
'START': pkt_time,
'CONTENTION':False,
'RFS': _rf_src,
'TYPE': 'UNIT',
'DST': _dst_id,
'ACTIVE': True
}
# # if (_frame_type == const.HBPF_DATA_SYNC) and (_dtype_vseq == const.HBPF_SLT_VTERM) and (self.STATUS[_slot]['RX_TYPE'] != const.HBPF_SLT_VTERM) and (self.CALL_DATA):
# # call_duration = pkt_time - self.STATUS['RX_START']
# # print(call_duration)
# # Final actions - Is this a voice terminator?
if (_frame_type == const.HBPF_DATA_SYNC) and (_dtype_vseq == const.HBPF_SLT_VTERM) and (self.STATUS[_slot]['RX_TYPE'] != const.HBPF_SLT_VTERM):
self._targets = []
call_duration = pkt_time - self.STATUS[_slot]['RX_START']
print(call_duration)
# print(int_id(_dst_id))
# print(ahex(_dst_id))
# print(ahex(_stream_id))
# try:
# print(pkt_time - DST_DICT[int_id(_dst_id)][0] < 5)
# print(DST_DICT[int_id(_dst_id)][1] != (_stream_id))
# print(DST_DICT[int_id(_dst_id)][1])
# # print(pkt_time)
# # print(DST_DICT[int_id(_dst_id)])
# if pkt_time - DST_DICT[int_id(_dst_id)][0] < 5 and DST_DICT[int_id(_dst_id)][1] != (_stream_id):
# print('true -------------------')
# else:
# del DST_DICT[int_id(_dst_id)]
# except:
# DST_DICT[int_id(_dst_id)] = [pkt_time, (_stream_id)]
# if len(str(int_id(_dst_id))) > 7:
# _mode = int(str(int_id(_dst_id))[7:])
# _dst = int(str(int_id(_dst_id))[:7])
# print(_dst)
# # print(_mode)
# if _mode == 1:
# REC_DICT[int_id(_rf_src)] = _dst
# # print('rec')
# # _play_seq = play(50)
# # for i in _play_seq:
# # self.send_system(i)
# # sleep(0.06)
# # os.remove('playback_test/50.seq')
# elif int_id(_dst_id) == 9:
# print(int_id(_dst_id))
if _call_type == 'group' or _call_type == 'unit' and REC_DICT[int_id(_rf_src)] == True and int_id(_dst_id) != 91:
# _dst_id = bytes_3(int(str(int_id(_dst_id))[:7]))
# print(ahex(_data))
# Is this is a new call stream?
if (_stream_id != self.STATUS[_slot]['RX_STREAM_ID']):
@ -139,6 +261,23 @@ class playback(HBSYSTEM):
self.send_system(i)
#print(i)
sleep(0.06)
if REC_DICT[int_id(_rf_src)] == True:
write_file(self.CALL_DATA, int_id(_dst_id))
REC_DICT[int_id(_rf_src)] = False
# print(self.CALL_DATA)
# try:
# print(REC_DICT)
# print(REC_DICT[int_id(_rf_src)])
# except:
# print('nope')
# if int_id(_dst_id) == 9:
# for i in play(91):
# self.send_system(i)
# sleep(0.06)
# print(i)
# write_file(self.CALL_DATA)
self.CALL_DATA = []
logger.info('(%s) *END PLAYBACK* STREAM ID: %s', self._system, int_id(_stream_id))
@ -237,4 +376,5 @@ 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])
print(const.HBPF_DATA_SYNC)
reactor.run()