forked from xuos/xiuos
optimize control framework using socket, support LwIP and W5500(need to add init/socket apis)
This commit is contained in:
parent
9ad282c39e
commit
f8b845ca62
|
@ -7,10 +7,28 @@ menuconfig SUPPORT_CONTROL_FRAMEWORK
|
|||
select LIB_USING_CJSON
|
||||
|
||||
if SUPPORT_CONTROL_FRAMEWORK
|
||||
config BSP_USING_SERIAL_485
|
||||
config CONTROL_USING_SERIAL_485
|
||||
bool
|
||||
default n
|
||||
|
||||
config CONTROL_USING_SOCKET
|
||||
bool
|
||||
default n
|
||||
if CONTROL_USING_SOCKET
|
||||
choice
|
||||
prompt "select socket lib"
|
||||
default CONTROL_SOCKET_LWIP
|
||||
|
||||
config CONTROL_SOCKET_LWIP
|
||||
bool "support socket, using LwIP"
|
||||
select BSP_USING_LWIP
|
||||
|
||||
config CONTROL_SOCKET_W5500
|
||||
bool "support socket, using W5500"
|
||||
select BSP_USING_W5500
|
||||
endchoice
|
||||
endif
|
||||
|
||||
config CONTROL_RECIPE_FILE
|
||||
string "control framework recipe file name"
|
||||
default "test_recipe.json"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
config CONTROL_PROTOCOL_MODBUS_TCP
|
||||
bool "Using modbus_tcp control protocol"
|
||||
default n
|
||||
select BSP_USING_LWIP
|
||||
select CONTROL_USING_SOCKET
|
||||
if CONTROL_PROTOCOL_MODBUS_TCP
|
||||
source "$APP_DIR/Framework/control/ipc_protocol/modbus_tcp/Kconfig"
|
||||
endif
|
||||
|
|
|
@ -75,6 +75,7 @@ static void ModbusTcpTransformRecvBuffToData(ModbusTcpReadItem *p_read_item, uin
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/**
|
||||
* @description: Modbus Tcp Get Data From Socket
|
||||
* @param socket - socket
|
||||
|
@ -133,6 +134,7 @@ static int ModbusTcpGetData(int32_t socket, ModbusTcpReadItem *p_read_item)
|
|||
}
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @description: Modbus Tcp Data Info Init
|
||||
|
@ -312,6 +314,7 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
|
||||
while (1) {
|
||||
for (i = 0; i < control_protocol->recipe->read_item_count; i ++) {
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/*only connect socket when close socket or init*/
|
||||
while (ControlConnectSocket(&plc_socket) < 0) {
|
||||
PrivTaskDelay(1000);
|
||||
|
@ -320,6 +323,7 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
ModbusTcpForamatWriteData((ModbusTcpReadItem *)modbus_tcp_read_item + i);
|
||||
|
||||
ModbusTcpGetData(plc_socket.socket, (ModbusTcpReadItem *)modbus_tcp_read_item + i);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*read all variable item data, put them into circular_area*/
|
||||
|
@ -360,7 +364,9 @@ int ModbusTcpClose(struct ControlProtocol *control_protocol)
|
|||
{
|
||||
CircularAreaAppRelease(g_write_data);
|
||||
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
ControlDisconnectSocket(&plc_socket);
|
||||
#endif
|
||||
|
||||
ControlProtocolCloseDef();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
config CONTROL_PROTOCOL_FINS
|
||||
bool "Using fins control protocol"
|
||||
default n
|
||||
select BSP_USING_LWIP
|
||||
select CONTROL_USING_SOCKET
|
||||
if CONTROL_PROTOCOL_FINS
|
||||
source "$APP_DIR/Framework/control/plc_protocol/fins/Kconfig"
|
||||
endif
|
||||
|
|
|
@ -154,6 +154,7 @@ static int FinsTransformRecvBuffToData(FinsReadItem *p_read_item, uint8_t *recv_
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/**
|
||||
* @description: Fins Protocol Handshake
|
||||
* @param socket - socket
|
||||
|
@ -242,6 +243,7 @@ static int FinsGetData(int32_t socket, FinsReadItem *p_read_item)
|
|||
}
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @description: Fins Data Info Init
|
||||
|
@ -303,6 +305,7 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
|
||||
while (1) {
|
||||
for (i = 0; i < control_protocol->recipe->read_item_count; i ++) {
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/*only connect socket when close socket or init*/
|
||||
while (ControlConnectSocket(&plc_socket) < 0) {
|
||||
PrivTaskDelay(1000);
|
||||
|
@ -320,6 +323,7 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
plc_socket.secondary_connect_flag = 1;
|
||||
|
||||
FinsGetData(plc_socket.socket, (FinsReadItem *)fins_read_item + i);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*read all variable item data, put them into circular_area*/
|
||||
|
@ -352,7 +356,9 @@ int FinsOpen(struct ControlProtocol *control_protocol)
|
|||
*/
|
||||
int FinsClose(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
ControlDisconnectSocket(&plc_socket);
|
||||
#endif
|
||||
|
||||
ControlProtocolCloseDef();
|
||||
|
||||
|
|
|
@ -3,27 +3,27 @@ choice
|
|||
default CONTROL_PROTOCOL_MELSEC_1E
|
||||
|
||||
config CONTROL_PROTOCOL_MELSEC_1E
|
||||
bool "support melsec_1e protocol, using TCP"
|
||||
select BSP_USING_LWIP
|
||||
bool "support melsec_1e protocol, using SOCKET"
|
||||
select CONTROL_USING_SOCKET
|
||||
|
||||
config CONTROL_PROTOCOL_MELSEC_3E_Q_L
|
||||
bool "support melsec_3e_q_l protocol, using TCP"
|
||||
select BSP_USING_LWIP
|
||||
bool "support melsec_3e_q_l protocol, using SOCKET"
|
||||
select CONTROL_USING_SOCKET
|
||||
|
||||
config CONTROL_PROTOCOL_MELSEC_3E_IQ_R
|
||||
bool "support melsec_3e_iq_r protocol, using TCP"
|
||||
select BSP_USING_LWIP
|
||||
bool "support melsec_3e_iq_r protocol, using SOCKET"
|
||||
select CONTROL_USING_SOCKET
|
||||
|
||||
config CONTROL_PROTOCOL_MELSEC_1C
|
||||
bool "support melsec_1c protocol, using SERIAL"
|
||||
select BSP_USING_SERIAL_485
|
||||
select CONTROL_USING_SERIAL_485
|
||||
|
||||
config CONTROL_PROTOCOL_MELSEC_3C
|
||||
bool "support melsec_3c protocol, using SERIAL"
|
||||
select BSP_USING_SERIAL_485
|
||||
select CONTROL_USING_SERIAL_485
|
||||
endchoice
|
||||
|
||||
if BSP_USING_SERIAL_485
|
||||
if CONTROL_USING_SERIAL_485
|
||||
if ADD_XIZI_FETURES
|
||||
config CONTROL_FRAMEWORK_UART_485_DIR
|
||||
int "control framework 485 direction pin number"
|
||||
|
|
|
@ -575,7 +575,7 @@ static int MelsecTransformRecvBuffToData(MelsecReadItem *p_read_item, uint8_t *r
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/**
|
||||
* @description: Melsec Get Data From Socket
|
||||
* @param socket - socket
|
||||
|
@ -675,7 +675,7 @@ void *ReceivePlcDataTask(void *parameter)
|
|||
if ((PROTOCOL_MELSEC_1C == control_protocol->protocol_type) || (PROTOCOL_MELSEC_3C == control_protocol->protocol_type)) {
|
||||
MelsecGetDataBySerial((MelsecReadItem *)melsec_read_item + i);
|
||||
} else {
|
||||
#ifdef BSP_USING_LWIP
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/*only connect socket when close socket or init*/
|
||||
while (ControlConnectSocket(&plc_socket) < 0) {
|
||||
PrivTaskDelay(1000);
|
||||
|
@ -717,7 +717,7 @@ int MelsecOpen(struct ControlProtocol *control_protocol)
|
|||
int MelsecClose(struct ControlProtocol *control_protocol)
|
||||
{
|
||||
if ((PROTOCOL_MELSEC_1C != control_protocol->protocol_type) && (PROTOCOL_MELSEC_3C != control_protocol->protocol_type)) {
|
||||
#ifdef BSP_USING_LWIP
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
ControlDisconnectSocket(&plc_socket);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ extern int MelsecProtocolInit(struct ControlRecipe *p_recipe);
|
|||
extern int ModbusTcpProtocolInit(struct ControlRecipe *p_recipe);
|
||||
#endif
|
||||
|
||||
#ifdef CONTROL_PROTOCOL_MODBUS_UART
|
||||
extern int ModbusUartProtocolInit(struct ControlRecipe *p_recipe);
|
||||
#endif
|
||||
|
||||
/*
|
||||
CONTROL FRAMEWORK READ DATA FORMAT:
|
||||
| HEAD |device_id|read data length|read item count| data |
|
||||
|
@ -73,6 +77,9 @@ static struct ControlProtocolInitParam protocol_init[] =
|
|||
#ifdef CONTROL_PROTOCOL_MODBUS_TCP
|
||||
{ PROTOCOL_MODBUS_TCP, ModbusTcpProtocolInit },
|
||||
#endif
|
||||
#ifdef CONTROL_PROTOCOL_MODBUS_UART
|
||||
{ PROTOCOL_MODBUS_UART, ModbusUartProtocolInit },
|
||||
#endif
|
||||
|
||||
{ PROTOCOL_END, NULL },
|
||||
};
|
||||
|
@ -210,7 +217,7 @@ void ControlPrintfList(char name[5], uint8_t *number_list, uint16_t length)
|
|||
printf("\n**************************************\n");
|
||||
}
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
/**
|
||||
* @description: Control Framework Connect Socket
|
||||
* @param p_plc - basic socket plc pointer
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <control_io.h>
|
||||
|
||||
#ifdef BSP_USING_SERIAL_485
|
||||
#ifdef CONTROL_USING_SERIAL_485
|
||||
static int pin_fd = 0;
|
||||
static int uart_fd = 0;
|
||||
|
||||
|
@ -119,9 +119,14 @@ void SocketInit(char *ip, char *mask, char *gw)
|
|||
ip[0], ip[1], ip[2], ip[3],
|
||||
mask[0], mask[1], mask[2], mask[3],
|
||||
gw[0], gw[1], gw[2], gw[3]);
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
#ifdef BSP_USING_LWIP
|
||||
lwip_config_tcp(0, ip, mask, gw);
|
||||
#endif
|
||||
#ifdef BSP_USING_W5500
|
||||
//to do
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +139,7 @@ void SocketInit(char *ip, char *mask, char *gw)
|
|||
*/
|
||||
void SerialInit(uint32_t baud_rate, uint8_t data_bits, uint8_t stop_bits, uint8_t check_mode)
|
||||
{
|
||||
#ifdef BSP_USING_SERIAL_485
|
||||
#ifdef CONTROL_USING_SERIAL_485
|
||||
Uart485Init(baud_rate, data_bits, stop_bits, check_mode);
|
||||
#endif
|
||||
}
|
||||
|
@ -147,7 +152,7 @@ void SerialInit(uint32_t baud_rate, uint8_t data_bits, uint8_t stop_bits, uint8_
|
|||
*/
|
||||
void SerialWrite(uint8_t *write_data, int length)
|
||||
{
|
||||
#ifdef BSP_USING_SERIAL_485
|
||||
#ifdef CONTROL_USING_SERIAL_485
|
||||
Set485Output();
|
||||
PrivTaskDelay(20);
|
||||
|
||||
|
@ -166,7 +171,7 @@ void SerialWrite(uint8_t *write_data, int length)
|
|||
*/
|
||||
int SerialRead(uint8_t *read_data, int length)
|
||||
{
|
||||
#ifdef BSP_USING_SERIAL_485
|
||||
#ifdef CONTROL_USING_SERIAL_485
|
||||
int data_size = 0;
|
||||
int data_recv_size = 0;
|
||||
|
||||
|
|
|
@ -24,20 +24,30 @@
|
|||
#include <transform.h>
|
||||
#include <list.h>
|
||||
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
#ifdef BSP_USING_LWIP
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CONTROL_USING_SOCKET
|
||||
#ifdef BSP_USING_LWIP
|
||||
#define socket_write lwip_write
|
||||
#define socket_read lwip_read
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_W5500
|
||||
//to do
|
||||
#define socket_write
|
||||
#define socket_read
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Control Framework Socket Init*/
|
||||
void SocketInit(char *ip, char *mask, char *gw);
|
||||
|
||||
|
|
Loading…
Reference in New Issue