diff --git a/src/sampled_values/sv_publisher.c b/src/sampled_values/sv_publisher.c index 315417ca..6bac2cb6 100644 --- a/src/sampled_values/sv_publisher.c +++ b/src/sampled_values/sv_publisher.c @@ -627,6 +627,24 @@ SVPublisher_ASDU_setTimestamp(SVPublisher_ASDU self, int index, Timestamp value) } } +int +SVPublisher_ASDU_addQuality(SVPublisher_ASDU self) +{ + int index = self->dataSize; + self->dataSize += 4; + return index; +} + +void +SVPublisher_ASDU_setQuality(SVPublisher_ASDU self, int index, Quality value) +{ + uint8_t* buffer = self->_dataBuffer + index; + buffer[0] = 0; + buffer[1] = 0; + buffer[2] = value / 0x100; + buffer[3] = value % 0x100; +} + 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 d4acc399..d75f5f5e 100644 --- a/src/sampled_values/sv_publisher.h +++ b/src/sampled_values/sv_publisher.h @@ -244,6 +244,27 @@ SVPublisher_ASDU_addTimestamp(SVPublisher_ASDU self); void SVPublisher_ASDU_setTimestamp(SVPublisher_ASDU self, int index, Timestamp value); +/** + * \brief Reserve memory for a quality value in the ASDU + * + * NOTE: Quality is encoded as BITSTRING (4 byte) + * + * \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_addQuality(SVPublisher_ASDU self); + +/** + * \brief Set the value of a quality attribute 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_setQuality(SVPublisher_ASDU self, int index, Quality 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 251c0497..a895d410 100644 --- a/src/sampled_values/sv_subscriber.c +++ b/src/sampled_values/sv_subscriber.c @@ -842,6 +842,19 @@ SVSubscriber_ASDU_getTimestamp(SVSubscriber_ASDU self, int index) return retVal; } +Quality +SVSubscriber_ASDU_getQuality(SVSubscriber_ASDU self, int index) +{ + Quality retVal; + + uint8_t* buffer = self->dataBuffer + index; + + retVal = buffer[3]; + retVal += (buffer[2] * 0x100); + + 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 d6ad938d..e3760e99 100644 --- a/src/sampled_values/sv_subscriber.h +++ b/src/sampled_values/sv_subscriber.h @@ -74,6 +74,7 @@ typedef struct sEthernetSocket* EthernetSocket; * | TimeStamp | 8 byte | * | EntryTime | 6 byte | * | BITSTRING | 4 byte | + * | Quality | 4 byte | * * The SV subscriber API can be used independent of the IEC 61850 client API. In order to access the SVCB via MMS you * have to use the IEC 61850 client API. Please see \ref ClientSVControlBlock object in section \ref IEC61850_CLIENT_SV. @@ -493,6 +494,19 @@ SVSubscriber_ASDU_getFLOAT64(SVSubscriber_ASDU self, int index); Timestamp SVSubscriber_ASDU_getTimestamp(SVSubscriber_ASDU self, int index); +/** + * \brief Get a quality value in the data part of the ASDU + * + * NOTE: Quality is encoded as BITSTRING (4 byte) + * + * \param self ASDU object instance + * \param index the index (byte position of the start) of the data in the data part + * + * \return SV data + */ +Quality +SVSubscriber_ASDU_getQuality(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 6df41f0e..68309da5 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -701,4 +701,7 @@ EXPORTS SVReceiver_isRunning SVSubscriber_ASDU_getTimestamp SVPublisher_ASDU_addTimestamp - SVPublisher_ASDU_setTimestamp \ No newline at end of file + SVPublisher_ASDU_setTimestamp + SVSubscriber_ASDU_getQuality + SVPublisher_ASDU_addQuality + SVPublisher_ASDU_setQuality \ No newline at end of file