hat.drivers.iec101
IEC 60870-5-101 communication protocol
1"""IEC 60870-5-101 communication protocol""" 2 3from hat.drivers.iec101.common import (AsduTypeError, 4 Address, 5 AddressSize, 6 CauseSize, 7 AsduAddressSize, 8 IoAddressSize, 9 TimeSize, 10 Time, 11 OriginatorAddress, 12 AsduAddress, 13 IoAddress, 14 IndicationQuality, 15 MeasurementQuality, 16 CounterQuality, 17 ProtectionQuality, 18 Quality, 19 FreezeCode, 20 SingleValue, 21 DoubleValue, 22 RegulatingValue, 23 StepPositionValue, 24 BitstringValue, 25 NormalizedValue, 26 ScaledValue, 27 FloatingValue, 28 BinaryCounterValue, 29 ProtectionValue, 30 ProtectionStartValue, 31 ProtectionCommandValue, 32 StatusValue, 33 OtherCause, 34 DataResCause, 35 DataCause, 36 CommandReqCause, 37 CommandResCause, 38 CommandCause, 39 InitializationResCause, 40 InitializationCause, 41 ReadReqCause, 42 ReadResCause, 43 ReadCause, 44 ClockSyncReqCause, 45 ClockSyncResCause, 46 ClockSyncCause, 47 ActivationReqCause, 48 ActivationResCause, 49 ActivationCause, 50 DelayReqCause, 51 DelayResCause, 52 DelayCause, 53 ParameterReqCause, 54 ParameterResCause, 55 ParameterCause, 56 ParameterActivationReqCause, 57 ParameterActivationResCause, 58 ParameterActivationCause, 59 SingleData, 60 DoubleData, 61 StepPositionData, 62 BitstringData, 63 NormalizedData, 64 ScaledData, 65 FloatingData, 66 BinaryCounterData, 67 ProtectionData, 68 ProtectionStartData, 69 ProtectionCommandData, 70 StatusData, 71 Data, 72 SingleCommand, 73 DoubleCommand, 74 RegulatingCommand, 75 NormalizedCommand, 76 ScaledCommand, 77 FloatingCommand, 78 BitstringCommand, 79 Command, 80 NormalizedParameter, 81 ScaledParameter, 82 FloatingParameter, 83 Parameter, 84 DataMsg, 85 CommandMsg, 86 InitializationMsg, 87 InterrogationMsg, 88 CounterInterrogationMsg, 89 ReadMsg, 90 ClockSyncMsg, 91 TestMsg, 92 ResetMsg, 93 DelayMsg, 94 ParameterMsg, 95 ParameterActivationMsg, 96 Msg, 97 time_from_datetime, 98 time_to_datetime) 99from hat.drivers.iec101.master import MasterConnection 100from hat.drivers.iec101.slave import SlaveConnection 101 102 103__all__ = ['AsduTypeError', 104 'Address', 105 'AddressSize', 106 'CauseSize', 107 'AsduAddressSize', 108 'IoAddressSize', 109 'TimeSize', 110 'Time', 111 'OriginatorAddress', 112 'AsduAddress', 113 'IoAddress', 114 'IndicationQuality', 115 'MeasurementQuality', 116 'CounterQuality', 117 'ProtectionQuality', 118 'Quality', 119 'FreezeCode', 120 'SingleValue', 121 'DoubleValue', 122 'RegulatingValue', 123 'StepPositionValue', 124 'BitstringValue', 125 'NormalizedValue', 126 'ScaledValue', 127 'FloatingValue', 128 'BinaryCounterValue', 129 'ProtectionValue', 130 'ProtectionStartValue', 131 'ProtectionCommandValue', 132 'StatusValue', 133 'OtherCause', 134 'DataResCause', 135 'DataCause', 136 'CommandReqCause', 137 'CommandResCause', 138 'CommandCause', 139 'InitializationResCause', 140 'InitializationCause', 141 'ReadReqCause', 142 'ReadResCause', 143 'ReadCause', 144 'ClockSyncReqCause', 145 'ClockSyncResCause', 146 'ClockSyncCause', 147 'ActivationReqCause', 148 'ActivationResCause', 149 'ActivationCause', 150 'DelayReqCause', 151 'DelayResCause', 152 'DelayCause', 153 'ParameterReqCause', 154 'ParameterResCause', 155 'ParameterCause', 156 'ParameterActivationReqCause', 157 'ParameterActivationResCause', 158 'ParameterActivationCause', 159 'SingleData', 160 'DoubleData', 161 'StepPositionData', 162 'BitstringData', 163 'NormalizedData', 164 'ScaledData', 165 'FloatingData', 166 'BinaryCounterData', 167 'ProtectionData', 168 'ProtectionStartData', 169 'ProtectionCommandData', 170 'StatusData', 171 'Data', 172 'SingleCommand', 173 'DoubleCommand', 174 'RegulatingCommand', 175 'NormalizedCommand', 176 'ScaledCommand', 177 'FloatingCommand', 178 'BitstringCommand', 179 'Command', 180 'NormalizedParameter', 181 'ScaledParameter', 182 'FloatingParameter', 183 'Parameter', 184 'DataMsg', 185 'CommandMsg', 186 'InitializationMsg', 187 'InterrogationMsg', 188 'CounterInterrogationMsg', 189 'ReadMsg', 190 'ClockSyncMsg', 191 'TestMsg', 192 'ResetMsg', 193 'DelayMsg', 194 'ParameterMsg', 195 'ParameterActivationMsg', 196 'Msg', 197 'time_from_datetime', 198 'time_to_datetime', 199 'MasterConnection', 200 'SlaveConnection']
Common base class for all non-exit exceptions.
An enumeration.
An enumeration.
An enumeration.
An enumeration.
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)
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)
50class DataResCause(enum.Enum): 51 PERIODIC = iec101.CauseType.PERIODIC.value 52 BACKGROUND_SCAN = iec101.CauseType.BACKGROUND_SCAN.value 53 SPONTANEOUS = iec101.CauseType.SPONTANEOUS.value 54 REQUEST = iec101.CauseType.REQUEST.value 55 REMOTE_COMMAND = iec101.CauseType.REMOTE_COMMAND.value 56 LOCAL_COMMAND = iec101.CauseType.LOCAL_COMMAND.value 57 INTERROGATED_STATION = iec101.CauseType.INTERROGATED_STATION.value 58 INTERROGATED_GROUP01 = iec101.CauseType.INTERROGATED_GROUP01.value 59 INTERROGATED_GROUP02 = iec101.CauseType.INTERROGATED_GROUP02.value 60 INTERROGATED_GROUP03 = iec101.CauseType.INTERROGATED_GROUP03.value 61 INTERROGATED_GROUP04 = iec101.CauseType.INTERROGATED_GROUP04.value 62 INTERROGATED_GROUP05 = iec101.CauseType.INTERROGATED_GROUP05.value 63 INTERROGATED_GROUP06 = iec101.CauseType.INTERROGATED_GROUP06.value 64 INTERROGATED_GROUP07 = iec101.CauseType.INTERROGATED_GROUP07.value 65 INTERROGATED_GROUP08 = iec101.CauseType.INTERROGATED_GROUP08.value 66 INTERROGATED_GROUP09 = iec101.CauseType.INTERROGATED_GROUP09.value 67 INTERROGATED_GROUP10 = iec101.CauseType.INTERROGATED_GROUP10.value 68 INTERROGATED_GROUP11 = iec101.CauseType.INTERROGATED_GROUP11.value 69 INTERROGATED_GROUP12 = iec101.CauseType.INTERROGATED_GROUP12.value 70 INTERROGATED_GROUP13 = iec101.CauseType.INTERROGATED_GROUP13.value 71 INTERROGATED_GROUP14 = iec101.CauseType.INTERROGATED_GROUP14.value 72 INTERROGATED_GROUP15 = iec101.CauseType.INTERROGATED_GROUP15.value 73 INTERROGATED_GROUP16 = iec101.CauseType.INTERROGATED_GROUP16.value 74 INTERROGATED_COUNTER = iec101.CauseType.INTERROGATED_COUNTER.value 75 INTERROGATED_COUNTER01 = iec101.CauseType.INTERROGATED_COUNTER01.value 76 INTERROGATED_COUNTER02 = iec101.CauseType.INTERROGATED_COUNTER02.value 77 INTERROGATED_COUNTER03 = iec101.CauseType.INTERROGATED_COUNTER03.value 78 INTERROGATED_COUNTER04 = iec101.CauseType.INTERROGATED_COUNTER04.value
An enumeration.
84class CommandReqCause(enum.Enum): 85 ACTIVATION = iec101.CauseType.ACTIVATION.value 86 DEACTIVATION = iec101.CauseType.DEACTIVATION.value
An enumeration.
89class CommandResCause(enum.Enum): 90 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 91 DEACTIVATION_CONFIRMATION = iec101.CauseType.DEACTIVATION_CONFIRMATION.value # NOQA 92 ACTIVATION_TERMINATION = iec101.CauseType.ACTIVATION_TERMINATION.value 93 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 94 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 95 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 96 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
102class InitializationResCause(enum.Enum): 103 LOCAL_POWER = 0 104 LOCAL_RESET = 1 105 REMOTE_RESET = 2
An enumeration.
An enumeration.
115class ReadResCause(enum.Enum): 116 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 117 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 118 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 119 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
An enumeration.
129class ClockSyncResCause(enum.Enum): 130 SPONTANEOUS = iec101.CauseType.SPONTANEOUS.value 131 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 132 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 133 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 134 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 135 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
An enumeration.
147class ActivationResCause(enum.Enum): 148 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 149 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 150 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 151 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 152 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
160class DelayReqCause(enum.Enum): 161 SPONTANEOUS = iec101.CauseType.SPONTANEOUS.value 162 ACTIVATION = iec101.CauseType.ACTIVATION.value
An enumeration.
165class DelayResCause(enum.Enum): 166 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 167 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 168 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 169 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 170 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
176class ParameterReqCause(enum.Enum): 177 SPONTANEOUS = iec101.CauseType.SPONTANEOUS.value 178 ACTIVATION = iec101.CauseType.ACTIVATION.value
An enumeration.
181class ParameterResCause(enum.Enum): 182 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 183 INTERROGATED_STATION = iec101.CauseType.INTERROGATED_STATION.value 184 INTERROGATED_GROUP01 = iec101.CauseType.INTERROGATED_GROUP01.value 185 INTERROGATED_GROUP02 = iec101.CauseType.INTERROGATED_GROUP02.value 186 INTERROGATED_GROUP03 = iec101.CauseType.INTERROGATED_GROUP03.value 187 INTERROGATED_GROUP04 = iec101.CauseType.INTERROGATED_GROUP04.value 188 INTERROGATED_GROUP05 = iec101.CauseType.INTERROGATED_GROUP05.value 189 INTERROGATED_GROUP06 = iec101.CauseType.INTERROGATED_GROUP06.value 190 INTERROGATED_GROUP07 = iec101.CauseType.INTERROGATED_GROUP07.value 191 INTERROGATED_GROUP08 = iec101.CauseType.INTERROGATED_GROUP08.value 192 INTERROGATED_GROUP09 = iec101.CauseType.INTERROGATED_GROUP09.value 193 INTERROGATED_GROUP10 = iec101.CauseType.INTERROGATED_GROUP10.value 194 INTERROGATED_GROUP11 = iec101.CauseType.INTERROGATED_GROUP11.value 195 INTERROGATED_GROUP12 = iec101.CauseType.INTERROGATED_GROUP12.value 196 INTERROGATED_GROUP13 = iec101.CauseType.INTERROGATED_GROUP13.value 197 INTERROGATED_GROUP14 = iec101.CauseType.INTERROGATED_GROUP14.value 198 INTERROGATED_GROUP15 = iec101.CauseType.INTERROGATED_GROUP15.value 199 INTERROGATED_GROUP16 = iec101.CauseType.INTERROGATED_GROUP16.value 200 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 201 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 202 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 203 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
211class ParameterActivationReqCause(enum.Enum): 212 ACTIVATION = iec101.CauseType.ACTIVATION.value 213 DEACTIVATION = iec101.CauseType.DEACTIVATION.value
An enumeration.
216class ParameterActivationResCause(enum.Enum): 217 ACTIVATION_CONFIRMATION = iec101.CauseType.ACTIVATION_CONFIRMATION.value 218 DEACTIVATION_CONFIRMATION = iec101.CauseType.DEACTIVATION_CONFIRMATION.value # NOQA 219 UNKNOWN_TYPE = iec101.CauseType.UNKNOWN_TYPE.value 220 UNKNOWN_CAUSE = iec101.CauseType.UNKNOWN_CAUSE.value 221 UNKNOWN_ASDU_ADDRESS = iec101.CauseType.UNKNOWN_ASDU_ADDRESS.value 222 UNKNOWN_IO_ADDRESS = iec101.CauseType.UNKNOWN_IO_ADDRESS.value
An enumeration.
SingleData(value, quality)
Create new instance of SingleData(value, quality)
DoubleData(value, quality)
Create new instance of DoubleData(value, quality)
240class StepPositionData(typing.NamedTuple): 241 value: StepPositionValue 242 quality: MeasurementQuality
StepPositionData(value, quality)
Create new instance of StepPositionData(value, quality)
245class BitstringData(typing.NamedTuple): 246 value: BitstringValue 247 quality: MeasurementQuality
BitstringData(value, quality)
Create new instance of BitstringData(value, quality)
250class NormalizedData(typing.NamedTuple): 251 value: NormalizedValue 252 quality: MeasurementQuality | None
NormalizedData(value, quality)
Create new instance of NormalizedData(value, quality)
ScaledData(value, quality)
Create new instance of ScaledData(value, quality)
FloatingData(value, quality)
Create new instance of FloatingData(value, quality)
265class BinaryCounterData(typing.NamedTuple): 266 value: BinaryCounterValue 267 quality: CounterQuality
BinaryCounterData(value, quality)
Create new instance of BinaryCounterData(value, quality)
270class ProtectionData(typing.NamedTuple): 271 value: ProtectionValue 272 quality: ProtectionQuality 273 elapsed_time: int 274 """elapsed_time in range [0, 65535]"""
ProtectionData(value, quality, elapsed_time)
Create new instance of ProtectionData(value, quality, elapsed_time)
277class ProtectionStartData(typing.NamedTuple): 278 value: ProtectionStartValue 279 quality: ProtectionQuality 280 duration_time: int 281 """duration_time in range [0, 65535]"""
ProtectionStartData(value, quality, duration_time)
Create new instance of ProtectionStartData(value, quality, duration_time)
284class ProtectionCommandData(typing.NamedTuple): 285 value: ProtectionCommandValue 286 quality: ProtectionQuality 287 operating_time: int 288 """operating_time in range [0, 65535]"""
ProtectionCommandData(value, quality, operating_time)
Create new instance of ProtectionCommandData(value, quality, operating_time)
StatusData(value, quality)
Create new instance of StatusData(value, quality)
310class SingleCommand(typing.NamedTuple): 311 value: SingleValue 312 select: bool 313 qualifier: int 314 """qualifier in range [0, 31]"""
SingleCommand(value, select, qualifier)
Create new instance of SingleCommand(value, select, qualifier)
317class DoubleCommand(typing.NamedTuple): 318 value: DoubleValue 319 select: bool 320 qualifier: int 321 """qualifier in range [0, 31]"""
DoubleCommand(value, select, qualifier)
Create new instance of DoubleCommand(value, select, qualifier)
324class RegulatingCommand(typing.NamedTuple): 325 value: RegulatingValue 326 select: bool 327 qualifier: int 328 """qualifier in range [0, 31]"""
RegulatingCommand(value, select, qualifier)
Create new instance of RegulatingCommand(value, select, qualifier)
NormalizedCommand(value, select)
Create new instance of NormalizedCommand(value, select)
ScaledCommand(value, select)
Create new instance of ScaledCommand(value, select)
FloatingCommand(value, select)
Create new instance of FloatingCommand(value, select)
BitstringCommand(value,)
359class NormalizedParameter(typing.NamedTuple): 360 value: NormalizedValue 361 qualifier: int 362 """qualifier in range [0, 255]"""
NormalizedParameter(value, qualifier)
Create new instance of NormalizedParameter(value, qualifier)
365class ScaledParameter(typing.NamedTuple): 366 value: ScaledValue 367 qualifier: int 368 """qualifier in range [0, 255]"""
ScaledParameter(value, qualifier)
Create new instance of ScaledParameter(value, qualifier)
371class FloatingParameter(typing.NamedTuple): 372 value: FloatingValue 373 qualifier: int 374 """qualifier in range [0, 255]"""
FloatingParameter(value, qualifier)
Create new instance of FloatingParameter(value, qualifier)
382class DataMsg(typing.NamedTuple): 383 is_test: bool 384 originator_address: OriginatorAddress 385 asdu_address: AsduAddress 386 io_address: IoAddress 387 data: Data 388 time: Time | None 389 cause: DataCause
DataMsg(is_test, originator_address, asdu_address, io_address, data, time, cause)
Create new instance of DataMsg(is_test, originator_address, asdu_address, io_address, data, time, cause)
Alias for field number 4
392class CommandMsg(typing.NamedTuple): 393 is_test: bool 394 originator_address: OriginatorAddress 395 asdu_address: AsduAddress 396 io_address: IoAddress 397 command: Command 398 is_negative_confirm: bool 399 cause: CommandCause
CommandMsg(is_test, originator_address, asdu_address, io_address, command, is_negative_confirm, cause)
Create new instance of CommandMsg(is_test, originator_address, asdu_address, io_address, command, is_negative_confirm, cause)
Alias for field number 4
402class InitializationMsg(typing.NamedTuple): 403 is_test: bool 404 originator_address: OriginatorAddress 405 asdu_address: AsduAddress 406 param_change: bool 407 cause: InitializationCause
InitializationMsg(is_test, originator_address, asdu_address, param_change, cause)
Create new instance of InitializationMsg(is_test, originator_address, asdu_address, param_change, cause)
410class InterrogationMsg(typing.NamedTuple): 411 is_test: bool 412 originator_address: OriginatorAddress 413 asdu_address: AsduAddress 414 request: int 415 """request in range [0, 255]""" 416 is_negative_confirm: bool 417 cause: CommandCause
InterrogationMsg(is_test, originator_address, asdu_address, request, is_negative_confirm, cause)
Create new instance of InterrogationMsg(is_test, originator_address, asdu_address, request, is_negative_confirm, cause)
420class CounterInterrogationMsg(typing.NamedTuple): 421 is_test: bool 422 originator_address: OriginatorAddress 423 asdu_address: AsduAddress 424 request: int 425 """request in range [0, 63]""" 426 freeze: FreezeCode 427 is_negative_confirm: bool 428 cause: CommandCause
CounterInterrogationMsg(is_test, originator_address, asdu_address, request, freeze, is_negative_confirm, cause)
Create new instance of CounterInterrogationMsg(is_test, originator_address, asdu_address, request, freeze, is_negative_confirm, cause)
431class ReadMsg(typing.NamedTuple): 432 is_test: bool 433 originator_address: OriginatorAddress 434 asdu_address: AsduAddress 435 io_address: IoAddress 436 cause: ReadCause
ReadMsg(is_test, originator_address, asdu_address, io_address, cause)
Create new instance of ReadMsg(is_test, originator_address, asdu_address, io_address, cause)
439class ClockSyncMsg(typing.NamedTuple): 440 is_test: bool 441 originator_address: OriginatorAddress 442 asdu_address: AsduAddress 443 time: Time 444 is_negative_confirm: bool 445 cause: ClockSyncCause
ClockSyncMsg(is_test, originator_address, asdu_address, time, is_negative_confirm, cause)
Create new instance of ClockSyncMsg(is_test, originator_address, asdu_address, time, is_negative_confirm, cause)
448class TestMsg(typing.NamedTuple): 449 is_test: bool 450 originator_address: OriginatorAddress 451 asdu_address: AsduAddress 452 cause: ActivationCause
TestMsg(is_test, originator_address, asdu_address, cause)
Create new instance of TestMsg(is_test, originator_address, asdu_address, cause)
455class ResetMsg(typing.NamedTuple): 456 is_test: bool 457 originator_address: OriginatorAddress 458 asdu_address: AsduAddress 459 qualifier: int 460 """qualifier in range [0, 255]""" 461 cause: ActivationCause
ResetMsg(is_test, originator_address, asdu_address, qualifier, cause)
Create new instance of ResetMsg(is_test, originator_address, asdu_address, qualifier, cause)
464class DelayMsg(typing.NamedTuple): 465 is_test: bool 466 originator_address: OriginatorAddress 467 asdu_address: AsduAddress 468 time: int 469 """time in range [0, 65535]""" 470 cause: DelayCause
DelayMsg(is_test, originator_address, asdu_address, time, cause)
Create new instance of DelayMsg(is_test, originator_address, asdu_address, time, cause)
473class ParameterMsg(typing.NamedTuple): 474 is_test: bool 475 originator_address: OriginatorAddress 476 asdu_address: AsduAddress 477 io_address: IoAddress 478 parameter: Parameter 479 cause: ParameterCause
ParameterMsg(is_test, originator_address, asdu_address, io_address, parameter, cause)
Create new instance of ParameterMsg(is_test, originator_address, asdu_address, io_address, parameter, cause)
482class ParameterActivationMsg(typing.NamedTuple): 483 is_test: bool 484 originator_address: OriginatorAddress 485 asdu_address: AsduAddress 486 io_address: IoAddress 487 qualifier: int 488 """qualifier in range [0, 255]""" 489 cause: ParameterActivationCause
ParameterActivationMsg(is_test, originator_address, asdu_address, io_address, qualifier, cause)
Create new instance of ParameterActivationMsg(is_test, originator_address, asdu_address, io_address, qualifier, cause)
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
9class MasterConnection(aio.Resource): 10 11 def __init__(self, 12 conn: unbalanced.MasterConnection, 13 cause_size: common.CauseSize, 14 asdu_address_size: common.AsduAddressSize, 15 io_address_size: common.IoAddressSize): 16 self._conn = conn 17 self._encoder = encoder.Encoder(cause_size=cause_size, 18 asdu_address_size=asdu_address_size, 19 io_address_size=io_address_size) 20 21 @property 22 def async_group(self): 23 return self._conn.async_group 24 25 @property 26 def address(self) -> common.Address: 27 return self._conn.address 28 29 async def send(self, msgs: list[common.Msg]): 30 for data in self._encoder.encode(msgs): 31 await self._conn.send(data) 32 33 async def receive(self) -> list[common.Msg]: 34 data = await self._conn.receive() 35 return list(self._encoder.decode(data))
Resource with lifetime control based on Group
.
11 def __init__(self, 12 conn: unbalanced.MasterConnection, 13 cause_size: common.CauseSize, 14 asdu_address_size: common.AsduAddressSize, 15 io_address_size: common.IoAddressSize): 16 self._conn = conn 17 self._encoder = encoder.Encoder(cause_size=cause_size, 18 asdu_address_size=asdu_address_size, 19 io_address_size=io_address_size)
11class SlaveConnection(aio.Resource): 12 13 def __init__(self, 14 conn: unbalanced.SlaveConnection, 15 cause_size: common.CauseSize, 16 asdu_address_size: common.AsduAddressSize, 17 io_address_size: common.IoAddressSize): 18 self._conn = conn 19 self._encoder = encoder.Encoder(cause_size=cause_size, 20 asdu_address_size=asdu_address_size, 21 io_address_size=io_address_size) 22 23 @property 24 def async_group(self): 25 return self._conn.async_group 26 27 @property 28 def address(self) -> common.Address: 29 return self._conn.address 30 31 def send(self, 32 msgs: list[common.Msg], 33 sent_cb: aio.AsyncCallable[[], None] | None = None): 34 data = collections.deque(self._encoder.encode(msgs)) 35 while data: 36 i = data.popleft() 37 self._conn.send(i, sent_cb=None if data else sent_cb) 38 39 async def receive(self) -> list[common.Msg]: 40 data = await self._conn.receive() 41 return list(self._encoder.decode(data))
Resource with lifetime control based on Group
.
13 def __init__(self, 14 conn: unbalanced.SlaveConnection, 15 cause_size: common.CauseSize, 16 asdu_address_size: common.AsduAddressSize, 17 io_address_size: common.IoAddressSize): 18 self._conn = conn 19 self._encoder = encoder.Encoder(cause_size=cause_size, 20 asdu_address_size=asdu_address_size, 21 io_address_size=io_address_size)