- SV: added Timestamp type support

pull/143/head
Michael Zillgith 8 years ago
parent 36b0c94eef
commit 70c311d433

@ -35,11 +35,13 @@ main(int argc, char** argv)
int float1 = SVPublisher_ASDU_addFLOAT(asdu1); int float1 = SVPublisher_ASDU_addFLOAT(asdu1);
int float2 = SVPublisher_ASDU_addFLOAT(asdu1); int float2 = SVPublisher_ASDU_addFLOAT(asdu1);
int ts1 = SVPublisher_ASDU_addTimestamp(asdu1);
SVPublisher_ASDU asdu2 = SVPublisher_addASDU(svPublisher, "svpub2", NULL, 1); SVPublisher_ASDU asdu2 = SVPublisher_addASDU(svPublisher, "svpub2", NULL, 1);
int float3 = SVPublisher_ASDU_addFLOAT(asdu2); int float3 = SVPublisher_ASDU_addFLOAT(asdu2);
int float4 = SVPublisher_ASDU_addFLOAT(asdu2); int float4 = SVPublisher_ASDU_addFLOAT(asdu2);
int ts2 = SVPublisher_ASDU_addTimestamp(asdu2);
SVPublisher_setupComplete(svPublisher); SVPublisher_setupComplete(svPublisher);
@ -47,11 +49,17 @@ main(int argc, char** argv)
float fVal2 = 0.12345f; float fVal2 = 0.12345f;
while (running) { while (running) {
Timestamp ts;
Timestamp_clearFlags(&ts);
Timestamp_setTimeInMilliseconds(&ts, Hal_getTimeInMs());
SVPublisher_ASDU_setFLOAT(asdu1, float1, fVal1); SVPublisher_ASDU_setFLOAT(asdu1, float1, fVal1);
SVPublisher_ASDU_setFLOAT(asdu1, float2, fVal2); SVPublisher_ASDU_setFLOAT(asdu1, float2, fVal2);
SVPublisher_ASDU_setTimestamp(asdu1, ts1, ts);
SVPublisher_ASDU_setFLOAT(asdu2, float3, fVal1 * 2); SVPublisher_ASDU_setFLOAT(asdu2, float3, fVal1 * 2);
SVPublisher_ASDU_setFLOAT(asdu2, float4, fVal2 * 2); SVPublisher_ASDU_setFLOAT(asdu2, float4, fVal2 * 2);
SVPublisher_ASDU_setTimestamp(asdu2, ts2, ts);
SVPublisher_ASDU_increaseSmpCnt(asdu1); SVPublisher_ASDU_increaseSmpCnt(asdu1);
SVPublisher_ASDU_increaseSmpCnt(asdu2); SVPublisher_ASDU_increaseSmpCnt(asdu2);

@ -607,6 +607,26 @@ SVPublisher_ASDU_setFLOAT64(SVPublisher_ASDU self, int index, double value)
} }
} }
int
SVPublisher_ASDU_addTimestamp(SVPublisher_ASDU self)
{
int index = self->dataSize;
self->dataSize += 8;
return index;
}
void
SVPublisher_ASDU_setTimestamp(SVPublisher_ASDU self, int index, Timestamp value)
{
int i;
uint8_t* buffer = self->_dataBuffer + index;
for (i = 0; i < 8; i++) {
buffer[i] = value.val[i];
}
}
uint16_t uint16_t
SVPublisher_ASDU_getSmpCnt(SVPublisher_ASDU self) SVPublisher_ASDU_getSmpCnt(SVPublisher_ASDU self)
{ {

@ -26,6 +26,7 @@
#define LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_ #define LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_
#include "libiec61850_platform_includes.h" #include "libiec61850_platform_includes.h"
#include "iec61850_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -187,7 +188,7 @@ void
SVPublisher_ASDU_setINT64(SVPublisher_ASDU self, int index, int64_t value); SVPublisher_ASDU_setINT64(SVPublisher_ASDU self, int index, int64_t value);
/** /**
* \brief Reserve memory for a single precission floating point number in the ASDU. * \brief Reserve memory for a single precision floating point number in the ASDU.
* *
* \param[in] self the Sampled Values ASDU instance. * \param[in] self the Sampled Values ASDU instance.
* \return the offset in bytes of the new element within the ASDU data block. * \return the offset in bytes of the new element within the ASDU data block.
@ -196,7 +197,7 @@ int
SVPublisher_ASDU_addFLOAT(SVPublisher_ASDU self); SVPublisher_ASDU_addFLOAT(SVPublisher_ASDU self);
/** /**
* \brief Set the value of a single precission floating point number in the ASDU. * \brief Set the value of a single precision floating point number in the ASDU.
* *
* \param[in] self the Sampled Values ASDU instance. * \param[in] self the Sampled Values ASDU instance.
* \param[in] index The offset within the data block of the ASDU in bytes. * \param[in] index The offset within the data block of the ASDU in bytes.
@ -206,7 +207,7 @@ void
SVPublisher_ASDU_setFLOAT(SVPublisher_ASDU self, int index, float value); SVPublisher_ASDU_setFLOAT(SVPublisher_ASDU self, int index, float value);
/** /**
* \brief Reserve memory for a double precission floating point number in the ASDU. * \brief Reserve memory for a double precision floating point number in the ASDU.
* *
* \param[in] self the Sampled Values ASDU instance. * \param[in] self the Sampled Values ASDU instance.
* \return the offset in bytes of the new element within the ASDU data block. * \return the offset in bytes of the new element within the ASDU data block.
@ -215,7 +216,7 @@ int
SVPublisher_ASDU_addFLOAT64(SVPublisher_ASDU self); SVPublisher_ASDU_addFLOAT64(SVPublisher_ASDU self);
/** /**
* \brief Set the value of a double precission floating pointer number in the ASDU. * \brief Set the value of a double precision floating pointer number in the ASDU.
* *
* \param[in] self the Sampled Values ASDU instance. * \param[in] self the Sampled Values ASDU instance.
* \param[in] index The offset within the data block of the ASDU in bytes. * \param[in] index The offset within the data block of the ASDU in bytes.
@ -224,6 +225,25 @@ SVPublisher_ASDU_addFLOAT64(SVPublisher_ASDU self);
void void
SVPublisher_ASDU_setFLOAT64(SVPublisher_ASDU self, int index, double value); SVPublisher_ASDU_setFLOAT64(SVPublisher_ASDU self, int index, double value);
/**
* \brief Reserve memory for a 64 bit time stamp in the ASDU
*
* \param[in] self the Sampled Values ASDU instance.
* \return the offset in bytes of the new element within the ASDU data block.
*/
int
SVPublisher_ASDU_addTimestamp(SVPublisher_ASDU self);
/**
* \brief Set the value of a 64 bit time stamp in the ASDU.
*
* \param[in] self the Sampled Values ASDU instance.
* \param[in] index The offset within the data block of the ASDU in bytes.
* \param[in] value The value which should be set.
*/
void
SVPublisher_ASDU_setTimestamp(SVPublisher_ASDU self, int index, Timestamp value);
/** /**
* \brief Set the sample count attribute of the ASDU. * \brief Set the sample count attribute of the ASDU.
* *

@ -832,6 +832,15 @@ SVSubscriber_ASDU_getFLOAT64(SVSubscriber_ASDU self, int index)
return retVal; return retVal;
} }
Timestamp
SVSubscriber_ASDU_getTimestamp(SVSubscriber_ASDU self, int index)
{
Timestamp retVal;
memcpy(retVal.val, self->dataBuffer + index, sizeof(retVal.val));
return retVal;
}
int int
SVSubscriber_ASDU_getDataSize(SVSubscriber_ASDU self) SVSubscriber_ASDU_getDataSize(SVSubscriber_ASDU self)

@ -25,6 +25,7 @@
#define SAMPLED_VALUES_SV_SUBSCRIBER_H_ #define SAMPLED_VALUES_SV_SUBSCRIBER_H_
#include "libiec61850_common_api.h" #include "libiec61850_common_api.h"
#include "iec61850_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -481,6 +482,17 @@ SVSubscriber_ASDU_getFLOAT32(SVSubscriber_ASDU self, int index);
double double
SVSubscriber_ASDU_getFLOAT64(SVSubscriber_ASDU self, int index); SVSubscriber_ASDU_getFLOAT64(SVSubscriber_ASDU self, int index);
/**
* \brief Get a timestamp data value in the data part of the ASDU
*
* \param self ASDU object instance
* \param index the index (byte position of the start) of the data in the data part
*
* \return SV data
*/
Timestamp
SVSubscriber_ASDU_getTimestamp(SVSubscriber_ASDU self, int index);
/** /**
* \brief Returns the size of the data part of the ASDU * \brief Returns the size of the data part of the ASDU
* *

@ -699,3 +699,6 @@ EXPORTS
CDC_VSS_create CDC_VSS_create
CDC_VSG_create CDC_VSG_create
SVReceiver_isRunning SVReceiver_isRunning
SVSubscriber_ASDU_getTimestamp
SVPublisher_ASDU_addTimestamp
SVPublisher_ASDU_setTimestamp
Loading…
Cancel
Save