sv_publisher.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. * sv_publisher.h
  3. *
  4. * Copyright 2016-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 LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_
  24. #define LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_
  25. #include "iec61850_common.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifndef GOOSE_SV_COMM_PARAMETERS
  30. #define GOOSE_SV_COMM_PARAMETERS
  31. typedef struct sCommParameters {
  32. uint8_t vlanPriority;
  33. uint16_t vlanId;
  34. uint16_t appId;
  35. uint8_t dstAddress[6];
  36. } CommParameters;
  37. #endif
  38. /**
  39. * \defgroup sv_publisher_api_group IEC 61850 Sampled Values (SV) publisher API
  40. */
  41. /**@{*/
  42. #define IEC61850_SV_SMPSYNC_NOT_SYNCHRONIZED 0
  43. #define IEC61850_SV_SMPSYNC_SYNCED_UNSPEC_LOCAL_CLOCK 1
  44. #define IEC61850_SV_SMPSYNC_SYNCED_GLOBAL_CLOCK 2
  45. #define IEC61850_SV_SMPMOD_PER_NOMINAL_PERIOD 0
  46. #define IEC61850_SV_SMPMOD_SAMPLES_PER_SECOND 1
  47. #define IEC61850_SV_SMPMOD_SECONDS_PER_SAMPLE 2
  48. /**
  49. * \brief An opaque type representing an IEC 61850-9-2 Sampled Values publisher.
  50. */
  51. typedef struct sSVPublisher* SVPublisher;
  52. /**
  53. * \brief An opaque type representing an IEC 61850-9-2 Sampled Values Application Service Data Unit (ASDU).
  54. */
  55. typedef struct sSVPublisher_ASDU* SVPublisher_ASDU;
  56. /**
  57. * \brief Create a new IEC61850-9-2 Sampled Values publisher.
  58. *
  59. * NOTE: VLAN tagging is enabled when calling this constructor. To disable VLAN tagging
  60. * use \ref SVPublisher_createEx instead.
  61. *
  62. * \param[in] interfaceId the name of the interface over which the SV publisher should send SV packets.
  63. * \param[in] parameters optional parameters for setting VLAN options and destination MAC address. Use NULL for default values.
  64. * \return the new SV publisher instance.
  65. */
  66. LIB61850_API SVPublisher
  67. SVPublisher_create(CommParameters* parameters, const char* interfaceId);
  68. /**
  69. * \brief Create a new IEC61850-9-2 Sampled Values publisher.
  70. *
  71. * \param[in] interfaceId the name of the interface over which the SV publisher should send SV packets.
  72. * \param[in] parameters optional parameters for setting VLAN options and destination MAC address. Use NULL for default values.
  73. * \param[in] useVlanTags enable(true)/disable(false) VLAN tagging
  74. * \return the new SV publisher instance.
  75. */
  76. LIB61850_API SVPublisher
  77. SVPublisher_createEx(CommParameters* parameters, const char* interfaceId, bool useVlanTag);
  78. /**
  79. * \brief Create an Application Service Data Unit (ASDU) and add it to an existing Sampled Values publisher.
  80. *
  81. * \param[in] svID
  82. * \param[in] datset
  83. * \param[in] confRev Configuration revision number. Should be incremented each time that the configuration of the logical device changes.
  84. * \return the new ASDU instance.
  85. */
  86. LIB61850_API SVPublisher_ASDU
  87. SVPublisher_addASDU(SVPublisher self, const char* svID, const char* datset, uint32_t confRev);
  88. /**
  89. * \brief Prepare the publisher for publishing.
  90. *
  91. * This method must be called before SVPublisher_publish().
  92. *
  93. * \param[in] self the Sampled Values publisher instance.
  94. */
  95. LIB61850_API void
  96. SVPublisher_setupComplete(SVPublisher self);
  97. /**
  98. * \brief Publish all registered ASDUs
  99. *
  100. * \param[in] self the Sampled Values publisher instance.
  101. */
  102. LIB61850_API void
  103. SVPublisher_publish(SVPublisher self);
  104. /**
  105. * \brief Destroy an IEC61850-9-2 Sampled Values instance.
  106. *
  107. * \param[in] self the Sampled Values publisher instance.
  108. */
  109. LIB61850_API void
  110. SVPublisher_destroy(SVPublisher self);
  111. /**
  112. * \addtogroup sv_publisher_asdu_group Values Application Service Data Unit (ASDU)
  113. * @{
  114. */
  115. /**
  116. * \brief Reset the internal data buffer of an ASDU.
  117. *
  118. * All data elements added by SVPublisher_ASDU_add*() functions are removed.
  119. * SVPublisher_setupComplete() must be called afterwards.
  120. *
  121. * \param[in] self the Sampled Values ASDU instance.
  122. */
  123. LIB61850_API void
  124. SVPublisher_ASDU_resetBuffer(SVPublisher_ASDU self);
  125. /**
  126. * \brief Reserve memory for a signed 8-bit integer in the ASDU.
  127. *
  128. * \param[in] self the Sampled Values ASDU instance.
  129. * \return the offset in bytes within the ASDU data block.
  130. */
  131. LIB61850_API int
  132. SVPublisher_ASDU_addINT8(SVPublisher_ASDU self);
  133. /**
  134. * \brief Set the value of a 8-bit integer in the ASDU.
  135. *
  136. * \param[in] self the Sampled Values ASDU instance.
  137. * \param[in] index The offset within the data block of the ASDU in bytes.
  138. * \param[in] value The value which should be set.
  139. */
  140. LIB61850_API void
  141. SVPublisher_ASDU_setINT8(SVPublisher_ASDU self, int index, int8_t value);
  142. /**
  143. * \brief Reserve memory for a signed 32-bit integer in the ASDU.
  144. *
  145. * \param[in] self the Sampled Values ASDU instance.
  146. * \return the offset in bytes within the ASDU data block.
  147. */
  148. LIB61850_API int
  149. SVPublisher_ASDU_addINT32(SVPublisher_ASDU self);
  150. /**
  151. * \brief Set the value of a 32-bit integer in the ASDU.
  152. *
  153. * \param[in] self the Sampled Values ASDU instance.
  154. * \param[in] index The offset within the data block of the ASDU in bytes.
  155. * \param[in] value The value which should be set.
  156. */
  157. LIB61850_API void
  158. SVPublisher_ASDU_setINT32(SVPublisher_ASDU self, int index, int32_t value);
  159. /**
  160. * \brief Reserve memory for a signed 64-bit integer in the ASDU.
  161. *
  162. * \param[in] self the Sampled Values ASDU instance.
  163. * \return the offset in bytes of the new element within the ASDU data block.
  164. */
  165. LIB61850_API int
  166. SVPublisher_ASDU_addINT64(SVPublisher_ASDU self);
  167. /**
  168. * \brief Set the value of a 64-bit integer in the ASDU.
  169. *
  170. * \param[in] self the Sampled Values ASDU instance.
  171. * \param[in] index The offset within the data block of the ASDU in bytes.
  172. * \param[in] value The value which should be set.
  173. */
  174. LIB61850_API void
  175. SVPublisher_ASDU_setINT64(SVPublisher_ASDU self, int index, int64_t value);
  176. /**
  177. * \brief Reserve memory for a single precision floating point number in the ASDU.
  178. *
  179. * \param[in] self the Sampled Values ASDU instance.
  180. * \return the offset in bytes of the new element within the ASDU data block.
  181. */
  182. LIB61850_API int
  183. SVPublisher_ASDU_addFLOAT(SVPublisher_ASDU self);
  184. /**
  185. * \brief Set the value of a single precision floating point number in the ASDU.
  186. *
  187. * \param[in] self the Sampled Values ASDU instance.
  188. * \param[in] index The offset within the data block of the ASDU in bytes.
  189. * \param[in] value The value which should be set.
  190. */
  191. LIB61850_API void
  192. SVPublisher_ASDU_setFLOAT(SVPublisher_ASDU self, int index, float value);
  193. /**
  194. * \brief Reserve memory for a double precision floating point number in the ASDU.
  195. *
  196. * \param[in] self the Sampled Values ASDU instance.
  197. * \return the offset in bytes of the new element within the ASDU data block.
  198. */
  199. LIB61850_API int
  200. SVPublisher_ASDU_addFLOAT64(SVPublisher_ASDU self);
  201. /**
  202. * \brief Set the value of a double precision floating pointer number in the ASDU.
  203. *
  204. * \param[in] self the Sampled Values ASDU instance.
  205. * \param[in] index The offset within the data block of the ASDU in bytes.
  206. * \param[in] value The value which should be set.
  207. */
  208. LIB61850_API void
  209. SVPublisher_ASDU_setFLOAT64(SVPublisher_ASDU self, int index, double value);
  210. /**
  211. * \brief Reserve memory for a 64 bit time stamp in the ASDU
  212. *
  213. * \param[in] self the Sampled Values ASDU instance.
  214. * \return the offset in bytes of the new element within the ASDU data block.
  215. */
  216. LIB61850_API int
  217. SVPublisher_ASDU_addTimestamp(SVPublisher_ASDU self);
  218. /**
  219. * \brief Set the value of a 64 bit time stamp in the ASDU.
  220. *
  221. * \param[in] self the Sampled Values ASDU instance.
  222. * \param[in] index The offset within the data block of the ASDU in bytes.
  223. * \param[in] value The value which should be set.
  224. */
  225. LIB61850_API void
  226. SVPublisher_ASDU_setTimestamp(SVPublisher_ASDU self, int index, Timestamp value);
  227. /**
  228. * \brief Reserve memory for a quality value in the ASDU
  229. *
  230. * NOTE: Quality is encoded as BITSTRING (4 byte)
  231. *
  232. * \param[in] self the Sampled Values ASDU instance.
  233. * \return the offset in bytes of the new element within the ASDU data block.
  234. */
  235. LIB61850_API int
  236. SVPublisher_ASDU_addQuality(SVPublisher_ASDU self);
  237. /**
  238. * \brief Set the value of a quality attribute in the ASDU.
  239. *
  240. * \param[in] self the Sampled Values ASDU instance.
  241. * \param[in] index The offset within the data block of the ASDU in bytes.
  242. * \param[in] value The value which should be set.
  243. */
  244. LIB61850_API void
  245. SVPublisher_ASDU_setQuality(SVPublisher_ASDU self, int index, Quality value);
  246. /**
  247. * \brief Set the sample count attribute of the ASDU.
  248. *
  249. * \param[in] self the Sampled Values ASDU instance.
  250. * \param[in] value the new value of the attribute.
  251. */
  252. LIB61850_API void
  253. SVPublisher_ASDU_setSmpCnt(SVPublisher_ASDU self, uint16_t value);
  254. /**
  255. * \brief Get the sample count attribute of the ASDU.
  256. *
  257. * \param[in] self the Sampled Values ASDU instance.
  258. */
  259. LIB61850_API uint16_t
  260. SVPublisher_ASDU_getSmpCnt(SVPublisher_ASDU self);
  261. /**
  262. * \brief Increment the sample count attribute of the ASDU.
  263. *
  264. * The parameter SmpCnt shall contain the values of a counter, which is incremented each time a new sample of the analogue value is taken.
  265. * The sample values shall be kept in the right order.
  266. * If the counter is used to indicate time consistency of various sampled values, the counter shall be reset by an external synchronization event.
  267. *
  268. * \param[in] self the Sampled Values ASDU instance.
  269. */
  270. LIB61850_API void
  271. SVPublisher_ASDU_increaseSmpCnt(SVPublisher_ASDU self);
  272. /**
  273. * \brief Set the roll-over (wrap) limit for the sample counter. When reaching the limit the
  274. * sample counter will be reset to 0 (default is no limit)
  275. *
  276. * \param[in] self the Sampled Values ASDU instance.
  277. * \param[in] value the new sample counter limit
  278. */
  279. LIB61850_API void
  280. SVPublisher_ASDU_setSmpCntWrap(SVPublisher_ASDU self, uint16_t value);
  281. /**
  282. * \brief Enables the transmission of refresh time attribute of the ASDU
  283. *
  284. * The refresh time is the time when the data in put into the sampled values buffer
  285. *
  286. * \param[in] self the Sampled Values ASDU instance.
  287. */
  288. LIB61850_API void
  289. SVPublisher_ASDU_enableRefrTm(SVPublisher_ASDU self);
  290. /**
  291. * \brief Set the refresh time attribute of the ASDU with nanosecond resolution
  292. *
  293. * \param[in] self the Sampled Values ASDU instance.
  294. * \param[in] refrTmNs the refresh time value with nanoseconds resolution.
  295. */
  296. LIB61850_API void
  297. SVPublisher_ASDU_setRefrTmNs(SVPublisher_ASDU self, nsSinceEpoch refrTmNs);
  298. /**
  299. * \brief Set the refresh time attribute of the ASDU with millisecond resolution
  300. *
  301. * \param[in] self the Sampled Values ASDU instance.
  302. * \param[in] refrTmNs the refresh time value with with milliseconds resolution.
  303. */
  304. LIB61850_API void
  305. SVPublisher_ASDU_setRefrTm(SVPublisher_ASDU self, msSinceEpoch refrTm);
  306. /**
  307. * \brief Set the refresh time attribute of the ASDU
  308. *
  309. * NOTE: Using this function you can control the time quality flags and the
  310. * sub second precision (number of valid bits) of the RefrTm value.
  311. *
  312. * \param[in] self the Sampled Values ASDU instance.
  313. * \param[in] refrTm the refresh time value
  314. */
  315. LIB61850_API void
  316. SVPublisher_ASDU_setRefrTmByTimestamp(SVPublisher_ASDU self, Timestamp* refrTm);
  317. /**
  318. * \brief Set the sample mode attribute of the ASDU.
  319. *
  320. * The attribute SmpMod shall specify if the sample rate is defined in units of samples per nominal period, samples per second or seconds per sample.
  321. * If it is missing, the default value is samples per period.
  322. *
  323. * NOTE: Function has to be called before calling \ref SVPublisher_setupComplete
  324. *
  325. * \param[in] self the Sampled Values ASDU instance.
  326. * \param[in] smpMod one of IEC61850_SV_SMPMOD_PER_NOMINAL_PERIOD, IEC61850_SV_SMPMOD_SAMPLES_PER_SECOND or IEC61850_SV_SMPMOD_SECONDS_PER_SAMPLE
  327. */
  328. LIB61850_API void
  329. SVPublisher_ASDU_setSmpMod(SVPublisher_ASDU self, uint8_t smpMod);
  330. /**
  331. * \brief Set the sample rate attribute of the ASDU.
  332. *
  333. * The attribute SmpRate shall specify the sample rate.
  334. * The value shall be interpreted depending on the value of the SmpMod attribute.
  335. *
  336. * NOTE: Function has to be called before calling \ref SVPublisher_setupComplete
  337. *
  338. * \param[in] self the Sampled Values ASDU instance.
  339. * \param[in] smpRate Amount of samples (default per nominal period, see SmpMod).
  340. */
  341. LIB61850_API void
  342. SVPublisher_ASDU_setSmpRate(SVPublisher_ASDU self, uint16_t smpRate);
  343. /**
  344. * \brief Set the clock synchronization information
  345. *
  346. * Default value is not synchronized (0).
  347. * Possible values are:
  348. * 0 = SV are not synchronized by an external clock signal.
  349. * 1 = SV are synchronized by a clock signal from an unspecified local area clock.
  350. * 2 = SV are synchronized by a global area clock signal (time traceable).
  351. * 5 to 254 = SV are synchronized by a clock signal from a local area clock identified by this value.
  352. * 3;4;255 = Reserved values – Do not use.
  353. *
  354. * \param[in] self the Sampled Values ASDU instance.
  355. * \param[in] smpSynch the clock synchronization state
  356. */
  357. LIB61850_API void
  358. SVPublisher_ASDU_setSmpSynch(SVPublisher_ASDU self, uint16_t smpSynch);
  359. /**@} @}*/
  360. #ifndef DEPRECATED
  361. #if defined(__GNUC__) || defined(__clang__)
  362. #define DEPRECATED __attribute__((deprecated))
  363. #else
  364. #define DEPRECATED
  365. #endif
  366. #endif
  367. /**
  368. * \addtogroup sv_publisher_deprecated_api_group Deprecated API
  369. * \ingroup sv_publisher_api_group IEC 61850 Sampled Values (SV) publisher API
  370. * \deprecated
  371. * @{
  372. */
  373. typedef struct sSVPublisher* SampledValuesPublisher;
  374. typedef struct sSV_ASDU* SV_ASDU;
  375. LIB61850_API DEPRECATED SVPublisher
  376. SampledValuesPublisher_create(CommParameters* parameters, const char* interfaceId);
  377. LIB61850_API DEPRECATED SVPublisher_ASDU
  378. SampledValuesPublisher_addASDU(SVPublisher self, char* svID, char* datset, uint32_t confRev);
  379. LIB61850_API DEPRECATED void
  380. SampledValuesPublisher_setupComplete(SVPublisher self);
  381. LIB61850_API DEPRECATED void
  382. SampledValuesPublisher_publish(SVPublisher self);
  383. LIB61850_API DEPRECATED void
  384. SampledValuesPublisher_destroy(SVPublisher self);
  385. LIB61850_API DEPRECATED void
  386. SV_ASDU_resetBuffer(SVPublisher_ASDU self);
  387. LIB61850_API DEPRECATED int
  388. SV_ASDU_addINT8(SVPublisher_ASDU self);
  389. LIB61850_API DEPRECATED void
  390. SV_ASDU_setINT8(SVPublisher_ASDU self, int index, int8_t value);
  391. LIB61850_API DEPRECATED int
  392. SV_ASDU_addINT32(SVPublisher_ASDU self);
  393. LIB61850_API DEPRECATED void
  394. SV_ASDU_setINT32(SVPublisher_ASDU self, int index, int32_t value);
  395. LIB61850_API DEPRECATED int
  396. SV_ASDU_addINT64(SVPublisher_ASDU self);
  397. LIB61850_API DEPRECATED void
  398. SV_ASDU_setINT64(SVPublisher_ASDU self, int index, int64_t value);
  399. LIB61850_API DEPRECATED int
  400. SV_ASDU_addFLOAT(SVPublisher_ASDU self);
  401. LIB61850_API DEPRECATED void
  402. SV_ASDU_setFLOAT(SVPublisher_ASDU self, int index, float value);
  403. LIB61850_API DEPRECATED int
  404. SV_ASDU_addFLOAT64(SVPublisher_ASDU self);
  405. LIB61850_API DEPRECATED void
  406. SV_ASDU_setFLOAT64(SVPublisher_ASDU self, int index, double value);
  407. LIB61850_API DEPRECATED void
  408. SV_ASDU_setSmpCnt(SVPublisher_ASDU self, uint16_t value);
  409. LIB61850_API DEPRECATED uint16_t
  410. SV_ASDU_getSmpCnt(SVPublisher_ASDU self);
  411. LIB61850_API DEPRECATED void
  412. SV_ASDU_increaseSmpCnt(SVPublisher_ASDU self);
  413. LIB61850_API DEPRECATED void
  414. SV_ASDU_setRefrTm(SVPublisher_ASDU self, uint64_t refrTm);
  415. LIB61850_API DEPRECATED void
  416. SV_ASDU_setSmpMod(SVPublisher_ASDU self, uint8_t smpMod);
  417. LIB61850_API DEPRECATED void
  418. SV_ASDU_setSmpRate(SVPublisher_ASDU self, uint16_t smpRate);
  419. /**@}*/
  420. #ifdef __cplusplus
  421. }
  422. #endif
  423. #endif /* LIBIEC61850_SRC_SAMPLED_VALUES_SV_PUBLISHER_H_ */