- .NET API: added MmsValue.SetOctetStringOctet and MmsValue.GetOctetStringOctet

- added positiion paramter validation for MmsValue_setOctetStringOctet
pull/367/head
Michael Zillgith 4 years ago
parent 9d4fb692fe
commit 92a3b7668d

@ -174,6 +174,12 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern UInt16 MmsValue_getOctetStringMaxSize(IntPtr self); static extern UInt16 MmsValue_getOctetStringMaxSize(IntPtr self);
[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)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr MmsValue_getOctetStringBuffer(IntPtr self); static extern IntPtr MmsValue_getOctetStringBuffer(IntPtr self);
@ -518,6 +524,11 @@ namespace IEC61850
throw new MmsValueException ("Operation not supported for this type"); throw new MmsValueException ("Operation not supported for this type");
} }
/// <summary>
/// Sets the value of an octet string by a byte array
/// </summary>
/// <param name="octetString">Byte array containing the bytes of the octet string.</param>
/// <exception cref="MmsValueException">This exception is thrown if the value has the wrong type or the byte array is too large.</exception>
public void setOctetString (byte[] octetString) public void setOctetString (byte[] octetString)
{ {
if (GetType () == MmsType.MMS_OCTET_STRING) { if (GetType () == MmsType.MMS_OCTET_STRING) {
@ -531,6 +542,26 @@ namespace IEC61850
throw new MmsValueException ("Operation not supported for this type"); throw new MmsValueException ("Operation not supported for this type");
} }
/// <summary>
/// Gets the octet string octet.
/// </summary>
/// <returns>The octet string octet.</returns>
/// <param name="pos">Position of the octet in the octet string.</param>
public byte GetOctetStringOctet(int pos)
{
return MmsValue_getOctetStringOctet(valueReference, pos);
}
/// <summary>
/// Sets the octet string octet.
/// </summary>
/// <param name="pos">Position of the octet in the octet string.</param>
/// <param name="value">The octet string octet.</param>
public void SetOctetStringOctet(int pos, byte value)
{
MmsValue_setOctetStringOctet(valueReference, pos, value);
}
/// <summary> /// <summary>
/// Get an element of an array or structure /// Get an element of an array or structure
/// </summary> /// </summary>

@ -1429,7 +1429,7 @@ MmsValue_setOctetString(MmsValue* self, const uint8_t* buf, int size)
void void
MmsValue_setOctetStringOctet(MmsValue* self, int octetPos, uint8_t value) 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; self->value.octetString.buf[octetPos] = value;
if (octetPos >= self->value.octetString.size) { if (octetPos >= self->value.octetString.size) {
@ -1460,9 +1460,11 @@ uint8_t
MmsValue_getOctetStringOctet(MmsValue* self, int octetPos) MmsValue_getOctetStringOctet(MmsValue* self, int octetPos)
{ {
uint8_t octet = 0x00; /* default value, for out of range request */ uint8_t octet = 0x00; /* default value, for out of range request */
if (octetPos < self->value.octetString.size) { if (octetPos < self->value.octetString.size) {
octet = self->value.octetString.buf[octetPos]; octet = self->value.octetString.buf[octetPos];
} }
return octet; return octet;
} }

Loading…
Cancel
Save