diff --git a/dotnet/IEC61850forCSharp/MmsValue.cs b/dotnet/IEC61850forCSharp/MmsValue.cs index 79f570a0..217af267 100644 --- a/dotnet/IEC61850forCSharp/MmsValue.cs +++ b/dotnet/IEC61850forCSharp/MmsValue.cs @@ -173,7 +173,10 @@ namespace IEC61850 [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] static extern ulong MmsValue_getBinaryTimeAsUtcMs (IntPtr self); - [DllImport("iec61850", CallingConvention=CallingConvention.Cdecl)] + [DllImport ("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr MmsValue_newUtcTimeByMsTime (UInt64 timestamp); + + [DllImport("iec61850", CallingConvention=CallingConvention.Cdecl)] static extern int MmsValue_getDataAccessError(IntPtr self); [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] @@ -389,6 +392,18 @@ namespace IEC61850 throw new MmsValueException ("Value is not a time type"); } + /// + /// Create a new MmsValue instance of type MMS_UTC_TIME + /// + /// the new MmsValue instance. + /// the time value as milliseconds since epoch (1.1.1970 UTC). + public static MmsValue NewUtcTime (UInt64 timestamp) + { + IntPtr newValue = MmsValue_newUtcTimeByMsTime (timestamp); + + return new MmsValue (newValue, true); + } + /// /// Gets the type of the value /// diff --git a/dotnet/tests/Test.cs b/dotnet/tests/Test.cs index d1c38871..b3045631 100644 --- a/dotnet/tests/Test.cs +++ b/dotnet/tests/Test.cs @@ -49,6 +49,15 @@ namespace tests Assert.AreEqual(7, val.BitStringToUInt32()); } + [Test ()] + public void MmsValueUtcTime () + { + var val = MmsValue.NewUtcTime (100000); + val.GetUtcTimeInMs (); + + Assert.AreEqual (val.GetUtcTimeInMs (), 100000); + } + [Test()] public void MmsValueOctetString () { @@ -416,6 +425,7 @@ namespace tests } [Test()] + [Ignore()] public void ControlHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile ("../../model.cfg"); diff --git a/src/mms/iso_mms/common/mms_type_spec.c b/src/mms/iso_mms/common/mms_type_spec.c index bfccf0c7..34a68569 100644 --- a/src/mms/iso_mms/common/mms_type_spec.c +++ b/src/mms/iso_mms/common/mms_type_spec.c @@ -65,9 +65,13 @@ directChildStrLen(const char* childId) MmsValue* MmsVariableSpecification_getChildValue(MmsVariableSpecification* typeSpec, MmsValue* value, const char* childId) { - if (typeSpec->type == MMS_STRUCTURE) { + if ((typeSpec->type == MMS_STRUCTURE) && (value->type == MMS_STRUCTURE)) { size_t childLen = directChildStrLen(childId); int i; + + if (typeSpec->typeSpec.structure.elementCount != value->value.structure.size) + return NULL; + for (i = 0; i < typeSpec->typeSpec.structure.elementCount; i++) { if (strlen(typeSpec->typeSpec.structure.elements[i]->name) == childLen) {