diff --git a/src/mms/inc/mms_value.h b/src/mms/inc/mms_value.h index b4222f04..e67bccb2 100644 --- a/src/mms/inc/mms_value.h +++ b/src/mms/inc/mms_value.h @@ -554,6 +554,21 @@ MmsValue_getBinaryTimeAsUtcMs(const MmsValue* self); LIB61850_API void MmsValue_setOctetString(MmsValue* self, const uint8_t* buf, int size); +/** + * \brief Set a single octet of an MmsValue object of type MMS_OCTET_STRING. + * + * This method will copy the provided octet to the internal buffer of the + * MmsValue instance, at the 'octetPos' position. This will only happen + * if the internal buffer size is large enough. Otherwise the object value is not changed. + * + * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING. + * \param octetPos the position of the octet in the octet string. Starting with 0. + * The octet with position 0 is the first octet if the MmsValue instance is serialized. + * \param value the new value of the octet (0 to 255, or 0x00 to 0xFF) + */ +LIB61850_API void +MmsValue_setOctetStringOctet(MmsValue* self, int octetPos, uint8_t value); + /** * \brief Returns the size in bytes of an MmsValue object of type MMS_OCTET_STRING. * @@ -592,6 +607,20 @@ MmsValue_getOctetStringMaxSize(MmsValue* self); LIB61850_API uint8_t* MmsValue_getOctetStringBuffer(MmsValue* self); +/** + * \brief Get the value of a single octet of an MmsType object of type MMS_OCTET_STRING + * + * NOTE: The octet quantity of the octet string can be requested with + * the \ref MmsValue_getOctetStringSize function. + * + * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING. + * \param octetPos the position of the octet in the octet string. Starting with 0. The octet + * with position 0 is the first octet if the MmsValue instance is serialized. + * \return the value of the octet (0 to 255, or 0x00 to 0xFF) + */ +LIB61850_API uint8_t +MmsValue_getOctetStringOctet(MmsValue* self, int octetPos); + /** * \brief Update the value of an MmsValue instance by the value of another MmsValue instance. * diff --git a/src/mms/iso_mms/common/mms_value.c b/src/mms/iso_mms/common/mms_value.c index b6538262..0da7a196 100644 --- a/src/mms/iso_mms/common/mms_value.c +++ b/src/mms/iso_mms/common/mms_value.c @@ -1426,6 +1426,18 @@ MmsValue_setOctetString(MmsValue* self, const uint8_t* buf, int size) } } +void +MmsValue_setOctetStringOctet(MmsValue* self, int octetPos, uint8_t value) +{ + if (octetPos < self->value.octetString.maxSize) { + self->value.octetString.buf[octetPos] = value; + + if (octetPos >= self->value.octetString.size) { + self->value.octetString.size = octetPos + 1; + } + } +} + uint16_t MmsValue_getOctetStringSize(const MmsValue* self) { @@ -1444,6 +1456,16 @@ MmsValue_getOctetStringBuffer(MmsValue* self) return self->value.octetString.buf; } +uint8_t +MmsValue_getOctetStringOctet(MmsValue* self, int octetPos) +{ + uint8_t octet = 0x00; /* default value, for out of range request */ + if (octetPos < self->value.octetString.size) { + octet = self->value.octetString.buf[octetPos]; + } + return octet; +} + MmsValue* MmsValue_newStructure(const MmsVariableSpecification* typeSpec) {