ua_application.c 2.7 KB

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