From b374644d308416292127709784fac6002e2e9246 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Mon, 24 Jan 2022 07:13:37 -0500 Subject: [PATCH] - added functions Timestamp_fromMmsValue and Quality_toMmsValue --- src/iec61850/common/iec61850_common.c | 35 ++++++++++++++++++++++++++- src/iec61850/inc/iec61850_common.h | 14 +++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/iec61850/common/iec61850_common.c b/src/iec61850/common/iec61850_common.c index 20962e43..66530c96 100644 --- a/src/iec61850/common/iec61850_common.c +++ b/src/iec61850/common/iec61850_common.c @@ -1,7 +1,7 @@ /* * iec61850_common.c * - * Copyright 2013-2020 Michael Zillgith + * Copyright 2013-2022 Michael Zillgith * * This file is part of libIEC61850. * @@ -70,6 +70,20 @@ Quality_fromMmsValue(const MmsValue* mmsValue) return (Quality) MmsValue_getBitStringAsInteger(mmsValue); } +MmsValue* +Quality_toMmsValue(Quality* self, MmsValue* mmsValue) +{ + if (mmsValue == NULL) { + mmsValue = MmsValue_newBitString(13); + } + + if (mmsValue) { + MmsValue_setBitStringFromInteger(mmsValue, *self); + } + + return mmsValue; +} + Dbpos Dbpos_fromMmsValue(const MmsValue* mmsValue) { @@ -491,6 +505,25 @@ Timestamp_toMmsValue(Timestamp* self, MmsValue* mmsValue) return convertedValue; } +Timestamp* +Timestamp_fromMmsValue(Timestamp* self, MmsValue* mmsValue) +{ + if (mmsValue->type == MMS_UTC_TIME) { + + if (self == NULL) + self = Timestamp_create(); + + if (self) { + memcpy(self->val, mmsValue->value.utcTime, 8); + } + + return self; + } + else { + return NULL; + } +} + char* MmsMapping_getMmsDomainFromObjectReference(const char* objectReference, char* buffer) { diff --git a/src/iec61850/inc/iec61850_common.h b/src/iec61850/inc/iec61850_common.h index 335b6ea4..e8374072 100644 --- a/src/iec61850/inc/iec61850_common.h +++ b/src/iec61850/inc/iec61850_common.h @@ -370,6 +370,9 @@ Quality_isFlagSet(Quality* self, int flag); LIB61850_API Quality Quality_fromMmsValue(const MmsValue* mmsValue); +LIB61850_API MmsValue* +Quality_toMmsValue(Quality* self, MmsValue* mmsValue); + /** @} */ /** @@ -515,6 +518,17 @@ Timestamp_setByMmsUtcTime(Timestamp* self, const MmsValue* mmsValue); LIB61850_API MmsValue* Timestamp_toMmsValue(Timestamp* self, MmsValue* mmsValue); +/** + * \brief Get the Timestamp value from an MmsValue instance of type MMS_UTC_TIME + * + * \param self the Timestamp instance or NULL to create a new instance + * \param mmsValue the mmsValue instance of type MMS_UTC_TIME + * + * \return the updated Timestamp value or NULL in case of an error + */ +LIB61850_API Timestamp* +Timestamp_fromMmsValue(Timestamp* self, MmsValue* mmsValue); + /** * \brief Get the version of the library as string *