DLMS-SPODES 0.87.13__py3-none-any.whl → 0.87.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- DLMS_SPODES/Values/EN/__init__.py +1 -1
- DLMS_SPODES/Values/EN/actors.py +8 -8
- DLMS_SPODES/Values/EN/relation_to_obis_names.py +387 -387
- DLMS_SPODES/Values/RU/__init__.py +1 -1
- DLMS_SPODES/Values/RU/actors.py +8 -8
- DLMS_SPODES/Values/RU/relation_to_obis_names.py +396 -396
- DLMS_SPODES/__init__.py +6 -6
- DLMS_SPODES/configEN.ini +126 -126
- DLMS_SPODES/config_parser.py +53 -53
- DLMS_SPODES/cosem_interface_classes/__class_init__.py +3 -3
- DLMS_SPODES/cosem_interface_classes/__init__.py +1 -1
- DLMS_SPODES/cosem_interface_classes/a_parameter.py +20 -20
- DLMS_SPODES/cosem_interface_classes/activity_calendar.py +254 -254
- DLMS_SPODES/cosem_interface_classes/arbitrator.py +105 -105
- DLMS_SPODES/cosem_interface_classes/association_ln/abstract.py +34 -34
- DLMS_SPODES/cosem_interface_classes/association_ln/authentication_mechanism_name.py +25 -25
- DLMS_SPODES/cosem_interface_classes/association_ln/mechanism_id.py +25 -25
- DLMS_SPODES/cosem_interface_classes/association_ln/method.py +5 -5
- DLMS_SPODES/cosem_interface_classes/association_ln/ver0.py +485 -485
- DLMS_SPODES/cosem_interface_classes/association_ln/ver1.py +133 -133
- DLMS_SPODES/cosem_interface_classes/association_ln/ver2.py +36 -36
- DLMS_SPODES/cosem_interface_classes/association_ln/ver3.py +4 -4
- DLMS_SPODES/cosem_interface_classes/association_sn/ver0.py +12 -12
- DLMS_SPODES/cosem_interface_classes/attr_indexes.py +12 -12
- DLMS_SPODES/cosem_interface_classes/clock.py +131 -131
- DLMS_SPODES/cosem_interface_classes/collection.py +2122 -2122
- DLMS_SPODES/cosem_interface_classes/cosem_interface_class.py +583 -583
- DLMS_SPODES/cosem_interface_classes/data.py +21 -21
- DLMS_SPODES/cosem_interface_classes/demand_register/ver0.py +59 -59
- DLMS_SPODES/cosem_interface_classes/disconnect_control.py +74 -74
- DLMS_SPODES/cosem_interface_classes/extended_register.py +27 -27
- DLMS_SPODES/cosem_interface_classes/gprs_modem_setup.py +43 -43
- DLMS_SPODES/cosem_interface_classes/gsm_diagnostic/ver0.py +103 -103
- DLMS_SPODES/cosem_interface_classes/gsm_diagnostic/ver1.py +40 -40
- DLMS_SPODES/cosem_interface_classes/gsm_diagnostic/ver2.py +9 -9
- DLMS_SPODES/cosem_interface_classes/iec_hdlc_setup/ver0.py +11 -11
- DLMS_SPODES/cosem_interface_classes/iec_hdlc_setup/ver1.py +53 -53
- DLMS_SPODES/cosem_interface_classes/iec_local_port_setup.py +11 -11
- DLMS_SPODES/cosem_interface_classes/image_transfer/image_transfer_status.py +15 -15
- DLMS_SPODES/cosem_interface_classes/image_transfer/ver0.py +126 -126
- DLMS_SPODES/cosem_interface_classes/implementations/__init__.py +3 -3
- DLMS_SPODES/cosem_interface_classes/implementations/arbitrator.py +19 -19
- DLMS_SPODES/cosem_interface_classes/implementations/data.py +487 -487
- DLMS_SPODES/cosem_interface_classes/implementations/profile_generic.py +83 -83
- DLMS_SPODES/cosem_interface_classes/ipv4_setup.py +72 -72
- DLMS_SPODES/cosem_interface_classes/limiter.py +111 -111
- DLMS_SPODES/cosem_interface_classes/ln_pattern.py +333 -333
- DLMS_SPODES/cosem_interface_classes/modem_configuration/ver0.py +65 -65
- DLMS_SPODES/cosem_interface_classes/modem_configuration/ver1.py +39 -39
- DLMS_SPODES/cosem_interface_classes/ntp_setup/ver0.py +67 -67
- DLMS_SPODES/cosem_interface_classes/obis.py +23 -23
- DLMS_SPODES/cosem_interface_classes/overview.py +197 -197
- DLMS_SPODES/cosem_interface_classes/parameter.py +547 -547
- DLMS_SPODES/cosem_interface_classes/parameters.py +172 -172
- DLMS_SPODES/cosem_interface_classes/profile_generic/ver0.py +122 -122
- DLMS_SPODES/cosem_interface_classes/profile_generic/ver1.py +277 -277
- DLMS_SPODES/cosem_interface_classes/push_setup/ver0.py +12 -12
- DLMS_SPODES/cosem_interface_classes/push_setup/ver1.py +10 -10
- DLMS_SPODES/cosem_interface_classes/push_setup/ver2.py +166 -166
- DLMS_SPODES/cosem_interface_classes/register.py +45 -45
- DLMS_SPODES/cosem_interface_classes/register_activation/ver0.py +80 -80
- DLMS_SPODES/cosem_interface_classes/register_monitor.py +46 -46
- DLMS_SPODES/cosem_interface_classes/reports.py +70 -70
- DLMS_SPODES/cosem_interface_classes/schedule.py +176 -176
- DLMS_SPODES/cosem_interface_classes/script_table.py +87 -87
- DLMS_SPODES/cosem_interface_classes/security_setup/ver0.py +68 -68
- DLMS_SPODES/cosem_interface_classes/security_setup/ver1.py +158 -158
- DLMS_SPODES/cosem_interface_classes/single_action_schedule.py +50 -50
- DLMS_SPODES/cosem_interface_classes/special_days_table.py +84 -84
- DLMS_SPODES/cosem_interface_classes/tcp_udp_setup.py +42 -42
- DLMS_SPODES/cosem_pdu.py +93 -93
- DLMS_SPODES/enums.py +625 -625
- DLMS_SPODES/exceptions.py +106 -106
- DLMS_SPODES/firmwares.py +99 -99
- DLMS_SPODES/hdlc/frame.py +875 -875
- DLMS_SPODES/hdlc/sub_layer.py +54 -54
- DLMS_SPODES/literals.py +17 -17
- DLMS_SPODES/obis/__init__.py +1 -1
- DLMS_SPODES/obis/media_id.py +931 -931
- DLMS_SPODES/pardata.py +22 -22
- DLMS_SPODES/pdu_enums.py +98 -98
- DLMS_SPODES/relation_to_OBIS.py +465 -463
- DLMS_SPODES/settings.py +551 -551
- DLMS_SPODES/types/choices.py +142 -142
- DLMS_SPODES/types/common_data_types.py +2401 -2401
- DLMS_SPODES/types/cosem_service_types.py +109 -109
- DLMS_SPODES/types/implementations/arrays.py +25 -25
- DLMS_SPODES/types/implementations/bitstrings.py +97 -97
- DLMS_SPODES/types/implementations/double_long_usingneds.py +35 -35
- DLMS_SPODES/types/implementations/enums.py +57 -57
- DLMS_SPODES/types/implementations/integers.py +11 -11
- DLMS_SPODES/types/implementations/long_unsigneds.py +127 -127
- DLMS_SPODES/types/implementations/octet_string.py +11 -11
- DLMS_SPODES/types/implementations/structs.py +64 -64
- DLMS_SPODES/types/useful_types.py +677 -677
- {dlms_spodes-0.87.13.dist-info → dlms_spodes-0.87.16.dist-info}/METADATA +30 -30
- dlms_spodes-0.87.16.dist-info/RECORD +117 -0
- {dlms_spodes-0.87.13.dist-info → dlms_spodes-0.87.16.dist-info}/WHEEL +1 -1
- dlms_spodes-0.87.13.dist-info/RECORD +0 -117
- {dlms_spodes-0.87.13.dist-info → dlms_spodes-0.87.16.dist-info}/top_level.txt +0 -0
|
@@ -1,583 +1,583 @@
|
|
|
1
|
-
"""
|
|
2
|
-
DLMS UA 1000-1 Ed 14
|
|
3
|
-
"""
|
|
4
|
-
from dataclasses import dataclass, field
|
|
5
|
-
from functools import lru_cache
|
|
6
|
-
from typing_extensions import deprecated
|
|
7
|
-
from typing import Iterator, Type, TypeAlias, Callable, Any, Self, Literal, Optional, Protocol, ClassVar
|
|
8
|
-
from ..types import cdt, ut, cst
|
|
9
|
-
from StructResult import result
|
|
10
|
-
from ..relation_to_OBIS import get_name
|
|
11
|
-
from enum import IntEnum
|
|
12
|
-
from itertools import count
|
|
13
|
-
from .. import exceptions as exc
|
|
14
|
-
from .overview import ClassID
|
|
15
|
-
from ..settings import settings
|
|
16
|
-
from .. import literals
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_n_class = count(0)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Classifier(IntEnum):
|
|
23
|
-
""" (dyn.) Classifies an attribute that carries a process value, which is updated by the meter itself.
|
|
24
|
-
(static) Classifies an attribute, which is not updated by the meter itself (e.g. configuration data). """
|
|
25
|
-
NOT_SPECIFIC = 0
|
|
26
|
-
STATIC = 1
|
|
27
|
-
DYNAMIC = 2
|
|
28
|
-
|
|
29
|
-
def __str__(self):
|
|
30
|
-
return self.name
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
SelectiveAccessDescriptor: TypeAlias = ut.SelectiveAccessDescriptor # TODO: make with subclass
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@dataclass(frozen=True)
|
|
37
|
-
class ICElement:
|
|
38
|
-
NAME: str
|
|
39
|
-
|
|
40
|
-
def __str__(self) -> str:
|
|
41
|
-
try:
|
|
42
|
-
return getattr(settings.am_names, self.NAME)
|
|
43
|
-
except AttributeError:
|
|
44
|
-
return self.NAME
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@dataclass(frozen=True)
|
|
48
|
-
class ICAElement(ICElement):
|
|
49
|
-
DATA_TYPE: Type[cdt.CommonDataType] | ut.CHOICE
|
|
50
|
-
min: int = None
|
|
51
|
-
max: int = None
|
|
52
|
-
default: int = None
|
|
53
|
-
classifier: Classifier = Classifier.STATIC
|
|
54
|
-
selective_access: Type[SelectiveAccessDescriptor] | None = None
|
|
55
|
-
|
|
56
|
-
def get_change(self,
|
|
57
|
-
data_type: Type[cdt.CommonDataType] | ut.CHOICE = None,
|
|
58
|
-
classifier: Classifier = None) -> Self:
|
|
59
|
-
return ICAElement(
|
|
60
|
-
NAME=self.NAME,
|
|
61
|
-
DATA_TYPE=self.DATA_TYPE if data_type is None else data_type,
|
|
62
|
-
min=self.min,
|
|
63
|
-
max=self.max,
|
|
64
|
-
default=self.default,
|
|
65
|
-
classifier=self.classifier if classifier is None else classifier,
|
|
66
|
-
selective_access=self.selective_access)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@dataclass(frozen=True)
|
|
70
|
-
class ICMElement(ICElement):
|
|
71
|
-
DATA_TYPE: Type[cdt.CommonDataType]
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_LN_ELEMENT: ICAElement = ICAElement(
|
|
75
|
-
NAME="logical_name",
|
|
76
|
-
DATA_TYPE=cst.LogicalName)
|
|
77
|
-
"""" first element for each COSEM Interface Class"""
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class ObjectValidationError(exc.DLMSException):
|
|
81
|
-
"""use in validation method of COSEMInterfaceClasses"""
|
|
82
|
-
def __init__(self,
|
|
83
|
-
ln: cst.LogicalName,
|
|
84
|
-
i: int,
|
|
85
|
-
message: str):
|
|
86
|
-
Exception.__init__(self, F"for {ln}: {i}. {message}")
|
|
87
|
-
self.ln = ln
|
|
88
|
-
self.i = i
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
class EmptyAttribute(exc.DLMSException):
|
|
92
|
-
"""need read attribute"""
|
|
93
|
-
def __init__(self,
|
|
94
|
-
ln: cst.LogicalName,
|
|
95
|
-
i: int):
|
|
96
|
-
Exception.__init__(self, F"empty {ln}: {i}")
|
|
97
|
-
self.ln = ln
|
|
98
|
-
self.i = i
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
Name: Literal = Literal[
|
|
102
|
-
"Data",
|
|
103
|
-
"Register",
|
|
104
|
-
"Extended register",
|
|
105
|
-
"Demand register",
|
|
106
|
-
"Register activation",
|
|
107
|
-
"Profile generic",
|
|
108
|
-
"Clock",
|
|
109
|
-
"Script table",
|
|
110
|
-
"Schedule",
|
|
111
|
-
"Special days table",
|
|
112
|
-
"Association SN",
|
|
113
|
-
"Association LN",
|
|
114
|
-
"SAP Assignment",
|
|
115
|
-
"Image transfer",
|
|
116
|
-
"IEC local port setup",
|
|
117
|
-
"Activity calendar",
|
|
118
|
-
"Register monitor",
|
|
119
|
-
"Single action schedule",
|
|
120
|
-
"IEC HDLC setup",
|
|
121
|
-
"IEC twisted pair (1) setup",
|
|
122
|
-
"M-BUS slave port setup",
|
|
123
|
-
"Utility tables",
|
|
124
|
-
"Modem configuration",
|
|
125
|
-
"PSTN modem configuration",
|
|
126
|
-
"Auto answer",
|
|
127
|
-
"Auto connect",
|
|
128
|
-
"PSTN Auto dial",
|
|
129
|
-
"Data protection",
|
|
130
|
-
"Push setup",
|
|
131
|
-
"TCP-UDP setup",
|
|
132
|
-
"IPv4 setup",
|
|
133
|
-
"MAC address setup",
|
|
134
|
-
"PPP setup",
|
|
135
|
-
"GPRS modem setup",
|
|
136
|
-
"SMTP setup",
|
|
137
|
-
"GSM diagnostic",
|
|
138
|
-
"IPv6 setup",
|
|
139
|
-
"S-FSK Phy&MAC setup",
|
|
140
|
-
"S-FSK Active initiator",
|
|
141
|
-
"S-FSK MAC synchronization timeouts",
|
|
142
|
-
"S-FSK MAC counters",
|
|
143
|
-
"IEC 61334-4-32 LLC setup",
|
|
144
|
-
"S-FSK IEC 61334-4-32 LLC setup",
|
|
145
|
-
"S-FSK Reporting system list",
|
|
146
|
-
"ISO/IEC 8802-2 LLC Type 1 setup",
|
|
147
|
-
"ISO/IEC 8802-2 LLC Type 2 setup",
|
|
148
|
-
"ISO/IEC 8802-2 LLC Type 3 setup",
|
|
149
|
-
"Register table",
|
|
150
|
-
"Compact data",
|
|
151
|
-
"Status mapping",
|
|
152
|
-
"Security setup",
|
|
153
|
-
"Parameter monitor",
|
|
154
|
-
"Sensor manager",
|
|
155
|
-
"Arbitrator",
|
|
156
|
-
"Disconnect control",
|
|
157
|
-
"Limiter",
|
|
158
|
-
"M-Bus client",
|
|
159
|
-
"Wireless Mode Q channel",
|
|
160
|
-
"M-Bus master port setup",
|
|
161
|
-
"DLMS/COSEM server M-Bus port setup",
|
|
162
|
-
"M-Bus diagnostic",
|
|
163
|
-
"61334-4-32 LLC SSCS setup",
|
|
164
|
-
"PRIME NB OFDM PLC Physical layer counters",
|
|
165
|
-
"PRIME NB OFDM PLC MAC setup",
|
|
166
|
-
"PRIME NB OFDM PLC MAC functional parameters",
|
|
167
|
-
"PRIME NB OFDM PLC MAC counters",
|
|
168
|
-
"PRIME NB OFDM PLC MAC network administration data",
|
|
169
|
-
"PRIME NB OFDM PLC Application identification",
|
|
170
|
-
"G3-PLC MAC layer counters",
|
|
171
|
-
"G3 NB OFDM PLC MAC layer counters",
|
|
172
|
-
"G3-PLC MAC setup",
|
|
173
|
-
"G3 NB OFDM PLC MAC setup",
|
|
174
|
-
"G3-PLC 6LoWPAN adaptation layer setup",
|
|
175
|
-
"G3 NB OFDM PLC 6LoWPAN adaptation layer setup",
|
|
176
|
-
"Wi-SUN setup",
|
|
177
|
-
"Wi-SUN diagnostic",
|
|
178
|
-
"RPL diagnostic",
|
|
179
|
-
"MPL diagnostic",
|
|
180
|
-
"NTP Setup",
|
|
181
|
-
"ZigBee® SAS startup",
|
|
182
|
-
"ZigBee® SAS join",
|
|
183
|
-
"ZigBee® SAS APS fragmentation",
|
|
184
|
-
"ZigBee® network control",
|
|
185
|
-
"ZigBee® tunnel setup",
|
|
186
|
-
"Account",
|
|
187
|
-
"Credit",
|
|
188
|
-
"Charge",
|
|
189
|
-
"Token gateway",
|
|
190
|
-
"Function control",
|
|
191
|
-
"Array manager",
|
|
192
|
-
"Communication port protection",
|
|
193
|
-
"SCHC-LPWAN setup",
|
|
194
|
-
"SCHC-LPWAN diagnostic",
|
|
195
|
-
"LoRaWAN setup",
|
|
196
|
-
"LoRaWAN diagnostic",
|
|
197
|
-
"ISO/IEC14908 Identification",
|
|
198
|
-
"ISO/IEC 14908 Protocol setup",
|
|
199
|
-
"ISO/IEC 14908 protocol status",
|
|
200
|
-
"ISO/IEC 14908 diagnostic",
|
|
201
|
-
"HS-PLC ISO/IEC 12139-1 MAC setup",
|
|
202
|
-
"HS-PLC ISO/IEC 12139-1 CPAS setup",
|
|
203
|
-
"HS-PLC ISO/IEC 12139-1 IP SSAS setup",
|
|
204
|
-
"HS-PLC ISO/IEC 12139-1 HDLC SSAS setup",
|
|
205
|
-
"LTE monitoring"
|
|
206
|
-
]
|
|
207
|
-
"""Interface class name row from Table 3 – List of interface classes by class_id"""
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
@lru_cache(150)
|
|
211
|
-
def ClassIDVer2Name(class_id: ClassID, ver: cdt.Unsigned) -> Name:
|
|
212
|
-
"""Table 3 – List of interface classes by class_id"""
|
|
213
|
-
match int(class_id), int(ver):
|
|
214
|
-
case 1, 0: return "Data"
|
|
215
|
-
case 3, 0: return "Register"
|
|
216
|
-
case 4, 0: return "Extended register"
|
|
217
|
-
case 5, 0: return "Demand register"
|
|
218
|
-
case 6, 0: return "Register activation"
|
|
219
|
-
case 7, 0 | 1: return "Profile generic"
|
|
220
|
-
case 8, 0: return "Clock"
|
|
221
|
-
case 9, 0: return "Script table"
|
|
222
|
-
case 10, 0: return "Schedule"
|
|
223
|
-
case 11, 0: return "Special days table"
|
|
224
|
-
case 12, 0 | 1 | 2 | 3 | 4: return "Association SN"
|
|
225
|
-
case 15, 0 | 1 | 2 | 3: return "Association LN"
|
|
226
|
-
case 17, 0: return "SAP Assignment"
|
|
227
|
-
case 18, 0: return "Image transfer"
|
|
228
|
-
case 19, 0 | 1: return "IEC local port setup"
|
|
229
|
-
case 20, 0: return "Activity calendar"
|
|
230
|
-
case 21, 0: return "Register monitor"
|
|
231
|
-
case 22, 0: return "Single action schedule"
|
|
232
|
-
case 23, 0 | 1: return "IEC HDLC setup"
|
|
233
|
-
case 24, 0 | 1: return "IEC twisted pair (1) setup"
|
|
234
|
-
case 25, 0: return "M-BUS slave port setup"
|
|
235
|
-
case 26, 0: return "Utility tables"
|
|
236
|
-
case 27, 1: return "Modem configuration"
|
|
237
|
-
case 27, 0: return "PSTN modem configuration"
|
|
238
|
-
case 28, 0 | 2: return "Auto answer"
|
|
239
|
-
case 29, 1 | 2: return "Auto connect"
|
|
240
|
-
case 29, 0: return "PSTN Auto dial"
|
|
241
|
-
case 30, 0: return "Data protection"
|
|
242
|
-
case 40, 0 | 1 | 2: return "Push setup"
|
|
243
|
-
case 41, 0: return "TCP-UDP setup"
|
|
244
|
-
case 42, 0: return "IPv4 setup"
|
|
245
|
-
case 43, 0: return "MAC address setup"
|
|
246
|
-
case 44, 0: return "PPP setup"
|
|
247
|
-
case 45, 0: return "GPRS modem setup"
|
|
248
|
-
case 46, 0: return "SMTP setup"
|
|
249
|
-
case 47, 0 | 1 | 2: return "GSM diagnostic"
|
|
250
|
-
case 48, 0: return "IPv6 setup"
|
|
251
|
-
case 50, 0 | 1: return "S-FSK Phy&MAC setup"
|
|
252
|
-
case 51, 0: return "S-FSK Active initiator"
|
|
253
|
-
case 52, 0: return "S-FSK MAC synchronization timeouts"
|
|
254
|
-
case 53, 0: return "S-FSK MAC counters"
|
|
255
|
-
case 55, 1: return "IEC 61334-4-32 LLC setup"
|
|
256
|
-
case 55, 0: return "S-FSK IEC 61334-4-32 LLC setup"
|
|
257
|
-
case 56, 0: return "S-FSK Reporting system list"
|
|
258
|
-
case 57, 0: return "ISO/IEC 8802-2 LLC Type 1 setup"
|
|
259
|
-
case 58, 0: return "ISO/IEC 8802-2 LLC Type 2 setup"
|
|
260
|
-
case 59, 0: return "ISO/IEC 8802-2 LLC Type 3 setup"
|
|
261
|
-
case 61, 0: return "Register table"
|
|
262
|
-
case 62, 0 | 1: return "Compact data"
|
|
263
|
-
case 63, 0: return "Status mapping"
|
|
264
|
-
case 64, 0 | 1: return "Security setup"
|
|
265
|
-
case 65, 0 | 1: return "Parameter monitor"
|
|
266
|
-
case 67, 0: return "Sensor manager"
|
|
267
|
-
case 68, 0: return "Arbitrator"
|
|
268
|
-
case 70, 0: return "Disconnect control"
|
|
269
|
-
case 71, 0: return "Limiter"
|
|
270
|
-
case 72, 0 | 1: return "M-Bus client"
|
|
271
|
-
case 73, 0: return "Wireless Mode Q channel"
|
|
272
|
-
case 74, 0: return "M-Bus master port setup"
|
|
273
|
-
case 76, 0: return "DLMS/COSEM server M-Bus port setup"
|
|
274
|
-
case 77, 0: return "M-Bus diagnostic"
|
|
275
|
-
case 80, 0: return "61334-4-32 LLC SSCS setup"
|
|
276
|
-
case 81, 0: return "PRIME NB OFDM PLC Physical layer counters"
|
|
277
|
-
case 82, 0: return "PRIME NB OFDM PLC MAC setup"
|
|
278
|
-
case 83, 0: return "PRIME NB OFDM PLC MAC functional parameters"
|
|
279
|
-
case 84, 0: return "PRIME NB OFDM PLC MAC counters"
|
|
280
|
-
case 85, 0: return "PRIME NB OFDM PLC MAC network administration data"
|
|
281
|
-
case 86, 0: return "PRIME NB OFDM PLC Application identification"
|
|
282
|
-
case 90, 1: return "G3-PLC MAC layer counters"
|
|
283
|
-
case 90, 0: return "G3 NB OFDM PLC MAC layer counters"
|
|
284
|
-
case 91, 1 | 2: return "G3-PLC MAC setup"
|
|
285
|
-
case 91, 0: return "G3 NB OFDM PLC MAC setup"
|
|
286
|
-
case 92, 1 | 2: return "G3-PLC 6LoWPAN adaptation layer setup"
|
|
287
|
-
case 92, 0: return "G3 NB OFDM PLC 6LoWPAN adaptation layer setup"
|
|
288
|
-
case 95, 0: return "Wi-SUN setup"
|
|
289
|
-
case 96, 0: return "Wi-SUN diagnostic"
|
|
290
|
-
case 97, 0: return "RPL diagnostic"
|
|
291
|
-
case 98, 0: return "MPL diagnostic"
|
|
292
|
-
case 100, 0: return "NTP Setup"
|
|
293
|
-
case 101, 0: return "ZigBee® SAS startup"
|
|
294
|
-
case 102, 0: return "ZigBee® SAS join"
|
|
295
|
-
case 103, 0: return "ZigBee® SAS APS fragmentation"
|
|
296
|
-
case 104, 0: return "ZigBee® network control"
|
|
297
|
-
case 104, 0: return "ZigBee® tunnel setup"
|
|
298
|
-
case 111, 0: return "Account"
|
|
299
|
-
case 112, 0: return "Credit"
|
|
300
|
-
case 113, 0: return "Charge"
|
|
301
|
-
case 115, 0: return "Token gateway"
|
|
302
|
-
case 122, 0: return "Function control"
|
|
303
|
-
case 123, 0: return "Array manager"
|
|
304
|
-
case 124, 0: return "Communication port protection"
|
|
305
|
-
case 126, 0: return "SCHC-LPWAN setup"
|
|
306
|
-
case 127, 0: return "SCHC-LPWAN diagnostic"
|
|
307
|
-
case 128, 0: return "LoRaWAN setup"
|
|
308
|
-
case 129, 0: return "LoRaWAN diagnostic"
|
|
309
|
-
case 130, 0: return "ISO/IEC14908 Identification"
|
|
310
|
-
case 131, 0: return "ISO/IEC 14908 Protocol setup"
|
|
311
|
-
case 132, 1: return "ISO/IEC 14908 protocol status"
|
|
312
|
-
case 133, 1: return "ISO/IEC 14908 diagnostic"
|
|
313
|
-
case 140, 0: return "HS-PLC ISO/IEC 12139-1 MAC setup"
|
|
314
|
-
case 141, 0: return "HS-PLC ISO/IEC 12139-1 CPAS setup"
|
|
315
|
-
case 142, 0: return "HS-PLC ISO/IEC 12139-1 IP SSAS setup"
|
|
316
|
-
case 143, 0: return "HS-PLC ISO/IEC 12139-1 HDLC SSAS setup"
|
|
317
|
-
case 151, 0 | 1: return "LTE monitoring"
|
|
318
|
-
case _: raise exc.ITEApplication(F"not find <Interface class name> with: {class_id=}, {ver=}")
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
@dataclass
|
|
322
|
-
class Cardinality:
|
|
323
|
-
"""4.1.4 Class description notation"""
|
|
324
|
-
min: int = 0
|
|
325
|
-
max: int = -1
|
|
326
|
-
"""default -1 as infinity"""
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
class COSEMInterfaceClasses(Protocol):
|
|
330
|
-
CLASS_ID: ClassVar[ut.CosemClassId]
|
|
331
|
-
VERSION: ClassVar[cdt.Unsigned]
|
|
332
|
-
""" Identification code of the version of the class. The version of each object is retrieved together with the logical name and the class_id by reading the object_list
|
|
333
|
-
attribute of an “Association LN” / ”Association SN” object. Within one logical device, all instances of a certain class must be of the same version."""
|
|
334
|
-
A_ELEMENTS: tuple[ICAElement, ...]
|
|
335
|
-
cardinality: ClassVar[Cardinality] = field(default_factory=Cardinality)
|
|
336
|
-
M_ELEMENTS: tuple[ICMElement, ...] = tuple() # empty if class not has the methods
|
|
337
|
-
__attributes: list[cdt.CommonDataType | None]
|
|
338
|
-
__specific_methods: tuple[cdt.CommonDataType, ...] = None
|
|
339
|
-
_cbs_attr_post_init: dict[int, Callable]
|
|
340
|
-
# collection: Any | None # Collection. todo: remove in future
|
|
341
|
-
hash_: int
|
|
342
|
-
|
|
343
|
-
def __init__(self, logical_name: cst.LogicalName | bytes | str):
|
|
344
|
-
self.collection = None
|
|
345
|
-
# """ TODO: """
|
|
346
|
-
self.cardinality = (0, None)
|
|
347
|
-
""" (min, max). default is (0, None) from 0 to infinity. If min == max then they are value.
|
|
348
|
-
Specifies the number of instances of the class within a logical device. value The class shall be
|
|
349
|
-
instantiated exactly “value” times. min...max. The class shall be instantiated at least “min.” times
|
|
350
|
-
and at most “max.” times. If min. is zero (0) then the class is optional, otherwise (min. > 0) "min."
|
|
351
|
-
instantiations of the class are mandatory. """
|
|
352
|
-
|
|
353
|
-
self.__attributes = [_LN_ELEMENT.DATA_TYPE(logical_name), *[None] * len(self.A_ELEMENTS)]
|
|
354
|
-
""" Attributes container """
|
|
355
|
-
|
|
356
|
-
if self.M_ELEMENTS is not None:
|
|
357
|
-
self.__specific_methods = tuple(el.DATA_TYPE() for el in self.M_ELEMENTS)
|
|
358
|
-
"""Specific methods container"""
|
|
359
|
-
|
|
360
|
-
self._cbs_attr_post_init = dict()
|
|
361
|
-
"""container with callbacks for post initial attribute by index"""
|
|
362
|
-
|
|
363
|
-
self._cbs_attr_before_init = dict()
|
|
364
|
-
"""container with callbacks for before initial attribute by index"""
|
|
365
|
-
|
|
366
|
-
# init all attributes with default value
|
|
367
|
-
for i in range(2, len(self.A_ELEMENTS)+2):
|
|
368
|
-
default = self.get_attr_element(i).default
|
|
369
|
-
if default is not None:
|
|
370
|
-
self.set_attr(i, default)
|
|
371
|
-
|
|
372
|
-
self.characteristics_init()
|
|
373
|
-
|
|
374
|
-
def __init_subclass__(cls, **kwargs):
|
|
375
|
-
super().__init_subclass__(**kwargs)
|
|
376
|
-
cls.hash_ = next(_n_class)
|
|
377
|
-
# print(cls.__name__)
|
|
378
|
-
|
|
379
|
-
@classmethod
|
|
380
|
-
@deprecated("use <getAElement>")
|
|
381
|
-
def get_attr_element(cls, i: int) -> ICAElement:
|
|
382
|
-
"""return element by order index. Override in each new class"""
|
|
383
|
-
if i == 1:
|
|
384
|
-
return _LN_ELEMENT
|
|
385
|
-
elif i > len(cls.A_ELEMENTS) + 1:
|
|
386
|
-
raise exc.DLMSException(F"got attribute index: {i}, expected 1..{len(cls.A_ELEMENTS) + 1}")
|
|
387
|
-
else:
|
|
388
|
-
return cls.A_ELEMENTS[i - 2]
|
|
389
|
-
|
|
390
|
-
@classmethod
|
|
391
|
-
def getAElement(cls, i: int) -> result.Simple[ICAElement] | result.Error:
|
|
392
|
-
"""return element by order index. Override in each new class"""
|
|
393
|
-
if i == 1:
|
|
394
|
-
return result.Simple(_LN_ELEMENT)
|
|
395
|
-
elif i > len(cls.A_ELEMENTS) + 1:
|
|
396
|
-
return result.Error.from_e(exc.DLMSException(F"got attribute index: {i}, expected 1..{len(cls.A_ELEMENTS) + 1}"))
|
|
397
|
-
else:
|
|
398
|
-
return result.Simple(cls.A_ELEMENTS[i - 2])
|
|
399
|
-
|
|
400
|
-
@classmethod
|
|
401
|
-
def get_meth_element(cls, i: int) -> ICMElement:
|
|
402
|
-
""" implement in subclasses with methods """
|
|
403
|
-
return cls.M_ELEMENTS[i - 1]
|
|
404
|
-
|
|
405
|
-
def characteristics_init(self):
|
|
406
|
-
""" initiate all attributes and methods of class """
|
|
407
|
-
|
|
408
|
-
def get_attr(self, index: int) -> Optional[cdt.CommonDataType]:
|
|
409
|
-
if index > (max_l := self.get_attr_length()):
|
|
410
|
-
raise IndexError(F"for {self} got attribute index: {index}, expected 0..{max_l}")
|
|
411
|
-
elif index >= 1:
|
|
412
|
-
return self.__attributes[index-1]
|
|
413
|
-
else:
|
|
414
|
-
raise IndexError(F"not support {index=} as attribute")
|
|
415
|
-
|
|
416
|
-
def set_attr_force(self,
|
|
417
|
-
index: int,
|
|
418
|
-
value: cdt.CommonDataType):
|
|
419
|
-
self.__attributes[index-1] = value
|
|
420
|
-
"""use for change official types to custom(not valid)"""
|
|
421
|
-
|
|
422
|
-
def encode(self,
|
|
423
|
-
index: int,
|
|
424
|
-
value: str | int) -> cdt.CommonDataType | None:
|
|
425
|
-
"""encode attribute value from string if possible, else return None(for CHOICE variant)"""
|
|
426
|
-
if (attr := self.get_attr(index)) is None:
|
|
427
|
-
data_type = self.get_attr_element(index).DATA_TYPE
|
|
428
|
-
if isinstance(data_type, ut.CHOICE):
|
|
429
|
-
return None
|
|
430
|
-
else:
|
|
431
|
-
return self.get_attr_element(index).DATA_TYPE(value)
|
|
432
|
-
else:
|
|
433
|
-
ret = attr.copy()
|
|
434
|
-
ret.set(value)
|
|
435
|
-
return ret
|
|
436
|
-
|
|
437
|
-
def set_attr(self,
|
|
438
|
-
index: int,
|
|
439
|
-
value=None,
|
|
440
|
-
data_type: cdt.CommonDataType = None):
|
|
441
|
-
value = self.get_attr_element(index).default if value is None else value
|
|
442
|
-
data_type = self.get_attr_element(index).DATA_TYPE if data_type is None else data_type
|
|
443
|
-
if self.__attributes[index-1] is None:
|
|
444
|
-
new_value = data_type(value)
|
|
445
|
-
if cb_func := self._cbs_attr_before_init.get(index, None):
|
|
446
|
-
cb_func(new_value)
|
|
447
|
-
self._cbs_attr_before_init.pop(index)
|
|
448
|
-
self.__attributes[index-1] = new_value
|
|
449
|
-
if cb_func := self._cbs_attr_post_init.get(index, None):
|
|
450
|
-
cb_func()
|
|
451
|
-
self._cbs_attr_post_init.pop(index)
|
|
452
|
-
else:
|
|
453
|
-
"""without callback post init"""
|
|
454
|
-
else:
|
|
455
|
-
self.__attributes[index-1].set(value)
|
|
456
|
-
|
|
457
|
-
def parse_attr(self, index: int, value: cdt.Transcript, data_type: cdt.CommonDataType = None):
|
|
458
|
-
"""set attribute value by Transcript"""
|
|
459
|
-
dt = self.get_attr_element(index).DATA_TYPE if data_type is None else data_type
|
|
460
|
-
if hasattr(dt, "TAG"):
|
|
461
|
-
self.__attributes[index - 1] = dt.parse(value)
|
|
462
|
-
else: # maybe CHOICE
|
|
463
|
-
self.__attributes[index - 1] = self.get_attr(index).parse(value)
|
|
464
|
-
|
|
465
|
-
def set_attr_link(self, index: int, link: cdt.CommonDataType):
|
|
466
|
-
# self.__attributes[index - 1] = link # TODO: without validate now for pass load_objects
|
|
467
|
-
if isinstance(link, self.get_attr_element(index).DATA_TYPE):
|
|
468
|
-
self.__attributes[index-1] = link
|
|
469
|
-
else:
|
|
470
|
-
raise ValueError(F'get wrong link: {link} for {self} attr: {index}')
|
|
471
|
-
|
|
472
|
-
def get_attr_data_type(self, index: int) -> Type[cdt.CommonDataType] | ut.CHOICE:
|
|
473
|
-
"""search data_type attribute value"""
|
|
474
|
-
value: cdt.CommonDataType = self.get_attr(index)
|
|
475
|
-
if value is not None:
|
|
476
|
-
return value.__class__
|
|
477
|
-
else:
|
|
478
|
-
return self.get_attr_element(index).DATA_TYPE
|
|
479
|
-
|
|
480
|
-
def clear_attr(self, i: int):
|
|
481
|
-
"""use in template"""
|
|
482
|
-
if i > 1:
|
|
483
|
-
self.__attributes[i-1] = None
|
|
484
|
-
else:
|
|
485
|
-
raise ValueError(F'not support clear {self} attr: {i}')
|
|
486
|
-
|
|
487
|
-
@deprecated("use get_meth_element")
|
|
488
|
-
def get_meth(self, index: int) -> Any:
|
|
489
|
-
if index >= 1:
|
|
490
|
-
return self.__specific_methods[index-1]
|
|
491
|
-
else:
|
|
492
|
-
raise IndexError(F'not support {index=} as attribute')
|
|
493
|
-
|
|
494
|
-
def get_index_with_attributes(self) -> Iterator[tuple[int, cdt.CommonDataType | None]]:
|
|
495
|
-
""" if by initiation order is True then need override method for concrete class"""
|
|
496
|
-
return iter(zip(range(1, self.get_attr_length()+1), self.__attributes))
|
|
497
|
-
|
|
498
|
-
def get_attr_length(self) -> int:
|
|
499
|
-
"""common attributes amount"""
|
|
500
|
-
return len(self.A_ELEMENTS)+1
|
|
501
|
-
|
|
502
|
-
@property
|
|
503
|
-
def it_index_with_meth(self) -> Iterator[tuple[int, cdt.CommonDataType]]:
|
|
504
|
-
return iter(zip(range(1, 20), self.__specific_methods))
|
|
505
|
-
|
|
506
|
-
@property
|
|
507
|
-
def logical_name(self) -> cst.LogicalName:
|
|
508
|
-
""" The logical name is always the first attribute of a class. It identifies the instantiation (COSEM object) of this class.
|
|
509
|
-
The value of the logical_name conforms to OBIS (see IEC 62056-61)"""
|
|
510
|
-
return self.get_attr(1)
|
|
511
|
-
|
|
512
|
-
def __lt__(self, other: Self):
|
|
513
|
-
return self.logical_name < other.logical_name
|
|
514
|
-
|
|
515
|
-
def __setattr__(self, key, value):
|
|
516
|
-
match key:
|
|
517
|
-
case 'VERSION' | 'CLASS_ID' | 'A_ELEMENTS' | 'M_ELEMENTS' as prop: raise ValueError(F"Don't support set {prop}")
|
|
518
|
-
case _: super().__setattr__(key, value)
|
|
519
|
-
|
|
520
|
-
def __getitem__(self, item) -> cdt.CommonDataType:
|
|
521
|
-
""" get attribute value by index, start with 1 """
|
|
522
|
-
if isinstance(item, str):
|
|
523
|
-
return super(COSEMInterfaceClasses, self).__getattr__(item)
|
|
524
|
-
return self.get_attr(item)
|
|
525
|
-
|
|
526
|
-
def __iter__(self) -> Iterator[cdt.CommonDataType]:
|
|
527
|
-
""" return attributes iterator"""
|
|
528
|
-
return iter(self.__attributes)
|
|
529
|
-
|
|
530
|
-
def __str__(self):
|
|
531
|
-
return F"{self.logical_name.get_report()} {get_name(self.logical_name)}"
|
|
532
|
-
|
|
533
|
-
def get_obis(self) -> bytes:
|
|
534
|
-
""" return obis as bytes[6] """
|
|
535
|
-
return self.logical_name.contents
|
|
536
|
-
|
|
537
|
-
@property
|
|
538
|
-
def instance_id(self) -> cdt.OctetString:
|
|
539
|
-
return self.logical_name
|
|
540
|
-
|
|
541
|
-
# TODO: rewrite this
|
|
542
|
-
def get_attribute_descriptor(self, index: int) -> bytes:
|
|
543
|
-
""" Cosem-Attribute-Descriptor IS/IEC 62056-53 : 2006, 8.3 Useful types """
|
|
544
|
-
return self.CLASS_ID.contents + self.instance_id.contents + ut.CosemObjectAttributeId(index).contents
|
|
545
|
-
|
|
546
|
-
def reset_attribute(self, index: int):
|
|
547
|
-
""" try set default to value """
|
|
548
|
-
self.set_attr(index, self.get_attr_element(index).default)
|
|
549
|
-
|
|
550
|
-
def get_attr_descriptor(self,
|
|
551
|
-
value: int,
|
|
552
|
-
with_selection: bool = False) -> ut.CosemAttributeDescriptor:
|
|
553
|
-
""" return AttributeDescriptor without selection """
|
|
554
|
-
return ut.CosemAttributeDescriptor((
|
|
555
|
-
self.CLASS_ID,
|
|
556
|
-
ut.CosemObjectInstanceId(self.logical_name.contents),
|
|
557
|
-
ut.CosemObjectAttributeId(value)))
|
|
558
|
-
|
|
559
|
-
def get_meth_descriptor(self, value: str | int) -> ut.CosemMethodDescriptor:
|
|
560
|
-
""" TODO """
|
|
561
|
-
match value:
|
|
562
|
-
case int() as index:
|
|
563
|
-
return ut.CosemMethodDescriptor((ut.CosemClassId(self.CLASS_ID.contents),
|
|
564
|
-
ut.CosemObjectInstanceId(self.logical_name.contents),
|
|
565
|
-
ut.CosemObjectMethodId(index)))
|
|
566
|
-
|
|
567
|
-
def __hash__(self):
|
|
568
|
-
return hash(self.logical_name)
|
|
569
|
-
|
|
570
|
-
def validate(self):
|
|
571
|
-
"""procedure for validate class values"""
|
|
572
|
-
|
|
573
|
-
def get_value(self, par: bytes) -> cdt.CommonDataType:
|
|
574
|
-
ret = self.get_attr(par[0])
|
|
575
|
-
for i in par[1:]:
|
|
576
|
-
ret = ret[i]
|
|
577
|
-
return ret
|
|
578
|
-
|
|
579
|
-
def get_values(self, par: bytes) -> list[cdt.CommonDataType]:
|
|
580
|
-
ret = [self.get_attr(par[0])]
|
|
581
|
-
for i in par[1:]:
|
|
582
|
-
ret.append(ret[-1][i])
|
|
583
|
-
return ret
|
|
1
|
+
"""
|
|
2
|
+
DLMS UA 1000-1 Ed 14
|
|
3
|
+
"""
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
from typing_extensions import deprecated
|
|
7
|
+
from typing import Iterator, Type, TypeAlias, Callable, Any, Self, Literal, Optional, Protocol, ClassVar
|
|
8
|
+
from ..types import cdt, ut, cst
|
|
9
|
+
from StructResult import result
|
|
10
|
+
from ..relation_to_OBIS import get_name
|
|
11
|
+
from enum import IntEnum
|
|
12
|
+
from itertools import count
|
|
13
|
+
from .. import exceptions as exc
|
|
14
|
+
from .overview import ClassID
|
|
15
|
+
from ..settings import settings
|
|
16
|
+
from .. import literals
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_n_class = count(0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Classifier(IntEnum):
|
|
23
|
+
""" (dyn.) Classifies an attribute that carries a process value, which is updated by the meter itself.
|
|
24
|
+
(static) Classifies an attribute, which is not updated by the meter itself (e.g. configuration data). """
|
|
25
|
+
NOT_SPECIFIC = 0
|
|
26
|
+
STATIC = 1
|
|
27
|
+
DYNAMIC = 2
|
|
28
|
+
|
|
29
|
+
def __str__(self):
|
|
30
|
+
return self.name
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
SelectiveAccessDescriptor: TypeAlias = ut.SelectiveAccessDescriptor # TODO: make with subclass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class ICElement:
|
|
38
|
+
NAME: str
|
|
39
|
+
|
|
40
|
+
def __str__(self) -> str:
|
|
41
|
+
try:
|
|
42
|
+
return getattr(settings.am_names, self.NAME)
|
|
43
|
+
except AttributeError:
|
|
44
|
+
return self.NAME
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class ICAElement(ICElement):
|
|
49
|
+
DATA_TYPE: Type[cdt.CommonDataType] | ut.CHOICE
|
|
50
|
+
min: int = None
|
|
51
|
+
max: int = None
|
|
52
|
+
default: int = None
|
|
53
|
+
classifier: Classifier = Classifier.STATIC
|
|
54
|
+
selective_access: Type[SelectiveAccessDescriptor] | None = None
|
|
55
|
+
|
|
56
|
+
def get_change(self,
|
|
57
|
+
data_type: Type[cdt.CommonDataType] | ut.CHOICE = None,
|
|
58
|
+
classifier: Classifier = None) -> Self:
|
|
59
|
+
return ICAElement(
|
|
60
|
+
NAME=self.NAME,
|
|
61
|
+
DATA_TYPE=self.DATA_TYPE if data_type is None else data_type,
|
|
62
|
+
min=self.min,
|
|
63
|
+
max=self.max,
|
|
64
|
+
default=self.default,
|
|
65
|
+
classifier=self.classifier if classifier is None else classifier,
|
|
66
|
+
selective_access=self.selective_access)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class ICMElement(ICElement):
|
|
71
|
+
DATA_TYPE: Type[cdt.CommonDataType]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
_LN_ELEMENT: ICAElement = ICAElement(
|
|
75
|
+
NAME="logical_name",
|
|
76
|
+
DATA_TYPE=cst.LogicalName)
|
|
77
|
+
"""" first element for each COSEM Interface Class"""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class ObjectValidationError(exc.DLMSException):
|
|
81
|
+
"""use in validation method of COSEMInterfaceClasses"""
|
|
82
|
+
def __init__(self,
|
|
83
|
+
ln: cst.LogicalName,
|
|
84
|
+
i: int,
|
|
85
|
+
message: str):
|
|
86
|
+
Exception.__init__(self, F"for {ln}: {i}. {message}")
|
|
87
|
+
self.ln = ln
|
|
88
|
+
self.i = i
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class EmptyAttribute(exc.DLMSException):
|
|
92
|
+
"""need read attribute"""
|
|
93
|
+
def __init__(self,
|
|
94
|
+
ln: cst.LogicalName,
|
|
95
|
+
i: int):
|
|
96
|
+
Exception.__init__(self, F"empty {ln}: {i}")
|
|
97
|
+
self.ln = ln
|
|
98
|
+
self.i = i
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
Name: Literal = Literal[
|
|
102
|
+
"Data",
|
|
103
|
+
"Register",
|
|
104
|
+
"Extended register",
|
|
105
|
+
"Demand register",
|
|
106
|
+
"Register activation",
|
|
107
|
+
"Profile generic",
|
|
108
|
+
"Clock",
|
|
109
|
+
"Script table",
|
|
110
|
+
"Schedule",
|
|
111
|
+
"Special days table",
|
|
112
|
+
"Association SN",
|
|
113
|
+
"Association LN",
|
|
114
|
+
"SAP Assignment",
|
|
115
|
+
"Image transfer",
|
|
116
|
+
"IEC local port setup",
|
|
117
|
+
"Activity calendar",
|
|
118
|
+
"Register monitor",
|
|
119
|
+
"Single action schedule",
|
|
120
|
+
"IEC HDLC setup",
|
|
121
|
+
"IEC twisted pair (1) setup",
|
|
122
|
+
"M-BUS slave port setup",
|
|
123
|
+
"Utility tables",
|
|
124
|
+
"Modem configuration",
|
|
125
|
+
"PSTN modem configuration",
|
|
126
|
+
"Auto answer",
|
|
127
|
+
"Auto connect",
|
|
128
|
+
"PSTN Auto dial",
|
|
129
|
+
"Data protection",
|
|
130
|
+
"Push setup",
|
|
131
|
+
"TCP-UDP setup",
|
|
132
|
+
"IPv4 setup",
|
|
133
|
+
"MAC address setup",
|
|
134
|
+
"PPP setup",
|
|
135
|
+
"GPRS modem setup",
|
|
136
|
+
"SMTP setup",
|
|
137
|
+
"GSM diagnostic",
|
|
138
|
+
"IPv6 setup",
|
|
139
|
+
"S-FSK Phy&MAC setup",
|
|
140
|
+
"S-FSK Active initiator",
|
|
141
|
+
"S-FSK MAC synchronization timeouts",
|
|
142
|
+
"S-FSK MAC counters",
|
|
143
|
+
"IEC 61334-4-32 LLC setup",
|
|
144
|
+
"S-FSK IEC 61334-4-32 LLC setup",
|
|
145
|
+
"S-FSK Reporting system list",
|
|
146
|
+
"ISO/IEC 8802-2 LLC Type 1 setup",
|
|
147
|
+
"ISO/IEC 8802-2 LLC Type 2 setup",
|
|
148
|
+
"ISO/IEC 8802-2 LLC Type 3 setup",
|
|
149
|
+
"Register table",
|
|
150
|
+
"Compact data",
|
|
151
|
+
"Status mapping",
|
|
152
|
+
"Security setup",
|
|
153
|
+
"Parameter monitor",
|
|
154
|
+
"Sensor manager",
|
|
155
|
+
"Arbitrator",
|
|
156
|
+
"Disconnect control",
|
|
157
|
+
"Limiter",
|
|
158
|
+
"M-Bus client",
|
|
159
|
+
"Wireless Mode Q channel",
|
|
160
|
+
"M-Bus master port setup",
|
|
161
|
+
"DLMS/COSEM server M-Bus port setup",
|
|
162
|
+
"M-Bus diagnostic",
|
|
163
|
+
"61334-4-32 LLC SSCS setup",
|
|
164
|
+
"PRIME NB OFDM PLC Physical layer counters",
|
|
165
|
+
"PRIME NB OFDM PLC MAC setup",
|
|
166
|
+
"PRIME NB OFDM PLC MAC functional parameters",
|
|
167
|
+
"PRIME NB OFDM PLC MAC counters",
|
|
168
|
+
"PRIME NB OFDM PLC MAC network administration data",
|
|
169
|
+
"PRIME NB OFDM PLC Application identification",
|
|
170
|
+
"G3-PLC MAC layer counters",
|
|
171
|
+
"G3 NB OFDM PLC MAC layer counters",
|
|
172
|
+
"G3-PLC MAC setup",
|
|
173
|
+
"G3 NB OFDM PLC MAC setup",
|
|
174
|
+
"G3-PLC 6LoWPAN adaptation layer setup",
|
|
175
|
+
"G3 NB OFDM PLC 6LoWPAN adaptation layer setup",
|
|
176
|
+
"Wi-SUN setup",
|
|
177
|
+
"Wi-SUN diagnostic",
|
|
178
|
+
"RPL diagnostic",
|
|
179
|
+
"MPL diagnostic",
|
|
180
|
+
"NTP Setup",
|
|
181
|
+
"ZigBee® SAS startup",
|
|
182
|
+
"ZigBee® SAS join",
|
|
183
|
+
"ZigBee® SAS APS fragmentation",
|
|
184
|
+
"ZigBee® network control",
|
|
185
|
+
"ZigBee® tunnel setup",
|
|
186
|
+
"Account",
|
|
187
|
+
"Credit",
|
|
188
|
+
"Charge",
|
|
189
|
+
"Token gateway",
|
|
190
|
+
"Function control",
|
|
191
|
+
"Array manager",
|
|
192
|
+
"Communication port protection",
|
|
193
|
+
"SCHC-LPWAN setup",
|
|
194
|
+
"SCHC-LPWAN diagnostic",
|
|
195
|
+
"LoRaWAN setup",
|
|
196
|
+
"LoRaWAN diagnostic",
|
|
197
|
+
"ISO/IEC14908 Identification",
|
|
198
|
+
"ISO/IEC 14908 Protocol setup",
|
|
199
|
+
"ISO/IEC 14908 protocol status",
|
|
200
|
+
"ISO/IEC 14908 diagnostic",
|
|
201
|
+
"HS-PLC ISO/IEC 12139-1 MAC setup",
|
|
202
|
+
"HS-PLC ISO/IEC 12139-1 CPAS setup",
|
|
203
|
+
"HS-PLC ISO/IEC 12139-1 IP SSAS setup",
|
|
204
|
+
"HS-PLC ISO/IEC 12139-1 HDLC SSAS setup",
|
|
205
|
+
"LTE monitoring"
|
|
206
|
+
]
|
|
207
|
+
"""Interface class name row from Table 3 – List of interface classes by class_id"""
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@lru_cache(150)
|
|
211
|
+
def ClassIDVer2Name(class_id: ClassID, ver: cdt.Unsigned) -> Name:
|
|
212
|
+
"""Table 3 – List of interface classes by class_id"""
|
|
213
|
+
match int(class_id), int(ver):
|
|
214
|
+
case 1, 0: return "Data"
|
|
215
|
+
case 3, 0: return "Register"
|
|
216
|
+
case 4, 0: return "Extended register"
|
|
217
|
+
case 5, 0: return "Demand register"
|
|
218
|
+
case 6, 0: return "Register activation"
|
|
219
|
+
case 7, 0 | 1: return "Profile generic"
|
|
220
|
+
case 8, 0: return "Clock"
|
|
221
|
+
case 9, 0: return "Script table"
|
|
222
|
+
case 10, 0: return "Schedule"
|
|
223
|
+
case 11, 0: return "Special days table"
|
|
224
|
+
case 12, 0 | 1 | 2 | 3 | 4: return "Association SN"
|
|
225
|
+
case 15, 0 | 1 | 2 | 3: return "Association LN"
|
|
226
|
+
case 17, 0: return "SAP Assignment"
|
|
227
|
+
case 18, 0: return "Image transfer"
|
|
228
|
+
case 19, 0 | 1: return "IEC local port setup"
|
|
229
|
+
case 20, 0: return "Activity calendar"
|
|
230
|
+
case 21, 0: return "Register monitor"
|
|
231
|
+
case 22, 0: return "Single action schedule"
|
|
232
|
+
case 23, 0 | 1: return "IEC HDLC setup"
|
|
233
|
+
case 24, 0 | 1: return "IEC twisted pair (1) setup"
|
|
234
|
+
case 25, 0: return "M-BUS slave port setup"
|
|
235
|
+
case 26, 0: return "Utility tables"
|
|
236
|
+
case 27, 1: return "Modem configuration"
|
|
237
|
+
case 27, 0: return "PSTN modem configuration"
|
|
238
|
+
case 28, 0 | 2: return "Auto answer"
|
|
239
|
+
case 29, 1 | 2: return "Auto connect"
|
|
240
|
+
case 29, 0: return "PSTN Auto dial"
|
|
241
|
+
case 30, 0: return "Data protection"
|
|
242
|
+
case 40, 0 | 1 | 2: return "Push setup"
|
|
243
|
+
case 41, 0: return "TCP-UDP setup"
|
|
244
|
+
case 42, 0: return "IPv4 setup"
|
|
245
|
+
case 43, 0: return "MAC address setup"
|
|
246
|
+
case 44, 0: return "PPP setup"
|
|
247
|
+
case 45, 0: return "GPRS modem setup"
|
|
248
|
+
case 46, 0: return "SMTP setup"
|
|
249
|
+
case 47, 0 | 1 | 2: return "GSM diagnostic"
|
|
250
|
+
case 48, 0: return "IPv6 setup"
|
|
251
|
+
case 50, 0 | 1: return "S-FSK Phy&MAC setup"
|
|
252
|
+
case 51, 0: return "S-FSK Active initiator"
|
|
253
|
+
case 52, 0: return "S-FSK MAC synchronization timeouts"
|
|
254
|
+
case 53, 0: return "S-FSK MAC counters"
|
|
255
|
+
case 55, 1: return "IEC 61334-4-32 LLC setup"
|
|
256
|
+
case 55, 0: return "S-FSK IEC 61334-4-32 LLC setup"
|
|
257
|
+
case 56, 0: return "S-FSK Reporting system list"
|
|
258
|
+
case 57, 0: return "ISO/IEC 8802-2 LLC Type 1 setup"
|
|
259
|
+
case 58, 0: return "ISO/IEC 8802-2 LLC Type 2 setup"
|
|
260
|
+
case 59, 0: return "ISO/IEC 8802-2 LLC Type 3 setup"
|
|
261
|
+
case 61, 0: return "Register table"
|
|
262
|
+
case 62, 0 | 1: return "Compact data"
|
|
263
|
+
case 63, 0: return "Status mapping"
|
|
264
|
+
case 64, 0 | 1: return "Security setup"
|
|
265
|
+
case 65, 0 | 1: return "Parameter monitor"
|
|
266
|
+
case 67, 0: return "Sensor manager"
|
|
267
|
+
case 68, 0: return "Arbitrator"
|
|
268
|
+
case 70, 0: return "Disconnect control"
|
|
269
|
+
case 71, 0: return "Limiter"
|
|
270
|
+
case 72, 0 | 1: return "M-Bus client"
|
|
271
|
+
case 73, 0: return "Wireless Mode Q channel"
|
|
272
|
+
case 74, 0: return "M-Bus master port setup"
|
|
273
|
+
case 76, 0: return "DLMS/COSEM server M-Bus port setup"
|
|
274
|
+
case 77, 0: return "M-Bus diagnostic"
|
|
275
|
+
case 80, 0: return "61334-4-32 LLC SSCS setup"
|
|
276
|
+
case 81, 0: return "PRIME NB OFDM PLC Physical layer counters"
|
|
277
|
+
case 82, 0: return "PRIME NB OFDM PLC MAC setup"
|
|
278
|
+
case 83, 0: return "PRIME NB OFDM PLC MAC functional parameters"
|
|
279
|
+
case 84, 0: return "PRIME NB OFDM PLC MAC counters"
|
|
280
|
+
case 85, 0: return "PRIME NB OFDM PLC MAC network administration data"
|
|
281
|
+
case 86, 0: return "PRIME NB OFDM PLC Application identification"
|
|
282
|
+
case 90, 1: return "G3-PLC MAC layer counters"
|
|
283
|
+
case 90, 0: return "G3 NB OFDM PLC MAC layer counters"
|
|
284
|
+
case 91, 1 | 2: return "G3-PLC MAC setup"
|
|
285
|
+
case 91, 0: return "G3 NB OFDM PLC MAC setup"
|
|
286
|
+
case 92, 1 | 2: return "G3-PLC 6LoWPAN adaptation layer setup"
|
|
287
|
+
case 92, 0: return "G3 NB OFDM PLC 6LoWPAN adaptation layer setup"
|
|
288
|
+
case 95, 0: return "Wi-SUN setup"
|
|
289
|
+
case 96, 0: return "Wi-SUN diagnostic"
|
|
290
|
+
case 97, 0: return "RPL diagnostic"
|
|
291
|
+
case 98, 0: return "MPL diagnostic"
|
|
292
|
+
case 100, 0: return "NTP Setup"
|
|
293
|
+
case 101, 0: return "ZigBee® SAS startup"
|
|
294
|
+
case 102, 0: return "ZigBee® SAS join"
|
|
295
|
+
case 103, 0: return "ZigBee® SAS APS fragmentation"
|
|
296
|
+
case 104, 0: return "ZigBee® network control"
|
|
297
|
+
case 104, 0: return "ZigBee® tunnel setup"
|
|
298
|
+
case 111, 0: return "Account"
|
|
299
|
+
case 112, 0: return "Credit"
|
|
300
|
+
case 113, 0: return "Charge"
|
|
301
|
+
case 115, 0: return "Token gateway"
|
|
302
|
+
case 122, 0: return "Function control"
|
|
303
|
+
case 123, 0: return "Array manager"
|
|
304
|
+
case 124, 0: return "Communication port protection"
|
|
305
|
+
case 126, 0: return "SCHC-LPWAN setup"
|
|
306
|
+
case 127, 0: return "SCHC-LPWAN diagnostic"
|
|
307
|
+
case 128, 0: return "LoRaWAN setup"
|
|
308
|
+
case 129, 0: return "LoRaWAN diagnostic"
|
|
309
|
+
case 130, 0: return "ISO/IEC14908 Identification"
|
|
310
|
+
case 131, 0: return "ISO/IEC 14908 Protocol setup"
|
|
311
|
+
case 132, 1: return "ISO/IEC 14908 protocol status"
|
|
312
|
+
case 133, 1: return "ISO/IEC 14908 diagnostic"
|
|
313
|
+
case 140, 0: return "HS-PLC ISO/IEC 12139-1 MAC setup"
|
|
314
|
+
case 141, 0: return "HS-PLC ISO/IEC 12139-1 CPAS setup"
|
|
315
|
+
case 142, 0: return "HS-PLC ISO/IEC 12139-1 IP SSAS setup"
|
|
316
|
+
case 143, 0: return "HS-PLC ISO/IEC 12139-1 HDLC SSAS setup"
|
|
317
|
+
case 151, 0 | 1: return "LTE monitoring"
|
|
318
|
+
case _: raise exc.ITEApplication(F"not find <Interface class name> with: {class_id=}, {ver=}")
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
@dataclass
|
|
322
|
+
class Cardinality:
|
|
323
|
+
"""4.1.4 Class description notation"""
|
|
324
|
+
min: int = 0
|
|
325
|
+
max: int = -1
|
|
326
|
+
"""default -1 as infinity"""
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
class COSEMInterfaceClasses(Protocol):
|
|
330
|
+
CLASS_ID: ClassVar[ut.CosemClassId]
|
|
331
|
+
VERSION: ClassVar[cdt.Unsigned]
|
|
332
|
+
""" Identification code of the version of the class. The version of each object is retrieved together with the logical name and the class_id by reading the object_list
|
|
333
|
+
attribute of an “Association LN” / ”Association SN” object. Within one logical device, all instances of a certain class must be of the same version."""
|
|
334
|
+
A_ELEMENTS: tuple[ICAElement, ...]
|
|
335
|
+
cardinality: ClassVar[Cardinality] = field(default_factory=Cardinality)
|
|
336
|
+
M_ELEMENTS: tuple[ICMElement, ...] = tuple() # empty if class not has the methods
|
|
337
|
+
__attributes: list[cdt.CommonDataType | None]
|
|
338
|
+
__specific_methods: tuple[cdt.CommonDataType, ...] = None
|
|
339
|
+
_cbs_attr_post_init: dict[int, Callable]
|
|
340
|
+
# collection: Any | None # Collection. todo: remove in future
|
|
341
|
+
hash_: int
|
|
342
|
+
|
|
343
|
+
def __init__(self, logical_name: cst.LogicalName | bytes | str):
|
|
344
|
+
self.collection = None
|
|
345
|
+
# """ TODO: """
|
|
346
|
+
self.cardinality = (0, None)
|
|
347
|
+
""" (min, max). default is (0, None) from 0 to infinity. If min == max then they are value.
|
|
348
|
+
Specifies the number of instances of the class within a logical device. value The class shall be
|
|
349
|
+
instantiated exactly “value” times. min...max. The class shall be instantiated at least “min.” times
|
|
350
|
+
and at most “max.” times. If min. is zero (0) then the class is optional, otherwise (min. > 0) "min."
|
|
351
|
+
instantiations of the class are mandatory. """
|
|
352
|
+
|
|
353
|
+
self.__attributes = [_LN_ELEMENT.DATA_TYPE(logical_name), *[None] * len(self.A_ELEMENTS)]
|
|
354
|
+
""" Attributes container """
|
|
355
|
+
|
|
356
|
+
if self.M_ELEMENTS is not None:
|
|
357
|
+
self.__specific_methods = tuple(el.DATA_TYPE() for el in self.M_ELEMENTS)
|
|
358
|
+
"""Specific methods container"""
|
|
359
|
+
|
|
360
|
+
self._cbs_attr_post_init = dict()
|
|
361
|
+
"""container with callbacks for post initial attribute by index"""
|
|
362
|
+
|
|
363
|
+
self._cbs_attr_before_init = dict()
|
|
364
|
+
"""container with callbacks for before initial attribute by index"""
|
|
365
|
+
|
|
366
|
+
# init all attributes with default value
|
|
367
|
+
for i in range(2, len(self.A_ELEMENTS)+2):
|
|
368
|
+
default = self.get_attr_element(i).default
|
|
369
|
+
if default is not None:
|
|
370
|
+
self.set_attr(i, default)
|
|
371
|
+
|
|
372
|
+
self.characteristics_init()
|
|
373
|
+
|
|
374
|
+
def __init_subclass__(cls, **kwargs):
|
|
375
|
+
super().__init_subclass__(**kwargs)
|
|
376
|
+
cls.hash_ = next(_n_class)
|
|
377
|
+
# print(cls.__name__)
|
|
378
|
+
|
|
379
|
+
@classmethod
|
|
380
|
+
@deprecated("use <getAElement>")
|
|
381
|
+
def get_attr_element(cls, i: int) -> ICAElement:
|
|
382
|
+
"""return element by order index. Override in each new class"""
|
|
383
|
+
if i == 1:
|
|
384
|
+
return _LN_ELEMENT
|
|
385
|
+
elif i > len(cls.A_ELEMENTS) + 1:
|
|
386
|
+
raise exc.DLMSException(F"got attribute index: {i}, expected 1..{len(cls.A_ELEMENTS) + 1}")
|
|
387
|
+
else:
|
|
388
|
+
return cls.A_ELEMENTS[i - 2]
|
|
389
|
+
|
|
390
|
+
@classmethod
|
|
391
|
+
def getAElement(cls, i: int) -> result.Simple[ICAElement] | result.Error:
|
|
392
|
+
"""return element by order index. Override in each new class"""
|
|
393
|
+
if i == 1:
|
|
394
|
+
return result.Simple(_LN_ELEMENT)
|
|
395
|
+
elif i > len(cls.A_ELEMENTS) + 1:
|
|
396
|
+
return result.Error.from_e(exc.DLMSException(F"got attribute index: {i}, expected 1..{len(cls.A_ELEMENTS) + 1}"))
|
|
397
|
+
else:
|
|
398
|
+
return result.Simple(cls.A_ELEMENTS[i - 2])
|
|
399
|
+
|
|
400
|
+
@classmethod
|
|
401
|
+
def get_meth_element(cls, i: int) -> ICMElement:
|
|
402
|
+
""" implement in subclasses with methods """
|
|
403
|
+
return cls.M_ELEMENTS[i - 1]
|
|
404
|
+
|
|
405
|
+
def characteristics_init(self):
|
|
406
|
+
""" initiate all attributes and methods of class """
|
|
407
|
+
|
|
408
|
+
def get_attr(self, index: int) -> Optional[cdt.CommonDataType]:
|
|
409
|
+
if index > (max_l := self.get_attr_length()):
|
|
410
|
+
raise IndexError(F"for {self} got attribute index: {index}, expected 0..{max_l}")
|
|
411
|
+
elif index >= 1:
|
|
412
|
+
return self.__attributes[index-1]
|
|
413
|
+
else:
|
|
414
|
+
raise IndexError(F"not support {index=} as attribute")
|
|
415
|
+
|
|
416
|
+
def set_attr_force(self,
|
|
417
|
+
index: int,
|
|
418
|
+
value: cdt.CommonDataType):
|
|
419
|
+
self.__attributes[index-1] = value
|
|
420
|
+
"""use for change official types to custom(not valid)"""
|
|
421
|
+
|
|
422
|
+
def encode(self,
|
|
423
|
+
index: int,
|
|
424
|
+
value: str | int) -> cdt.CommonDataType | None:
|
|
425
|
+
"""encode attribute value from string if possible, else return None(for CHOICE variant)"""
|
|
426
|
+
if (attr := self.get_attr(index)) is None:
|
|
427
|
+
data_type = self.get_attr_element(index).DATA_TYPE
|
|
428
|
+
if isinstance(data_type, ut.CHOICE):
|
|
429
|
+
return None
|
|
430
|
+
else:
|
|
431
|
+
return self.get_attr_element(index).DATA_TYPE(value)
|
|
432
|
+
else:
|
|
433
|
+
ret = attr.copy()
|
|
434
|
+
ret.set(value)
|
|
435
|
+
return ret
|
|
436
|
+
|
|
437
|
+
def set_attr(self,
|
|
438
|
+
index: int,
|
|
439
|
+
value=None,
|
|
440
|
+
data_type: cdt.CommonDataType = None):
|
|
441
|
+
value = self.get_attr_element(index).default if value is None else value
|
|
442
|
+
data_type = self.get_attr_element(index).DATA_TYPE if data_type is None else data_type
|
|
443
|
+
if self.__attributes[index-1] is None:
|
|
444
|
+
new_value = data_type(value)
|
|
445
|
+
if cb_func := self._cbs_attr_before_init.get(index, None):
|
|
446
|
+
cb_func(new_value)
|
|
447
|
+
self._cbs_attr_before_init.pop(index)
|
|
448
|
+
self.__attributes[index-1] = new_value
|
|
449
|
+
if cb_func := self._cbs_attr_post_init.get(index, None):
|
|
450
|
+
cb_func()
|
|
451
|
+
self._cbs_attr_post_init.pop(index)
|
|
452
|
+
else:
|
|
453
|
+
"""without callback post init"""
|
|
454
|
+
else:
|
|
455
|
+
self.__attributes[index-1].set(value)
|
|
456
|
+
|
|
457
|
+
def parse_attr(self, index: int, value: cdt.Transcript, data_type: cdt.CommonDataType = None):
|
|
458
|
+
"""set attribute value by Transcript"""
|
|
459
|
+
dt = self.get_attr_element(index).DATA_TYPE if data_type is None else data_type
|
|
460
|
+
if hasattr(dt, "TAG"):
|
|
461
|
+
self.__attributes[index - 1] = dt.parse(value)
|
|
462
|
+
else: # maybe CHOICE
|
|
463
|
+
self.__attributes[index - 1] = self.get_attr(index).parse(value)
|
|
464
|
+
|
|
465
|
+
def set_attr_link(self, index: int, link: cdt.CommonDataType):
|
|
466
|
+
# self.__attributes[index - 1] = link # TODO: without validate now for pass load_objects
|
|
467
|
+
if isinstance(link, self.get_attr_element(index).DATA_TYPE):
|
|
468
|
+
self.__attributes[index-1] = link
|
|
469
|
+
else:
|
|
470
|
+
raise ValueError(F'get wrong link: {link} for {self} attr: {index}')
|
|
471
|
+
|
|
472
|
+
def get_attr_data_type(self, index: int) -> Type[cdt.CommonDataType] | ut.CHOICE:
|
|
473
|
+
"""search data_type attribute value"""
|
|
474
|
+
value: cdt.CommonDataType = self.get_attr(index)
|
|
475
|
+
if value is not None:
|
|
476
|
+
return value.__class__
|
|
477
|
+
else:
|
|
478
|
+
return self.get_attr_element(index).DATA_TYPE
|
|
479
|
+
|
|
480
|
+
def clear_attr(self, i: int):
|
|
481
|
+
"""use in template"""
|
|
482
|
+
if i > 1:
|
|
483
|
+
self.__attributes[i-1] = None
|
|
484
|
+
else:
|
|
485
|
+
raise ValueError(F'not support clear {self} attr: {i}')
|
|
486
|
+
|
|
487
|
+
@deprecated("use get_meth_element")
|
|
488
|
+
def get_meth(self, index: int) -> Any:
|
|
489
|
+
if index >= 1:
|
|
490
|
+
return self.__specific_methods[index-1]
|
|
491
|
+
else:
|
|
492
|
+
raise IndexError(F'not support {index=} as attribute')
|
|
493
|
+
|
|
494
|
+
def get_index_with_attributes(self) -> Iterator[tuple[int, cdt.CommonDataType | None]]:
|
|
495
|
+
""" if by initiation order is True then need override method for concrete class"""
|
|
496
|
+
return iter(zip(range(1, self.get_attr_length()+1), self.__attributes))
|
|
497
|
+
|
|
498
|
+
def get_attr_length(self) -> int:
|
|
499
|
+
"""common attributes amount"""
|
|
500
|
+
return len(self.A_ELEMENTS)+1
|
|
501
|
+
|
|
502
|
+
@property
|
|
503
|
+
def it_index_with_meth(self) -> Iterator[tuple[int, cdt.CommonDataType]]:
|
|
504
|
+
return iter(zip(range(1, 20), self.__specific_methods))
|
|
505
|
+
|
|
506
|
+
@property
|
|
507
|
+
def logical_name(self) -> cst.LogicalName:
|
|
508
|
+
""" The logical name is always the first attribute of a class. It identifies the instantiation (COSEM object) of this class.
|
|
509
|
+
The value of the logical_name conforms to OBIS (see IEC 62056-61)"""
|
|
510
|
+
return self.get_attr(1)
|
|
511
|
+
|
|
512
|
+
def __lt__(self, other: Self):
|
|
513
|
+
return self.logical_name < other.logical_name
|
|
514
|
+
|
|
515
|
+
def __setattr__(self, key, value):
|
|
516
|
+
match key:
|
|
517
|
+
case 'VERSION' | 'CLASS_ID' | 'A_ELEMENTS' | 'M_ELEMENTS' as prop: raise ValueError(F"Don't support set {prop}")
|
|
518
|
+
case _: super().__setattr__(key, value)
|
|
519
|
+
|
|
520
|
+
def __getitem__(self, item) -> cdt.CommonDataType:
|
|
521
|
+
""" get attribute value by index, start with 1 """
|
|
522
|
+
if isinstance(item, str):
|
|
523
|
+
return super(COSEMInterfaceClasses, self).__getattr__(item)
|
|
524
|
+
return self.get_attr(item)
|
|
525
|
+
|
|
526
|
+
def __iter__(self) -> Iterator[cdt.CommonDataType]:
|
|
527
|
+
""" return attributes iterator"""
|
|
528
|
+
return iter(self.__attributes)
|
|
529
|
+
|
|
530
|
+
def __str__(self):
|
|
531
|
+
return F"{self.logical_name.get_report()} {get_name(self.logical_name)}"
|
|
532
|
+
|
|
533
|
+
def get_obis(self) -> bytes:
|
|
534
|
+
""" return obis as bytes[6] """
|
|
535
|
+
return self.logical_name.contents
|
|
536
|
+
|
|
537
|
+
@property
|
|
538
|
+
def instance_id(self) -> cdt.OctetString:
|
|
539
|
+
return self.logical_name
|
|
540
|
+
|
|
541
|
+
# TODO: rewrite this
|
|
542
|
+
def get_attribute_descriptor(self, index: int) -> bytes:
|
|
543
|
+
""" Cosem-Attribute-Descriptor IS/IEC 62056-53 : 2006, 8.3 Useful types """
|
|
544
|
+
return self.CLASS_ID.contents + self.instance_id.contents + ut.CosemObjectAttributeId(index).contents
|
|
545
|
+
|
|
546
|
+
def reset_attribute(self, index: int):
|
|
547
|
+
""" try set default to value """
|
|
548
|
+
self.set_attr(index, self.get_attr_element(index).default)
|
|
549
|
+
|
|
550
|
+
def get_attr_descriptor(self,
|
|
551
|
+
value: int,
|
|
552
|
+
with_selection: bool = False) -> ut.CosemAttributeDescriptor:
|
|
553
|
+
""" return AttributeDescriptor without selection """
|
|
554
|
+
return ut.CosemAttributeDescriptor((
|
|
555
|
+
self.CLASS_ID,
|
|
556
|
+
ut.CosemObjectInstanceId(self.logical_name.contents),
|
|
557
|
+
ut.CosemObjectAttributeId(value)))
|
|
558
|
+
|
|
559
|
+
def get_meth_descriptor(self, value: str | int) -> ut.CosemMethodDescriptor:
|
|
560
|
+
""" TODO """
|
|
561
|
+
match value:
|
|
562
|
+
case int() as index:
|
|
563
|
+
return ut.CosemMethodDescriptor((ut.CosemClassId(self.CLASS_ID.contents),
|
|
564
|
+
ut.CosemObjectInstanceId(self.logical_name.contents),
|
|
565
|
+
ut.CosemObjectMethodId(index)))
|
|
566
|
+
|
|
567
|
+
def __hash__(self):
|
|
568
|
+
return hash(self.logical_name)
|
|
569
|
+
|
|
570
|
+
def validate(self):
|
|
571
|
+
"""procedure for validate class values"""
|
|
572
|
+
|
|
573
|
+
def get_value(self, par: bytes) -> cdt.CommonDataType:
|
|
574
|
+
ret = self.get_attr(par[0])
|
|
575
|
+
for i in par[1:]:
|
|
576
|
+
ret = ret[i]
|
|
577
|
+
return ret
|
|
578
|
+
|
|
579
|
+
def get_values(self, par: bytes) -> list[cdt.CommonDataType]:
|
|
580
|
+
ret = [self.get_attr(par[0])]
|
|
581
|
+
for i in par[1:]:
|
|
582
|
+
ret.append(ret[-1][i])
|
|
583
|
+
return ret
|