- .NET API: Added support for Timestamp and Quality to SV subscriber

pull/143/head
Michael Zillgith 8 years ago
parent e63abff71c
commit 33fb9206b3

@ -349,6 +349,9 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr Timestamp_create (); static extern IntPtr Timestamp_create ();
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr Timestamp_createFromByteArray(byte[] byteArry);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void Timestamp_destroy (IntPtr self); static extern void Timestamp_destroy (IntPtr self);
@ -399,12 +402,12 @@ namespace IEC61850
static extern void Timestamp_setByMmsUtcTime (IntPtr self, IntPtr mmsValue); static extern void Timestamp_setByMmsUtcTime (IntPtr self, IntPtr mmsValue);
internal IntPtr timestampRef = IntPtr.Zero; internal IntPtr timestampRef = IntPtr.Zero;
private bool responsableForDeletion; private bool responsibleForDeletion;
internal Timestamp(IntPtr timestampRef, bool selfAllocated) internal Timestamp(IntPtr timestampRef, bool selfAllocated)
{ {
this.timestampRef = timestampRef; this.timestampRef = timestampRef;
this.responsableForDeletion = selfAllocated; this.responsibleForDeletion = selfAllocated;
} }
public Timestamp (DateTime timestamp) : this () public Timestamp (DateTime timestamp) : this ()
@ -421,12 +424,18 @@ namespace IEC61850
{ {
timestampRef = Timestamp_create (); timestampRef = Timestamp_create ();
LeapSecondKnown = true; LeapSecondKnown = true;
responsableForDeletion = true; responsibleForDeletion = true;
}
public Timestamp(byte[] value)
{
timestampRef = Timestamp_createFromByteArray (value);
responsibleForDeletion = true;
} }
~Timestamp () ~Timestamp ()
{ {
if (responsableForDeletion) if (responsibleForDeletion)
Timestamp_destroy (timestampRef); Timestamp_destroy (timestampRef);
} }
@ -536,6 +545,15 @@ namespace IEC61850
Timestamp_setByMmsUtcTime (timestampRef, mmsValue.valueReference); Timestamp_setByMmsUtcTime (timestampRef, mmsValue.valueReference);
} }
public DateTime AsDateTime()
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime retVal = epoch.AddMilliseconds ((double) GetTimeInMilliseconds ());
return retVal;
}
} }
public enum ACSIClass public enum ACSIClass

@ -274,6 +274,9 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern double SVSubscriber_ASDU_getFLOAT64(IntPtr self, int index); private static extern double SVSubscriber_ASDU_getFLOAT64(IntPtr self, int index);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern UInt16 SVSubscriber_ASDU_getQuality(IntPtr self, int index);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern int SVSubscriber_ASDU_getDataSize(IntPtr self); private static extern int SVSubscriber_ASDU_getDataSize(IntPtr self);
@ -389,6 +392,29 @@ namespace IEC61850
return SVSubscriber_ASDU_getFLOAT64 (self, index); return SVSubscriber_ASDU_getFLOAT64 (self, index);
} }
private struct PTimestamp
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I1, SizeConst = 8)]
public byte[] val;
}
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern PTimestamp SVSubscriber_ASDU_getTimestamp(IntPtr self, int index);
public Timestamp GetTimestamp(int index)
{
PTimestamp retVal = SVSubscriber_ASDU_getTimestamp (self, index);
return new Timestamp (retVal.val);
}
public Quality GetQuality(int index)
{
UInt16 qValue = SVSubscriber_ASDU_getQuality (self, index);
return new Quality (qValue);
}
/// <summary> /// <summary>
/// Gets the size of the payload data in bytes. The payload comprises the data set data. /// Gets the size of the payload data in bytes. The payload comprises the data set data.
/// </summary> /// </summary>

@ -10,7 +10,7 @@ namespace sv_subscriber
{ {
private static void svUpdateListener(SVSubscriber subscriber, object parameter, SVSubscriberASDU asdu) private static void svUpdateListener(SVSubscriber subscriber, object parameter, SVSubscriberASDU asdu)
{ {
Console.WriteLine ("svUpdateListener called"); Console.WriteLine ("RECV ASDU:");
string svID = asdu.GetSvId (); string svID = asdu.GetSvId ();
@ -22,7 +22,11 @@ namespace sv_subscriber
if (asdu.GetDataSize () >= 8) { if (asdu.GetDataSize () >= 8) {
Console.WriteLine (" DATA[0]: " + asdu.GetFLOAT32(0)); Console.WriteLine (" DATA[0]: " + asdu.GetFLOAT32(0));
Console.WriteLine (" DATA[1]: " + asdu.GetFLOAT32(4)); Console.WriteLine (" DATA[1]: " + asdu.GetFLOAT32 (4));
}
if (asdu.GetDataSize () >= 16) {
Console.WriteLine (" DATA[2]: " + asdu.GetTimestamp (8).AsDateTime().ToString());
} }
} }

@ -232,6 +232,21 @@ Timestamp_create()
return self; return self;
} }
Timestamp*
Timestamp_createFromByteArray(uint8_t* byteArray)
{
Timestamp* self = Timestamp_create();
if (self) {
int i;
for (i = 0; i < 8; i++)
self->val[i] = byteArray[i];
}
return self;
}
void void
Timestamp_destroy(Timestamp* self) Timestamp_destroy(Timestamp* self)
{ {

@ -356,6 +356,9 @@ typedef union {
Timestamp* Timestamp*
Timestamp_create(void); Timestamp_create(void);
Timestamp*
Timestamp_createFromByteArray(uint8_t* byteArray);
void void
Timestamp_destroy(Timestamp* self); Timestamp_destroy(Timestamp* self);

@ -578,4 +578,5 @@ EXPORTS
ClientGooseControlBlock_getDstAddress ClientGooseControlBlock_getDstAddress
ClientGooseControlBlock_setDstAddress ClientGooseControlBlock_setDstAddress
CDC_VSS_create CDC_VSS_create
CDC_VSG_create CDC_VSG_create
Timestamp_createFromByteArray

@ -704,4 +704,5 @@ EXPORTS
SVPublisher_ASDU_setTimestamp SVPublisher_ASDU_setTimestamp
SVSubscriber_ASDU_getQuality SVSubscriber_ASDU_getQuality
SVPublisher_ASDU_addQuality SVPublisher_ASDU_addQuality
SVPublisher_ASDU_setQuality SVPublisher_ASDU_setQuality
Timestamp_createFromByteArray
Loading…
Cancel
Save