diff --git a/dotnet/IEC61850forCSharp/MmsValue.cs b/dotnet/IEC61850forCSharp/MmsValue.cs index 3b5e06ee..d262688a 100644 --- a/dotnet/IEC61850forCSharp/MmsValue.cs +++ b/dotnet/IEC61850forCSharp/MmsValue.cs @@ -174,7 +174,13 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern UInt16 MmsValue_getOctetStringMaxSize(IntPtr self); - [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern byte MmsValue_getOctetStringOctet(IntPtr self, int pos); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern void MmsValue_setOctetStringOctet(IntPtr self, int pos, byte value); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr MmsValue_getOctetStringBuffer(IntPtr self); [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] @@ -518,6 +524,11 @@ namespace IEC61850 throw new MmsValueException ("Operation not supported for this type"); } + /// + /// Sets the value of an octet string by a byte array + /// + /// Byte array containing the bytes of the octet string. + /// This exception is thrown if the value has the wrong type or the byte array is too large. public void setOctetString (byte[] octetString) { if (GetType () == MmsType.MMS_OCTET_STRING) { @@ -531,6 +542,26 @@ namespace IEC61850 throw new MmsValueException ("Operation not supported for this type"); } + /// + /// Gets the octet string octet. + /// + /// The octet string octet. + /// Position of the octet in the octet string. + public byte GetOctetStringOctet(int pos) + { + return MmsValue_getOctetStringOctet(valueReference, pos); + } + + /// + /// Sets the octet string octet. + /// + /// Position of the octet in the octet string. + /// The octet string octet. + public void SetOctetStringOctet(int pos, byte value) + { + MmsValue_setOctetStringOctet(valueReference, pos, value); + } + /// /// Get an element of an array or structure /// diff --git a/src/mms/iso_mms/common/mms_value.c b/src/mms/iso_mms/common/mms_value.c index 0da7a196..1281c8a8 100644 --- a/src/mms/iso_mms/common/mms_value.c +++ b/src/mms/iso_mms/common/mms_value.c @@ -1429,7 +1429,7 @@ 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) { + if ((octetPos >= 0) && (octetPos < self->value.octetString.maxSize)) { self->value.octetString.buf[octetPos] = value; if (octetPos >= self->value.octetString.size) { @@ -1460,9 +1460,11 @@ 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; }