opcuaServer.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "networklayer.h"
  4. #include "ua_application.h"
  5. #ifdef WIN32
  6. #else
  7. #include <sys/mman.h>
  8. #include <sys/wait.h>
  9. #include <unistd.h>
  10. #endif
  11. #include <sys/types.h>
  12. #include <time.h>
  13. #include <fcntl.h>
  14. #include <signal.h>
  15. #include "ua_stack_channel_manager.h"
  16. #include "ua_stack_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. }