iec61850_dynamic_model.h 15 KB

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