diff --git a/src/cursed_hr/cursed_hr.py b/src/cursed_hr/cursed_hr.py index 762579d36..5536fab43 100644 --- a/src/cursed_hr/cursed_hr.py +++ b/src/cursed_hr/cursed_hr.py @@ -20,7 +20,7 @@ from copy import deepcopy from dataclasses import dataclass from datetime import datetime -from enum import IntEnum +from enum import IntEnum, unique from math import ceil from pathlib import Path from typing import Any, BinaryIO, Optional, Union @@ -31,6 +31,7 @@ from gallia.uds.core.service import NegativeResponse, UDSRequest, UDSResponse +@unique class InterpretationColor(IntEnum): DEFAULT = 42 UDS_REQUEST = 43 diff --git a/src/gallia/db/db_handler.py b/src/gallia/db/db_handler.py index 0cdc763df..6cd59931d 100644 --- a/src/gallia/db/db_handler.py +++ b/src/gallia/db/db_handler.py @@ -5,7 +5,7 @@ import asyncio import json from datetime import datetime -from enum import Enum +from enum import Enum, unique from pathlib import Path from typing import Any, Optional @@ -118,6 +118,7 @@ def bytes_repr(data: bytes) -> str: """ +@unique class LogMode(Enum): implicit = "implicit" explicit = "explicit" diff --git a/src/gallia/penlog.py b/src/gallia/penlog.py index 2d6de5e56..898521758 100644 --- a/src/gallia/penlog.py +++ b/src/gallia/penlog.py @@ -2,12 +2,13 @@ # # SPDX-License-Identifier: Apache-2.0 -from enum import Enum +from enum import Enum, unique from typing import Any, Optional import penlog +@unique class MessageType(str, Enum): READ = "read" WRITE = "write" diff --git a/src/gallia/transports/doip.py b/src/gallia/transports/doip.py index d3300bd58..98070838d 100644 --- a/src/gallia/transports/doip.py +++ b/src/gallia/transports/doip.py @@ -7,24 +7,27 @@ import asyncio import struct from dataclasses import dataclass -from enum import IntEnum +from enum import IntEnum, unique from typing import Optional, TypedDict, Union, cast from gallia.penlog import Logger from gallia.transports.base import BaseTransport, TargetURI, _int_spec +@unique class ProtocolVersions(IntEnum): ISO_13400_2_2010 = 0x01 ISO_13400_2_2012 = 0x02 +@unique class RoutingActivationRequestTypes(IntEnum): Default = 0x00 WWH_OBD = 0x01 CentralSecurity = 0xE0 +@unique class RoutingActivationResponseCodes(IntEnum): UnknownSourceAddress = 0x00 NoRessources = 0x01 @@ -37,6 +40,7 @@ class RoutingActivationResponseCodes(IntEnum): SuccessConfirmationRequired = 0x11 +@unique class PayloadTypes(IntEnum): NegativeAcknowledge = 0x0000 VehicleIdentificationRequestMessage = 0x0002 @@ -47,16 +51,18 @@ class PayloadTypes(IntEnum): AliveCheckRequest = 0x0007 AliveCheckResponse = 0x0008 DoIPEntityStatusRequest = 0x4001 - DoIPEntityStatusResponse = 0x4001 + DoIPEntityStatusResponse = 0x4002 DiagnosticMessage = 0x8001 DiagnosticMessagePositiveAcknowledgement = 0x8002 DiagnosticMessageNegativeAcknowledgement = 0x8003 +@unique class DiagnosticMessagePositiveAckCodes(IntEnum): Success = 0x00 +@unique class DiagnosticMessageNegativeAckCodes(IntEnum): InvalidSourceAddress = 0x02 UnknownTargetAddress = 0x03 @@ -67,6 +73,7 @@ class DiagnosticMessageNegativeAckCodes(IntEnum): TransportProtocolError = 0x08 +@unique class GenericHeaderNACKCodes(IntEnum): IncorrectPatternFormat = 0x01 UnknownPayloadType = 0x02 diff --git a/src/gallia/uds/core/constants.py b/src/gallia/uds/core/constants.py index bc7a1f3f1..aa5bfc99b 100644 --- a/src/gallia/uds/core/constants.py +++ b/src/gallia/uds/core/constants.py @@ -2,9 +2,10 @@ # # SPDX-License-Identifier: Apache-2.0 -from enum import IntEnum +from enum import IntEnum, unique +@unique class UDSIsoServices(IntEnum): ShowCurrentData = 0x01 ShowFreezeFrameData = 0x02 @@ -46,6 +47,7 @@ class UDSIsoServices(IntEnum): NegativeResponse = 0x7F +@unique class UDSErrorCodes(IntEnum): generalReject = 0x10 serviceNotSupported = 0x11 @@ -56,7 +58,7 @@ class UDSErrorCodes(IntEnum): conditionsNotCorrect = 0x22 requestSequenceError = 0x24 noResponseFromSubnetComponent = 0x25 - failurePreventsExecutionOfRequestedAction = 0x25 + failurePreventsExecutionOfRequestedAction = 0x26 requestOutOfRange = 0x31 securityAccessDenied = 0x33 authenticationRequired = 0x34 @@ -123,6 +125,7 @@ class UDSErrorCodes(IntEnum): vehicleManufacturerSpecificConditionsNotCorrectFE = 0xFE +@unique class DSCSubFuncs(IntEnum): # defaultSession DS = 0x01 @@ -134,6 +137,7 @@ class DSCSubFuncs(IntEnum): SSDS = 0x04 +@unique class RCSubFuncs(IntEnum): # start routine STR = 0x01 @@ -143,6 +147,7 @@ class RCSubFuncs(IntEnum): RRR = 0x03 +@unique class CCSubFuncs(IntEnum): # enableRxAndTx ERXTX = 0x00 @@ -155,12 +160,14 @@ class CCSubFuncs(IntEnum): # Plus vendor specific stuff... +@unique class CDTCSSubFuncs(IntEnum): ON = 0x01 OFF = 0x02 # Plus vendor specific stuff... +@unique class RDTCISubFuncs(IntEnum): # reportNumberOfDTCByStatusMask RNODTCBSM = 0x01 @@ -190,6 +197,7 @@ class RDTCISubFuncs(IntEnum): RDTCWPS = 0x15 +@unique class ERSubFuncs(IntEnum): # hardReset HR = 0x01 @@ -203,6 +211,7 @@ class ERSubFuncs(IntEnum): DRPSD = 0x05 +@unique class InputOutputControlParameter(IntEnum): # returnControlToECU RCTECU = 0x00 @@ -214,6 +223,7 @@ class InputOutputControlParameter(IntEnum): STA = 0x03 +@unique class DTCFormatIdentifier(IntEnum): # ISO15031-6DTCFormat ISO_15031_6 = 0x00 @@ -256,5 +266,6 @@ class DTCFormatIdentifier(IntEnum): } +@unique class DataIdentifier(IntEnum): ActiveDiagnosticSessionDataIdentifier = 0xF186 diff --git a/src/gallia/udscan/core.py b/src/gallia/udscan/core.py index bc5bdd260..73fe9703f 100644 --- a/src/gallia/udscan/core.py +++ b/src/gallia/udscan/core.py @@ -14,7 +14,7 @@ from argparse import ArgumentDefaultsHelpFormatter, Namespace from asyncio import Task from datetime import datetime, timezone -from enum import Enum, IntEnum +from enum import Enum, IntEnum, unique from importlib.metadata import EntryPoint, entry_points, version from pathlib import Path from secrets import token_urlsafe @@ -37,6 +37,7 @@ from gallia.utils import camel_to_snake, g_repr +@unique class ExitCodes(IntEnum): SUCCESS = 0 GENERIC_ERROR = 1 @@ -44,6 +45,7 @@ class ExitCodes(IntEnum): TEARDOWN_FAILED = 11 +@unique class FileNames(Enum): PROPERTIES_PRE = "PROPERTIES_PRE.json" PROPERTIES_POST = "PROPERTIES_POST.json" diff --git a/src/penlog/__init__.py b/src/penlog/__init__.py index bff4c5d7f..dd1b2aaec 100644 --- a/src/penlog/__init__.py +++ b/src/penlog/__init__.py @@ -11,14 +11,16 @@ import uuid from dataclasses import dataclass, asdict from datetime import datetime -from enum import Enum, IntEnum +from enum import Enum, IntEnum, unique from typing import Any, TextIO, Optional +@unique class MessageType(str, Enum): MESSAGE = "message" +@unique class MessagePrio(IntEnum): EMERGENCY = 0 ALERT = 1 @@ -31,6 +33,7 @@ class MessagePrio(IntEnum): TRACE = 8 +@unique class OutputType(Enum): JSON = "json" JSON_PRETTY = "json-pretty" @@ -39,6 +42,7 @@ class OutputType(Enum): HR_NANO = "hr-nano" +@unique class Color(Enum): NOP = "" RESET = "\033[0m"