diff --git a/APP_Framework/Applications/control_app/s7_demo/s7_demo.c b/APP_Framework/Applications/control_app/s7_demo/s7_demo.c index 59bd83219..7579f7aa3 100644 --- a/APP_Framework/Applications/control_app/s7_demo/s7_demo.c +++ b/APP_Framework/Applications/control_app/s7_demo/s7_demo.c @@ -1,10 +1,11 @@ #include "snap7.h" #include +#include "lwip/sys.h" static S7Object Client; static unsigned char Buffer[65536]; // 64 K buffer -static char Address[20]="192.168.250.252"; // PLC IP Address 192.168.250.8 +static char* Address="192.168.250.252"; // plc 250.8, pc 250.252 static int Rack = 0, Slot = 1; // Default Rack and Slot static int Area = S7AreaDB, DBNumber = 13, Start = 0, Amount = 4, WordLen = S7WLByte; // Default Rack and Slot static int bRead = 1; // By default read @@ -18,9 +19,9 @@ static int CliConnect() if (Check(Client, res, "UNIT Connection")) { Cli_GetPduLength(Client, Requested, Negotiated); - KPrintf(" Connected to : %s (Rack=%d, Slot=%d)\n", Address, Rack, Slot); - KPrintf(" PDU Requested : %d bytes\n", Requested); - KPrintf(" PDU Negotiated : %d bytes\n", Negotiated); + printf(" Connected to : %s (Rack=%d, Slot=%d)\n", Address, Rack, Slot); + printf(" PDU Requested : %d bytes\n", Requested); + printf(" PDU Negotiated : %d bytes\n", Negotiated); }; return !res; } @@ -56,11 +57,19 @@ void PerformTasks() } } -void s7_demo() +void s7_demo(int argc, char *argv[]) { + if(argc >= 2) + { + Address = argv[1]; + } + printf(" Connected to : %s", Address); // Client Creation Client = Cli_Create(); + ETH_BSP_Config(); + lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr); + // Connection if (CliConnect()) { diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap7_libmain.cpp b/APP_Framework/Framework/control/plc/interoperability/s7/snap7_libmain.cpp index f782d4cb7..49c42e811 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap7_libmain.cpp +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap7_libmain.cpp @@ -43,28 +43,6 @@ void libdone(void) // in future expansions here can be inserted some destruction code } -#ifdef OS_WINDOWS -BOOL APIENTRY DllMain (HINSTANCE hInst, - DWORD reason, - LPVOID reserved) -{ - switch (reason) - { - case DLL_PROCESS_ATTACH: - libinit(); - break; - case DLL_PROCESS_DETACH: - libdone(); - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - } - return libresult; -} -#endif - //*************************************************************************** // CLIENT //*************************************************************************** diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.cpp b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.cpp index cf94a8eba..bce175864 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.cpp +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.cpp @@ -57,21 +57,13 @@ longword TSnapBase::SwapDWord(longword Value) //--------------------------------------------------------------------------- void Msg_CloseSocket(socket_t FSocket) { - #ifdef OS_WINDOWS - closesocket(FSocket); - #else close(FSocket); - #endif } //--------------------------------------------------------------------------- longword Msg_GetSockAddr(socket_t FSocket) { sockaddr_in RemoteSin; - #ifdef OS_WINDOWS - int namelen = sizeof(RemoteSin); - #else uint32_t namelen = sizeof(RemoteSin); - #endif namelen=sizeof(sockaddr_in); if (getpeername(FSocket,(struct sockaddr*)&RemoteSin, &namelen)==0) return RemoteSin.sin_addr.s_addr; @@ -128,33 +120,21 @@ void TMsgSocket::GetSin(sockaddr_in sin, char *Address, u_short &Port) //--------------------------------------------------------------------------- void TMsgSocket::GetLocal() { - #ifdef OS_WINDOWS - int namelen = sizeof(LocalSin); - #else - uint32_t namelen = sizeof(LocalSin); - #endif + uint32_t namelen = sizeof(LocalSin); if (getsockname(FSocket, (struct sockaddr*)&LocalSin, &namelen)==0) GetSin(LocalSin, LocalAddress, LocalPort); } //--------------------------------------------------------------------------- void TMsgSocket::GetRemote() { - #ifdef OS_WINDOWS - int namelen = sizeof(RemoteSin); - #else - uint32_t namelen = sizeof(RemoteSin); - #endif + uint32_t namelen = sizeof(RemoteSin); if (getpeername(FSocket,(struct sockaddr*)&RemoteSin, &namelen)==0) GetSin(RemoteSin, RemoteAddress, RemotePort); } //--------------------------------------------------------------------------- int TMsgSocket::GetLastSocketError() { -#ifdef OS_WINDOWS - return WSAGetLastError(); -#else return errno; -#endif } //--------------------------------------------------------------------------- void TMsgSocket::Purge() @@ -178,8 +158,9 @@ void TMsgSocket::CreateSocket() DestroySocket(); LastTcpError=0; FSocket =socket(AF_INET, SOCK_STREAM, IPPROTO_TCP ); - if (FSocket!=INVALID_SOCKET) - SetSocketOptions(); + if (FSocket!=INVALID_SOCKET){ + SetSocketOptions(); + } else LastTcpError =GetLastSocketError(); } @@ -209,11 +190,7 @@ void TMsgSocket::DestroySocket() { if (shutdown(FSocket, SD_SEND)==0) Purge(); - #ifdef OS_WINDOWS - closesocket(FSocket); - #else close(FSocket); - #endif FSocket=INVALID_SOCKET; } LastTcpError=0; @@ -223,13 +200,8 @@ int TMsgSocket::WaitingData() { int result = 0; u_long x = 0; -#ifdef OS_WINDOWS - if (ioctlsocket(FSocket, FIONREAD, &x) == 0) - result = x; -#else if (ioctl(FSocket, FIONREAD, &x) == 0) result = x; -#endif if (result>MaxPacketSize) result = MaxPacketSize; return result; @@ -270,9 +242,9 @@ void TMsgSocket::SetSocketOptions() int KeepAlive = 1; LastTcpError=0; SockCheck(setsockopt(FSocket, IPPROTO_TCP, TCP_NODELAY,(char*)&NoDelay, sizeof(NoDelay))); - - if (LastTcpError==0) + if (LastTcpError==0){ SockCheck(setsockopt(FSocket, SOL_SOCKET, SO_KEEPALIVE,(char*)&KeepAlive, sizeof(KeepAlive))); + } } //--------------------------------------------------------------------------- int TMsgSocket::SockCheck(int SockResult) @@ -321,7 +293,6 @@ bool TMsgSocket::CanRead(int Timeout) FD_ZERO(&FDset); FD_SET(FSocket, &FDset); - x = select(FSocket + 1, &FDset, NULL, NULL, &TimeV); //<-Ignore this warning in 64bit Visual Studio if (x==(int)SOCKET_ERROR) { @@ -348,10 +319,13 @@ int TMsgSocket::SckConnect() CreateSocket(); if (LastTcpError == 0) { flags = fcntl(FSocket, F_GETFL, 0); - if (flags >= 0) { - if (fcntl(FSocket, F_SETFL, flags | O_NONBLOCK) != -1) { + if (flags >= 0) { + // lwip defines O_NONBLOCK as 1 + #define LWIP_O_NONBLOCK 1 + int setfl_res = fcntl(FSocket, F_SETFL, flags | LWIP_O_NONBLOCK); + if (setfl_res != -1) { n = connect(FSocket, (struct sockaddr*)&RemoteSin, sizeof(RemoteSin)); - if (n < 0) { + if (n < 0) { if (errno != EINPROGRESS) { LastTcpError = GetLastSocketError(); } @@ -429,11 +403,7 @@ void TMsgSocket::ForceClose() if(FSocket != INVALID_SOCKET) { try { - #ifdef OS_WINDOWS - closesocket(FSocket); - #else close(FSocket); - #endif } catch (...) { } FSocket=INVALID_SOCKET; @@ -617,12 +587,8 @@ TRawSocketPinger::~TRawSocketPinger() { if (FSocket!=INVALID_SOCKET) { - #ifdef OS_WINDOWS - closesocket(FSocket); - #else - close(FSocket); - #endif - FSocket=INVALID_SOCKET; + close(FSocket); + FSocket=INVALID_SOCKET; }; } //--------------------------------------------------------------------------- @@ -759,11 +725,7 @@ bool RawSocketsCheck() Result=RawSocket != INVALID_SOCKET; if (Result) - #ifdef OS_WINDOWS - closesocket(RawSocket); - #else close(RawSocket); - #endif return Result; } diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h index 9253cb0c8..61c8c767f 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h @@ -29,14 +29,7 @@ #include "snap_platform.h" #include "snap_sysutils.h" #include "errno.h" -//---------------------------------------------------------------------------- -//---------------------------------------------------------------------------- -// Non blocking connection to avoid root priviledges under UNIX -// i.e. raw socket pinger is not more used. -// Thanks to Rolf Stalder that made it ;) -//---------------------------------------------------------------------------- -#include //---------------------------------------------------------------------------- typedef int socket_t; @@ -183,9 +176,6 @@ class TPinger private: PRawSocketPinger RawPinger; bool RawAvail; -#ifdef OS_WINDOWS - bool WinPing(longword ip_addr, int Timeout); -#endif bool RawPing(longword ip_addr, int Timeout); public: TPinger(); diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_platform.h b/APP_Framework/Framework/control/plc/interoperability/s7/snap_platform.h index e0379c1ae..913496e5c 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_platform.h +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_platform.h @@ -30,6 +30,7 @@ #include #include #include +#include // fcntl related status definition is different from linux #include #include diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.c b/APP_Framework/Framework/transform_layer/nuttx/transform.c index b31989482..82c7d6fb3 100644 --- a/APP_Framework/Framework/transform_layer/nuttx/transform.c +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.c @@ -95,6 +95,12 @@ int PrivTaskDelay(int32_t ms) return usleep(ms); } +uint32_t PrivGetTickTime(){ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} + /*********************fs**************************/ /************************Driver Posix Transform***********************/ diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.h b/APP_Framework/Framework/transform_layer/nuttx/transform.h index 7f21e332a..3810bf3ec 100644 --- a/APP_Framework/Framework/transform_layer/nuttx/transform.h +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.h @@ -190,6 +190,7 @@ int PrivTaskStartup(pthread_t *thread); int PrivTaskDelete(pthread_t thread, int sig); void PrivTaskQuit(void *value_ptr); int PrivTaskDelay(int32_t ms); +uint32_t PrivGetTickTime(); /*********************driver*************************/ diff --git a/Ubiquitous/XiUOS/Makefile b/Ubiquitous/XiUOS/Makefile index 51b129141..82913424c 100755 --- a/Ubiquitous/XiUOS/Makefile +++ b/Ubiquitous/XiUOS/Makefile @@ -7,8 +7,8 @@ MAKEFLAGS += --no-print-directory support :=kd233 stm32f407-st-discovery maix-go stm32f407zgt6 aiit-riscv64-board aiit-arm32-board hifive1-rev-B hifive1-emulator k210-emulator cortex-m3-emulator cortex-m4-emulator ok1052-c gapuino stm32f103-nano gd32vf103_rvstar cortex-m0-emulator SRC_DIR:= - -export BOARD ?=kd233 +# kd233 +export BOARD ?=ok1052-c ifeq ($(filter $(BOARD),$(support)),) $(warning "You should choose board like this:make BOARD=kd233") diff --git a/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/opt.h b/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/opt.h index 0d427d229..6dca07f94 100644 --- a/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/opt.h +++ b/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/opt.h @@ -2009,7 +2009,7 @@ * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. */ #if !defined LWIP_SO_RCVBUF || defined __DOXYGEN__ -#define LWIP_SO_RCVBUF 0 +#define LWIP_SO_RCVBUF 1 #endif /** @@ -3292,7 +3292,7 @@ * SOCKETS_DEBUG: Enable debugging in sockets.c. */ #if !defined SOCKETS_DEBUG || defined __DOXYGEN__ -#define SOCKETS_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_ON #endif /**