ua_architecture.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_FREERTOS_UA_ARCHITECTURE_H_
  8. #define PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_
  9. //------------------------------------------------------------------
  10. // NOT WORKING YET!!!!!!!!!!!!!!!!!!!!!
  11. //------------------------------------------------------------------
  12. #define AI_PASSIVE 0x01
  13. #define UA_FREERTOS_HOSTNAME "10.200.4.114"
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #define LWIP_TIMEVAL_PRIVATE 0
  17. #define LWIP_COMPAT_MUTEX 0
  18. #define LWIP_POSIX_SOCKETS_IO_NAMES 0
  19. #ifdef LWIP_COMPAT_SOCKETS
  20. #undef LWIP_COMPAT_SOCKETS
  21. #endif
  22. #define LWIP_COMPAT_SOCKETS 0
  23. //#define __USE_W32_SOCKETS 1 //needed to avoid redefining of select in sys/select.h
  24. #include <lwip/tcpip.h>
  25. #include <lwip/netdb.h>
  26. #define sockaddr_storage sockaddr
  27. #ifdef BYTE_ORDER
  28. # undef BYTE_ORDER
  29. #endif
  30. #define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
  31. #define OPTVAL_TYPE int
  32. #include <unistd.h> // read, write, close
  33. #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  34. #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  35. #define UA_IPV6 0
  36. #define UA_SOCKET int
  37. #define UA_INVALID_SOCKET -1
  38. #define UA_ERRNO errno
  39. #define UA_INTERRUPTED EINTR
  40. #define UA_AGAIN EAGAIN
  41. #define UA_EAGAIN EAGAIN
  42. #define UA_WOULDBLOCK EWOULDBLOCK
  43. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  44. #include "ua_types.h"
  45. static UA_INLINE int gethostname_freertos(char* name, size_t len){
  46. if(strlen(UA_FREERTOS_HOSTNAME) > (len))
  47. return -1;
  48. strcpy(name, UA_FREERTOS_HOSTNAME);
  49. return 0;
  50. }
  51. #define gethostname gethostname_freertos
  52. #define ua_send lwip_send
  53. #define ua_recv lwip_recv
  54. #define ua_close lwip_close
  55. #define ua_select lwip_select
  56. #define ua_shutdown lwip_shutdown
  57. #define ua_socket lwip_socket
  58. #define ua_bind lwip_bind
  59. #define ua_listen lwip_listen
  60. #define ua_accept lwip_accept
  61. #define ua_connect lwip_connect
  62. #define ua_getsockopt lwip_getsockopt
  63. #define ua_setsockopt lwip_setsockopt
  64. #define ua_translate_error(x) ""
  65. #define ua_freeaddrinfo lwip_freeaddrinfo
  66. static UA_INLINE int ua_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res){
  67. if(NULL == node){
  68. const char* hostname = UA_FREERTOS_HOSTNAME;
  69. return lwip_getaddrinfo(hostname, service, hints, res);
  70. }else{
  71. return lwip_getaddrinfo(node, service, hints, res);
  72. }
  73. }
  74. static UA_INLINE uint32_t socket_set_blocking(UA_SOCKET sockfd){
  75. int on = 0;
  76. if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
  77. return UA_STATUSCODE_BADINTERNALERROR;
  78. return UA_STATUSCODE_GOOD;
  79. }
  80. static UA_INLINE uint32_t socket_set_nonblocking(UA_SOCKET sockfd){
  81. int on = 1;
  82. if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
  83. return UA_STATUSCODE_BADINTERNALERROR;
  84. return UA_STATUSCODE_GOOD;
  85. }
  86. #include <stdio.h>
  87. #define ua_snprintf snprintf
  88. static UA_INLINE void ua_initialize_architecture_network(void){
  89. return;
  90. }
  91. static UA_INLINE void ua_deinitialize_architecture_network(void){
  92. return;
  93. }
  94. #endif /* PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_ */