initial commit of working SMS que, sucessful receive

This commit is contained in:
KF7EEL 2021-10-13 07:22:12 -07:00
parent 8e5912fa60
commit 7c5b505484
3 changed files with 129 additions and 26 deletions

View File

@ -234,6 +234,23 @@ def send_unit_table(CONFIG, _data):
except requests.ConnectionError:
logger.error('Config server unreachable')
def send_sms_que_req(CONFIG):
user_man_url = CONFIG['WEB_SERVICE']['URL']
shared_secret = str(sha256(CONFIG['WEB_SERVICE']['SHARED_SECRET'].encode()).hexdigest())
sms_req_data = {
'get_sms_que': CONFIG['WEB_SERVICE']['THIS_SERVER_NAME'],
'secret':shared_secret,
}
json_object = json.dumps(sms_req_data, indent = 4)
try:
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
resp = json.loads(req.text)
print(resp)
return resp['que']
except requests.ConnectionError:
logger.error('Config server unreachable')
@ -897,7 +914,11 @@ def create_sms_seq(dst_id, src_id, peer_id, _slot, _call_type, dmr_string):
mmdvm_send_seq.append(ahex(the_mmdvm_pkt))
cap_in = cap_in + 1
print(ahex(the_mmdvm_pkt))
systems[UNIT_MAP[bytes.fromhex(dst_id)][0]].send_system(the_mmdvm_pkt)
if bytes.fromhex(dst_id) in UNIT_MAP:
systems[UNIT_MAP[bytes.fromhex(dst_id)][0]].send_system(the_mmdvm_pkt)
else:
systems['MASTER-1'].send_system(the_mmdvm_pkt)
print('need to code, flood all systems , ' + str(bytes.fromhex(dst_id) ))
with open('/tmp/.hblink_data_que_' + str(CONFIG['DATA_CONFIG']['APRS_LOGIN_CALL']).upper() + '/' + str(random.randint(1000, 9999)) + '.mmdvm_seq', "w") as packet_write_file:
packet_write_file.write(str(mmdvm_send_seq))
@ -973,18 +994,19 @@ def send_sms(csbk, to_id, from_id, peer_id, call_type, msg):
peer_id = str(hex(peer_id))[2:].zfill(8)
if call_type == 'unit':
call_type = 1
# Try to find slot from UNIT_MAP
try:
#Slot 2
if UNIT_MAP[bytes.fromhex(to_id)][2] == 2:
slot = 1
# Slot 1
if UNIT_MAP[bytes.fromhex(to_id)][2] == 1:
slot = 0
except Exception as e:
logger.info(e)
# Change to config value later
slot = 1
slot = 1
## # Try to find slot from UNIT_MAP
## try:
## #Slot 2
## if UNIT_MAP[bytes.fromhex(to_id)][2] == 2:
## slot = 1
## # Slot 1
## if UNIT_MAP[bytes.fromhex(to_id)][2] == 1:
## slot = 0
## except Exception as e:
## logger.info(e)
## # Change to config value later
## slot = 1
if call_type == 'group':
call_type = 0
# Send all Group data to TS 2, need to fix later.
@ -1059,6 +1081,9 @@ def aprs_process(packet):
try:
if 'msgNo' in aprslib.parse(packet):
#sleep(1)
# Write function to check UNIT_MAP and see if X amount of time has passed, if time passed, no ACK. This will prevent multiple gateways from
# ACKing. time of 24hrs?
logger.info(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo']))
aprs_send(str(aprslib.parse(packet)['addresse']) + '>APHBL3,TCPIP*:' + ':' + str(aprslib.parse(packet)['from'].ljust(9)) +':ack' + str(aprslib.parse(packet)['msgNo']))
logger.info('Send ACK')
@ -1378,6 +1403,16 @@ def rule_timer_loop():
logger.debug('Removed unit(s) %s from UNIT_MAP', remove_list)
ping(CONFIG)
send_unit_table(CONFIG, UNIT_MAP)
send_que = send_sms_que_req(CONFIG)
print(type(send_sms_que_req(CONFIG)))
print(send_sms_que_req(CONFIG))
for i in send_que:
try:
send_sms(False, i['rcv_id'], 0000, 0000, 'unit', i['msg'])
except Exception as e:
logger.info('Error sending SMS in que to ' + str(i['rcv_id']) + ' - ' + i['msg'])
logger.info(e)
class OBP(OPENBRIDGE):
@ -1446,7 +1481,9 @@ class HBP(HBSYSTEM):
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
UNIT_MAP[_rf_src] = (self._system, time())
print(_dtype_vseq)
print('MMDVM RCVD')
print(UNIT_MAP)
if _rf_src not in PACKET_MATCH:
PACKET_MATCH[_rf_src] = [_data, time()]
elif _data == PACKET_MATCH[_rf_src][0] and time() - 1 < PACKET_MATCH[_rf_src][1]:
@ -1455,10 +1492,13 @@ class HBP(HBSYSTEM):
pass
else:
PACKET_MATCH[_rf_src] = [_data, time()]
if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dytpe_vseq == 6 or _call_type == 'vcsbk':
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
else:
pass
try:
if _dtype_vseq in [3,6,7] and _call_type == 'unit' or _call_type == 'group' and _dytpe_vseq == 6 or _call_type == 'vcsbk':
data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data)
else:
pass
except Exception as e:
logger.error('Error, possibly received voice group call.')
## pass
@ -1605,7 +1645,7 @@ if __name__ == '__main__':
# Initialize the rule timer -- this if for user activated stuff
rule_timer_task = task.LoopingCall(rule_timer_loop)
rule_timer = rule_timer_task.start(60)
rule_timer = rule_timer_task.start(20)
rule_timer.addErrback(loopingErrHandle)
if 'N0CALL' in aprs_callsign:

View File

@ -2793,6 +2793,14 @@ TG #: <strong> ''' + str(tg_d.tg) + '''</strong>
<p style="text-align: center;">Redirecting in 1 seconds.</p>
<meta http-equiv="refresh" content="1; URL=''' + url + '''/mail/''' + current_user.username + '''" /> '''
elif request.args.get('send_sms'):
sms_que_add(current_user.username, '', 0, int(request.form.get('dmr_id')), 'motorola', 'unit', 'DATA', '', request.form.get('message'))
content = '''<h3 style="text-align: center;">Message in que.</h3>
<p style="text-align: center;">Redirecting in 1 seconds.</p>
<meta http-equiv="refresh" content="1; URL=''' + url + '''/mail/''' + current_user.username + '''" /> '''
else:
show_mailbox = True
mail_all = MailBox.query.filter_by(rcv_callsign=user.upper()).order_by(MailBox.time.desc()).all()
@ -2936,11 +2944,32 @@ Name: <strong>''' + p.name + '''</strong>&nbsp; -&nbsp; Port: <strong>''' + str(
que_list = []
for i in que_db:
print(i)
que_list.append({'snd_call': i.snd_callsign, 'rcv_id': i.rcv_id, 'msg_type': i.msg_type, 'call_type': i.call_type, 'msg': i.message})
return que_list
def sms_que_add():
pass
def sms_que_purge():
pass
def sms_que_add(_snd_call, _rcv_call, _snd_id, _rcv_id, _msg_type, _call_type, _server, _system_name, _msg):
sqa = SMS_Que(
snd_callsign = _snd_call,
rcv_callsign = _rcv_call,
message = _msg,
time = datetime.datetime.utcnow(),
server = _server,
system_name = _system_name,
snd_id = _snd_id,
rcv_id = _rcv_id,
msg_type = _msg_type,
call_type = _call_type
)
db.session.add(sqa)
db.session.commit()
def sms_que_purge(_server):
sqd = SMS_Que.query.filter_by(server=_server).all()
for i in sqd:
db.session.delete(i)
db.session.commit()
def get_peer_configs(_server_name):
mmdvm_pl = mmdvmPeer.query.filter_by(server=_server_name).filter_by(enabled=True).all()
@ -6783,16 +6812,19 @@ Name: <strong>''' + p.name + '''</strong>&nbsp; -&nbsp; Port: <strong>''' + str(
## except:
## message = jsonify(message='Config error')
## response = make_response(message, 401)
.
elif 'get_sms_que' in hblink_req:
if hblink_req['get_sms_que']:
q = sms_que('DATA')
print(q)
response = jsonify(
que=server_get(hblink_req['get_config'])
que=q
## OBP=get_OBP(hblink_req['get_config'])
)
sms_que_purge('DATA')
elif 'get_rules' in hblink_req:
if hblink_req['get_rules']: # == 'burn_list':

View File

@ -31,10 +31,41 @@
</div>
<div id="compose_sms" class="collapse">
<div class="card">
<div class="card-header">Send SMS to radio</div>
<div class="card-body">
<form action="{{ current_user.username or current_user.email }}?send_sms=true" method="post">
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">DMR ID</span>
<input type="text" id="dmr_id" name="dmr_id" class="form-control" aria-label="DMR ID" aria-describedby="basic-addon1">
</div>
<div class="input-group">
<span class="input-group-text">Message</span>
<textarea id="message" name="message" class="form-control" aria-label="Message"></textarea>
</div>
<br />
<p style="text-align: center;"><input class="btn btn-primary" type="submit" value="Send" /></form></p>
</div>
</div>
</div>
{% if show_mail %}
<div class="row">
<div class="col-lg-12">
<p style="text-align: right;"><button data-bs-toggle="collapse" data-bs-target="#compose" class="btn btn-primary">Compose</button></p>
{% if call_or_get(current_user.has_roles('Admin')) %}
<p style="text-align: right;"><button data-bs-toggle="collapse" data-bs-target="#compose_sms" class="btn btn-primary">Send SMS</button></p>
{% endif %}
<table data-toggle="table" data-pagination="true" data-search="true" >
<thead>