diff --git a/examples/sv_publisher/sv_publisher_example.c b/examples/sv_publisher/sv_publisher_example.c index 1b589f40..311b6ff6 100644 --- a/examples/sv_publisher/sv_publisher_example.c +++ b/examples/sv_publisher/sv_publisher_example.c @@ -35,11 +35,13 @@ main(int argc, char** argv) int float1 = 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); int float3 = SVPublisher_ASDU_addFLOAT(asdu2); int float4 = SVPublisher_ASDU_addFLOAT(asdu2); + int ts2 = SVPublisher_ASDU_addTimestamp(asdu2); SVPublisher_setupComplete(svPublisher); @@ -47,11 +49,17 @@ main(int argc, char** argv) float fVal2 = 0.12345f; while (running) { + Timestamp ts; + Timestamp_clearFlags(&ts); + Timestamp_setTimeInMilliseconds(&ts, Hal_getTimeInMs()); + SVPublisher_ASDU_setFLOAT(asdu1, float1, fVal1); SVPublisher_ASDU_setFLOAT(asdu1, float2, fVal2); + SVPublisher_ASDU_setTimestamp(asdu1, ts1, ts); SVPublisher_ASDU_setFLOAT(asdu2, float3, fVal1 * 2); SVPublisher_ASDU_setFLOAT(asdu2, float4, fVal2 * 2); + SVPublisher_ASDU_setTimestamp(asdu2, ts2, ts); SVPublisher_ASDU_increaseSmpCnt(asdu1); SVPublisher_ASDU_increaseSmpCnt(asdu2); diff --git a/src/sampled_values/sv_publisher.c b/src/sampled_values/sv_publisher.c index 7c681899..315417ca 100644 --- a/src/sampled_values/sv_publisher.c +++ b/src/sampled_values/sv_publisher.c @@ -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 SVPublisher_ASDU_getSmpCnt(SVPublisher_ASDU self) { diff --git a/src/sampled_values/sv_publisher.h b/src/sampled_values/sv_publisher.h index 82c0cdfc..d4acc399 100644 --- a/src/sampled_values/sv_publisher.h +++ b/src/sampled_values/sv_publisher.h @@ -26,6 +26,7 @@ #define LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_ #include "libiec61850_platform_includes.h" +#include "iec61850_common.h" #ifdef __cplusplus extern "C" { @@ -187,7 +188,7 @@ void 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. * \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); /** - * \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] 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); /** - * \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. * \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); /** - * \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] index The offset within the data block of the ASDU in bytes. @@ -224,6 +225,25 @@ SVPublisher_ASDU_addFLOAT64(SVPublisher_ASDU self); void 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. * diff --git a/src/sampled_values/sv_subscriber.c b/src/sampled_values/sv_subscriber.c index 8cefa423..251c0497 100644 --- a/src/sampled_values/sv_subscriber.c +++ b/src/sampled_values/sv_subscriber.c @@ -832,6 +832,15 @@ SVSubscriber_ASDU_getFLOAT64(SVSubscriber_ASDU self, int index) 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 SVSubscriber_ASDU_getDataSize(SVSubscriber_ASDU self) diff --git a/src/sampled_values/sv_subscriber.h b/src/sampled_values/sv_subscriber.h index 04728cc1..d6ad938d 100644 --- a/src/sampled_values/sv_subscriber.h +++ b/src/sampled_values/sv_subscriber.h @@ -25,6 +25,7 @@ #define SAMPLED_VALUES_SV_SUBSCRIBER_H_ #include "libiec61850_common_api.h" +#include "iec61850_common.h" #ifdef __cplusplus extern "C" { @@ -481,6 +482,17 @@ SVSubscriber_ASDU_getFLOAT32(SVSubscriber_ASDU self, int index); double 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 * diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index 98fab54b..6df41f0e 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -698,4 +698,7 @@ EXPORTS SVSubscriber_ASDU_getDataSize CDC_VSS_create CDC_VSG_create - SVReceiver_isRunning \ No newline at end of file + SVReceiver_isRunning + SVSubscriber_ASDU_getTimestamp + SVPublisher_ASDU_addTimestamp + SVPublisher_ASDU_setTimestamp \ No newline at end of file