ua_application.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * ua_application.c
  3. *
  4. * Created on: 16.04.2014
  5. * Author: mrt
  6. */
  7. #include "ua_application.h"
  8. #include "ua_namespace.h"
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. UA_indexedList_List nsMockup;
  12. Application appMockup = {
  13. ( UA_ApplicationDescription*) UA_NULL,
  14. &nsMockup
  15. };
  16. UA_Node* create_node_ns0(UA_Int32 class, UA_Int32 nodeClass, UA_Int32 const id, char const * qn, char const * dn, char const * desc) {
  17. UA_Node* n; UA_[class].new((void **)&n);
  18. n->nodeId.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  19. n->nodeId.namespace = 0;
  20. n->nodeId.identifier.numeric = id;
  21. UA_String_copycstring(qn,&(n->browseName.name));
  22. n->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  23. UA_String_copycstring(dn,&(n->displayName.text));
  24. n->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  25. UA_String_copycstring(desc,&(n->description.text));
  26. n->nodeClass = nodeClass;
  27. return n;
  28. }
  29. #define C2UA_STRING(s) (UA_String) { sizeof(s)-1, (UA_Byte*) s }
  30. void appMockup_init() {
  31. // create namespaces
  32. namespace* ns0; create_ns(&ns0,100);
  33. ns0->namespaceId = 0;
  34. ns0->namespaceUri = C2UA_STRING("http://opcfoundation.org/UA/");
  35. namespace* local; create_ns(&local,100);
  36. local->namespaceId = 1;
  37. local->namespaceUri = C2UA_STRING("http://localhost:16664/open62541/");
  38. // add to list of namespaces
  39. UA_indexedList_init(appMockup.namespaces);
  40. UA_indexedList_addValueToFront(appMockup.namespaces,0,ns0);
  41. UA_indexedList_addValueToFront(appMockup.namespaces,1,local);
  42. UA_Node* np;
  43. np = create_node_ns0(UA_OBJECTNODE, UA_NODECLASS_OBJECT, 2253, "Server", "open62541", "...");
  44. insert_node(ns0,np);
  45. UA_ObjectNode* o = (UA_ObjectNode*)np;
  46. o->eventNotifier = UA_FALSE;
  47. np = create_node_ns0(UA_VARIABLENODE, UA_NODECLASS_VARIABLE, 2255, "Server_NamespaceArray", "open62541", "..." );
  48. UA_VariableNode* v = (UA_VariableNode*)np;
  49. UA_Array_new((void**)&(v->value.data),2,UA_STRING);
  50. v->value.vt = &UA_[UA_STRING];
  51. v->value.arrayLength = 2;
  52. v->value.encodingMask = UA_VARIANT_ENCODINGMASKTYPE_ARRAY || UA_STRING_NS0;
  53. UA_String_copycstring("http://opcfoundation.org/UA/",((UA_String **)(((v)->value).data))[0]);
  54. UA_String_copycstring("http://localhost:16664/open62541/",((UA_String **)(((v)->value).data))[1]);
  55. v->dataType.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  56. v->dataType.identifier.numeric = UA_STRING_NS0;
  57. v->valueRank = 1;
  58. v->minimumSamplingInterval = 1.0;
  59. v->historizing = UA_FALSE;
  60. insert_node(ns0,np);
  61. #if defined(DEBUG) && defined(VERBOSE)
  62. uint32_t i, j;
  63. for (i=0, j=0; i < ns0->size && j < ns0->count; i++) {
  64. if (ns0->entries[i].node != UA_NULL) {
  65. printf("appMockup_init - entries[%d]={",i);
  66. UA_NodeId_printf("nodeId=",&(ns0->entries[i].node->nodeId));
  67. UA_String_printf(",browseName=",&(ns0->entries[i].node->browseName.name));
  68. j++;
  69. printf("}\n");
  70. }
  71. }
  72. #endif
  73. }