Pārlūkot izejas kodu

added arch for windows embedded compact 7

Kantelberg 5 gadi atpakaļ
vecāks
revīzija
f4f0970776

+ 1 - 0
arch/CMakeLists.txt

@@ -7,6 +7,7 @@ add_subdirectory(win32)
 add_subdirectory(freertosLWIP)
 add_subdirectory(vxworks)
 add_subdirectory(eCos)
+add_subdirectory(wec7)
 
 SET(UA_ARCH_EXTRA_INCLUDES "" CACHE STRING "Folders to include from the architecture")
 ua_include_directories(${UA_ARCH_EXTRA_INCLUDES})

+ 3 - 0
arch/ua_architecture_definitions.h

@@ -17,6 +17,9 @@
 #include <stddef.h>
 
 /* Include stdint.h and stdbool.h or workaround for older Visual Studios */
+#ifdef UNDER_CE
+# include "stdint.h"
+#endif
 #if !defined(_MSC_VER) || _MSC_VER >= 1600
 # include <stdint.h>
 # include <stdbool.h> /* C99 Boolean */

+ 17 - 0
arch/wec7/CMakeLists.txt

@@ -0,0 +1,17 @@
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\wec7)
+
+ua_add_architecture("wec7")
+
+list (FIND UA_AMALGAMATION_ARCHITECUTRES "wec7" _index)
+if (${_index} GREATER -1 OR "${UA_ARCHITECTURE}" STREQUAL "wec7")
+
+    ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+    ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
+
+    if("${UA_ARCHITECTURE}" STREQUAL "wec7")
+        ua_architecture_append_to_library(ws2)
+        ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+    endif()
+
+endif()

+ 142 - 0
arch/wec7/ua_architecture.h

@@ -0,0 +1,142 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Stephan Kantelberg
+ */
+
+#ifdef UA_ARCHITECTURE_WEC7
+
+#ifndef PLUGINS_ARCH_WEC7_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_WEC7_UA_ARCHITECTURE_H_
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE
+#endif
+
+/* Disable some security warnings on MSVC */
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#include "stdint.h"
+#ifdef UNDER_CE
+#define MAX_STRERROR 31
+static char *errorStrings[]= {"Error 0","","No such file or directory","","","","","Arg list too long",
+                              "Exec format error","Bad file number","","","Not enough core","Permission denied","","",
+                              "","File exists","Cross-device link","","","","Invalid argument","","Too many open files",
+                              "","","","No space left on device","","","","","Math argument","Result too large","",
+                              "Resource deadlock would occur", "Unknown error under wince"};
+
+char *strerror(int errnum);
+#endif
+
+#include <stdlib.h>
+#if defined(_WIN32)
+# include <malloc.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <winsock2.h>
+#include <windows.h>
+#include <ws2tcpip.h>
+
+#ifdef _MSC_VER
+# ifndef UNDER_CE
+#  include <io.h> //access
+#  define UA_access _access
+# endif
+#else
+# include <unistd.h> //access and tests
+# define UA_access access
+#endif
+
+#define ssize_t int
+#define OPTVAL_TYPE char
+#ifndef UA_sleep_ms
+# define UA_sleep_ms(X) Sleep(X)
+#else /* UA_sleep_ms */
+/* With this one can define its own UA_sleep_ms using a preprocessor define.
+E.g. see unit tests. */
+void UA_sleep_ms(size_t ms);
+#endif
+
+// Windows does not support ansi colors
+// #define UA_ENABLE_LOG_COLORS
+
+#if defined(__MINGW32__) //mingw defines SOCKET as long long unsigned int, giving errors in logging and when comparing with UA_Int32
+# define UA_SOCKET int
+# define UA_INVALID_SOCKET -1
+#else
+# define UA_SOCKET SOCKET
+# define UA_INVALID_SOCKET INVALID_SOCKET
+#endif
+#define UA_ERRNO WSAGetLastError()
+#define UA_INTERRUPTED WSAEINTR
+#define UA_AGAIN WSAEWOULDBLOCK
+#define UA_EAGAIN EAGAIN
+#define UA_WOULDBLOCK WSAEWOULDBLOCK
+#define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
+
+#define UA_fd_set(fd, fds) FD_SET((UA_SOCKET)fd, fds)
+#define UA_fd_isset(fd, fds) FD_ISSET((UA_SOCKET)fd, fds)
+
+#ifdef UNDER_CE
+#define UA_ERRNO WSAGetLastError()
+#endif
+
+#define UA_getnameinfo getnameinfo
+#define UA_send(sockfd, buf, len, flags) send(sockfd, buf, (int)(len), flags)
+#define UA_recv recv
+#define UA_sendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, (const char*)(buf), (int)(len), flags, dest_addr, (int) (addrlen))
+#define UA_recvfrom(sockfd, buf, len, flags, src_addr, addrlen) recvfrom(sockfd, (char*)(buf), (int)(len), flags, src_addr, addrlen)
+#define UA_htonl htonl
+#define UA_ntohl ntohl
+#define UA_close closesocket
+#define UA_select(nfds, readfds, writefds, exceptfds, timeout) select((int)(nfds), readfds, writefds, exceptfds, timeout)
+#define UA_shutdown shutdown
+#define UA_socket socket
+#define UA_bind bind
+#define UA_listen listen
+#define UA_accept accept
+#define UA_connect(sockfd, addr, addrlen) connect(sockfd, addr, (int)(addrlen))
+#define UA_getaddrinfo getaddrinfo
+#define UA_getsockopt getsockopt
+#define UA_setsockopt(sockfd, level, optname, optval, optlen) setsockopt(sockfd, level, optname, (const char*) (optval), optlen)
+#define UA_freeaddrinfo freeaddrinfo
+#define UA_gethostname gethostname
+#define UA_inet_pton InetPton
+
+#ifdef maxStringLength //defined in mingw64
+# undef maxStringLength
+#endif
+
+#define UA_free free
+#define UA_malloc malloc
+#define UA_calloc calloc
+#define UA_realloc realloc
+
+#define UA_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
+
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    LPVOID errno_str = NULL; \
+    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
+    NULL, WSAGetLastError(), \
+    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
+    (LPWSTR)&errno_str, \
+    0, NULL); \
+    LOG; \
+    LocalFree(errno_str); \
+}
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
+
+#include "../ua_architecture_functions.h"
+
+/* Fix redefinition of SLIST_ENTRY on mingw winnt.h */
+#ifdef SLIST_ENTRY
+# undef SLIST_ENTRY
+#endif
+
+#endif /* PLUGINS_ARCH_WEC7_UA_ARCHITECTURE_H_ */
+
+#endif /* UA_ARCHITECTURE_WEC7 */

+ 53 - 0
arch/wec7/ua_architecture_functions.c

@@ -0,0 +1,53 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Stephan Kantelberg
+ */
+
+#ifdef UA_ARCHITECTURE_WEC7
+
+#include "ua_types.h"
+
+#undef UA_fileExists
+UA_Boolean UA_fileExists(const char* path) {
+  FILE *fp = fopen(path,"rb");
+  UA_Boolean exists = (fp==NULL);
+  if(fp)
+      fclose(fp);
+  return exists;
+}
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  u_long iMode = 0;
+  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;;
+}
+
+#ifdef UNDER_CE
+char *strerror(int errnum)
+{
+    if (errnum > MAX_STRERROR)
+        return errorStrings[MAX_STRERROR];
+    else
+        return errorStrings[errnum];
+}
+#endif
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  u_long iMode = 1;
+  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;;
+}
+
+void UA_initialize_architecture_network(void){
+  WSADATA wsaData;
+  WSAStartup(MAKEWORD(2, 2), &wsaData);
+}
+
+void UA_deinitialize_architecture_network(void){
+  WSACleanup();
+}
+
+#endif /* UA_ARCHITECTURE_WEC7 */

+ 53 - 0
arch/wec7/ua_clock.c

@@ -0,0 +1,53 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Stephan Kantelberg
+ */
+
+#ifdef UA_ARCHITECTURE_WEC7
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE
+#endif
+
+#include "ua_types.h"
+#include <time.h>
+/* Backup definition of SLIST_ENTRY on mingw winnt.h */
+# ifdef SLIST_ENTRY
+#  pragma push_macro("SLIST_ENTRY")
+#  undef SLIST_ENTRY
+#  define POP_SLIST_ENTRY
+# endif
+# include <windows.h>
+/* restore definition */
+# ifdef POP_SLIST_ENTRY
+#  undef SLIST_ENTRY
+#  undef POP_SLIST_ENTRY
+#  pragma pop_macro("SLIST_ENTRY")
+# endif
+
+UA_DateTime UA_DateTime_now(void) {
+    /* Windows filetime has the same definition as UA_DateTime */
+    FILETIME ft;
+    SYSTEMTIME st;
+    GetSystemTime(&st);
+    SystemTimeToFileTime(&st, &ft);
+    ULARGE_INTEGER ul;
+    ul.LowPart = ft.dwLowDateTime;
+    ul.HighPart = ft.dwHighDateTime;
+    return (UA_DateTime)ul.QuadPart;
+}
+
+UA_Int64 UA_DateTime_localTimeUtcOffset(void) {
+    return 0;
+}
+
+UA_DateTime UA_DateTime_nowMonotonic(void) {
+    LARGE_INTEGER freq, ticks;
+    QueryPerformanceFrequency(&freq);
+    QueryPerformanceCounter(&ticks);
+    UA_Double ticks2dt = UA_DATETIME_SEC / (UA_Double)freq.QuadPart;
+    return (UA_DateTime)(ticks.QuadPart * ticks2dt);
+}
+
+#endif /* UA_ARCHITECTURE_WEC7 */

+ 1 - 1
plugins/ua_log_stdout.c

@@ -1,5 +1,5 @@
 /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. 
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  *
  *    Copyright 2016-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  *    Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA

+ 1 - 1
src/server/ua_services_discovery.c

@@ -1,6 +1,6 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  *    Copyright 2014-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  *    Copyright 2014-2016 (c) Sten Grüner