opcuaServer.c 1.4 KB

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