opcuaServer.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "networklayer.h"
  19. #include "ua_application.h"
  20. UA_Boolean running = UA_TRUE;
  21. void stopHandler(int sign) {
  22. running = UA_FALSE;
  23. }
  24. UA_Int32 serverCallback(void * arg) {
  25. char *name = (char *) arg;
  26. printf("%s does whatever servers do\n",name);
  27. /* Namespace* ns0 = (Namespace*)UA_indexedList_find(appMockup.namespaces, 0)->payload; */
  28. /* UA_Int32 retval; */
  29. /* const UA_Node * node; */
  30. /* UA_ExpandedNodeId serverStatusNodeId; NS0EXPANDEDNODEID(serverStatusNodeId, 2256); */
  31. /* retval = Namespace_get(ns0, &serverStatusNodeId.nodeId, &node); */
  32. /* if(retval == UA_SUCCESS){ */
  33. /* ((UA_ServerStatusDataType*)(((UA_VariableNode*)node)->value.data))->currentTime = UA_DateTime_now(); */
  34. /* } */
  35. return UA_SUCCESS;
  36. }
  37. int main(int argc, char** argv) {
  38. UA_Int32 retval;
  39. /* gets called at ctrl-c */
  40. signal(SIGINT, stopHandler);
  41. UA_Server server;
  42. UA_alloc((void**)&server.applications, sizeof(UA_Application));
  43. server.applicationsSize = 1;
  44. server.logger_init = Logger_Stdout_init;
  45. UA_Application_init(server.applications);
  46. NL_data* nl = NL_init(&NL_Description_TcpBinary, 16664);
  47. UA_String endpointUrl;
  48. UA_String_copycstring("no endpoint url",&endpointUrl);
  49. SL_ChannelManager_init(10,36000,244,2,&endpointUrl);
  50. UA_SessionManager_init(10,3600000,25);
  51. struct timeval tv = {1, 0}; // 1 second
  52. retval = NL_msgLoop(nl, &tv, &server, serverCallback, argv[0], &running);
  53. return retval == UA_SUCCESS ? 0 : retval;
  54. }