ua_application.c 2.7 KB

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