|
|
|
|
@ -3,6 +3,7 @@ from hmac import new as hmac_new
|
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
import unittest
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
|
|
import config as freedmr_config
|
|
|
|
|
from freedmr_dmr_codec import (
|
|
|
|
|
@ -1577,6 +1578,95 @@ NETWORK_DIRECT_DIAL_SLOT: {value}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_dial_timeout_announcement_uses_expired_slot_and_its_default(self):
|
|
|
|
|
for slot in (1, 2):
|
|
|
|
|
for default_tg in (0, 90 + slot):
|
|
|
|
|
with self.subTest(slot=slot, default_tg=default_tg):
|
|
|
|
|
config = minimal_config(("MASTER-A",))
|
|
|
|
|
other_slot = 3 - slot
|
|
|
|
|
config["SYSTEMS"]["MASTER-A"]["DEFAULT_DIAL_TS1"] = 91
|
|
|
|
|
config["SYSTEMS"]["MASTER-A"]["DEFAULT_DIAL_TS2"] = 92
|
|
|
|
|
config["SYSTEMS"]["MASTER-A"][f"DEFAULT_DIAL_TS{slot}"] = default_tg
|
|
|
|
|
with DeterministicScenario(config=config) as scenario:
|
|
|
|
|
scenario.bm.make_single_reflector(bytes_3(235), 1, "MASTER-A", slot)
|
|
|
|
|
scenario.bm.make_single_reflector(bytes_3(236), 2, "MASTER-A", other_slot)
|
|
|
|
|
other_status = dict(scenario.systems["MASTER-A"].STATUS[other_slot])
|
|
|
|
|
scenario.clock.advance(61)
|
|
|
|
|
scenario.bm.rule_timer_loop()
|
|
|
|
|
|
|
|
|
|
expired = next(entry for entry in scenario.bridge_state["#235"]
|
|
|
|
|
if entry["SYSTEM"] == "MASTER-A" and entry["TS"] == slot)
|
|
|
|
|
other = next(entry for entry in scenario.bridge_state["#236"]
|
|
|
|
|
if entry["SYSTEM"] == "MASTER-A" and entry["TS"] == other_slot)
|
|
|
|
|
self.assertFalse(expired["ACTIVE"])
|
|
|
|
|
self.assertTrue(other["ACTIVE"])
|
|
|
|
|
self.assertEqual(scenario.reactor.thread_calls,
|
|
|
|
|
[(scenario.bm.disconnectedVoice, ("MASTER-A", slot), {})])
|
|
|
|
|
|
|
|
|
|
spoken = []
|
|
|
|
|
scenario.bm.words["en_GB"].update({
|
|
|
|
|
"linkedto": b"linkedto", "notlinked": b"notlinked",
|
|
|
|
|
**{str(n): str(n).encode("ascii") for n in range(10)},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def generate(source_id, dst_id, peer_id, generated_slot, say):
|
|
|
|
|
spoken.extend(say)
|
|
|
|
|
return iter([PacketSpec(
|
|
|
|
|
rf_src=int.from_bytes(source_id, "big"),
|
|
|
|
|
dst_id=int.from_bytes(dst_id, "big"),
|
|
|
|
|
slot=generated_slot + 1, stream_id=0x01020309,
|
|
|
|
|
).data()])
|
|
|
|
|
|
|
|
|
|
callback, args, kwargs = scenario.reactor.thread_calls[0]
|
|
|
|
|
with patch.object(scenario.bm, "pkt_gen", generate), patch.object(
|
|
|
|
|
scenario.bm, "sleep", lambda seconds: None
|
|
|
|
|
):
|
|
|
|
|
callback(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
captured = scenario.capture.for_system("MASTER-A")
|
|
|
|
|
self.assertEqual(len(captured), 1)
|
|
|
|
|
self.assertEqual(captured[0].fields["slot"], slot)
|
|
|
|
|
self.assertEqual(captured[0].fields["dst_id"], bytes_3(9))
|
|
|
|
|
self.assertEqual(captured[0].fields["rf_src"], bytes_3(5000))
|
|
|
|
|
status = scenario.systems["MASTER-A"].STATUS[slot]
|
|
|
|
|
self.assertEqual(status["TX_PROMPT_STREAM_ID"], bytes_4(0x01020309))
|
|
|
|
|
self.assertFalse(status["TX_PROMPT_ACTIVE"])
|
|
|
|
|
self.assertEqual(scenario.systems["MASTER-A"].STATUS[other_slot], other_status)
|
|
|
|
|
if default_tg:
|
|
|
|
|
self.assertIn(b"linkedto", spoken)
|
|
|
|
|
self.assertNotIn(b"notlinked", spoken)
|
|
|
|
|
self.assertEqual([word for word in spoken if word.isdigit()],
|
|
|
|
|
[str(n).encode("ascii") for n in str(default_tg)])
|
|
|
|
|
else:
|
|
|
|
|
self.assertIn(b"notlinked", spoken)
|
|
|
|
|
self.assertNotIn(b"linkedto", spoken)
|
|
|
|
|
|
|
|
|
|
def test_disconnected_voice_legacy_default_is_slot_two_only(self):
|
|
|
|
|
config = minimal_config(("MASTER-A",))
|
|
|
|
|
system_config = config["SYSTEMS"]["MASTER-A"]
|
|
|
|
|
system_config.pop("DEFAULT_DIAL_TS1", None)
|
|
|
|
|
system_config.pop("DEFAULT_DIAL_TS2", None)
|
|
|
|
|
system_config["DEFAULT_REFLECTOR"] = 91
|
|
|
|
|
with DeterministicScenario(config=config) as scenario:
|
|
|
|
|
scenario.bm.words["en_GB"].update({
|
|
|
|
|
"linkedto": b"linkedto", "notlinked": b"notlinked",
|
|
|
|
|
"9": b"9", "1": b"1",
|
|
|
|
|
})
|
|
|
|
|
with patch.object(scenario.bm, "pkt_gen", side_effect=lambda *args: iter(())) as generate, patch.object(
|
|
|
|
|
scenario.bm, "sleep", lambda seconds: None
|
|
|
|
|
):
|
|
|
|
|
scenario.bm.disconnectedVoice("MASTER-A")
|
|
|
|
|
args = generate.call_args.args
|
|
|
|
|
self.assertEqual(args[3], 1)
|
|
|
|
|
self.assertIn(b"linkedto", args[4])
|
|
|
|
|
self.assertEqual([word for word in args[4] if word.isdigit()], [b"9", b"1"])
|
|
|
|
|
|
|
|
|
|
scenario.bm.disconnectedVoice("MASTER-A", 1)
|
|
|
|
|
args = generate.call_args.args
|
|
|
|
|
self.assertEqual(args[3], 0)
|
|
|
|
|
self.assertIn(b"notlinked", args[4])
|
|
|
|
|
self.assertNotIn(b"linkedto", args[4])
|
|
|
|
|
|
|
|
|
|
def test_send_speech_tracks_stream_on_router_system_not_global_system(self):
|
|
|
|
|
config = minimal_config(("MASTER-A", "MASTER-B"))
|
|
|
|
|
packet = PacketSpec(dst_id=9, slot=2, stream_id=0x01020309).data()
|
|
|
|
|
|