opcuaServerMT.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. UA_Boolean running = UA_TRUE;
  13. void stopHandler(int sign) {
  14. running = UA_FALSE;
  15. }
  16. UA_Int32 serverCallback(void * arg) {
  17. char *name = (char *) arg;
  18. printf("%s does whatever servers do\n",name);
  19. Namespace* ns0 = (Namespace*)UA_indexedList_find(appMockup.namespaces, 0)->payload;
  20. UA_Int32 retval;
  21. const UA_Node * node;
  22. UA_ExpandedNodeId serverStatusNodeId = NS0EXPANDEDNODEID(2256);
  23. retval = Namespace_get(ns0, &serverStatusNodeId.nodeId, &node);
  24. if(retval == UA_SUCCESS){
  25. ((UA_ServerStatusDataType*)(((UA_VariableNode*)node)->value.data))->currentTime = UA_DateTime_now();
  26. }
  27. return UA_SUCCESS;
  28. }
  29. int main(int argc, char** argv) {
  30. /* gets called at ctrl-c */
  31. signal(SIGINT, stopHandler);
  32. appMockup_init();
  33. NL_data* nl = NL_init(&NL_Description_TcpBinary, 16664);
  34. struct timeval tv = {1, 0}; // 1 second
  35. NL_msgLoop(nl, &tv, serverCallback, argv[0], &running);
  36. printf("Shutting down after Ctrl-C.\n");
  37. exit(0);
  38. }