opcuaServer.c 1.5 KB

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