ua_architecture.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
  5. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  6. */
  7. #ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  8. #define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  9. /* Enable POSIX features */
  10. #if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
  11. # define _XOPEN_SOURCE 600
  12. #endif
  13. #ifndef _DEFAULT_SOURCE
  14. # define _DEFAULT_SOURCE
  15. #endif
  16. /* On older systems we need to define _BSD_SOURCE.
  17. * _DEFAULT_SOURCE is an alias for that. */
  18. #ifndef _BSD_SOURCE
  19. # define _BSD_SOURCE
  20. #endif
  21. #if !defined(UA_FREERTOS)
  22. # include <errno.h>
  23. #else
  24. # define AI_PASSIVE 0x01
  25. # define TRUE 1
  26. # define FALSE 0
  27. # define ioctl ioctlsocket
  28. #endif
  29. # if defined(UA_FREERTOS)
  30. # define UA_FREERTOS_HOSTNAME "10.200.4.114"
  31. static inline int gethostname_freertos(char* name, size_t len){
  32. if(strlen(UA_FREERTOS_HOSTNAME) > (len))
  33. return -1;
  34. strcpy(name, UA_FREERTOS_HOSTNAME);
  35. return 0;
  36. }
  37. #define gethostname gethostname_freertos
  38. # include <lwip/tcpip.h>
  39. # include <lwip/netdb.h>
  40. # define CLOSESOCKET(S) lwip_close(S)
  41. # define sockaddr_storage sockaddr
  42. # ifdef BYTE_ORDER
  43. # undef BYTE_ORDER
  44. # endif
  45. # define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
  46. # else /* Not freeRTOS */
  47. # define CLOSESOCKET(S) close(S)
  48. # include <arpa/inet.h>
  49. # include <netinet/in.h>
  50. # include <netdb.h>
  51. # include <sys/ioctl.h>
  52. # if defined(_WRS_KERNEL)
  53. # include <hostLib.h>
  54. # include <selectLib.h>
  55. # define UA_sleep_ms(X) \
  56. { \
  57. struct timespec timeToSleep; \
  58. timeToSleep.tv_sec = X / 1000; \
  59. timeToSleep.tv_nsec = 1000000 * (X % 1000); \
  60. nanosleep(&timeToSleep, NULL); \
  61. }
  62. # else /* defined(_WRS_KERNEL) */
  63. # include <sys/select.h>
  64. # define UA_sleep_ms(X) usleep(X * 1000)
  65. # endif /* defined(_WRS_KERNEL) */
  66. # endif /* Not freeRTOS */
  67. # define SOCKET int
  68. # define WIN32_INT
  69. # define OPTVAL_TYPE int
  70. # define ERR_CONNECTION_PROGRESS EINPROGRESS
  71. # include <fcntl.h>
  72. # include <unistd.h> // read, write, close
  73. # ifdef __QNX__
  74. # include <sys/socket.h>
  75. # endif
  76. # if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  77. # include <sys/param.h>
  78. # if defined(BSD)
  79. # include<sys/socket.h>
  80. # endif
  81. # endif
  82. # if !defined(__CYGWIN__) && !defined(UA_FREERTOS)
  83. # include <netinet/tcp.h>
  84. # endif
  85. /* unsigned int for windows and workaround to a glibc bug */
  86. /* Additionally if GNU_LIBRARY is not defined, it may be using
  87. * musl libc (e.g. Docker Alpine) */
  88. #if defined(_WIN32) || defined(__OpenBSD__) || \
  89. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  90. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  91. !defined(__GNU_LIBRARY__))
  92. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  93. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  94. #else
  95. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  96. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  97. #endif
  98. # define errno__ errno
  99. # define INTERRUPTED EINTR
  100. # define WOULDBLOCK EWOULDBLOCK
  101. # define AGAIN EAGAIN
  102. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */