forked from xuos/xiuos
fixed the bug of lwip IRQ and optimize TCP and OPCUA demo
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#define TCP_LOCAL_PORT 4840
|
||||
#define UA_URL_SIZE 100
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
@@ -39,24 +40,19 @@
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
const char *test_uri = "opc.tcp://192.168.250.5:4840";
|
||||
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;
|
||||
char test_ua_ip[] = {192, 168, 250, 5};
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void *test_ua_get_server_info(void *param);
|
||||
|
||||
static void test_ua_connect(void *arg)
|
||||
{
|
||||
struct netif net;
|
||||
UA_StatusCode retval;
|
||||
char ua_uri[UA_URL_SIZE];
|
||||
|
||||
memset(ua_uri, 0, sizeof(ua_uri));
|
||||
|
||||
UA_Client *client = UA_Client_new();
|
||||
|
||||
@@ -69,7 +65,10 @@ static void test_ua_connect(void *arg)
|
||||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||
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)
|
||||
{
|
||||
ua_print("ua: [%s] ret %x\n", __func__, retval);
|
||||
@@ -83,7 +82,7 @@ static void test_ua_connect(void *arg)
|
||||
void test_ua_connect_thr(void *arg)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ 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),
|
||||
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();
|
||||
|
||||
@@ -107,7 +106,7 @@ void *test_ua_get_server_info(void *param)
|
||||
if (client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig *config = UA_Client_getConfig(client);
|
||||
@@ -117,7 +116,7 @@ void *test_ua_get_server_info(void *param)
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
UA_Client_delete(client);
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
@@ -128,37 +127,85 @@ void *test_ua_get_server_info(void *param)
|
||||
ua_pr_info("--- get server info ---\n", __func__);
|
||||
ua_browser_objects(client);
|
||||
|
||||
/* Same thing, this time using the node iterator... */
|
||||
ua_browser_nodes(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);
|
||||
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
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();
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_gw);
|
||||
test_ua_get_server_info(NULL);
|
||||
}
|
||||
|
||||
void *test_sh_ua_get_server_info(void *param)
|
||||
{
|
||||
int result = 0;
|
||||
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);
|
||||
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(0),
|
||||
UaGetInfo, test_sh_ua_get_server_info, Get information from OpcUA server);
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
UaInfo, test_sh_ua_get_info, UaInfo [IP]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user