Skip to content

Commit

Permalink
- Add function to set MMSValue before startinf the server for dynamic…
Browse files Browse the repository at this point in the history
… model.

- gige feedback for set control handler
  • Loading branch information
Olivier BLANC committed Jul 16, 2018
1 parent 05efad2 commit 0919686
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 62 deletions.
2 changes: 1 addition & 1 deletion dotnet/IEC61850forCSharp/IEC61850.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down
107 changes: 63 additions & 44 deletions dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ public class DataAttribute : ModelNode
static extern IntPtr DataAttribute_create(string name, IntPtr parent, int type, int fc,
byte triggerOptions, int arrayElements, UInt32 sAddr);

internal DataAttribute(IntPtr self) : base(self)
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern bool DataAttribute_setValue(IntPtr self, IntPtr MmsValue);

internal DataAttribute(IntPtr self) : base(self)
{
}

Expand All @@ -387,54 +390,70 @@ public DataAttribute (string name, ModelNode parent, DataAttributeType type, Fun
self = DataAttribute_create (name, parent.self, (int)type, (int)fc, (byte)trgOps, arrayElements, sAddr);
}

}
public bool SetValue(MmsValue value)
{
return DataAttribute_setValue(self, value.valueReference);
}
}

public class ModelNode
{
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModelNode_getChild(IntPtr self, string name);
public class ModelNode
{
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModelNode_getChild(IntPtr self, string name);

[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern int ModelNode_getType(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern int ModelNode_getType(IntPtr self);

public IntPtr self;
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ModelNode_getObjectReference(IntPtr self, IntPtr objectReference);

internal ModelNode()
{
}
public IntPtr self;

public ModelNode(IntPtr self)
{
this.self = self;
}
internal ModelNode()
{
}

public ModelNode GetChild(string name)
{
IntPtr childPtr = ModelNode_getChild(self, name);
public ModelNode(IntPtr self)
{
this.self = self;
}

if (childPtr == IntPtr.Zero)
return null;
public ModelNode GetChild(string name)
{
IntPtr childPtr = ModelNode_getChild(self, name);

int nodeType = ModelNode_getType (childPtr);
if (childPtr == IntPtr.Zero)
return null;

switch (nodeType) {
case 0:
return new LogicalDevice (childPtr);
int nodeType = ModelNode_getType(childPtr);

case 1:
return new LogicalNode (childPtr);
switch (nodeType) {
case 0:
return new LogicalDevice(childPtr);

case 2:
return new DataObject (childPtr);
case 1:
return new LogicalNode(childPtr);

case 3:
return new DataAttribute (childPtr);
case 2:
return new DataObject(childPtr);

default:
return new ModelNode (childPtr);
}
case 3:
return new DataAttribute(childPtr);

}
default:
return new ModelNode(childPtr);
}

}

public string GetObjectReference()
{
IntPtr ptr = ModelNode_getObjectReference(self, IntPtr.Zero);

string returnString = Marshal.PtrToStringAnsi(ptr);

return returnString;
}
}


Expand Down Expand Up @@ -622,13 +641,13 @@ public class IedServer
private delegate int InternalControlHandler (IntPtr parameter, IntPtr ctlVal, bool test);

[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedServer_setWaitForExecutionHandler(IntPtr self, IntPtr node, InternalControlWaitForExecutionHandler handler, IntPtr parameter);
static extern bool IedServer_setWaitForExecutionHandler(IntPtr self, IntPtr node, InternalControlWaitForExecutionHandler handler, IntPtr parameter);

[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedServer_setPerformCheckHandler(IntPtr self, IntPtr node, InternalControlPerformCheckHandler handler, IntPtr parameter);
static extern bool IedServer_setPerformCheckHandler(IntPtr self, IntPtr node, InternalControlPerformCheckHandler handler, IntPtr parameter);

[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedServer_setControlHandler (IntPtr self, IntPtr node, InternalControlHandler handler, IntPtr parameter);
static extern bool IedServer_setControlHandler (IntPtr self, IntPtr node, InternalControlHandler handler, IntPtr parameter);

[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void IedServer_setWriteAccessPolicy(IntPtr self, FunctionalConstraint fc, AccessPolicy policy);
Expand Down Expand Up @@ -879,7 +898,7 @@ private ControlHandlerInfo GetControlHandlerInfo(DataObject controlObject)
return info;
}

public void SetControlHandler (DataObject controlObject, ControlHandler handler, object parameter)
public bool SetControlHandler (DataObject controlObject, ControlHandler handler, object parameter)
{
ControlHandlerInfo info = GetControlHandlerInfo (controlObject);

Expand All @@ -889,10 +908,10 @@ public void SetControlHandler (DataObject controlObject, ControlHandler handler,
if (internalControlHandlerRef == null)
internalControlHandlerRef = new InternalControlHandler (internalControlHandler);

IedServer_setControlHandler(self, controlObject.self, internalControlHandlerRef, GCHandle.ToIntPtr(info.handle));
return IedServer_setControlHandler(self, controlObject.self, internalControlHandlerRef, GCHandle.ToIntPtr(info.handle));
}

public void SetCheckHandler (DataObject controlObject, CheckHandler handler, object parameter)
public bool SetCheckHandler (DataObject controlObject, CheckHandler handler, object parameter)
{
ControlHandlerInfo info = GetControlHandlerInfo (controlObject);

Expand All @@ -902,10 +921,10 @@ public void SetCheckHandler (DataObject controlObject, CheckHandler handler, obj
if (internalControlPerformCheckHandlerRef == null)
internalControlPerformCheckHandlerRef = new InternalControlPerformCheckHandler (internalCheckHandler);

IedServer_setPerformCheckHandler(self, controlObject.self, internalControlPerformCheckHandlerRef, GCHandle.ToIntPtr(info.handle));
return IedServer_setPerformCheckHandler(self, controlObject.self, internalControlPerformCheckHandlerRef, GCHandle.ToIntPtr(info.handle));
}

public void SetWaitForExecutionHandler (DataObject controlObject, ControlWaitForExecutionHandler handler, object parameter)
public bool SetWaitForExecutionHandler (DataObject controlObject, ControlWaitForExecutionHandler handler, object parameter)
{
ControlHandlerInfo info = GetControlHandlerInfo (controlObject);

Expand All @@ -915,7 +934,7 @@ public void SetWaitForExecutionHandler (DataObject controlObject, ControlWaitFor
if (internalControlWaitForExecutionHandlerRef == null)
internalControlWaitForExecutionHandlerRef = new InternalControlWaitForExecutionHandler (internalControlWaitForExecutionHandler);

IedServer_setWaitForExecutionHandler(self, controlObject.self, internalControlWaitForExecutionHandlerRef, GCHandle.ToIntPtr(info.handle));
return IedServer_setWaitForExecutionHandler(self, controlObject.self, internalControlWaitForExecutionHandlerRef, GCHandle.ToIntPtr(info.handle));
}

public void HandleWriteAccess (DataAttribute dataAttr, WriteAccessHandler handler, object parameter)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/server1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void Main (string[] args)
running = false;
};

IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile ("../../model.cfg");
IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile ("./model.cfg");

if (iedModel == null) {
Console.WriteLine ("No valid data model found!");
Expand Down
11 changes: 11 additions & 0 deletions src/iec61850/inc/iec61850_dynamic_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ DataAttribute*
DataAttribute_create(const char* name, ModelNode* parent, DataAttributeType type, FunctionalConstraint fc,
uint8_t triggerOptions, int arrayElements, uint32_t sAddr);

/**
* \brief Set the MMS Value
*
* The parent model node has to be of type LogicalNode or DataObject
*
*
* \return true if the assignement is ok
*/
bool
DataAttribute_setValue(DataAttribute* self, MmsValue* value);

/**
* \brief create a new report control block (RCB)
*
Expand Down
10 changes: 7 additions & 3 deletions src/iec61850/inc/iec61850_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,10 @@ typedef ControlHandlerResult (*ControlHandler) (void* parameter, MmsValue* ctlVa
* \param node the controllable data object handle
* \param handler a callback function of type ControlHandler
* \param parameter a user provided parameter that is passed to the control handler.
*
* \return true if installation is ok
*/
void
bool
IedServer_setControlHandler(IedServer self, DataObject* node, ControlHandler handler, void* parameter);

/**
Expand All @@ -937,8 +939,9 @@ IedServer_setControlHandler(IedServer self, DataObject* node, ControlHandler han
* \param handler a callback function of type ControlHandler
* \param parameter a user provided parameter that is passed to the control handler.
*
* \return true if installation is ok
*/
void
bool
IedServer_setPerformCheckHandler(IedServer self, DataObject* node, ControlPerformCheckHandler handler, void* parameter);

/**
Expand All @@ -955,8 +958,9 @@ IedServer_setPerformCheckHandler(IedServer self, DataObject* node, ControlPerfor
* \param handler a callback function of type ControlHandler
* \param parameter a user provided parameter that is passed to the control handler.
*
* \return true if installation is ok
*/
void
bool
IedServer_setWaitForExecutionHandler(IedServer self, DataObject* node, ControlWaitForExecutionHandler handler, void* parameter);

/**@}*/
Expand Down
32 changes: 21 additions & 11 deletions src/iec61850/server/impl/ied_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ lookupControlObject(IedServer self, DataObject* node)
return controlObject;
}

void
bool
IedServer_setControlHandler(
IedServer self,
DataObject* node,
Expand All @@ -709,29 +709,39 @@ IedServer_setControlHandler(
ControlObject_installListener(controlObject, listener, parameter);
if (DEBUG_IED_SERVER)
printf("IED_SERVER: Installed control handler for %s!\n", node->name);
return true;
}
else
if (DEBUG_IED_SERVER)
printf("IED_SERVER: Failed to install control handler!\n");
else {
if (DEBUG_IED_SERVER)
printf("IED_SERVER: Failed to install control handler!\n");
return false;
}
}

void
bool
IedServer_setPerformCheckHandler(IedServer self, DataObject* node, ControlPerformCheckHandler handler, void* parameter)
{
ControlObject* controlObject = lookupControlObject(self, node);

if (controlObject != NULL)
ControlObject_installCheckHandler(controlObject, handler, parameter);
if (controlObject != NULL) {
ControlObject_installCheckHandler(controlObject, handler, parameter);
return true;
}
else
return false;
}

void
bool
IedServer_setWaitForExecutionHandler(IedServer self, DataObject* node, ControlWaitForExecutionHandler handler,
void* parameter)
{
ControlObject* controlObject = lookupControlObject(self, node);

if (controlObject != NULL)
ControlObject_installWaitForExecutionHandler(controlObject, handler, parameter);
if (controlObject != NULL) {
ControlObject_installWaitForExecutionHandler(controlObject, handler, parameter);
return true;
}
else
return false;
}
#endif /* (CONFIG_IEC61850_CONTROL_SERVICE == 1) */

Expand Down
9 changes: 9 additions & 0 deletions src/iec61850/server/model/dynamic_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ DataAttribute_create(const char* name, ModelNode* parent, DataAttributeType type
return self;
}

bool
DataAttribute_setValue(DataAttribute* self, MmsValue* value) {
if (self->mmsValue != NULL )
return false;

self->mmsValue = value;
return true;
}

DataSet*
DataSet_create(const char* name, LogicalNode* parent)
{
Expand Down
3 changes: 2 additions & 1 deletion src/vs/libiec61850-wo-goose.def
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,5 @@ EXPORTS
ClientGooseControlBlock_getDstAddress_vid
ClientGooseControlBlock_setDstAddress_vid
ClientGooseControlBlock_getDstAddress_appid
ClientGooseControlBlock_setDstAddress_appid
ClientGooseControlBlock_setDstAddress_appid
DataAttribute_setValue
3 changes: 2 additions & 1 deletion src/vs/libiec61850.def
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,5 @@ EXPORTS
ClientGooseControlBlock_getDstAddress_vid
ClientGooseControlBlock_setDstAddress_vid
ClientGooseControlBlock_getDstAddress_appid
ClientGooseControlBlock_setDstAddress_appid
ClientGooseControlBlock_setDstAddress_appid
DataAttribute_setValue

0 comments on commit 0919686

Please sign in to comment.