mms_value.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /*
  2. * mms_value.h
  3. *
  4. * Copyright 2013-2018 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. #ifndef MMS_VALUE_H_
  24. #define MMS_VALUE_H_
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #include "libiec61850_common_api.h"
  29. #include "mms_common.h"
  30. #include "mms_types.h"
  31. /**
  32. * \defgroup common_api_group libIEC61850 API common parts
  33. */
  34. /**@{*/
  35. /**
  36. * \defgroup MMS_VALUE MmsValue data type definition and handling functions
  37. */
  38. /**@{*/
  39. typedef enum {
  40. DATA_ACCESS_ERROR_SUCCESS_NO_UPDATE = -3,
  41. DATA_ACCESS_ERROR_NO_RESPONSE = -2, /* for server internal purposes only! */
  42. DATA_ACCESS_ERROR_SUCCESS = -1,
  43. DATA_ACCESS_ERROR_OBJECT_INVALIDATED = 0,
  44. DATA_ACCESS_ERROR_HARDWARE_FAULT = 1,
  45. DATA_ACCESS_ERROR_TEMPORARILY_UNAVAILABLE = 2,
  46. DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED = 3,
  47. DATA_ACCESS_ERROR_OBJECT_UNDEFINED = 4,
  48. DATA_ACCESS_ERROR_INVALID_ADDRESS = 5,
  49. DATA_ACCESS_ERROR_TYPE_UNSUPPORTED = 6,
  50. DATA_ACCESS_ERROR_TYPE_INCONSISTENT = 7,
  51. DATA_ACCESS_ERROR_OBJECT_ATTRIBUTE_INCONSISTENT = 8,
  52. DATA_ACCESS_ERROR_OBJECT_ACCESS_UNSUPPORTED = 9,
  53. DATA_ACCESS_ERROR_OBJECT_NONE_EXISTENT = 10,
  54. DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID = 11,
  55. DATA_ACCESS_ERROR_UNKNOWN = 12
  56. } MmsDataAccessError;
  57. /**
  58. * MmsValue - complex value type for MMS Client API
  59. */
  60. typedef struct sMmsValue MmsValue;
  61. /*************************************************************************************
  62. * Array functions
  63. *************************************************************************************/
  64. /**
  65. * \brief Create an Array and initialize elements with default values.
  66. *
  67. * \param elementType type description for the elements the new array
  68. * \param size the size of the new array
  69. *
  70. * \return a newly created array instance
  71. */
  72. LIB61850_API MmsValue*
  73. MmsValue_createArray(const MmsVariableSpecification* elementType, int size);
  74. /**
  75. * \brief Get the size of an array.
  76. *
  77. * \param self MmsValue instance to operate on. Has to be of type MMS_ARRAY.
  78. *
  79. * \return the size of the array
  80. */
  81. LIB61850_API uint32_t
  82. MmsValue_getArraySize(const MmsValue* self);
  83. /**
  84. * \brief Get an element of an array or structure.
  85. *
  86. * \param self MmsValue instance to operate on. Has to be of type MMS_ARRAY or MMS_STRUCTURE.
  87. * \param index ndex of the requested array or structure element
  88. *
  89. * \return the element object
  90. */
  91. LIB61850_API MmsValue*
  92. MmsValue_getElement(const MmsValue* array, int index);
  93. /**
  94. * \brief Create an emtpy array.
  95. *
  96. * \param size the size of the new array
  97. *
  98. * \return a newly created empty array instance
  99. */
  100. LIB61850_API MmsValue*
  101. MmsValue_createEmptyArray(int size);
  102. /**
  103. * \brief Set an element of a complex type
  104. *
  105. * NOTE: If the element already exists it will simply be replaced by the provided new value.
  106. * The caller is responsible to free the replaced value.
  107. *
  108. * \param complexValue MmsValue instance to operate on. Has to be of a type MMS_STRUCTURE or MMS_ARRAY
  109. * \param the index of the element to set/replace
  110. * \param elementValue the (new) value of the element
  111. */
  112. LIB61850_API void
  113. MmsValue_setElement(MmsValue* complexValue, int index, MmsValue* elementValue);
  114. /*************************************************************************************
  115. * Basic type functions
  116. *************************************************************************************/
  117. LIB61850_API MmsDataAccessError
  118. MmsValue_getDataAccessError(const MmsValue* self);
  119. /**
  120. * \brief Get the int64_t value of a MmsValue object.
  121. *
  122. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER or MMS_UNSIGNED
  123. *
  124. * \return signed 64 bit integer
  125. */
  126. LIB61850_API int64_t
  127. MmsValue_toInt64(const MmsValue* self);
  128. /**
  129. * \brief Get the int32_t value of a MmsValue object.
  130. *
  131. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER or MMS_UNSIGNED
  132. *
  133. * \return signed 32 bit integer
  134. */
  135. LIB61850_API int32_t
  136. MmsValue_toInt32(const MmsValue* value);
  137. /**
  138. * \brief Get the uint32_t value of a MmsValue object.
  139. *
  140. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER or MMS_UNSIGNED
  141. *
  142. * \return unsigned 32 bit integer
  143. */
  144. LIB61850_API uint32_t
  145. MmsValue_toUint32(const MmsValue* value);
  146. /**
  147. * \brief Get the double value of a MmsValue object.
  148. *
  149. * \param self MmsValue instance to operate on. Has to be of type MMS_FLOAT.
  150. *
  151. * \return 64 bit floating point value
  152. */
  153. LIB61850_API double
  154. MmsValue_toDouble(const MmsValue* self);
  155. /**
  156. * \brief Get the float value of a MmsValue object.
  157. *
  158. * \param self MmsValue instance to operate on. Has to be of type MMS_FLOAT.
  159. *
  160. * \return 32 bit floating point value
  161. */
  162. LIB61850_API float
  163. MmsValue_toFloat(const MmsValue* self);
  164. /**
  165. * \brief Get the unix timestamp of a MmsValue object of type MMS_UTCTIME.
  166. *
  167. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTC_TIME.
  168. *
  169. * \return unix timestamp of the MMS_UTCTIME variable.
  170. */
  171. LIB61850_API uint32_t
  172. MmsValue_toUnixTimestamp(const MmsValue* self);
  173. /**
  174. * \brief Set the float value of a MmsValue object.
  175. *
  176. * \param self MmsValue instance to operate on. Has to be of a type MMS_FLOAT.
  177. */
  178. LIB61850_API void
  179. MmsValue_setFloat(MmsValue* self, float newFloatValue);
  180. /**
  181. * \brief Set the double value of a MmsValue object.
  182. *
  183. * \param self MmsValue instance to operate on. Has to be of a type MMS_FLOAT.
  184. */
  185. LIB61850_API void
  186. MmsValue_setDouble(MmsValue* self, double newFloatValue);
  187. /**
  188. * \brief Set the Int8 value of a MmsValue object.
  189. *
  190. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER.
  191. * \param integer the new value to set
  192. */
  193. LIB61850_API void
  194. MmsValue_setInt8(MmsValue* value, int8_t integer);
  195. /**
  196. * \brief Set the Int16 value of a MmsValue object.
  197. *
  198. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER.
  199. * \param integer the new value to set
  200. */
  201. LIB61850_API void
  202. MmsValue_setInt16(MmsValue* value, int16_t integer);
  203. /**
  204. * \brief Set the Int32 value of a MmsValue object.
  205. *
  206. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER.
  207. * \param integer the new value to set
  208. */
  209. LIB61850_API void
  210. MmsValue_setInt32(MmsValue* self, int32_t integer);
  211. /**
  212. * \brief Set the Int64 value of a MmsValue object.
  213. *
  214. * \param self MmsValue instance to operate on. Has to be of a type MMS_INTEGER.
  215. * \param integer the new value to set
  216. */
  217. LIB61850_API void
  218. MmsValue_setInt64(MmsValue* value, int64_t integer);
  219. /**
  220. * \brief Set the UInt8 value of a MmsValue object.
  221. *
  222. * \param self MmsValue instance to operate on. Has to be of a type MMS_UNSIGNED.
  223. * \param integer the new value to set
  224. */
  225. LIB61850_API void
  226. MmsValue_setUint8(MmsValue* value, uint8_t integer);
  227. /**
  228. * \brief Set the UInt16 value of a MmsValue object.
  229. *
  230. * \param self MmsValue instance to operate on. Has to be of a type MMS_UNSIGNED.
  231. * \param integer the new value to set
  232. */
  233. LIB61850_API void
  234. MmsValue_setUint16(MmsValue* value, uint16_t integer);
  235. /**
  236. * \brief Set the UInt32 value of a MmsValue object.
  237. *
  238. * \param self MmsValue instance to operate on. Has to be of a type MMS_UNSIGNED.
  239. * \param integer the new value to set
  240. */
  241. LIB61850_API void
  242. MmsValue_setUint32(MmsValue* value, uint32_t integer);
  243. /**
  244. * \brief Set the bool value of a MmsValue object.
  245. *
  246. * \param self MmsValue instance to operate on. Has to be of a type MMS_BOOLEAN.
  247. * \param boolValue a bool value
  248. */
  249. LIB61850_API void
  250. MmsValue_setBoolean(MmsValue* value, bool boolValue);
  251. /**
  252. * \brief Get the bool value of a MmsValue object.
  253. *
  254. * \param self MmsValue instance to operate on. Has to be of a type MMS_BOOLEAN.
  255. * \return the MmsValue value as bool value
  256. */
  257. LIB61850_API bool
  258. MmsValue_getBoolean(const MmsValue* value);
  259. /**
  260. * \brief Returns the value of an MMS_VISIBLE_STRING object as C string
  261. *
  262. * \param self MmsValue instance to operate on. Has to be of a type MMS_VISIBLE_STRING or MMS_STRING.
  263. *
  264. * \returns the string value as 0 terminated C string
  265. */
  266. LIB61850_API const char*
  267. MmsValue_toString(MmsValue* self);
  268. /**
  269. * \brief Returns the (maximum) length of the string
  270. *
  271. * NOTE: this function return the amount of memory allocated for the string buffer - 1.
  272. *
  273. * \param self MmsValue instance to operate on. Has to be of a type MMS_VISIBLE_STRING or MMS_STRING.
  274. */
  275. LIB61850_API int
  276. MmsValue_getStringSize(MmsValue* self);
  277. LIB61850_API void
  278. MmsValue_setVisibleString(MmsValue* self, const char* string);
  279. /**
  280. * \brief Set a single bit (set to one) of an MmsType object of type MMS_BITSTRING
  281. *
  282. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  283. * \param bitPos the position of the bit in the bit string. Starting with 0. The bit
  284. * with position 0 is the first bit if the MmsValue instance is serialized.
  285. * \param value the new value of the bit (true = 1 / false = 0)
  286. */
  287. LIB61850_API void
  288. MmsValue_setBitStringBit(MmsValue* self, int bitPos, bool value);
  289. /**
  290. * \brief Get the value of a single bit (set to one) of an MmsType object of type MMS_BITSTRING
  291. *
  292. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  293. * \param bitPos the position of the bit in the bit string. Starting with 0. The bit
  294. * with position 0 is the first bit if the MmsValue instance is serialized.
  295. * \return the value of the bit (true = 1 / false = 0)
  296. */
  297. LIB61850_API bool
  298. MmsValue_getBitStringBit(const MmsValue* self, int bitPos);
  299. /**
  300. * \brief Delete all bits (set to zero) of an MmsType object of type MMS_BITSTRING
  301. *
  302. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  303. */
  304. LIB61850_API void
  305. MmsValue_deleteAllBitStringBits(MmsValue* self);
  306. /**
  307. * \brief Get the size of a bit string in bits.
  308. *
  309. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  310. */
  311. LIB61850_API int
  312. MmsValue_getBitStringSize(const MmsValue* self);
  313. /**
  314. * \brief Get the number of bytes required by this bitString
  315. *
  316. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  317. */
  318. LIB61850_API int
  319. MmsValue_getBitStringByteSize(const MmsValue* self);
  320. /**
  321. * \brief Count the number of set bits in a bit string.
  322. *
  323. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  324. */
  325. LIB61850_API int
  326. MmsValue_getNumberOfSetBits(const MmsValue* self);
  327. /**
  328. * Set all bits (set to one) of an MmsType object of type MMS_BITSTRING
  329. *
  330. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  331. */
  332. LIB61850_API void
  333. MmsValue_setAllBitStringBits(MmsValue* self);
  334. /**
  335. * \brief Convert a bit string to an unsigned integer
  336. *
  337. * This function assumes that the first bit in the bit string is the
  338. * least significant bit (little endian bit order).
  339. *
  340. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  341. */
  342. LIB61850_API uint32_t
  343. MmsValue_getBitStringAsInteger(const MmsValue* self);
  344. /**
  345. * \brief Convert an unsigned integer to a bit string
  346. *
  347. * The integer representation in the bit string assumes the first bit is the
  348. * least significant bit (little endian bit order).
  349. *
  350. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  351. * \param intValue the integer value that is used to set the bit string
  352. */
  353. LIB61850_API void
  354. MmsValue_setBitStringFromInteger(MmsValue* self, uint32_t intValue);
  355. /**
  356. * \brief Convert a bit string to an unsigned integer (big endian bit order)
  357. *
  358. * This function assumes that the first bit in the bit string is the
  359. * most significant bit (big endian bit order).
  360. *
  361. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  362. */
  363. LIB61850_API uint32_t
  364. MmsValue_getBitStringAsIntegerBigEndian(const MmsValue* self);
  365. /**
  366. * \brief Convert an unsigned integer to a bit string (big endian bit order)
  367. *
  368. * The integer representation in the bit string assumes the first bit is the
  369. * most significant bit (big endian bit order).
  370. *
  371. * \param self MmsValue instance to operate on. Has to be of a type MMS_BITSTRING.
  372. * \param intValue the integer value that is used to set the bit string
  373. */
  374. LIB61850_API void
  375. MmsValue_setBitStringFromIntegerBigEndian(MmsValue* self, uint32_t intValue);
  376. /**
  377. * \brief Update an MmsValue object of UtcTime type with a timestamp in s
  378. *
  379. * \param self MmsValue instance to operate on. Has to be of a type MMS_BOOLEAN.
  380. * \param timeval the new value in seconds since epoch (1970/01/01 00:00 UTC)
  381. */
  382. LIB61850_API MmsValue*
  383. MmsValue_setUtcTime(MmsValue* self, uint32_t timeval);
  384. /**
  385. * \brief Update an MmsValue object of type MMS_UTCTIME with a millisecond time.
  386. *
  387. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  388. * \param timeval the new value in milliseconds since epoch (1970/01/01 00:00 UTC)
  389. */
  390. LIB61850_API MmsValue*
  391. MmsValue_setUtcTimeMs(MmsValue* self, uint64_t timeval);
  392. /**
  393. * \brief Update an MmsValue object of type MMS_UTCTIME with a buffer containing a BER encoded UTCTime.
  394. *
  395. * The buffer must have a size of 8 bytes!
  396. *
  397. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  398. * \param buffer buffer containing the encoded UTCTime.
  399. */
  400. LIB61850_API void
  401. MmsValue_setUtcTimeByBuffer(MmsValue* self, const uint8_t* buffer);
  402. /**
  403. * \brief return the raw buffer containing the UTC time data
  404. *
  405. * Note: This will return the address of the raw byte buffer. The array length is 8 byte.
  406. *
  407. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  408. *
  409. * \return the buffer containing the raw data
  410. */
  411. LIB61850_API uint8_t*
  412. MmsValue_getUtcTimeBuffer(MmsValue* self);
  413. /**
  414. * \brief Get a millisecond time value from an MmsValue object of MMS_UTCTIME type.
  415. *
  416. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  417. *
  418. * \return the value in milliseconds since epoch (1970/01/01 00:00 UTC)
  419. */
  420. LIB61850_API uint64_t
  421. MmsValue_getUtcTimeInMs(const MmsValue* value);
  422. /**
  423. * \brief Get a millisecond time value and optional us part from an MmsValue object of MMS_UTCTIME type.
  424. *
  425. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  426. * \param usec a pointer to store the us (microsecond) value.
  427. *
  428. * \return the value in milliseconds since epoch (1970/01/01 00:00 UTC)
  429. */
  430. LIB61850_API uint64_t
  431. MmsValue_getUtcTimeInMsWithUs(const MmsValue* self, uint32_t* usec);
  432. /**
  433. * \brief set the TimeQuality byte of the UtcTime
  434. *
  435. * Meaning of the bits in the timeQuality byte:
  436. *
  437. * bit 7 = leapSecondsKnown
  438. * bit 6 = clockFailure
  439. * bit 5 = clockNotSynchronized
  440. * bit 0-4 = subsecond time accuracy (number of significant bits of subsecond time)
  441. *
  442. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  443. *
  444. * \param timeQuality the byte representing the time quality
  445. */
  446. LIB61850_API void
  447. MmsValue_setUtcTimeQuality(MmsValue* self, uint8_t timeQuality);
  448. /**
  449. * \brief get the TimeQuality byte of the UtcTime
  450. *
  451. * Meaning of the bits in the timeQuality byte:
  452. *
  453. * bit 7 = leapSecondsKnown
  454. * bit 6 = clockFailure
  455. * bit 5 = clockNotSynchronized
  456. * bit 0-4 = subsecond time accuracy (number of significant bits of subsecond time)
  457. *
  458. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  459. *
  460. * \return the byte representing the time quality
  461. */
  462. LIB61850_API uint8_t
  463. MmsValue_getUtcTimeQuality(const MmsValue* self);
  464. /**
  465. * \brief Update an MmsValue object of type MMS_BINARYTIME with a millisecond time.
  466. *
  467. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  468. * \param timeval the new value in milliseconds since epoch (1970/01/01 00:00 UTC)
  469. */
  470. LIB61850_API void
  471. MmsValue_setBinaryTime(MmsValue* self, uint64_t timestamp);
  472. /**
  473. * \brief Get a millisecond time value from an MmsValue object of type MMS_BINARYTIME.
  474. *
  475. * \param self MmsValue instance to operate on. Has to be of a type MMS_BINARYTIME.
  476. *
  477. * \return the value in milliseconds since epoch (1970/01/01 00:00 UTC)
  478. */
  479. LIB61850_API uint64_t
  480. MmsValue_getBinaryTimeAsUtcMs(const MmsValue* self);
  481. /**
  482. * \brief Set the value of an MmsValue object of type MMS_OCTET_STRING.
  483. *
  484. * This method will copy the provided buffer to the internal buffer of the
  485. * MmsValue instance. This will only happen if the internal buffer size is large
  486. * enough for the new value. Otherwise the object value is not changed.
  487. *
  488. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  489. * \param buf the buffer that contains the new value
  490. * \param size the size of the buffer that contains the new value
  491. */
  492. LIB61850_API void
  493. MmsValue_setOctetString(MmsValue* self, const uint8_t* buf, int size);
  494. /**
  495. * \brief Set a single octet of an MmsValue object of type MMS_OCTET_STRING.
  496. *
  497. * This method will copy the provided octet to the internal buffer of the
  498. * MmsValue instance, at the 'octetPos' position. This will only happen
  499. * if the internal buffer size is large enough. Otherwise the object value is not changed.
  500. *
  501. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  502. * \param octetPos the position of the octet in the octet string. Starting with 0.
  503. * The octet with position 0 is the first octet if the MmsValue instance is serialized.
  504. * \param value the new value of the octet (0 to 255, or 0x00 to 0xFF)
  505. */
  506. LIB61850_API void
  507. MmsValue_setOctetStringOctet(MmsValue* self, int octetPos, uint8_t value);
  508. /**
  509. * \brief Returns the size in bytes of an MmsValue object of type MMS_OCTET_STRING.
  510. *
  511. * NOTE: To access the byte in the buffer the function \ref MmsValue_getOctetStringBuffer
  512. * has to be used.
  513. *
  514. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  515. *
  516. * \return size in bytes
  517. */
  518. LIB61850_API uint16_t
  519. MmsValue_getOctetStringSize(const MmsValue* self);
  520. /**
  521. * \brief Returns the maximum size in bytes of an MmsValue object of type MMS_OCTET_STRING.
  522. *
  523. * Returns the maximum size if bytes of the MmsValue object of type MMS_OCTET_STRING. This
  524. * is the size of the internally allocated buffer to hold the octet string data.
  525. *
  526. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  527. *
  528. * \return maximum size in bytes
  529. */
  530. LIB61850_API uint16_t
  531. MmsValue_getOctetStringMaxSize(MmsValue* self);
  532. /**
  533. * \brief Returns the reference to the internally hold buffer of an MmsValue object of type MMS_OCTET_STRING.
  534. *
  535. * NOTE: The size of the buffer can be requested with the \ref MmsValue_getOctetStringSize function.
  536. *
  537. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  538. *
  539. * \return reference to the buffer
  540. */
  541. LIB61850_API uint8_t*
  542. MmsValue_getOctetStringBuffer(MmsValue* self);
  543. /**
  544. * \brief Get the value of a single octet of an MmsType object of type MMS_OCTET_STRING
  545. *
  546. * NOTE: The octet quantity of the octet string can be requested with
  547. * the \ref MmsValue_getOctetStringSize function.
  548. *
  549. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  550. * \param octetPos the position of the octet in the octet string. Starting with 0. The octet
  551. * with position 0 is the first octet if the MmsValue instance is serialized.
  552. * \return the value of the octet (0 to 255, or 0x00 to 0xFF)
  553. */
  554. LIB61850_API uint8_t
  555. MmsValue_getOctetStringOctet(MmsValue* self, int octetPos);
  556. /**
  557. * \brief Update the value of an MmsValue instance by the value of another MmsValue instance.
  558. *
  559. * Both instances should be of same time. E.g. is self is of type MMS_INTEGER then
  560. * source has also to be of type MMS_INTEGER. Otherwise the call will have no effect.
  561. *
  562. * \param self MmsValue instance to operate on.
  563. * \param source MmsValue used as source for the update. Has to be of same type as self
  564. *
  565. * \return indicates if the update has been successful (false if not)
  566. */
  567. LIB61850_API bool
  568. MmsValue_update(MmsValue* self, const MmsValue* source);
  569. /**
  570. * \brief Check if two instances of MmsValue have the same value.
  571. *
  572. * Both instances should be of same type. E.g. is self is of type MMS_INTEGER then
  573. * source has also to be of type MMS_INTEGER. Otherwise the call will return false.
  574. *
  575. * \param self MmsValue instance to operate on.
  576. * \param otherValue MmsValue that is used to test
  577. *
  578. * \return true if both instances are of the same type and have the same value
  579. */
  580. LIB61850_API bool
  581. MmsValue_equals(const MmsValue* self, const MmsValue* otherValue);
  582. /**
  583. * \brief Check if two (complex) instances of MmsValue have the same type.
  584. *
  585. * This function will test if the two values are of the same type. The function
  586. * will return true only if all child instances in the MmsValue instance tree are
  587. * also of equal type.
  588. *
  589. * \param self MmsValue instance to operate on.
  590. * \param otherValue MmsValue that is used to test
  591. *
  592. * \return true if both instances and all their children are of the same type.
  593. */
  594. LIB61850_API bool
  595. MmsValue_equalTypes(const MmsValue* self, const MmsValue* otherValue);
  596. /*************************************************************************************
  597. * Constructors and destructors
  598. *************************************************************************************/
  599. LIB61850_API MmsValue*
  600. MmsValue_newDataAccessError(MmsDataAccessError accessError);
  601. LIB61850_API MmsValue*
  602. MmsValue_newInteger(int size);
  603. LIB61850_API MmsValue*
  604. MmsValue_newUnsigned(int size);
  605. LIB61850_API MmsValue*
  606. MmsValue_newBoolean(bool boolean);
  607. /**
  608. * \brief Create a new MmsValue instance of type MMS_BITSTRING.
  609. *
  610. * \param bitSize the size of the bit string in bit
  611. *
  612. * \return new MmsValue instance of type MMS_BITSTRING
  613. */
  614. LIB61850_API MmsValue*
  615. MmsValue_newBitString(int bitSize);
  616. LIB61850_API MmsValue*
  617. MmsValue_newOctetString(int size, int maxSize);
  618. LIB61850_API MmsValue*
  619. MmsValue_newStructure(const MmsVariableSpecification* typeSpec);
  620. LIB61850_API MmsValue*
  621. MmsValue_createEmptyStructure(int size);
  622. LIB61850_API MmsValue*
  623. MmsValue_newDefaultValue(const MmsVariableSpecification* typeSpec);
  624. LIB61850_API MmsValue*
  625. MmsValue_newIntegerFromInt8(int8_t integer);
  626. LIB61850_API MmsValue*
  627. MmsValue_newIntegerFromInt16(int16_t integer);
  628. LIB61850_API MmsValue*
  629. MmsValue_newIntegerFromInt32(int32_t integer);
  630. LIB61850_API MmsValue*
  631. MmsValue_newIntegerFromInt64(int64_t integer);
  632. LIB61850_API MmsValue*
  633. MmsValue_newUnsignedFromUint32(uint32_t integer);
  634. /**
  635. * \brief Create a new 32 bit wide float variable and initialize with value
  636. *
  637. * \param value the initial value
  638. *
  639. * \return new MmsValue instance of type MMS_FLOAT
  640. */
  641. LIB61850_API MmsValue*
  642. MmsValue_newFloat(float value);
  643. /**
  644. * \brief Create a new 64 bit wide float variable and initialize with value
  645. *
  646. * \param value the initial value
  647. *
  648. * \return new MmsValue instance of type MMS_FLOAT
  649. */
  650. LIB61850_API MmsValue*
  651. MmsValue_newDouble(double value);
  652. /**
  653. * \brief Create a (deep) copy of an MmsValue instance
  654. *
  655. * This operation will allocate dynamic memory. It is up to the caller to
  656. * free this memory by calling MmsValue_delete() later.
  657. *
  658. * \param self the MmsValue instance that will be cloned
  659. *
  660. * \return an MmsValue instance that is an exact copy of the given instance.
  661. */
  662. LIB61850_API MmsValue*
  663. MmsValue_clone(const MmsValue* self);
  664. /**
  665. * \brief Create a (deep) copy of an MmsValue instance in a user provided buffer
  666. *
  667. * This operation copies the give MmsValue instance to a user provided buffer.
  668. *
  669. * \param self the MmsValue instance that will be cloned
  670. * \param destinationAddress the start address of the user provided buffer
  671. *
  672. * \return a pointer to the position in the buffer just after the last byte written.
  673. */
  674. LIB61850_API uint8_t*
  675. MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress);
  676. /**
  677. * \brief Determine the required amount of bytes by a clone.
  678. *
  679. * This function is intended to be used to determine the buffer size of a clone operation
  680. * (MmsValue_cloneToBuffer) in advance.
  681. *
  682. * \param self the MmsValue instance
  683. *
  684. * \return the number of bytes required by a clone
  685. */
  686. LIB61850_API int
  687. MmsValue_getSizeInMemory(const MmsValue* self);
  688. /**
  689. * \brief Delete an MmsValue instance.
  690. *
  691. * This operation frees all dynamically allocated memory of the MmsValue instance.
  692. * If the instance is of type MMS_STRUCTURE or MMS_ARRAY all child elements will
  693. * be deleted too.
  694. *
  695. * \param self the MmsValue instance to be deleted.
  696. */
  697. LIB61850_API void
  698. MmsValue_delete(MmsValue* self);
  699. /**
  700. * \brief Delete an MmsValue instance.
  701. *
  702. * This operation frees all dynamically allocated memory of the MmsValue instance.
  703. * If the instance is of type MMS_STRUCTURE or MMS_ARRAY all child elements will
  704. * be deleted too.
  705. *
  706. * NOTE: this functions only frees the instance if deleteValue field = 0!
  707. *
  708. *
  709. * \param self the MmsValue instance to be deleted.
  710. */
  711. LIB61850_API void
  712. MmsValue_deleteConditional(MmsValue* value);
  713. /**
  714. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING.
  715. *
  716. * This function will allocate as much memory as required to hold the string and sets the maximum size of
  717. * the string to this size.
  718. *
  719. * \param string a text string that should be the value of the new instance of NULL for an empty string.
  720. *
  721. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  722. */
  723. LIB61850_API MmsValue*
  724. MmsValue_newVisibleString(const char* string);
  725. /**
  726. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING.
  727. *
  728. * This function will create a new empty MmsValue string object. The maximum size of the string is set
  729. * according to the size parameter. The function allocates as much memory as is required to hold a string
  730. * of the maximum size.
  731. *
  732. * \param size the new maximum size of the string.
  733. *
  734. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  735. */
  736. LIB61850_API MmsValue*
  737. MmsValue_newVisibleStringWithSize(int size);
  738. /**
  739. * \brief Create a new MmsValue instance of type MMS_STRING.
  740. *
  741. * This function will create a new empty MmsValue string object. The maximum size of the string is set
  742. * according to the size parameter. The function allocates as much memory as is required to hold a string
  743. * of the maximum size.
  744. *
  745. * \param size the new maximum size of the string.
  746. *
  747. * \return new MmsValue instance of type MMS_STRING
  748. */
  749. LIB61850_API MmsValue*
  750. MmsValue_newMmsStringWithSize(int size);
  751. /**
  752. * \brief Create a new MmsValue instance of type MMS_BINARYTIME.
  753. *
  754. * If the timeOfDay parameter is set to true then the resulting
  755. * MMS_BINARYTIME object is only 4 octets long and includes only
  756. * the seconds since midnight. Otherwise the MMS_BINARYTIME
  757. *
  758. * \param timeOfDay if true only the TimeOfDay value is included.
  759. *
  760. * \return new MmsValue instance of type MMS_BINARYTIME
  761. */
  762. LIB61850_API MmsValue*
  763. MmsValue_newBinaryTime(bool timeOfDay);
  764. /**
  765. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING from the specified byte array
  766. *
  767. * \param byteArray the byte array containing the string data
  768. * \param size the size of the byte array
  769. *
  770. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  771. */
  772. LIB61850_API MmsValue*
  773. MmsValue_newVisibleStringFromByteArray(const uint8_t* byteArray, int size);
  774. /**
  775. * \brief Create a new MmsValue instance of type MMS_STRING from the specified byte array
  776. *
  777. * \param byteArray the byte array containing the string data
  778. * \param size the size of the byte array
  779. *
  780. * \return new MmsValue instance of type MMS_STRING
  781. */
  782. LIB61850_API MmsValue*
  783. MmsValue_newMmsStringFromByteArray(const uint8_t* byteArray, int size);
  784. /**
  785. * \brief Create a new MmsValue instance of type MMS_STRING.
  786. *
  787. * \param string a text string that should be the value of the new instance of NULL for an empty string.
  788. *
  789. * \return new MmsValue instance of type MMS_STRING
  790. */
  791. LIB61850_API MmsValue*
  792. MmsValue_newMmsString(const char* string);
  793. /**
  794. * \brief Set the value of MmsValue instance of type MMS_STRING
  795. *
  796. * \param string a text string that will be the new value of the instance
  797. */
  798. LIB61850_API void
  799. MmsValue_setMmsString(MmsValue* value, const char* string);
  800. /**
  801. * \brief Create a new MmsValue instance of type MMS_UTCTIME.
  802. *
  803. * \param timeval time value as UNIX timestamp (seconds since epoch)
  804. *
  805. * \return new MmsValue instance of type MMS_UTCTIME
  806. */
  807. LIB61850_API MmsValue*
  808. MmsValue_newUtcTime(uint32_t timeval);
  809. /**
  810. * \brief Create a new MmsValue instance of type MMS_UTCTIME.
  811. *
  812. * \param timeval time value as millisecond timestamp (milliseconds since epoch)
  813. *
  814. * \return new MmsValue instance of type MMS_UTCTIME
  815. */
  816. LIB61850_API MmsValue*
  817. MmsValue_newUtcTimeByMsTime(uint64_t timeval);
  818. LIB61850_API void
  819. MmsValue_setDeletable(MmsValue* self);
  820. LIB61850_API void
  821. MmsValue_setDeletableRecursive(MmsValue* value);
  822. /**
  823. * \brief Check if the MmsValue instance has the deletable flag set.
  824. *
  825. * The deletable flag indicates if an libiec61850 API client should call the
  826. * MmsValue_delete() method or not if the MmsValue instance was passed to the
  827. * client by an API call or callback method.
  828. *
  829. * \param self the MmsValue instance
  830. *
  831. * \return 1 if deletable flag is set, otherwise 0
  832. */
  833. LIB61850_API int
  834. MmsValue_isDeletable(MmsValue* self);
  835. /**
  836. * \brief Get the MmsType of an MmsValue instance
  837. *
  838. * \param self the MmsValue instance
  839. */
  840. LIB61850_API MmsType
  841. MmsValue_getType(const MmsValue* self);
  842. /**
  843. * \brief Get a sub-element of a MMS_STRUCTURE value specified by a path name.
  844. *
  845. * \param self the MmsValue instance
  846. * \param varSpec - type specification if the MMS_STRUCTURE value
  847. * \param mmsPath - path (in MMS variable name syntax) to specify the sub element.
  848. *
  849. * \return the sub elements MmsValue instance or NULL if the element does not exist
  850. */
  851. LIB61850_API MmsValue*
  852. MmsValue_getSubElement(MmsValue* self, MmsVariableSpecification* varSpec, char* mmsPath);
  853. /**
  854. * \brief return the value type as a human readable string
  855. *
  856. * \param self the MmsValue instance
  857. *
  858. * \return the value type as a human readable string
  859. */
  860. LIB61850_API char*
  861. MmsValue_getTypeString(MmsValue* self);
  862. /**
  863. * \brief create a string representation of the MmsValue object in the provided buffer
  864. *
  865. * NOTE: This function is for debugging purposes only. It may not be aimed to be used
  866. * in embedded systems. It requires a full featured snprintf function.
  867. *
  868. * \param self the MmsValue instance
  869. * \param buffer the buffer where to copy the string representation
  870. * \param bufferSize the size of the provided buffer
  871. *
  872. * \return a pointer to the start of the buffer
  873. */
  874. LIB61850_API const char*
  875. MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize);
  876. /**
  877. * \brief create a new MmsValue instance from a BER encoded MMS Data element (deserialize)
  878. *
  879. * WARNING: API changed with version 1.0.3 (added endBufPos parameter)
  880. *
  881. * \param buffer the buffer to read from
  882. * \param bufPos the start position of the mms value data in the buffer
  883. * \param bufferLength the length of the buffer
  884. * \param endBufPos the position in the buffer after the read MMS data element (NULL if not required)
  885. *
  886. * \return the MmsValue instance created from the buffer
  887. */
  888. LIB61850_API MmsValue*
  889. MmsValue_decodeMmsData(uint8_t* buffer, int bufPos, int bufferLength, int* endBufPos);
  890. /**
  891. * \brief Serialize the MmsValue instance as BER encoded MMS Data element
  892. *
  893. * \param self the MmsValue instance
  894. *
  895. * \param buffer the buffer to encode the MMS data element
  896. * \param bufPos the position in the buffer where to start encoding
  897. * \param encode encode to buffer (true) or calculate length only (false)
  898. *
  899. * \return the encoded length of the corresponding MMS data element
  900. */
  901. LIB61850_API int
  902. MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode);
  903. /**
  904. * \brief Get the maximum possible BER encoded size of the MMS data element
  905. *
  906. * \param self the MmsValue instance
  907. *
  908. * \return the maximum encoded size in bytes of the MMS data element
  909. */
  910. LIB61850_API int
  911. MmsValue_getMaxEncodedSize(MmsValue* self);
  912. /**
  913. * \brief Calculate the maximum encoded size of a variable of this type
  914. *
  915. * \param self the MMS variable specification instance
  916. */
  917. LIB61850_API int
  918. MmsVariableSpecification_getMaxEncodedSize(MmsVariableSpecification* self);
  919. /**@}*/
  920. /**@}*/
  921. #ifdef __cplusplus
  922. }
  923. #endif
  924. #endif /* MMS_VALUE_H_ */