REFACT enums
Этот коммит содержится в:
Executable
+26
@@ -0,0 +1,26 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import enum
|
||||||
|
|
||||||
|
|
||||||
|
CallType = enum.StrEnum('CallType', ['UNIT', 'GROUP'])
|
||||||
|
|
||||||
|
|
||||||
|
class VoiceType(enum.Enum):
|
||||||
|
NONE = 0b000000
|
||||||
|
HEAD = 0b100001
|
||||||
|
BURST_A = 0b010000
|
||||||
|
BURST_B = 0b000001
|
||||||
|
BURST_C = 0b000010
|
||||||
|
BURST_D = 0b000011
|
||||||
|
BURST_E = 0b000100
|
||||||
|
BURST_F = 0b000101
|
||||||
|
TERM = 0b100010
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_value(value: int) -> VoiceType:
|
||||||
|
try:
|
||||||
|
return VoiceType(value)
|
||||||
|
except ValueError:
|
||||||
|
return VoiceType.NONE
|
||||||
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import enum
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from typing import Type, Self
|
from typing import Type, Self, TypeAlias
|
||||||
|
|
||||||
from .base_fields import DMRPFieldInt, DMRPFieldBytes, DMRPFieldStr
|
from .base_fields import DMRPFieldInt, DMRPFieldBytes, DMRPFieldStr
|
||||||
|
from .enums import CallType, VoiceType
|
||||||
from .exceptions import DMRPBadPacketException
|
from .exceptions import DMRPBadPacketException
|
||||||
from .exceptions import DMRPFieldOutOfRangeException
|
from .exceptions import DMRPFieldOutOfRangeException
|
||||||
from .exceptions import DMRPUnknownPacketTypeException
|
from .exceptions import DMRPUnknownPacketTypeException
|
||||||
@@ -260,25 +260,8 @@ class DMRPPacketData(DMRPBasePeerPacket):
|
|||||||
PKT_TYPE = b'DMRD'
|
PKT_TYPE = b'DMRD'
|
||||||
PKT_SIZE = 55
|
PKT_SIZE = 55
|
||||||
|
|
||||||
CallType = enum.StrEnum('CallType', ['UNIT', 'GROUP'])
|
CallType: TypeAlias = CallType # legacy alias
|
||||||
|
VoiceType: TypeAlias = VoiceType # legacy alias
|
||||||
class VoiceType(enum.Enum):
|
|
||||||
NONE = 0b000000
|
|
||||||
HEAD = 0b100001
|
|
||||||
BURST_A = 0b010000
|
|
||||||
BURST_B = 0b000001
|
|
||||||
BURST_C = 0b000010
|
|
||||||
BURST_D = 0b000011
|
|
||||||
BURST_E = 0b000100
|
|
||||||
BURST_F = 0b000101
|
|
||||||
TERM = 0b100010
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_value(value: int) -> DMRPPacketData.VoiceType:
|
|
||||||
try:
|
|
||||||
return DMRPPacketData.VoiceType(value)
|
|
||||||
except ValueError:
|
|
||||||
return DMRPPacketData.VoiceType.NONE
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
bits:
|
bits:
|
||||||
@@ -322,17 +305,17 @@ class DMRPPacketData(DMRPBasePeerPacket):
|
|||||||
# call_type
|
# call_type
|
||||||
def get_call_type(self) -> CallType:
|
def get_call_type(self) -> CallType:
|
||||||
if self._data is None or self._data[15] & 0x40 != 0:
|
if self._data is None or self._data[15] & 0x40 != 0:
|
||||||
return DMRPPacketData.CallType.UNIT
|
return CallType.UNIT
|
||||||
return DMRPPacketData.CallType.GROUP
|
return CallType.GROUP
|
||||||
|
|
||||||
def set_call_type(self, call_type: CallType) -> None:
|
def set_call_type(self, call_type: CallType) -> None:
|
||||||
if call_type not in DMRPPacketData.CallType:
|
if call_type not in CallType:
|
||||||
raise DMRPFieldOutOfRangeException("call_type", '|'.join(
|
raise DMRPFieldOutOfRangeException(
|
||||||
ct.value for ct in DMRPPacketData.CallType))
|
"call_type", '|'.join(ct.value for ct in CallType))
|
||||||
if self._data is not None:
|
if self._data is not None:
|
||||||
self._data[15] = (
|
self._data[15] = (
|
||||||
(self._data[15] & ~0x40) |
|
(self._data[15] & ~0x40) |
|
||||||
(0x40 if call_type == DMRPPacketData.CallType.UNIT else 0))
|
(0x40 if call_type == CallType.UNIT else 0))
|
||||||
|
|
||||||
call_type = property(get_call_type, set_call_type)
|
call_type = property(get_call_type, set_call_type)
|
||||||
|
|
||||||
@@ -366,7 +349,7 @@ class DMRPPacketData(DMRPBasePeerPacket):
|
|||||||
|
|
||||||
# voice_type
|
# voice_type
|
||||||
def get_voice_type(self) -> VoiceType:
|
def get_voice_type(self) -> VoiceType:
|
||||||
return DMRPPacketData.VoiceType.from_value(self.bits & 0x3F)
|
return VoiceType.from_value(self.bits & 0x3F)
|
||||||
|
|
||||||
def set_voice_type(self, voice_type: VoiceType) -> None:
|
def set_voice_type(self, voice_type: VoiceType) -> None:
|
||||||
if self._data is not None:
|
if self._data is not None:
|
||||||
@@ -378,22 +361,22 @@ class DMRPPacketData(DMRPBasePeerPacket):
|
|||||||
# is_voice_term
|
# is_voice_term
|
||||||
@property
|
@property
|
||||||
def is_voice_term(self) -> bool:
|
def is_voice_term(self) -> bool:
|
||||||
return self.voice_type == DMRPPacketData.VoiceType.TERM
|
return self.voice_type == VoiceType.TERM
|
||||||
|
|
||||||
def get_l2(self) -> DMRPL2Base|None:
|
def get_l2(self) -> DMRPL2Base|None:
|
||||||
if self.__l2 is not None:
|
if self.__l2 is not None:
|
||||||
return self.__l2
|
return self.__l2
|
||||||
|
|
||||||
if self.voice_type in (DMRPPacketData.VoiceType.HEAD,
|
if self.voice_type in (VoiceType.HEAD,
|
||||||
DMRPPacketData.VoiceType.TERM):
|
VoiceType.TERM):
|
||||||
self.__l2 = DMRPL2FullLC(self.dmr_data)
|
self.__l2 = DMRPL2FullLC(self.dmr_data)
|
||||||
|
|
||||||
if self.voice_type in (DMRPPacketData.VoiceType.BURST_A,
|
if self.voice_type in (VoiceType.BURST_A,
|
||||||
DMRPPacketData.VoiceType.BURST_B,
|
VoiceType.BURST_B,
|
||||||
DMRPPacketData.VoiceType.BURST_C,
|
VoiceType.BURST_C,
|
||||||
DMRPPacketData.VoiceType.BURST_D,
|
VoiceType.BURST_D,
|
||||||
DMRPPacketData.VoiceType.BURST_E,
|
VoiceType.BURST_E,
|
||||||
DMRPPacketData.VoiceType.BURST_F):
|
VoiceType.BURST_F):
|
||||||
self.__l2 = DMRPL2VoiceBurst(self.dmr_data)
|
self.__l2 = DMRPL2VoiceBurst(self.dmr_data)
|
||||||
|
|
||||||
return self.__l2
|
return self.__l2
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user