Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into xidatong
This commit is contained in:
commit
f1d372dcf7
|
@ -1,17 +1,17 @@
|
|||
[submodule "Ubiquitous/RT_Thread/rt-thread"]
|
||||
path = Ubiquitous/RT_Thread/rt-thread
|
||||
[submodule "Ubiquitous/RT-Thread_Fusion_XiUOS/rt-thread"]
|
||||
path = Ubiquitous/RT-Thread_Fusion_XiUOS/rt-thread
|
||||
url = https://code.gitlink.org.cn/chunyexixiaoyu/rt-thread.git
|
||||
[submodule "Ubiquitous/RT_Thread/aiit_board/k210/kendryte-sdk/kendryte-sdk-source"]
|
||||
path = Ubiquitous/RT_Thread/aiit_board/k210/kendryte-sdk/kendryte-sdk-source
|
||||
[submodule "Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/k210/kendryte-sdk/kendryte-sdk-source"]
|
||||
path = Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/k210/kendryte-sdk/kendryte-sdk-source
|
||||
url = https://code.gitlink.org.cn/chunyexixiaoyu/kendryte-sdk-source.git
|
||||
[submodule "Ubiquitous/RT_Thread/aiit_board/aiit-riscv64-board/kendryte-sdk/kendryte-sdk-source"]
|
||||
path = Ubiquitous/RT_Thread/aiit_board/aiit-riscv64-board/kendryte-sdk/kendryte-sdk-source
|
||||
[submodule "Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/aiit-riscv64-board/kendryte-sdk/kendryte-sdk-source"]
|
||||
path = Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/aiit-riscv64-board/kendryte-sdk/kendryte-sdk-source
|
||||
url = https://code.gitlink.org.cn/chunyexixiaoyu/kendryte-sdk-source.git
|
||||
[submodule "Ubiquitous/Nuttx/apps"]
|
||||
path = Ubiquitous/Nuttx/apps
|
||||
[submodule "Ubiquitous/Nuttx_Fusion_XiUOS/apps"]
|
||||
path = Ubiquitous/Nuttx_Fusion_XiUOS/apps
|
||||
url = https://code.gitlink.org.cn/wgzAIIT/incubator-nuttx-apps.git
|
||||
[submodule "Ubiquitous/Nuttx/nuttx"]
|
||||
path = Ubiquitous/Nuttx/nuttx
|
||||
[submodule "Ubiquitous/Nuttx_Fusion_XiUOS/nuttx"]
|
||||
path = Ubiquitous/Nuttx_Fusion_XiUOS/nuttx
|
||||
url = https://code.gitlink.org.cn/wgzAIIT/incubator-nuttx.git
|
||||
[submodule "Ubiquitous/XiZi/fs/lwext4/lwext4_submodule"]
|
||||
path = Ubiquitous/XiZi/fs/lwext4/lwext4_submodule
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <list.h>
|
||||
#include <transform.h>
|
||||
#include "board.h"
|
||||
#include <lwip/altcp.h>
|
||||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
|
||||
|
@ -40,6 +39,9 @@
|
|||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
// to count test
|
||||
static int test_cnt = 0;
|
||||
static int fail_cnt = 0; // count failure times
|
||||
|
||||
char test_ua_ip[] = {192, 168, 250, 2};
|
||||
|
||||
|
@ -50,37 +52,56 @@ char test_ua_ip[] = {192, 168, 250, 2};
|
|||
static void UaConnectTestTask(void* arg)
|
||||
{
|
||||
struct netif net;
|
||||
UA_StatusCode retval;
|
||||
char ua_uri[UA_URL_SIZE];
|
||||
memset(ua_uri, 0, sizeof(ua_uri));
|
||||
UA_StatusCode ret;
|
||||
char url[UA_URL_SIZE];
|
||||
memset(url, 0, sizeof(url));
|
||||
|
||||
UA_Client* client = UA_Client_new();
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
ua_error("ua: [%s] tcp client null\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
snprintf(ua_uri, sizeof(ua_uri), "opc.tcp://%d.%d.%d.%d:4840",
|
||||
test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]);
|
||||
ua_notice("ua uri: %d %s\n", strlen(ua_uri), ua_uri);
|
||||
retval = UA_Client_connect(client,ua_uri);
|
||||
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
UA_ClientConfig_setDefault(config);
|
||||
|
||||
snprintf(url, sizeof(url), "opc.tcp://%d.%d.%d.%d:4840",
|
||||
test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]);
|
||||
|
||||
ua_notice("ua connect cnt %d fail %d\n", test_cnt++, fail_cnt ++);
|
||||
ua_notice("ua connect uri: %.*s\n", strlen(url), url);
|
||||
|
||||
ret = UA_Client_connect(client, url);
|
||||
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_notice("ua: [%s] connected failed %x\n", __func__, retval);
|
||||
ua_error("ua: [%s] connected failed %x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
fail_cnt++;
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("ua: [%s] connected ok!\n", __func__);
|
||||
ua_notice("ua connected ok!\n");
|
||||
UA_Client_delete(client);
|
||||
}
|
||||
|
||||
void UaConnectTest(void* arg)
|
||||
static void UaConnectTest(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_notice("input wrong ip\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
sys_thread_new("ua test", UaConnectTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
|
||||
}
|
||||
|
@ -90,10 +111,10 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
|||
|
||||
void UaBrowserObjectsTestTask(void* param)
|
||||
{
|
||||
static int test_cnt = 0;
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_notice("ua: [%s] start %d ...\n", __func__, test_cnt++);
|
||||
|
||||
UA_Client* client = UA_Client_new();
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] tcp client NULL\n", __func__);
|
||||
|
@ -102,25 +123,26 @@ void UaBrowserObjectsTestTask(void* param)
|
|||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
UA_StatusCode retval = UA_Client_connect(client, opc_server_url);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("--- start read time ---\n", __func__);
|
||||
ua_read_time(client);
|
||||
UaGetServerTime(client);
|
||||
|
||||
ua_notice("--- get server info ---\n", __func__);
|
||||
ua_test_browser_objects(client);
|
||||
UaTestBrowserObjects(client);
|
||||
|
||||
/* Clean up */
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
void* UaBrowserObjectsTest(int argc, char* argv[])
|
||||
static void* UaBrowserObjectsTest(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
|
@ -140,35 +162,33 @@ void* UaBrowserObjectsTest(int argc, char* argv[])
|
|||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
UaObj, UaBrowserObjectsTest, UaObj [IP]);
|
||||
UaObject, UaBrowserObjectsTest, UaObject [IP]);
|
||||
|
||||
void UaGetInfoTestTask(void* param)
|
||||
{
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_notice("ua: [%s] start ...\n", __func__);
|
||||
ua_notice("--- Get OPUCA objects ---\n", __func__);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
ua_error("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_url);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
ua_notice("--- interactive server ---\n", __func__);
|
||||
ua_test_interact_server(client);
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
UaTestInteractServer(client);
|
||||
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
|
@ -201,26 +221,24 @@ void UaAddNodesTask(void* param)
|
|||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
ua_error("ua: [%s] 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_url);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
ua_notice("--- add nodes ---\n", __func__);
|
||||
ua_add_nodes(client);
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
UaAddNodes(client);
|
||||
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,49 @@ struct PlcChannel plc_demo_ch;
|
|||
struct PlcDriver plc_demo_drv;
|
||||
struct PlcDevice plc_demo_dev;
|
||||
|
||||
int plc_test_flag = 0;
|
||||
|
||||
PlcCtrlParamType plc_ctrl_param;
|
||||
|
||||
UA_NodeId test_nodeid = {4, UA_NODEIDTYPE_NUMERIC, 5};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void PlcDelay(int sec)
|
||||
{
|
||||
volatile uint32_t i = 0;
|
||||
for (i = 0; i < 100000000 * sec; ++i)
|
||||
{
|
||||
__asm("NOP"); /* delay */
|
||||
}
|
||||
}
|
||||
|
||||
// get NodeId from str
|
||||
void PlcGetTestNodeId(char *str, UA_NodeId *id)
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
plc_print("plc: arg %s\n", str);
|
||||
|
||||
if(sscanf(str, PLC_NS_FORMAT, &id->namespaceIndex, node_str) != EOF)
|
||||
{
|
||||
if(isdigit(node_str[0]))
|
||||
{
|
||||
id->identifierType = UA_NODEIDTYPE_NUMERIC;
|
||||
id->identifier.numeric = atoi(node_str);
|
||||
plc_print("ns %d num %d\n", id->namespaceIndex, id->identifier.numeric);
|
||||
}
|
||||
else
|
||||
{
|
||||
id->identifierType = UA_NODEIDTYPE_STRING;
|
||||
id->identifier.string.length = strlen(node_str);
|
||||
id->identifier.string.data = node_str;
|
||||
plc_print("ns %d str %s\n", id->namespaceIndex, id->identifier.string.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlcDemoChannelDrvInit(void)
|
||||
{
|
||||
static uint8_t init_flag = 0;
|
||||
|
@ -52,33 +89,42 @@ void PlcDemoChannelDrvInit(void)
|
|||
memset(&plc_demo_dev, 0, sizeof(plc_demo_dev));
|
||||
}
|
||||
|
||||
static void PlcGetDemoDev(PlcDeviceType *dev, UA_NodeId *id)
|
||||
{
|
||||
// register plc device
|
||||
dev->state = CHDEV_INIT;
|
||||
strcpy(dev->name, "UA Demo");
|
||||
dev->info.product = "CPU 1215C";
|
||||
dev->info.vendor = "SIEMENS";
|
||||
dev->info.model = "S7-1200";
|
||||
dev->info.id = 123;
|
||||
dev->net = PLC_IND_ENET_OPCUA;
|
||||
|
||||
// register UA parameter
|
||||
if(!dev->priv_data)
|
||||
{
|
||||
dev->priv_data = (UaParamType*)malloc(sizeof(UaParamType));
|
||||
}
|
||||
UaParamType* ua_ptr = dev->priv_data;
|
||||
memset(ua_ptr, 0, sizeof(UaParamType));
|
||||
strcpy(ua_ptr->ua_remote_ip, opc_server_url);
|
||||
ua_ptr->act = UA_ACT_ATTR;
|
||||
memcpy(&ua_ptr->ua_id, id, sizeof(*id));
|
||||
}
|
||||
|
||||
static void PlcCtrlDemoInit(void)
|
||||
{
|
||||
static uint8_t init_flag = 0;
|
||||
|
||||
PlcDemoChannelDrvInit();
|
||||
// register plc device
|
||||
plc_demo_dev.state = CHDEV_INIT;
|
||||
strcpy(plc_demo_dev.name, "UA Demo");
|
||||
plc_demo_dev.info.product = "CPU 1215C";
|
||||
plc_demo_dev.info.vendor = "SIEMENS";
|
||||
plc_demo_dev.info.model = "S7-1200";
|
||||
plc_demo_dev.info.id = 123;
|
||||
plc_demo_dev.net = PLC_IND_ENET_OPCUA;
|
||||
|
||||
// register UA parameter
|
||||
if(!plc_demo_dev.priv_data)
|
||||
{
|
||||
plc_demo_dev.priv_data = (UaParamType*)malloc(sizeof(UaParamType));
|
||||
}
|
||||
UaParamType* ua_ptr = plc_demo_dev.priv_data;
|
||||
memset(ua_ptr, 0, sizeof(UaParamType));
|
||||
strcpy(ua_ptr->ua_remote_ip, opc_server_url);
|
||||
ua_ptr->act = UA_ACT_ATTR;
|
||||
memcpy(&ua_ptr->ua_id, &test_nodeid, sizeof(test_nodeid));
|
||||
// register plc device
|
||||
PlcGetDemoDev(&plc_demo_dev, &test_nodeid);
|
||||
|
||||
if(init_flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
init_flag = 1;
|
||||
|
||||
if(PlcDevRegister(&plc_demo_dev, NULL, plc_demo_dev.name) != EOK)
|
||||
|
@ -114,38 +160,21 @@ void PlcReadUATask(void* arg)
|
|||
ops->close(&plc_demo_dev);
|
||||
}
|
||||
|
||||
void PlcReadTest(int argc, char* argv[])
|
||||
void PlcReadTestShell(int argc, char* argv[])
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
plc_print("plc: arg %s\n", argv[1]);
|
||||
|
||||
if(sscanf(argv[1], PLC_NS_FORMAT, &test_nodeid.namespaceIndex, node_str) != EOF)
|
||||
{
|
||||
if(isdigit(node_str[0]))
|
||||
{
|
||||
test_nodeid.identifierType = UA_NODEIDTYPE_NUMERIC;
|
||||
test_nodeid.identifier.numeric = atoi(node_str);
|
||||
plc_print("ns %d num %d\n", test_nodeid.namespaceIndex, test_nodeid.identifier.numeric);
|
||||
}
|
||||
else
|
||||
{
|
||||
test_nodeid.identifierType = UA_NODEIDTYPE_STRING;
|
||||
test_nodeid.identifier.string.length = strlen(node_str);
|
||||
test_nodeid.identifier.string.data = node_str;
|
||||
plc_print("ns %d str %s\n", test_nodeid.namespaceIndex, test_nodeid.identifier.string.data);
|
||||
}
|
||||
}
|
||||
PlcGetTestNodeId(argv[1], &test_nodeid);
|
||||
}
|
||||
|
||||
sys_thread_new("plc read", PlcReadUATask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcRead, PlcReadTest, Read PLC);
|
||||
PlcRead, PlcReadTestShell, Read PLC);
|
||||
|
||||
void PlcWriteUATask(void* arg)
|
||||
{
|
||||
|
@ -168,13 +197,13 @@ void PlcWriteUATask(void* arg)
|
|||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] read failed\n", __func__);
|
||||
plc_print("plc: [%s] write failed\n", __func__);
|
||||
}
|
||||
|
||||
ops->close(&plc_demo_dev);
|
||||
}
|
||||
|
||||
void PlcWriteTest(int argc, char* argv[])
|
||||
void PlcWriteTestShell(int argc, char* argv[])
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
static char val_param[UA_NODE_LEN];
|
||||
|
@ -183,35 +212,143 @@ void PlcWriteTest(int argc, char* argv[])
|
|||
|
||||
if(argc > 1)
|
||||
{
|
||||
plc_print("plc: arg %s\n", argv[1]);
|
||||
PlcGetTestNodeId(argv[1], &test_nodeid);
|
||||
}
|
||||
|
||||
if(sscanf(argv[1], PLC_NS_FORMAT, &test_nodeid.namespaceIndex, node_str) != EOF)
|
||||
{
|
||||
if(isdigit(node_str[0]))
|
||||
{
|
||||
test_nodeid.identifierType = UA_NODEIDTYPE_NUMERIC;
|
||||
test_nodeid.identifier.numeric = atoi(node_str);
|
||||
plc_print("ns %d num %d\n", test_nodeid.namespaceIndex, test_nodeid.identifier.numeric);
|
||||
}
|
||||
else
|
||||
{
|
||||
test_nodeid.identifierType = UA_NODEIDTYPE_STRING;
|
||||
test_nodeid.identifier.string.length = strlen(node_str);
|
||||
test_nodeid.identifier.string.data = node_str;
|
||||
plc_print("ns %d str %s\n", test_nodeid.namespaceIndex, test_nodeid.identifier.string.data);
|
||||
}
|
||||
}
|
||||
|
||||
if(argc > 2)
|
||||
{
|
||||
strcpy(val_param, argv[2]);
|
||||
plc_print("write value %s\n", val_param);
|
||||
}
|
||||
if(argc > 2)
|
||||
{
|
||||
strcpy(val_param, argv[2]);
|
||||
plc_print("write value %s\n", val_param);
|
||||
}
|
||||
|
||||
sys_thread_new("plc write", PlcWriteUATask, val_param, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcWrite, PlcWriteTest, Read PLC);
|
||||
PlcWrite, PlcWriteTestShell, Read PLC);
|
||||
|
||||
// test motor
|
||||
// clear parameter
|
||||
// PlcWrite n4,2 0b
|
||||
// PlcWrite n4,3 0b
|
||||
// PlcWrite n4,4 0b
|
||||
// PlcWrite n4,5 0b
|
||||
//
|
||||
// enable
|
||||
// PlcWrite n4,2 1b
|
||||
//
|
||||
// set rotate speed
|
||||
// PlcWrite n4,3 50
|
||||
//
|
||||
// positive turn
|
||||
// PlcWrite n4,4 1b
|
||||
//
|
||||
// reversal turn
|
||||
// PlcWrite n4,5 1b
|
||||
|
||||
static int plc_test_speed = 50;
|
||||
static int plc_test_dir = 1; // direction positive: 1 reversal: 0
|
||||
|
||||
void PlcMotorTestTask(void* arg)
|
||||
{
|
||||
//support node id
|
||||
char *test_nodeid[] = {"n4,2", "n4,3", "n4,4", "n4,5", "n4,7"};
|
||||
// enable -> speed -> positive dir or inversal dir -> stop -> enable
|
||||
char test_sort[] = {0, 4, 2, 1, 0};
|
||||
char test_cmd[][4] = {"1b", "50", "1b", "1b", "0b"};
|
||||
char *test_notice[] = {"Enable Motor", "Set Speed", "Set Forward", "Set Reverse", "Stop Motor"};
|
||||
|
||||
int ret = 0;
|
||||
struct PlcOps* ops = NULL;
|
||||
char buf[PLC_BUF_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
PlcCtrlDemoInit();
|
||||
ops = plc_demo_dev.ops;
|
||||
ret = ops->open(&plc_demo_dev);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
UaParamType* ua_ptr = plc_demo_dev.priv_data;
|
||||
|
||||
// initialize step
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
plc_print("###\n### Clear %s\n###\n", test_notice[i]);
|
||||
PlcGetTestNodeId(test_nodeid[i], &ua_ptr->ua_id);
|
||||
ret = ops->write(&plc_demo_dev, "0b", PLC_BUF_SIZE);
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
|
||||
}
|
||||
PlcDelay(1);
|
||||
}
|
||||
|
||||
if(plc_test_speed != 50)
|
||||
{
|
||||
snprintf(test_cmd[1], 4, "%d", plc_test_speed);
|
||||
}
|
||||
|
||||
if(plc_test_dir == 0) // if not postive, next running
|
||||
test_sort[2] = 3;
|
||||
|
||||
for(int i = 0; i < sizeof(test_sort)/sizeof(test_sort[0]); i++)
|
||||
{
|
||||
PlcGetTestNodeId(test_nodeid[test_sort[i]], &ua_ptr->ua_id);
|
||||
plc_print("###\n### %s\n###\n", test_notice[i]);
|
||||
ret = ops->write(&plc_demo_dev, test_cmd[i], PLC_BUF_SIZE);
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
|
||||
}
|
||||
PlcDelay(1);
|
||||
if(i == 2) // postive
|
||||
{
|
||||
PlcDelay(10);
|
||||
}
|
||||
}
|
||||
ops->close(&plc_demo_dev);
|
||||
plc_test_flag = 0;
|
||||
}
|
||||
|
||||
// get parameter from
|
||||
void PlcGetMotorParam(char *str)
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
plc_print("plc: arg %s\n", str);
|
||||
|
||||
sscanf(str, "speed=%d", &plc_test_speed);
|
||||
sscanf(str, "dir=%d", &plc_test_dir);
|
||||
plc_print("speed is %d\n", plc_test_speed);
|
||||
plc_print("dir is %d\n", plc_test_dir);
|
||||
}
|
||||
|
||||
void PlcMotorTestShell(int argc, char* argv[])
|
||||
{
|
||||
if(plc_test_flag)
|
||||
{
|
||||
plc_print("PLC Motor testing!\n");
|
||||
return;
|
||||
}
|
||||
plc_test_flag = 1;
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
PlcGetMotorParam(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
sys_thread_new("plc motor", PlcMotorTestTask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcMotorTest, PlcMotorTestShell, Run motor);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @filepm10_0_ps5308
|
||||
* @file pm10_0_ps5308.c
|
||||
* @brief PS5308 PM10.0 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file pm2_5_ps5308
|
||||
* @file pm2_5_ps5308.c
|
||||
* @brief PS5308 PM2.5 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
|
|
|
@ -62,12 +62,6 @@ if SUPPORT_CONNECTION_FRAMEWORK
|
|||
default n
|
||||
if CONNECTION_ADAPTER_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/ethernet/Kconfig"
|
||||
config CONNECTION_ADAPTER_ETHERCAT
|
||||
bool "Using ethercat on ethernet adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/ethercat/Kconfig"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_BLUETOOTH
|
||||
|
|
|
@ -41,10 +41,6 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
|||
SRC_DIR += ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERCAT),y)
|
||||
SRC_DIR += ethercat
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
|
||||
SRC_DIR += bluetooth
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
config CONNECTION_ADAPTER_ETHERCAT
|
||||
bool "Using ethercat on industrial_ethernet adapter device"
|
||||
default n
|
||||
|
||||
if CONNECTION_ADAPTER_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/industrial_ethernet/ethercat/Kconfig"
|
||||
endif
|
|
@ -1,2 +1,5 @@
|
|||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERCAT),y)
|
||||
SRC_DIR += ethercat
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -5,6 +5,7 @@ config ADAPTER_HFA21_ETHERCAT
|
|||
bool "Using ethercat on ethernet adapter device HFA21"
|
||||
default n
|
||||
|
||||
if ADAPTER_HFA21_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/ethercat/hfa21_ethercat/Kconfig"
|
||||
endif
|
||||
if ADAPTER_HFA21_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/industrial_ethernet/ethercat/hfa21_ethercat/Kconfig"
|
||||
endif
|
||||
|
|
@ -23,6 +23,19 @@
|
|||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: open62541.c
|
||||
Description: Support OPCUA protocol
|
||||
Others: take https://github.com/open62541/open62541.git
|
||||
History:
|
||||
1. Date: 2021-12-15
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. added debug information for locate
|
||||
2. avoid calling client NEW at same time
|
||||
3. fixed the bug of free twice when receiveResponse timeout
|
||||
*************************************************/
|
||||
|
||||
#ifndef UA_DYNAMIC_LINKING_EXPORT
|
||||
# define UA_DYNAMIC_LINKING_EXPORT
|
||||
# define MDNSD_DYNAMIC_LINKING
|
||||
|
@ -36,6 +49,8 @@
|
|||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
|
||||
int ua_run_flag = 0;
|
||||
|
||||
#if LWIP_DNS
|
||||
|
||||
#else
|
||||
|
@ -7482,10 +7497,6 @@ Array_encodeBinary(const void *src, size_t length, const UA_DataType *type, Ctx
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -8330,24 +8341,9 @@ encodeBinaryStruct(const void *src, const UA_DataType *type, Ctx *ctx) {
|
|||
|
||||
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. */
|
||||
if(m->isArray) {
|
||||
const size_t length = *((const size_t*)ptr);
|
||||
|
@ -8362,20 +8358,6 @@ encodeBinaryStruct(const void *src, const UA_DataType *type, Ctx *ctx) {
|
|||
ret = encodeWithExchangeBuffer((const void*)ptr, mt, ctx);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -8614,68 +8596,23 @@ decodeBinaryStructure(void *dst, const UA_DataType *type, Ctx *ctx) {
|
|||
|
||||
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 */
|
||||
if(m->isArray) {
|
||||
size_t *length = (size_t*)ptr;
|
||||
ptr += sizeof(size_t);
|
||||
ret = Array_decodeBinary((void *UA_RESTRICT *UA_RESTRICT)ptr, length, mt , ctx);
|
||||
ptr += sizeof(void*);
|
||||
ua_debug("ua: [%s] %d ret %d ptr %p len %d\n", __func__, i, ret, ptr, length);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Scalar */
|
||||
ret = decodeBinaryJumpTable[mt->typeKind]((void *UA_RESTRICT)ptr, mt, ctx);
|
||||
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--;
|
||||
return ret;
|
||||
}
|
||||
|
@ -8818,17 +8755,8 @@ UA_decodeBinaryInternal(const UA_ByteString *src, size_t *offset,
|
|||
/* Decode */
|
||||
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);
|
||||
|
||||
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)) {
|
||||
/* Set the new offset */
|
||||
*offset = (size_t)(ctx.pos - src->data) / sizeof(u8);
|
||||
|
@ -8836,16 +8764,8 @@ UA_decodeBinaryInternal(const UA_ByteString *src, size_t *offset,
|
|||
/* Clean up */
|
||||
UA_clear(dst, type);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -17969,6 +17889,11 @@ UA_SecureChannel_close(UA_SecureChannel *channel) {
|
|||
/* Set the status to closed */
|
||||
channel->state = UA_SECURECHANNELSTATE_CLOSED;
|
||||
|
||||
if(channel->connection == 0)
|
||||
{
|
||||
ua_error("ua: [%s] conn null return!\n", __func__);
|
||||
return;
|
||||
}
|
||||
/* Detach from the connection and close the connection */
|
||||
if(channel->connection) {
|
||||
if(channel->connection->state != UA_CONNECTIONSTATE_CLOSED)
|
||||
|
@ -18613,12 +18538,6 @@ processChunks(UA_SecureChannel *channel, void *application,
|
|||
channel->decryptedChunksCount > channel->config.localMaxChunkCount) ||
|
||||
(channel->config.localMaxMessageSize != 0 &&
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -18656,9 +18575,6 @@ extractCompleteChunk(UA_SecureChannel *channel, const UA_ByteString *buffer,
|
|||
UA_decodeBinaryInternal(buffer, &initial_offset, &hdr,
|
||||
&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);
|
||||
(void)res; /* pacify compilers if assert is ignored */
|
||||
UA_MessageType msgType = (UA_MessageType)
|
||||
|
@ -18671,7 +18587,6 @@ extractCompleteChunk(UA_SecureChannel *channel, const UA_ByteString *buffer,
|
|||
return UA_STATUSCODE_BADTCPMESSAGETYPEINVALID;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -43657,6 +43572,8 @@ UA_Client_delete(UA_Client* client) {
|
|||
UA_Client_clear(client);
|
||||
UA_ClientConfig_clear(&client->config);
|
||||
UA_free(client);
|
||||
client = NULL;
|
||||
ua_run_flag = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -43976,7 +43893,7 @@ receiveResponse(UA_Client *client, void *response, const UA_DataType *responseTy
|
|||
"Receiving the response failed with StatusCode %s",
|
||||
UA_StatusCode_name(retval));
|
||||
ua_print("ua: [%s] state %d ret %d %#x\n", __func__, client->channel.state, retval, retval);
|
||||
closeSecureChannel(client);
|
||||
// closeSecureChannel(client);
|
||||
retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
|
||||
break;
|
||||
}
|
||||
|
@ -44244,7 +44161,7 @@ UA_Client_run_iterate(UA_Client *client, UA_UInt32 timeout) {
|
|||
client->sessionState < UA_SESSIONSTATE_ACTIVATED) {
|
||||
retval = connectIterate(client, timeout);
|
||||
notifyClientState(client);
|
||||
ua_print("lw: [%s] ret %d timeout %d state %d ch %d\n", __func__, retval, timeout,
|
||||
ua_print("lw: [%s] ret %x timeout %d state %d ch %d\n", __func__, retval, timeout,
|
||||
client->sessionState, client->channel.state);
|
||||
return retval;
|
||||
}
|
||||
|
@ -45187,9 +45104,6 @@ connectIterate(UA_Client *client, UA_UInt32 timeout) {
|
|||
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
|
||||
* connection */
|
||||
if(client->connection.state == UA_CONNECTIONSTATE_CLOSED)
|
||||
|
@ -45200,11 +45114,6 @@ connectIterate(UA_Client *client, UA_UInt32 timeout) {
|
|||
client->connectStatus =
|
||||
client->config.pollConnectionFunc(&client->connection, timeout,
|
||||
&client->config.logger);
|
||||
|
||||
ua_debug("ua: [%s] exit conn %x %d time %d handle %p\n", __func__,
|
||||
client->connectStatus,
|
||||
client->connection.state, timeout, client->connection.handle);
|
||||
|
||||
return client->connectStatus;
|
||||
}
|
||||
|
||||
|
@ -45399,8 +45308,6 @@ connectSync(UA_Client *client) {
|
|||
UA_DateTime now = UA_DateTime_nowMonotonic();
|
||||
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);
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
return retval;
|
||||
|
@ -70300,16 +70207,30 @@ UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
|
|||
|
||||
UA_Client * UA_Client_new() {
|
||||
UA_ClientConfig config;
|
||||
UA_Client *ret = NULL;
|
||||
|
||||
if(ua_run_flag)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(&config, 0, sizeof(UA_ClientConfig));
|
||||
config.logger.log = UA_Log_Stdout_log;
|
||||
config.logger.context = NULL;
|
||||
config.logger.clear = UA_Log_Stdout_clear;
|
||||
return UA_Client_newWithConfig(&config);
|
||||
|
||||
ret = UA_Client_newWithConfig(&config);
|
||||
|
||||
if(ret)
|
||||
{
|
||||
ua_run_flag = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
UA_StatusCode
|
||||
UA_ClientConfig_setDefault(UA_ClientConfig *config) {
|
||||
config->timeout = 20000;
|
||||
config->timeout = 5000;
|
||||
config->secureChannelLifeTime = 10 * 60 * 1000; /* 10 minutes */
|
||||
|
||||
if(!config->logger.log) {
|
||||
|
@ -71205,7 +71126,6 @@ ServerNetworkLayerTCP_add(UA_ServerNetworkLayer *nl, ServerNetworkLayerTCP *laye
|
|||
static UA_StatusCode
|
||||
addServerSocket(ServerNetworkLayerTCP *layer, struct addrinfo *ai) {
|
||||
/* Create the server socket */
|
||||
ua_print("ua: [%s] %d %d %d\n", __func__, ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
UA_SOCKET newsock = UA_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
if(newsock == UA_INVALID_SOCKET)
|
||||
{
|
||||
|
@ -71341,18 +71261,12 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_Logger *logger,
|
|||
int retcode = UA_getaddrinfo(customHostname->length ? hostname : NULL,
|
||||
portno, &hints, &res);
|
||||
|
||||
ua_print("ua: [%s] host %s pro %d ret %d\n", __func__, hostname, portno, retcode);
|
||||
|
||||
if(retcode != 0) {
|
||||
UA_LOG_SOCKET_ERRNO_GAI_WRAP(UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
|
||||
"getaddrinfo lookup of %s failed with error %d - %s", hostname, retcode, errno_str));
|
||||
return UA_STATUSCODE_BADINTERNALERROR;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] res %p fam %d len %d %s\n", __func__, res, res->ai_family,
|
||||
customHostname->length,
|
||||
customHostname->data);
|
||||
|
||||
/* There might be serveral addrinfos (for different network cards,
|
||||
* IPv4/IPv6). Add a server socket for all of them. */
|
||||
struct addrinfo *ai = res;
|
||||
|
@ -71597,6 +71511,12 @@ typedef struct TCPClientConnection {
|
|||
|
||||
static void
|
||||
ClientNetworkLayerTCP_close(UA_Connection *connection) {
|
||||
if(connection == NULL)
|
||||
{
|
||||
ua_error("connection NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(connection->state == UA_CONNECTIONSTATE_CLOSED)
|
||||
return;
|
||||
|
||||
|
@ -71637,10 +71557,6 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
return UA_STATUSCODE_BADDISCONNECT;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] conn handle %p fam %d sa %d\n", __func__,
|
||||
connection->handle, tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_addr->sa_family);
|
||||
|
||||
/* Get a socket and connect (only once) if not already done in a previous
|
||||
* call. On win32, calling connect multiple times is not recommended on
|
||||
* non-blocking sockets
|
||||
|
@ -71651,27 +71567,17 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
* and getsockopt using SO_ERROR on win32 and posix.
|
||||
*/
|
||||
if(connection->sockfd == UA_INVALID_SOCKET) {
|
||||
ua_print("ua: [%s] start socket %p ai %d sa %d\n", __func__,
|
||||
tcpConnection->server,
|
||||
tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_addr->sa_family);
|
||||
|
||||
connection->sockfd = UA_socket(tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_socktype,
|
||||
tcpConnection->server->ai_protocol);
|
||||
if(connection->sockfd == UA_INVALID_SOCKET) {
|
||||
ua_print("ua: [%s] %s\n", __func__, strerror(UA_ERRNO));
|
||||
UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
||||
"Could not create client socket: %s", strerror(UA_ERRNO));
|
||||
ClientNetworkLayerTCP_close(connection);
|
||||
return UA_STATUSCODE_BADDISCONNECT;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] socket fd %d %p fam %d sa %d\n", __func__,
|
||||
connection->sockfd,
|
||||
tcpConnection->server,
|
||||
tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_addr->sa_family);
|
||||
|
||||
/* Non blocking connect to be able to timeout */
|
||||
if(UA_socket_set_nonblocking(connection->sockfd) != UA_STATUSCODE_GOOD) {
|
||||
UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
||||
|
@ -71680,11 +71586,6 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
return UA_STATUSCODE_BADDISCONNECT;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] check fd %d %p fam %d sa %d\n", __func__,
|
||||
connection->sockfd,
|
||||
tcpConnection->server,
|
||||
tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_addr->sa_family);
|
||||
/* Don't have the socket create interrupt signals */
|
||||
#ifdef SO_NOSIGPIPE
|
||||
int val = 1;
|
||||
|
@ -71693,12 +71594,6 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
if(sso_result < 0)
|
||||
UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK, "Couldn't set SO_NOSIGPIPE");
|
||||
#endif
|
||||
ua_print("ua: [%s] connect ai %d sa fam %d len %d %x addr len %d\n", __func__,
|
||||
tcpConnection->server->ai_family,
|
||||
tcpConnection->server->ai_addr->sa_family,
|
||||
tcpConnection->server->ai_addr->sa_len,
|
||||
tcpConnection->server->ai_addr->sa_data[0],
|
||||
tcpConnection->server->ai_addrlen);
|
||||
|
||||
int error = UA_connect(connection->sockfd, tcpConnection->server->ai_addr,
|
||||
tcpConnection->server->ai_addrlen);
|
||||
|
@ -71708,7 +71603,6 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
connection->state = UA_CONNECTIONSTATE_ESTABLISHED;
|
||||
return UA_STATUSCODE_GOOD;
|
||||
}
|
||||
ua_print("ua: [%s] connected failed %d\n", __func__, error);
|
||||
|
||||
/* The connection failed */
|
||||
if((UA_ERRNO != UA_ERR_CONNECTION_PROGRESS)) {
|
||||
|
@ -71772,6 +71666,7 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
(int)tcpConnection->endpointUrl.length,
|
||||
tcpConnection->endpointUrl.data, strerror(UA_ERRNO));
|
||||
ClientNetworkLayerTCP_close(connection);
|
||||
ua_error("ua: [%s] line %d failed\n", __func__, __LINE__);
|
||||
return UA_STATUSCODE_BADDISCONNECT;
|
||||
}
|
||||
|
||||
|
@ -71802,6 +71697,7 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
|
|||
LocalFree(errno_str);
|
||||
#endif
|
||||
ClientNetworkLayerTCP_close(connection);
|
||||
ua_error("ua: [%s] line %d failed\n", __func__, __LINE__);
|
||||
return UA_STATUSCODE_BADDISCONNECT;
|
||||
}
|
||||
|
||||
|
@ -71831,14 +71727,11 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const UA_String endpoint
|
|||
connection.releaseSendBuffer = connection_releasesendbuffer;
|
||||
connection.releaseRecvBuffer = connection_releaserecvbuffer;
|
||||
|
||||
ua_print("ua: [%s] endpoint url (%d)%.28s %d\n", __func__, endpointUrl.length, endpointUrl.data,
|
||||
sizeof(TCPClientConnection));
|
||||
|
||||
TCPClientConnection *tcpClientConnection = (TCPClientConnection*)
|
||||
UA_malloc(sizeof(TCPClientConnection));
|
||||
if(!tcpClientConnection) {
|
||||
connection.state = UA_CONNECTIONSTATE_CLOSED;
|
||||
ua_print("ua: [%s] malloc %d failed\n", __func__, sizeof(TCPClientConnection));
|
||||
ua_error("ua: [%s] malloc %d failed\n", __func__, sizeof(TCPClientConnection));
|
||||
return connection;
|
||||
}
|
||||
memset(tcpClientConnection, 0, sizeof(TCPClientConnection));
|
||||
|
@ -71850,8 +71743,6 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const UA_String endpoint
|
|||
char hostname[512];
|
||||
tcpClientConnection->connStart = UA_DateTime_nowMonotonic();
|
||||
|
||||
ua_print("ua: [%s] line %d!\n", __func__, __LINE__);
|
||||
|
||||
UA_String_copy(&endpointUrl, &tcpClientConnection->endpointUrl);
|
||||
|
||||
UA_StatusCode parse_retval =
|
||||
|
@ -71864,8 +71755,6 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const UA_String endpoint
|
|||
return connection;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] line %d!\n", __func__, __LINE__);
|
||||
|
||||
memcpy(hostname, hostnameString.data, hostnameString.length);
|
||||
hostname[hostnameString.length] = 0;
|
||||
|
||||
|
@ -71875,22 +71764,16 @@ UA_ClientConnectionTCP_init(UA_ConnectionConfig config, const UA_String endpoint
|
|||
"No port defined, using default port %" PRIu16, port);
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] line %d!\n", __func__, __LINE__);
|
||||
|
||||
memset(&tcpClientConnection->hints, 0, sizeof(tcpClientConnection->hints));
|
||||
tcpClientConnection->hints.ai_family = AF_UNSPEC;
|
||||
tcpClientConnection->hints.ai_socktype = SOCK_STREAM;
|
||||
char portStr[6];
|
||||
UA_snprintf(portStr, 6, "%d", port);
|
||||
|
||||
// ua_print("ua: [%s] host %s port %s fam %d\n", __func__, hostname, portStr,
|
||||
// tcpClientConnection->server->ai_addr->sa_family);
|
||||
|
||||
#if LWIP_DNS
|
||||
int error = UA_getaddrinfo(hostname, portStr, &tcpClientConnection->hints,
|
||||
&tcpClientConnection->server);
|
||||
if(error != 0 || !tcpClientConnection->server) {
|
||||
ua_print("ua: [%s] host %s error %d\n", __func__, hostname, error);
|
||||
UA_LOG_SOCKET_ERRNO_GAI_WRAP(UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
||||
"DNS lookup of %s failed with error %d - %s",
|
||||
hostname, error, errno_str));
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "ua_api.h"
|
||||
|
||||
int ua_open(void *dev)
|
||||
int UaDevOpen(void *dev)
|
||||
{
|
||||
UaParamType *param = (UaParamType *)dev;
|
||||
|
||||
|
@ -32,7 +32,7 @@ int ua_open(void *dev)
|
|||
|
||||
if (param->client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
ua_error("ua: [%s] tcp client null\n", __func__);
|
||||
return EEMPTY;
|
||||
}
|
||||
|
||||
|
@ -43,28 +43,29 @@ int ua_open(void *dev)
|
|||
|
||||
UA_StatusCode retval = UA_Client_connect(param->client, param->ua_remote_ip);
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
ua_notice("ua: [%s] deleted ret %x!\n", __func__, retval);
|
||||
ua_error("ua: [%s] deleted ret %x!\n", __func__, retval);
|
||||
return (int)retval;
|
||||
}
|
||||
return EOK;
|
||||
}
|
||||
|
||||
void ua_close(void *dev)
|
||||
void UaDevClose(void *dev)
|
||||
{
|
||||
UaParamType *param = (UaParamType *)dev;
|
||||
ua_notice("ua: [%s] close %s!\n", __func__, param->ua_remote_ip);
|
||||
UA_Client_delete(param->client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
int ua_read(void *dev, void *buf, size_t len)
|
||||
int UaDevRead(void *dev, void *buf, size_t len)
|
||||
{
|
||||
UaParamType *param = (UaParamType *)dev;
|
||||
switch(param->act)
|
||||
{
|
||||
case UA_ACT_ATTR:
|
||||
ua_read_nodeid_value(param->client, param->ua_id, buf);
|
||||
UaReadNodeValue(param->client, param->ua_id, buf);
|
||||
break;
|
||||
case UA_ACT_OBJ:
|
||||
ua_test_browser_objects(param->client);
|
||||
UaTestBrowserObjects(param->client);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -72,17 +73,17 @@ int ua_read(void *dev, void *buf, size_t len)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
int ua_write(void *dev, const void *buf, size_t len)
|
||||
int UaDevWrite(void *dev, const void *buf, size_t len)
|
||||
{
|
||||
UaParamType *param = (UaParamType *)dev;
|
||||
|
||||
switch(param->act)
|
||||
{
|
||||
case UA_ACT_ATTR:
|
||||
ua_write_nodeid_value(param->client, param->ua_id, (char *)buf);
|
||||
UaWriteNodeValue(param->client, param->ua_id, (char *)buf);
|
||||
break;
|
||||
case UA_ACT_OBJ:
|
||||
ua_test_browser_objects(param->client);
|
||||
UaTestBrowserObjects(param->client);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -90,7 +91,7 @@ int ua_write(void *dev, const void *buf, size_t len)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
int ua_ioctl(void *dev, int cmd, void *arg)
|
||||
int UaDevIoctl(void *dev, int cmd, void *arg)
|
||||
{
|
||||
return EOK;
|
||||
}
|
||||
|
|
|
@ -42,32 +42,31 @@ typedef struct UaParam
|
|||
}UaParamType;
|
||||
|
||||
#define ua_print //KPrintf
|
||||
#define ua_trace() //KPrintf("ua: [%s] line %d checked!\n", __func__, __LINE__)
|
||||
#define ua_notice KPrintf
|
||||
#define ua_debug //KPrintf
|
||||
#define ua_error KPrintf
|
||||
|
||||
extern const char *opc_server_url;
|
||||
extern char test_ua_ip[];
|
||||
|
||||
int ua_server_connect(void);
|
||||
void ua_browser_nodes(UA_Client *client);
|
||||
void ua_browser_id(UA_Client *client, UA_NodeId id);
|
||||
void ua_read_time(UA_Client *client);
|
||||
void ua_add_nodes(UA_Client *client);
|
||||
int UaServerRun(void);
|
||||
void UaBrowserNodes(UA_Client *client);
|
||||
void UaBrowserNodeId(UA_Client *client, UA_NodeId id);
|
||||
void UaGetServerTime(UA_Client *client);
|
||||
void UaAddNodes(UA_Client *client);
|
||||
|
||||
int ua_open(void *dev); // open and connect PLC device
|
||||
void ua_close(void* dev); // close and disconnect PLC device
|
||||
int ua_read(void* dev, void *buf, size_t len); // read data from PLC
|
||||
int ua_write(void* dev, const void *buf, size_t len); // write data from PLC
|
||||
int ua_ioctl(void* dev, int cmd, void *arg); // send control command to PLC
|
||||
int UaDevOpen(void *dev); // open and connect PLC device
|
||||
void UaDevClose(void* dev); // close and disconnect PLC device
|
||||
int UaDevRead(void* dev, void *buf, size_t len); // read data from PLC
|
||||
int UaDevWrite(void* dev, const void *buf, size_t len); // write data from PLC
|
||||
int UaDevIoctl(void* dev, int cmd, void *arg); // send control command to PLC
|
||||
|
||||
char *ua_get_nodeid_str(UA_NodeId *node_id);
|
||||
void ua_read_nodeid_value(UA_Client *client, UA_NodeId id, UA_Int32 *value);
|
||||
void ua_write_nodeid_value(UA_Client *client, UA_NodeId id, char* value);
|
||||
void ua_test_attr(UA_Client *client);
|
||||
UA_StatusCode ua_read_array_value(UA_Client *client, int array_size, UA_ReadValueId *array);
|
||||
void ua_test_browser_objects(UA_Client *client);
|
||||
int ua_test_interact_server(UA_Client *client);
|
||||
char *UaGetNodeIdString(UA_NodeId *node_id);
|
||||
void UaReadNodeValue(UA_Client *client, UA_NodeId id, UA_Int32 *value);
|
||||
void UaWriteNodeValue(UA_Client *client, UA_NodeId id, char* value);
|
||||
UA_StatusCode UaReadArrayValue(UA_Client *client, int array_size, UA_ReadValueId *array);
|
||||
int UaGetNodeIdArray(UA_Client* client, UA_NodeId id, int array_size, int *id_array);
|
||||
|
||||
void UaTestBrowserObjects(UA_Client *client);
|
||||
int UaTestInteractServer(UA_Client *client);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
const char *opc_server_url = {"opc.tcp://192.168.250.2:4840"};
|
||||
|
||||
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
||||
static void handler_TheAnswerChanged(UA_Client* client, UA_UInt32 subId, void* subContext,
|
||||
static void UaAnswerChangedHandler(UA_Client* client, UA_UInt32 subId, void* subContext,
|
||||
UA_UInt32 monId, void* monContext, UA_DataValue* value)
|
||||
{
|
||||
ua_print("The Answer has changed!\n");
|
||||
ua_notice("Answer changed!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
static UA_StatusCode nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void* handle)
|
||||
static UA_StatusCode UaShowNodeIdIterate(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void* handle)
|
||||
{
|
||||
if(isInverse)
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ static UA_StatusCode nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId
|
|||
return UA_STATUSCODE_GOOD;
|
||||
}
|
||||
|
||||
int ua_get_points(UA_Client* client)
|
||||
int UaGetEndPoints(UA_Client* client)
|
||||
{
|
||||
/* Listing endpoints */
|
||||
UA_EndpointDescription* endpointArray = NULL;
|
||||
|
@ -76,7 +76,7 @@ int ua_get_points(UA_Client* client)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void ua_print_value(UA_Variant* val)
|
||||
static void UaShowNodeValue(UA_Variant* val)
|
||||
{
|
||||
if(val->type == &UA_TYPES[UA_TYPES_LOCALIZEDTEXT])
|
||||
{
|
||||
|
@ -103,6 +103,16 @@ void ua_print_value(UA_Variant* val)
|
|||
UA_Int16* ptr = (UA_Int16*)val->data;
|
||||
ua_notice("%d (Int16)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_FLOAT])
|
||||
{
|
||||
UA_Float* ptr = (UA_Float*)val->data;
|
||||
printf("%f (Float)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_DOUBLE])
|
||||
{
|
||||
UA_Double* ptr = (UA_Double*)val->data;
|
||||
printf("%f (Double)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_STRING])
|
||||
{
|
||||
UA_String* ptr = (UA_String*)val->data;
|
||||
|
@ -117,7 +127,7 @@ void ua_print_value(UA_Variant* val)
|
|||
}
|
||||
}
|
||||
|
||||
char *ua_get_nodeid_str(UA_NodeId *node_id)
|
||||
char *UaGetNodeIdString(UA_NodeId *node_id)
|
||||
{
|
||||
static char nodeid_str[UA_NODE_LEN] = {0};
|
||||
|
||||
|
@ -139,7 +149,7 @@ char *ua_get_nodeid_str(UA_NodeId *node_id)
|
|||
return nodeid_str;
|
||||
}
|
||||
|
||||
void ua_print_nodeid(UA_NodeId *node_id)
|
||||
static void UaShowNodeId(UA_NodeId *node_id)
|
||||
{
|
||||
switch(node_id->identifierType)
|
||||
{
|
||||
|
@ -158,7 +168,7 @@ void ua_print_nodeid(UA_NodeId *node_id)
|
|||
}
|
||||
}
|
||||
|
||||
void ua_print_object(UA_BrowseResponse* res)
|
||||
static void UaShowObject(UA_BrowseResponse* res)
|
||||
{
|
||||
ua_notice("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME");
|
||||
|
||||
|
@ -191,7 +201,7 @@ void ua_print_object(UA_BrowseResponse* res)
|
|||
ua_notice("\n");
|
||||
}
|
||||
|
||||
UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValueId* array)
|
||||
UA_StatusCode UaReadArrayValue(UA_Client* client, int array_size, UA_ReadValueId* array)
|
||||
{
|
||||
UA_ReadRequest request;
|
||||
UA_ReadRequest_init(&request);
|
||||
|
@ -209,14 +219,19 @@ UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValu
|
|||
}
|
||||
|
||||
UA_StatusCode* arr_ret = malloc(array_size * sizeof(UA_StatusCode));
|
||||
if(arr_ret == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] malloc %d failed!\n", __func__, array_size * sizeof(UA_StatusCode));
|
||||
return UA_STATUSCODE_BADOUTOFMEMORY;
|
||||
}
|
||||
|
||||
for(int i = 0; i < array_size; ++i)
|
||||
{
|
||||
if((response.results[i].status == UA_STATUSCODE_GOOD)
|
||||
&& (response.results[i].hasValue))
|
||||
{
|
||||
ua_notice("node %s: ", ua_get_nodeid_str(&array[i].nodeId));
|
||||
ua_print_value(&response.results[i].value);
|
||||
ua_notice("node %s: ", UaGetNodeIdString(&array[i].nodeId));
|
||||
UaShowNodeValue(&response.results[i].value);
|
||||
}
|
||||
}
|
||||
ua_notice("\n");
|
||||
|
@ -226,32 +241,82 @@ UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValu
|
|||
return UA_STATUSCODE_GOOD;
|
||||
}
|
||||
|
||||
void ua_browser_id(UA_Client* client, UA_NodeId id)
|
||||
void UaBrowserNodeId(UA_Client* client, UA_NodeId id)
|
||||
{
|
||||
UA_BrowseRequest ua_req;
|
||||
UA_BrowseResponse ua_resp;
|
||||
|
||||
/* Browse some objects */
|
||||
ua_notice("Browsing nodes in objects folder:\n");
|
||||
UA_BrowseRequest bReq;
|
||||
UA_BrowseRequest_init(&bReq);
|
||||
bReq.requestedMaxReferencesPerNode = 0;
|
||||
bReq.nodesToBrowse = UA_BrowseDescription_new();
|
||||
bReq.nodesToBrowseSize = 1;
|
||||
bReq.nodesToBrowse[0].nodeId = id; /* browse objects folder */
|
||||
bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
|
||||
UA_BrowseResponse res = UA_Client_Service_browse(client, bReq);
|
||||
ua_print_object(&res);
|
||||
UA_BrowseResponse_clear(&res);
|
||||
// UA_BrowseRequest_clear(&bReq);
|
||||
|
||||
UA_BrowseRequest_init(&ua_req);
|
||||
|
||||
ua_req.requestedMaxReferencesPerNode = 0;
|
||||
ua_req.nodesToBrowse = UA_BrowseDescription_new();
|
||||
ua_req.nodesToBrowseSize = 1;
|
||||
ua_req.nodesToBrowse[0].nodeId = id; /* browse objects folder */
|
||||
ua_req.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
|
||||
|
||||
ua_resp = UA_Client_Service_browse(client, ua_req);
|
||||
|
||||
UaShowObject(&ua_resp);
|
||||
|
||||
UA_BrowseResponse_clear(&ua_resp);
|
||||
}
|
||||
|
||||
void ua_browser_nodes(UA_Client* client)
|
||||
|
||||
int UaGetNodeIdArray(UA_Client* client, UA_NodeId id, int array_size, int *id_array)
|
||||
{
|
||||
int i, j;
|
||||
int array_cnt = 0;// return array number
|
||||
UA_BrowseRequest ua_req;
|
||||
UA_BrowseResponse ua_resp;
|
||||
|
||||
/* Browse some objects */
|
||||
ua_notice("Browsing nodes in objects folder:\n");
|
||||
|
||||
UA_BrowseRequest_init(&ua_req);
|
||||
|
||||
ua_req.requestedMaxReferencesPerNode = 0;
|
||||
ua_req.nodesToBrowse = UA_BrowseDescription_new();
|
||||
ua_req.nodesToBrowseSize = 1;
|
||||
ua_req.nodesToBrowse[0].nodeId = id; /* browse objects folder */
|
||||
ua_req.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
|
||||
|
||||
ua_resp = UA_Client_Service_browse(client, ua_req);
|
||||
|
||||
for(i = 0; i < ua_resp.resultsSize; ++i)
|
||||
{
|
||||
for(j = 0; j < ua_resp.results[i].referencesSize; ++j)
|
||||
{
|
||||
UA_ReferenceDescription* ref = &(ua_resp.results[i].references[j]);
|
||||
|
||||
if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC)
|
||||
{
|
||||
*(id_array + array_cnt) = ref->nodeId.nodeId.identifier.numeric;
|
||||
array_cnt ++;
|
||||
if(array_cnt >= array_size)
|
||||
{
|
||||
UA_BrowseResponse_clear(&ua_resp);
|
||||
return array_cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UA_BrowseResponse_clear(&ua_resp);
|
||||
return array_cnt;
|
||||
}
|
||||
|
||||
void UaBrowserNodes(UA_Client* client)
|
||||
{
|
||||
UA_NodeId* parent = UA_NodeId_new();
|
||||
*parent = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
|
||||
UA_Client_forEachChildNodeCall(client, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), nodeIter, (void*) parent);
|
||||
UA_Client_forEachChildNodeCall(client, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UaShowNodeIdIterate, (void*) parent);
|
||||
UA_NodeId_delete(parent);
|
||||
}
|
||||
|
||||
UA_UInt32 ua_start_sub(UA_Client* client, UA_NodeId node_id)
|
||||
UA_UInt32 UaStartSubscription(UA_Client* client, UA_NodeId node_id)
|
||||
{
|
||||
/* Create a subscription */
|
||||
UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
||||
|
@ -274,7 +339,7 @@ UA_UInt32 ua_start_sub(UA_Client* client, UA_NodeId node_id)
|
|||
UA_MonitoredItemCreateResult monResponse =
|
||||
UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
||||
UA_TIMESTAMPSTORETURN_BOTH,
|
||||
monRequest, NULL, handler_TheAnswerChanged, NULL);
|
||||
monRequest, NULL, UaAnswerChangedHandler, NULL);
|
||||
|
||||
if(monResponse.statusCode == UA_STATUSCODE_GOOD)
|
||||
{
|
||||
|
@ -290,7 +355,7 @@ UA_UInt32 ua_start_sub(UA_Client* client, UA_NodeId node_id)
|
|||
return subId;
|
||||
}
|
||||
|
||||
void ua_write_nodeid_value(UA_Client* client, UA_NodeId id, char* value)
|
||||
void UaWriteNodeValue(UA_Client* client, UA_NodeId id, char* value)
|
||||
{
|
||||
UA_Boolean bool_val;
|
||||
uint32_t integer_val;
|
||||
|
@ -332,24 +397,17 @@ void ua_write_nodeid_value(UA_Client* client, UA_NodeId id, char* value)
|
|||
|
||||
UA_WriteRequest_clear(&wReq);
|
||||
UA_WriteResponse_clear(&wResp);
|
||||
|
||||
// /* Write node attribute (using the highlevel API) */
|
||||
// value++;
|
||||
// UA_Variant *myVariant = UA_Variant_new();
|
||||
// UA_Variant_setScalarCopy(myVariant, &value, &UA_TYPES[UA_TYPES_INT32]);
|
||||
// UA_Client_writeValueAttribute(client, UA_NODEID_STRING(1, UA_NODE_STR), myVariant);
|
||||
// UA_Variant_delete(myVariant);
|
||||
}
|
||||
|
||||
/* Read attribute */
|
||||
void ua_read_nodeid_value(UA_Client* client, UA_NodeId id, UA_Int32 *value)
|
||||
void UaReadNodeValue(UA_Client* client, UA_NodeId id, UA_Int32 *value)
|
||||
{
|
||||
UA_Variant* val = UA_Variant_new();
|
||||
UA_StatusCode ret = UA_Client_readValueAttribute(client, id, val);
|
||||
|
||||
if(ret == UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print_value(val);
|
||||
UaShowNodeValue(val);
|
||||
if(UA_Variant_isScalar(val))
|
||||
{
|
||||
if(val->type == &UA_TYPES[UA_TYPES_BOOLEAN])
|
||||
|
@ -370,7 +428,7 @@ void ua_read_nodeid_value(UA_Client* client, UA_NodeId id, UA_Int32 *value)
|
|||
UA_Variant_delete(val);
|
||||
}
|
||||
|
||||
void ua_call_remote(UA_Client* client)
|
||||
void UaCallRemote(UA_Client* client)
|
||||
{
|
||||
/* Call a remote method */
|
||||
UA_Variant input;
|
||||
|
@ -397,7 +455,7 @@ void ua_call_remote(UA_Client* client)
|
|||
}
|
||||
|
||||
|
||||
void ua_add_nodes(UA_Client* client)
|
||||
void UaAddNodes(UA_Client* client)
|
||||
{
|
||||
/* Add new nodes*/
|
||||
/* New ReferenceType */
|
||||
|
@ -477,7 +535,7 @@ void ua_add_nodes(UA_Client* client)
|
|||
}
|
||||
}
|
||||
|
||||
void ua_read_time(UA_Client* client)
|
||||
void UaGetServerTime(UA_Client* client)
|
||||
{
|
||||
UA_Variant value;
|
||||
UA_Variant_init(&value);
|
||||
|
|
|
@ -10,29 +10,29 @@
|
|||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file ua_server.c
|
||||
* @brief Server for OpcUa function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.11.11
|
||||
*/
|
||||
|
||||
#include "open62541.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
UA_Boolean ua_server_flag = true;
|
||||
|
||||
UA_Boolean running = true;
|
||||
|
||||
static void stopHandler(int sign) {
|
||||
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
|
||||
running = false;
|
||||
}
|
||||
|
||||
int ua_server_connect(void)
|
||||
int UaRunServer(void)
|
||||
{
|
||||
signal(SIGINT, stopHandler);
|
||||
signal(SIGTERM, stopHandler);
|
||||
UA_StatusCode ret;
|
||||
|
||||
UA_Server *server = UA_Server_new();
|
||||
|
||||
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
|
||||
UA_StatusCode retval = UA_Server_run(server, &running);
|
||||
|
||||
ret = UA_Server_run(server, &ua_server_flag);
|
||||
|
||||
UA_Server_delete(server);
|
||||
|
||||
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -27,72 +27,60 @@
|
|||
#define UA_TEST_BROWSER_NODEID1 UA_NODEID_NUMERIC(4, 1)
|
||||
#define UA_TEST_WRITE_NODEID UA_NODEID_NUMERIC(4, 5)
|
||||
|
||||
#define UA_TEST_NODE_ARRAY_NUM 10
|
||||
|
||||
static UA_StatusCode ua_test_read_array(UA_Client *client)
|
||||
static UA_StatusCode UaTestReadArrayValue(UA_Client *client, UA_NodeId id)
|
||||
{
|
||||
const int item_size = 4;
|
||||
UA_ReadValueId test_item[item_size];
|
||||
int i;
|
||||
int array_size = 0;
|
||||
int test_id[UA_TEST_NODE_ARRAY_NUM];
|
||||
UA_ReadValueId test_array[UA_TEST_NODE_ARRAY_NUM];
|
||||
|
||||
for (int i = 0; i < item_size; i++)
|
||||
for(i = 0; i < UA_TEST_NODE_ARRAY_NUM; i++)
|
||||
{
|
||||
UA_ReadValueId_init(&test_item[i]);
|
||||
test_item[i].attributeId = UA_ATTRIBUTEID_VALUE;
|
||||
UA_ReadValueId_init(&test_array[i]);
|
||||
test_array[i].attributeId = UA_ATTRIBUTEID_VALUE;
|
||||
}
|
||||
|
||||
test_item[0].nodeId = UA_NODEID_NUMERIC(4, 2);
|
||||
test_item[1].nodeId = UA_NODEID_NUMERIC(4, 3);
|
||||
test_item[2].nodeId = UA_NODEID_NUMERIC(4, 4);
|
||||
test_item[3].nodeId = UA_NODEID_NUMERIC(4, 5);
|
||||
array_size = UaGetNodeIdArray(client, id, UA_TEST_NODE_ARRAY_NUM, test_id);
|
||||
|
||||
return ua_read_array_value(client, item_size, test_item);
|
||||
for(i = 0; i < array_size; i++)
|
||||
{
|
||||
test_array[i].nodeId = UA_NODEID_NUMERIC(id.namespaceIndex, test_id[i]);
|
||||
}
|
||||
|
||||
return UaReadArrayValue(client, array_size, test_array);
|
||||
}
|
||||
|
||||
void ua_test_browser_objects(UA_Client *client)
|
||||
void UaTestBrowserObjects(UA_Client *client)
|
||||
{
|
||||
UA_NodeId test_id;
|
||||
ua_browser_id(client, UA_TEST_BROWSER_NODEID);
|
||||
ua_browser_id(client, UA_TEST_BROWSER_NODEID1);
|
||||
UaBrowserNodeId(client, UA_TEST_BROWSER_NODEID);
|
||||
UaBrowserNodeId(client, UA_TEST_BROWSER_NODEID1);
|
||||
test_id = UA_TEST_BROWSER_NODEID1;
|
||||
ua_notice("Show values in %s:\n", ua_get_nodeid_str(&test_id));
|
||||
ua_test_read_array(client);
|
||||
ua_notice("Show values in %s:\n", UaGetNodeIdString(&test_id));
|
||||
UaTestReadArrayValue(client, test_id);
|
||||
return;
|
||||
}
|
||||
|
||||
void ua_test_write_attr(UA_Client *client)
|
||||
static void UaTestWriteNodeValue(UA_Client *client)
|
||||
{
|
||||
UA_Int32 value;
|
||||
char val_str[UA_NODE_LEN];
|
||||
UA_NodeId id = UA_TEST_WRITE_NODEID;
|
||||
|
||||
ua_notice("--- Test write %s ---\n", ua_get_nodeid_str(&id));
|
||||
ua_read_nodeid_value(client, id, &value);
|
||||
ua_write_nodeid_value(client, id, itoa(value + 1, val_str, 10));
|
||||
ua_read_nodeid_value(client, id, &value);
|
||||
ua_notice("--- Test write %s ---\n", UaGetNodeIdString(&id));
|
||||
UaReadNodeValue(client, id, &value);
|
||||
UaWriteNodeValue(client, id, itoa(value + 1, val_str, 10));
|
||||
UaReadNodeValue(client, id, &value);
|
||||
ua_notice("\n");
|
||||
}
|
||||
|
||||
int ua_test_interact_server(UA_Client *client)
|
||||
int UaTestInteractServer(UA_Client *client)
|
||||
{
|
||||
ua_read_time(client);
|
||||
ua_test_browser_objects(client);
|
||||
ua_test_write_attr(client);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int16 ua_test(void)
|
||||
{
|
||||
UA_Client *client = UA_Client_new();
|
||||
UA_StatusCode retval = UA_Client_connect(client, opc_server_url);
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
UA_Client_delete(client);
|
||||
return (int)retval;
|
||||
}
|
||||
|
||||
ua_read_time(client);
|
||||
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
UaGetServerTime(client);
|
||||
UaTestBrowserObjects(client);
|
||||
UaTestWriteNodeValue(client);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ ChDevType ChannelFindDevice(struct Channel *ch, const char *device_name)
|
|||
* @param dev_recv_callback - callback function
|
||||
* @return successful:EOK,failed:ERROR
|
||||
*/
|
||||
uint32 ChannelDevRecvCallback(struct ChDev *dev, int (*dev_recv_callback) (void *dev, x_size_t length))
|
||||
uint32 ChannelDevRecvCallback(struct ChDev *dev, int (*dev_recv_callback) (void *dev, size_t length))
|
||||
{
|
||||
CHECK_CH_PARAM(dev );
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
/**
|
||||
* @file plc_channel.h
|
||||
* @brief define ch driver framework function and common API
|
||||
* @brief define channel driver framework function and common API
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-01
|
||||
|
@ -23,9 +23,6 @@
|
|||
|
||||
#include "list.h"
|
||||
|
||||
#define x_OffPos uint32
|
||||
#define x_size_t size_t
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -97,27 +94,19 @@ struct ChConfigInfo
|
|||
|
||||
struct ChReadParam
|
||||
{
|
||||
x_OffPos pos;
|
||||
uint32 pos;
|
||||
void* buffer;
|
||||
x_size_t size;
|
||||
x_size_t read_length;
|
||||
size_t size;
|
||||
size_t read_length;
|
||||
};
|
||||
|
||||
struct ChWriteParam
|
||||
{
|
||||
x_OffPos pos;
|
||||
uint32 pos;
|
||||
const void* buffer;
|
||||
x_size_t size;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
//struct ChHalDevBlockParam
|
||||
//{
|
||||
// uint32 cmd;
|
||||
////tst by wly
|
||||
//// struct DeviceBlockArrange dev_block;
|
||||
//// struct DeviceBlockAddr *dev_addr;
|
||||
//};
|
||||
|
||||
struct ChHalDevDone
|
||||
{
|
||||
uint32 (*open) (void *dev);
|
||||
|
@ -134,8 +123,7 @@ struct ChDev
|
|||
|
||||
const struct ChHalDevDone *dev_done;
|
||||
|
||||
int (*dev_recv_callback) (void *dev, x_size_t length);
|
||||
// int (*dev_block_control) (struct ChDev *dev, struct ChHalDevBlockParam *block_param);
|
||||
int (*dev_recv_callback) (void *dev, size_t length);
|
||||
|
||||
struct Channel *owner_ch;
|
||||
void *private_data;
|
||||
|
@ -220,7 +208,7 @@ ChDrvType ChannelFindDriver(struct Channel *ch, const char *driver_name);
|
|||
ChDevType ChannelFindDevice(struct Channel *ch, const char *device_name);
|
||||
|
||||
/*Dev receive data callback function*/
|
||||
uint32 ChannelDevRecvCallback(struct ChDev *dev, int (*dev_recv_callback) (void *dev, x_size_t length));
|
||||
uint32 ChannelDevRecvCallback(struct ChDev *dev, int (*dev_recv_callback) (void *dev, size_t length));
|
||||
|
||||
/*Open the device of the channel*/
|
||||
uint32 ChannelDevOpen(struct ChDev *dev);
|
||||
|
|
|
@ -40,7 +40,7 @@ static int PlcDeviceOpen(void *dev)
|
|||
|
||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||
{
|
||||
return ua_open(plc_dev->priv_data);
|
||||
return UaDevOpen(plc_dev->priv_data);
|
||||
}
|
||||
|
||||
return EOK;
|
||||
|
@ -54,7 +54,7 @@ static void PlcDeviceClose(void *dev)
|
|||
|
||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||
{
|
||||
ua_close(plc_dev->priv_data);
|
||||
UaDevClose(plc_dev->priv_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ static int PlcDeviceWrite(void *dev, const void *buf, size_t len)
|
|||
|
||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||
{
|
||||
ret = ua_write(plc_dev->priv_data, buf, len);
|
||||
ret = UaDevWrite(plc_dev->priv_data, buf, len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -83,7 +83,7 @@ static int PlcDeviceRead(void *dev, void *buf, size_t len)
|
|||
|
||||
if(plc_dev->net == PLC_IND_ENET_OPCUA)
|
||||
{
|
||||
ret = ua_read(plc_dev->priv_data, buf, len);
|
||||
ret = UaDevRead(plc_dev->priv_data, buf, len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
if ARCH_BOARD_XIDATONG
|
||||
|
||||
choice
|
||||
prompt "Boot Flash"
|
||||
default XIDATONG_HYPER_FLASH
|
||||
|
||||
config XIDATONG_HYPER_FLASH
|
||||
bool "HYPER Flash"
|
||||
|
||||
config XIDATONG_QSPI_FLASH
|
||||
bool "QSPI Flash"
|
||||
|
||||
endchoice # Boot Flash
|
||||
|
||||
config XIDATONG_SDRAM
|
||||
bool "Enable SDRAM"
|
||||
default n
|
||||
select IMXRT_SEMC_INIT_DONE
|
||||
---help---
|
||||
Activate DCD configuration of SDRAM
|
||||
|
||||
endif
|
Binary file not shown.
Before Width: | Height: | Size: 63 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue