diff --git a/src/adn_server/application/plugins/domain/send.py b/src/adn_server/application/plugins/domain/send.py index 4201c65..26c670e 100644 --- a/src/adn_server/application/plugins/domain/send.py +++ b/src/adn_server/application/plugins/domain/send.py @@ -24,10 +24,10 @@ from __future__ import annotations import math from dataclasses import dataclass -from typing import Any, NamedTuple +from typing import Any from ....domain import HBPF_DATA_SYNC, HBPF_SLT_VHEAD, HBPF_SLT_VTERM, HBPF_VOICE, HBPF_VOICE_SYNC -from ....domain.mesh_admission import call_attributes +from ....domain.dmrd import DmrdHeader, parse_dmrd_header # noqa: F401 — re-export # CSBK, data header, rate 1/2 and rate 3/4 data blocks: ARS, LRRP, SMS and the like. PLUGIN_SENDABLE_DTYPES = frozenset({3, 6, 7, 8}) @@ -38,36 +38,6 @@ DEFAULT_MAX_FRAMES_PER_S = 40.0 VOICE_FRAMES_PER_S_PER_TG = 18.0 -class DmrdHeader(NamedTuple): - seq: int - rf_src: bytes - dst_id: bytes - peer_id: bytes - slot: int - call_type: str - frame_type: int - dtype_vseq: int - stream_id: bytes - - -def parse_dmrd_header(pkt: bytes) -> DmrdHeader | None: - """The HBP DMRD header fields of any call type (group, vcsbk or unit).""" - if len(pkt) < 53 or pkt[:4] != b"DMRD": - return None - attrs = call_attributes(pkt[15]) - return DmrdHeader( - seq=pkt[4], - rf_src=pkt[5:8], - dst_id=pkt[8:11], - peer_id=pkt[11:15], - slot=attrs.slot, - call_type=attrs.call_type, - frame_type=attrs.frame_type, - dtype_vseq=attrs.dtype_vseq, - stream_id=pkt[16:20], - ) - - def plugin_frame_kind(call_type: str, frame_type: int, dtype_vseq: int) -> str | None: """UNIT_DATA, GROUP_VOICE, or None for anything a plugin may not send (e.g. private voice).""" if call_type == "unit": diff --git a/src/adn_server/domain/dmrd.py b/src/adn_server/domain/dmrd.py new file mode 100644 index 0000000..bb42ddc --- /dev/null +++ b/src/adn_server/domain/dmrd.py @@ -0,0 +1,60 @@ +# ADN DMR Peer Server - DMRD voice frames +# Copyright (C) 2026 Rodrigo Pérez, CE5RPY +# +# Derived from ADN DMR Server / FreeDMR / HBlink. Original license: +############################################################################### +# Copyright (C) 2020 Simon Adlem, G7RZU +# Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +############################################################################### + +"""Fields of an HBP DMRD frame.""" + +from __future__ import annotations + +from typing import NamedTuple + +from .mesh_admission import call_attributes + + +class DmrdHeader(NamedTuple): + seq: int + rf_src: bytes + dst_id: bytes + peer_id: bytes + slot: int + call_type: str + frame_type: int + dtype_vseq: int + stream_id: bytes + + +def parse_dmrd_header(pkt: bytes) -> DmrdHeader | None: + """The HBP DMRD header fields of any call type (group, vcsbk or unit).""" + if len(pkt) < 53 or pkt[:4] != b"DMRD": + return None + attrs = call_attributes(pkt[15]) + return DmrdHeader( + seq=pkt[4], + rf_src=pkt[5:8], + dst_id=pkt[8:11], + peer_id=pkt[11:15], + slot=attrs.slot, + call_type=attrs.call_type, + frame_type=attrs.frame_type, + dtype_vseq=attrs.dtype_vseq, + stream_id=pkt[16:20], + )