I’m new to using pyasn1 and am trying to convert a SEQUENCE type to a python class model following the Berkeley published PyASN1 programmer’s manual documentation
The IEC 61850-9-2 Section 8.5.2 Table 14 Encoding for a SavPdu is defined as
SavPdu ::= SEQUENCE {
noASDU [0] IMPLICIT INTEGER (1..65535),
security [1] ANY OPTIONAL,
asdu [2] IMPLICIT SEQUENCE OF ASDU
}
ASDU ::= SEQUENCE {
svID [0] IMPLICIT VisibleString,
datset [1] IMPLICIT VisibleString OPTIONAL,
smpCnt [2] IMPLICIT OCTET STRING (SIZE(2)),
confRev [3] IMPLICIT OCTET STRING (SIZE(4)),
refrTm [4] IMPLICIT UtcTime OPTIONAL,
smpSynch [5] IMPLICIT OCTET STRING (SIZE(1)),
smpRate [6] IMPLICIT OCTET STRING (SIZE(2)) OPTIONAL,
sample [7] IMPLICIT OCTET STRING (SIZE(n)),
smpMod [8] IMPLICIT OCTET STRING (SIZE(2)) OPTIONAL
}
This is my first attempt at creating a python class of the above model:
from pyasn1.type import constraint, namedtype, tag, univ
class SavPdu(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('noASDU', univ.Integer(suptypeSpec = constraint.ValueRangeConstraint(1,65535)).tagSet.tagImplicitly(tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('security', univ.Any),
namedtype.NamedType('asdu', univ.Sequence(ASDU).tagSet.tagImplicitly(tag.tagClassContext, tag.tagFormatSimple, 2))
)
where ASDU is another python class defined elsewhere in the file.
Am I defining my class correctly based on the model and library?