ua_application.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "ua_application.h"
  2. #include "ua_namespace.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. UA_indexedList_List nsMockup;
  6. Application appMockup = {
  7. ( UA_ApplicationDescription*) UA_NULL,
  8. &nsMockup
  9. };
  10. UA_Node* create_node_ns0(UA_Int32 class, UA_Int32 nodeClass, UA_Int32 const id, char const * qn, char const * dn, char const * desc) {
  11. UA_Node* n; UA_.types[class].new((void **)&n);
  12. n->nodeId.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  13. n->nodeId.namespace = 0;
  14. n->nodeId.identifier.numeric = id;
  15. UA_String_copycstring(qn,&(n->browseName.name));
  16. UA_String_copycstring(dn,&n->displayName.text);
  17. UA_String_copycstring(desc,&n->description.text);
  18. n->nodeClass = nodeClass;
  19. return n;
  20. }
  21. #define C2UA_STRING(s) (UA_String) { sizeof(s)-1, (UA_Byte*) s }
  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. UA_Node* np;
  34. np = create_node_ns0(UA_OBJECTNODE, UA_NODECLASS_OBJECT, 2253, "Server", "open62541", "...");
  35. Namespace_insert(ns0,np);
  36. UA_ObjectNode* o = (UA_ObjectNode*)np;
  37. o->eventNotifier = UA_FALSE;
  38. np = create_node_ns0(UA_VARIABLENODE, UA_NODECLASS_VARIABLE, 2255, "Server_NamespaceArray", "open62541", "..." );
  39. UA_VariableNode* v = (UA_VariableNode*)np;
  40. UA_Array_new((void**)&v->value.data, 2, &UA_.types[UA_STRING]);
  41. v->value.vt = &UA_.types[UA_STRING];
  42. v->value.arrayLength = 2;
  43. UA_String_copycstring("http://opcfoundation.org/UA/",&((UA_String *)((v->value).data))[0]);
  44. UA_String_copycstring("http://localhost:16664/open62541/",&((UA_String *)(((v)->value).data))[1]);
  45. v->dataType.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  46. v->dataType.identifier.numeric = UA_STRING_NS0;
  47. v->valueRank = 1;
  48. v->minimumSamplingInterval = 1.0;
  49. v->historizing = UA_FALSE;
  50. Namespace_insert(ns0,np);
  51. #if defined(DEBUG) && defined(VERBOSE)
  52. uint32_t i;
  53. for (i=0;i < ns0->size;i++) {
  54. if (ns0->entries[i].node != UA_NULL) {
  55. printf("appMockup_init - entries[%d]={",i);
  56. UA_Node_print(ns0->entries[i].node, stdout);
  57. printf("}\n");
  58. }
  59. }
  60. #endif
  61. }