iec61850_dynamic_model.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. * dynamic_model.h
  3. *
  4. * Copyright 2014 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 DYNAMIC_MODEL_H_
  24. #define DYNAMIC_MODEL_H_
  25. #include "iec61850_model.h"
  26. #include "iec61850_cdc.h"
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** \addtogroup server_api_group
  31. * @{
  32. */
  33. /**
  34. * @defgroup DYNAMIC_MODEL General dynamic model creation functions
  35. *
  36. * \brief Functions to dynamically create IEC 61850 data models without using SCL or configuration files
  37. *
  38. * @{
  39. */
  40. /**
  41. * \brief create a new IedModel instance
  42. *
  43. * The IedModel object is the root node of an IEC 61850 data model.
  44. *
  45. * \param name the name of the IedModel
  46. *
  47. * \return the new data model instance
  48. */
  49. LIB61850_API IedModel*
  50. IedModel_create(const char* name);
  51. /**
  52. * \brief Set the name of the IED (use only for dynamic model!)
  53. *
  54. * This will change the default name (usually "TEMPLATE") to a user configured values.
  55. * NOTE: This function has to be called before IedServer_create !
  56. * NOTE: For dynamic model (and configuration file date model) this function has to be
  57. * used instead of IedModel_setIedName.
  58. *
  59. * \param model the IedModel instance
  60. * \param the name of the configured IED
  61. */
  62. LIB61850_API void
  63. IedModel_setIedNameForDynamicModel(IedModel* self, const char* name);
  64. /**
  65. * \brief destroy a dynamically created data model
  66. *
  67. * This function will free all the memory allocated for the data model.
  68. *
  69. * NOTE: Do not use this function when using a static data model (static_model.c create by static model generator).
  70. *
  71. * \param model the model instance to destroy
  72. */
  73. LIB61850_API void
  74. IedModel_destroy(IedModel* model);
  75. /**
  76. * \brief Create a new logical device and add it to the IED model
  77. *
  78. * \param name the name of the new logical device
  79. * \param parent the parent IED model
  80. *
  81. * \return the newly created LogicalDevice instance
  82. */
  83. LIB61850_API LogicalDevice*
  84. LogicalDevice_create(const char* name, IedModel* parent);
  85. /**
  86. * \brief Create a new logical device and add it to the IED model
  87. *
  88. * \param name the name of the new logical device
  89. * \param parent the parent IED model
  90. * \param ldName when not NULL functional naming is used for this LD (ldName <= 64 chars)
  91. *
  92. * \return the newly created LogicalDevice instance
  93. */
  94. LIB61850_API LogicalDevice*
  95. LogicalDevice_createEx(const char* inst, IedModel* parent, const char* ldName);
  96. /**
  97. * \brief Create a new logical mode and add it to a logical device
  98. *
  99. * \param name the name of the new logical node
  100. * \param parent the parent logical device
  101. *
  102. * \return the newly created LogicalNode instance
  103. */
  104. LIB61850_API LogicalNode*
  105. LogicalNode_create(const char* name, LogicalDevice* parent);
  106. /**
  107. * \brief create a new data object or array data object and add it to a parent model node
  108. *
  109. * The parent model node has to be of type DataObject or LogicalNode.
  110. *
  111. * NOTE: When the data object is an array the array elements will also be created by this function.
  112. * This will result in child DataObject instances for each array element.
  113. *
  114. * \param name the name of the data object (e.h. "Mod", "Health" ...)
  115. * \param parent the parent model node
  116. * \param arrayElements the number of array elements if the data object is an array or 0
  117. *
  118. * \return the newly create DataObject instance
  119. */
  120. LIB61850_API DataObject*
  121. DataObject_create(const char* name, ModelNode* parent, int arrayElements);
  122. /**
  123. * \brief create a new data attribute and add it to a parent model node
  124. *
  125. * The parent model node has to be of type DataObject or DataAttribute
  126. *
  127. * \param name the name of the data attribute (e.g. "stVal")
  128. * \param parent the parent model node
  129. * \param type the type of the data attribute (CONSTRUCTED if the type contains sub data attributes)
  130. * \param fc the functional constraint (FC) of the data attribute
  131. * \param triggerOptions the trigger options (dupd, dchg, qchg) that cause an event notification
  132. * \param arrayElements the number of array elements if the data attribute is an array or 0
  133. * \param sAddr an optional short address
  134. *
  135. * \return the newly create DataAttribute instance
  136. */
  137. LIB61850_API DataAttribute*
  138. DataAttribute_create(const char* name, ModelNode* parent, DataAttributeType type, FunctionalConstraint fc,
  139. uint8_t triggerOptions, int arrayElements, uint32_t sAddr);
  140. /**
  141. * \brief Get the data type of the data attribute
  142. *
  143. * \param self the data attribute instance
  144. *
  145. * \return the data attribute type
  146. */
  147. LIB61850_API DataAttributeType
  148. DataAttribute_getType(DataAttribute* self);
  149. /**
  150. * \brief Get the functional constraint (FC) of the data attribute
  151. *
  152. * \param self the data attribute instance
  153. *
  154. * \return the functional constraint (FC) of the data attribute
  155. */
  156. LIB61850_API FunctionalConstraint
  157. DataAttribute_getFC(DataAttribute* self);
  158. /**
  159. * \brief Get the trigger options of the data attribute
  160. *
  161. * \param self the data attribute instance
  162. *
  163. * \return the trigger options (dupd, dchg, qchg) that cause an event notification
  164. */
  165. LIB61850_API uint8_t
  166. DataAttribute_getTrgOps(DataAttribute* self);
  167. /**
  168. * \brief Set the value of the data attribute (can be used to set default values before server is created)
  169. *
  170. * \param self the data attribute instance
  171. * \param value the new default value
  172. */
  173. LIB61850_API void
  174. DataAttribute_setValue(DataAttribute* self, MmsValue* value);
  175. /**
  176. * \brief create a new report control block (RCB)
  177. *
  178. * Create a new report control block (RCB) and add it to the given logical node (LN).
  179. *
  180. * \param name name of the RCB relative to the parent LN
  181. * \param parent the parent LN.
  182. * \param rptId of the report. If NULL the default report ID (object reference) is used.
  183. * \param isBuffered true for a buffered RCB - false for unbuffered RCB
  184. * \param dataSetName name (object reference) of the default data set or NULL if no data set
  185. * is set by default
  186. * \param confRef the configuration revision
  187. * \param trgOps the trigger options supported by this RCB (bit set)
  188. * \param options the inclusion options. Specifies what elements are included in a report (bit set)
  189. * \param bufTm the buffering time of the RCB in milliseconds (time between the first event and the preparation of the report).
  190. * \param intgPd integrity period in milliseconds
  191. *
  192. * \return the new RCB instance.
  193. */
  194. LIB61850_API ReportControlBlock*
  195. ReportControlBlock_create(const char* name, LogicalNode* parent, const char* rptId, bool isBuffered, const char*
  196. dataSetName, uint32_t confRef, uint8_t trgOps, uint8_t options, uint32_t bufTm, uint32_t intgPd);
  197. /**
  198. * \brief Set a pre-configured client for the RCB
  199. *
  200. * If set only the pre configured client should use this RCB instance
  201. *
  202. * \param self the RCB instance
  203. * \param clientType the type of the client (0 = no client, 4 = IPv4 client, 6 = IPv6 client)
  204. * \param clientAddress buffer containing the client address (4 byte in case of an IPv4 address, 16 byte in case of an IPv6 address, NULL for no client)
  205. */
  206. LIB61850_API void
  207. ReportControlBlock_setPreconfiguredClient(ReportControlBlock* self, uint8_t clientType, const uint8_t* clientAddress);
  208. /**
  209. * \brief Get the name of the RCB instance
  210. *
  211. * NOTE: the returned string is only valid during the lifetime of the ReportControlBlock instance!
  212. *
  213. * \param self the RCB instance
  214. *
  215. * \return the RCB instance name
  216. */
  217. LIB61850_API const char*
  218. ReportControlBlock_getName(ReportControlBlock* self);
  219. /**
  220. * \brief Is the RCB buffered or unbuffered?
  221. *
  222. * \param self the RCB instance
  223. *
  224. * \return true, in case of a buffered RCB, false otherwise
  225. */
  226. LIB61850_API bool
  227. ReportControlBlock_isBuffered(ReportControlBlock* self);
  228. /**
  229. * \brief Get the parent (LogicalNode) of the RCB instance
  230. *
  231. * \param self the RCB instance
  232. *
  233. * \return the parent (LogicalNode) of the RCB instance
  234. */
  235. LIB61850_API LogicalNode*
  236. ReportControlBlock_getParent(ReportControlBlock* self);
  237. /**
  238. * \brief Get the name of the currently set report ID
  239. *
  240. * \param self the RCB instance
  241. *
  242. * \return a null terminated string containing the current data set name (the string has to be released by the caller!)
  243. */
  244. LIB61850_API char*
  245. ReportControlBlock_getRptID(ReportControlBlock* self);
  246. /**
  247. * \brief Check if RCB instance is enabled
  248. *
  249. * \param self the RCB instance
  250. *
  251. * \return true when the RCB instance is enabled, false otherwise
  252. */
  253. LIB61850_API bool
  254. ReportControlBlock_getRptEna(ReportControlBlock* self);
  255. /**
  256. * \brief Get the name of the currenlty set data set
  257. *
  258. * \param self the RCB instance
  259. *
  260. * \return a null terminated string containing the current data set name (the string has to be released by the caller!)
  261. */
  262. LIB61850_API char*
  263. ReportControlBlock_getDataSet(ReportControlBlock* self);
  264. /**
  265. * \brief Get the confRev value
  266. *
  267. * \param self the RCB instance
  268. *
  269. * \return confRev value
  270. */
  271. LIB61850_API uint32_t
  272. ReportControlBlock_getConfRev(ReportControlBlock* self);
  273. /**
  274. * \brief Get the currently set OptFlds value
  275. *
  276. * The OptField (option field) value is a bit field with the following fields:
  277. * - RPT_OPT_SEQ_NUM
  278. * - RPT_OPT_TIME_STAMP
  279. * - RPT_OPT_REASON_FOR_INCLUSION
  280. * - RPT_OPT_DATA_SET
  281. * - RPT_OPT_DATA_REFERENCE
  282. * - RPT_OPT_BUFFER_OVERFLOW
  283. * - RPT_OPT_ENTRY_ID
  284. * - RPT_OPT_CONF_REV
  285. *
  286. * \param self the RCB instance
  287. *
  288. * \return OptFlds options value
  289. */
  290. LIB61850_API uint32_t
  291. ReportControlBlock_getOptFlds(ReportControlBlock* self);
  292. /**
  293. * \brief Get the BufTm value (buffer time)
  294. *
  295. * The buffer time is the maximum value between an event and
  296. * the actual report generation.
  297. *
  298. * \param self the RCB instance
  299. *
  300. * \return bufTm value
  301. */
  302. LIB61850_API uint32_t
  303. ReportControlBlock_getBufTm(ReportControlBlock* self);
  304. LIB61850_API uint16_t
  305. ReportControlBlock_getSqNum(ReportControlBlock* self);
  306. /**
  307. * \brief Get the currently set trigger options
  308. *
  309. * The trigger option value is a bit field with the following fields:
  310. * - TRG_OPT_DATA_CHANGED
  311. * - TRG_OPT_QUALITY_CHANGED
  312. * - TRG_OPT_DATA_UPDATE
  313. * - TRG_OPT_INTEGRITY
  314. * - TRG_OPT_GI
  315. *
  316. * \param self the RCB instance
  317. *
  318. * \return trigger options value
  319. */
  320. LIB61850_API uint32_t
  321. ReportControlBlock_getTrgOps(ReportControlBlock* self);
  322. LIB61850_API uint32_t
  323. ReportControlBlock_getIntgPd(ReportControlBlock* self);
  324. LIB61850_API bool
  325. ReportControlBlock_getGI(ReportControlBlock* self);
  326. LIB61850_API bool
  327. ReportControlBlock_getPurgeBuf(ReportControlBlock* self);
  328. LIB61850_API MmsValue*
  329. ReportControlBlock_getEntryId(ReportControlBlock* self);
  330. LIB61850_API uint64_t
  331. ReportControlBlock_getTimeofEntry(ReportControlBlock* self);
  332. LIB61850_API int16_t
  333. ReportControlBlock_getResvTms(ReportControlBlock* self);
  334. LIB61850_API bool
  335. ReportControlBlock_getResv(ReportControlBlock* self);
  336. LIB61850_API MmsValue*
  337. ReportControlBlock_getOwner(ReportControlBlock* self);
  338. /**
  339. * \brief create a new log control block (LCB)
  340. *
  341. * Create a new log control block (LCB) and add it to the given logical node (LN).
  342. *
  343. * \param name name of the LCB relative to the parent LN
  344. * \param parent the parent LN.
  345. * \param dataSetName name (object reference) of the default data set or NULL if no data set
  346. * is set by default
  347. * \param logRef name (object reference) of the default log or NULL if no log is set by default. THe LDname doesn't contain the IED name!
  348. * \param trgOps the trigger options supported by this LCB (bit set)
  349. * \param intgPd integrity period in milliseconds
  350. * \param logEna if true the log will be enabled by default, false otherwise
  351. * \param reasonCode if true the reasonCode will be included in the log (this is always true in MMS mapping)
  352. *
  353. * \return the new LCB instance
  354. */
  355. LIB61850_API LogControlBlock*
  356. LogControlBlock_create(const char* name, LogicalNode* parent, const char* dataSetName, const char* logRef, uint8_t trgOps,
  357. uint32_t intgPd, bool logEna, bool reasonCode);
  358. LIB61850_API const char*
  359. LogControlBlock_getName(LogControlBlock* self);
  360. LIB61850_API LogicalNode*
  361. LogControlBlock_getParent(LogControlBlock* self);
  362. /**
  363. * \brief create a log (used by the IEC 61850 log service)
  364. *
  365. * \param name name of the LOG relative to the parent LN
  366. * \param parent the parent LN
  367. *
  368. * \return the new LOG instance
  369. */
  370. LIB61850_API Log*
  371. Log_create(const char* name, LogicalNode* parent);
  372. /**
  373. * \brief create a setting group control block (SGCB)
  374. *
  375. * Create a new setting group control block (SGCB) and add it to the given logical node (LN).
  376. *
  377. * \param parent the parent LN.
  378. * \param the active setting group on server startup (1..N)
  379. * \param the number of setting groups (N)
  380. *
  381. * \return the new SGCB instance
  382. */
  383. LIB61850_API SettingGroupControlBlock*
  384. SettingGroupControlBlock_create(LogicalNode* parent, uint8_t actSG, uint8_t numOfSGs);
  385. /**
  386. * \brief create a new GSE/GOOSE control block (GoCB)
  387. *
  388. * Create a new GOOSE control block (GoCB) and add it to the given logical node (LN)
  389. *
  390. * \param name name of the GoCB relative to the parent LN
  391. * \param parent the parent LN
  392. * \param appId the application ID of the GoCB
  393. * \param dataSet the data set reference to be used by the GoCB
  394. * \param confRev the configuration revision
  395. * \param fixedOffs indicates if GOOSE publisher shall use fixed offsets (NOT YET SUPPORTED)
  396. * \param minTime minimum GOOSE retransmission time (-1 if not specified - uses stack default then)
  397. * \param maxTime GOOSE retransmission time in stable state (-1 if not specified - uses stack default then)
  398. *
  399. * \return the new GoCB instance
  400. */
  401. LIB61850_API GSEControlBlock*
  402. GSEControlBlock_create(const char* name, LogicalNode* parent, const char* appId, const char* dataSet, uint32_t confRev,
  403. bool fixedOffs, int minTime, int maxTime);
  404. /**
  405. * \brief create a new Multicast/Unicast Sampled Value (SV) control block (SvCB)
  406. *
  407. * Create a new Sampled Value control block (SvCB) and add it to the given logical node (LN)
  408. *
  409. * \param name name of the SvCB relative to the parent LN
  410. * \param parent the parent LN
  411. * \param svID the application ID of the SvCB
  412. * \param dataSet the data set reference to be used by the SVCB
  413. * \param confRev the configuration revision
  414. * \param smpMod the sampling mode used
  415. * \param smpRate the sampling rate used
  416. * \param optFlds the optional element configuration
  417. *
  418. * \return the new SvCB instance
  419. */
  420. LIB61850_API SVControlBlock*
  421. SVControlBlock_create(const char* name, LogicalNode* parent, const char* svID, const char* dataSet, uint32_t confRev, uint8_t smpMod,
  422. uint16_t smpRate, uint8_t optFlds, bool isUnicast);
  423. LIB61850_API void
  424. SVControlBlock_addPhyComAddress(SVControlBlock* self, PhyComAddress* phyComAddress);
  425. LIB61850_API void
  426. GSEControlBlock_addPhyComAddress(GSEControlBlock* self, PhyComAddress* phyComAddress);
  427. /**
  428. * \brief create a PhyComAddress object
  429. *
  430. * A PhyComAddress object contains all required addressing information for a GOOSE publisher.
  431. *
  432. * \param vlanPriority the priority field of the VLAN tag
  433. * \param vlanId the ID field of the VLAN tag
  434. * \param appId the application identifier
  435. * \param dstAddress the 6 byte multicast MAC address to specify the destination
  436. *
  437. * \return the new PhyComAddress object
  438. */
  439. LIB61850_API PhyComAddress*
  440. PhyComAddress_create(uint8_t vlanPriority, uint16_t vlanId, uint16_t appId, uint8_t dstAddress[]);
  441. /**
  442. * \brief create a new data set
  443. *
  444. * \param name the name of the data set
  445. * \param parent the logical node that hosts the data set (typically a LLN0)
  446. *
  447. * \return the new data set instance
  448. */
  449. LIB61850_API DataSet*
  450. DataSet_create(const char* name, LogicalNode* parent);
  451. /**
  452. * \brief Get the name of the data set
  453. *
  454. * \param self the instance of the data set
  455. *
  456. * \returns the name of the data set (not the object reference).
  457. */
  458. LIB61850_API const char*
  459. DataSet_getName(DataSet* self);
  460. /**
  461. * \brief returns the number of elements (entries) of the data set
  462. *
  463. * \param self the instance of the data set
  464. *
  465. * \returns the number of data set elements
  466. */
  467. LIB61850_API int
  468. DataSet_getSize(DataSet* self);
  469. LIB61850_API DataSetEntry*
  470. DataSet_getFirstEntry(DataSet* self);
  471. LIB61850_API DataSetEntry*
  472. DataSetEntry_getNext(DataSetEntry* self);
  473. /**
  474. * \brief create a new data set entry (FCDA)
  475. *
  476. * Create a new FCDA reference and add it to the given data set as a new data set member.
  477. *
  478. * Note: Be aware that data set entries are not IEC 61850 object reference but MMS variable names
  479. * that have to contain the LN name, the FC and subsequent path elements separated by "$" instead of ".".
  480. * This is due to efficiency reasons to avoid the creation of additional strings.
  481. *
  482. * If the variable parameter does not contain a logical device name (separated from the remaining variable
  483. * name by the "/" character) the logical device where the data set resides is used automatically.
  484. *
  485. * \param dataSet the data set to which the new entry will be added
  486. * \param variable the name of the variable as MMS variable name including FC ("$" used as separator!)
  487. * \param index the index if the FCDA is an array element, otherwise -1
  488. * \param component the name of the component of the variable if the FCDA is a sub element of an array
  489. * element. If this is not the case then NULL should be given here.
  490. *
  491. * \return the new data set entry instance
  492. */
  493. LIB61850_API DataSetEntry*
  494. DataSetEntry_create(DataSet* dataSet, const char* variable, int index, const char* component);
  495. /**@}*/
  496. /**@}*/
  497. #ifdef __cplusplus
  498. }
  499. #endif
  500. #endif /* DYNAMIC_MODEL_H_ */