ua_application.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_[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. n->displayName.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  17. UA_String_copycstring(dn,&(n->displayName.text));
  18. n->description.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  19. UA_String_copycstring(desc,&(n->description.text));
  20. n->nodeClass = nodeClass;
  21. return n;
  22. }
  23. #define C2UA_STRING(s) (UA_String) { sizeof(s)-1, (UA_Byte*) s }
  24. void appMockup_init() {
  25. // create namespaces
  26. namespace* ns0; create_ns(&ns0,100);
  27. ns0->namespaceId = 0;
  28. ns0->namespaceUri = C2UA_STRING("http://opcfoundation.org/UA/");
  29. namespace* local; create_ns(&local,100);
  30. local->namespaceId = 1;
  31. local->namespaceUri = C2UA_STRING("http://localhost:16664/open62541/");
  32. // add to list of namespaces
  33. UA_indexedList_init(appMockup.namespaces);
  34. UA_indexedList_addValueToFront(appMockup.namespaces,0,ns0);
  35. UA_indexedList_addValueToFront(appMockup.namespaces,1,local);
  36. UA_Node* np;
  37. np = create_node_ns0(UA_OBJECTNODE, UA_NODECLASS_OBJECT, 2253, "Server", "open62541", "...");
  38. insert_node(ns0,np);
  39. UA_ObjectNode* o = (UA_ObjectNode*)np;
  40. o->eventNotifier = UA_FALSE;
  41. np = create_node_ns0(UA_VARIABLENODE, UA_NODECLASS_VARIABLE, 2255, "Server_NamespaceArray", "open62541", "..." );
  42. UA_VariableNode* v = (UA_VariableNode*)np;
  43. UA_Array_new((void***)&v->value.data,2,UA_STRING);
  44. v->value.vt = &UA_[UA_STRING];
  45. v->value.arrayLength = 2;
  46. v->value.encodingMask = UA_VARIANT_ENCODINGMASKTYPE_ARRAY | UA_STRING_NS0;
  47. UA_String_copycstring("http://opcfoundation.org/UA/",((UA_String **)(((v)->value).data))[0]);
  48. UA_String_copycstring("http://localhost:16664/open62541/",((UA_String **)(((v)->value).data))[1]);
  49. v->dataType.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  50. v->dataType.identifier.numeric = UA_STRING_NS0;
  51. v->valueRank = 1;
  52. v->minimumSamplingInterval = 1.0;
  53. v->historizing = UA_FALSE;
  54. insert_node(ns0,np);
  55. #if defined(DEBUG) && defined(VERBOSE)
  56. uint32_t i, j;
  57. for (i=0, j=0; i < ns0->size && j < ns0->count; i++) {
  58. if (ns0->entries[i].node != UA_NULL) {
  59. printf("appMockup_init - entries[%d]={",i);
  60. UA_NodeId_printf("nodeId=",&(ns0->entries[i].node->nodeId));
  61. UA_String_printf(",browseName=",&(ns0->entries[i].node->browseName.name));
  62. j++;
  63. printf("}\n");
  64. }
  65. }
  66. #endif
  67. }