mms_value.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. * \param timeQuality the byte representing the time quality
  444. */
  445. LIB61850_API void
  446. MmsValue_setUtcTimeQuality(MmsValue* self, uint8_t timeQuality);
  447. /**
  448. * \brief Update an MmsValue object of type MMS_UTCTIME with a millisecond time.
  449. *
  450. * Meaning of the bits in the timeQuality byte:
  451. *
  452. * bit 7 = leapSecondsKnown
  453. * bit 6 = clockFailure
  454. * bit 5 = clockNotSynchronized
  455. * bit 0-4 = subsecond time accuracy (number of significant bits of subsecond time)
  456. *
  457. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  458. * \param timeval the new value in milliseconds since epoch (1970/01/01 00:00 UTC)
  459. * \param timeQuality the byte representing the time quality
  460. *
  461. * \return the updated MmsValue instance
  462. */
  463. LIB61850_API MmsValue*
  464. MmsValue_setUtcTimeMsEx(MmsValue* self, uint64_t timeval, uint8_t timeQuality);
  465. /**
  466. * \brief get the TimeQuality byte of the UtcTime
  467. *
  468. * Meaning of the bits in the timeQuality byte:
  469. *
  470. * bit 7 = leapSecondsKnown
  471. * bit 6 = clockFailure
  472. * bit 5 = clockNotSynchronized
  473. * bit 0-4 = subsecond time accuracy (number of significant bits of subsecond time)
  474. *
  475. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  476. *
  477. * \return the byte representing the time quality
  478. */
  479. LIB61850_API uint8_t
  480. MmsValue_getUtcTimeQuality(const MmsValue* self);
  481. /**
  482. * \brief Update an MmsValue object of type MMS_BINARYTIME with a millisecond time.
  483. *
  484. * \param self MmsValue instance to operate on. Has to be of a type MMS_UTCTIME.
  485. * \param timeval the new value in milliseconds since epoch (1970/01/01 00:00 UTC)
  486. */
  487. LIB61850_API void
  488. MmsValue_setBinaryTime(MmsValue* self, uint64_t timestamp);
  489. /**
  490. * \brief Get a millisecond time value from an MmsValue object of type MMS_BINARYTIME.
  491. *
  492. * \param self MmsValue instance to operate on. Has to be of a type MMS_BINARYTIME.
  493. *
  494. * \return the value in milliseconds since epoch (1970/01/01 00:00 UTC)
  495. */
  496. LIB61850_API uint64_t
  497. MmsValue_getBinaryTimeAsUtcMs(const MmsValue* self);
  498. /**
  499. * \brief Set the value of an MmsValue object of type MMS_OCTET_STRING.
  500. *
  501. * This method will copy the provided buffer to the internal buffer of the
  502. * MmsValue instance. This will only happen if the internal buffer size is large
  503. * enough for the new value. Otherwise the object value is not changed.
  504. *
  505. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  506. * \param buf the buffer that contains the new value
  507. * \param size the size of the buffer that contains the new value
  508. */
  509. LIB61850_API void
  510. MmsValue_setOctetString(MmsValue* self, const uint8_t* buf, int size);
  511. /**
  512. * \brief Set a single octet of an MmsValue object of type MMS_OCTET_STRING.
  513. *
  514. * This method will copy the provided octet to the internal buffer of the
  515. * MmsValue instance, at the 'octetPos' position. This will only happen
  516. * if the internal buffer size is large enough. Otherwise the object value is not changed.
  517. *
  518. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  519. * \param octetPos the position of the octet in the octet string. Starting with 0.
  520. * The octet with position 0 is the first octet if the MmsValue instance is serialized.
  521. * \param value the new value of the octet (0 to 255, or 0x00 to 0xFF)
  522. */
  523. LIB61850_API void
  524. MmsValue_setOctetStringOctet(MmsValue* self, int octetPos, uint8_t value);
  525. /**
  526. * \brief Returns the size in bytes of an MmsValue object of type MMS_OCTET_STRING.
  527. *
  528. * NOTE: To access the byte in the buffer the function \ref MmsValue_getOctetStringBuffer
  529. * has to be used.
  530. *
  531. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  532. *
  533. * \return size in bytes
  534. */
  535. LIB61850_API uint16_t
  536. MmsValue_getOctetStringSize(const MmsValue* self);
  537. /**
  538. * \brief Returns the maximum size in bytes of an MmsValue object of type MMS_OCTET_STRING.
  539. *
  540. * Returns the maximum size if bytes of the MmsValue object of type MMS_OCTET_STRING. This
  541. * is the size of the internally allocated buffer to hold the octet string data.
  542. *
  543. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  544. *
  545. * \return maximum size in bytes
  546. */
  547. LIB61850_API uint16_t
  548. MmsValue_getOctetStringMaxSize(MmsValue* self);
  549. /**
  550. * \brief Returns the reference to the internally hold buffer of an MmsValue object of type MMS_OCTET_STRING.
  551. *
  552. * NOTE: The size of the buffer can be requested with the \ref MmsValue_getOctetStringSize function.
  553. *
  554. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  555. *
  556. * \return reference to the buffer
  557. */
  558. LIB61850_API uint8_t*
  559. MmsValue_getOctetStringBuffer(MmsValue* self);
  560. /**
  561. * \brief Get the value of a single octet of an MmsType object of type MMS_OCTET_STRING
  562. *
  563. * NOTE: The octet quantity of the octet string can be requested with
  564. * the \ref MmsValue_getOctetStringSize function.
  565. *
  566. * \param self MmsValue instance to operate on. Has to be of a type MMS_OCTET_STRING.
  567. * \param octetPos the position of the octet in the octet string. Starting with 0. The octet
  568. * with position 0 is the first octet if the MmsValue instance is serialized.
  569. * \return the value of the octet (0 to 255, or 0x00 to 0xFF)
  570. */
  571. LIB61850_API uint8_t
  572. MmsValue_getOctetStringOctet(MmsValue* self, int octetPos);
  573. /**
  574. * \brief Update the value of an MmsValue instance by the value of another MmsValue instance.
  575. *
  576. * Both instances should be of same time. E.g. is self is of type MMS_INTEGER then
  577. * source has also to be of type MMS_INTEGER. Otherwise the call will have no effect.
  578. *
  579. * \param self MmsValue instance to operate on.
  580. * \param source MmsValue used as source for the update. Has to be of same type as self
  581. *
  582. * \return indicates if the update has been successful (false if not)
  583. */
  584. LIB61850_API bool
  585. MmsValue_update(MmsValue* self, const MmsValue* source);
  586. /**
  587. * \brief Check if two instances of MmsValue have the same value.
  588. *
  589. * Both instances should be of same type. E.g. is self is of type MMS_INTEGER then
  590. * source has also to be of type MMS_INTEGER. Otherwise the call will return false.
  591. *
  592. * \param self MmsValue instance to operate on.
  593. * \param otherValue MmsValue that is used to test
  594. *
  595. * \return true if both instances are of the same type and have the same value
  596. */
  597. LIB61850_API bool
  598. MmsValue_equals(const MmsValue* self, const MmsValue* otherValue);
  599. /**
  600. * \brief Check if two (complex) instances of MmsValue have the same type.
  601. *
  602. * This function will test if the two values are of the same type. The function
  603. * will return true only if all child instances in the MmsValue instance tree are
  604. * also of equal type.
  605. *
  606. * \param self MmsValue instance to operate on.
  607. * \param otherValue MmsValue that is used to test
  608. *
  609. * \return true if both instances and all their children are of the same type.
  610. */
  611. LIB61850_API bool
  612. MmsValue_equalTypes(const MmsValue* self, const MmsValue* otherValue);
  613. /*************************************************************************************
  614. * Constructors and destructors
  615. *************************************************************************************/
  616. LIB61850_API MmsValue*
  617. MmsValue_newDataAccessError(MmsDataAccessError accessError);
  618. LIB61850_API MmsValue*
  619. MmsValue_newInteger(int size);
  620. LIB61850_API MmsValue*
  621. MmsValue_newUnsigned(int size);
  622. LIB61850_API MmsValue*
  623. MmsValue_newBoolean(bool boolean);
  624. /**
  625. * \brief Create a new MmsValue instance of type MMS_BITSTRING.
  626. *
  627. * \param bitSize the size of the bit string in bit
  628. *
  629. * \return new MmsValue instance of type MMS_BITSTRING
  630. */
  631. LIB61850_API MmsValue*
  632. MmsValue_newBitString(int bitSize);
  633. LIB61850_API MmsValue*
  634. MmsValue_newOctetString(int size, int maxSize);
  635. LIB61850_API MmsValue*
  636. MmsValue_newStructure(const MmsVariableSpecification* typeSpec);
  637. LIB61850_API MmsValue*
  638. MmsValue_createEmptyStructure(int size);
  639. LIB61850_API MmsValue*
  640. MmsValue_newDefaultValue(const MmsVariableSpecification* typeSpec);
  641. LIB61850_API MmsValue*
  642. MmsValue_newIntegerFromInt8(int8_t integer);
  643. LIB61850_API MmsValue*
  644. MmsValue_newIntegerFromInt16(int16_t integer);
  645. LIB61850_API MmsValue*
  646. MmsValue_newIntegerFromInt32(int32_t integer);
  647. LIB61850_API MmsValue*
  648. MmsValue_newIntegerFromInt64(int64_t integer);
  649. LIB61850_API MmsValue*
  650. MmsValue_newUnsignedFromUint32(uint32_t integer);
  651. /**
  652. * \brief Create a new 32 bit wide float variable and initialize with value
  653. *
  654. * \param value the initial value
  655. *
  656. * \return new MmsValue instance of type MMS_FLOAT
  657. */
  658. LIB61850_API MmsValue*
  659. MmsValue_newFloat(float value);
  660. /**
  661. * \brief Create a new 64 bit wide float variable and initialize with value
  662. *
  663. * \param value the initial value
  664. *
  665. * \return new MmsValue instance of type MMS_FLOAT
  666. */
  667. LIB61850_API MmsValue*
  668. MmsValue_newDouble(double value);
  669. /**
  670. * \brief Create a (deep) copy of an MmsValue instance
  671. *
  672. * This operation will allocate dynamic memory. It is up to the caller to
  673. * free this memory by calling MmsValue_delete() later.
  674. *
  675. * \param self the MmsValue instance that will be cloned
  676. *
  677. * \return an MmsValue instance that is an exact copy of the given instance.
  678. */
  679. LIB61850_API MmsValue*
  680. MmsValue_clone(const MmsValue* self);
  681. /**
  682. * \brief Create a (deep) copy of an MmsValue instance in a user provided buffer
  683. *
  684. * This operation copies the give MmsValue instance to a user provided buffer.
  685. *
  686. * \param self the MmsValue instance that will be cloned
  687. * \param destinationAddress the start address of the user provided buffer
  688. *
  689. * \return a pointer to the position in the buffer just after the last byte written.
  690. */
  691. LIB61850_API uint8_t*
  692. MmsValue_cloneToBuffer(const MmsValue* self, uint8_t* destinationAddress);
  693. /**
  694. * \brief Determine the required amount of bytes by a clone.
  695. *
  696. * This function is intended to be used to determine the buffer size of a clone operation
  697. * (MmsValue_cloneToBuffer) in advance.
  698. *
  699. * \param self the MmsValue instance
  700. *
  701. * \return the number of bytes required by a clone
  702. */
  703. LIB61850_API int
  704. MmsValue_getSizeInMemory(const MmsValue* self);
  705. /**
  706. * \brief Delete an MmsValue instance.
  707. *
  708. * This operation frees all dynamically allocated memory of the MmsValue instance.
  709. * If the instance is of type MMS_STRUCTURE or MMS_ARRAY all child elements will
  710. * be deleted too.
  711. *
  712. * \param self the MmsValue instance to be deleted.
  713. */
  714. LIB61850_API void
  715. MmsValue_delete(MmsValue* self);
  716. /**
  717. * \brief Delete an MmsValue instance.
  718. *
  719. * This operation frees all dynamically allocated memory of the MmsValue instance.
  720. * If the instance is of type MMS_STRUCTURE or MMS_ARRAY all child elements will
  721. * be deleted too.
  722. *
  723. * NOTE: this functions only frees the instance if deleteValue field = 0!
  724. *
  725. *
  726. * \param self the MmsValue instance to be deleted.
  727. */
  728. LIB61850_API void
  729. MmsValue_deleteConditional(MmsValue* value);
  730. /**
  731. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING.
  732. *
  733. * This function will allocate as much memory as required to hold the string and sets the maximum size of
  734. * the string to this size.
  735. *
  736. * \param string a text string that should be the value of the new instance of NULL for an empty string.
  737. *
  738. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  739. */
  740. LIB61850_API MmsValue*
  741. MmsValue_newVisibleString(const char* string);
  742. /**
  743. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING.
  744. *
  745. * This function will create a new empty MmsValue string object. The maximum size of the string is set
  746. * according to the size parameter. The function allocates as much memory as is required to hold a string
  747. * of the maximum size.
  748. *
  749. * \param size the new maximum size of the string.
  750. *
  751. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  752. */
  753. LIB61850_API MmsValue*
  754. MmsValue_newVisibleStringWithSize(int size);
  755. /**
  756. * \brief Create a new MmsValue instance of type MMS_STRING.
  757. *
  758. * This function will create a new empty MmsValue string object. The maximum size of the string is set
  759. * according to the size parameter. The function allocates as much memory as is required to hold a string
  760. * of the maximum size.
  761. *
  762. * \param size the new maximum size of the string.
  763. *
  764. * \return new MmsValue instance of type MMS_STRING
  765. */
  766. LIB61850_API MmsValue*
  767. MmsValue_newMmsStringWithSize(int size);
  768. /**
  769. * \brief Create a new MmsValue instance of type MMS_BINARYTIME.
  770. *
  771. * If the timeOfDay parameter is set to true then the resulting
  772. * MMS_BINARYTIME object is only 4 octets long and includes only
  773. * the seconds since midnight. Otherwise the MMS_BINARYTIME
  774. *
  775. * \param timeOfDay if true only the TimeOfDay value is included.
  776. *
  777. * \return new MmsValue instance of type MMS_BINARYTIME
  778. */
  779. LIB61850_API MmsValue*
  780. MmsValue_newBinaryTime(bool timeOfDay);
  781. /**
  782. * \brief Create a new MmsValue instance of type MMS_VISIBLE_STRING from the specified byte array
  783. *
  784. * \param byteArray the byte array containing the string data
  785. * \param size the size of the byte array
  786. *
  787. * \return new MmsValue instance of type MMS_VISIBLE_STRING
  788. */
  789. LIB61850_API MmsValue*
  790. MmsValue_newVisibleStringFromByteArray(const uint8_t* byteArray, int size);
  791. /**
  792. * \brief Create a new MmsValue instance of type MMS_STRING from the specified byte array
  793. *
  794. * \param byteArray the byte array containing the string data
  795. * \param size the size of the byte array
  796. *
  797. * \return new MmsValue instance of type MMS_STRING
  798. */
  799. LIB61850_API MmsValue*
  800. MmsValue_newMmsStringFromByteArray(const uint8_t* byteArray, int size);
  801. /**
  802. * \brief Create a new MmsValue instance of type MMS_STRING.
  803. *
  804. * \param string a text string that should be the value of the new instance of NULL for an empty string.
  805. *
  806. * \return new MmsValue instance of type MMS_STRING
  807. */
  808. LIB61850_API MmsValue*
  809. MmsValue_newMmsString(const char* string);
  810. /**
  811. * \brief Set the value of MmsValue instance of type MMS_STRING
  812. *
  813. * \param string a text string that will be the new value of the instance
  814. */
  815. LIB61850_API void
  816. MmsValue_setMmsString(MmsValue* value, const char* string);
  817. /**
  818. * \brief Create a new MmsValue instance of type MMS_UTCTIME.
  819. *
  820. * \param timeval time value as UNIX timestamp (seconds since epoch)
  821. *
  822. * \return new MmsValue instance of type MMS_UTCTIME
  823. */
  824. LIB61850_API MmsValue*
  825. MmsValue_newUtcTime(uint32_t timeval);
  826. /**
  827. * \brief Create a new MmsValue instance of type MMS_UTCTIME.
  828. *
  829. * \param timeval time value as millisecond timestamp (milliseconds since epoch)
  830. *
  831. * \return new MmsValue instance of type MMS_UTCTIME
  832. */
  833. LIB61850_API MmsValue*
  834. MmsValue_newUtcTimeByMsTime(uint64_t timeval);
  835. LIB61850_API void
  836. MmsValue_setDeletable(MmsValue* self);
  837. LIB61850_API void
  838. MmsValue_setDeletableRecursive(MmsValue* value);
  839. /**
  840. * \brief Check if the MmsValue instance has the deletable flag set.
  841. *
  842. * The deletable flag indicates if an libiec61850 API client should call the
  843. * MmsValue_delete() method or not if the MmsValue instance was passed to the
  844. * client by an API call or callback method.
  845. *
  846. * \param self the MmsValue instance
  847. *
  848. * \return 1 if deletable flag is set, otherwise 0
  849. */
  850. LIB61850_API int
  851. MmsValue_isDeletable(MmsValue* self);
  852. /**
  853. * \brief Get the MmsType of an MmsValue instance
  854. *
  855. * \param self the MmsValue instance
  856. */
  857. LIB61850_API MmsType
  858. MmsValue_getType(const MmsValue* self);
  859. /**
  860. * \brief Get a sub-element of a MMS_STRUCTURE value specified by a path name.
  861. *
  862. * \param self the MmsValue instance
  863. * \param varSpec - type specification if the MMS_STRUCTURE value
  864. * \param mmsPath - path (in MMS variable name syntax) to specify the sub element.
  865. *
  866. * \return the sub elements MmsValue instance or NULL if the element does not exist
  867. */
  868. LIB61850_API MmsValue*
  869. MmsValue_getSubElement(MmsValue* self, MmsVariableSpecification* varSpec, char* mmsPath);
  870. /**
  871. * \brief return the value type as a human readable string
  872. *
  873. * \param self the MmsValue instance
  874. *
  875. * \return the value type as a human readable string
  876. */
  877. LIB61850_API char*
  878. MmsValue_getTypeString(MmsValue* self);
  879. /**
  880. * \brief create a string representation of the MmsValue object in the provided buffer
  881. *
  882. * NOTE: This function is for debugging purposes only. It may not be aimed to be used
  883. * in embedded systems. It requires a full featured snprintf function.
  884. *
  885. * \param self the MmsValue instance
  886. * \param buffer the buffer where to copy the string representation
  887. * \param bufferSize the size of the provided buffer
  888. *
  889. * \return a pointer to the start of the buffer
  890. */
  891. LIB61850_API const char*
  892. MmsValue_printToBuffer(const MmsValue* self, char* buffer, int bufferSize);
  893. /**
  894. * \brief create a new MmsValue instance from a BER encoded MMS Data element (deserialize)
  895. *
  896. * WARNING: API changed with version 1.0.3 (added endBufPos parameter)
  897. *
  898. * \param buffer the buffer to read from
  899. * \param bufPos the start position of the mms value data in the buffer
  900. * \param bufferLength the length of the buffer
  901. * \param endBufPos the position in the buffer after the read MMS data element (NULL if not required)
  902. *
  903. * \return the MmsValue instance created from the buffer
  904. */
  905. LIB61850_API MmsValue*
  906. MmsValue_decodeMmsData(uint8_t* buffer, int bufPos, int bufferLength, int* endBufPos);
  907. /**
  908. * \brief create a new MmsValue instance from a BER encoded MMS Data element (deserialize) with a defined maximum recursion depth
  909. *
  910. * \param buffer the buffer to read from
  911. * \param bufPos the start position of the mms value data in the buffer
  912. * \param bufferLength the length of the buffer
  913. * \param endBufPos the position in the buffer after the read MMS data element (NULL if not required)
  914. * \param maxDepth the maximum recursion depth
  915. *
  916. * \return the MmsValue instance created from the buffer
  917. */
  918. LIB61850_API MmsValue*
  919. MmsValue_decodeMmsDataMaxRecursion(uint8_t* buffer, int bufPos, int bufferLength, int* endBufPos, int maxDepth);
  920. /**
  921. * \brief Serialize the MmsValue instance as BER encoded MMS Data element
  922. *
  923. * \param self the MmsValue instance
  924. *
  925. * \param buffer the buffer to encode the MMS data element
  926. * \param bufPos the position in the buffer where to start encoding
  927. * \param encode encode to buffer (true) or calculate length only (false)
  928. *
  929. * \return the encoded length of the corresponding MMS data element
  930. */
  931. LIB61850_API int
  932. MmsValue_encodeMmsData(MmsValue* self, uint8_t* buffer, int bufPos, bool encode);
  933. /**
  934. * \brief Get the maximum possible BER encoded size of the MMS data element
  935. *
  936. * \param self the MmsValue instance
  937. *
  938. * \return the maximum encoded size in bytes of the MMS data element
  939. */
  940. LIB61850_API int
  941. MmsValue_getMaxEncodedSize(MmsValue* self);
  942. /**
  943. * \brief Calculate the maximum encoded size of a variable of this type
  944. *
  945. * \param self the MMS variable specification instance
  946. */
  947. LIB61850_API int
  948. MmsVariableSpecification_getMaxEncodedSize(MmsVariableSpecification* self);
  949. /**@}*/
  950. /**@}*/
  951. #ifdef __cplusplus
  952. }
  953. #endif
  954. #endif /* MMS_VALUE_H_ */