diff --git a/APP_Framework/Framework/connection/industrial_network/Kconfig b/APP_Framework/Framework/connection/industrial_network/Kconfig index 6a1486e30..2795791b1 100644 --- a/APP_Framework/Framework/connection/industrial_network/Kconfig +++ b/APP_Framework/Framework/connection/industrial_network/Kconfig @@ -13,3 +13,12 @@ config CONNECTION_ADAPTER_POWERLINK if CONNECTION_ADAPTER_POWERLINK source "$APP_DIR/Framework/connection/industrial_network/powerlink/Kconfig" endif + +config CONNECTION_ADAPTER_FREEMODBUSTCP + bool "Using FREEMODBUSTCP on industrial network adapter device" + default n + + if CONNECTION_ADAPTER_FREEMODBUSTCP + source "$APP_DIR/Framework/connection/industrial_network/freemodbus_tcp/Kconfig" + endif + \ No newline at end of file diff --git a/APP_Framework/Framework/connection/industrial_network/Makefile b/APP_Framework/Framework/connection/industrial_network/Makefile index 89b0289c9..2196c6baa 100644 --- a/APP_Framework/Framework/connection/industrial_network/Makefile +++ b/APP_Framework/Framework/connection/industrial_network/Makefile @@ -8,4 +8,8 @@ ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERCAT),y) SRC_DIR += ethercat endif +ifeq ($(CONFIG_CONNECTION_ADAPTER_FREEMODBUSTCP),y) + SRC_DIR += freemodbus_tcp +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/Kconfig b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/Kconfig similarity index 100% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/Kconfig rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/Kconfig diff --git a/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest new file mode 100644 index 000000000..2c28feb04 --- /dev/null +++ b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest @@ -0,0 +1,92 @@ + + +void LwipTcpRecvTest(void) +{ + uint8_t enet_port = 0; ///< test enet port 0 + + lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr); + + uint8_t *recv_data; + socklen_t sin_size; + int sock = -1, connected, bytes_received, i; + struct sockaddr_in server_addr, client_addr; + fd_set readset; + struct timeval timeout; + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__); + goto __exit; + } + + recv_data = (uint8_t *)malloc(128); + if (recv_data == NULL) { + KPrintf("No memory!\n"); + goto __exit; + } + + //configure tcp server param + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(tcp_server_port); + server_addr.sin_addr.s_addr = INADDR_ANY; + memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero)); + + if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { + KPrintf("Unable to bind!\n"); + goto __exit; + } + + if (listen(sock, 5) == -1) { + KPrintf("Listen error!\n"); + goto __exit; + } + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) ==-1) { + KPrintf("setsockopt failed!"); + goto __exit; + } + + while (1) { + FD_ZERO(&readset); + FD_SET(sock, &readset); + + if (select(sock + 1, &readset, NULL, NULL, &timeout) == 0) { + continue; + } + + sin_size = sizeof(struct sockaddr_in); + connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size); + while (1) { + bytes_received = recv(connected, recv_data, 128, 0); + if (bytes_received == 0) { + KPrintf("client disconnected (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); + break; + } else if (bytes_received < 0) { + KPrintf("recv error, client: (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); + break; + } else { + KPrintf("new client connected from (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); + KPrintf("recv data length %d Bytes\n", bytes_received); + for (i = 0; i < bytes_received; i ++) { + KPrintf("data 0x%x\n", recv_data[i]); + } + if (i = bytes_received) { + KPrintf("\r\n"); + memset(recv_data, 0, sizeof(recv_data)); + } + } + } + if (connected >= 0) { + closesocket(connected); + connected = -1; + break; + } + + __exit: + if (sock >= 0) closesocket(sock); + if (recv_data) free(recv_data); +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | +SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),TCPRecv, LwipTcpRecvTest, TCP Recv message); \ No newline at end of file diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/Makefile b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/Makefile similarity index 100% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/Makefile rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/Makefile diff --git a/APP_Framework/lib/freemodbus/mb.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mb.c similarity index 100% rename from APP_Framework/lib/freemodbus/mb.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mb.c diff --git a/APP_Framework/lib/freemodbus/mb.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mb.h similarity index 100% rename from APP_Framework/lib/freemodbus/mb.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mb.h diff --git a/APP_Framework/lib/freemodbus/mbconfig.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbconfig.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbconfig.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbconfig.h diff --git a/APP_Framework/lib/freemodbus/mbframe.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbframe.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbframe.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbframe.h diff --git a/APP_Framework/lib/freemodbus/mbfunc.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfunc.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbfunc.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfunc.h diff --git a/APP_Framework/lib/freemodbus/mbfunccoils.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfunccoils.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfunccoils.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfunccoils.c diff --git a/APP_Framework/lib/freemodbus/mbfuncdiag.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncdiag.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfuncdiag.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncdiag.c diff --git a/APP_Framework/lib/freemodbus/mbfuncdisc.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncdisc.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfuncdisc.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncdisc.c diff --git a/APP_Framework/lib/freemodbus/mbfuncholding.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncholding.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfuncholding.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncholding.c diff --git a/APP_Framework/lib/freemodbus/mbfuncinput.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncinput.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfuncinput.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncinput.c diff --git a/APP_Framework/lib/freemodbus/mbfuncother.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncother.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbfuncother.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbfuncother.c diff --git a/APP_Framework/lib/freemodbus/mbport.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbport.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbport.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbport.h diff --git a/APP_Framework/lib/freemodbus/mbproto.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbproto.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbproto.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbproto.h diff --git a/APP_Framework/lib/freemodbus/mbtcp.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbtcp.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbtcp.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbtcp.c diff --git a/APP_Framework/lib/freemodbus/mbtcp.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbtcp.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbtcp.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbtcp.h diff --git a/APP_Framework/lib/freemodbus/mbutils.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbutils.c similarity index 100% rename from APP_Framework/lib/freemodbus/mbutils.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbutils.c diff --git a/APP_Framework/lib/freemodbus/mbutils.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbutils.h similarity index 100% rename from APP_Framework/lib/freemodbus/mbutils.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/mbutils.h diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/port.h b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/port.h similarity index 100% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/port.h rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/port.h diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/portevent.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/portevent.c similarity index 100% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/portevent.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/portevent.c diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/portother.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/portother.c similarity index 100% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/portother.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/portother.c diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/porttcp.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/porttcp.c similarity index 99% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/porttcp.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/porttcp.c index e206bfd01..d32950d2b 100644 --- a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/porttcp.c +++ b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/porttcp.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c similarity index 85% rename from APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.c rename to APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c index a59723611..5526acae5 100644 --- a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.c +++ b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c @@ -33,11 +33,13 @@ #include #include #include +#include +#include "lwip/sys.h" +#include "lwip/sockets.h" /* ----------------------- Modbus includes ----------------------------------*/ #include "mb.h" #include "mbport.h" -#include "freemodbustcpserver.h" /* ----------------------- Defines ------------------------------------------*/ #define PROG "freemodbus" @@ -65,6 +67,7 @@ static BOOL bCreatePollingThread( void ); static enum ThreadState eGetPollingThreadState( void ); static void eSetPollingThreadState( enum ThreadState eNewState ); static void* pvPollingThread( void *pvParameter ); +int LWIPConnectSocket(uint16_t port); /* ----------------------- Start implementation -----------------------------*/ int MBServer() @@ -74,6 +77,17 @@ int MBServer() BOOL bDoExit; usRegHoldingBuf[5] = 123; usRegHoldingBuf[7] = 234; + + printf("%s ip %d.%d.%d.%d mask %d.%d.%d.%d gw %d.%d.%d.%d\n", __func__, + 192, 168, 250, 233, + 255, 255, 255, 255, + 192, 168, 250, 1); + uint8_t local_ip[4] = {192,168,250,233}; + uint8_t gateway[4] = {192,168,250,1}; + uint8_t netmask[4] = {255,255,255,0}; + lwip_config_tcp(0, local_ip, netmask, gateway); + printf("%s LWIPInit done\n", __func__); + if( eMBTCPInit( MB_TCP_PORT_USE_DEFAULT ) != MB_ENOERR ) { fprintf( stderr, "%s: can't initialize modbus stack!\r\n", PROG ); @@ -88,19 +102,23 @@ int MBServer() printf( "Can't start protocol stack! Already running?\r\n" ); } } - printf("%d %d\n",sizeof(usRegHoldingBuf),__LINE__); + printf("%d %d %s\n",sizeof(usRegHoldingBuf),__LINE__,__func__); + while(1) { for(int i =0; idone = &FreeModbusTcp_protocol_done; - return 0; -} \ No newline at end of file +// int FreeModbusTcpServerInit(struct ControlRecipe *p_recipe) +// { +// p_recipe->done = &FreeModbusTcp_protocol_done; +// return 0; +// } \ No newline at end of file diff --git a/APP_Framework/Framework/control/ipc_protocol/Kconfig b/APP_Framework/Framework/control/ipc_protocol/Kconfig index 371095a70..b6fd0d13f 100755 --- a/APP_Framework/Framework/control/ipc_protocol/Kconfig +++ b/APP_Framework/Framework/control/ipc_protocol/Kconfig @@ -14,11 +14,3 @@ if CONTROL_PROTOCOL_MODBUS_UART source "$APP_DIR/Framework/control/ipc_protocol/modbus_uart/Kconfig" endif -config CONTROL_PROTOCOL_FREEMODBUS_TCP_SERVER - bool "Using modbus_tcp_server control protocol" - default n - select CONTROL_USING_SOCKET - select LIB_USING_FREEMODBUS -if CONTROL_PROTOCOL_FREEMODBUS_TCP_SERVER - source "$APP_DIR/Framework/control/ipc_protocol/freemodbustcpserver/Kconfig" -endif diff --git a/APP_Framework/Framework/control/ipc_protocol/Makefile b/APP_Framework/Framework/control/ipc_protocol/Makefile index c2ad32548..a22240e9a 100755 --- a/APP_Framework/Framework/control/ipc_protocol/Makefile +++ b/APP_Framework/Framework/control/ipc_protocol/Makefile @@ -6,9 +6,5 @@ ifeq ($(CONFIG_CONTROL_PROTOCOL_MODBUS_UART), y) SRC_DIR := modbus_uart endif -ifeq ($(CONFIG_CONTROL_PROTOCOL_FREEMODBUS_TCP_SERVER), y) - SRC_DIR := freemodbustcpserver -endif - include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.h b/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.h deleted file mode 100644 index e1a303d6d..000000000 --- a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/freemodbustcpserver.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef FREEMODBUSTCP_H -#define FREEMODBUSTCP_H - -#include - -#endif \ No newline at end of file diff --git a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/test_recipe.json b/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/test_recipe.json deleted file mode 100644 index 64661f11b..000000000 --- a/APP_Framework/Framework/control/ipc_protocol/freemodbustcpserver/test_recipe.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "device_id": 1, - "device_name": "freemodbustcp", - "communication_type": 0, - "socket_config": { - "local_ip": "192.168.250.233", - "gateway": "192.168.250.1", - "netmask": "255.255.255.0", - "port": 502 - }, - "protocol_type": 2, - "read_period": 100 -} \ No newline at end of file diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c b/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c index ddb35a542..bbe9b20f5 100644 --- a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c +++ b/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c @@ -220,7 +220,6 @@ cip_error_code_e read_value(int fd, const char *address, int length, byte_array_ response.length = BUFFER_SIZE; if (cip_read_response(fd, &response)) ret = cip_analysis_read_byte(response, out_bytes); - // printf("%s %hu\n",__func__,response.data); free(response.data); } free(core_cmd.data); diff --git a/APP_Framework/lib/Kconfig b/APP_Framework/lib/Kconfig index d1838f585..8f9b35eda 100755 --- a/APP_Framework/lib/Kconfig +++ b/APP_Framework/lib/Kconfig @@ -15,5 +15,4 @@ menu "app lib" source "$APP_DIR/lib/embedded_database/Kconfig" source "$APP_DIR/lib/lorawan/Kconfig" source "$APP_DIR/lib/mqtt/Kconfig" - source "$APP_DIR/lib/freemodbus/Kconfig" endmenu diff --git a/APP_Framework/lib/Makefile b/APP_Framework/lib/Makefile index 28ba32301..2033da4ac 100644 --- a/APP_Framework/lib/Makefile +++ b/APP_Framework/lib/Makefile @@ -22,8 +22,8 @@ ifeq ($(CONFIG_TOOL_USING_MQTT),y) SRC_DIR += mqtt endif -ifeq ($(CONFIG_LIB_USING_FREEMODBUS),y) - SRC_DIR += freemodbus -endif +# ifeq ($(CONFIG_LIB_USING_FREEMODBUS),y) +# SRC_DIR += freemodbus +# endif include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/lib/freemodbus/Kconfig b/APP_Framework/lib/freemodbus/Kconfig deleted file mode 100755 index af05c629d..000000000 --- a/APP_Framework/lib/freemodbus/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -menu "lib using freemodbus" - menuconfig LIB_USING_FREEMODBUS - bool "USING freemodbus" - default n -endmenu diff --git a/APP_Framework/lib/freemodbus/Makefile b/APP_Framework/lib/freemodbus/Makefile deleted file mode 100755 index a72b1a41e..000000000 --- a/APP_Framework/lib/freemodbus/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -SRC_FILES := $(wildcard ./*.c) - -include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/resources/ethernet/cmd_lwip/Makefile b/Ubiquitous/XiZi_IIoT/resources/ethernet/cmd_lwip/Makefile index 5cb85ac11..327983fc6 100755 --- a/Ubiquitous/XiZi_IIoT/resources/ethernet/cmd_lwip/Makefile +++ b/Ubiquitous/XiZi_IIoT/resources/ethernet/cmd_lwip/Makefile @@ -1,4 +1,4 @@ # SRC_FILES := ping.c lwip_ping_demo.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c -SRC_FILES := ping.c lwip_ping_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c +SRC_FILES := ping.c lwip_ping_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c lwip_tcp_demo.c include $(KERNEL_ROOT)/compiler.mk