ua_application.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "ua_application.h"
  2. #include "ua_namespace.h"
  3. #include "ua_services_internal.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. UA_indexedList_List nsMockup;
  7. Application appMockup = {
  8. ( UA_ApplicationDescription*) UA_NULL,
  9. &nsMockup
  10. };
  11. UA_Node* create_node_ns0(UA_Int32 class, UA_Int32 nodeClass, UA_Int32 const id, char const * qn, char const * dn, char const * desc) {
  12. UA_Node* n; UA_.types[class].new((void **)&n);
  13. n->nodeId.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  14. n->nodeId.namespace = 0;
  15. n->nodeId.identifier.numeric = id;
  16. UA_String_copycstring(qn,&(n->browseName.name));
  17. UA_String_copycstring(dn,&n->displayName.text);
  18. UA_String_copycstring(desc,&n->description.text);
  19. n->nodeClass = nodeClass;
  20. return n;
  21. }
  22. void appMockup_init() {
  23. // create namespaces
  24. // TODO: A table that maps the namespaceUris to Ids
  25. Namespace* ns0;
  26. Namespace_new(&ns0, 100, 0); //C2UA_STRING("http://opcfoundation.org/UA/"));
  27. Namespace* local;
  28. Namespace_new(&local, 100, 1); //C2UA_STRING("http://localhost:16664/open62541/"));
  29. // add to list of namespaces
  30. UA_indexedList_init(appMockup.namespaces);
  31. UA_indexedList_addValueToFront(appMockup.namespaces,0,ns0);
  32. UA_indexedList_addValueToFront(appMockup.namespaces,1,local);
  33. /**************/
  34. /* References */
  35. /**************/
  36. // ReferenceType Ids
  37. UA_NodeId RefTypeId_References = NS0NODEID(31);
  38. UA_NodeId RefTypeId_NonHierarchicalReferences = NS0NODEID(32);
  39. UA_NodeId RefTypeId_HierarchicalReferences = NS0NODEID(33);
  40. UA_NodeId RefTypeId_HasChild = NS0NODEID(34);
  41. UA_NodeId RefTypeId_Organizes = NS0NODEID(35);
  42. UA_NodeId RefTypeId_HasEventSource = NS0NODEID(36);
  43. UA_NodeId RefTypeId_HasModellingRule = NS0NODEID(37);
  44. UA_NodeId RefTypeId_HasEncoding = NS0NODEID(38);
  45. UA_NodeId RefTypeId_HasDescription = NS0NODEID(39);
  46. UA_NodeId RefTypeId_HasTypeDefinition = NS0NODEID(40);
  47. UA_NodeId RefTypeId_GeneratesEvent = NS0NODEID(41);
  48. UA_NodeId RefTypeId_Aggregates = NS0NODEID(44);
  49. UA_NodeId RefTypeId_HasSubtype = NS0NODEID(45);
  50. UA_NodeId RefTypeId_HasProperty = NS0NODEID(46);
  51. UA_NodeId RefTypeId_HasComponent = NS0NODEID(47);
  52. UA_NodeId RefTypeId_HasNotifier = NS0NODEID(48);
  53. UA_NodeId RefTypeId_HasOrderedComponent = NS0NODEID(49);
  54. UA_NodeId RefTypeId_HasModelParent = NS0NODEID(50);
  55. UA_NodeId RefTypeId_FromState = NS0NODEID(51);
  56. UA_NodeId RefTypeId_ToState = NS0NODEID(52);
  57. UA_NodeId RefTypeId_HasCause = NS0NODEID(53);
  58. UA_NodeId RefTypeId_HasEffect = NS0NODEID(54);
  59. UA_NodeId RefTypeId_HasHistoricalConfiguration = NS0NODEID(56);
  60. UA_ReferenceTypeNode *references;
  61. UA_ReferenceTypeNode_new(&references);
  62. references->nodeId = RefTypeId_References;
  63. references->nodeClass = UA_NODECLASS_REFERENCETYPE;
  64. references->browseName = UA_QUALIFIEDNAME_STATIC("References");
  65. references->displayName = UA_LOCALIZEDTEXT_STATIC("References");
  66. references->description = UA_LOCALIZEDTEXT_STATIC("References");
  67. references->isAbstract = UA_TRUE;
  68. references->symmetric = UA_TRUE;
  69. Namespace_insert(ns0,(UA_Node*)references);
  70. UA_ReferenceTypeNode *hierarchicalreferences;
  71. UA_ReferenceTypeNode_new(&hierarchicalreferences);
  72. hierarchicalreferences->nodeId = RefTypeId_HierarchicalReferences;
  73. hierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  74. hierarchicalreferences->browseName = UA_QUALIFIEDNAME_STATIC("HierarchicalReferences");
  75. hierarchicalreferences->displayName = UA_LOCALIZEDTEXT_STATIC("HierarchicalReferences");
  76. hierarchicalreferences->description = UA_LOCALIZEDTEXT_STATIC("HierarchicalReferences");
  77. hierarchicalreferences->isAbstract = UA_TRUE;
  78. hierarchicalreferences->symmetric = UA_FALSE;
  79. AddReference((UA_Node*)hierarchicalreferences, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  80. (UA_ExpandedNodeId){RefTypeId_References, UA_STRING_NULL, 0}}, ns0);
  81. Namespace_insert(ns0,(UA_Node*)hierarchicalreferences);
  82. UA_ReferenceTypeNode *nonhierarchicalreferences;
  83. UA_ReferenceTypeNode_new(&nonhierarchicalreferences);
  84. nonhierarchicalreferences->nodeId = RefTypeId_NonHierarchicalReferences;
  85. nonhierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
  86. nonhierarchicalreferences->browseName = UA_QUALIFIEDNAME_STATIC("NonHierarchicalReferences");
  87. nonhierarchicalreferences->displayName = UA_LOCALIZEDTEXT_STATIC("NonHierarchicalReferences");
  88. nonhierarchicalreferences->description = UA_LOCALIZEDTEXT_STATIC("NonHierarchicalReferences");
  89. nonhierarchicalreferences->isAbstract = UA_TRUE;
  90. nonhierarchicalreferences->symmetric = UA_FALSE;
  91. AddReference((UA_Node*)nonhierarchicalreferences, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  92. (UA_ExpandedNodeId){RefTypeId_References, UA_STRING_NULL, 0}}, ns0);
  93. Namespace_insert(ns0,(UA_Node*)nonhierarchicalreferences);
  94. UA_ReferenceTypeNode *haschild;
  95. UA_ReferenceTypeNode_new(&haschild);
  96. haschild->nodeId = RefTypeId_HasChild;
  97. haschild->nodeClass = UA_NODECLASS_REFERENCETYPE;
  98. haschild->browseName = UA_QUALIFIEDNAME_STATIC("HasChild");
  99. haschild->displayName = UA_LOCALIZEDTEXT_STATIC("HasChild");
  100. haschild->description = UA_LOCALIZEDTEXT_STATIC("HasChild");
  101. haschild->isAbstract = UA_TRUE;
  102. haschild->symmetric = UA_FALSE;
  103. AddReference((UA_Node*)haschild, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  104. (UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  105. Namespace_insert(ns0,(UA_Node*)haschild);
  106. UA_ReferenceTypeNode *organizes;
  107. UA_ReferenceTypeNode_new(&organizes);
  108. organizes->nodeId = RefTypeId_Organizes;
  109. organizes->nodeClass = UA_NODECLASS_REFERENCETYPE;
  110. organizes->browseName = UA_QUALIFIEDNAME_STATIC("Organizes");
  111. organizes->displayName = UA_LOCALIZEDTEXT_STATIC("Organizes");
  112. organizes->description = UA_LOCALIZEDTEXT_STATIC("Organizes");
  113. organizes->isAbstract = UA_FALSE;
  114. organizes->symmetric = UA_FALSE;
  115. organizes->inverseName = UA_LOCALIZEDTEXT_STATIC("OrganizedBy");
  116. AddReference((UA_Node*)organizes, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  117. (UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  118. Namespace_insert(ns0,(UA_Node*)organizes);
  119. UA_ReferenceTypeNode *haseventsource;
  120. UA_ReferenceTypeNode_new(&haseventsource);
  121. haseventsource->nodeId = RefTypeId_HasEventSource;
  122. haseventsource->nodeClass = UA_NODECLASS_REFERENCETYPE;
  123. haseventsource->browseName = UA_QUALIFIEDNAME_STATIC("HasEventSource");
  124. haseventsource->displayName = UA_LOCALIZEDTEXT_STATIC("HasEventSource");
  125. haseventsource->description = UA_LOCALIZEDTEXT_STATIC("HasEventSource");
  126. haseventsource->isAbstract = UA_FALSE;
  127. haseventsource->symmetric = UA_FALSE;
  128. haseventsource->inverseName = UA_LOCALIZEDTEXT_STATIC("EventSourceOf");
  129. AddReference((UA_Node*)haseventsource, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  130. (UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  131. Namespace_insert(ns0,(UA_Node*)haseventsource);
  132. UA_ReferenceTypeNode *hasmodellingrule;
  133. UA_ReferenceTypeNode_new(&hasmodellingrule);
  134. hasmodellingrule->nodeId = RefTypeId_HasModellingRule;
  135. hasmodellingrule->nodeClass = UA_NODECLASS_REFERENCETYPE;
  136. hasmodellingrule->browseName = UA_QUALIFIEDNAME_STATIC("HasModellingRule");
  137. hasmodellingrule->displayName = UA_LOCALIZEDTEXT_STATIC("HasModellingRule");
  138. hasmodellingrule->description = UA_LOCALIZEDTEXT_STATIC("HasModellingRule");
  139. hasmodellingrule->isAbstract = UA_FALSE;
  140. hasmodellingrule->symmetric = UA_FALSE;
  141. hasmodellingrule->inverseName = UA_LOCALIZEDTEXT_STATIC("ModellingRuleOf");
  142. AddReference((UA_Node*)hasmodellingrule, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  143. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  144. Namespace_insert(ns0,(UA_Node*)hasmodellingrule);
  145. UA_ReferenceTypeNode *hasencoding;
  146. UA_ReferenceTypeNode_new(&hasencoding);
  147. hasencoding->nodeId = RefTypeId_HasEncoding;
  148. hasencoding->nodeClass = UA_NODECLASS_REFERENCETYPE;
  149. hasencoding->browseName = UA_QUALIFIEDNAME_STATIC("HasEncoding");
  150. hasencoding->displayName = UA_LOCALIZEDTEXT_STATIC("HasEncoding");
  151. hasencoding->description = UA_LOCALIZEDTEXT_STATIC("HasEncoding");
  152. hasencoding->isAbstract = UA_FALSE;
  153. hasencoding->symmetric = UA_FALSE;
  154. hasencoding->inverseName = UA_LOCALIZEDTEXT_STATIC("EncodingOf");
  155. AddReference((UA_Node*)hasencoding, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  156. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  157. Namespace_insert(ns0,(UA_Node*)hasencoding);
  158. UA_ReferenceTypeNode *hasdescription;
  159. UA_ReferenceTypeNode_new(&hasdescription);
  160. hasdescription->nodeId = RefTypeId_HasDescription;
  161. hasdescription->nodeClass = UA_NODECLASS_REFERENCETYPE;
  162. hasdescription->browseName = UA_QUALIFIEDNAME_STATIC("HasDescription");
  163. hasdescription->displayName = UA_LOCALIZEDTEXT_STATIC("HasDescription");
  164. hasdescription->description = UA_LOCALIZEDTEXT_STATIC("HasDescription");
  165. hasdescription->isAbstract = UA_FALSE;
  166. hasdescription->symmetric = UA_FALSE;
  167. hasdescription->inverseName = UA_LOCALIZEDTEXT_STATIC("DescriptionOf");
  168. AddReference((UA_Node*)hasdescription, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  169. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  170. Namespace_insert(ns0,(UA_Node*)hasdescription);
  171. UA_ReferenceTypeNode *hastypedefinition;
  172. UA_ReferenceTypeNode_new(&hastypedefinition);
  173. hastypedefinition->nodeId = RefTypeId_HasTypeDefinition;
  174. hastypedefinition->nodeClass = UA_NODECLASS_REFERENCETYPE;
  175. hastypedefinition->browseName = UA_QUALIFIEDNAME_STATIC("HasTypeDefinition");
  176. hastypedefinition->displayName = UA_LOCALIZEDTEXT_STATIC("HasTypeDefinition");
  177. hastypedefinition->description = UA_LOCALIZEDTEXT_STATIC("HasTypeDefinition");
  178. hastypedefinition->isAbstract = UA_FALSE;
  179. hastypedefinition->symmetric = UA_FALSE;
  180. hastypedefinition->inverseName = UA_LOCALIZEDTEXT_STATIC("TypeDefinitionOf");
  181. AddReference((UA_Node*)hastypedefinition, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  182. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  183. Namespace_insert(ns0,(UA_Node*)hastypedefinition);
  184. UA_ReferenceTypeNode *generatesevent;
  185. UA_ReferenceTypeNode_new(&generatesevent);
  186. generatesevent->nodeId = RefTypeId_GeneratesEvent;
  187. generatesevent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  188. generatesevent->browseName = UA_QUALIFIEDNAME_STATIC("GeneratesEvent");
  189. generatesevent->displayName = UA_LOCALIZEDTEXT_STATIC("GeneratesEvent");
  190. generatesevent->description = UA_LOCALIZEDTEXT_STATIC("GeneratesEvent");
  191. generatesevent->isAbstract = UA_FALSE;
  192. generatesevent->symmetric = UA_FALSE;
  193. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("GeneratedBy");
  194. AddReference((UA_Node*)generatesevent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  195. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  196. Namespace_insert(ns0,(UA_Node*)generatesevent);
  197. UA_ReferenceTypeNode *aggregates;
  198. UA_ReferenceTypeNode_new(&aggregates);
  199. aggregates->nodeId = RefTypeId_Aggregates;
  200. aggregates->nodeClass = UA_NODECLASS_REFERENCETYPE;
  201. aggregates->browseName = UA_QUALIFIEDNAME_STATIC("Aggregates");
  202. aggregates->displayName = UA_LOCALIZEDTEXT_STATIC("Aggregates");
  203. aggregates->description = UA_LOCALIZEDTEXT_STATIC("Aggregates");
  204. aggregates->isAbstract = UA_TRUE;
  205. aggregates->symmetric = UA_FALSE;
  206. AddReference((UA_Node*)aggregates, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  207. (UA_ExpandedNodeId){RefTypeId_HasChild, UA_STRING_NULL, 0}}, ns0);
  208. Namespace_insert(ns0,(UA_Node*)aggregates);
  209. UA_ReferenceTypeNode *hassubtype;
  210. UA_ReferenceTypeNode_new(&hassubtype);
  211. hassubtype->nodeId = RefTypeId_HasSubtype;
  212. hassubtype->nodeClass = UA_NODECLASS_REFERENCETYPE;
  213. hassubtype->browseName = UA_QUALIFIEDNAME_STATIC("HasSubtype");
  214. hassubtype->displayName = UA_LOCALIZEDTEXT_STATIC("HasSubtype");
  215. hassubtype->description = UA_LOCALIZEDTEXT_STATIC("HasSubtype");
  216. hassubtype->isAbstract = UA_FALSE;
  217. hassubtype->symmetric = UA_FALSE;
  218. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("SubtypeOf");
  219. AddReference((UA_Node*)hassubtype, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  220. (UA_ExpandedNodeId){RefTypeId_HasChild, UA_STRING_NULL, 0}}, ns0);
  221. Namespace_insert(ns0,(UA_Node*)hassubtype);
  222. UA_ReferenceTypeNode *hasproperty;
  223. UA_ReferenceTypeNode_new(&hasproperty);
  224. hasproperty->nodeId = RefTypeId_HasProperty;
  225. hasproperty->nodeClass = UA_NODECLASS_REFERENCETYPE;
  226. hasproperty->browseName = UA_QUALIFIEDNAME_STATIC("HasProperty");
  227. hasproperty->displayName = UA_LOCALIZEDTEXT_STATIC("HasProperty");
  228. hasproperty->description = UA_LOCALIZEDTEXT_STATIC("HasProperty");
  229. hasproperty->isAbstract = UA_FALSE;
  230. hasproperty->symmetric = UA_FALSE;
  231. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("PropertyOf");
  232. AddReference((UA_Node*)hasproperty, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  233. (UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
  234. Namespace_insert(ns0,(UA_Node*)hasproperty);
  235. UA_ReferenceTypeNode *hascomponent;
  236. UA_ReferenceTypeNode_new(&hascomponent);
  237. hascomponent->nodeId = RefTypeId_HasComponent;
  238. hascomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  239. hascomponent->browseName = UA_QUALIFIEDNAME_STATIC("HasComponent");
  240. hascomponent->displayName = UA_LOCALIZEDTEXT_STATIC("HasComponent");
  241. hascomponent->description = UA_LOCALIZEDTEXT_STATIC("HasComponent");
  242. hascomponent->isAbstract = UA_FALSE;
  243. hascomponent->symmetric = UA_FALSE;
  244. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("ComponentOf");
  245. AddReference((UA_Node*)hascomponent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  246. (UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
  247. Namespace_insert(ns0,(UA_Node*)hascomponent);
  248. UA_ReferenceTypeNode *hasnotifier;
  249. UA_ReferenceTypeNode_new(&hasnotifier);
  250. hasnotifier->nodeId = RefTypeId_HasNotifier;
  251. hasnotifier->nodeClass = UA_NODECLASS_REFERENCETYPE;
  252. hasnotifier->browseName = UA_QUALIFIEDNAME_STATIC("HasNotifier");
  253. hasnotifier->displayName = UA_LOCALIZEDTEXT_STATIC("HasNotifier");
  254. hasnotifier->description = UA_LOCALIZEDTEXT_STATIC("HasNotifier");
  255. hasnotifier->isAbstract = UA_FALSE;
  256. hasnotifier->symmetric = UA_FALSE;
  257. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("NotifierOf");
  258. AddReference((UA_Node*)hasnotifier, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  259. (UA_ExpandedNodeId){RefTypeId_HasEventSource, UA_STRING_NULL, 0}}, ns0);
  260. Namespace_insert(ns0,(UA_Node*)hasnotifier);
  261. UA_ReferenceTypeNode *hasorderedcomponent;
  262. UA_ReferenceTypeNode_new(&hasorderedcomponent);
  263. hasorderedcomponent->nodeId = RefTypeId_HasOrderedComponent;
  264. hasorderedcomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  265. hasorderedcomponent->browseName = UA_QUALIFIEDNAME_STATIC("HasOrderedComponent");
  266. hasorderedcomponent->displayName = UA_LOCALIZEDTEXT_STATIC("HasOrderedComponent");
  267. hasorderedcomponent->description = UA_LOCALIZEDTEXT_STATIC("HasOrderedComponent");
  268. hasorderedcomponent->isAbstract = UA_FALSE;
  269. hasorderedcomponent->symmetric = UA_FALSE;
  270. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("OrderedComponentOf");
  271. AddReference((UA_Node*)hasorderedcomponent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  272. (UA_ExpandedNodeId){RefTypeId_HasComponent, UA_STRING_NULL, 0}}, ns0);
  273. Namespace_insert(ns0,(UA_Node*)hasorderedcomponent);
  274. UA_ReferenceTypeNode *hasmodelparent;
  275. UA_ReferenceTypeNode_new(&hasmodelparent);
  276. hasmodelparent->nodeId = RefTypeId_HasModelParent;
  277. hasmodelparent->nodeClass = UA_NODECLASS_REFERENCETYPE;
  278. hasmodelparent->browseName = UA_QUALIFIEDNAME_STATIC("HasModelParent");
  279. hasmodelparent->displayName = UA_LOCALIZEDTEXT_STATIC("HasModelParent");
  280. hasmodelparent->description = UA_LOCALIZEDTEXT_STATIC("HasModelParent");
  281. hasmodelparent->isAbstract = UA_FALSE;
  282. hasmodelparent->symmetric = UA_FALSE;
  283. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("ModelParentOf");
  284. AddReference((UA_Node*)hasmodelparent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  285. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  286. Namespace_insert(ns0,(UA_Node*)hasmodelparent);
  287. UA_ReferenceTypeNode *fromstate;
  288. UA_ReferenceTypeNode_new(&fromstate);
  289. fromstate->nodeId = RefTypeId_FromState;
  290. fromstate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  291. fromstate->browseName = UA_QUALIFIEDNAME_STATIC("FromState");
  292. fromstate->displayName = UA_LOCALIZEDTEXT_STATIC("FromState");
  293. fromstate->description = UA_LOCALIZEDTEXT_STATIC("FromState");
  294. fromstate->isAbstract = UA_FALSE;
  295. fromstate->symmetric = UA_FALSE;
  296. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("ToTransition");
  297. AddReference((UA_Node*)fromstate, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  298. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  299. Namespace_insert(ns0,(UA_Node*)fromstate);
  300. UA_ReferenceTypeNode *tostate;
  301. UA_ReferenceTypeNode_new(&tostate);
  302. tostate->nodeId = RefTypeId_ToState;
  303. tostate->nodeClass = UA_NODECLASS_REFERENCETYPE;
  304. tostate->browseName = UA_QUALIFIEDNAME_STATIC("ToState");
  305. tostate->displayName = UA_LOCALIZEDTEXT_STATIC("ToState");
  306. tostate->description = UA_LOCALIZEDTEXT_STATIC("ToState");
  307. tostate->isAbstract = UA_FALSE;
  308. tostate->symmetric = UA_FALSE;
  309. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("FromTransition");
  310. AddReference((UA_Node*)tostate, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  311. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  312. Namespace_insert(ns0,(UA_Node*)tostate);
  313. UA_ReferenceTypeNode *hascause;
  314. UA_ReferenceTypeNode_new(&hascause);
  315. hascause->nodeId = RefTypeId_HasCause;
  316. hascause->nodeClass = UA_NODECLASS_REFERENCETYPE;
  317. hascause->browseName = UA_QUALIFIEDNAME_STATIC("HasCause");
  318. hascause->displayName = UA_LOCALIZEDTEXT_STATIC("HasCause");
  319. hascause->description = UA_LOCALIZEDTEXT_STATIC("HasCause");
  320. hascause->isAbstract = UA_FALSE;
  321. hascause->symmetric = UA_FALSE;
  322. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("MayBeCausedBy");
  323. AddReference((UA_Node*)hascause, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  324. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  325. Namespace_insert(ns0,(UA_Node*)hascause);
  326. UA_ReferenceTypeNode *haseffect;
  327. UA_ReferenceTypeNode_new(&haseffect);
  328. haseffect->nodeId = RefTypeId_HasEffect;
  329. haseffect->nodeClass = UA_NODECLASS_REFERENCETYPE;
  330. haseffect->browseName = UA_QUALIFIEDNAME_STATIC("HasEffect");
  331. haseffect->displayName = UA_LOCALIZEDTEXT_STATIC("HasEffect");
  332. haseffect->description = UA_LOCALIZEDTEXT_STATIC("HasEffect");
  333. haseffect->isAbstract = UA_FALSE;
  334. haseffect->symmetric = UA_FALSE;
  335. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("MayBeEffectedBy");
  336. AddReference((UA_Node*)haseffect, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
  337. (UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
  338. Namespace_insert(ns0,(UA_Node*)haseffect);
  339. UA_ReferenceTypeNode *hashistoricalconfiguration;
  340. UA_ReferenceTypeNode_new(&hashistoricalconfiguration);
  341. hashistoricalconfiguration->nodeId = RefTypeId_HasHistoricalConfiguration;
  342. hashistoricalconfiguration->nodeClass = UA_NODECLASS_REFERENCETYPE;
  343. hashistoricalconfiguration->browseName = UA_QUALIFIEDNAME_STATIC("HasHistoricalConfiguration");
  344. hashistoricalconfiguration->displayName = UA_LOCALIZEDTEXT_STATIC("HasHistoricalConfiguration");
  345. hashistoricalconfiguration->description = UA_LOCALIZEDTEXT_STATIC("HasHistoricalConfiguration");
  346. hashistoricalconfiguration->isAbstract = UA_FALSE;
  347. hashistoricalconfiguration->symmetric = UA_FALSE;
  348. generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("HistoricalConfigurationOf");
  349. AddReference((UA_Node*)hashistoricalconfiguration, &(UA_ReferenceNode){RefTypeId_HasSubtype,
  350. UA_TRUE, (UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
  351. Namespace_insert(ns0,(UA_Node*)hashistoricalconfiguration);
  352. // ObjectTypes (Ids only)
  353. UA_ExpandedNodeId ObjTypeId_FolderType = NS0EXPANDEDNODEID(61);
  354. // Objects (Ids only)
  355. UA_ExpandedNodeId ObjId_ObjectsFolder = NS0EXPANDEDNODEID(85);
  356. UA_ExpandedNodeId ObjId_TypesFolder = NS0EXPANDEDNODEID(86);
  357. UA_ExpandedNodeId ObjId_ViewsFolder = NS0EXPANDEDNODEID(87);
  358. UA_ExpandedNodeId ObjId_Server = NS0EXPANDEDNODEID(2253);
  359. UA_ExpandedNodeId ObjId_ServerArray = NS0EXPANDEDNODEID(2254);
  360. UA_ExpandedNodeId ObjId_NamespaceArray = NS0EXPANDEDNODEID(2255);
  361. UA_ExpandedNodeId ObjId_ServerStatus = NS0EXPANDEDNODEID(2256);
  362. UA_ExpandedNodeId ObjId_ServerCapabilities = NS0EXPANDEDNODEID(2268);
  363. UA_ExpandedNodeId ObjId_State = NS0EXPANDEDNODEID(2259);
  364. // FolderType
  365. UA_ObjectNode *folderType;
  366. UA_ObjectNode_new(&folderType);
  367. folderType->nodeId = NS0NODEID(61);
  368. folderType->nodeClass = UA_NODECLASS_OBJECTTYPE; // I should not have to set this manually
  369. folderType->browseName = UA_QUALIFIEDNAME_STATIC("FolderType");
  370. folderType->displayName = UA_LOCALIZEDTEXT_STATIC("FolderType");
  371. folderType->description = UA_LOCALIZEDTEXT_STATIC("FolderType");
  372. Namespace_insert(ns0,(UA_Node*)folderType);
  373. // Root
  374. UA_ObjectNode *root;
  375. UA_ObjectNode_new(&root);
  376. root->nodeId = NS0NODEID(84);
  377. root->nodeClass = UA_NODECLASS_OBJECT; // I should not have to set this manually
  378. root->browseName = UA_QUALIFIEDNAME_STATIC("Root");
  379. root->displayName = UA_LOCALIZEDTEXT_STATIC("Root");
  380. root->description = UA_LOCALIZEDTEXT_STATIC("Root");
  381. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
  382. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_ObjectsFolder}, ns0);
  383. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_TypesFolder}, ns0);
  384. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_ViewsFolder}, ns0);
  385. Namespace_insert(ns0,(UA_Node*)root);
  386. // Objects
  387. UA_ObjectNode *objects;
  388. UA_ObjectNode_new(&objects);
  389. objects->nodeId = ObjId_ObjectsFolder.nodeId;
  390. objects->nodeClass = UA_NODECLASS_OBJECT;
  391. objects->browseName = UA_QUALIFIEDNAME_STATIC("Objects");
  392. objects->displayName = UA_LOCALIZEDTEXT_STATIC("Objects");
  393. objects->description = UA_LOCALIZEDTEXT_STATIC("Objects");
  394. AddReference((UA_Node*)objects, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
  395. AddReference((UA_Node*)objects, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_Server}, ns0);
  396. Namespace_insert(ns0,(UA_Node*)objects);
  397. // Types
  398. UA_ObjectNode *types;
  399. UA_ObjectNode_new(&types);
  400. types->nodeId = ObjId_TypesFolder.nodeId;
  401. types->nodeClass = UA_NODECLASS_OBJECT;
  402. types->browseName = UA_QUALIFIEDNAME_STATIC("Types");
  403. types->displayName = UA_LOCALIZEDTEXT_STATIC("Types");
  404. types->description = UA_LOCALIZEDTEXT_STATIC("Types");
  405. AddReference((UA_Node*)types, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
  406. Namespace_insert(ns0,(UA_Node*)types);
  407. // Views
  408. UA_ObjectNode *views;
  409. UA_ObjectNode_new(&views);
  410. views->nodeId = ObjId_ViewsFolder.nodeId;
  411. views->nodeClass = UA_NODECLASS_OBJECT;
  412. views->browseName = UA_QUALIFIEDNAME_STATIC("Views");
  413. views->displayName = UA_LOCALIZEDTEXT_STATIC("Views");
  414. views->description = UA_LOCALIZEDTEXT_STATIC("Views");
  415. AddReference((UA_Node*)views, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
  416. Namespace_insert(ns0,(UA_Node*)views);
  417. // Server
  418. UA_ObjectNode *server;
  419. UA_ObjectNode_new(&server);
  420. server->nodeId = ObjId_Server.nodeId;
  421. server->nodeClass = UA_NODECLASS_OBJECT;
  422. server->browseName = UA_QUALIFIEDNAME_STATIC("Server");
  423. server->displayName = UA_LOCALIZEDTEXT_STATIC("Server");
  424. server->description = UA_LOCALIZEDTEXT_STATIC("Server");
  425. AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasComponent, UA_FALSE, ObjId_ServerCapabilities}, ns0);
  426. AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasComponent, UA_FALSE, ObjId_NamespaceArray}, ns0);
  427. AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasProperty, UA_FALSE, ObjId_ServerStatus}, ns0);
  428. AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasProperty, UA_FALSE, ObjId_ServerArray}, ns0);
  429. Namespace_insert(ns0,(UA_Node*)server);
  430. // NamespaceArray
  431. UA_VariableNode *namespaceArray;
  432. UA_VariableNode_new(&namespaceArray);
  433. namespaceArray->nodeId = ObjId_NamespaceArray.nodeId;
  434. namespaceArray->nodeClass = UA_NODECLASS_VARIABLE; //FIXME: this should go into _new?
  435. namespaceArray->browseName = UA_QUALIFIEDNAME_STATIC("NamespaceArray");
  436. namespaceArray->displayName = UA_LOCALIZEDTEXT_STATIC("NamespaceArray");
  437. namespaceArray->description = UA_LOCALIZEDTEXT_STATIC("NamespaceArray");
  438. UA_Array_new((void**)&namespaceArray->value.data, 2, &UA_.types[UA_STRING]);
  439. namespaceArray->value.vt = &UA_.types[UA_STRING];
  440. namespaceArray->value.arrayLength = 2;
  441. UA_String_copycstring("http://opcfoundation.org/UA/",&((UA_String *)((namespaceArray->value).data))[0]);
  442. UA_String_copycstring("http://localhost:16664/open62541/",&((UA_String *)(((namespaceArray)->value).data))[1]);
  443. namespaceArray->arrayDimensionsSize = 1;
  444. UA_UInt32* dimensions = UA_NULL;
  445. UA_alloc((void**)&dimensions, sizeof(UA_UInt32));
  446. *dimensions = 2;
  447. namespaceArray->arrayDimensions = dimensions;
  448. namespaceArray->dataType = NS0NODEID(UA_STRING_NS0);
  449. namespaceArray->valueRank = 1;
  450. namespaceArray->minimumSamplingInterval = 1.0;
  451. namespaceArray->historizing = UA_FALSE;
  452. Namespace_insert(ns0,(UA_Node*)namespaceArray);
  453. // ServerStatus
  454. UA_VariableNode *serverstatus;
  455. UA_VariableNode_new(&serverstatus);
  456. serverstatus->nodeId = ObjId_ServerStatus.nodeId;
  457. serverstatus->nodeClass = UA_NODECLASS_VARIABLE;
  458. serverstatus->browseName = UA_QUALIFIEDNAME_STATIC("ServerStatus");
  459. serverstatus->displayName = UA_LOCALIZEDTEXT_STATIC("ServerStatus");
  460. serverstatus->description = UA_LOCALIZEDTEXT_STATIC("ServerStatus");
  461. UA_ServerStatusDataType *status;
  462. UA_ServerStatusDataType_new(&status);
  463. status->startTime = UA_DateTime_now();
  464. status->currentTime = UA_DateTime_now();
  465. status->state = UA_SERVERSTATE_RUNNING;
  466. status->buildInfo = (UA_BuildInfo){
  467. .productUri = UA_STRING_STATIC("open62541.org"),
  468. .manufacturerName = UA_STRING_STATIC("open62541"),
  469. .productName = UA_STRING_STATIC("open62541"),
  470. .softwareVersion = UA_STRING_STATIC("0.0"),
  471. .buildNumber = UA_STRING_STATIC("0.0"),
  472. .buildDate = UA_DateTime_now()};
  473. status->secondsTillShutdown = 99999999;
  474. status->shutdownReason = UA_LOCALIZEDTEXT_STATIC("because");
  475. serverstatus->value.vt = &UA_.types[UA_SERVERSTATUSDATATYPE]; // gets encoded as an extensionobject
  476. serverstatus->value.arrayLength = 1;
  477. serverstatus->value.data = status;
  478. Namespace_insert(ns0,(UA_Node*)serverstatus);
  479. // State (Component of ServerStatus)
  480. UA_VariableNode *state;
  481. UA_VariableNode_new(&state);
  482. state->nodeId = ObjId_State.nodeId;
  483. state->nodeClass = UA_NODECLASS_VARIABLE;
  484. state->browseName = UA_QUALIFIEDNAME_STATIC("State");
  485. state->displayName = UA_LOCALIZEDTEXT_STATIC("State");
  486. state->description = UA_LOCALIZEDTEXT_STATIC("State");
  487. state->value.vt = &UA_borrowed_.types[UA_SERVERSTATE];
  488. state->value.arrayLength = 1;
  489. state->value.data = &status->state; // points into the other object.
  490. Namespace_insert(ns0,(UA_Node*)state);
  491. //TODO: free(namespaceArray->value.data) later or forget it
  492. /* UA_VariableNode* v = (UA_VariableNode*)np; */
  493. /* UA_Array_new((void**)&v->value.data, 2, &UA_.types[UA_STRING]); */
  494. /* v->value.vt = &UA_.types[UA_STRING]; */
  495. /* v->value.arrayLength = 2; */
  496. /* UA_String_copycstring("http://opcfoundation.org/UA/",&((UA_String *)((v->value).data))[0]); */
  497. /* UA_String_copycstring("http://localhost:16664/open62541/",&((UA_String *)(((v)->value).data))[1]); */
  498. /* v->dataType.encodingByte = UA_NODEIDTYPE_FOURBYTE; */
  499. /* v->dataType.identifier.numeric = UA_STRING_NS0; */
  500. /* v->valueRank = 1; */
  501. /* v->minimumSamplingInterval = 1.0; */
  502. /* v->historizing = UA_FALSE; */
  503. /* Namespace_insert(ns0,np); */
  504. /*******************/
  505. /* Namespace local */
  506. /*******************/
  507. // WORKS
  508. UA_ExpandedNodeId ObjId_temperature1 = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 108}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
  509. // temperature sensor
  510. UA_VariableNode *temperature1;
  511. UA_VariableNode_new(&temperature1);
  512. temperature1->nodeId = ObjId_temperature1.nodeId;
  513. temperature1->nodeClass = UA_NODECLASS_VARIABLE;
  514. temperature1->browseName = UA_QUALIFIEDNAME_STATIC("temperature1");
  515. temperature1->displayName = UA_LOCALIZEDTEXT_STATIC("temperature1");
  516. temperature1->description = UA_LOCALIZEDTEXT_STATIC("temperature1");
  517. //Set node value
  518. UA_Variant *tmpNodeValue;
  519. UA_Float *tmpFloat;
  520. UA_Float_new(&tmpFloat);
  521. *tmpFloat = -273.15f;
  522. UA_Variant_new(&tmpNodeValue);
  523. tmpNodeValue->arrayDimensionsLength = 0;
  524. tmpNodeValue->arrayLength = 1;
  525. tmpNodeValue->data = (void*)tmpFloat;
  526. tmpNodeValue->vt = &UA_.types[UA_FLOAT];
  527. UA_Variant_copy(tmpNodeValue, &temperature1->value);
  528. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_temperature1}, ns0);
  529. Namespace_insert(ns0,(UA_Node*)temperature1);
  530. UA_ExpandedNodeId ObjId_redLED = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 109}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
  531. // redLED sensor
  532. UA_VariableNode *redLED;
  533. UA_VariableNode_new(&redLED);
  534. redLED->nodeId = ObjId_redLED.nodeId;
  535. redLED->nodeClass = UA_NODECLASS_VARIABLE;
  536. redLED->browseName = UA_QUALIFIEDNAME_STATIC("redLED");
  537. redLED->displayName = UA_LOCALIZEDTEXT_STATIC("redLED");
  538. redLED->description = UA_LOCALIZEDTEXT_STATIC("redLED");
  539. //Set node value
  540. UA_Variant *tmpNodeValue1;
  541. UA_Boolean *ledVal;
  542. UA_Boolean_new(&ledVal);
  543. *ledVal = UA_FALSE;
  544. UA_Variant_new(&tmpNodeValue1);
  545. tmpNodeValue1->arrayDimensionsLength = 0;
  546. tmpNodeValue1->arrayLength = 1;
  547. tmpNodeValue1->data = (void*)ledVal;
  548. tmpNodeValue1->vt = &UA_.types[UA_BOOLEAN];
  549. UA_Variant_copy(tmpNodeValue1, &redLED->value);
  550. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_redLED}, ns0);
  551. Namespace_insert(ns0,(UA_Node*)redLED);
  552. UA_ExpandedNodeId ObjId_yellowLED = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 110}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
  553. // yellowLED sensor
  554. UA_VariableNode *yellowLED;
  555. UA_VariableNode_new(&yellowLED);
  556. yellowLED->nodeId = ObjId_yellowLED.nodeId;
  557. yellowLED->nodeClass = UA_NODECLASS_VARIABLE;
  558. yellowLED->browseName = UA_QUALIFIEDNAME_STATIC("yellowLED");
  559. yellowLED->displayName = UA_LOCALIZEDTEXT_STATIC("yellowLED");
  560. yellowLED->description = UA_LOCALIZEDTEXT_STATIC("yellowLED");
  561. //Set node value
  562. UA_Variant *tmpNodeValue2;
  563. UA_Boolean *ledVal1;
  564. UA_Boolean_new(&ledVal1);
  565. *ledVal1 = UA_FALSE;
  566. UA_Variant_new(&tmpNodeValue2);
  567. tmpNodeValue2->arrayDimensionsLength = 0;
  568. tmpNodeValue2->arrayLength = 1;
  569. tmpNodeValue2->data = (void*)ledVal1;
  570. tmpNodeValue2->vt = &UA_.types[UA_BOOLEAN];
  571. UA_Variant_copy(tmpNodeValue2, &yellowLED->value);
  572. AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_yellowLED}, ns0);
  573. Namespace_insert(ns0,(UA_Node*)yellowLED);
  574. #if defined(DEBUG) && defined(VERBOSE)
  575. uint32_t i;
  576. for (i=0;i < ns0->size;i++) {
  577. if (ns0->entries[i].node != UA_NULL) {
  578. printf("appMockup_init - entries[%d]={",i);
  579. UA_Node_print(ns0->entries[i].node, stdout);
  580. printf("}\n");
  581. }
  582. }
  583. #endif
  584. }