- Added functions to access fraction of second part of Timestamp (LIB61850-345)

v1.6_develop_rgoose_sntp
Michael Zillgith 3 years ago
parent aa91961b41
commit 75c1e89bba

@ -426,12 +426,21 @@ namespace IEC61850
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void Timestamp_setByMmsUtcTime (IntPtr self, IntPtr mmsValue); static extern void Timestamp_setByMmsUtcTime (IntPtr self, IntPtr mmsValue);
internal IntPtr timestampRef = IntPtr.Zero; [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern UInt32 Timestamp_getFractionOfSecondPart(IntPtr self);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern void Timestamp_setFractionOfSecondPart(IntPtr self, UInt32 fractionOfSecond);
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
static extern float Timestamp_getFractionOfSecond(IntPtr self);
internal IntPtr self = IntPtr.Zero;
private bool responsibleForDeletion; private bool responsibleForDeletion;
internal Timestamp(IntPtr timestampRef, bool selfAllocated) internal Timestamp(IntPtr timestampRef, bool selfAllocated)
{ {
this.timestampRef = timestampRef; this.self = timestampRef;
this.responsibleForDeletion = selfAllocated; this.responsibleForDeletion = selfAllocated;
} }
@ -447,26 +456,26 @@ namespace IEC61850
public Timestamp() public Timestamp()
{ {
timestampRef = Timestamp_create (); self = Timestamp_create ();
LeapSecondKnown = true; LeapSecondKnown = true;
responsibleForDeletion = true; responsibleForDeletion = true;
} }
public Timestamp(byte[] value) public Timestamp(byte[] value)
{ {
timestampRef = Timestamp_createFromByteArray (value); self = Timestamp_createFromByteArray (value);
responsibleForDeletion = true; responsibleForDeletion = true;
} }
~Timestamp () ~Timestamp ()
{ {
if (responsibleForDeletion) if (responsibleForDeletion)
Timestamp_destroy (timestampRef); Timestamp_destroy (self);
} }
public void ClearFlags() public void ClearFlags()
{ {
Timestamp_clearFlags (timestampRef); Timestamp_clearFlags (self);
} }
public void SetDateTime(DateTime timestamp) public void SetDateTime(DateTime timestamp)
@ -487,12 +496,12 @@ namespace IEC61850
public bool IsLeapSecondKnown() public bool IsLeapSecondKnown()
{ {
return Timestamp_isLeapSecondKnown (timestampRef); return Timestamp_isLeapSecondKnown (self);
} }
public void SetLeapSecondKnow(bool value) public void SetLeapSecondKnow(bool value)
{ {
Timestamp_setLeapSecondKnown (timestampRef, value); Timestamp_setLeapSecondKnown (self, value);
} }
public bool ClockFailure { public bool ClockFailure {
@ -502,12 +511,12 @@ namespace IEC61850
public bool HasClockFailure() public bool HasClockFailure()
{ {
return Timestamp_hasClockFailure (timestampRef); return Timestamp_hasClockFailure (self);
} }
public void SetClockFailure(bool value) public void SetClockFailure(bool value)
{ {
Timestamp_setClockFailure (timestampRef, value); Timestamp_setClockFailure (self, value);
} }
public bool ClockNotSynchronized { public bool ClockNotSynchronized {
@ -516,11 +525,11 @@ namespace IEC61850
} }
public bool IsClockNotSynchronized() { public bool IsClockNotSynchronized() {
return Timestamp_isClockNotSynchronized(timestampRef); return Timestamp_isClockNotSynchronized(self);
} }
public void SetClockNotSynchronized(bool value) { public void SetClockNotSynchronized(bool value) {
Timestamp_setClockNotSynchronized (timestampRef, value); Timestamp_setClockNotSynchronized (self, value);
} }
public int SubsecondPrecision { public int SubsecondPrecision {
@ -529,11 +538,11 @@ namespace IEC61850
} }
public int GetSubsecondPrecision() { public int GetSubsecondPrecision() {
return Timestamp_getSubsecondPrecision (timestampRef); return Timestamp_getSubsecondPrecision (self);
} }
public void SetSubsecondPrecision(int subsecondPrecision) { public void SetSubsecondPrecision(int subsecondPrecision) {
Timestamp_setSubsecondPrecision (timestampRef, subsecondPrecision); Timestamp_setSubsecondPrecision (self, subsecondPrecision);
} }
public UInt32 TimeInSeconds { public UInt32 TimeInSeconds {
@ -543,12 +552,12 @@ namespace IEC61850
public UInt32 GetTimeInSeconds() public UInt32 GetTimeInSeconds()
{ {
return Timestamp_getTimeInSeconds (timestampRef); return Timestamp_getTimeInSeconds (self);
} }
public void SetTimeInSeconds(UInt32 secondsSinceEpoch) public void SetTimeInSeconds(UInt32 secondsSinceEpoch)
{ {
Timestamp_setTimeInSeconds (timestampRef, secondsSinceEpoch); Timestamp_setTimeInSeconds (self, secondsSinceEpoch);
} }
public UInt64 TimeInMilliseconds { public UInt64 TimeInMilliseconds {
@ -558,16 +567,16 @@ namespace IEC61850
public UInt64 GetTimeInMilliseconds() public UInt64 GetTimeInMilliseconds()
{ {
return Timestamp_getTimeInMs (timestampRef); return Timestamp_getTimeInMs (self);
} }
public void SetTimeInMilliseconds(UInt64 millisSinceEpoch) { public void SetTimeInMilliseconds(UInt64 millisSinceEpoch) {
Timestamp_setTimeInMilliseconds (timestampRef, millisSinceEpoch); Timestamp_setTimeInMilliseconds (self, millisSinceEpoch);
} }
public void SetByMmsUtcTime(MmsValue mmsValue) public void SetByMmsUtcTime(MmsValue mmsValue)
{ {
Timestamp_setByMmsUtcTime (timestampRef, mmsValue.valueReference); Timestamp_setByMmsUtcTime (self, mmsValue.valueReference);
} }
public DateTime AsDateTime() public DateTime AsDateTime()
@ -579,9 +588,24 @@ namespace IEC61850
return retVal; return retVal;
} }
public UInt32 GetFractionOfSecondPart()
{
return Timestamp_getFractionOfSecondPart(self);
}
public void SetFractionOfSecondPart(UInt32 fractionOfSecond)
{
Timestamp_setFractionOfSecondPart(self, fractionOfSecond);
}
public float GetFractionOfSecond()
{
return Timestamp_getFractionOfSecond(self);
}
} }
public enum ACSIClass public enum ACSIClass
{ {
/** data objects */ /** data objects */
ACSI_CLASS_DATA_OBJECT, ACSI_CLASS_DATA_OBJECT,

@ -2794,7 +2794,7 @@ namespace IEC61850
public void UpdateTimestampAttributeValue(DataAttribute dataAttr, Timestamp timestamp) public void UpdateTimestampAttributeValue(DataAttribute dataAttr, Timestamp timestamp)
{ {
IedServer_updateTimestampAttributeValue (self, dataAttr.self, timestamp.timestampRef); IedServer_updateTimestampAttributeValue (self, dataAttr.self, timestamp.self);
} }
public void UpdateQuality(DataAttribute dataAttr, ushort value) public void UpdateQuality(DataAttribute dataAttr, ushort value)

@ -419,6 +419,35 @@ Timestamp_setTimeInNanoseconds(Timestamp* self, nsSinceEpoch nsTime)
/* don't touch time quality */ /* don't touch time quality */
} }
void
Timestamp_setFractionOfSecondPart(Timestamp* self, uint32_t fractionOfSecond)
{
uint8_t* valueArray = self->val;
valueArray[4] = ((fractionOfSecond >> 16) & 0xff);
valueArray[5] = ((fractionOfSecond >> 8) & 0xff);
valueArray[6] = (fractionOfSecond & 0xff);
}
uint32_t
Timestamp_getFractionOfSecondPart(Timestamp* self)
{
uint32_t fractionOfSecond = 0;
uint8_t* valueArray = self->val;
fractionOfSecond = (valueArray[4] << 16);
fractionOfSecond += (valueArray[5] << 8);
fractionOfSecond += (valueArray[6]);
return fractionOfSecond;
}
float
Timestamp_getFractionOfSecond(Timestamp* self)
{
return (float)((float)Timestamp_getFractionOfSecondPart(self) / (float)(1 << 24));
}
uint32_t uint32_t
Timestamp_getTimeInSeconds(Timestamp* self) Timestamp_getTimeInSeconds(Timestamp* self)
{ {

@ -464,6 +464,15 @@ Timestamp_setClockNotSynchronized(Timestamp* self, bool value);
LIB61850_API int LIB61850_API int
Timestamp_getSubsecondPrecision(Timestamp* self); Timestamp_getSubsecondPrecision(Timestamp* self);
LIB61850_API void
Timestamp_setFractionOfSecondPart(Timestamp* self, uint32_t fractionOfSecond);
LIB61850_API uint32_t
Timestamp_getFractionOfSecondPart(Timestamp* self);
LIB61850_API float
Timestamp_getFractionOfSecond(Timestamp* self);
/** /**
* \brief Set the subsecond precision value of the time stamp * \brief Set the subsecond precision value of the time stamp
* *

Loading…
Cancel
Save