opcuaServer.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "networklayer.h"
  4. #include "ua_application.h"
  5. #include <sys/mman.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8. #include <unistd.h>
  9. #include <time.h>
  10. #include <fcntl.h>
  11. #include <signal.h>
  12. #include "ua_stack_channel_manager.h"
  13. #include "ua_stack_session_manager.h"
  14. #include "ua_server.h"
  15. UA_Boolean running = UA_TRUE;
  16. void stopHandler(int sign) {
  17. running = UA_FALSE;
  18. }
  19. UA_Int32 serverCallback(void * arg) {
  20. char *name = (char *) arg;
  21. printf("%s does whatever servers do\n",name);
  22. Namespace* ns0 = (Namespace*)UA_indexedList_find(appMockup.namespaces, 0)->payload;
  23. UA_Int32 retval;
  24. const UA_Node * node;
  25. UA_ExpandedNodeId serverStatusNodeId; NS0EXPANDEDNODEID(serverStatusNodeId, 2256);
  26. retval = Namespace_get(ns0, &serverStatusNodeId.nodeId, &node);
  27. if(retval == UA_SUCCESS){
  28. ((UA_ServerStatusDataType*)(((UA_VariableNode*)node)->value.data))->currentTime = UA_DateTime_now();
  29. }
  30. return UA_SUCCESS;
  31. }
  32. int main(int argc, char** argv) {
  33. /* gets called at ctrl-c */
  34. signal(SIGINT, stopHandler);
  35. appMockup_init();
  36. NL_data* nl = NL_init(&NL_Description_TcpBinary, 16664);
  37. UA_String endpointUrl;
  38. UA_String_copycstring("no endpoint url",&endpointUrl);
  39. SL_ChannelManager_init(10,36000,244,2,&endpointUrl);
  40. UA_SessionManager_init(10,3600000,25);
  41. struct timeval tv = {1, 0}; // 1 second
  42. NL_msgLoop(nl, &tv, serverCallback, argv[0], &running);
  43. }