- IED server: Add function ModelNode_getObjectReferenceEx

pull/331/head
Michael Zillgith 5 years ago
parent 5e39c94cf3
commit 5afa1310f3

@ -797,7 +797,10 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModelNode_getObjectReference(IntPtr self, IntPtr objectReference);
public IntPtr self;
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModelNode_getObjectReferenceEx(IntPtr self, IntPtr objectReference, [MarshalAs(UnmanagedType.I1)] bool withoutIedName);
public IntPtr self;
internal ModelNode()
{
@ -836,9 +839,14 @@ namespace IEC61850
}
public string GetObjectReference()
/// <summary>
/// Gets the object reference of the model node
/// </summary>
/// <returns>the object reference</returns>
/// <param name="withoutIedName">If set to <c>true</c> the object reference is created without IED name.</param>
public string GetObjectReference(bool withoutIedName = false)
{
IntPtr objRefPtr = ModelNode_getObjectReference(self, IntPtr.Zero);
IntPtr objRefPtr = ModelNode_getObjectReferenceEx(self, IntPtr.Zero, withoutIedName);
if (objRefPtr != IntPtr.Zero) {
string objRef = Marshal.PtrToStringAnsi(objRefPtr);

@ -397,6 +397,19 @@ ModelNode_getChildWithFc(ModelNode* self, const char* name, FunctionalConstraint
LIB61850_API char*
ModelNode_getObjectReference(ModelNode* self, char* objectReference);
/**
* \brief Return the IEC 61850 object reference of a model node
*
* \param self the model node instance
* \param objectReference pointer to a buffer where to write the object reference string. If NULL
* is given the buffer is allocated by the function.
* \param withoutIedName create object reference without IED name part
*
* \return the object reference string
*/
LIB61850_API char*
ModelNode_getObjectReferenceEx(ModelNode* node, char* objectReference, bool withoutIedName);
/**
* \brief Get the type of the ModelNode
*

@ -513,12 +513,12 @@ LogicalDevice_getChildByMmsVariableName(LogicalDevice* logicalDevice, const char
}
static int
createObjectReference(ModelNode* node, char* objectReference)
createObjectReference(ModelNode* node, char* objectReference, bool withoutIedName)
{
int bufPos;
if (node->modelType != LogicalNodeModelType) {
bufPos = createObjectReference(node->parent, objectReference);
bufPos = createObjectReference(node->parent, objectReference, withoutIedName);
objectReference[bufPos++] = '.';
}
@ -531,10 +531,18 @@ createObjectReference(ModelNode* node, char* objectReference)
bufPos = 0;
int nameLength = strlen (iedModel->name) + strlen(lDevice->name);
int nameLength = 0;
strncpy(objectReference, iedModel->name, 64);
strncat(objectReference, lDevice->name, 64);
if (withoutIedName) {
nameLength = strlen(lDevice->name);
strncpy(objectReference, lDevice->name, 64);
}
else {
nameLength = strlen (iedModel->name) + strlen(lDevice->name);
strncpy(objectReference, iedModel->name, 64);
strncat(objectReference, lDevice->name, 64);
}
bufPos += nameLength;
@ -558,7 +566,20 @@ ModelNode_getObjectReference(ModelNode* node, char* objectReference)
if (objectReference == NULL)
objectReference = (char*) GLOBAL_MALLOC(130);
int bufPos = createObjectReference(node, objectReference);
int bufPos = createObjectReference(node, objectReference, false);
objectReference[bufPos] = 0;
return objectReference;
}
char*
ModelNode_getObjectReferenceEx(ModelNode* node, char* objectReference, bool withoutIedName)
{
if (objectReference == NULL)
objectReference = (char*) GLOBAL_MALLOC(130);
int bufPos = createObjectReference(node, objectReference, withoutIedName);
objectReference[bufPos] = 0;

Loading…
Cancel
Save