hat.drivers.iec60870.encodings.iec104
IEC 60870-5-104 messages
1"""IEC 60870-5-104 messages""" 2 3from hat.drivers.iec60870.encodings.iec104.common import ( 4 AsduTypeError, 5 TimeSize, 6 Time, 7 time_from_datetime, 8 time_to_datetime, 9 OriginatorAddress, 10 AsduAddress, 11 IoAddress, 12 AsduType, 13 CauseType, 14 OtherCauseType, 15 Cause, 16 QualityType, 17 IndicationQuality, 18 MeasurementQuality, 19 CounterQuality, 20 ProtectionQuality, 21 Quality, 22 FreezeCode, 23 SingleValue, 24 DoubleValue, 25 RegulatingValue, 26 StepPositionValue, 27 BitstringValue, 28 NormalizedValue, 29 ScaledValue, 30 FloatingValue, 31 BinaryCounterValue, 32 ProtectionValue, 33 ProtectionStartValue, 34 ProtectionCommandValue, 35 StatusValue, 36 IoElement_M_SP_NA, 37 IoElement_M_DP_NA, 38 IoElement_M_ST_NA, 39 IoElement_M_BO_NA, 40 IoElement_M_ME_NA, 41 IoElement_M_ME_NB, 42 IoElement_M_ME_NC, 43 IoElement_M_IT_NA, 44 IoElement_M_PS_NA, 45 IoElement_M_ME_ND, 46 IoElement_M_SP_TB, 47 IoElement_M_DP_TB, 48 IoElement_M_ST_TB, 49 IoElement_M_BO_TB, 50 IoElement_M_ME_TD, 51 IoElement_M_ME_TE, 52 IoElement_M_ME_TF, 53 IoElement_M_IT_TB, 54 IoElement_M_EP_TD, 55 IoElement_M_EP_TE, 56 IoElement_M_EP_TF, 57 IoElement_C_SC_NA, 58 IoElement_C_DC_NA, 59 IoElement_C_RC_NA, 60 IoElement_C_SE_NA, 61 IoElement_C_SE_NB, 62 IoElement_C_SE_NC, 63 IoElement_C_BO_NA, 64 IoElement_M_EI_NA, 65 IoElement_C_IC_NA, 66 IoElement_C_CI_NA, 67 IoElement_C_RD_NA, 68 IoElement_C_CS_NA, 69 IoElement_C_RP_NA, 70 IoElement_P_ME_NA, 71 IoElement_P_ME_NB, 72 IoElement_P_ME_NC, 73 IoElement_P_AC_NA, 74 IoElement_F_FR_NA, 75 IoElement_F_SR_NA, 76 IoElement_F_SC_NA, 77 IoElement_F_LS_NA, 78 IoElement_F_AF_NA, 79 IoElement_F_SG_NA, 80 IoElement_F_DR_TA, 81 IoElement_C_SC_TA, 82 IoElement_C_DC_TA, 83 IoElement_C_RC_TA, 84 IoElement_C_SE_TA, 85 IoElement_C_SE_TB, 86 IoElement_C_SE_TC, 87 IoElement_C_BO_TA, 88 IoElement_C_TS_TA, 89 IoElement, 90 IO, 91 ASDU) 92from hat.drivers.iec60870.encodings.iec104.encoder import ( 93 iec101_asdu_types, 94 Encoder) 95 96 97__all__ = ['AsduTypeError', 98 'TimeSize', 99 'Time', 100 'time_from_datetime', 101 'time_to_datetime', 102 'OriginatorAddress', 103 'AsduAddress', 104 'IoAddress', 105 'AsduType', 106 'CauseType', 107 'OtherCauseType', 108 'Cause', 109 'QualityType', 110 'IndicationQuality', 111 'MeasurementQuality', 112 'CounterQuality', 113 'ProtectionQuality', 114 'Quality', 115 'FreezeCode', 116 'SingleValue', 117 'DoubleValue', 118 'RegulatingValue', 119 'StepPositionValue', 120 'BitstringValue', 121 'NormalizedValue', 122 'ScaledValue', 123 'FloatingValue', 124 'BinaryCounterValue', 125 'ProtectionValue', 126 'ProtectionStartValue', 127 'ProtectionCommandValue', 128 'StatusValue', 129 'IoElement_M_SP_NA', 130 'IoElement_M_DP_NA', 131 'IoElement_M_ST_NA', 132 'IoElement_M_BO_NA', 133 'IoElement_M_ME_NA', 134 'IoElement_M_ME_NB', 135 'IoElement_M_ME_NC', 136 'IoElement_M_IT_NA', 137 'IoElement_M_PS_NA', 138 'IoElement_M_ME_ND', 139 'IoElement_M_SP_TB', 140 'IoElement_M_DP_TB', 141 'IoElement_M_ST_TB', 142 'IoElement_M_BO_TB', 143 'IoElement_M_ME_TD', 144 'IoElement_M_ME_TE', 145 'IoElement_M_ME_TF', 146 'IoElement_M_IT_TB', 147 'IoElement_M_EP_TD', 148 'IoElement_M_EP_TE', 149 'IoElement_M_EP_TF', 150 'IoElement_C_SC_NA', 151 'IoElement_C_DC_NA', 152 'IoElement_C_RC_NA', 153 'IoElement_C_SE_NA', 154 'IoElement_C_SE_NB', 155 'IoElement_C_SE_NC', 156 'IoElement_C_BO_NA', 157 'IoElement_M_EI_NA', 158 'IoElement_C_IC_NA', 159 'IoElement_C_CI_NA', 160 'IoElement_C_RD_NA', 161 'IoElement_C_CS_NA', 162 'IoElement_C_RP_NA', 163 'IoElement_P_ME_NA', 164 'IoElement_P_ME_NB', 165 'IoElement_P_ME_NC', 166 'IoElement_P_AC_NA', 167 'IoElement_F_FR_NA', 168 'IoElement_F_SR_NA', 169 'IoElement_F_SC_NA', 170 'IoElement_F_LS_NA', 171 'IoElement_F_AF_NA', 172 'IoElement_F_SG_NA', 173 'IoElement_F_DR_TA', 174 'IoElement_C_SC_TA', 175 'IoElement_C_DC_TA', 176 'IoElement_C_RC_TA', 177 'IoElement_C_SE_TA', 178 'IoElement_C_SE_TB', 179 'IoElement_C_SE_TC', 180 'IoElement_C_BO_TA', 181 'IoElement_C_TS_TA', 182 'IoElement', 183 'IO', 184 'ASDU', 185 'iec101_asdu_types', 186 'Encoder']
Common base class for all non-exit exceptions.
An enumeration.
31class Time(typing.NamedTuple): 32 size: TimeSize 33 milliseconds: int 34 """milliseconds in range [0, 59999]""" 35 invalid: bool | None 36 """available for size THREE, FOUR, SEVEN""" 37 minutes: int | None 38 """available for size THREE, FOUR, SEVEN (minutes in range [0, 59])""" 39 summer_time: bool | None 40 """available for size FOUR, SEVEN""" 41 hours: int | None 42 """available for size FOUR, SEVEN (hours in range [0, 23])""" 43 day_of_week: int | None 44 """available for size SEVEN (day_of_week in range [1, 7])""" 45 day_of_month: int | None 46 """available for size SEVEN (day_of_month in range [1, 31])""" 47 months: int | None 48 """available for size SEVEN (months in range [1, 12])""" 49 years: int | None 50 """available for size SEVEN (years in range [0, 99])"""
Time(size, milliseconds, invalid, minutes, summer_time, hours, day_of_week, day_of_month, months, years)
Create new instance of Time(size, milliseconds, invalid, minutes, summer_time, hours, day_of_week, day_of_month, months, years)
66def time_from_datetime(dt: datetime.datetime, 67 invalid: bool = False 68 ) -> Time: 69 """Create Time from datetime.datetime""" 70 # TODO document edge cases (local time, os implementation, ...) 71 # rounding microseconds to the nearest millisecond 72 dt_rounded = ( 73 dt.replace(microsecond=0) + 74 datetime.timedelta(milliseconds=round(dt.microsecond / 1000))) 75 local_time = time.localtime(dt_rounded.timestamp()) 76 77 return Time( 78 size=TimeSize.SEVEN, 79 milliseconds=(local_time.tm_sec * 1000 + 80 dt_rounded.microsecond // 1000), 81 invalid=invalid, 82 minutes=local_time.tm_min, 83 summer_time=bool(local_time.tm_isdst), 84 hours=local_time.tm_hour, 85 day_of_week=local_time.tm_wday + 1, 86 day_of_month=local_time.tm_mday, 87 months=local_time.tm_mon, 88 years=local_time.tm_year % 100)
Create Time from datetime.datetime
91def time_to_datetime(t: Time 92 ) -> datetime.datetime: 93 """Convert Time to datetime.datetime""" 94 # TODO document edge cases (local time, os implementation, ...) 95 # TODO maybe allow diferent time size (use now for time) 96 if t.size != TimeSize.SEVEN: 97 raise ValueError('unsupported time size') 98 99 local_dt = datetime.datetime( 100 year=2000 + t.years if t.years < 70 else 1900 + t.years, 101 month=t.months, 102 day=t.day_of_month, 103 hour=t.hours, 104 minute=t.minutes, 105 second=int(t.milliseconds / 1000), 106 microsecond=(t.milliseconds % 1000) * 1000, 107 fold=not t.summer_time) 108 109 return local_dt.astimezone(tz=datetime.timezone.utc)
Convert Time to datetime.datetime
24class AsduType(enum.Enum): 25 M_SP_NA = iec101.AsduType.M_SP_NA.value 26 M_DP_NA = iec101.AsduType.M_DP_NA.value 27 M_ST_NA = iec101.AsduType.M_ST_NA.value 28 M_BO_NA = iec101.AsduType.M_BO_NA.value 29 M_ME_NA = iec101.AsduType.M_ME_NA.value 30 M_ME_NB = iec101.AsduType.M_ME_NB.value 31 M_ME_NC = iec101.AsduType.M_ME_NC.value 32 M_IT_NA = iec101.AsduType.M_IT_NA.value 33 M_PS_NA = iec101.AsduType.M_PS_NA.value 34 M_ME_ND = iec101.AsduType.M_ME_ND.value 35 M_SP_TB = iec101.AsduType.M_SP_TB.value 36 M_DP_TB = iec101.AsduType.M_DP_TB.value 37 M_ST_TB = iec101.AsduType.M_ST_TB.value 38 M_BO_TB = iec101.AsduType.M_BO_TB.value 39 M_ME_TD = iec101.AsduType.M_ME_TD.value 40 M_ME_TE = iec101.AsduType.M_ME_TE.value 41 M_ME_TF = iec101.AsduType.M_ME_TF.value 42 M_IT_TB = iec101.AsduType.M_IT_TB.value 43 M_EP_TD = iec101.AsduType.M_EP_TD.value 44 M_EP_TE = iec101.AsduType.M_EP_TE.value 45 M_EP_TF = iec101.AsduType.M_EP_TF.value 46 C_SC_NA = iec101.AsduType.C_SC_NA.value 47 C_DC_NA = iec101.AsduType.C_DC_NA.value 48 C_RC_NA = iec101.AsduType.C_RC_NA.value 49 C_SE_NA = iec101.AsduType.C_SE_NA.value 50 C_SE_NB = iec101.AsduType.C_SE_NB.value 51 C_SE_NC = iec101.AsduType.C_SE_NC.value 52 C_BO_NA = iec101.AsduType.C_BO_NA.value 53 C_SC_TA = 58 54 C_DC_TA = 59 55 C_RC_TA = 60 56 C_SE_TA = 61 57 C_SE_TB = 62 58 C_SE_TC = 63 59 C_BO_TA = 64 60 M_EI_NA = iec101.AsduType.M_EI_NA.value 61 C_IC_NA = iec101.AsduType.C_IC_NA.value 62 C_CI_NA = iec101.AsduType.C_CI_NA.value 63 C_RD_NA = iec101.AsduType.C_RD_NA.value 64 C_CS_NA = iec101.AsduType.C_CS_NA.value 65 C_RP_NA = iec101.AsduType.C_RP_NA.value 66 C_TS_TA = 107 67 P_ME_NA = iec101.AsduType.P_ME_NA.value 68 P_ME_NB = iec101.AsduType.P_ME_NB.value 69 P_ME_NC = iec101.AsduType.P_ME_NC.value 70 P_AC_NA = iec101.AsduType.P_AC_NA.value 71 F_FR_NA = iec101.AsduType.F_FR_NA.value 72 F_SR_NA = iec101.AsduType.F_SR_NA.value 73 F_SC_NA = iec101.AsduType.F_SC_NA.value 74 F_LS_NA = iec101.AsduType.F_LS_NA.value 75 F_AF_NA = iec101.AsduType.F_AF_NA.value 76 F_SG_NA = iec101.AsduType.F_SG_NA.value 77 F_DR_TA = iec101.AsduType.F_DR_TA.value
An enumeration.
90class CauseType(enum.Enum): 91 UNDEFINED = 0 92 PERIODIC = 1 93 BACKGROUND_SCAN = 2 94 SPONTANEOUS = 3 95 INITIALIZED = 4 96 REQUEST = 5 97 ACTIVATION = 6 98 ACTIVATION_CONFIRMATION = 7 99 DEACTIVATION = 8 100 DEACTIVATION_CONFIRMATION = 9 101 ACTIVATION_TERMINATION = 10 102 REMOTE_COMMAND = 11 103 LOCAL_COMMAND = 12 104 FILE_TRANSFER = 13 105 INTERROGATED_STATION = 20 106 INTERROGATED_GROUP01 = 21 107 INTERROGATED_GROUP02 = 22 108 INTERROGATED_GROUP03 = 23 109 INTERROGATED_GROUP04 = 24 110 INTERROGATED_GROUP05 = 25 111 INTERROGATED_GROUP06 = 26 112 INTERROGATED_GROUP07 = 27 113 INTERROGATED_GROUP08 = 28 114 INTERROGATED_GROUP09 = 29 115 INTERROGATED_GROUP10 = 30 116 INTERROGATED_GROUP11 = 31 117 INTERROGATED_GROUP12 = 32 118 INTERROGATED_GROUP13 = 33 119 INTERROGATED_GROUP14 = 34 120 INTERROGATED_GROUP15 = 35 121 INTERROGATED_GROUP16 = 36 122 INTERROGATED_COUNTER = 37 123 INTERROGATED_COUNTER01 = 38 124 INTERROGATED_COUNTER02 = 39 125 INTERROGATED_COUNTER03 = 40 126 INTERROGATED_COUNTER04 = 41 127 UNKNOWN_TYPE = 44 128 UNKNOWN_CAUSE = 45 129 UNKNOWN_ASDU_ADDRESS = 46 130 UNKNOWN_IO_ADDRESS = 47
An enumeration.
133class Cause(typing.NamedTuple): 134 type: CauseType | OtherCauseType 135 is_negative_confirm: bool 136 is_test: bool 137 originator_address: OriginatorAddress
Cause(type, is_negative_confirm, is_test, originator_address)
Create new instance of Cause(type, is_negative_confirm, is_test, originator_address)
140class QualityType(enum.Enum): 141 INDICATION = 0 142 MEASUREMENT = 1 143 COUNTER = 2 144 PROTECTION = 3
An enumeration.
147class IndicationQuality(typing.NamedTuple): 148 invalid: bool 149 not_topical: bool 150 substituted: bool 151 blocked: bool
IndicationQuality(invalid, not_topical, substituted, blocked)
154class MeasurementQuality(typing.NamedTuple): 155 invalid: bool 156 not_topical: bool 157 substituted: bool 158 blocked: bool 159 overflow: bool
MeasurementQuality(invalid, not_topical, substituted, blocked, overflow)
162class CounterQuality(typing.NamedTuple): 163 invalid: bool 164 adjusted: bool 165 overflow: bool 166 sequence: int 167 """sequence in range [0, 31]"""
CounterQuality(invalid, adjusted, overflow, sequence)
170class ProtectionQuality(typing.NamedTuple): 171 invalid: bool 172 not_topical: bool 173 substituted: bool 174 blocked: bool 175 time_invalid: bool
ProtectionQuality(invalid, not_topical, substituted, blocked, time_invalid)
An enumeration.
An enumeration.
196class DoubleValue(enum.Enum): 197 """DoubleDataValue 198 199 `FAULT` stands for value 3, defined in the protocol as *INDETERMINATE*. 200 This is in order to make it more distinguishable from ``INTERMEDIATE``. 201 202 """ 203 INTERMEDIATE = 0 204 OFF = 1 205 ON = 2 206 FAULT = 3
DoubleDataValue
FAULT
stands for value 3, defined in the protocol as INDETERMINATE.
This is in order to make it more distinguishable from INTERMEDIATE
.
An enumeration.
214class StepPositionValue(typing.NamedTuple): 215 value: int 216 """value in range [-64, 63]""" 217 transient: bool
StepPositionValue(value, transient)
220class BitstringValue(typing.NamedTuple): 221 value: util.Bytes 222 """bitstring encoded as 4 bytes"""
BitstringValue(value,)
NormalizedValue(value,)
ScaledValue(value,)
FloatingValue(value,)
239class BinaryCounterValue(typing.NamedTuple): 240 value: int 241 """value in range [-2^31, 2^31-1]"""
BinaryCounterValue(value,)
An enumeration.
249class ProtectionStartValue(typing.NamedTuple): 250 general: bool 251 l1: bool 252 l2: bool 253 l3: bool 254 ie: bool 255 reverse: bool
ProtectionStartValue(general, l1, l2, l3, ie, reverse)
258class ProtectionCommandValue(typing.NamedTuple): 259 general: bool 260 l1: bool 261 l2: bool 262 l3: bool
ProtectionCommandValue(general, l1, l2, l3)
265class StatusValue(typing.NamedTuple): 266 value: list[bool] 267 """value length is 16""" 268 change: list[bool] 269 """change length is 16"""
StatusValue(value, change)
272class IoElement_M_SP_NA(typing.NamedTuple): 273 value: SingleValue 274 quality: IndicationQuality
IoElement_M_SP_NA(value, quality)
Create new instance of IoElement_M_SP_NA(value, quality)
282class IoElement_M_DP_NA(typing.NamedTuple): 283 value: DoubleValue 284 quality: IndicationQuality
IoElement_M_DP_NA(value, quality)
Create new instance of IoElement_M_DP_NA(value, quality)
292class IoElement_M_ST_NA(typing.NamedTuple): 293 value: StepPositionValue 294 quality: MeasurementQuality
IoElement_M_ST_NA(value, quality)
Create new instance of IoElement_M_ST_NA(value, quality)
302class IoElement_M_BO_NA(typing.NamedTuple): 303 value: BitstringValue 304 quality: MeasurementQuality
IoElement_M_BO_NA(value, quality)
Create new instance of IoElement_M_BO_NA(value, quality)
312class IoElement_M_ME_NA(typing.NamedTuple): 313 value: NormalizedValue 314 quality: MeasurementQuality
IoElement_M_ME_NA(value, quality)
Create new instance of IoElement_M_ME_NA(value, quality)
322class IoElement_M_ME_NB(typing.NamedTuple): 323 value: ScaledValue 324 quality: MeasurementQuality
IoElement_M_ME_NB(value, quality)
Create new instance of IoElement_M_ME_NB(value, quality)
332class IoElement_M_ME_NC(typing.NamedTuple): 333 value: FloatingValue 334 quality: MeasurementQuality
IoElement_M_ME_NC(value, quality)
Create new instance of IoElement_M_ME_NC(value, quality)
342class IoElement_M_IT_NA(typing.NamedTuple): 343 value: BinaryCounterValue 344 quality: CounterQuality
IoElement_M_IT_NA(value, quality)
Create new instance of IoElement_M_IT_NA(value, quality)
373class IoElement_M_PS_NA(typing.NamedTuple): 374 value: StatusValue 375 quality: MeasurementQuality
IoElement_M_PS_NA(value, quality)
Create new instance of IoElement_M_PS_NA(value, quality)
IoElement_M_ME_ND(value,)
382class IoElement_M_SP_TB(typing.NamedTuple): 383 value: SingleValue 384 quality: IndicationQuality
IoElement_M_SP_TB(value, quality)
Create new instance of IoElement_M_SP_TB(value, quality)
387class IoElement_M_DP_TB(typing.NamedTuple): 388 value: DoubleValue 389 quality: IndicationQuality
IoElement_M_DP_TB(value, quality)
Create new instance of IoElement_M_DP_TB(value, quality)
392class IoElement_M_ST_TB(typing.NamedTuple): 393 value: StepPositionValue 394 quality: MeasurementQuality
IoElement_M_ST_TB(value, quality)
Create new instance of IoElement_M_ST_TB(value, quality)
397class IoElement_M_BO_TB(typing.NamedTuple): 398 value: BitstringValue 399 quality: MeasurementQuality
IoElement_M_BO_TB(value, quality)
Create new instance of IoElement_M_BO_TB(value, quality)
402class IoElement_M_ME_TD(typing.NamedTuple): 403 value: NormalizedValue 404 quality: MeasurementQuality
IoElement_M_ME_TD(value, quality)
Create new instance of IoElement_M_ME_TD(value, quality)
407class IoElement_M_ME_TE(typing.NamedTuple): 408 value: ScaledValue 409 quality: MeasurementQuality
IoElement_M_ME_TE(value, quality)
Create new instance of IoElement_M_ME_TE(value, quality)
412class IoElement_M_ME_TF(typing.NamedTuple): 413 value: FloatingValue 414 quality: MeasurementQuality
IoElement_M_ME_TF(value, quality)
Create new instance of IoElement_M_ME_TF(value, quality)
417class IoElement_M_IT_TB(typing.NamedTuple): 418 value: BinaryCounterValue 419 quality: CounterQuality
IoElement_M_IT_TB(value, quality)
Create new instance of IoElement_M_IT_TB(value, quality)
422class IoElement_M_EP_TD(typing.NamedTuple): 423 value: ProtectionValue 424 quality: ProtectionQuality 425 elapsed_time: int 426 """elapsed_time in range [0, 65535]"""
IoElement_M_EP_TD(value, quality, elapsed_time)
Create new instance of IoElement_M_EP_TD(value, quality, elapsed_time)
429class IoElement_M_EP_TE(typing.NamedTuple): 430 value: ProtectionStartValue 431 quality: ProtectionQuality 432 duration_time: int 433 """duration_time in range [0, 65535]"""
IoElement_M_EP_TE(value, quality, duration_time)
Create new instance of IoElement_M_EP_TE(value, quality, duration_time)
436class IoElement_M_EP_TF(typing.NamedTuple): 437 value: ProtectionCommandValue 438 quality: ProtectionQuality 439 operating_time: int 440 """operating_time in range [0, 65535]"""
IoElement_M_EP_TF(value, quality, operating_time)
Create new instance of IoElement_M_EP_TF(value, quality, operating_time)
443class IoElement_C_SC_NA(typing.NamedTuple): 444 value: SingleValue 445 select: bool 446 qualifier: int 447 """qualifier in range [0, 31]"""
IoElement_C_SC_NA(value, select, qualifier)
Create new instance of IoElement_C_SC_NA(value, select, qualifier)
450class IoElement_C_DC_NA(typing.NamedTuple): 451 value: DoubleValue 452 select: bool 453 qualifier: int 454 """qualifier in range [0, 31]"""
IoElement_C_DC_NA(value, select, qualifier)
Create new instance of IoElement_C_DC_NA(value, select, qualifier)
457class IoElement_C_RC_NA(typing.NamedTuple): 458 value: RegulatingValue 459 select: bool 460 qualifier: int 461 """qualifier in range [0, 31]"""
IoElement_C_RC_NA(value, select, qualifier)
Create new instance of IoElement_C_RC_NA(value, select, qualifier)
IoElement_C_SE_NA(value, select)
Create new instance of IoElement_C_SE_NA(value, select)
IoElement_C_SE_NB(value, select)
Create new instance of IoElement_C_SE_NB(value, select)
IoElement_C_SE_NC(value, select)
Create new instance of IoElement_C_SE_NC(value, select)
IoElement_C_BO_NA(value,)
483class IoElement_M_EI_NA(typing.NamedTuple): 484 param_change: bool 485 cause: int 486 """cause in range [0, 127]"""
IoElement_M_EI_NA(param_change, cause)
489class IoElement_C_IC_NA(typing.NamedTuple): 490 qualifier: int 491 """qualifier in range [0, 255]"""
IoElement_C_IC_NA(qualifier,)
494class IoElement_C_CI_NA(typing.NamedTuple): 495 request: int 496 """request in range [0, 63]""" 497 freeze: FreezeCode
IoElement_C_CI_NA(request, freeze)
Create new instance of IoElement_C_CI_NA(request, freeze)
IoElement_C_RD_NA()
IoElement_C_CS_NA(time,)
513class IoElement_C_RP_NA(typing.NamedTuple): 514 qualifier: int 515 """qualifier in range [0, 255]"""
IoElement_C_RP_NA(qualifier,)
523class IoElement_P_ME_NA(typing.NamedTuple): 524 value: NormalizedValue 525 qualifier: int 526 """qualifier in range [0, 255]"""
IoElement_P_ME_NA(value, qualifier)
Create new instance of IoElement_P_ME_NA(value, qualifier)
529class IoElement_P_ME_NB(typing.NamedTuple): 530 value: ScaledValue 531 qualifier: int 532 """qualifier in range [0, 255]"""
IoElement_P_ME_NB(value, qualifier)
Create new instance of IoElement_P_ME_NB(value, qualifier)
535class IoElement_P_ME_NC(typing.NamedTuple): 536 value: FloatingValue 537 qualifier: int 538 """qualifier in range [0, 255]"""
IoElement_P_ME_NC(value, qualifier)
Create new instance of IoElement_P_ME_NC(value, qualifier)
541class IoElement_P_AC_NA(typing.NamedTuple): 542 qualifier: int 543 """qualifier in range [0, 255]"""
IoElement_P_AC_NA(qualifier,)
546class IoElement_F_FR_NA(typing.NamedTuple): 547 file_name: int 548 """file_name in range [0, 65535]""" 549 file_length: int 550 """file_length in range [0, 16777215]""" 551 ready: bool
IoElement_F_FR_NA(file_name, file_length, ready)
554class IoElement_F_SR_NA(typing.NamedTuple): 555 file_name: int 556 """file_name in range [0, 65535]""" 557 section_name: int 558 """section_name in range [0, 255]""" 559 section_length: int 560 """section_length in range [0, 16777215]""" 561 ready: bool
IoElement_F_SR_NA(file_name, section_name, section_length, ready)
564class IoElement_F_SC_NA(typing.NamedTuple): 565 file_name: int 566 """file_name in range [0, 65535]""" 567 section_name: int 568 """section_name in range [0, 255]""" 569 qualifier: int 570 """qualifier in range [0, 255]"""
IoElement_F_SC_NA(file_name, section_name, qualifier)
573class IoElement_F_LS_NA(typing.NamedTuple): 574 file_name: int 575 """file_name in range [0, 65535]""" 576 section_name: int 577 """section_name in range [0, 255]""" 578 last_qualifier: int 579 """last_qualifier in range [0, 255]""" 580 checksum: int 581 """checksum in range [0, 255]"""
IoElement_F_LS_NA(file_name, section_name, last_qualifier, checksum)
584class IoElement_F_AF_NA(typing.NamedTuple): 585 file_name: int 586 """file_name in range [0, 65535]""" 587 section_name: int 588 """section_name in range [0, 255]""" 589 qualifier: int 590 """qualifier in range [0, 255]"""
IoElement_F_AF_NA(file_name, section_name, qualifier)
593class IoElement_F_SG_NA(typing.NamedTuple): 594 file_name: int 595 """file_name in range [0, 65535]""" 596 section_name: int 597 """section_name in range [0, 255]""" 598 segment: util.Bytes
IoElement_F_SG_NA(file_name, section_name, segment)
601class IoElement_F_DR_TA(typing.NamedTuple): 602 file_name: int 603 """file_name in range [0, 65535]""" 604 file_length: int 605 """file_length in range [0, 16777215]""" 606 more_follows: bool 607 is_directory: bool 608 transfer_active: bool 609 creation_time: Time
IoElement_F_DR_TA(file_name, file_length, more_follows, is_directory, transfer_active, creation_time)
Create new instance of IoElement_F_DR_TA(file_name, file_length, more_follows, is_directory, transfer_active, creation_time)
154class IoElement_C_SC_TA(typing.NamedTuple): 155 value: SingleValue 156 select: bool 157 qualifier: int 158 """qualifier in range [0, 31]"""
IoElement_C_SC_TA(value, select, qualifier)
Create new instance of IoElement_C_SC_TA(value, select, qualifier)
161class IoElement_C_DC_TA(typing.NamedTuple): 162 value: DoubleValue 163 select: bool 164 qualifier: int 165 """qualifier in range [0, 31]"""
IoElement_C_DC_TA(value, select, qualifier)
Create new instance of IoElement_C_DC_TA(value, select, qualifier)
168class IoElement_C_RC_TA(typing.NamedTuple): 169 value: RegulatingValue 170 select: bool 171 qualifier: int 172 """qualifier in range [0, 31]"""
IoElement_C_RC_TA(value, select, qualifier)
Create new instance of IoElement_C_RC_TA(value, select, qualifier)
IoElement_C_SE_TA(value, select)
Create new instance of IoElement_C_SE_TA(value, select)
IoElement_C_SE_TB(value, select)
Create new instance of IoElement_C_SE_TB(value, select)
IoElement_C_SE_TC(value, select)
Create new instance of IoElement_C_SE_TC(value, select)
IoElement_C_BO_TA(value,)
194class IoElement_C_TS_TA(typing.NamedTuple): 195 counter: int 196 """counter in range [0, 65535]"""
IoElement_C_TS_TA(counter,)
254class IO(typing.NamedTuple): 255 address: IoAddress 256 elements: list[IoElement] 257 time: Time | None
IO(address, elements, time)
Create new instance of IO(address, elements, time)
Alias for field number 1
260class ASDU(typing.NamedTuple): 261 type: AsduType 262 cause: Cause 263 address: AsduAddress 264 ios: list[IO]
ASDU(type, cause, address, ios)
56class Encoder: 57 58 def __init__(self, max_asdu_size: int = 249): 59 self._max_asdu_size = max_asdu_size 60 self._encoder = encoder.Encoder( 61 cause_size=common.CauseSize.TWO, 62 asdu_address_size=common.AsduAddressSize.TWO, 63 io_address_size=common.IoAddressSize.THREE, 64 asdu_type_time_sizes=_asdu_type_time_sizes, 65 inverted_sequence_bit=False, 66 decode_io_element_cb=_decode_io_element, 67 encode_io_element_cb=_encode_io_element) 68 69 @property 70 def max_asdu_size(self) -> int: 71 return self._max_asdu_size 72 73 @property 74 def cause_size(self) -> common.CauseSize: 75 return self._encoder.cause_size 76 77 @property 78 def asdu_address_size(self) -> common.AsduAddressSize: 79 return self._encoder.asdu_address_size 80 81 @property 82 def io_address_size(self) -> common.IoAddressSize: 83 return self._encoder.io_address_size 84 85 def decode_asdu(self, 86 asdu_bytes: util.Bytes 87 ) -> tuple[common.ASDU, util.Bytes]: 88 asdu, rest = self._encoder.decode_asdu(asdu_bytes) 89 90 asdu_type = _decode_asdu_type(asdu.type) 91 92 cause = iec101.decode_cause(asdu.cause, common.CauseSize.TWO) 93 address = asdu.address 94 ios = [common.IO(address=io.address, 95 elements=io.elements, 96 time=io.time) 97 for io in asdu.ios] 98 99 asdu = common.ASDU(type=asdu_type, 100 cause=cause, 101 address=address, 102 ios=ios) 103 return asdu, rest 104 105 def encode_asdu(self, asdu: common.ASDU) -> util.Bytes: 106 asdu_type = asdu.type.value 107 cause = iec101.encode_cause(asdu.cause, common.CauseSize.TWO) 108 address = asdu.address 109 ios = [encoder.common.IO(address=io.address, 110 elements=io.elements, 111 time=io.time) 112 for io in asdu.ios] 113 114 asdu = encoder.common.ASDU(type=asdu_type, 115 cause=cause, 116 address=address, 117 ios=ios) 118 119 return self._encoder.encode_asdu(asdu)
58 def __init__(self, max_asdu_size: int = 249): 59 self._max_asdu_size = max_asdu_size 60 self._encoder = encoder.Encoder( 61 cause_size=common.CauseSize.TWO, 62 asdu_address_size=common.AsduAddressSize.TWO, 63 io_address_size=common.IoAddressSize.THREE, 64 asdu_type_time_sizes=_asdu_type_time_sizes, 65 inverted_sequence_bit=False, 66 decode_io_element_cb=_decode_io_element, 67 encode_io_element_cb=_encode_io_element)
85 def decode_asdu(self, 86 asdu_bytes: util.Bytes 87 ) -> tuple[common.ASDU, util.Bytes]: 88 asdu, rest = self._encoder.decode_asdu(asdu_bytes) 89 90 asdu_type = _decode_asdu_type(asdu.type) 91 92 cause = iec101.decode_cause(asdu.cause, common.CauseSize.TWO) 93 address = asdu.address 94 ios = [common.IO(address=io.address, 95 elements=io.elements, 96 time=io.time) 97 for io in asdu.ios] 98 99 asdu = common.ASDU(type=asdu_type, 100 cause=cause, 101 address=address, 102 ios=ios) 103 return asdu, rest
105 def encode_asdu(self, asdu: common.ASDU) -> util.Bytes: 106 asdu_type = asdu.type.value 107 cause = iec101.encode_cause(asdu.cause, common.CauseSize.TWO) 108 address = asdu.address 109 ios = [encoder.common.IO(address=io.address, 110 elements=io.elements, 111 time=io.time) 112 for io in asdu.ios] 113 114 asdu = encoder.common.ASDU(type=asdu_type, 115 cause=cause, 116 address=address, 117 ios=ios) 118 119 return self._encoder.encode_asdu(asdu)