diff --git a/dotnet/IEC61850forCSharp/IEC61850.NET.csproj b/dotnet/IEC61850forCSharp/IEC61850.NET.csproj index e1de37377..ca47a26a0 100644 --- a/dotnet/IEC61850forCSharp/IEC61850.NET.csproj +++ b/dotnet/IEC61850forCSharp/IEC61850.NET.csproj @@ -17,7 +17,7 @@ prompt 4 false - x86 + AnyCPU none diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index fc08dd8f0..832bc40aa 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -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) { } @@ -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; + } } @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) diff --git a/dotnet/server1/Program.cs b/dotnet/server1/Program.cs index 197787906..036a4a8b6 100644 --- a/dotnet/server1/Program.cs +++ b/dotnet/server1/Program.cs @@ -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!"); diff --git a/src/iec61850/inc/iec61850_dynamic_model.h b/src/iec61850/inc/iec61850_dynamic_model.h index ee011dbee..7ade4d7df 100644 --- a/src/iec61850/inc/iec61850_dynamic_model.h +++ b/src/iec61850/inc/iec61850_dynamic_model.h @@ -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) * diff --git a/src/iec61850/inc/iec61850_server.h b/src/iec61850/inc/iec61850_server.h index 5a5c66d19..c6ae28f6e 100644 --- a/src/iec61850/inc/iec61850_server.h +++ b/src/iec61850/inc/iec61850_server.h @@ -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); /** @@ -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); /** @@ -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); /**@}*/ diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index 72f07d45a..f56bfcc08 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -696,7 +696,7 @@ lookupControlObject(IedServer self, DataObject* node) return controlObject; } -void +bool IedServer_setControlHandler( IedServer self, DataObject* node, @@ -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) */ diff --git a/src/iec61850/server/model/dynamic_model.c b/src/iec61850/server/model/dynamic_model.c index 13185edf6..cb749930b 100644 --- a/src/iec61850/server/model/dynamic_model.c +++ b/src/iec61850/server/model/dynamic_model.c @@ -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) { diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index 24517252f..dc903363b 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -597,4 +597,5 @@ EXPORTS ClientGooseControlBlock_getDstAddress_vid ClientGooseControlBlock_setDstAddress_vid ClientGooseControlBlock_getDstAddress_appid - ClientGooseControlBlock_setDstAddress_appid \ No newline at end of file + ClientGooseControlBlock_setDstAddress_appid + DataAttribute_setValue \ No newline at end of file diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index 8a911c6ae..4ff9d9120 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -684,4 +684,5 @@ EXPORTS ClientGooseControlBlock_getDstAddress_vid ClientGooseControlBlock_setDstAddress_vid ClientGooseControlBlock_getDstAddress_appid - ClientGooseControlBlock_setDstAddress_appid \ No newline at end of file + ClientGooseControlBlock_setDstAddress_appid + DataAttribute_setValue \ No newline at end of file