forked from xuos/xiuos
commit
27657d6219
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
char tcp_socket_ip[] = {192, 168, 250, 252};
|
char tcp_socket_ip[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
#define TCP_BUF_SIZE 1024
|
#define TCP_DEMO_BUF_SIZE 65535
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Code
|
* Code
|
||||||
|
@ -46,17 +46,15 @@ char tcp_socket_ip[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
static void tcp_recv_demo(void *arg)
|
static void tcp_recv_demo(void *arg)
|
||||||
{
|
{
|
||||||
lw_print("tcp_recv_demo start.\n");
|
int fd = -1, clientfd;
|
||||||
|
|
||||||
int fd = -1;
|
|
||||||
char *recv_buf;
|
|
||||||
struct sockaddr_in tcp_addr, server_addr;
|
|
||||||
int recv_len;
|
int recv_len;
|
||||||
|
char *recv_buf;
|
||||||
|
struct sockaddr_in tcp_addr;
|
||||||
socklen_t addr_len;
|
socklen_t addr_len;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
recv_buf = (char *)malloc(TCP_BUF_SIZE);
|
recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE);
|
||||||
if (recv_buf == NULL)
|
if (recv_buf == NULL)
|
||||||
{
|
{
|
||||||
lw_print("No memory\n");
|
lw_print("No memory\n");
|
||||||
|
@ -72,7 +70,7 @@ static void tcp_recv_demo(void *arg)
|
||||||
|
|
||||||
tcp_addr.sin_family = AF_INET;
|
tcp_addr.sin_family = AF_INET;
|
||||||
tcp_addr.sin_addr.s_addr = INADDR_ANY;
|
tcp_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
tcp_addr.sin_port = htons(LOCAL_PORT_SERVER);
|
tcp_addr.sin_port = htons(LWIP_LOCAL_PORT);
|
||||||
memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero));
|
memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero));
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1)
|
if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1)
|
||||||
|
@ -81,16 +79,30 @@ static void tcp_recv_demo(void *arg)
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
lw_print("tcp bind sucess, start to receive.\n");
|
lw_print("tcp bind success, start to receive.\n");
|
||||||
lw_print("\n\nLocal Port:%d\n\n", LOCAL_PORT_SERVER);
|
lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
|
||||||
|
|
||||||
|
// setup socket fd as listening mode
|
||||||
|
if (listen(fd, 5) != 0 )
|
||||||
|
{
|
||||||
|
lw_print("Unable to listen\n");
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// accept client connection
|
||||||
|
clientfd = accept(fd, (struct sockaddr *)&tcp_addr, (socklen_t*)&addr_len);
|
||||||
|
lw_print("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
memset(recv_buf, 0, TCP_BUF_SIZE);
|
memset(recv_buf, 0, TCP_DEMO_BUF_SIZE);
|
||||||
recv_len = recvfrom(fd, recv_buf, TCP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len);
|
recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len);
|
||||||
lw_pr_info("Receive from : %s\n", inet_ntoa(server_addr.sin_addr));
|
if(recv_len > 0)
|
||||||
lw_pr_info("Receive data : %s\n\n", recv_buf);
|
{
|
||||||
sendto(fd, recv_buf, recv_len, 0, (struct sockaddr*)&server_addr, addr_len);
|
lw_pr_info("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr));
|
||||||
|
lw_pr_info("Receive data : %d - %s\n\n", recv_len, recv_buf);
|
||||||
|
}
|
||||||
|
sendto(clientfd, recv_buf, recv_len, 0, (struct sockaddr*)&tcp_addr, addr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
__exit:
|
__exit:
|
||||||
|
@ -116,7 +128,7 @@ void tcp_socket_recv_run(int argc, char *argv[])
|
||||||
|
|
||||||
ETH_BSP_Config();
|
ETH_BSP_Config();
|
||||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||||
sys_thread_new("tcp_recv_demo", tcp_recv_demo, NULL, 4096, 15);
|
sys_thread_new("tcp_recv_demo", tcp_recv_demo, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||||
|
@ -124,11 +136,12 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
||||||
|
|
||||||
static void tcp_send_demo(void *arg)
|
static void tcp_send_demo(void *arg)
|
||||||
{
|
{
|
||||||
int cnt = TEST_LWIP_TIMES;
|
int cnt = LWIP_DEMO_TIMES;
|
||||||
lw_print("tcp_send_demo start.\n");
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
char send_msg[128];
|
char send_msg[128];
|
||||||
|
|
||||||
|
lw_print("%s start\n", __func__);
|
||||||
|
|
||||||
memset(send_msg, 0, sizeof(send_msg));
|
memset(send_msg, 0, sizeof(send_msg));
|
||||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -139,8 +152,8 @@ static void tcp_send_demo(void *arg)
|
||||||
|
|
||||||
struct sockaddr_in tcp_sock;
|
struct sockaddr_in tcp_sock;
|
||||||
tcp_sock.sin_family = AF_INET;
|
tcp_sock.sin_family = AF_INET;
|
||||||
tcp_sock.sin_port = htons(TARGET_PORT_CLIENT);
|
tcp_sock.sin_port = htons(LWIP_TARGET_PORT);
|
||||||
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0],tcp_socket_ip[1],tcp_socket_ip[2],tcp_socket_ip[3]));
|
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0], tcp_socket_ip[1], tcp_socket_ip[2], tcp_socket_ip[3]));
|
||||||
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
|
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
|
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
|
||||||
|
@ -150,14 +163,14 @@ static void tcp_send_demo(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
lw_print("tcp connect success, start to send.\n");
|
lw_print("tcp connect success, start to send.\n");
|
||||||
lw_print("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
|
lw_pr_info("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
|
||||||
|
|
||||||
while (cnt --)
|
while (cnt --)
|
||||||
{
|
{
|
||||||
lw_print("Lwip client is running.\n");
|
lw_print("Lwip client is running.\n");
|
||||||
snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt);
|
snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt);
|
||||||
sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
|
sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
|
||||||
lw_print("Send tcp msg: %s ", send_msg);
|
lw_pr_info("Send tcp msg: %s ", send_msg);
|
||||||
MdelayKTask(1000);
|
MdelayKTask(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +191,8 @@ void tcp_socket_send_run(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
ETH_BSP_Config();
|
ETH_BSP_Config();
|
||||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||||
sys_thread_new("tcp socket", tcp_send_demo, NULL, 4096, 25);
|
sys_thread_new("tcp socket", tcp_send_demo, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||||
|
|
|
@ -78,7 +78,7 @@ static void udp_recv_demo(void *arg)
|
||||||
|
|
||||||
udp_addr.sin_family = AF_INET;
|
udp_addr.sin_family = AF_INET;
|
||||||
udp_addr.sin_addr.s_addr = INADDR_ANY;
|
udp_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
udp_addr.sin_port = htons(LOCAL_PORT_SERVER);
|
udp_addr.sin_port = htons(LWIP_LOCAL_PORT);
|
||||||
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
|
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
|
||||||
|
|
||||||
if (bind(socket_fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
|
if (bind(socket_fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
|
||||||
|
@ -88,7 +88,7 @@ static void udp_recv_demo(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
lw_print("UDP bind sucess, start to receive.\n");
|
lw_print("UDP bind sucess, start to receive.\n");
|
||||||
lw_print("\n\nLocal Port:%d\n\n", LOCAL_PORT_SERVER);
|
lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +135,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
||||||
|
|
||||||
static void udp_send_demo(void *arg)
|
static void udp_send_demo(void *arg)
|
||||||
{
|
{
|
||||||
int cnt = TEST_LWIP_TIMES;
|
int cnt = LWIP_DEMO_TIMES;
|
||||||
char send_str[128];
|
char send_str[128];
|
||||||
|
|
||||||
lw_print("udp_send_demo start.\n");
|
lw_print("udp_send_demo start.\n");
|
||||||
|
@ -152,7 +152,7 @@ static void udp_send_demo(void *arg)
|
||||||
|
|
||||||
struct sockaddr_in udp_sock;
|
struct sockaddr_in udp_sock;
|
||||||
udp_sock.sin_family = AF_INET;
|
udp_sock.sin_family = AF_INET;
|
||||||
udp_sock.sin_port = htons(TARGET_PORT_CLIENT);
|
udp_sock.sin_port = htons(LWIP_TARGET_PORT);
|
||||||
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3]));
|
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3]));
|
||||||
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
|
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,9 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
//#define ua_print KPrintf
|
|
||||||
#define ua_trace() KPrintf("ua: [%s] %d pass!\n", __func__, __LINE__)
|
|
||||||
|
|
||||||
#define TCP_LOCAL_PORT 4840
|
#define TCP_LOCAL_PORT 4840
|
||||||
|
#define UA_URL_SIZE 100
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Prototypes
|
* Prototypes
|
||||||
|
@ -41,24 +40,19 @@
|
||||||
* Variables
|
* Variables
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
const char *test_uri = "opc.tcp://192.168.250.5:4840";
|
char test_ua_ip[] = {192, 168, 250, 5};
|
||||||
const char *test_cb_str = "tcp client connected\r\n";
|
|
||||||
|
|
||||||
char test_ua_gw[] = {192, 168, 250, 5};
|
|
||||||
|
|
||||||
static pthread_t eth_input_id = 0;
|
|
||||||
static pthread_t ua_demo_id;
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Code
|
* Code
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
void *test_ua_get_server_info(void *param);
|
|
||||||
|
|
||||||
static void test_ua_connect(void *arg)
|
static void test_ua_connect(void *arg)
|
||||||
{
|
{
|
||||||
struct netif net;
|
struct netif net;
|
||||||
UA_StatusCode retval;
|
UA_StatusCode retval;
|
||||||
|
char ua_uri[UA_URL_SIZE];
|
||||||
|
|
||||||
|
memset(ua_uri, 0, sizeof(ua_uri));
|
||||||
|
|
||||||
UA_Client *client = UA_Client_new();
|
UA_Client *client = UA_Client_new();
|
||||||
|
|
||||||
|
@ -71,7 +65,10 @@ static void test_ua_connect(void *arg)
|
||||||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||||
UA_ClientConfig_setDefault(config);
|
UA_ClientConfig_setDefault(config);
|
||||||
|
|
||||||
retval = UA_Client_connect(client, test_uri);
|
snprintf(ua_uri, UA_URL_SIZE, "opc.tcp://%d.%d.%d.%d:4840",
|
||||||
|
test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]);
|
||||||
|
|
||||||
|
retval = UA_Client_connect(client, ua_uri);
|
||||||
if (retval != UA_STATUSCODE_GOOD)
|
if (retval != UA_STATUSCODE_GOOD)
|
||||||
{
|
{
|
||||||
ua_print("ua: [%s] ret %x\n", __func__, retval);
|
ua_print("ua: [%s] ret %x\n", __func__, retval);
|
||||||
|
@ -85,7 +82,7 @@ static void test_ua_connect(void *arg)
|
||||||
void test_ua_connect_thr(void *arg)
|
void test_ua_connect_thr(void *arg)
|
||||||
{
|
{
|
||||||
ETH_BSP_Config();
|
ETH_BSP_Config();
|
||||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw);
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||||
test_ua_connect(NULL);
|
test_ua_connect(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,16 +97,16 @@ void test_sh_ua_connect(void)
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||||
UaConnect, test_sh_ua_connect, Test Opc UA connection);
|
UaConnect, test_sh_ua_connect, Test Opc UA connection);
|
||||||
|
|
||||||
void *test_ua_get_server_info(void *param)
|
void test_ua_browser_objects(void *param)
|
||||||
{
|
{
|
||||||
UA_Client *client = UA_Client_new();
|
UA_Client *client = UA_Client_new();
|
||||||
|
|
||||||
ua_print("ua: [%s] start ...\n", __func__);
|
ua_pr_info("ua: [%s] start ...\n", __func__);
|
||||||
|
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
{
|
{
|
||||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||||
|
@ -119,12 +116,69 @@ void *test_ua_get_server_info(void *param)
|
||||||
if(retval != UA_STATUSCODE_GOOD) {
|
if(retval != UA_STATUSCODE_GOOD) {
|
||||||
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||||
UA_Client_delete(client);
|
UA_Client_delete(client);
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||||
|
ua_pr_info("--- start read time ---\n", __func__);
|
||||||
|
|
||||||
ua_read_time(client);
|
ua_read_time(client);
|
||||||
|
|
||||||
|
ua_pr_info("--- get server info ---\n", __func__);
|
||||||
|
ua_browser_objects(client);
|
||||||
|
|
||||||
|
/* Clean up */
|
||||||
|
UA_Client_disconnect(client);
|
||||||
|
UA_Client_delete(client); /* Disconnects the client internally */
|
||||||
|
}
|
||||||
|
|
||||||
|
void *test_sh_ua_brower_objects(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if(argc == 2)
|
||||||
|
{
|
||||||
|
if(isdigit(argv[1][0]))
|
||||||
|
{
|
||||||
|
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||||
|
{
|
||||||
|
lw_pr_info("input wrong ip\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ETH_BSP_Config();
|
||||||
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||||
|
sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||||
|
UaObj, test_sh_ua_brower_objects, UaObj [IP]);
|
||||||
|
|
||||||
|
void test_ua_get_info(void *param)
|
||||||
|
{
|
||||||
|
UA_Client *client = UA_Client_new();
|
||||||
|
|
||||||
|
ua_pr_info("ua: [%s] start ...\n", __func__);
|
||||||
|
|
||||||
|
if (client == NULL)
|
||||||
|
{
|
||||||
|
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||||
|
UA_ClientConfig_setDefault(config);
|
||||||
|
|
||||||
|
UA_StatusCode retval = UA_Client_connect(client, OPC_SERVER);
|
||||||
|
if(retval != UA_STATUSCODE_GOOD) {
|
||||||
|
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||||
|
UA_Client_delete(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||||
|
ua_pr_info("--- get server info ---\n", __func__);
|
||||||
ua_get_server_info(client);
|
ua_get_server_info(client);
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
|
@ -132,29 +186,26 @@ void *test_ua_get_server_info(void *param)
|
||||||
UA_Client_delete(client); /* Disconnects the client internally */
|
UA_Client_delete(client); /* Disconnects the client internally */
|
||||||
}
|
}
|
||||||
|
|
||||||
void *test_ua_get_server_info_thr(void *arg)
|
void *test_sh_ua_get_info(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ETH_BSP_Config();
|
if(argc == 2)
|
||||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw);
|
{
|
||||||
test_ua_get_server_info(NULL);
|
if(isdigit(argv[1][0]))
|
||||||
}
|
{
|
||||||
|
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||||
void *test_sh_ua_get_server_info(void *param)
|
{
|
||||||
{
|
lw_pr_info("input wrong ip\n");
|
||||||
int result = 0;
|
return NULL;
|
||||||
pthread_attr_t attr;
|
}
|
||||||
|
}
|
||||||
attr.schedparam.sched_priority = 15;
|
|
||||||
attr.stacksize = 4096;
|
|
||||||
|
|
||||||
result = pthread_create(&ua_demo_id, &attr, test_ua_get_server_info_thr, NULL);
|
|
||||||
if (0 == result) {
|
|
||||||
lw_print("test_ua_get_server_info %d successfully!\n", __func__, ua_demo_id);
|
|
||||||
} else {
|
|
||||||
lw_print("test_ua_get_server_info failed! error code is %d\n", __func__, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ETH_BSP_Config();
|
||||||
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||||
|
sys_thread_new("ua object", test_ua_browser_objects, NULL, 4096, 15);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||||
UaGetInfo, test_sh_ua_get_server_info, Get information from OpcUA server);
|
UaInfo, test_sh_ua_get_info, UaInfo [IP]);
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
|
#include "ua_api.h"
|
||||||
#define ua_print KPrintf
|
|
||||||
#define ua_trace() KPrintf("ua: [%s] line %d checked!\n", __func__, __LINE__)
|
|
||||||
|
|
||||||
#if LWIP_DNS
|
#if LWIP_DNS
|
||||||
|
|
||||||
|
@ -7147,6 +7145,8 @@ encodeWithExchangeBuffer(const void *ptr, const UA_DataType *type, Ctx *ctx) {
|
||||||
ctx->pos = oldpos; /* Set to the last known good position and exchange */
|
ctx->pos = oldpos; /* Set to the last known good position and exchange */
|
||||||
ret = exchangeBuffer(ctx);
|
ret = exchangeBuffer(ctx);
|
||||||
UA_CHECK_STATUS(ret, return ret);
|
UA_CHECK_STATUS(ret, return ret);
|
||||||
|
|
||||||
|
ua_print("ua: [%s] exchange kind %d ret %d\n", __func__, type->typeKind, ret);
|
||||||
ret = encodeBinaryJumpTable[type->typeKind](ptr, type, ctx);
|
ret = encodeBinaryJumpTable[type->typeKind](ptr, type, ctx);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -7493,6 +7493,11 @@ Array_encodeBinary(const void *src, size_t length, const UA_DataType *type, Ctx
|
||||||
ret = Array_encodeBinaryComplex((uintptr_t)src, length, type, ctx);
|
ret = Array_encodeBinaryComplex((uintptr_t)src, length, type, ctx);
|
||||||
}
|
}
|
||||||
UA_assert(ret != UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED);
|
UA_assert(ret != UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED);
|
||||||
|
|
||||||
|
//tst by wly
|
||||||
|
ua_debug("ua: [%s] src %p len %d %d type %p <%d> <%d> %p ret %d\n", __func__,
|
||||||
|
src, length, signed_length, *type, type->typeKind, type->overlayable, ctx, ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8335,6 +8340,26 @@ encodeBinaryStruct(const void *src, const UA_DataType *type, Ctx *ctx) {
|
||||||
const UA_DataType *mt = m->memberType;
|
const UA_DataType *mt = m->memberType;
|
||||||
ptr += m->padding;
|
ptr += m->padding;
|
||||||
|
|
||||||
|
if(mt->typeKind > UA_DATATYPEKINDS)
|
||||||
|
{
|
||||||
|
ua_debug("ua: [%s] %d type %d %p ptr %p failed\n", __func__, i, mt->typeKind, m->memberType, ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] > %d < %d mt %p %d %d dep %d msg %p %p:<%x> <%d> isArry %d ret %d\n", __func__,
|
||||||
|
i,
|
||||||
|
type->membersSize,
|
||||||
|
mt,
|
||||||
|
mt->typeKind,
|
||||||
|
mt->memSize,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
src,
|
||||||
|
((UA_TcpMessageHeader *)src)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)src)->messageSize,
|
||||||
|
m->isArray,
|
||||||
|
ret);
|
||||||
|
|
||||||
/* Array. Buffer-exchange is done inside Array_encodeBinary if required. */
|
/* Array. Buffer-exchange is done inside Array_encodeBinary if required. */
|
||||||
if(m->isArray) {
|
if(m->isArray) {
|
||||||
const size_t length = *((const size_t*)ptr);
|
const size_t length = *((const size_t*)ptr);
|
||||||
|
@ -8348,6 +8373,21 @@ encodeBinaryStruct(const void *src, const UA_DataType *type, Ctx *ctx) {
|
||||||
/* Scalar */
|
/* Scalar */
|
||||||
ret = encodeWithExchangeBuffer((const void*)ptr, mt, ctx);
|
ret = encodeWithExchangeBuffer((const void*)ptr, mt, ctx);
|
||||||
UA_assert(ret != UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED);
|
UA_assert(ret != UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED);
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] >> %d < %d mt %p %d %d dep %d msg %p %p:<%x> <%d> isArry %d ret %d\n", __func__,
|
||||||
|
i,
|
||||||
|
type->membersSize,
|
||||||
|
mt,
|
||||||
|
mt->typeKind,
|
||||||
|
mt->memSize,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
src,
|
||||||
|
((UA_TcpMessageHeader *)src)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)src)->messageSize,
|
||||||
|
m->isArray,
|
||||||
|
ret);
|
||||||
|
|
||||||
ptr += mt->memSize;
|
ptr += mt->memSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8584,20 +8624,70 @@ decodeBinaryStructure(void *dst, const UA_DataType *type, Ctx *ctx) {
|
||||||
const UA_DataType *mt = m->memberType;
|
const UA_DataType *mt = m->memberType;
|
||||||
ptr += m->padding;
|
ptr += m->padding;
|
||||||
|
|
||||||
|
if(mt->typeKind >= UA_DATATYPEKINDS)
|
||||||
|
{
|
||||||
|
ua_debug("ua: [%s] fail %d < %d mt %p %d %d dep %d msg %p %p:<%x> <%d>\n", __func__,
|
||||||
|
i,
|
||||||
|
membersSize,
|
||||||
|
mt,
|
||||||
|
mt->typeKind,
|
||||||
|
mt->memSize,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
dst,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] > %d < %d mt %p %d %d dep %d msg %p %p:<%x> <%d> isArry %d ret %d\n", __func__,
|
||||||
|
i,
|
||||||
|
membersSize,
|
||||||
|
mt,
|
||||||
|
mt->typeKind,
|
||||||
|
mt->memSize,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
dst,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize,
|
||||||
|
m->isArray,
|
||||||
|
ret);
|
||||||
|
|
||||||
/* Array */
|
/* Array */
|
||||||
if(m->isArray) {
|
if(m->isArray) {
|
||||||
size_t *length = (size_t*)ptr;
|
size_t *length = (size_t*)ptr;
|
||||||
ptr += sizeof(size_t);
|
ptr += sizeof(size_t);
|
||||||
ret = Array_decodeBinary((void *UA_RESTRICT *UA_RESTRICT)ptr, length, mt , ctx);
|
ret = Array_decodeBinary((void *UA_RESTRICT *UA_RESTRICT)ptr, length, mt , ctx);
|
||||||
ptr += sizeof(void*);
|
ptr += sizeof(void*);
|
||||||
|
ua_debug("ua: [%s] %d ret %d ptr %p len %d\n", __func__, i, ret, ptr, length);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scalar */
|
/* Scalar */
|
||||||
ret = decodeBinaryJumpTable[mt->typeKind]((void *UA_RESTRICT)ptr, mt, ctx);
|
ret = decodeBinaryJumpTable[mt->typeKind]((void *UA_RESTRICT)ptr, mt, ctx);
|
||||||
ptr += mt->memSize;
|
ptr += mt->memSize;
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] >> %d < %d dep %d msg %p %p:<%x> <%d> ret %d\n", __func__,
|
||||||
|
i,
|
||||||
|
membersSize,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
dst,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize,
|
||||||
|
ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] >>> dep %d msg %p %p:<%x> <%d> ret %d\n", __func__,
|
||||||
|
ctx->depth,
|
||||||
|
ptr,
|
||||||
|
dst,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize,
|
||||||
|
ret);
|
||||||
|
|
||||||
ctx->depth--;
|
ctx->depth--;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -8739,8 +8829,18 @@ UA_decodeBinaryInternal(const UA_ByteString *src, size_t *offset,
|
||||||
|
|
||||||
/* Decode */
|
/* Decode */
|
||||||
memset(dst, 0, type->memSize); /* Initialize the value */
|
memset(dst, 0, type->memSize); /* Initialize the value */
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] t %d mem %d len %d off %d pos %d end %d dst %p type %x size %x\n", __func__,
|
||||||
|
type->typeKind, type->memSize, src->length, *offset, *ctx.pos, *ctx.end,
|
||||||
|
dst, ((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize);
|
||||||
|
|
||||||
status ret = decodeBinaryJumpTable[type->typeKind](dst, type, &ctx);
|
status ret = decodeBinaryJumpTable[type->typeKind](dst, type, &ctx);
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] -> t %d dst %p type %x size %x ret %d\n", __func__,
|
||||||
|
type->typeKind, dst, ((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize, ret);
|
||||||
|
|
||||||
if(UA_LIKELY(ret == UA_STATUSCODE_GOOD)) {
|
if(UA_LIKELY(ret == UA_STATUSCODE_GOOD)) {
|
||||||
/* Set the new offset */
|
/* Set the new offset */
|
||||||
*offset = (size_t)(ctx.pos - src->data) / sizeof(u8);
|
*offset = (size_t)(ctx.pos - src->data) / sizeof(u8);
|
||||||
|
@ -8748,7 +8848,16 @@ UA_decodeBinaryInternal(const UA_ByteString *src, size_t *offset,
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
UA_clear(dst, type);
|
UA_clear(dst, type);
|
||||||
memset(dst, 0, type->memSize);
|
memset(dst, 0, type->memSize);
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] => t %d dst %p type %x size %x\n", __func__,
|
||||||
|
type->typeKind, dst, ((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] #> off %d %p %p t %d dst %p type %x size %x\n", __func__, *offset,
|
||||||
|
ctx.pos, src->data,
|
||||||
|
type->typeKind, dst, ((UA_TcpMessageHeader *)dst)->messageTypeAndChunkType,
|
||||||
|
((UA_TcpMessageHeader *)dst)->messageSize);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18516,6 +18625,12 @@ processChunks(UA_SecureChannel *channel, void *application,
|
||||||
channel->decryptedChunksCount > channel->config.localMaxChunkCount) ||
|
channel->decryptedChunksCount > channel->config.localMaxChunkCount) ||
|
||||||
(channel->config.localMaxMessageSize != 0 &&
|
(channel->config.localMaxMessageSize != 0 &&
|
||||||
channel->decryptedChunksLength > channel->config.localMaxMessageSize)) {
|
channel->decryptedChunksLength > channel->config.localMaxMessageSize)) {
|
||||||
|
ua_print("ua: [%s] count %d max %d len %d mess %d\n",
|
||||||
|
channel->decryptedChunksCount,
|
||||||
|
channel->config.localMaxChunkCount,
|
||||||
|
channel->decryptedChunksLength,
|
||||||
|
channel->config.localMaxMessageSize
|
||||||
|
);
|
||||||
return UA_STATUSCODE_BADTCPMESSAGETOOLARGE;
|
return UA_STATUSCODE_BADTCPMESSAGETOOLARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18552,6 +18667,10 @@ extractCompleteChunk(UA_SecureChannel *channel, const UA_ByteString *buffer,
|
||||||
UA_StatusCode res =
|
UA_StatusCode res =
|
||||||
UA_decodeBinaryInternal(buffer, &initial_offset, &hdr,
|
UA_decodeBinaryInternal(buffer, &initial_offset, &hdr,
|
||||||
&UA_TRANSPORT[UA_TRANSPORT_TCPMESSAGEHEADER], NULL);
|
&UA_TRANSPORT[UA_TRANSPORT_TCPMESSAGEHEADER], NULL);
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] res %d buf %p offset %d hdr %d size %d\n", __func__, res, buffer, *offset,
|
||||||
|
hdr.messageTypeAndChunkType, hdr.messageSize);
|
||||||
|
|
||||||
UA_assert(res == UA_STATUSCODE_GOOD);
|
UA_assert(res == UA_STATUSCODE_GOOD);
|
||||||
(void)res; /* pacify compilers if assert is ignored */
|
(void)res; /* pacify compilers if assert is ignored */
|
||||||
UA_MessageType msgType = (UA_MessageType)
|
UA_MessageType msgType = (UA_MessageType)
|
||||||
|
@ -18563,7 +18682,10 @@ extractCompleteChunk(UA_SecureChannel *channel, const UA_ByteString *buffer,
|
||||||
if(hdr.messageSize < UA_SECURECHANNEL_MESSAGE_MIN_LENGTH)
|
if(hdr.messageSize < UA_SECURECHANNEL_MESSAGE_MIN_LENGTH)
|
||||||
return UA_STATUSCODE_BADTCPMESSAGETYPEINVALID;
|
return UA_STATUSCODE_BADTCPMESSAGETYPEINVALID;
|
||||||
if(hdr.messageSize > channel->config.recvBufferSize)
|
if(hdr.messageSize > channel->config.recvBufferSize)
|
||||||
|
{
|
||||||
|
ua_debug("lw: [%s] msg size %d rec %d\n", __func__, hdr.messageSize, channel->config.recvBufferSize);
|
||||||
return UA_STATUSCODE_BADTCPMESSAGETOOLARGE;
|
return UA_STATUSCODE_BADTCPMESSAGETOOLARGE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Incomplete chunk */
|
/* Incomplete chunk */
|
||||||
if(hdr.messageSize > remaining) {
|
if(hdr.messageSize > remaining) {
|
||||||
|
@ -44134,6 +44256,8 @@ UA_Client_run_iterate(UA_Client *client, UA_UInt32 timeout) {
|
||||||
client->sessionState < UA_SESSIONSTATE_ACTIVATED) {
|
client->sessionState < UA_SESSIONSTATE_ACTIVATED) {
|
||||||
retval = connectIterate(client, timeout);
|
retval = connectIterate(client, timeout);
|
||||||
notifyClientState(client);
|
notifyClientState(client);
|
||||||
|
lw_print("lw: [%s] ret %d timeout %d state %d ch %d\n", __func__, retval, timeout,
|
||||||
|
client->sessionState, client->channel.state);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45075,21 +45199,21 @@ connectIterate(UA_Client *client, UA_UInt32 timeout) {
|
||||||
return UA_STATUSCODE_BADCONNECTIONCLOSED;
|
return UA_STATUSCODE_BADCONNECTIONCLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ua_debug("ua: [%s] conn %d state %d handle %p\n", __func__, client->connectStatus,
|
||||||
|
client->connection.state, client->connection.handle);
|
||||||
|
|
||||||
/* The connection is closed. Reset the SecureChannel and open a new TCP
|
/* The connection is closed. Reset the SecureChannel and open a new TCP
|
||||||
* connection */
|
* connection */
|
||||||
if(client->connection.state == UA_CONNECTIONSTATE_CLOSED)
|
if(client->connection.state == UA_CONNECTIONSTATE_CLOSED)
|
||||||
return initConnect(client);
|
return initConnect(client);
|
||||||
|
|
||||||
ua_print("ua: [%s] state %d %d handle %p\n", __func__, client->connectStatus,
|
|
||||||
client->connection.state, client->connection.handle);
|
|
||||||
|
|
||||||
/* Poll the connection status */
|
/* Poll the connection status */
|
||||||
if(client->connection.state == UA_CONNECTIONSTATE_OPENING) {
|
if(client->connection.state == UA_CONNECTIONSTATE_OPENING) {
|
||||||
client->connectStatus =
|
client->connectStatus =
|
||||||
client->config.pollConnectionFunc(&client->connection, timeout,
|
client->config.pollConnectionFunc(&client->connection, timeout,
|
||||||
&client->config.logger);
|
&client->config.logger);
|
||||||
|
|
||||||
ua_print("ua: [%s] exit conn %x %d time %d handle %p\n", __func__,
|
ua_debug("ua: [%s] exit conn %x %d time %d handle %p\n", __func__,
|
||||||
client->connectStatus,
|
client->connectStatus,
|
||||||
client->connection.state, timeout, client->connection.handle);
|
client->connection.state, timeout, client->connection.handle);
|
||||||
|
|
||||||
|
@ -45175,6 +45299,7 @@ connectIterate(UA_Client *client, UA_UInt32 timeout) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lw_print("lw: [%s] sess %d conn %d\n", __func__, client->sessionState, client->connectStatus);
|
||||||
return client->connectStatus;
|
return client->connectStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45286,6 +45411,8 @@ connectSync(UA_Client *client) {
|
||||||
UA_DateTime now = UA_DateTime_nowMonotonic();
|
UA_DateTime now = UA_DateTime_nowMonotonic();
|
||||||
UA_DateTime maxDate = now + ((UA_DateTime)client->config.timeout * UA_DATETIME_MSEC);
|
UA_DateTime maxDate = now + ((UA_DateTime)client->config.timeout * UA_DATETIME_MSEC);
|
||||||
|
|
||||||
|
ua_print("ua; [%s] time %d\n", __func__, (UA_DateTime)client->config.timeout);
|
||||||
|
|
||||||
UA_StatusCode retval = initConnect(client);
|
UA_StatusCode retval = initConnect(client);
|
||||||
if(retval != UA_STATUSCODE_GOOD)
|
if(retval != UA_STATUSCODE_GOOD)
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -68096,6 +68223,9 @@ void
|
||||||
UA_Log_Stdout_log(void *context, UA_LogLevel level, UA_LogCategory category,
|
UA_Log_Stdout_log(void *context, UA_LogLevel level, UA_LogCategory category,
|
||||||
const char *msg, va_list args) {
|
const char *msg, va_list args) {
|
||||||
|
|
||||||
|
char str[120];
|
||||||
|
memset(str, 0, sizeof(str));
|
||||||
|
|
||||||
/* Assume that context is casted to UA_LogLevel */
|
/* Assume that context is casted to UA_LogLevel */
|
||||||
/* TODO we may later change this to a struct with bitfields to filter on category */
|
/* TODO we may later change this to a struct with bitfields to filter on category */
|
||||||
if ( context != NULL && (UA_LogLevel)(uintptr_t)context > level )
|
if ( context != NULL && (UA_LogLevel)(uintptr_t)context > level )
|
||||||
|
@ -68115,8 +68245,8 @@ UA_Log_Stdout_log(void *context, UA_LogLevel level, UA_LogCategory category,
|
||||||
|
|
||||||
KPrintf("%s/%s" ANSI_COLOR_RESET "\t",
|
KPrintf("%s/%s" ANSI_COLOR_RESET "\t",
|
||||||
logLevelNames[level], logCategoryNames[category]);
|
logLevelNames[level], logCategoryNames[category]);
|
||||||
|
vsnprintf(str, sizeof(str) - 1, msg, args);
|
||||||
KPrintf(msg, args);
|
KPrintf(msg, str);
|
||||||
KPrintf("\n");
|
KPrintf("\n");
|
||||||
|
|
||||||
// printf("\n");
|
// printf("\n");
|
||||||
|
@ -70191,7 +70321,7 @@ UA_Client * UA_Client_new() {
|
||||||
|
|
||||||
UA_StatusCode
|
UA_StatusCode
|
||||||
UA_ClientConfig_setDefault(UA_ClientConfig *config) {
|
UA_ClientConfig_setDefault(UA_ClientConfig *config) {
|
||||||
config->timeout = 5000;
|
config->timeout = 20000;
|
||||||
config->secureChannelLifeTime = 10 * 60 * 1000; /* 10 minutes */
|
config->secureChannelLifeTime = 10 * 60 * 1000; /* 10 minutes */
|
||||||
|
|
||||||
if(!config->logger.log) {
|
if(!config->logger.log) {
|
||||||
|
@ -70656,13 +70786,15 @@ UA_Log_Syslog_withLevel(UA_LogLevel minlevel) {
|
||||||
#define configTICK_RATE_HZ TICK_PER_SECOND
|
#define configTICK_RATE_HZ TICK_PER_SECOND
|
||||||
#define xTaskGetTickCount CurrentTicksGain
|
#define xTaskGetTickCount CurrentTicksGain
|
||||||
|
|
||||||
#define EHOSTUNREACH 113 /* No route to host */
|
|
||||||
#define EINPROGRESS 115 /* Operation now in progress */
|
|
||||||
#define EADDRINUSE 98 /* Address already in use */
|
#define EADDRINUSE 98 /* Address already in use */
|
||||||
#define EALREADY 114 /* Operation already in progress */
|
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||||
|
|
||||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
|
||||||
|
#define EHOSTUNREACH 113 /* No route to host */
|
||||||
|
#define EALREADY 114 /* Operation already in progress */
|
||||||
|
#define EINPROGRESS 115 /* Operation now in progress */
|
||||||
|
|
||||||
#ifdef UA_ARCHITECTURE_FREERTOSLWIP_POSIX_CLOCK
|
#ifdef UA_ARCHITECTURE_FREERTOSLWIP_POSIX_CLOCK
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,16 @@
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
|
|
||||||
#define OPC_SERVER "opc.tcp://192.168.250.5:4840"
|
#define OPC_SERVER "opc.tcp://192.168.250.5:4840"
|
||||||
#define ua_print printf
|
|
||||||
|
#define ua_print //printf
|
||||||
|
#define ua_trace() //printf("ua: [%s] line %d checked!\n", __func__, __LINE__)
|
||||||
|
#define ua_pr_info KPrintf
|
||||||
|
#define ua_debug
|
||||||
|
|
||||||
int ua_server_connect(void);
|
int ua_server_connect(void);
|
||||||
int ua_get_server_info(UA_Client *client);
|
int ua_get_server_info(UA_Client *client);
|
||||||
|
void ua_browser_objects(UA_Client *client);
|
||||||
|
void ua_browser_nodes(UA_Client *client);
|
||||||
void ua_read_time(UA_Client *client);
|
void ua_read_time(UA_Client *client);
|
||||||
int16 ua_test(void);
|
int16 ua_test(void);
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "ua_api.h"
|
||||||
#define OPC_SERVER "opc.tcp://192.168.250.5:4840"
|
|
||||||
#define ua_print printf
|
|
||||||
|
|
||||||
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
||||||
static void handler_TheAnswerChanged(UA_Client *client, UA_UInt32 subId, void *subContext,
|
static void handler_TheAnswerChanged(UA_Client *client, UA_UInt32 subId, void *subContext,
|
||||||
|
@ -32,7 +30,7 @@ static UA_StatusCode nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId
|
||||||
}
|
}
|
||||||
|
|
||||||
UA_NodeId *parent = (UA_NodeId *)handle;
|
UA_NodeId *parent = (UA_NodeId *)handle;
|
||||||
ua_print("%d, %d --- %d ---> NodeId %d, %d\n",
|
ua_pr_info("%d, %d --- %d ---> NodeId %d, %d\n",
|
||||||
parent->namespaceIndex, parent->identifier.numeric,
|
parent->namespaceIndex, parent->identifier.numeric,
|
||||||
referenceTypeId.identifier.numeric, childId.namespaceIndex,
|
referenceTypeId.identifier.numeric, childId.namespaceIndex,
|
||||||
childId.identifier.numeric);
|
childId.identifier.numeric);
|
||||||
|
@ -61,32 +59,42 @@ int ua_get_points(UA_Client *client)
|
||||||
endpointArray[i].endpointUrl.data);
|
endpointArray[i].endpointUrl.data);
|
||||||
}
|
}
|
||||||
UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
|
UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ua_browser_objects(UA_Client *client)
|
void ua_browser_objects(UA_Client *client)
|
||||||
{
|
{
|
||||||
/* Browse some objects */
|
/* Browse some objects */
|
||||||
ua_print("Browsing nodes in objects folder:\n");
|
ua_pr_info("Browsing nodes in objects folder:\n");
|
||||||
|
|
||||||
UA_BrowseRequest bReq;
|
UA_BrowseRequest bReq;
|
||||||
UA_BrowseRequest_init(&bReq);
|
UA_BrowseRequest_init(&bReq);
|
||||||
|
|
||||||
bReq.requestedMaxReferencesPerNode = 0;
|
bReq.requestedMaxReferencesPerNode = 0;
|
||||||
bReq.nodesToBrowse = UA_BrowseDescription_new();
|
bReq.nodesToBrowse = UA_BrowseDescription_new();
|
||||||
bReq.nodesToBrowseSize = 1;
|
bReq.nodesToBrowseSize = 1;
|
||||||
bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); /* browse objects folder */
|
bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); /* browse objects folder */
|
||||||
bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
|
bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
|
||||||
|
|
||||||
UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
|
UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq);
|
||||||
ua_print("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME");
|
|
||||||
for(size_t i = 0; i < bResp.resultsSize; ++i) {
|
ua_pr_info("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME");
|
||||||
for(size_t j = 0; j < bResp.results[i].referencesSize; ++j) {
|
|
||||||
|
for(size_t i = 0; i < bResp.resultsSize; ++i)
|
||||||
|
{
|
||||||
|
for(size_t j = 0; j < bResp.results[i].referencesSize; ++j)
|
||||||
|
{
|
||||||
UA_ReferenceDescription *ref = &(bResp.results[i].references[j]);
|
UA_ReferenceDescription *ref = &(bResp.results[i].references[j]);
|
||||||
if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC) {
|
if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC)
|
||||||
ua_print("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
{
|
||||||
|
ua_pr_info("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||||
ref->nodeId.nodeId.identifier.numeric, (int)ref->browseName.name.length,
|
ref->nodeId.nodeId.identifier.numeric, (int)ref->browseName.name.length,
|
||||||
ref->browseName.name.data, (int)ref->displayName.text.length,
|
ref->browseName.name.data, (int)ref->displayName.text.length,
|
||||||
ref->displayName.text.data);
|
ref->displayName.text.data);
|
||||||
} else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING) {
|
}
|
||||||
ua_print("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING)
|
||||||
|
{
|
||||||
|
ua_pr_info("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||||
(int)ref->nodeId.nodeId.identifier.string.length,
|
(int)ref->nodeId.nodeId.identifier.string.length,
|
||||||
ref->nodeId.nodeId.identifier.string.data,
|
ref->nodeId.nodeId.identifier.string.data,
|
||||||
(int)ref->browseName.name.length, ref->browseName.name.data,
|
(int)ref->browseName.name.length, ref->browseName.name.data,
|
||||||
|
@ -95,6 +103,7 @@ void ua_browser_objects(UA_Client *client)
|
||||||
/* TODO: distinguish further types */
|
/* TODO: distinguish further types */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ua_pr_info("\n");
|
||||||
UA_BrowseRequest_clear(&bReq);
|
UA_BrowseRequest_clear(&bReq);
|
||||||
UA_BrowseResponse_clear(&bResp);
|
UA_BrowseResponse_clear(&bResp);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +142,7 @@ UA_UInt32 ua_start_sub(UA_Client *client)
|
||||||
|
|
||||||
/* The first publish request should return the initial value of the variable */
|
/* The first publish request should return the initial value of the variable */
|
||||||
UA_Client_run_iterate(client, 1000);
|
UA_Client_run_iterate(client, 1000);
|
||||||
return subId;
|
return subId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ua_read_attr(UA_Client *client)
|
void ua_read_attr(UA_Client *client)
|
||||||
|
@ -165,7 +174,8 @@ void ua_read_attr(UA_Client *client)
|
||||||
wReq.nodesToWrite[0].value.value.data = &value;
|
wReq.nodesToWrite[0].value.value.data = &value;
|
||||||
UA_WriteResponse wResp = UA_Client_Service_write(client, wReq);
|
UA_WriteResponse wResp = UA_Client_Service_write(client, wReq);
|
||||||
if(wResp.responseHeader.serviceResult == UA_STATUSCODE_GOOD)
|
if(wResp.responseHeader.serviceResult == UA_STATUSCODE_GOOD)
|
||||||
ua_print("the new value is: %i\n", value);
|
ua_print("the new value is: %i\n", value);
|
||||||
|
|
||||||
UA_WriteRequest_clear(&wReq);
|
UA_WriteRequest_clear(&wReq);
|
||||||
UA_WriteResponse_clear(&wResp);
|
UA_WriteResponse_clear(&wResp);
|
||||||
|
|
||||||
|
@ -189,11 +199,14 @@ void ua_call_remote(UA_Client *client)
|
||||||
UA_Variant *output;
|
UA_Variant *output;
|
||||||
UA_StatusCode retval = UA_Client_call(client, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
|
UA_StatusCode retval = UA_Client_call(client, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
|
||||||
UA_NODEID_NUMERIC(1, 62541), 1, &input, &outputSize, &output);
|
UA_NODEID_NUMERIC(1, 62541), 1, &input, &outputSize, &output);
|
||||||
if(retval == UA_STATUSCODE_GOOD) {
|
if(retval == UA_STATUSCODE_GOOD)
|
||||||
|
{
|
||||||
ua_print("Method call was successful, and %lu returned values available.\n",
|
ua_print("Method call was successful, and %lu returned values available.\n",
|
||||||
(unsigned long)outputSize);
|
(unsigned long)outputSize);
|
||||||
UA_Array_delete(output, outputSize, &UA_TYPES[UA_TYPES_VARIANT]);
|
UA_Array_delete(output, outputSize, &UA_TYPES[UA_TYPES_VARIANT]);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ua_print("Method call was unsuccessful, and %x returned values available.\n", retval);
|
ua_print("Method call was unsuccessful, and %x returned values available.\n", retval);
|
||||||
}
|
}
|
||||||
UA_Variant_clear(&input);
|
UA_Variant_clear(&input);
|
||||||
|
@ -271,33 +284,16 @@ void ua_add_nodes(UA_Client *client)
|
||||||
|
|
||||||
int ua_get_server_info(UA_Client *client)
|
int ua_get_server_info(UA_Client *client)
|
||||||
{
|
{
|
||||||
UA_StatusCode retval;
|
ua_browser_objects(client);
|
||||||
|
|
||||||
/* Listing endpoints */
|
|
||||||
retval = ua_get_points(client);
|
|
||||||
if(retval != UA_STATUSCODE_GOOD) {
|
|
||||||
UA_Client_delete(client);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect to a server */
|
|
||||||
/* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */
|
|
||||||
retval = UA_Client_connect(client, OPC_SERVER);
|
|
||||||
if(retval != UA_STATUSCODE_GOOD) {
|
|
||||||
UA_Client_delete(client);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ua_browser_objects(client);
|
|
||||||
|
|
||||||
/* Same thing, this time using the node iterator... */
|
/* Same thing, this time using the node iterator... */
|
||||||
ua_browser_nodes(client);
|
ua_browser_nodes(client);
|
||||||
|
|
||||||
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
||||||
UA_Int32 subId = ua_start_sub(client);
|
UA_Int32 subId = ua_start_sub(client);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ua_read_attr(client);
|
ua_read_attr(client);
|
||||||
|
|
||||||
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
||||||
/* Take another look at the.answer */
|
/* Take another look at the.answer */
|
||||||
|
@ -308,11 +304,11 @@ int ua_get_server_info(UA_Client *client)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UA_ENABLE_METHODCALLS
|
#ifdef UA_ENABLE_METHODCALLS
|
||||||
ua_call_remote(client);
|
ua_call_remote(client);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UA_ENABLE_NODEMANAGEMENT
|
#ifdef UA_ENABLE_NODEMANAGEMENT
|
||||||
ua_add_nodes(client);
|
ua_add_nodes(client);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -216,7 +216,7 @@ void ethernetif_input(struct netif *netif)
|
||||||
/* pass all packets to ethernet_input, which decides what packets it supports */
|
/* pass all packets to ethernet_input, which decides what packets it supports */
|
||||||
if ((ret = netif->input(p, netif)) != ERR_OK)
|
if ((ret = netif->input(p, netif)) != ERR_OK)
|
||||||
{
|
{
|
||||||
// LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||||
lw_print("lw: [%s] ret %d p %p\n", __func__, ret, p);
|
lw_print("lw: [%s] ret %d p %p\n", __func__, ret, p);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -801,30 +801,30 @@ err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy)
|
if (copy)
|
||||||
{
|
{
|
||||||
/* Pbuf needs to be copied. */
|
/* Pbuf needs to be copied. */
|
||||||
|
|
||||||
p_copy = pbuf_alloc(PBUF_RAW, (uint16_t) p->tot_len, PBUF_POOL);
|
p_copy = pbuf_alloc(PBUF_RAW, (uint16_t) p->tot_len, PBUF_POOL);
|
||||||
if (p_copy == NULL)
|
if (p_copy == NULL)
|
||||||
{
|
{
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst = (uint8_t *) p_copy->payload;
|
dst = (uint8_t *) p_copy->payload;
|
||||||
for (q = p; q != NULL; q = q->next)
|
for (q = p; q != NULL; q = q->next)
|
||||||
{
|
{
|
||||||
LWIP_ASSERT("Copied bytes would exceed p->tot_len",
|
LWIP_ASSERT("Copied bytes would exceed p->tot_len",
|
||||||
(q->len + dst - (uint8_t *) p_copy->payload) <= p->tot_len);
|
(q->len + dst - (uint8_t *) p_copy->payload) <= p->tot_len);
|
||||||
memcpy(dst, (uint8_t *)q->payload, q->len);
|
memcpy(dst, (uint8_t *)q->payload, q->len);
|
||||||
dst += q->len;
|
dst += q->len;
|
||||||
}
|
}
|
||||||
LWIP_ASSERT("Copied bytes != p->tot_len",
|
LWIP_ASSERT("Copied bytes != p->tot_len",
|
||||||
(dst - (uint8_t *) p_copy->payload) == p->tot_len);
|
(dst - (uint8_t *) p_copy->payload) == p->tot_len);
|
||||||
p_copy->len = p_copy->tot_len = p->tot_len;
|
p_copy->len = p_copy->tot_len = p->tot_len;
|
||||||
|
|
||||||
p = p_copy;
|
p = p_copy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1490,6 +1490,9 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
|
||||||
assert(handle);
|
assert(handle);
|
||||||
assert(ringId < FSL_FEATURE_ENET_QUEUE);
|
assert(ringId < FSL_FEATURE_ENET_QUEUE);
|
||||||
|
|
||||||
|
|
||||||
|
// lw_print("lw: [%s] base %p handle %p ring %d\n", __func__, base, handle, ringId);
|
||||||
|
|
||||||
/* Clears status. */
|
/* Clears status. */
|
||||||
handle->rxBdCurrent[ringId]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
|
handle->rxBdCurrent[ringId]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
|
||||||
/* Sets the receive buffer descriptor with the empty flag. */
|
/* Sets the receive buffer descriptor with the empty flag. */
|
||||||
|
|
|
@ -195,6 +195,8 @@ void ethernetif_input( struct netif *netif);
|
||||||
|
|
||||||
void ETH_BSP_Config(void);
|
void ETH_BSP_Config(void);
|
||||||
|
|
||||||
|
int32 lwip_obtain_semaphore(struct netif *netif);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
|
@ -81,20 +81,13 @@
|
||||||
#include "enet_ethernetif.h"
|
#include "enet_ethernetif.h"
|
||||||
#include <transform.h>
|
#include <transform.h>
|
||||||
|
|
||||||
/* MAC address configuration. */
|
|
||||||
#define configMAC_ADDR { 0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
|
|
||||||
|
|
||||||
char lwip_ipaddr[] = {192, 168, 250, 253};
|
char lwip_ipaddr[] = {192, 168, 250, 253};
|
||||||
char lwip_netmask[] = {255, 255, 255, 0};
|
char lwip_netmask[] = {255, 255, 255, 0};
|
||||||
char lwip_gwaddr[] = {192, 168, 250, 252};
|
char lwip_gwaddr[] = {192, 168, 250, 252};
|
||||||
|
char lwip_flag = 0;
|
||||||
int errno;
|
|
||||||
int is_lwip_test = 0; //for lwip input thread
|
|
||||||
|
|
||||||
x_ticks_t lwip_sys_now;
|
x_ticks_t lwip_sys_now;
|
||||||
|
|
||||||
static int lwip_init_flag = 0;
|
|
||||||
|
|
||||||
struct sys_timeouts {
|
struct sys_timeouts {
|
||||||
struct sys_timeo *next;
|
struct sys_timeo *next;
|
||||||
};
|
};
|
||||||
|
@ -389,7 +382,7 @@ ip4_addr_t ipaddr;
|
||||||
ip4_addr_t netmask;
|
ip4_addr_t netmask;
|
||||||
ip4_addr_t gw;
|
ip4_addr_t gw;
|
||||||
|
|
||||||
void TcpIpInit(void)
|
void lwip_tcp_init(void)
|
||||||
{
|
{
|
||||||
tcpip_init(NULL, NULL);
|
tcpip_init(NULL, NULL);
|
||||||
|
|
||||||
|
@ -400,14 +393,9 @@ void TcpIpInit(void)
|
||||||
ip_addr_set_zero_ip4(&netmask);
|
ip_addr_set_zero_ip4(&netmask);
|
||||||
ip_addr_set_zero_ip4(&gw);
|
ip_addr_set_zero_ip4(&gw);
|
||||||
#else
|
#else
|
||||||
#ifdef SET_AS_SERVER
|
IP4_ADDR(&ipaddr, lwip_ipaddr[0], lwip_ipaddr[1], lwip_ipaddr[2], lwip_ipaddr[3]);
|
||||||
IP4_ADDR(&ipaddr,IP_ADDR0_SERVER,IP_ADDR1_SERVER,IP_ADDR2_SERVER,IP_ADDR3_SERVER);
|
IP4_ADDR(&netmask, lwip_netmask[0], lwip_netmask[1], lwip_netmask[2], lwip_netmask[3]);
|
||||||
#else
|
IP4_ADDR(&gw, lwip_gwaddr[0], lwip_gwaddr[1], lwip_gwaddr[2], lwip_gwaddr[3]);
|
||||||
IP4_ADDR(&ipaddr,IP_ADDR0_ClIENT,IP_ADDR1_ClIENT,IP_ADDR2_ClIENT,IP_ADDR3_ClIENT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IP4_ADDR(&netmask,NETMASK_ADDR0,NETMASK_ADDR1,NETMASK_ADDR2,NETMASK_ADDR3);
|
|
||||||
IP4_ADDR(&gw,GW_ADDR0,GW_ADDR1,GW_ADDR2,GW_ADDR3);
|
|
||||||
#endif /* USE_DHCP */
|
#endif /* USE_DHCP */
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
/* Initilialize the LwIP stack without RTOS */
|
/* Initilialize the LwIP stack without RTOS */
|
||||||
|
@ -420,13 +408,13 @@ void TcpIpInit(void)
|
||||||
if (netif_is_link_up(&gnetif))
|
if (netif_is_link_up(&gnetif))
|
||||||
{
|
{
|
||||||
/* When the netif is fully configured this function must be called */
|
/* When the netif is fully configured this function must be called */
|
||||||
KPrintf("TcpIpInit : netif_set_up\n");
|
KPrintf("%s : netif_set_up\n", __func__);
|
||||||
netif_set_up(&gnetif);
|
netif_set_up(&gnetif);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* When the netif link is down this function must be called */
|
/* When the netif link is down this function must be called */
|
||||||
KPrintf("TcpIpInit : netif_set_down\n");
|
KPrintf("%s : netif_set_down\n", __func__);
|
||||||
netif_set_down(&gnetif);
|
netif_set_down(&gnetif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,10 +450,14 @@ void lwip_input_thread(void *param)
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* Poll the driver, get any outstanding frames */
|
#ifdef FSL_RTOS_XIUOS
|
||||||
ethernetif_input(net);
|
if (lwip_obtain_semaphore(net) == EOK)
|
||||||
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
|
#endif
|
||||||
// DelayKTask(1);
|
{
|
||||||
|
/* Poll the driver, get any outstanding frames */
|
||||||
|
ethernetif_input(net);
|
||||||
|
sys_check_timeouts(); /* Handle all system timeouts for all core protocols */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +489,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
|
||||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||||
};
|
};
|
||||||
|
|
||||||
if(lwip_init_flag)
|
if(chk_lwip_bit(LWIP_INIT_FLAG))
|
||||||
{
|
{
|
||||||
lw_print("lw: [%s] already ...\n", __func__);
|
lw_print("lw: [%s] already ...\n", __func__);
|
||||||
|
|
||||||
|
@ -505,6 +497,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
|
||||||
IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]);
|
IP4_ADDR(&net_netmask, mask[0], mask[1], mask[2], mask[3]);
|
||||||
IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]);
|
IP4_ADDR(&net_gw, gw[0], gw[1], gw[2], gw[3]);
|
||||||
|
|
||||||
|
// update ip addr
|
||||||
netif_set_down(&gnetif);
|
netif_set_down(&gnetif);
|
||||||
netif_set_gw(&gnetif, &net_gw);
|
netif_set_gw(&gnetif, &net_gw);
|
||||||
netif_set_netmask(&gnetif, &net_netmask);
|
netif_set_netmask(&gnetif, &net_netmask);
|
||||||
|
@ -512,7 +505,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
|
||||||
netif_set_up(&gnetif);
|
netif_set_up(&gnetif);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lwip_init_flag = 1;
|
set_lwip_bit(LWIP_INIT_FLAG);
|
||||||
|
|
||||||
lw_print("lw: [%s] start ...\n", __func__);
|
lw_print("lw: [%s] start ...\n", __func__);
|
||||||
|
|
||||||
|
@ -527,7 +520,7 @@ void lwip_config_net(char *ip, char *mask, char *gw)
|
||||||
netif_set_default(&gnetif);
|
netif_set_default(&gnetif);
|
||||||
netif_set_up(&gnetif);
|
netif_set_up(&gnetif);
|
||||||
|
|
||||||
if(is_lwip_test)
|
if(chk_lwip_bit(LWIP_PRINT_FLAG))
|
||||||
{
|
{
|
||||||
lw_pr_info("\r\n************************************************\r\n");
|
lw_pr_info("\r\n************************************************\r\n");
|
||||||
lw_pr_info(" Network Configuration\r\n");
|
lw_pr_info(" Network Configuration\r\n");
|
||||||
|
@ -558,12 +551,13 @@ void lwip_config_tcp(char *ip, char *mask, char *gw)
|
||||||
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
#endif /* FSL_FEATURE_SOC_LPC_ENET_COUNT */
|
||||||
};
|
};
|
||||||
|
|
||||||
if(lwip_init_flag)
|
if(chk_lwip_bit(LWIP_INIT_FLAG))
|
||||||
{
|
{
|
||||||
lw_print("lw: [%s] already ...\n", __func__);
|
lw_print("lw: [%s] already ...\n", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lwip_init_flag = 1;
|
|
||||||
|
set_lwip_bit(LWIP_INIT_FLAG);
|
||||||
|
|
||||||
tcpip_init(NULL, NULL);
|
tcpip_init(NULL, NULL);
|
||||||
|
|
||||||
|
|
|
@ -60,38 +60,18 @@
|
||||||
|
|
||||||
#include <xs_base.h>
|
#include <xs_base.h>
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
/* LWIP task parameter */
|
||||||
// #define SET_AS_SERVER 1 /* define this terminal is udp server or not*/
|
#define LWIP_LOCAL_PORT 4840
|
||||||
|
#define LWIP_TARGET_PORT LWIP_LOCAL_PORT
|
||||||
|
|
||||||
#define LOCAL_PORT_SERVER 4840
|
#define LWIP_DEMO_TIMES 3
|
||||||
#define TARGET_PORT_CLIENT LOCAL_PORT_SERVER
|
#define LWIP_TASK_STACK_SIZE 4096
|
||||||
|
#define LWIP_DEMO_TASK_PRIO 20
|
||||||
|
|
||||||
#define TEST_LWIP_TIMES 3
|
/* MAC address configuration. */
|
||||||
|
#define configMAC_ADDR {0x02, 0x12, 0x13, 0x10, 0x15, 0x11}
|
||||||
|
|
||||||
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
|
|
||||||
#define IP_ADDR0_SERVER 192
|
|
||||||
#define IP_ADDR1_SERVER 168
|
|
||||||
#define IP_ADDR2_SERVER 250
|
|
||||||
#define IP_ADDR3_SERVER 252
|
|
||||||
|
|
||||||
#define IP_ADDR0_ClIENT 192
|
|
||||||
#define IP_ADDR1_ClIENT 168
|
|
||||||
#define IP_ADDR2_ClIENT 250
|
|
||||||
#define IP_ADDR3_ClIENT 253
|
|
||||||
|
|
||||||
/*NETMASK*/
|
|
||||||
#define NETMASK_ADDR0 255
|
|
||||||
#define NETMASK_ADDR1 255
|
|
||||||
#define NETMASK_ADDR2 255
|
|
||||||
#define NETMASK_ADDR3 0
|
|
||||||
|
|
||||||
/*Gateway Address*/
|
|
||||||
#define GW_ADDR0 192
|
|
||||||
#define GW_ADDR1 168
|
|
||||||
#define GW_ADDR2 250
|
|
||||||
#define GW_ADDR3 5
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
#define SYS_MBOX_NULL -1
|
#define SYS_MBOX_NULL -1
|
||||||
#define SYS_SEM_NULL 0
|
#define SYS_SEM_NULL 0
|
||||||
#define SYS_MRTEX_NULL SYS_SEM_NULL
|
#define SYS_MRTEX_NULL SYS_SEM_NULL
|
||||||
|
@ -100,18 +80,28 @@ typedef int32 sys_sem_t;
|
||||||
typedef int32 sys_mutex_t;
|
typedef int32 sys_mutex_t;
|
||||||
typedef int32 sys_mbox_t;
|
typedef int32 sys_mbox_t;
|
||||||
typedef int32 sys_thread_t;
|
typedef int32 sys_thread_t;
|
||||||
|
|
||||||
typedef x_base sys_prot_t;
|
typedef x_base sys_prot_t;
|
||||||
|
|
||||||
#define MS_PER_SYSTICK_F407 1000/TICK_PER_SECOND
|
#define MS_PER_SYSTICK_F407 (1000 / TICK_PER_SECOND)
|
||||||
|
|
||||||
|
//debug rtos with IRQ
|
||||||
|
//#define FSL_RTOS_XIUOS
|
||||||
|
|
||||||
|
extern char lwip_flag;
|
||||||
|
|
||||||
|
#define LWIP_INIT_FLAG (1 << 0)
|
||||||
|
#define LWIP_PRINT_FLAG (1 << 1)
|
||||||
|
|
||||||
|
#define set_lwip_bit(__bit) lwip_flag |= (__bit)
|
||||||
|
#define clr_lwip_bit(__bit) lwip_flag &= ~(__bit)
|
||||||
|
#define chk_lwip_bit(__bit) ((lwip_flag & (__bit)) == (__bit))
|
||||||
|
|
||||||
extern char lwip_ipaddr[];
|
extern char lwip_ipaddr[];
|
||||||
extern char lwip_netmask[];
|
extern char lwip_netmask[];
|
||||||
extern char lwip_gwaddr[];
|
extern char lwip_gwaddr[];
|
||||||
extern int is_lwip_test;
|
|
||||||
extern struct netif gnetif;
|
extern struct netif gnetif;
|
||||||
|
|
||||||
void TcpIpInit(void);
|
void lwip_tcp_init(void);
|
||||||
void lwip_config_net(char *ip, char *mask, char *gw);
|
void lwip_config_net(char *ip, char *mask, char *gw);
|
||||||
void lwip_config_tcp(char *ip, char *mask, char *gw);
|
void lwip_config_tcp(char *ip, char *mask, char *gw);
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,10 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
||||||
setip, lwip_setip_thread, SetIp [IP] [Netmask] [Gateway]);
|
setip, lwip_setip_thread, SetIp [IP] [Netmask] [Gateway]);
|
||||||
|
|
||||||
|
|
||||||
void lwip_getip_thread(int argc, char *argv[])
|
void lwip_showip_thread(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
char mac_addr[] = configMAC_ADDR;
|
||||||
|
|
||||||
lw_pr_info("\r\n************************************************\r\n");
|
lw_pr_info("\r\n************************************************\r\n");
|
||||||
lw_pr_info(" Network Configuration\r\n");
|
lw_pr_info(" Network Configuration\r\n");
|
||||||
lw_pr_info("************************************************\r\n");
|
lw_pr_info("************************************************\r\n");
|
||||||
|
@ -118,10 +120,12 @@ void lwip_getip_thread(int argc, char *argv[])
|
||||||
((u8_t *)&lwip_netmask)[2], ((u8_t *)&lwip_netmask)[3]);
|
((u8_t *)&lwip_netmask)[2], ((u8_t *)&lwip_netmask)[3]);
|
||||||
lw_pr_info(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_gwaddr)[0], ((u8_t *)&lwip_gwaddr)[1],
|
lw_pr_info(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_gwaddr)[0], ((u8_t *)&lwip_gwaddr)[1],
|
||||||
((u8_t *)&lwip_gwaddr)[2], ((u8_t *)&lwip_gwaddr)[3]);
|
((u8_t *)&lwip_gwaddr)[2], ((u8_t *)&lwip_gwaddr)[3]);
|
||||||
|
lw_pr_info(" MAC Address : %x:%x:%x:%x:%x:%x\r\n", mac_addr[0], mac_addr[1], mac_addr[2],
|
||||||
|
mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||||
lw_pr_info("************************************************\r\n");
|
lw_pr_info("************************************************\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||||
showip, lwip_getip_thread, GetIp [IP] [Netmask] [Gateway]);
|
showip, lwip_showip_thread, GetIp [IP] [Netmask] [Gateway]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef __LWIP_DEMO_H__
|
#ifndef __LWIP_DEMO_H__
|
||||||
#define __LWIP_DEMO_H__
|
#define __LWIP_DEMO_H__
|
||||||
|
|
||||||
void *eth_input_thread(void *param);
|
#define LWIP_TEST_STACK_SIZE 4096
|
||||||
|
#define LWIP_TEST_TASK_PRIO 20
|
||||||
|
|
||||||
#endif /* __LWIP_DEMO_H__ */
|
#endif /* __LWIP_DEMO_H__ */
|
||||||
|
|
|
@ -133,7 +133,7 @@ void lwip_dhcp_test(void)
|
||||||
ETH_BSP_Config();
|
ETH_BSP_Config();
|
||||||
|
|
||||||
lwip_config_net(ip_addr, ip_addr, ip_addr);
|
lwip_config_net(ip_addr, ip_addr, ip_addr);
|
||||||
is_lwip_test = 1;
|
set_lwip_bit(LWIP_PRINT_FLAG);
|
||||||
|
|
||||||
dhcp_start(&gnetif);
|
dhcp_start(&gnetif);
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ void lwip_dhcp_test(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is_lwip_test = 0;
|
clr_lwip_bit(LWIP_PRINT_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,11 +101,13 @@ void lwip_ping_thread(int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if (LWIP_DHCP) && (PING_USE_SOCKETS)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
get_url_ip(argv[1]);
|
get_url_ip(argv[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
lw_print("lw: [%s] argc %d\n", __func__, argc);
|
lw_print("lw: [%s] argc %d\n", __func__, argc);
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
* Definitions
|
* Definitions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
#define MSG_SIZE 128
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Prototypes
|
* Prototypes
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
@ -37,10 +39,9 @@
|
||||||
* Variables
|
* Variables
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
char tcp_target[] = {192, 168, 250, 252};
|
|
||||||
#define MSG_SIZE 128
|
|
||||||
// this is for test in shell, in fact, shell restrict the length of input string, which is less then 128
|
// this is for test in shell, in fact, shell restrict the length of input string, which is less then 128
|
||||||
char tcp_send_msg[MSG_SIZE] = {0};
|
char tcp_send_msg[MSG_SIZE] = {0};
|
||||||
|
char tcp_target[] = {192, 168, 250, 252};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Code
|
* Code
|
||||||
|
@ -60,7 +61,7 @@ static void lwip_tcp_send_thread(void *arg)
|
||||||
|
|
||||||
struct sockaddr_in tcp_sock;
|
struct sockaddr_in tcp_sock;
|
||||||
tcp_sock.sin_family = AF_INET;
|
tcp_sock.sin_family = AF_INET;
|
||||||
tcp_sock.sin_port = htons(TARGET_PORT_CLIENT);
|
tcp_sock.sin_port = htons(LWIP_TARGET_PORT);
|
||||||
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_target[0], tcp_target[1], tcp_target[2], tcp_target[3]));
|
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_target[0], tcp_target[1], tcp_target[2], tcp_target[3]));
|
||||||
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
|
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ void lwip_tcp_send_run(int argc, char *argv[])
|
||||||
|
|
||||||
ETH_BSP_Config();
|
ETH_BSP_Config();
|
||||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||||
sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, 4096, 25);
|
sys_thread_new("tcp send", lwip_tcp_send_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||||
|
|
|
@ -53,7 +53,7 @@ char udp_send_msg[] = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
|
||||||
|
|
||||||
static void lwip_udp_send(void *arg)
|
static void lwip_udp_send(void *arg)
|
||||||
{
|
{
|
||||||
int cnt = TEST_LWIP_TIMES;
|
int cnt = LWIP_DEMO_TIMES;
|
||||||
|
|
||||||
lw_print("udp_send_demo start.\n");
|
lw_print("udp_send_demo start.\n");
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ static void lwip_udp_send(void *arg)
|
||||||
|
|
||||||
struct sockaddr_in udp_sock;
|
struct sockaddr_in udp_sock;
|
||||||
udp_sock.sin_family = AF_INET;
|
udp_sock.sin_family = AF_INET;
|
||||||
udp_sock.sin_port = htons(TARGET_PORT_CLIENT);
|
udp_sock.sin_port = htons(LWIP_TARGET_PORT);
|
||||||
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3]));
|
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_target[0],udp_target[1],udp_target[2],udp_target[3]));
|
||||||
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
|
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ void udpecho_raw_init(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LOCAL_PORT_SERVER);
|
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LWIP_LOCAL_PORT);
|
||||||
if (err == ERR_OK)
|
if (err == ERR_OK)
|
||||||
{
|
{
|
||||||
udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL);
|
udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL);
|
||||||
|
|
|
@ -105,10 +105,6 @@ static u32_t ping_time;
|
||||||
static struct raw_pcb *ping_pcb;
|
static struct raw_pcb *ping_pcb;
|
||||||
#endif /* PING_USE_SOCKETS */
|
#endif /* PING_USE_SOCKETS */
|
||||||
|
|
||||||
#define PING_THREAD_STACKSIZE 4096
|
|
||||||
#define PING_THREAD_PRIO 15
|
|
||||||
|
|
||||||
|
|
||||||
/** Prepare a echo ICMP request */
|
/** Prepare a echo ICMP request */
|
||||||
static void
|
static void
|
||||||
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
|
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
|
||||||
|
@ -248,7 +244,7 @@ ping_thread(void *arg)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
int ret;
|
int ret;
|
||||||
int cnt = TEST_LWIP_TIMES;
|
int cnt = LWIP_DEMO_TIMES;
|
||||||
|
|
||||||
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
|
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
|
||||||
int timeout = PING_RCV_TIMEO;
|
int timeout = PING_RCV_TIMEO;
|
||||||
|
@ -268,7 +264,7 @@ ping_thread(void *arg)
|
||||||
s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
|
s = lwip_socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
|
s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
|
||||||
#endif
|
#endif
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
lw_print("lw: [%s] ping failed %d!\n", __func__, s);
|
lw_print("lw: [%s] ping failed %d!\n", __func__, s);
|
||||||
|
@ -367,7 +363,7 @@ ping_send(struct raw_pcb *raw, const ip_addr_t *addr)
|
||||||
static void
|
static void
|
||||||
ping_timeout(void *arg)
|
ping_timeout(void *arg)
|
||||||
{
|
{
|
||||||
static int cnt = TEST_LWIP_TIMES;
|
static int cnt = LWIP_DEMO_TIMES;
|
||||||
struct raw_pcb *pcb = (struct raw_pcb*)arg;
|
struct raw_pcb *pcb = (struct raw_pcb*)arg;
|
||||||
|
|
||||||
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
|
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
|
||||||
|
@ -380,7 +376,7 @@ ping_timeout(void *arg)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cnt = TEST_LWIP_TIMES;
|
cnt = LWIP_DEMO_TIMES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +408,7 @@ ping_init(const ip_addr_t* ping_addr)
|
||||||
ping_target = ping_addr;
|
ping_target = ping_addr;
|
||||||
|
|
||||||
#if PING_USE_SOCKETS
|
#if PING_USE_SOCKETS
|
||||||
th = sys_thread_new("ping_thread", ping_thread, NULL, PING_THREAD_STACKSIZE, PING_THREAD_PRIO);
|
th = sys_thread_new("ping_thread", ping_thread, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||||
lw_print("lw: [%s] new thread %d addr %#x\n", __func__, th, (*ping_addr).addr);
|
lw_print("lw: [%s] new thread %d addr %#x\n", __func__, th, (*ping_addr).addr);
|
||||||
#else /* PING_USE_SOCKETS */
|
#else /* PING_USE_SOCKETS */
|
||||||
ping_raw_init();
|
ping_raw_init();
|
||||||
|
@ -476,6 +472,7 @@ int lwip_ping_recv(int s, int *ttl)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (LWIP_DHCP) && (PING_USE_SOCKETS)
|
||||||
int get_url_ip(char* url)
|
int get_url_ip(char* url)
|
||||||
{
|
{
|
||||||
#if LWIP_VERSION_MAJOR >= 2U
|
#if LWIP_VERSION_MAJOR >= 2U
|
||||||
|
@ -483,7 +480,7 @@ int get_url_ip(char* url)
|
||||||
#else
|
#else
|
||||||
int timeout = PING_RCV_TIMEO * 1000UL / TICK_PER_SECOND;
|
int timeout = PING_RCV_TIMEO * 1000UL / TICK_PER_SECOND;
|
||||||
#endif
|
#endif
|
||||||
int cnt = TEST_LWIP_TIMES;
|
int cnt = LWIP_DEMO_TIMES;
|
||||||
|
|
||||||
int s, ttl, recv_len;
|
int s, ttl, recv_len;
|
||||||
ip_addr_t target_addr;
|
ip_addr_t target_addr;
|
||||||
|
@ -539,6 +536,6 @@ int get_url_ip(char* url)
|
||||||
lwip_close(s);
|
lwip_close(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_RAW */
|
#endif /* LWIP_RAW */
|
||||||
|
|
|
@ -49,7 +49,10 @@
|
||||||
|
|
||||||
#if LWIP_TCP && LWIP_CALLBACK_API
|
#if LWIP_TCP && LWIP_CALLBACK_API
|
||||||
|
|
||||||
#define MAX_TESTED_TCP_SEND_SIZE (56000)
|
#define MAX_TCP_RECV_SIZE (56000)
|
||||||
|
#define MAX_TCP_SHOW_SIZE 80
|
||||||
|
#define TCP_ACK_MSG_SIZE 20
|
||||||
|
#define TCP_EOF_CH '\n'
|
||||||
|
|
||||||
static struct tcp_pcb *tcpecho_raw_pcb;
|
static struct tcp_pcb *tcpecho_raw_pcb;
|
||||||
|
|
||||||
|
@ -109,70 +112,73 @@ tcpecho_raw_error(void *arg, err_t err)
|
||||||
tcpecho_raw_free(es);
|
tcpecho_raw_free(es);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SHELL_TCP_LENGTH 80
|
static void
|
||||||
char* recved_msg;
|
tcpecho_raw_ack_size(struct tcp_pcb *tpcb, int ack_len)
|
||||||
int recved_msg_length;
|
{
|
||||||
|
struct pbuf *ack_buf = NULL;
|
||||||
|
|
||||||
|
// ack message
|
||||||
|
ack_buf = pbuf_alloc(PBUF_TRANSPORT, TCP_ACK_MSG_SIZE, PBUF_RAM);
|
||||||
|
snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n\0", ack_len);
|
||||||
|
ack_buf->len = strlen(ack_buf->payload);
|
||||||
|
ack_buf->tot_len = strlen(ack_buf->payload);
|
||||||
|
ack_buf->next = NULL;
|
||||||
|
|
||||||
|
tcp_write(tpcb, ack_buf->payload, ack_buf->len, 1);
|
||||||
|
pbuf_free(ack_buf);
|
||||||
|
}
|
||||||
|
|
||||||
// compute received message length until '\n'
|
// compute received message length until '\n'
|
||||||
static void record_msg(struct tcp_pcb *tpcb, struct tcpecho_raw_state* es){
|
static void
|
||||||
struct pbuf* ptr = es->p;
|
tcpecho_raw_ack(struct tcp_pcb *tpcb, struct tcpecho_raw_state* es){
|
||||||
int plen = ptr->len;
|
struct pbuf *ptr = es->p;
|
||||||
if(es==NULL||ptr==NULL||plen==0){
|
char *recv_buf = ptr->payload;
|
||||||
if(recved_msg){
|
int recv_len = ptr->len;
|
||||||
free(recved_msg);
|
static char *g_buf = NULL; //global received buffer
|
||||||
recved_msg = NULL;
|
static int g_buf_size = 0;
|
||||||
}
|
|
||||||
recved_msg_length = 0;
|
lw_print("lw: [%s] recv %d tot %d next %p ref %d tye %d id %d %s\n", __func__, ptr->len, ptr->tot_len,
|
||||||
|
ptr->next, ptr->ref, ptr->type_internal,
|
||||||
|
ptr->if_idx, ptr->payload);
|
||||||
|
|
||||||
|
if(g_buf == NULL)
|
||||||
|
{
|
||||||
|
g_buf = (char *)malloc(MAX_TCP_RECV_SIZE);
|
||||||
|
memset(g_buf, 0, MAX_TCP_RECV_SIZE);
|
||||||
|
memcpy(g_buf, recv_buf, recv_len);
|
||||||
}
|
}
|
||||||
int new_size = plen+1;
|
else
|
||||||
char* temp = recved_msg;
|
{
|
||||||
if(temp!=NULL){
|
if(g_buf_size + recv_len <= MAX_TCP_RECV_SIZE)
|
||||||
new_size += strlen(temp);
|
{
|
||||||
}
|
memcpy(g_buf + g_buf_size, recv_buf, recv_len);
|
||||||
recved_msg = malloc(new_size);
|
|
||||||
memset(recved_msg, 0, new_size);
|
|
||||||
if(temp!=NULL){
|
|
||||||
memcpy(recved_msg,temp,strlen(temp));
|
|
||||||
}
|
|
||||||
memcpy(recved_msg+new_size-plen-1, ptr->payload, plen);
|
|
||||||
free(temp);
|
|
||||||
recved_msg_length += plen;
|
|
||||||
if(recved_msg_length>=SHELL_TCP_LENGTH){
|
|
||||||
if(recved_msg){
|
|
||||||
free(recved_msg);
|
|
||||||
recved_msg = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(((char*)ptr->payload)[plen-1]=='\n'){
|
g_buf_size += recv_len;
|
||||||
if(recved_msg_length>MAX_TESTED_TCP_SEND_SIZE){
|
|
||||||
KPrintf("Recved_msg_length is larger than %d, which may lead to unexpected exceptions.\n",MAX_TESTED_TCP_SEND_SIZE);
|
if((recv_len != TCP_MSS) || (recv_buf[recv_len - 1] == TCP_EOF_CH))
|
||||||
}
|
{
|
||||||
if(recved_msg_length<SHELL_TCP_LENGTH){
|
if(g_buf_size < MAX_TCP_SHOW_SIZE){
|
||||||
KPrintf("Received: %s\n", recved_msg);
|
lw_pr_info("Received: %s\n", g_buf);
|
||||||
KPrintf("Received: %s\n", recved_msg);
|
|
||||||
}else{
|
}else{
|
||||||
KPrintf("Received a string of length %d\n", recved_msg_length);
|
lw_pr_info("Received a string of length %d\n", g_buf_size);
|
||||||
}
|
}
|
||||||
struct pbuf* reply_pbuf = pbuf_alloc(PBUF_TRANSPORT, 20, PBUF_RAM); // only reply received message length
|
|
||||||
sprintf(reply_pbuf->payload,"%d\n\0",recved_msg_length);
|
tcpecho_raw_ack_size(tpcb, g_buf_size);
|
||||||
reply_pbuf->len = strlen(reply_pbuf->payload);
|
|
||||||
reply_pbuf->tot_len = strlen(reply_pbuf->payload);
|
free(g_buf);
|
||||||
reply_pbuf->next = NULL;
|
g_buf = NULL;
|
||||||
|
g_buf_size = 0;
|
||||||
tcp_write(tpcb, reply_pbuf->payload, reply_pbuf->len, 1);
|
|
||||||
|
|
||||||
pbuf_free(reply_pbuf);
|
|
||||||
free(recved_msg);
|
|
||||||
recved_msg = NULL;
|
|
||||||
recved_msg_length = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
es->p = ptr->next;
|
es->p = ptr->next;
|
||||||
if(es->p != NULL) {
|
if(es->p != NULL) {
|
||||||
/* new reference! */
|
/* new reference! */
|
||||||
pbuf_ref(es->p);
|
pbuf_ref(es->p);
|
||||||
}
|
}
|
||||||
pbuf_free(ptr);
|
pbuf_free(ptr);
|
||||||
tcp_recved(tpcb, plen);
|
tcp_recved(tpcb, recv_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t
|
static err_t
|
||||||
tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb)
|
tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb)
|
||||||
|
@ -184,7 +190,7 @@ tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb)
|
||||||
if (es != NULL) {
|
if (es != NULL) {
|
||||||
if (es->p != NULL) {
|
if (es->p != NULL) {
|
||||||
/* there is a remaining pbuf (chain) */
|
/* there is a remaining pbuf (chain) */
|
||||||
record_msg(tpcb, es);
|
tcpecho_raw_ack(tpcb, es);
|
||||||
} else {
|
} else {
|
||||||
/* no remaining pbuf (chain) */
|
/* no remaining pbuf (chain) */
|
||||||
if(es->state == ES_CLOSING) {
|
if(es->state == ES_CLOSING) {
|
||||||
|
@ -233,7 +239,7 @@ tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||||
tcpecho_raw_close(tpcb, es);
|
tcpecho_raw_close(tpcb, es);
|
||||||
} else {
|
} else {
|
||||||
/* we're not done yet */
|
/* we're not done yet */
|
||||||
record_msg(tpcb, es);
|
tcpecho_raw_ack(tpcb, es);
|
||||||
}
|
}
|
||||||
ret_err = ERR_OK;
|
ret_err = ERR_OK;
|
||||||
} else if(err != ERR_OK) {
|
} else if(err != ERR_OK) {
|
||||||
|
@ -248,13 +254,13 @@ tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||||
es->state = ES_RECEIVED;
|
es->state = ES_RECEIVED;
|
||||||
/* store reference to incoming pbuf (chain) */
|
/* store reference to incoming pbuf (chain) */
|
||||||
es->p = p;
|
es->p = p;
|
||||||
record_msg(tpcb, es);
|
tcpecho_raw_ack(tpcb, es);
|
||||||
ret_err = ERR_OK;
|
ret_err = ERR_OK;
|
||||||
} else if (es->state == ES_RECEIVED) {
|
} else if (es->state == ES_RECEIVED) {
|
||||||
/* read some more data */
|
/* read some more data */
|
||||||
if(es->p == NULL) {
|
if(es->p == NULL) {
|
||||||
es->p = p;
|
es->p = p;
|
||||||
record_msg(tpcb, es);
|
tcpecho_raw_ack(tpcb, es);
|
||||||
} else {
|
} else {
|
||||||
struct pbuf *ptr;
|
struct pbuf *ptr;
|
||||||
|
|
||||||
|
@ -277,8 +283,6 @@ tcpecho_raw_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||||
{
|
{
|
||||||
err_t ret_err;
|
err_t ret_err;
|
||||||
struct tcpecho_raw_state *es;
|
struct tcpecho_raw_state *es;
|
||||||
recved_msg = NULL;
|
|
||||||
recved_msg_length = 0;
|
|
||||||
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
if ((err != ERR_OK) || (newpcb == NULL)) {
|
if ((err != ERR_OK) || (newpcb == NULL)) {
|
||||||
|
|
Loading…
Reference in New Issue