opcuaServer.c 1.5 KB

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