libiec61850  1.2.0
mms_value.h
Go to the documentation of this file.
1 /*
2  * mms_value.h
3  *
4  * Copyright 2013 Michael Zillgith
5  *
6  * This file is part of libIEC61850.
7  *
8  * libIEC61850 is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * libIEC61850 is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * See COPYING file for the complete license text.
22  */
23 
24 #ifndef MMS_VALUE_H_
25 #define MMS_VALUE_H_
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include "libiec61850_common_api.h"
32 #include "mms_common.h"
33 #include "mms_types.h"
34 #include "ber_integer.h"
35 
47 typedef enum {
48  DATA_ACCESS_ERROR_NO_RESPONSE = -2, /* for server internal purposes only! */
64 
68 typedef struct sMmsValue MmsValue;
69 
70 /*************************************************************************************
71  * Array functions
72  *************************************************************************************/
73 
82 MmsValue*
83 MmsValue_createArray(MmsVariableSpecification* elementType, int size);
84 
92 uint32_t
93 MmsValue_getArraySize(const MmsValue* self);
94 
103 MmsValue*
104 MmsValue_getElement(const MmsValue* array, int index);
105 
113 MmsValue*
114 MmsValue_createEmptyArray(int size);
115 
126 void
127 MmsValue_setElement(MmsValue* complexValue, int index, MmsValue* elementValue);
128 
129 
130 /*************************************************************************************
131  * Basic type functions
132  *************************************************************************************/
133 
136 
144 int64_t
145 MmsValue_toInt64(const MmsValue* self);
146 
154 int32_t
155 MmsValue_toInt32(const MmsValue* value);
156 
164 uint32_t
165 MmsValue_toUint32(const MmsValue* value);
166 
174 double
175 MmsValue_toDouble(const MmsValue* self);
176 
184 float
185 MmsValue_toFloat(const MmsValue* self);
186 
194 uint32_t
196 
202 void
203 MmsValue_setFloat(MmsValue* self, float newFloatValue);
204 
210 void
211 MmsValue_setDouble(MmsValue* self, double newFloatValue);
212 
219 void
220 MmsValue_setInt8(MmsValue* value, int8_t integer);
221 
228 void
229 MmsValue_setInt16(MmsValue* value, int16_t integer);
230 
237 void
238 MmsValue_setInt32(MmsValue* self, int32_t integer);
239 
246 void
247 MmsValue_setInt64(MmsValue* value, int64_t integer);
248 
255 void
256 MmsValue_setUint8(MmsValue* value, uint8_t integer);
257 
264 void
265 MmsValue_setUint16(MmsValue* value, uint16_t integer);
266 
273 void
274 MmsValue_setUint32(MmsValue* value, uint32_t integer);
275 
276 
283 void
284 MmsValue_setBoolean(MmsValue* value, bool boolValue);
285 
292 bool
293 MmsValue_getBoolean(const MmsValue* value);
294 
302 const char*
304 
312 int
314 
315 void
316 MmsValue_setVisibleString(MmsValue* self, const char* string);
317 
318 
327 void
328 MmsValue_setBitStringBit(MmsValue* self, int bitPos, bool value);
329 
338 bool
339 MmsValue_getBitStringBit(const MmsValue* self, int bitPos);
340 
346 void
348 
349 
355 int
357 
363 int
365 
371 int
373 
379 void
381 
390 uint32_t
392 
402 void
403 MmsValue_setBitStringFromInteger(MmsValue* self, uint32_t intValue);
404 
413 uint32_t
415 
425 void
426 MmsValue_setBitStringFromIntegerBigEndian(MmsValue* self, uint32_t intValue);
427 
434 MmsValue*
435 MmsValue_setUtcTime(MmsValue* self, uint32_t timeval);
436 
443 MmsValue*
444 MmsValue_setUtcTimeMs(MmsValue* self, uint64_t timeval);
445 
454 void
455 MmsValue_setUtcTimeByBuffer(MmsValue* self, const uint8_t* buffer);
456 
466 uint8_t*
468 
476 uint64_t
477 MmsValue_getUtcTimeInMs(const MmsValue* value);
478 
487 uint64_t
488 MmsValue_getUtcTimeInMsWithUs(const MmsValue* self, uint32_t* usec);
489 
504 void
505 MmsValue_setUtcTimeQuality(MmsValue* self, uint8_t timeQuality);
506 
521 uint8_t
523 
530 void
531 MmsValue_setBinaryTime(MmsValue* self, uint64_t timestamp);
532 
540 uint64_t
542 
554 void
555 MmsValue_setOctetString(MmsValue* self, uint8_t* buf, int size);
556 
564 uint16_t
566 
577 uint16_t
579 
587 uint8_t*
589 
601 bool
602 MmsValue_update(MmsValue* self, const MmsValue* source);
603 
615 bool
616 MmsValue_equals(const MmsValue* self, const MmsValue* otherValue);
617 
630 bool
631 MmsValue_equalTypes(const MmsValue* self, const MmsValue* otherValue);
632 
633 /*************************************************************************************
634  * Constructors and destructors
635  *************************************************************************************/
636 
637 
638 MmsValue*
640 
641 MmsValue*
642 MmsValue_newIntegerFromBerInteger(Asn1PrimitiveValue* berInteger);
643 
644 MmsValue*
645 MmsValue_newUnsignedFromBerInteger(Asn1PrimitiveValue* berInteger);
646 
647 MmsValue*
648 MmsValue_newInteger(int size);
649 
650 MmsValue*
651 MmsValue_newUnsigned(int size);
652 
653 MmsValue*
654 MmsValue_newBoolean(bool boolean);
655 
663 MmsValue*
664 MmsValue_newBitString(int bitSize);
665 
666 MmsValue*
667 MmsValue_newOctetString(int size, int maxSize);
668 
669 MmsValue*
670 MmsValue_newStructure(const MmsVariableSpecification* typeSpec);
671 
672 MmsValue*
674 
675 MmsValue*
676 MmsValue_newDefaultValue(const MmsVariableSpecification* typeSpec);
677 
678 MmsValue*
679 MmsValue_newIntegerFromInt8(int8_t integer);
680 
681 MmsValue*
682 MmsValue_newIntegerFromInt16(int16_t integer);
683 
684 MmsValue*
685 MmsValue_newIntegerFromInt32(int32_t integer);
686 
687 MmsValue*
688 MmsValue_newIntegerFromInt64(int64_t integer);
689 
690 MmsValue*
691 MmsValue_newUnsignedFromUint32(uint32_t integer);
692 
693 MmsValue*
694 MmsValue_newFloat(float variable);
695 
696 MmsValue*
697 MmsValue_newDouble(double variable);
698 
709 MmsValue*
710 MmsValue_clone(const MmsValue* self);
711 
722 uint8_t*
723 MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress);
724 
735 int
737 
747 void
749 
762 void
764 
774 void
776 
787 MmsValue*
788 MmsValue_newVisibleString(const char* string);
789 
801 MmsValue*
803 
815 MmsValue*
817 
829 MmsValue*
830 MmsValue_newBinaryTime(bool timeOfDay);
831 
840 MmsValue*
841 MmsValue_newVisibleStringFromByteArray(uint8_t* byteArray, int size);
842 
851 MmsValue*
852 MmsValue_newMmsStringFromByteArray(uint8_t* byteArray, int size);
853 
861 MmsValue*
862 MmsValue_newMmsString(char* string);
863 
864 void
865 MmsValue_setMmsString(MmsValue* value, const char* string);
866 
874 MmsValue*
875 MmsValue_newUtcTime(uint32_t timeval);
876 
884 MmsValue*
885 MmsValue_newUtcTimeByMsTime(uint64_t timeval);
886 
887 
888 void
890 
891 void
893 
905 int
907 
913 MmsType
914 MmsValue_getType(const MmsValue* self);
915 
925 MmsValue*
926 MmsValue_getSubElement(MmsValue* self, MmsVariableSpecification* varSpec, char* mmsPath);
927 
935 char*
937 
950 const char*
951 MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize);
952 
965 MmsValue*
966 MmsValue_decodeMmsData(uint8_t* buffer, int bufPos, int bufferLength, int* endBufPos);
967 
979 int
980 MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode);
981 
986 #ifdef __cplusplus
987 }
988 #endif
989 
990 #endif /* MMS_VALUE_H_ */
double MmsValue_toDouble(const MmsValue *self)
Get the double value of a MmsValue object.
uint64_t MmsValue_getUtcTimeInMs(const MmsValue *value)
Get a millisecond time value from an MmsValue object of MMS_UTCTIME type.
MmsValue * MmsValue_newUnsignedFromUint32(uint32_t integer)
Definition: mms_value.h:55
MmsValue * MmsValue_newIntegerFromInt64(int64_t integer)
void MmsValue_setBitStringBit(MmsValue *self, int bitPos, bool value)
Set a single bit (set to one) of an MmsType object of type MMS_BITSTRING.
Definition: mms_value.h:56
bool MmsValue_getBoolean(const MmsValue *value)
Get the bool value of a MmsValue object.
void MmsValue_setAllBitStringBits(MmsValue *self)
int32_t MmsValue_toInt32(const MmsValue *value)
Get the int32_t value of a MmsValue object.
uint8_t * MmsValue_getUtcTimeBuffer(MmsValue *self)
return the raw buffer containing the UTC time data
int MmsValue_encodeMmsData(MmsValue *self, uint8_t *buffer, int bufPos, bool encode)
Serialize the MmsValue instance as BER encoded MMS Data element.
void MmsValue_setBinaryTime(MmsValue *self, uint64_t timestamp)
Update an MmsValue object of type MMS_BINARYTIME with a millisecond time.
int64_t MmsValue_toInt64(const MmsValue *self)
Get the int64_t value of a MmsValue object.
uint32_t MmsValue_toUint32(const MmsValue *value)
Get the uint32_t value of a MmsValue object.
void MmsValue_setDouble(MmsValue *self, double newFloatValue)
Set the double value of a MmsValue object.
MmsValue * MmsValue_newVisibleStringWithSize(int size)
Create a new MmsValue instance of type MMS_VISIBLE_STRING.
uint32_t MmsValue_getBitStringAsInteger(const MmsValue *self)
Convert a bit string to an unsigned integer.
uint64_t MmsValue_getUtcTimeInMsWithUs(const MmsValue *self, uint32_t *usec)
Get a millisecond time value and optional us part from an MmsValue object of MMS_UTCTIME type...
MmsValue * MmsValue_newIntegerFromInt32(int32_t integer)
Definition: mms_value.h:57
MmsValue * MmsValue_clone(const MmsValue *self)
Create a (deep) copy of an MmsValue instance.
int MmsValue_getSizeInMemory(const MmsValue *self)
Determine the required amount of bytes by a clone.
uint8_t * MmsValue_getOctetStringBuffer(MmsValue *self)
Returns the reference to the internally hold buffer of an MmsValue object of type MMS_OCTET_STRING...
bool MmsValue_update(MmsValue *self, const MmsValue *source)
Update the value of an MmsValue instance by the value of another MmsValue instance.
MmsValue * MmsValue_createArray(MmsVariableSpecification *elementType, int size)
Create an Array and initialize elements with default values.
MmsValue * MmsValue_newStructure(const MmsVariableSpecification *typeSpec)
MmsValue * MmsValue_newIntegerFromInt8(int8_t integer)
char * MmsValue_getTypeString(MmsValue *self)
return the value type as a human readable string
void MmsValue_setUint16(MmsValue *value, uint16_t integer)
Set the UInt16 value of a MmsValue object.
MmsValue * MmsValue_newFloat(float variable)
float MmsValue_toFloat(const MmsValue *self)
Get the float value of a MmsValue object.
int MmsValue_getBitStringSize(const MmsValue *self)
Get the size of a bit string in bits.
int MmsValue_getNumberOfSetBits(const MmsValue *self)
Count the number of set bits in a bit string.
bool MmsValue_equalTypes(const MmsValue *self, const MmsValue *otherValue)
Check if two (complex) instances of MmsValue have the same type.
uint32_t MmsValue_getArraySize(const MmsValue *self)
Get the size of an array.
void MmsValue_setUint8(MmsValue *value, uint8_t integer)
Set the UInt8 value of a MmsValue object.
Definition: mms_value.h:50
MmsValue * MmsValue_newBoolean(bool boolean)
MmsValue * MmsValue_getElement(const MmsValue *array, int index)
Get an element of an array or structure.
MmsValue * MmsValue_newVisibleString(const char *string)
Create a new MmsValue instance of type MMS_VISIBLE_STRING.
Definition: mms_value.h:62
void MmsValue_setOctetString(MmsValue *self, uint8_t *buf, int size)
Set the value of an MmsValue object of type MMS_OCTET_STRING.
Definition: mms_value.h:51
void MmsValue_delete(MmsValue *self)
Delete an MmsValue instance.
MmsValue * MmsValue_newBitString(int bitSize)
Create a new MmsValue instance of type MMS_BITSTRING.
uint32_t MmsValue_getBitStringAsIntegerBigEndian(const MmsValue *self)
Convert a bit string to an unsigned integer (big endian bit order)
MmsValue * MmsValue_getSubElement(MmsValue *self, MmsVariableSpecification *varSpec, char *mmsPath)
Get a sub-element of a MMS_STRUCTURE value specified by a path name.
void MmsValue_setElement(MmsValue *complexValue, int index, MmsValue *elementValue)
Set an element of a complex type.
uint8_t * MmsValue_cloneToBuffer(const MmsValue *self, uint8_t *destinationAddress)
Create a (deep) copy of an MmsValue instance in a user provided buffer.
MmsValue * MmsValue_setUtcTime(MmsValue *self, uint32_t timeval)
Update an MmsValue object of UtcTime type with a timestamp in s.
bool MmsValue_getBitStringBit(const MmsValue *self, int bitPos)
Get the value of a single bit (set to one) of an MmsType object of type MMS_BITSTRING.
uint16_t MmsValue_getOctetStringSize(const MmsValue *self)
Returns the size in bytes of an MmsValue object of type MMS_OCTET_STRING.
void MmsValue_setBitStringFromInteger(MmsValue *self, uint32_t intValue)
Convert an unsigned integer to a bit string.
MmsValue * MmsValue_decodeMmsData(uint8_t *buffer, int bufPos, int bufferLength, int *endBufPos)
create a new MmsValue instance from a BER encoded MMS Data element (deserialize)
void MmsValue_setUtcTimeByBuffer(MmsValue *self, const uint8_t *buffer)
Update an MmsValue object of type MMS_UTCTIME with a buffer containing a BER encoded UTCTime...
MmsValue * MmsValue_newMmsString(char *string)
Create a new MmsValue instance of type MMS_STRING.
MmsValue * MmsValue_newUnsigned(int size)
MmsValue * MmsValue_newIntegerFromBerInteger(Asn1PrimitiveValue *berInteger)
void MmsValue_setUtcTimeQuality(MmsValue *self, uint8_t timeQuality)
set the TimeQuality byte of the UtcTime
Definition: mms_value.h:61
MmsValue * MmsValue_newUtcTime(uint32_t timeval)
Create a new MmsValue instance of type MMS_UTCTIME.
const char * MmsValue_printToBuffer(const MmsValue *self, char *buffer, int bufferSize)
create a string representation of the MmsValue object in the provided buffer
bool MmsValue_equals(const MmsValue *self, const MmsValue *otherValue)
Check if two instances of MmsValue have the same value.
MmsValue * MmsValue_setUtcTimeMs(MmsValue *self, uint64_t timeval)
Update an MmsValue object of type MMS_UTCTIME with a millisecond time.
MmsValue * MmsValue_newUnsignedFromBerInteger(Asn1PrimitiveValue *berInteger)
void MmsValue_setInt64(MmsValue *value, int64_t integer)
Set the Int64 value of a MmsValue object.
int MmsValue_isDeletable(MmsValue *self)
Check if the MmsValue instance has the deletable flag set.
MmsValue * MmsValue_newDataAccessError(MmsDataAccessError accessError)
void MmsValue_setVisibleString(MmsValue *self, const char *string)
const char * MmsValue_toString(MmsValue *self)
Returns the value of an MMS_VISIBLE_STRING object as C string.
int MmsValue_getStringSize(MmsValue *self)
Returns the (maximum) length of the string.
MmsValue * MmsValue_newVisibleStringFromByteArray(uint8_t *byteArray, int size)
Create a new MmsValue instance of type MMS_VISIBLE_STRING from the specified byte array...
void MmsValue_setFloat(MmsValue *self, float newFloatValue)
Set the float value of a MmsValue object.
void MmsValue_setDeletable(MmsValue *self)
MmsDataAccessError
Definition: mms_value.h:47
void MmsValue_setInt32(MmsValue *self, int32_t integer)
Set the Int32 value of a MmsValue object.
MmsValue * MmsValue_newBinaryTime(bool timeOfDay)
Create a new MmsValue instance of type MMS_BINARYTIME.
MmsDataAccessError MmsValue_getDataAccessError(const MmsValue *self)
void MmsValue_deleteAllBitStringBits(MmsValue *self)
Delete all bits (set to zero) of an MmsType object of type MMS_BITSTRING.
MmsValue * MmsValue_newMmsStringWithSize(int size)
Create a new MmsValue instance of type MMS_STRING.
uint8_t MmsValue_getUtcTimeQuality(const MmsValue *self)
get the TimeQuality byte of the UtcTime
void MmsValue_setBitStringFromIntegerBigEndian(MmsValue *self, uint32_t intValue)
Convert an unsigned integer to a bit string (big endian bit order)
void MmsValue_deleteConditional(MmsValue *value)
Delete an MmsValue instance.
MmsValue * MmsValue_newOctetString(int size, int maxSize)
uint64_t MmsValue_getBinaryTimeAsUtcMs(const MmsValue *self)
Get a millisecond time value from an MmsValue object of type MMS_BINARYTIME.
MmsValue * MmsValue_newDefaultValue(const MmsVariableSpecification *typeSpec)
void MmsValue_setDeletableRecursive(MmsValue *value)
MmsValue * MmsValue_createEmptyStructure(int size)
uint32_t MmsValue_toUnixTimestamp(const MmsValue *self)
Get the unix timestamp of a MmsValue object of type MMS_UTCTIME.
uint16_t MmsValue_getOctetStringMaxSize(MmsValue *self)
Returns the maximum size in bytes of an MmsValue object of type MMS_OCTET_STRING. ...
MmsValue * MmsValue_newMmsStringFromByteArray(uint8_t *byteArray, int size)
Create a new MmsValue instance of type MMS_STRING from the specified byte array.
void MmsValue_setInt16(MmsValue *value, int16_t integer)
Set the Int16 value of a MmsValue object.
void MmsValue_deleteIfNotNull(MmsValue *value)
Delete an MmsValue instance if the provided pointer is not NULL.
Definition: mms_value.h:60
Definition: mms_value.h:53
void MmsValue_setBoolean(MmsValue *value, bool boolValue)
Set the bool value of a MmsValue object.
MmsValue * MmsValue_newDouble(double variable)
Definition: mms_value.h:48
MmsValue * MmsValue_createEmptyArray(int size)
Create an emtpy array.
Definition: mms_value.h:49
void MmsValue_setMmsString(MmsValue *value, const char *string)
void MmsValue_setUint32(MmsValue *value, uint32_t integer)
Set the UInt32 value of a MmsValue object.
MmsValue * MmsValue_newUtcTimeByMsTime(uint64_t timeval)
Create a new MmsValue instance of type MMS_UTCTIME.
MmsType MmsValue_getType(const MmsValue *self)
Get the MmsType of an MmsValue instance.
MmsValue * MmsValue_newInteger(int size)
int MmsValue_getBitStringByteSize(const MmsValue *self)
Get the number of bytes required by this bitString.
void MmsValue_setInt8(MmsValue *value, int8_t integer)
Set the Int8 value of a MmsValue object.
Definition: mms_value.h:54
struct sMmsValue MmsValue
Definition: mms_value.h:68
MmsType
Definition: mms_common.h:105
MmsValue * MmsValue_newIntegerFromInt16(int16_t integer)