-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathGXDLMSConverter.py
More file actions
724 lines (702 loc) · 27.3 KB
/
GXDLMSConverter.py
File metadata and controls
724 lines (702 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#
# --------------------------------------------------------------------------
# Gurux Ltd
#
#
#
# Filename: $HeadURL$
#
# Version: $Revision$,
# $Date$
# $Author$
#
# Copyright (c) Gurux Ltd
#
# ---------------------------------------------------------------------------
#
# DESCRIPTION
#
# This file is a part of Gurux Device Framework.
#
# Gurux Device Framework is Open Source 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; version 2 of the License.
# Gurux Device Framework 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.
#
# More information of Gurux products: http://www.gurux.org
#
# This code is licensed under the GNU General Public License v2.
# Full text may be retrieved at http://www.gnu.org/licenses/gpl-2.0.txt
# ---------------------------------------------------------------------------
import sys
if sys.version_info > (3, 8):
from importlib.resources import files
elif sys.version_info >= (3, 7) and sys.version_info <= (3, 8):
import importlib_resources
else:
import pkg_resources
from .enums import Standard, ObjectType, DataType
from .GXStandardObisCodeCollection import GXStandardObisCodeCollection
from .GXStandardObisCode import GXStandardObisCode
from .internal._GXCommon import _GXCommon
from .GXEnum import GXEnum
from .GXInt8 import GXInt8
from .GXInt16 import GXInt16
from .GXInt32 import GXInt32
from .GXInt64 import GXInt64
from .GXUInt8 import GXUInt8
from .GXUInt16 import GXUInt16
from .GXUInt32 import GXUInt32
from .GXUInt64 import GXUInt64
from .GXDate import GXDate
from .GXDateTime import GXDateTime
from .GXTime import GXTime
from .GXByteBuffer import GXByteBuffer
from .manufacturersettings.GXObisCode import GXObisCode
from .objects.enums.CertificateType import CertificateType
###Python 2 requires this
# pylint: disable=bad-option-value,old-style-class
class GXDLMSConverter:
#
# Constructor.
#
# value: Used standard.
#
def __init__(self, value=Standard.DLMS):
self.standard = value
# Collection of standard OBIS codes.
self.codes = GXStandardObisCodeCollection()
#
# Get OBIS code description.
#
# @param logicalName
# Logical name (OBIS code).
# @param type
# Object type.
# @param description
# Description filter.
# Array of descriptions that match given OBIS code.
#
def getDescription(self, logicalName, type_=ObjectType.NONE, description=None):
if not self.codes:
self.__readStandardObisInfo(self.standard, self.codes)
list_ = []
all_ = not logicalName
for it in self.codes.find(logicalName, type_):
if description and not it.description.lower().contains(description.lower()):
continue
if all_:
list_.append(
"A="
+ it.getOBIS()[0]
+ ", B="
+ it.getOBIS()[1]
+ ", C="
+ it.getOBIS()[2]
+ ", D="
+ it.getOBIS()[3]
+ ", E="
+ it.getOBIS()[4]
+ ", F="
+ it.getOBIS()[5]
+ "\r\n"
+ it.description
)
else:
list_.append(it.description)
return list_
# pylint: disable=too-many-boolean-expressions
@classmethod
def __updateOBISCodeInfo(cls, codes, it, standard):
ln = it.logicalName
list_ = codes.find(ln, it.objectType)
code_ = list_[0]
if code_:
if not it.description:
it.description = code_.description
# Update data type from DLMS standard.
if standard != Standard.DLMS:
d = list_[len(list_) - 1]
code_.dataType = d.dataType
if not code_.uiDataType:
if "10" in code_.dataType:
code_.uiDataType = "10"
elif "25" in code_.dataType or "26" in code_.dataType:
code_.uiDataType = "25"
elif "9" in code_.dataType:
if (
GXStandardObisCodeCollection.equalsMask2(
"0.0-64.96.7.10-14.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"0.0-64.0.1.5.0-99,255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"0.0-64.0.1.2.0-99,255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.1.2.0-99,255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.1.5.0-99,255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.0.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.6.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.7.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.13.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.14.255", ln
)
or GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.15.255", ln
)
):
code_.uiDataType = "25"
# Local time
elif GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.1.255", ln
):
code_.uiDataType = "27"
# Local date
elif GXStandardObisCodeCollection.equalsMask2(
"1.0-64.0.9.2.255", ln
):
code_.uiDataType = "26"
# Active firmware identifier
elif GXStandardObisCodeCollection.equalsMask2("1.0.0.2.0.255", ln):
code_.uiDataType = "10"
# Unix time
elif (
it.objectType == ObjectType.DATA
and GXStandardObisCodeCollection.equalsMask2(
"0.0.1.1.0.255", it.logicalName
)
):
code_.uiDataType = "25"
if (
not code_.dataType == "*"
and not code_.dataType == ""
and "," not in code_.dataType
):
tp = int(code_.dataType)
if it.objectType in (
ObjectType.DATA,
ObjectType.REGISTER,
ObjectType.REGISTER_ACTIVATION,
ObjectType.EXTENDED_REGISTER,
):
it.setDataType(2, tp)
if code_.uiDataType:
tp = int(code_.uiDataType)
if it.objectType in (
ObjectType.DATA,
ObjectType.REGISTER,
ObjectType.REGISTER_ACTIVATION,
ObjectType.EXTENDED_REGISTER,
):
it.setUIDataType(2, tp)
else:
print("Unknown OBIS Code: " + it.logicalName + " Type: " + it.objectType)
def updateOBISCodeInformation(self, objects):
if not self.codes:
self.__readStandardObisInfo(self.standard, self.codes)
if isinstance(objects, list):
for it in objects:
self.__updateOBISCodeInfo(self.codes, it, self.standard)
else:
self.__updateOBISCodeInfo(self.codes, objects, self.standard)
@classmethod
def __load(cls, name):
if sys.version_info > (3, 8):
str_ = (files(__package__) / name).read_text("utf-8")
elif sys.version_info >= (3, 7) and sys.version_info <= (3, 8):
str_ = (
importlib_resources.files(__package__).joinpath(name).read_text("utf-8")
)
else:
str_ = pkg_resources.resource_string(__name__, name).decode("utf-8")
return str_
@classmethod
def __getObjects(cls, standard):
codes = []
if standard == Standard.ITALY:
str_ = cls.__load("Italy.txt")
elif standard == Standard.INDIA:
str_ = cls.__load("India.txt")
elif standard == Standard.SAUDI_ARABIA:
str_ = cls.__load("SaudiArabia.txt")
elif standard == Standard.SPAIN:
str_ = cls.__load("Spain.txt")
if not str_:
return None
str_ = str_.replace("\n", "\r")
rows = str_.split("\r")
for it in rows:
if it and not it.startswith("#"):
items = it.split(";")
if len(items) > 1:
ot = int(items[0])
ln = _GXCommon.toLogicalName(_GXCommon.logicalNameToBytes(items[1]))
version = int(items[2])
desc = items[3]
code_ = GXObisCode(ln, ot, 0, desc)
code_.version = version
if len(items) > 4:
code_.uiDataType = items[4]
codes.append(code_)
return codes
@classmethod
def __readStandardObisInfo(cls, standard, codes):
if standard != Standard.DLMS:
for it in GXDLMSConverter.__getObjects(standard):
tmp = GXStandardObisCode(it.logicalName.split("."))
tmp.interfaces = str(it.objectType)
tmp.description = it.description
tmp.uiDataType = it.uiDataType
codes.append(tmp)
str_ = cls.__load("OBISCodes.txt")
str_ = str_.replace("\n", "\r")
rows = str_.split("\r")
for it in rows:
if it and not it.startswith("#"):
items = it.split(";")
obis = items[0].split(".")
try:
code_ = GXStandardObisCode(
obis,
str(items[3])
+ "; "
+ str(items[4])
+ "; "
+ str(items[5])
+ "; "
+ str(items[6])
+ "; "
+ str(items[7]),
str(items[1]),
str(items[2]),
)
codes.append(code_)
except UnicodeEncodeError:
pass
@classmethod
def changeType(cls, value, type_):
if _GXCommon.getDLMSDataType(value) == type_:
return value
if type_ == DataType.ARRAY:
raise ValueError("Can't change array types.")
if type_ == DataType.BCD:
ret = int(value)
elif type_ == DataType.BOOLEAN:
ret = bool(int(value))
elif type_ == DataType.COMPACT_ARRAY:
raise ValueError("Can't change compact array types.")
elif type_ == DataType.DATE:
ret = GXDate(value)
elif type_ == DataType.DATETIME:
ret = GXDateTime(value)
elif type_ == DataType.ENUM:
ret = GXEnum(value)
elif type_ == DataType.FLOAT32:
ret = float(value)
elif type_ == DataType.FLOAT64:
ret = float(value)
elif type_ == DataType.INT16:
ret = GXInt16(value)
elif type_ == DataType.INT32:
ret = GXInt32(value)
elif type_ == DataType.INT64:
ret = GXInt64(value)
elif type_ == DataType.INT8:
ret = GXInt8(value)
elif type_ == DataType.NONE:
ret = None
elif type_ == DataType.OCTET_STRING:
if isinstance(value, str):
ret = GXByteBuffer.hexToBytes(str(value))
else:
raise ValueError("Can't change octect string type.")
elif type_ == DataType.STRING:
ret = str(value)
elif type_ == DataType.BITSTRING:
ret = str(value)
elif type_ == DataType.STRING_UTF8:
ret = str(value)
elif type_ == DataType.STRUCTURE:
raise ValueError("Can't change structure types.")
elif type_ == DataType.TIME:
ret = GXTime(value)
elif type_ == DataType.UINT16:
ret = GXUInt16(value)
elif type_ == DataType.UINT32:
ret = GXUInt32(value)
elif type_ == DataType.UINT64:
ret = GXUInt64(value)
elif type_ == DataType.UINT8:
ret = GXUInt8(value)
else:
raise ValueError("Invalid data type.")
return ret
@classmethod
def objectTypeToString(cls, ot):
if ot == ObjectType.ACTION_SCHEDULE:
ret = "ActionSchedule"
elif ot == ObjectType.ACTIVITY_CALENDAR:
ret = "ActivityCalendar"
elif ot == ObjectType.ASSOCIATION_LOGICAL_NAME:
ret = "AssociationLogicalName"
elif ot == ObjectType.ASSOCIATION_SHORT_NAME:
ret = "AssociationShortName"
elif ot == ObjectType.AUTO_ANSWER:
ret = "AutoAnswer"
elif ot == ObjectType.AUTO_CONNECT:
ret = "AutoConnect"
elif ot == ObjectType.CLOCK:
ret = "Clock"
elif ot == ObjectType.DATA:
ret = "Data"
elif ot == ObjectType.DEMAND_REGISTER:
ret = "DemandRegister"
elif ot == ObjectType.MAC_ADDRESS_SETUP:
ret = "MacAddressSetup"
elif ot == ObjectType.EXTENDED_REGISTER:
ret = "ExtendedRegister"
elif ot == ObjectType.GPRS_SETUP:
ret = "GprsSetup"
elif ot == ObjectType.SECURITY_SETUP:
ret = "SecuritySetup"
elif ot == ObjectType.IEC_HDLC_SETUP:
ret = "IecHdlcSetup"
elif ot == ObjectType.IEC_LOCAL_PORT_SETUP:
ret = "IecLocalPortSetup"
elif ot == ObjectType.IEC_TWISTED_PAIR_SETUP:
ret = "IEC_TWISTED_PAIR_SETUP"
elif ot == ObjectType.IP4_SETUP:
ret = "Ip4Setup"
elif ot == ObjectType.MBUS_SLAVE_PORT_SETUP:
ret = "MBusSlavePortSetup"
elif ot == ObjectType.IMAGE_TRANSFER:
ret = "ImageTransfer"
elif ot == ObjectType.DISCONNECT_CONTROL:
ret = "DisconnectControl"
elif ot == ObjectType.LIMITER:
ret = "Limiter"
elif ot == ObjectType.MBUS_CLIENT:
ret = "MBusClient"
elif ot == ObjectType.MODEM_CONFIGURATION:
ret = "ModemConfiguration"
elif ot == ObjectType.PPP_SETUP:
ret = "PppSetup"
elif ot == ObjectType.PROFILE_GENERIC:
ret = "ProfileGeneric"
elif ot == ObjectType.REGISTER:
ret = "Register"
elif ot == ObjectType.REGISTER_ACTIVATION:
ret = "RegisterActivation"
elif ot == ObjectType.REGISTER_MONITOR:
ret = "RegisterMonitor"
elif ot == ObjectType.REGISTER_TABLE:
ret = "RegisterTable"
elif ot == ObjectType.ZIG_BEE_SAS_STARTUP:
ret = "ZigBeeSasStartup"
elif ot == ObjectType.ZIG_BEE_SAS_JOIN:
ret = "ZigBeeSasJoin"
elif ot == ObjectType.ZIG_BEE_SAS_APS_FRAGMENTATION:
ret = "ZigBeeSasApsFragmentation"
elif ot == ObjectType.ZIG_BEE_NETWORK_CONTROL:
ret = "ZigBeeNetworkControl"
elif ot == ObjectType.SAP_ASSIGNMENT:
ret = "SapAssignment"
elif ot == ObjectType.SCHEDULE:
ret = "Schedule"
elif ot == ObjectType.SCRIPT_TABLE:
ret = "ScriptTable"
elif ot == ObjectType.SMTP_SETUP:
ret = "SMTPSetup"
elif ot == ObjectType.SPECIAL_DAYS_TABLE:
ret = "SpecialDaysTable"
elif ot == ObjectType.STATUS_MAPPING:
ret = "StatusMapping"
elif ot == ObjectType.TCP_UDP_SETUP:
ret = "TcpUdpSetup"
elif ot == ObjectType.UTILITY_TABLES:
ret = "UtilityTables"
elif ot == ObjectType.MBUS_MASTER_PORT_SETUP:
ret = "MBusMasterPortSetup"
elif ot == ObjectType.PUSH_SETUP:
ret = "PushSetup"
elif ot == ObjectType.ACCOUNT:
ret = "Account"
elif ot == ObjectType.CREDIT:
ret = "Credit"
elif ot == ObjectType.CHARGE:
ret = "Charge"
elif ot == ObjectType.PARAMETER_MONITOR:
ret = "ParameterMonitor"
elif ot == ObjectType.TOKEN_GATEWAY:
ret = "Token"
elif ot == ObjectType.GSM_DIAGNOSTIC:
ret = "GSMDiagnostic"
elif ot == ObjectType.COMPACT_DATA:
ret = "CompactData"
elif ot == ObjectType.IP6_SETUP:
ret = "Ip6Setup"
elif ot == ObjectType.LLC_SSCS_SETUP:
ret = "LlcSscsSetup"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_PHYSICAL_LAYER_COUNTERS:
ret = "PrimeNbOfdmPlcPhysicalLayerCounters"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_MAC_SETUP:
ret = "PrimeNbOfdmPlcMacSetup"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_MAC_FUNCTIONAL_PARAMETERS:
ret = "PrimeNbOfdmPlcMacFunctionalParameters"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_MAC_COUNTERS:
ret = "PrimeNbOfdmPlcMacCounters"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_MAC_NETWORK_ADMINISTRATION_DATA:
ret = "PrimeNbOfdmPlcMacNetworkAdministrationData"
elif ot == ObjectType.PRIME_NB_OFDM_PLC_APPLICATIONS_IDENTIFICATION:
ret = "PrimeNbOfdmPlcApplicationsIdentification"
elif ot == ObjectType.NTP_SETUP:
ret = "NtpSetup"
elif ot == ObjectType.FUNCTION_CONTROL:
ret = "FunctionControl"
elif ot == ObjectType.G3_PLC_MAC_SETUP:
ret = "G3PlcMacSetup"
elif ot == ObjectType.G3_PLC_MAC_LAYER_COUNTERS:
ret = "G3PlcMacLayerCounters"
elif ot == ObjectType.G3_PLC6_LO_WPAN:
ret = "G3Plc6LoWPan"
elif ot == ObjectType.G3_PLC6_LO_WPAN:
ret = "G3Plc6LoWPan"
elif ot == ObjectType.LTE_MONITORING:
ret = "GXDLMSLteMonitoring"
else:
ret = "ManufactureSpesific."
return ret
@classmethod
def valueOfObjectType(cls, value):
if value == "ActionSchedule":
ot = ObjectType.ACTION_SCHEDULE
elif value == "ActivityCalendar":
ot = ObjectType.ACTIVITY_CALENDAR
elif value == "AssociationLogicalName":
ot = ObjectType.ASSOCIATION_LOGICAL_NAME
elif value == "AssociationShortName":
ot = ObjectType.ASSOCIATION_SHORT_NAME
elif value == "AutoAnswer":
ot = ObjectType.AUTO_ANSWER
elif value == "AutoConnect":
ot = ObjectType.AUTO_CONNECT
elif value == "Clock":
ot = ObjectType.CLOCK
elif value == "Data":
ot = ObjectType.DATA
elif value == "DemandRegister":
ot = ObjectType.DEMAND_REGISTER
elif value == "MacAddressSetup":
ot = ObjectType.MAC_ADDRESS_SETUP
elif value == "ExtendedRegister":
ot = ObjectType.EXTENDED_REGISTER
elif value == "GprsSetup":
ot = ObjectType.GPRS_SETUP
elif value == "SecuritySetup":
ot = ObjectType.SECURITY_SETUP
elif value in ("IecHdlcSetup", "HdlcSetup"):
ot = ObjectType.IEC_HDLC_SETUP
elif value in (
"IecLocalPortSetup",
"IecOpticalPortSetup",
"IECOpticalPortSetup",
):
ot = ObjectType.IEC_LOCAL_PORT_SETUP
elif value == "IEC_TWISTED_PAIR_SETUP":
ot = ObjectType.IEC_TWISTED_PAIR_SETUP
elif value == "Ip4Setup":
ot = ObjectType.IP4_SETUP
elif value == "MBusSlavePortSetup":
ot = ObjectType.MBUS_SLAVE_PORT_SETUP
elif value == "ImageTransfer":
ot = ObjectType.IMAGE_TRANSFER
elif value == "DisconnectControl":
ot = ObjectType.DISCONNECT_CONTROL
elif value == "Limiter":
ot = ObjectType.LIMITER
elif value == "MBusClient":
ot = ObjectType.MBUS_CLIENT
elif value == "ModemConfiguration":
ot = ObjectType.MODEM_CONFIGURATION
elif value == "PppSetup":
ot = ObjectType.PPP_SETUP
elif value == "ProfileGeneric":
ot = ObjectType.PROFILE_GENERIC
elif value == "Register":
ot = ObjectType.REGISTER
elif value == "RegisterActivation":
ot = ObjectType.REGISTER_ACTIVATION
elif value == "RegisterMonitor":
ot = ObjectType.REGISTER_MONITOR
elif value == "RegisterTable":
ot = ObjectType.REGISTER_TABLE
elif value == "ZigBeeSasStartup":
ot = ObjectType.ZIG_BEE_SAS_STARTUP
elif value == "ZigBeeSasJoin":
ot = ObjectType.ZIG_BEE_SAS_JOIN
elif value == "ZigBeeSasApsFragmentation":
ot = ObjectType.ZIG_BEE_SAS_APS_FRAGMENTATION
elif value == "ZigBeeNetworkControl":
ot = ObjectType.ZIG_BEE_NETWORK_CONTROL
elif value == "SapAssignment":
ot = ObjectType.SAP_ASSIGNMENT
elif value == "Schedule":
ot = ObjectType.SCHEDULE
elif value == "ScriptTable":
ot = ObjectType.SCRIPT_TABLE
elif value == "SMTPSetup":
ot = ObjectType.SMTP_SETUP
elif value == "SpecialDaysTable":
ot = ObjectType.SPECIAL_DAYS_TABLE
elif value == "StatusMapping":
ot = ObjectType.STATUS_MAPPING
elif value == "TcpUdpSetup":
ot = ObjectType.TCP_UDP_SETUP
elif value == "UtilityTables":
ot = ObjectType.UTILITY_TABLES
elif value == "MBusMasterPortSetup":
ot = ObjectType.MBUS_MASTER_PORT_SETUP
elif value == "PushSetup":
ot = ObjectType.PUSH_SETUP
elif value == "Account":
ot = ObjectType.ACCOUNT
elif value == "Credit":
ot = ObjectType.CREDIT
elif value == "Charge":
ot = ObjectType.CHARGE
elif value == "ParameterMonitor":
ot = ObjectType.PARAMETER_MONITOR
elif value in ("Token", "TokenGateway"):
ot = ObjectType.TOKEN_GATEWAY
elif value == "GSMDiagnostic":
ot = ObjectType.GSM_DIAGNOSTIC
elif value == "CompactData":
ot = ObjectType.COMPACT_DATA
elif value == "Ip6Setup":
ot = ObjectType.IP6_SETUP
elif value == "LlcSscsSetup":
ot = ObjectType.LLC_SSCS_SETUP
elif value == "PrimeNbOfdmPlcPhysicalLayerCounters":
ot = ObjectType.PRIME_NB_OFDM_PLC_PHYSICAL_LAYER_COUNTERS
elif value == "PrimeNbOfdmPlcMacSetup":
ot = ObjectType.PRIME_NB_OFDM_PLC_MAC_SETUP
elif value == "PrimeNbOfdmPlcMacFunctionalParameters":
ot = ObjectType.PRIME_NB_OFDM_PLC_MAC_FUNCTIONAL_PARAMETERS
elif value == "PrimeNbOfdmPlcMacCounters":
ot = ObjectType.PRIME_NB_OFDM_PLC_MAC_COUNTERS
elif value == "PrimeNbOfdmPlcMacNetworkAdministrationData":
ot = ObjectType.PRIME_NB_OFDM_PLC_MAC_NETWORK_ADMINISTRATION_DATA
elif value == "PrimeNbOfdmPlcApplicationsIdentification":
ot = ObjectType.PRIME_NB_OFDM_PLC_APPLICATIONS_IDENTIFICATION
elif value == "NtpSetup":
ot = ObjectType.NTP_SETUP
elif value == "FunctionControl":
ot = ObjectType.FUNCTION_CONTROL
elif value == "G3PlcMacSetup":
ot = ObjectType.G3_PLC_MAC_SETUP
elif value == "G3PlcMacLayerCounters":
ot = ObjectType.G3_PLC_MAC_LAYER_COUNTERS
elif value == "G3Plc6LoWPan":
ot = ObjectType.G3_PLC6_LO_WPAN
elif value == "GXDLMSLteMonitoring":
ot = ObjectType.LTE_MONITORING
else:
ot = ObjectType.NONE
return ot
@classmethod
def dataTypeToString(cls, ot):
if ot == DataType.ARRAY:
return "Array"
elif ot == DataType.BCD:
return "Bcd"
elif ot == DataType.BITSTRING:
return "BitString"
elif ot == DataType.BOOLEAN:
return "Boolean"
elif ot == DataType.COMPACT_ARRAY:
return "CompactArray"
elif ot == DataType.DATE:
return "Date"
elif ot == DataType.DATETIME:
return "DateTime"
elif ot == DataType.ENUM:
return "Enum"
elif ot == DataType.FLOAT32:
return "Float32"
elif ot == DataType.FLOAT64:
return "Float64"
elif ot == DataType.INT16:
return "Int16"
elif ot == DataType.INT32:
return "Int32"
elif ot == DataType.INT64:
return "Int64"
elif ot == DataType.INT8:
return "Int8"
elif ot == DataType.NONE:
return "None"
elif ot == DataType.OCTET_STRING:
return "Octet-string"
elif ot == DataType.STRING:
return "String"
elif ot == DataType.STRING_UTF8:
return "String UTF8"
elif ot == DataType.STRUCTURE:
return "Structure"
elif ot == DataType.TIME:
return "Time"
elif ot == DataType.UINT16:
return "UInt16"
elif ot == DataType.UINT32:
return "UInt32"
elif ot == DataType.UINT64:
return "UInt64"
elif ot == DataType.UINT8:
return "UInt8"
else:
raise ValueError("Unknown DataType")
# pylint: disable=import-outside-toplevel
@classmethod
def systemTitleToString(cls, standard, st, addComments):
"""Convert system title to string."""
return _GXCommon.systemTitleToString(standard, st, addComments)
# pylint: disable=import-outside-toplevel
@classmethod
def keyUsageToCertificateType(cls, value):
"""Convert key usage to certificate type."""
from .asn.enums.KeyUsage import KeyUsage
if value == KeyUsage.DIGITAL_SIGNATURE:
return CertificateType.DIGITAL_SIGNATURE
if value == KeyUsage.KEY_AGREEMENT:
return CertificateType.KEY_AGREEMENT
if value == KeyUsage.DIGITAL_SIGNATURE | KeyUsage.KEY_AGREEMENT:
return CertificateType.TLS
raise ValueError("Unknown KeyUsage value")
# pylint: disable=import-outside-toplevel
@classmethod
def CertificateTypeToKeyUsage(cls, value):
from .asn.enums.KeyUsage import KeyUsage
if value == CertificateType.DIGITAL_SIGNATURE:
return KeyUsage.DIGITAL_SIGNATURE
if value == CertificateType.KEY_AGREEMENT:
return KeyUsage.KEY_AGREEMENT
if value == CertificateType.TLS:
return KeyUsage.DIGITAL_SIGNATURE | KeyUsage.KEY_AGREEMENT
raise ValueError("Unknown CertificateType value")