forked from xuos/xiuos
Merge branch 'develop' of https://git.trustie.net/wwg666/xiuos into develop
This commit is contained in:
commit
92def035b9
|
@ -1,15 +1,15 @@
|
|||
[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/Nuttx/apps"]
|
||||
path = Ubiquitous/Nuttx/apps
|
||||
url = https://gitlink.org.cn/wgzAIIT/incubator-nuttx-apps.git
|
||||
[submodule "Ubiquitous/Nuttx/nuttx"]
|
||||
path = Ubiquitous/Nuttx/nuttx
|
||||
url = https://gitlink.org.cn/wgzAIIT/incubator-nuttx.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_Fusion_XiUOS/apps"]
|
||||
path = Ubiquitous/Nuttx_Fusion_XiUOS/apps
|
||||
url = https://code.gitlink.org.cn/wgzAIIT/incubator-nuttx-apps.git
|
||||
[submodule "Ubiquitous/Nuttx_Fusion_XiUOS/nuttx"]
|
||||
path = Ubiquitous/Nuttx_Fusion_XiUOS/nuttx
|
||||
url = https://code.gitlink.org.cn/wgzAIIT/incubator-nuttx.git
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
/*
|
||||
* File : spi_flash_sfud.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
|
@ -11,16 +11,14 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file tcp_echo_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @file lwip_tcp_socket_demo.c
|
||||
* @brief TCP socket demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <xizi.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
|
@ -28,6 +26,7 @@
|
|||
#define TCP_DEMO_BUF_SIZE 65535
|
||||
|
||||
char tcp_socket_ip[] = {192, 168, 250, 252};
|
||||
u16_t tcp_socket_port = LWIP_TARGET_PORT;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -44,41 +43,46 @@ static void TCPSocketRecvTask(void *arg)
|
|||
recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE);
|
||||
if (recv_buf == NULL)
|
||||
{
|
||||
lw_print("No memory\n");
|
||||
goto __exit;
|
||||
lw_error("No memory\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
goto __exit;
|
||||
lw_error("Socket error\n");
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
tcp_addr.sin_family = AF_INET;
|
||||
tcp_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
tcp_addr.sin_port = htons(LWIP_LOCAL_PORT);
|
||||
tcp_addr.sin_port = htons(tcp_socket_port);
|
||||
memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero));
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1)
|
||||
{
|
||||
lw_print("Unable to bind\n");
|
||||
goto __exit;
|
||||
lw_error("Unable to bind\n");
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
lw_print("tcp bind success, start to receive.\n");
|
||||
lw_pr_info("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
|
||||
lw_notice("\n\nLocal Port:%d\n\n", tcp_socket_port);
|
||||
|
||||
// setup socket fd as listening mode
|
||||
if (listen(fd, 5) != 0 )
|
||||
{
|
||||
lw_print("Unable to listen\n");
|
||||
goto __exit;
|
||||
lw_error("Unable to listen\n");
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
// accept client connection
|
||||
clientfd = accept(fd, (struct sockaddr *)&tcp_addr, (socklen_t*)&addr_len);
|
||||
lw_pr_info("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
|
||||
lw_notice("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
@ -86,34 +90,31 @@ static void TCPSocketRecvTask(void *arg)
|
|||
recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len);
|
||||
if(recv_len > 0)
|
||||
{
|
||||
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);
|
||||
lw_notice("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr));
|
||||
lw_notice("Receive data : %d - %s\n\n", recv_len, recv_buf);
|
||||
}
|
||||
sendto(clientfd, recv_buf, recv_len, 0, (struct sockaddr*)&tcp_addr, addr_len);
|
||||
}
|
||||
|
||||
__exit:
|
||||
if (fd >= 0)
|
||||
closesocket(fd);
|
||||
|
||||
if (recv_buf)
|
||||
free(recv_buf);
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
}
|
||||
|
||||
void TCPSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if(argc == 2)
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
|
||||
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK)
|
||||
{
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("TCPSocketRecvTask", TCPSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
|
||||
|
@ -133,51 +134,51 @@ static void TCPSocketSendTask(void *arg)
|
|||
if (fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
goto __exit;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in tcp_sock;
|
||||
tcp_sock.sin_family = AF_INET;
|
||||
tcp_sock.sin_port = htons(LWIP_TARGET_PORT);
|
||||
tcp_sock.sin_port = htons(tcp_socket_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]));
|
||||
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
|
||||
{
|
||||
lw_print("Unable to connect\n");
|
||||
goto __exit;
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
lw_print("tcp connect success, start to send.\n");
|
||||
lw_pr_info("\n\nTarget Port:%d\n\n", LWIP_TARGET_PORT);
|
||||
lw_notice("\n\nTarget Port:%d\n\n", tcp_socket_port);
|
||||
|
||||
while (cnt --)
|
||||
{
|
||||
lw_print("Lwip client is running.\n");
|
||||
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));
|
||||
lw_pr_info("Send tcp msg: %s ", send_msg);
|
||||
lw_notice("Send tcp msg: %s ", send_msg);
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
__exit:
|
||||
if (fd >= 0)
|
||||
closesocket(fd);
|
||||
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void TCPSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
|
||||
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK)
|
||||
{
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("tcp socket", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
sys_thread_new("TCP Socket Send", TCPSocketSendTask, 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),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
|
@ -12,33 +12,25 @@
|
|||
|
||||
/**
|
||||
* @file lwip_udp_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @brief UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xizi.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/opt.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
#define UDP_BUF_SIZE 65536
|
||||
|
||||
extern char udp_target[];
|
||||
static struct udp_pcb *udpecho_raw_pcb;
|
||||
char udp_socket_ip[] = {192, 168, 250, 252};
|
||||
u16_t udp_socket_port = LWIP_LOCAL_PORT;
|
||||
|
||||
/******************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void UdpSocketRecvTask(void *arg)
|
||||
{
|
||||
lw_print("UdpSocketRecvTask start.\n");
|
||||
|
||||
int socket_fd = -1;
|
||||
int fd = -1;
|
||||
char *recv_buf;
|
||||
struct sockaddr_in udp_addr, server_addr;
|
||||
int recv_len;
|
||||
|
@ -49,134 +41,124 @@ static void UdpSocketRecvTask(void *arg)
|
|||
recv_buf = (char *)malloc(UDP_BUF_SIZE);
|
||||
if(recv_buf == NULL)
|
||||
{
|
||||
lw_print("No memory\n");
|
||||
goto __exit;
|
||||
lw_error("No memory\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(socket_fd < 0)
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
goto __exit;
|
||||
lw_error("Socket error\n");
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
udp_addr.sin_family = AF_INET;
|
||||
udp_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
udp_addr.sin_port = htons(LWIP_LOCAL_PORT);
|
||||
udp_addr.sin_port = htons(udp_socket_port);
|
||||
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(fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
|
||||
{
|
||||
lw_print("Unable to bind\n");
|
||||
goto __exit;
|
||||
lw_error("Unable to bind\n");
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
lw_print("UDP bind sucess, start to receive.\n");
|
||||
lw_print("\n\nLocal Port:%d\n\n", LWIP_LOCAL_PORT);
|
||||
lw_notice("UDP bind sucess, start to receive.\n");
|
||||
lw_notice("\n\nLocal Port:%d\n\n", udp_socket_port);
|
||||
|
||||
while(1)
|
||||
{
|
||||
memset(recv_buf, 0, UDP_BUF_SIZE);
|
||||
recv_len = recvfrom(socket_fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len);
|
||||
lw_pr_info("Receive from : %s\n", inet_ntoa(server_addr.sin_addr));
|
||||
lw_pr_info("Receive data : %s\n\n", recv_buf);
|
||||
sendto(socket_fd, recv_buf, recv_len, 0, (struct sockaddr*)&server_addr, addr_len);
|
||||
recv_len = recvfrom(fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len);
|
||||
if(recv_len > 0)
|
||||
{
|
||||
lw_notice("Receive from : %s\n", inet_ntoa(server_addr.sin_addr));
|
||||
lw_notice("Receive data : %s\n\n", recv_buf);
|
||||
}
|
||||
sendto(fd, recv_buf, recv_len, 0, (struct sockaddr*)&server_addr, addr_len);
|
||||
}
|
||||
|
||||
__exit:
|
||||
if(socket_fd >= 0)
|
||||
{
|
||||
closesocket(socket_fd);
|
||||
}
|
||||
|
||||
if(recv_buf)
|
||||
{
|
||||
free(recv_buf);
|
||||
}
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
}
|
||||
}
|
||||
|
||||
void UdpSocketRecvTask(int argc, char *argv[])
|
||||
void UdpSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if(argc == 2)
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
|
||||
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK)
|
||||
{
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, 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),
|
||||
UDPSocketRecv, UdpSocketRecvTask, UDP recv echo);
|
||||
UDPSocketRecv, UdpSocketRecvTest, UDP Receive DEMO);
|
||||
|
||||
static void UdpSocketSendTask(void *arg)
|
||||
{
|
||||
int cnt = LWIP_DEMO_TIMES;
|
||||
char send_str[128];
|
||||
int fd = -1;
|
||||
|
||||
lw_print("UdpSocketSendTask start.\n");
|
||||
|
||||
int socket_fd = -1;
|
||||
memset(send_str, 0, sizeof(send_str));
|
||||
|
||||
socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(socket_fd < 0)
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
goto __exit;
|
||||
lw_error("Socket error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in udp_sock;
|
||||
udp_sock.sin_family = AF_INET;
|
||||
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_port = htons(udp_socket_port);
|
||||
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_socket_ip[0], udp_socket_ip[1], udp_socket_ip[2], udp_socket_ip[3]));
|
||||
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
|
||||
|
||||
if(connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
|
||||
if(connect(fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
|
||||
{
|
||||
lw_print("Unable to connect\n");
|
||||
goto __exit;
|
||||
lw_error("Unable to connect\n");
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
lw_print("UDP connect success, start to send.\n");
|
||||
lw_print("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
|
||||
lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
|
||||
|
||||
while (cnt --)
|
||||
{
|
||||
snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt);
|
||||
sendto(socket_fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
|
||||
lw_pr_info("Send UDP msg: %s ", send_str);
|
||||
sendto(fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
|
||||
lw_notice("Send UDP msg: %s ", send_str);
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
__exit:
|
||||
if(socket_fd >= 0)
|
||||
{
|
||||
closesocket(socket_fd);
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
void UdpSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if(argc == 2)
|
||||
if(argc >= 2)
|
||||
{
|
||||
lw_print("lw: [%s] gw %s\n", __func__, argv[1]);
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
|
||||
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK)
|
||||
{
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# OPCUA DEMO README
|
||||
|
||||
## 文件说明
|
||||
|
||||
用于OPCUA 相关测试命令演示,需要开启LWIP和OPCUA协议.
|
||||
|
||||
### 命令行
|
||||
|
||||
UaConnect [IP]
|
||||
|
||||
用于测试与OPCUA服务器连接,连接成功应显示OK
|
||||
|
||||
UaObject [IP]
|
||||
|
||||
用于显示对应的OPCUA设备的节点信息
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file ua_demo.c
|
||||
* @file opcua_demo.c
|
||||
* @brief Demo for OpcUa function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
|
@ -29,7 +29,6 @@
|
|||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#define TCP_LOCAL_PORT 4840
|
||||
#define UA_URL_SIZE 100
|
||||
#define UA_STACK_SIZE 4096
|
||||
#define UA_TASK_PRIO 15
|
||||
|
@ -66,18 +65,17 @@ static void UaConnectTestTask(void* arg)
|
|||
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_pr_info("ua uri: %d %s\n", strlen(ua_uri), ua_uri);
|
||||
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_pr_info("ua: [%s] connected failed %x\n", __func__, retval);
|
||||
ua_notice("ua: [%s] connected failed %x\n", __func__, retval);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_pr_info("ua: [%s] connected ok!\n", __func__);
|
||||
UA_Client_disconnect(client);
|
||||
ua_notice("ua: [%s] connected ok!\n", __func__);
|
||||
UA_Client_delete(client);
|
||||
}
|
||||
|
||||
|
@ -92,12 +90,13 @@ 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_pr_info("ua: [%s] start ...\n", __func__);
|
||||
ua_notice("ua: [%s] start %d ...\n", __func__, test_cnt++);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_print("ua: [%s] tcp client null\n", __func__);
|
||||
ua_error("ua: [%s] tcp client NULL\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -107,18 +106,17 @@ void UaBrowserObjectsTestTask(void* param)
|
|||
|
||||
if(retval != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, retval);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
ua_pr_info("--- start read time ---\n", __func__);
|
||||
ua_notice("--- start read time ---\n", __func__);
|
||||
ua_read_time(client);
|
||||
ua_pr_info("--- get server info ---\n", __func__);
|
||||
ua_notice("--- get server info ---\n", __func__);
|
||||
ua_test_browser_objects(client);
|
||||
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
|
@ -130,7 +128,7 @@ void* UaBrowserObjectsTest(int argc, char* argv[])
|
|||
{
|
||||
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");
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +145,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
|||
void UaGetInfoTestTask(void* param)
|
||||
{
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_pr_info("ua: [%s] start ...\n", __func__);
|
||||
ua_notice("ua: [%s] start ...\n", __func__);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
|
@ -167,7 +165,7 @@ void UaGetInfoTestTask(void* param)
|
|||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
ua_pr_info("--- interactive server ---\n", __func__);
|
||||
ua_notice("--- interactive server ---\n", __func__);
|
||||
ua_test_interact_server(client);
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
|
@ -182,7 +180,7 @@ void* UaGetInfoTest(int argc, char* argv[])
|
|||
{
|
||||
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");
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +197,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
|
|||
void UaAddNodesTask(void* param)
|
||||
{
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_pr_info("ua: [%s] start ...\n", __func__);
|
||||
ua_notice("ua: [%s] start ...\n", __func__);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
|
@ -219,7 +217,7 @@ void UaAddNodesTask(void* param)
|
|||
}
|
||||
|
||||
ua_print("ua: [%s] connect ok!\n", __func__);
|
||||
ua_pr_info("--- add nodes ---\n", __func__);
|
||||
ua_notice("--- add nodes ---\n", __func__);
|
||||
ua_add_nodes(client);
|
||||
/* Clean up */
|
||||
UA_Client_disconnect(client);
|
||||
|
@ -234,7 +232,7 @@ void* UaAddNodesTest(int argc, char* argv[])
|
|||
{
|
||||
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");
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# PLC DEMO README
|
||||
|
||||
## 文件说明
|
||||
|
||||
用于PLC设备相关测试命令演示,目前支持OPCUA协议对PLC进行远程控制,该命令基于LWIP和OPCUA,需要开启相关开关。
|
||||
|
||||
多个PLC设备可以组成一个channel,用于一条相关业务线控制。
|
||||
|
||||
### 命令行
|
||||
|
||||
ShowChannel
|
||||
|
||||
显示注册到channel上的PLC设备,范例如下:
|
||||
|
||||
ch_type ch_name drv_name dev_name cnt
|
||||
-----------------------------------------------------------------
|
||||
PLC_Channel PLC OPCUA PLC Demo 4 1
|
||||
PLC Demo 3 2
|
||||
PLC Demo 2 3
|
||||
PLC Demo 1 4
|
||||
PLC Demo 0 5
|
||||
|
||||
ShowPLC
|
||||
|
||||
用于显示PLC,范例如下:
|
||||
|
||||
device vendor model product id
|
||||
-----------------------------------------------------------------
|
||||
PLC Demo 4 B&R X20 X20 CP1381 5
|
||||
PLC Demo 3 B&R X20 X20 CP1586 4
|
||||
PLC Demo 2 SIEMSNS S7-200 CPU SR60 3
|
||||
PLC Demo 1 SIEMENS S7-1200 CPU 1215C 2
|
||||
PLC Demo 0 SIEMENS S7-1500 CPU 1512SP-1PN 1
|
||||
|
||||
PlcRead [NodeID]
|
||||
|
||||
用于读取PLC节点信息
|
||||
|
||||
- [NodeID]: 如n4,1, 其中4代表namespace,1代表节点号
|
||||
|
||||
|
||||
PlcWrite
|
||||
|
||||
用于写入PLC节点数值
|
||||
|
||||
- [NodeID]: 如n4,1, 其中4代表namespace,1代表节点号
|
||||
|
||||
- [value]: 为写入数值,目前支持bool类型,和int类型。bool型应为0b(代表false), 1b(代表true)
|
|
@ -101,8 +101,6 @@ void PlcReadUATask(void* arg)
|
|||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
// free(plc_demo_dev.priv_data);
|
||||
// plc_demo_dev.priv_data = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -163,8 +161,6 @@ void PlcWriteUATask(void* arg)
|
|||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
// free(plc_demo_dev.priv_data);
|
||||
// plc_demo_dev.priv_data = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,14 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
|||
CSRCS += temperature_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDDIRECTION_QS_FX), y)
|
||||
CSRCS += winddirection_qs_fx.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDSPEED_QS_FS), y)
|
||||
CSRCS += windspeed_qs_fs.c
|
||||
endif
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
|
|
|
@ -34,5 +34,7 @@ void WindDirectionQsFx(void)
|
|||
printf("wind direction : %d degree\n", result);
|
||||
SensorQuantityClose(wind_direction);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindDirectionQsFx, WindDirectionQsFx, WindDirectionQsFx function);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,5 +34,7 @@ void WindSpeedQsFs(void)
|
|||
printf("wind speed : %d.%d m/s\n", result/10, result%10);
|
||||
SensorQuantityClose(wind_speed);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindSpeedQsFs, WindSpeedQsFs, WindSpeedQsFs function);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#define AT_CMD_MAX_LEN 128
|
||||
#define AT_AGENT_MAX 2
|
||||
static char send_buf[AT_CMD_MAX_LEN];
|
||||
static uint32 last_cmd_len = 0;
|
||||
static uint32_t last_cmd_len = 0;
|
||||
|
||||
static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0};
|
||||
|
||||
|
@ -126,7 +126,7 @@ void ATSprintf(int fd, const char *format, va_list params)
|
|||
PrivWrite(fd, send_buf, last_cmd_len);
|
||||
}
|
||||
|
||||
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...)
|
||||
int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...)
|
||||
{
|
||||
if (agent == NULL) {
|
||||
printf("ATAgent is null");
|
||||
|
@ -147,8 +147,8 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch
|
|||
agent->entm_recv_len = 0;
|
||||
|
||||
va_list params;
|
||||
uint32 cmd_size = 0;
|
||||
uint32 result = 0;
|
||||
uint32_t cmd_size = 0;
|
||||
uint32_t result = 0;
|
||||
const char *cmd = NULL;
|
||||
|
||||
agent->reply = reply;
|
||||
|
@ -317,7 +317,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
|||
|
||||
static int GetCompleteATReply(ATAgentType agent)
|
||||
{
|
||||
uint32 read_len = 0;
|
||||
uint32_t read_len = 0;
|
||||
char ch = 0, last_ch = 0;
|
||||
bool is_full = false;
|
||||
|
||||
|
@ -335,7 +335,9 @@ static int GetCompleteATReply(ATAgentType agent)
|
|||
{
|
||||
PrivRead(agent->fd, &ch, 1);
|
||||
#ifdef CONNECTION_FRAMEWORK_DEBUG
|
||||
printf(" %c (0x%x)\n", ch, ch);
|
||||
if(ch != 0){
|
||||
printf(" %c (0x%x)\n", ch, ch);
|
||||
}
|
||||
#endif
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
@ -365,9 +367,13 @@ static int GetCompleteATReply(ATAgentType agent)
|
|||
{
|
||||
if (read_len < agent->maintain_max)
|
||||
{
|
||||
agent->maintain_buffer[read_len] = ch;
|
||||
read_len++;
|
||||
agent->maintain_len = read_len;
|
||||
if(ch != 0) ///< if the char is null then do not save it to the buff
|
||||
{
|
||||
agent->maintain_buffer[read_len] = ch;
|
||||
read_len++;
|
||||
agent->maintain_len = read_len;
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("maintain_len is_full ...\n");
|
||||
is_full = true;
|
||||
|
|
|
@ -87,7 +87,7 @@ int InitATAgent(const char *agent_name, int fd, uint32 maintain_max);
|
|||
int DeleteATAgent(ATAgentType agent);
|
||||
int ParseATReply(char* str, const char *format, ...);
|
||||
void DeleteATReply(ATReplyType reply);
|
||||
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...);
|
||||
int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...);
|
||||
int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check);
|
||||
|
||||
#endif
|
|
@ -7,3 +7,11 @@ config ADAPTER_HFA21_WIFI
|
|||
if ADAPTER_HFA21_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/hfa21_wifi/Kconfig"
|
||||
endif
|
||||
|
||||
config ADAPTER_ESP07S_WIFI
|
||||
bool "Using wifi adapter device esp07s"
|
||||
default n
|
||||
|
||||
if ADAPTER_ESP07S_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/esp07s_wifi/Kconfig"
|
||||
endif
|
||||
|
|
|
@ -4,4 +4,8 @@ ifeq ($(CONFIG_ADAPTER_HFA21_WIFI),y)
|
|||
SRC_DIR += hfa21_wifi
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_ESP07S_WIFI),y)
|
||||
SRC_DIR += esp07s_wifi
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#ifdef ADAPTER_HFA21_WIFI
|
||||
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
#ifdef ADAPTER_ESP07S_WIFI
|
||||
extern AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_WIFI_NAME "wifi"
|
||||
|
||||
|
@ -77,6 +80,19 @@ int AdapterWifiInit(void)
|
|||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
#ifdef ADAPTER_ESP07S_WIFI
|
||||
AdapterProductInfoType product_info = Esp07sWifiAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterWifiInit ESP07S attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
@ -140,14 +156,14 @@ int AdapterWifiTest(void)
|
|||
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
// AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
AdapterDeviceSetUp(adapter);
|
||||
AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1");
|
||||
AdapterDeviceSetAddr(adapter, "192.168.64.253", "192.168.66.1", "255.255.252.0");
|
||||
AdapterDevicePing(adapter, "36.152.44.95");
|
||||
AdapterDeviceNetstat(adapter);
|
||||
|
||||
const char *ip = "192.168.66.211";
|
||||
const char *ip = "192.168.64.60";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = CLIENT;
|
||||
enum IpType ip_type = IPV4;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef ADAPTER_WIFI_H
|
||||
#define ADAPTER_WIFI_H
|
||||
|
||||
#define CONFIG_WIFI_RESET (0)
|
||||
#define CONFIG_WIFI_RESTORE (1)
|
||||
#define CONFIG_WIFI_BAUDRATE (2)
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,33 @@
|
|||
config ADAPTER_WIFI_ESP07S
|
||||
string "ESP07S WIFI adapter name"
|
||||
default "esp07s_wifi"
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
|
||||
config ADAPTER_ESP07S_DRIVER_EXTUART
|
||||
bool "Using extra uart to support wifi"
|
||||
default n
|
||||
|
||||
config ADAPTER_ESP07S_DRIVER
|
||||
string "ESP07S device uart driver path"
|
||||
default "/dev/uart2_dev2"
|
||||
depends on !ADAPTER_ESP07S_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_ESP07S_DRIVER_EXTUART
|
||||
config ADAPTER_ESP07S_DRIVER
|
||||
string "ESP07S device extra uart driver path"
|
||||
default "/dev/extuart_dev6"
|
||||
|
||||
config ADAPTER_ESP07S_DRIVER_EXT_PORT
|
||||
int "if ESP07S device using extuart, choose port"
|
||||
default "6"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := esp07s_wifi.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,538 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file esp07_wifi.c
|
||||
* @brief Implement the connection wifi adapter function, using ESP07S device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.04.08
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
#include "../adapter_wifi.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LEN_PARA_BUF 128
|
||||
#define SOCKET_PROTOCOL_TCP (6)
|
||||
#define SOCKET_PROTOCOL_UDP (17)
|
||||
|
||||
static int Esp07sWifiSetDown(struct Adapter *adapter_at);
|
||||
|
||||
/**
|
||||
* @description: check AT startup status
|
||||
* @param at_agent - wifi device agent pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiTestAtCmd(ATAgentType at_agent)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = AtCmdConfigAndCheck(at_agent, "AT", "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[AT] config failed!\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int Esp07sUartOpen(struct Adapter *adapter)
|
||||
{
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Open device in read-write mode */
|
||||
adapter->fd = PrivOpen(ADAPTER_ESP07S_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Esp07sWifiOpen get serial %s fd error\n", ADAPTER_ESP07S_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
/* set serial config, serial_baud_rate = 115200 */
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
memset(&cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
|
||||
cfg.serial_baud_rate = BAUD_RATE_115200;
|
||||
cfg.serial_data_bits = DATA_BITS_8;
|
||||
cfg.serial_stop_bits = STOP_BITS_1;
|
||||
cfg.serial_parity_mode = PARITY_NONE;
|
||||
cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||
cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
|
||||
#ifdef ADAPTER_ESP07S_DRIVER_EXT_PORT
|
||||
cfg.ext_uart_no = ADAPTER_ESP07S_DRIVER_EXT_PORT;
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
printf("esp07s uart config ready\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open wifi
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Esp07sWifiOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open esp07s serial port*/
|
||||
Esp07sUartOpen(adapter);
|
||||
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "wifi_uart_client";
|
||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
ATAgentType at_agent = GetATAgent(agent_name);
|
||||
|
||||
adapter->agent = at_agent;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Esp07sWifi open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close wifi
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiClose(struct Adapter *adapter)
|
||||
{
|
||||
Esp07sWifiSetDown(adapter);
|
||||
PrivClose(adapter->fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: send data to adapter
|
||||
* @param adapter - wifi device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiSend(struct Adapter *adapter, const void *data, size_t len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)data, len);
|
||||
}else {
|
||||
printf("Esp07sWifiSend can not find agent!\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param adapter - wifi device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
printf("esp07s receive waiting ... \n");
|
||||
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40);
|
||||
} else {
|
||||
printf("Esp07sWifiReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: connnect wifi to internet
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiSetUp(struct Adapter *adapter)
|
||||
{
|
||||
uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest";
|
||||
uint8 wifi_pwd[LEN_PARA_BUF] = "";
|
||||
char cmd[LEN_PARA_BUF];
|
||||
int ret = 0;
|
||||
char *result = NULL;
|
||||
|
||||
struct ATAgent *agent = adapter->agent;
|
||||
|
||||
/* wait esp07s device startup finish */
|
||||
PrivTaskDelay(2000);
|
||||
|
||||
if(Esp07sWifiTestAtCmd(agent) < 0)
|
||||
{
|
||||
printf("wifi at cmd startup failed.\n");
|
||||
return -1;
|
||||
}
|
||||
/* config as softAP+station mode */
|
||||
ret = AtCmdConfigAndCheck(agent, "AT+CWMODE=3", "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[AT+CWMODE=3] config failed!\n",__func__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* connect the router */
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strncpy(cmd,"AT+CWJAP=",strlen("AT+CWJAP="));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,wifi_ssid,strlen(wifi_ssid));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,",",1);
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,wifi_pwd,strlen(wifi_pwd));
|
||||
strncat(cmd,"\"",1);
|
||||
// strcat(cmd,"\r\n");
|
||||
|
||||
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] connect[%s] failed!\n",__func__,__LINE__,cmd,wifi_ssid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check the wifi ip address */
|
||||
ATReplyType reply = CreateATReply(256);
|
||||
if (NULL == reply) {
|
||||
printf("%s %d at_create_resp failed!\n",__func__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, "AT+CIFSR");
|
||||
if(ret < 0){
|
||||
printf("%s %d ATOrderSend AT+CIFSR failed.\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
result = GetReplyText(reply);
|
||||
if (!result) {
|
||||
printf("%s %n get reply failed.\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
printf("[%s]\n", result);
|
||||
|
||||
__exit:
|
||||
DeleteATReply(reply);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: disconnnect wifi from internet
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK
|
||||
*/
|
||||
static int Esp07sWifiSetDown(struct Adapter *adapter)
|
||||
{
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE");
|
||||
PrivTaskDelay(2000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: set wifi ip/gateway/netmask address(in sta mode)
|
||||
* @param adapter - wifi device pointer
|
||||
* @param ip - ip address
|
||||
* @param gateway - gateway address
|
||||
* @param netmask - netmask address
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Esp07sWifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
int ret = 0;
|
||||
char cmd[LEN_PARA_BUF];
|
||||
|
||||
/* e.g. AT+CIPSTA_DEF="192.168.6.100","192.168.6.1","255.255.255.0" */
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strncpy(cmd,"AT+CIPAP_DEF=",strlen(" AT+CIPAP_DEF="));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,ip,strlen(ip));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,",",1);
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,gateway,strlen(gateway));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,",",1);
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,netmask,strlen(netmask));
|
||||
strncat(cmd,"\"",1);
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config ip failed!\n",__func__,__LINE__,cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: wifi ping function
|
||||
* @param adapter - wifi device pointer
|
||||
* @param destination - domain name or ip address
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Esp07sWifiPing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
char cmd[LEN_PARA_BUF];
|
||||
int ret = 0;
|
||||
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
strncpy(cmd,"AT+PING=",strlen("AT+PING="));
|
||||
strncat(cmd,"\"",1);
|
||||
strncat(cmd,destination,strlen(destination));
|
||||
strncat(cmd,"\"",1);
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd, "OK"); ///< config as softAP+station mode
|
||||
if(ret < 0) {
|
||||
printf("%s %d ping [%s] failed!\n",__func__,__LINE__,destination);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("ping [%s] ok\n", destination);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: display wifi network configuration
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: EOK, failure: ENOMEMORY
|
||||
*/
|
||||
static int Esp07sWifiNetstat(struct Adapter *adapter)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: wifi connect function
|
||||
* @param adapter - wifi device pointer
|
||||
* @param net_role - net role, CLIENT or SERVER
|
||||
* @param ip - ip address
|
||||
* @param port - port num
|
||||
* @param ip_type - ip type, IPV4 or IPV6
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Esp07sWifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int ret = EOK;
|
||||
char cmd[LEN_PARA_BUF];
|
||||
struct ATAgent *agent = adapter->agent;
|
||||
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
if(adapter->socket.protocal == SOCKET_PROTOCOL_TCP && net_role == CLIENT) //esp07s as tcp client to connect server
|
||||
{
|
||||
//e.g. AT+CIPSTART="TCP","192.168.3.116",8080 protocol, server IP and port
|
||||
strncpy(cmd,"AT+CIPSTART=\"TCP\",",strlen("AT+CIPSTART=\"TCP\","));
|
||||
strncat(cmd,"\"",1);
|
||||
strncpy(cmd, ip, strlen(ip));
|
||||
strncat(cmd, "\"", 1);
|
||||
strncat(cmd, ",", 1);
|
||||
strncat(cmd, port, strlen(port));
|
||||
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d tcp connect [%s] failed!\n",__func__,__LINE__,ip);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(adapter->socket.protocal == SOCKET_PROTOCOL_UDP)
|
||||
{
|
||||
//e.g. AT+CIPSTART="UDP","192.168.3.116",8080,2233,0 UDP protocol, server IP, port,local port,udp mode
|
||||
strncpy(cmd,"AT+CIPSTART=\"UDP\",",strlen("AT+CIPSTART=\"UDP\","));
|
||||
strncat(cmd,"\"",1);
|
||||
strncpy(cmd, ip, strlen(ip));
|
||||
strncat(cmd, "\"", 1);
|
||||
strncat(cmd, ",", 1);
|
||||
strncat(cmd, port, strlen(port));
|
||||
strncat(cmd, ",", 1);
|
||||
strncat(cmd, "2233", strlen("2233")); ///< local port
|
||||
strncat(cmd, ",", 1);
|
||||
strncat(cmd, "0", 1); ///< udp transparent transmission mode must be 0
|
||||
|
||||
ret = AtCmdConfigAndCheck(agent, cmd, "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d udp connect [%s] failed!\n",__func__,__LINE__,ip);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=1", "OK"); ///< config as transparent transmission
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config as transparent transmission failed!\n",__func__,__LINE__,cmd);
|
||||
return -1;
|
||||
}
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, NULL, "AT+CIPSEND");
|
||||
|
||||
printf("[%s] connection config as transparent transmission\n",adapter->socket.protocal == SOCKET_PROTOCOL_UDP ? "udp" : "tcp");
|
||||
adapter->net_role = net_role;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: wifi disconnect function
|
||||
* @param adapter - wifi device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Esp07sWifiDisconnect(struct Adapter *adapter)
|
||||
{
|
||||
int ret = EOK;
|
||||
char cmd[LEN_PARA_BUF];
|
||||
struct ATAgent *agent = adapter->agent;
|
||||
memset(cmd,0,sizeof(cmd));
|
||||
|
||||
/* step1: stop transparent transmission mode */
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
|
||||
/* step2: exit transparent transmission mode */
|
||||
ret = AtCmdConfigAndCheck(agent, "AT+CIPMODE=0", "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[AT+CIPMODE=0] exit failed!\n",__func__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* step3: disconnect */
|
||||
ret = AtCmdConfigAndCheck(agent, "AT+CIPCLOSE", "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd [AT+CIPCLOSE] disconnect failed!\n",__func__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Esp07sWifiIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
char baud_str[LEN_PARA_BUF];
|
||||
struct SerialDataCfg cfg;
|
||||
char at_cmd[LEN_PARA_BUF];
|
||||
uint32_t baud_rate = 0 ;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case CONFIG_WIFI_RESET: /* reset wifi */
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RST");
|
||||
break;
|
||||
case CONFIG_WIFI_RESTORE: /* resore wifi */
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "AT+RESTORE");
|
||||
break;
|
||||
case CONFIG_WIFI_BAUDRATE:
|
||||
/* step1: config mcu uart*/
|
||||
baud_rate = *((uint32_t *)args);
|
||||
|
||||
memset(at_cmd, 0, sizeof(at_cmd));
|
||||
memset(baud_str, 0, sizeof(baud_str));
|
||||
memset(&cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
|
||||
cfg.serial_baud_rate = baud_rate;
|
||||
cfg.serial_data_bits = DATA_BITS_8;
|
||||
cfg.serial_stop_bits = STOP_BITS_1;
|
||||
cfg.serial_parity_mode = PARITY_NONE;
|
||||
cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||
cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
|
||||
#ifdef ADAPTER_ESP07S_DRIVER_EXT_PORT
|
||||
cfg.ext_uart_no = ADAPTER_ESP07S_DRIVER_EXT_PORT;
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
/* step2: config wifi uart*/
|
||||
itoa(baud_rate, baud_str, 10);
|
||||
|
||||
strncpy(at_cmd, "AT+UART_DEF=", strlen("AT+UART_DEF="));
|
||||
strncat(at_cmd, baud_str, strlen(baud_str));
|
||||
strncat(at_cmd, ",", 1);
|
||||
strncat(at_cmd, "8", 1);
|
||||
strncat(at_cmd, ",", 1);
|
||||
strncat(at_cmd, "1", 1);
|
||||
strncat(at_cmd, ",", 1);
|
||||
strncat(at_cmd, "0", 1);
|
||||
strncat(at_cmd, ",", 1);
|
||||
strncat(at_cmd, "3", 1);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd [%s] config uart failed!\n",__func__,__LINE__,at_cmd);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone esp07s_wifi_done =
|
||||
{
|
||||
.open = Esp07sWifiOpen,
|
||||
.close = Esp07sWifiClose,
|
||||
.ioctl = Esp07sWifiIoctl,
|
||||
.setup = Esp07sWifiSetUp,
|
||||
.setdown = Esp07sWifiSetDown,
|
||||
.setaddr = Esp07sWifiSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Esp07sWifiPing,
|
||||
.netstat = Esp07sWifiNetstat,
|
||||
.connect = Esp07sWifiConnect,
|
||||
.send = Esp07sWifiSend,
|
||||
.recv = Esp07sWifiReceive,
|
||||
.disconnect = Esp07sWifiDisconnect,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Register wifi device esp07s
|
||||
* @return success: EOK, failure: ERROR
|
||||
*/
|
||||
AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info)
|
||||
{
|
||||
printf("Esp07sWifiAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_WIFI_ESP07S, strlen(ADAPTER_WIFI_ESP07S));
|
||||
|
||||
product_info->model_done = (void *)&esp07s_wifi_done;
|
||||
|
||||
return product_info;
|
||||
}
|
|
@ -18,6 +18,13 @@ endchoice
|
|||
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_E18_MODEPIN
|
||||
int "E18 MODE pin number"
|
||||
default "61"
|
||||
|
||||
config ADAPTER_BC28_PIN_DRIVER
|
||||
string "BC28 device pin driver path"
|
||||
default "/dev/pin_dev"
|
||||
|
||||
config ADAPTER_E18_DRIVER_EXTUART
|
||||
bool "Using extra uart to support zigbee"
|
||||
|
|
|
@ -37,6 +37,33 @@ char *cmd_role_as_e = "AT+DEV=E"; /*set device type for end device*/
|
|||
char *cmd_role_as_r = "AT+DEV=R"; /*set device type for router*/
|
||||
char *cmd_set_ch = "AT+CH=11"; /*set channel as 11*/
|
||||
|
||||
#define E18_AS_HEX_MODE 0
|
||||
#define E18_AS_AT_MODE 1
|
||||
|
||||
static int E18HardwareModeGet()
|
||||
{
|
||||
int ret = 0;
|
||||
int pin_fd;
|
||||
|
||||
pin_fd = PrivOpen(ADAPTER_BC28_PIN_DRIVER, O_RDWR);
|
||||
|
||||
struct PinStat pin_stat;
|
||||
pin_stat.pin = ADAPTER_E18_MODEPIN;
|
||||
|
||||
ret = PrivRead(pin_fd, &pin_stat, 1);
|
||||
|
||||
PrivTaskDelay(200);
|
||||
|
||||
PrivClose(pin_fd);
|
||||
|
||||
if(pin_stat.val == GPIO_HIGH) {
|
||||
printf(" E18 as AT mode\n");
|
||||
return E18_AS_AT_MODE;
|
||||
} else {
|
||||
printf(" E18 as HEX mode\n");
|
||||
return E18_AS_HEX_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int E18UartOpen(struct Adapter *adapter)
|
||||
|
@ -96,15 +123,22 @@ static int E18UartOpen(struct Adapter *adapter)
|
|||
static int E18NetworkModeConfig(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
int mode = -1;
|
||||
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
}
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
mode = E18HardwareModeGet();
|
||||
if(E18_AS_HEX_MODE == mode)
|
||||
{
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (adapter->info->work_mode)
|
||||
{
|
||||
|
@ -141,26 +175,35 @@ static int E18NetworkModeConfig(struct Adapter *adapter)
|
|||
}
|
||||
|
||||
out:
|
||||
AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
if(E18_AS_HEX_MODE == mode){
|
||||
AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int E18NetRoleConfig(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
int mode = -1;
|
||||
|
||||
|
||||
if (NULL == adapter) {
|
||||
printf("%s %d adapter is null!\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
mode = E18HardwareModeGet();
|
||||
if(E18_AS_HEX_MODE == mode)
|
||||
{
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (adapter->net_role)
|
||||
{
|
||||
|
@ -197,7 +240,10 @@ static int E18NetRoleConfig(struct Adapter *adapter)
|
|||
}
|
||||
|
||||
out:
|
||||
AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
if(E18_AS_HEX_MODE == mode) {
|
||||
AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -205,6 +251,7 @@ static int E18Open(struct Adapter *adapter)
|
|||
{
|
||||
int ret = 0;
|
||||
int try_times = 5;
|
||||
int count = 0;
|
||||
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
|
@ -231,9 +278,12 @@ static int E18Open(struct Adapter *adapter)
|
|||
try_again:
|
||||
while(try_times--){
|
||||
ret = E18NetRoleConfig(adapter);
|
||||
count++;
|
||||
if(ret < 0){
|
||||
printf("E18NetRoleConfig failed [%d] times.\n",try_times);
|
||||
goto try_again;
|
||||
printf("E18NetRoleConfig failed [%d] times.\n",count);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,12 +324,17 @@ static int E18Ioctl(struct Adapter *adapter, int cmd, void *args)
|
|||
static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret = 0;
|
||||
int mode = -1;
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
mode = E18HardwareModeGet();
|
||||
if(E18_AS_HEX_MODE == mode)
|
||||
{
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
switch (adapter->net_role)
|
||||
|
@ -327,9 +382,13 @@ static int E18Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
|||
|
||||
// }
|
||||
if(!ret){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_exit);
|
||||
if(E18_AS_HEX_MODE == mode) {
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK");
|
||||
if(ret < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_exit);
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,9 @@
|
|||
menuconfig USING_CONTROL_PLC_OPCUA
|
||||
bool "PLC support OPCUA"
|
||||
default y
|
||||
depends on RESOURCES_LWIP
|
||||
depends on RESOURCES_LWIP
|
||||
|
||||
menuconfig USING_CONTROL_PLC_SOCKET
|
||||
bool "PLC support SOCKET"
|
||||
default y
|
||||
depends on RESOURCES_LWIP
|
||||
|
|
|
@ -6,6 +6,10 @@ ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
|
|||
SRC_DIR += opcua
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USING_CONTROL_PLC_SOCKET), y)
|
||||
SRC_DIR += socket
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
SRC_FILES += interoperability.c
|
||||
|
|
|
@ -68231,11 +68231,11 @@ UA_Log_Stdout_log(void *context, UA_LogLevel level, UA_LogCategory category,
|
|||
// (int)(tOffset / UA_DATETIME_SEC / 36), logLevelNames[level], logCategoryNames[category]);
|
||||
// vprintf(msg, args);
|
||||
|
||||
KPrintf("%s/%s" ANSI_COLOR_RESET "\t",
|
||||
ua_print("%s/%s" ANSI_COLOR_RESET "\t",
|
||||
logLevelNames[level], logCategoryNames[category]);
|
||||
vsnprintf(str, sizeof(str) - 1, msg, args);
|
||||
KPrintf(msg, str);
|
||||
KPrintf("\n");
|
||||
ua_print(msg, str);
|
||||
ua_print("\n");
|
||||
|
||||
// printf("\n");
|
||||
fflush(stdout);
|
||||
|
|
|
@ -28,7 +28,7 @@ int ua_open(void *dev)
|
|||
|
||||
param->client = UA_Client_new();
|
||||
|
||||
ua_pr_info("ua: [%s] start ...\n", __func__);
|
||||
ua_notice("ua: [%s] start ...\n", __func__);
|
||||
|
||||
if (param->client == NULL)
|
||||
{
|
||||
|
@ -39,11 +39,11 @@ int ua_open(void *dev)
|
|||
UA_ClientConfig *config = UA_Client_getConfig(param->client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
|
||||
ua_pr_info("ua: [%s] %d %s\n", __func__, strlen(param->ua_remote_ip), param->ua_remote_ip);
|
||||
ua_notice("ua: [%s] %d %s\n", __func__, strlen(param->ua_remote_ip), param->ua_remote_ip);
|
||||
|
||||
UA_StatusCode retval = UA_Client_connect(param->client, param->ua_remote_ip);
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
ua_pr_info("ua: [%s] deleted ret %x!\n", __func__, retval);
|
||||
ua_notice("ua: [%s] deleted ret %x!\n", __func__, retval);
|
||||
return (int)retval;
|
||||
}
|
||||
return EOK;
|
||||
|
@ -52,7 +52,6 @@ int ua_open(void *dev)
|
|||
void ua_close(void *dev)
|
||||
{
|
||||
UaParamType *param = (UaParamType *)dev;
|
||||
UA_Client_disconnect(param->client);
|
||||
UA_Client_delete(param->client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,9 @@ typedef struct UaParam
|
|||
|
||||
#define ua_print //KPrintf
|
||||
#define ua_trace() //KPrintf("ua: [%s] line %d checked!\n", __func__, __LINE__)
|
||||
#define ua_pr_info KPrintf
|
||||
#define ua_notice KPrintf
|
||||
#define ua_debug //KPrintf
|
||||
#define ua_error KPrintf
|
||||
|
||||
extern const char *opc_server_url;
|
||||
extern char test_ua_ip[];
|
||||
|
|
|
@ -42,7 +42,7 @@ static UA_StatusCode nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId
|
|||
}
|
||||
|
||||
UA_NodeId* parent = (UA_NodeId*)handle;
|
||||
ua_pr_info("%d, %d --- %d ---> NodeId %d, %d\n",
|
||||
ua_notice("%d, %d --- %d ---> NodeId %d, %d\n",
|
||||
parent->namespaceIndex, parent->identifier.numeric,
|
||||
referenceTypeId.identifier.numeric, childId.namespaceIndex,
|
||||
childId.identifier.numeric);
|
||||
|
@ -81,38 +81,38 @@ void ua_print_value(UA_Variant* val)
|
|||
if(val->type == &UA_TYPES[UA_TYPES_LOCALIZEDTEXT])
|
||||
{
|
||||
UA_LocalizedText* ptr = (UA_LocalizedText*)val->data;
|
||||
ua_pr_info("%.*s (Text)\n", ptr->text.length, ptr->text.data);
|
||||
ua_notice("%.*s (Text)\n", ptr->text.length, ptr->text.data);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_UINT32])
|
||||
{
|
||||
UA_UInt32* ptr = (UA_UInt32*)val->data;
|
||||
ua_pr_info("%d (UInt32)\n", *ptr);
|
||||
ua_notice("%d (UInt32)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_BOOLEAN])
|
||||
{
|
||||
UA_Boolean* ptr = (UA_Boolean*)val->data;
|
||||
ua_pr_info("%i (BOOL)\n", *ptr);
|
||||
ua_notice("%i (BOOL)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_INT32])
|
||||
{
|
||||
UA_Int32* ptr = (UA_Int32*)val->data;
|
||||
ua_pr_info("%d (Int32)\n", *ptr);
|
||||
ua_notice("%d (Int32)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_INT16])
|
||||
{
|
||||
UA_Int16* ptr = (UA_Int16*)val->data;
|
||||
ua_pr_info("%d (Int16)\n", *ptr);
|
||||
ua_notice("%d (Int16)\n", *ptr);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_STRING])
|
||||
{
|
||||
UA_String* ptr = (UA_String*)val->data;
|
||||
ua_pr_info("%*.s (String)\n", ptr->length, ptr->data);
|
||||
ua_notice("%*.s (String)\n", ptr->length, ptr->data);
|
||||
}
|
||||
else if(val->type == &UA_TYPES[UA_TYPES_DATETIME])
|
||||
{
|
||||
UA_DateTime* ptr = (UA_DateTime*)val->data;
|
||||
UA_DateTimeStruct dts = UA_DateTime_toStruct(*ptr);
|
||||
ua_pr_info("%d-%d-%d %d:%d:%d.%03d (Time)\n",
|
||||
ua_notice("%d-%d-%d %d:%d:%d.%03d (Time)\n",
|
||||
dts.day, dts.month, dts.year, dts.hour, dts.min, dts.sec, dts.milliSec);
|
||||
}
|
||||
}
|
||||
|
@ -144,14 +144,14 @@ void ua_print_nodeid(UA_NodeId *node_id)
|
|||
switch(node_id->identifierType)
|
||||
{
|
||||
case UA_NODEIDTYPE_NUMERIC:
|
||||
ua_pr_info(" NodeID n%d,%d ", node_id->namespaceIndex, node_id->identifier.numeric);
|
||||
ua_notice(" NodeID n%d,%d ", node_id->namespaceIndex, node_id->identifier.numeric);
|
||||
break;
|
||||
case UA_NODEIDTYPE_STRING:
|
||||
ua_pr_info(" NodeID n%d,%.*s ", node_id->namespaceIndex, node_id->identifier.string.length,
|
||||
ua_notice(" NodeID n%d,%.*s ", node_id->namespaceIndex, node_id->identifier.string.length,
|
||||
node_id->identifier.string.data);
|
||||
break;
|
||||
case UA_NODEIDTYPE_BYTESTRING:
|
||||
ua_pr_info(" NodeID n%d,%s ", node_id->namespaceIndex, node_id->identifier.byteString.data);
|
||||
ua_notice(" NodeID n%d,%s ", node_id->namespaceIndex, node_id->identifier.byteString.data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -160,7 +160,7 @@ void ua_print_nodeid(UA_NodeId *node_id)
|
|||
|
||||
void ua_print_object(UA_BrowseResponse* res)
|
||||
{
|
||||
ua_pr_info("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME");
|
||||
ua_notice("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME");
|
||||
|
||||
for(size_t i = 0; i < res->resultsSize; ++i)
|
||||
{
|
||||
|
@ -170,14 +170,14 @@ void ua_print_object(UA_BrowseResponse* res)
|
|||
|
||||
if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC)
|
||||
{
|
||||
ua_pr_info("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||
ua_notice("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||
ref->nodeId.nodeId.identifier.numeric, (int)ref->browseName.name.length,
|
||||
ref->browseName.name.data, (int)ref->displayName.text.length,
|
||||
ref->displayName.text.data);
|
||||
}
|
||||
else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING)
|
||||
{
|
||||
ua_pr_info("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||
ua_notice("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex,
|
||||
(int)ref->nodeId.nodeId.identifier.string.length,
|
||||
ref->nodeId.nodeId.identifier.string.data,
|
||||
(int)ref->browseName.name.length, ref->browseName.name.data,
|
||||
|
@ -188,7 +188,7 @@ void ua_print_object(UA_BrowseResponse* res)
|
|||
}
|
||||
}
|
||||
|
||||
ua_pr_info("\n");
|
||||
ua_notice("\n");
|
||||
}
|
||||
|
||||
UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValueId* array)
|
||||
|
@ -203,7 +203,7 @@ UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValu
|
|||
|| (response.resultsSize != array_size))
|
||||
{
|
||||
UA_ReadResponse_clear(&response);
|
||||
ua_pr_info("ua: [%s] read failed 0x%x\n", __func__,
|
||||
ua_notice("ua: [%s] read failed 0x%x\n", __func__,
|
||||
response.responseHeader.serviceResult);
|
||||
return UA_STATUSCODE_BADUNEXPECTEDERROR;
|
||||
}
|
||||
|
@ -215,11 +215,11 @@ UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValu
|
|||
if((response.results[i].status == UA_STATUSCODE_GOOD)
|
||||
&& (response.results[i].hasValue))
|
||||
{
|
||||
ua_pr_info("node %s: ", ua_get_nodeid_str(&array[i].nodeId));
|
||||
ua_notice("node %s: ", ua_get_nodeid_str(&array[i].nodeId));
|
||||
ua_print_value(&response.results[i].value);
|
||||
}
|
||||
}
|
||||
ua_pr_info("\n");
|
||||
ua_notice("\n");
|
||||
|
||||
free(arr_ret);
|
||||
UA_ReadResponse_clear(&response);
|
||||
|
@ -229,7 +229,7 @@ UA_StatusCode ua_read_array_value(UA_Client* client, int array_size, UA_ReadValu
|
|||
void ua_browser_id(UA_Client* client, UA_NodeId id)
|
||||
{
|
||||
/* Browse some objects */
|
||||
ua_pr_info("Browsing nodes in objects folder:\n");
|
||||
ua_notice("Browsing nodes in objects folder:\n");
|
||||
UA_BrowseRequest bReq;
|
||||
UA_BrowseRequest_init(&bReq);
|
||||
bReq.requestedMaxReferencesPerNode = 0;
|
||||
|
@ -327,7 +327,7 @@ void ua_write_nodeid_value(UA_Client* client, UA_NodeId id, char* value)
|
|||
|
||||
if(wResp.responseHeader.serviceResult == UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_pr_info("write new value is: %s\n", value);
|
||||
ua_notice("write new value is: %s\n", value);
|
||||
}
|
||||
|
||||
UA_WriteRequest_clear(&wReq);
|
||||
|
@ -489,7 +489,7 @@ void ua_read_time(UA_Client* client)
|
|||
{
|
||||
UA_DateTime raw_date = *(UA_DateTime*) value.data;
|
||||
UA_DateTimeStruct dts = UA_DateTime_toStruct(raw_date);
|
||||
ua_pr_info("date is: %d-%d-%d %d:%d:%d.%03d\n",
|
||||
ua_notice("date is: %d-%d-%d %d:%d:%d.%03d\n",
|
||||
dts.day, dts.month, dts.year, dts.hour, dts.min, dts.sec, dts.milliSec);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ void ua_test_browser_objects(UA_Client *client)
|
|||
ua_browser_id(client, UA_TEST_BROWSER_NODEID);
|
||||
ua_browser_id(client, UA_TEST_BROWSER_NODEID1);
|
||||
test_id = UA_TEST_BROWSER_NODEID1;
|
||||
ua_pr_info("Show values in %s:\n", ua_get_nodeid_str(&test_id));
|
||||
ua_notice("Show values in %s:\n", ua_get_nodeid_str(&test_id));
|
||||
ua_test_read_array(client);
|
||||
return;
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ void ua_test_write_attr(UA_Client *client)
|
|||
char val_str[UA_NODE_LEN];
|
||||
UA_NodeId id = UA_TEST_WRITE_NODEID;
|
||||
|
||||
ua_pr_info("--- Test write %s ---\n", ua_get_nodeid_str(&id));
|
||||
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_pr_info("\n");
|
||||
ua_notice("\n");
|
||||
}
|
||||
|
||||
int ua_test_interact_server(UA_Client *client)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
menuconfig USING_CONTROL_PLC_OPCUA
|
||||
bool "PLC support OPCUA"
|
||||
default y
|
||||
depends on RESOURCES_LWIP
|
||||
|
||||
menuconfig USING_CONTROL_PLC_SOCKET
|
||||
bool "PLC support SOCKET"
|
||||
default y
|
||||
depends on RESOURCES_LWIP
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
SRC_FILES := plc_socket.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# PLC SOCKET README
|
||||
|
||||
## 文件说明
|
||||
|
||||
用于测试PLC socket通信. 通过建立与制定IP的PLC设备的socket连接, 发送命令给PLC设备, 实现相关功能. 实现该功能需要开启LWIP, 同时需要扩大shell的栈大小和内存空间。
|
||||
|
||||
### 命令行
|
||||
|
||||
PLCSocket ip=[PLC IP] port=[PLC port] tcp=[1: TCP; 0: UDP] cmd=[相关命令] file=[制定配置文件]
|
||||
|
||||
配置文件支持json格式, 默认文件名为socket_param.json, 放置于plc目录下, 文件内容如下:
|
||||
|
||||
{
|
||||
"ip": "192.168.250.6",
|
||||
"port": 102,
|
||||
"tcp": 1,
|
||||
"cmd": [x, x, x]
|
||||
}
|
|
@ -0,0 +1,364 @@
|
|||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file plc_socket.c
|
||||
* @brief Demo for PLC socket communication function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.03.16
|
||||
*/
|
||||
|
||||
#include "transform.h"
|
||||
#include "plc_socket.h"
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "control_file.h"
|
||||
|
||||
// max support plc socket test commands number
|
||||
#define PLC_SOCK_CMD_NUM CTL_CMD_NUM
|
||||
#define PLC_SOCK_TIMEOUT 50000
|
||||
|
||||
// for saving PLC command index
|
||||
int plc_cmd_index = 0;
|
||||
|
||||
// only for test
|
||||
#define SUPPORT_PLC_SIEMENS
|
||||
|
||||
//siemens test
|
||||
PlcBinCmdType TestPlcCmd[PLC_SOCK_CMD_NUM] = {0};
|
||||
|
||||
//Test information
|
||||
//SIEMENS ip: 192.168.250.9 port: 102
|
||||
//S7-200 ip: 192.168.250.8 port: 102
|
||||
//S7-1200 ip: 192.168.250.6 port: 102
|
||||
//OML ip: 192.168.250.3 port: 9600
|
||||
|
||||
PlcSocketParamType plc_socket_demo_data = {
|
||||
#ifdef SUPPORT_PLC_SIEMENS
|
||||
.ip = {192, 168, 250, 6},
|
||||
.port = 102,
|
||||
.device_type = PLC_DEV_TYPE_SIEMENS,
|
||||
.socket_type = SOCK_STREAM,
|
||||
.cmd_num = 3,
|
||||
#else
|
||||
.ip = {192, 168, 250, 3},
|
||||
.port = 9600,
|
||||
.device_type = PLC_DEV_TYPE_OML,
|
||||
.socket_type = SOCK_DGRAM,
|
||||
.cmd_num = 1,
|
||||
#endif
|
||||
.recv_len = PLC_RECV_BUF_LEN,
|
||||
.recv_buf = NULL,
|
||||
};
|
||||
|
||||
#define OML_HEADER_LEN 78
|
||||
#define CHECK_OML_HEADER(_s) ((0xC0 == *(_s)) && (0x00 == *(_s + 1)) && (0x02 == *(_s + 2)) && (0x00 == *(_s + 3)))
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void plc_print_array(char *title, int size, uint8_t *cmd)
|
||||
{
|
||||
lw_notice("%s : %d - ", title, size);
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
lw_notice(" %#x", cmd[i]);
|
||||
}
|
||||
lw_notice("\n");
|
||||
}
|
||||
|
||||
static void *PlcSocketStart(void *arg)
|
||||
{
|
||||
int fd = -1;
|
||||
int timeout, recv_len;
|
||||
struct sockaddr_in sock_addr;
|
||||
socklen_t addr_len = sizeof(struct sockaddr_in);
|
||||
PlcSocketParamType *param = (PlcSocketParamType *)&plc_socket_demo_data;
|
||||
|
||||
plc_print("start %d.%d.%d.%d:%d dev %d sock %d\n",
|
||||
param->ip[0],
|
||||
param->ip[1],
|
||||
param->ip[2],
|
||||
param->ip[3],
|
||||
param->port,
|
||||
param->device_type,
|
||||
param->socket_type);
|
||||
|
||||
param->recv_len = PLC_RECV_BUF_LEN;
|
||||
|
||||
//malloc memory
|
||||
param->recv_buf = (char *)malloc(param->recv_len);
|
||||
if (param->recv_buf == NULL)
|
||||
{
|
||||
plc_error("No memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = socket(AF_INET, param->socket_type, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
plc_error("Socket error %d\n", param->socket_type);
|
||||
free(param->recv_buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
plc_print("start %d.%d.%d.%d:%d\n", param->ip[0], param->ip[1], param->ip[2], param->ip[3], param->port);
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_port = htons(param->port);
|
||||
sock_addr.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(param->ip[0], param->ip[1], param->ip[2], param->ip[3]));
|
||||
memset(&(sock_addr.sin_zero), 0, sizeof(sock_addr.sin_zero));
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr)) < 0)
|
||||
{
|
||||
plc_error("Unable to connect\n");
|
||||
closesocket(fd);
|
||||
free(param->recv_buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lw_notice("client %s connected\n", inet_ntoa(sock_addr.sin_addr));
|
||||
|
||||
for(int i = 0; i < param->cmd_num; i ++)
|
||||
{
|
||||
PlcBinCmdType *cmd = &TestPlcCmd[i];
|
||||
sendto(fd, cmd->cmd, cmd->cmd_len, 0, (struct sockaddr*)&sock_addr, addr_len);
|
||||
plc_print_array("Send cmd", cmd->cmd_len, cmd->cmd);
|
||||
|
||||
MdelayKTask(cmd->delay_ms);
|
||||
timeout = PLC_SOCK_TIMEOUT;
|
||||
memset(param->recv_buf, 0, param->recv_len);
|
||||
while(timeout --)
|
||||
{
|
||||
recv_len = recvfrom(fd, param->recv_buf, param->recv_len, 0, (struct sockaddr *)&sock_addr, &addr_len);
|
||||
if(recv_len > 0)
|
||||
{
|
||||
if(param->device_type == PLC_DEV_TYPE_OML)
|
||||
{
|
||||
if((recv_len == OML_HEADER_LEN) && (CHECK_OML_HEADER(param->recv_buf)))
|
||||
{
|
||||
lw_notice("This is Oml package!!!\n");
|
||||
}
|
||||
}
|
||||
lw_notice("Receive from : %s\n", inet_ntoa(sock_addr.sin_addr));
|
||||
plc_print_array("Receive data", recv_len, param->recv_buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
free(param->recv_buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PlcGetParamCmd(char *cmd)
|
||||
{
|
||||
const char s[2] = ",";
|
||||
char *token;
|
||||
uint16_t cmd_index = 0;
|
||||
char bin_cmd[PLC_BIN_CMD_LEN] = {0};
|
||||
token = strtok(cmd, s);
|
||||
while(token != NULL)
|
||||
{
|
||||
sscanf(token, "%x", &bin_cmd[cmd_index]);
|
||||
plc_print("%d - %s %d\n", cmd_index, token, bin_cmd[cmd_index]);
|
||||
token = strtok(NULL, s);
|
||||
cmd_index ++;
|
||||
}
|
||||
TestPlcCmd[plc_cmd_index].cmd_len = cmd_index;
|
||||
memcpy(TestPlcCmd[plc_cmd_index].cmd, bin_cmd, cmd_index);
|
||||
plc_print("get %d cmd len %d\n", plc_cmd_index, TestPlcCmd[plc_cmd_index].cmd_len);
|
||||
plc_cmd_index ++;
|
||||
plc_socket_demo_data.cmd_num = plc_cmd_index;
|
||||
}
|
||||
|
||||
void PlcShowUsage(void)
|
||||
{
|
||||
plc_notice("------------------------------------\n");
|
||||
plc_notice("PlcSocket [ip].[ip].[ip].[ip]:[port]\n");
|
||||
plc_notice("PlcSocket support other param:\n");
|
||||
plc_notice("plc=[] 0: OML 1:SIEMENS\n");
|
||||
plc_notice("tcp=[] 0: udp 1:tcp\n");
|
||||
plc_notice("ip=[ip.ip.ip.ip]\n");
|
||||
plc_notice("port=port\n");
|
||||
plc_notice("file: use %s\n", PLC_SOCK_FILE_NAME);
|
||||
plc_notice("------------------------------------\n");
|
||||
}
|
||||
|
||||
#if defined(MOUNT_SDCARD) && defined(LIB_USING_CJSON)
|
||||
void PlcGetParamFromFile(char *file_name)
|
||||
{
|
||||
PlcSocketParamType *param = &plc_socket_demo_data;
|
||||
|
||||
char *file_buf = malloc(CTL_FILE_LEN);
|
||||
if(file_buf == NULL)
|
||||
{
|
||||
plc_error("No enough buffer %d\n", CTL_FILE_LEN);
|
||||
return;
|
||||
}
|
||||
memset(file_buf, 0, CTL_FILE_LEN);
|
||||
|
||||
if(CtlFileReadWithFilename(file_name, CTL_FILE_LEN, file_buf) != EOK)
|
||||
{
|
||||
plc_error("Can't open file %s\n", file_name);
|
||||
//try again default file
|
||||
if(strcmp(file_name, PLC_SOCK_FILE_NAME) != 0)
|
||||
{
|
||||
if(CtlFileReadWithFilename(PLC_SOCK_FILE_NAME, CTL_FILE_LEN, file_buf) != EOK)
|
||||
{
|
||||
plc_error("Can't open file %s\n", file_name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
CtlParseJsonData(file_buf);
|
||||
|
||||
memcpy(param->ip, ctl_file_param.ip, 4);
|
||||
param->port = ctl_file_param.port;
|
||||
param->cmd_num = ctl_file_param.cmd_num;
|
||||
param->socket_type = ctl_file_param.tcp ? SOCK_STREAM : SOCK_DGRAM;
|
||||
|
||||
for(int i = 0; i < param->cmd_num; i++)
|
||||
{
|
||||
TestPlcCmd[i].cmd_len = ctl_file_param.cmd_len[i];
|
||||
memcpy(TestPlcCmd[i].cmd, ctl_file_param.cmd[i], TestPlcCmd[i].cmd_len);
|
||||
}
|
||||
|
||||
plc_print("ip: %d.%d.%d.%d\n", param->ip[0], param->ip[1], param->ip[2], param->ip[3]);
|
||||
plc_print("port: %d", param->port);
|
||||
plc_print("tcp: %d", param->socket_type);
|
||||
plc_print("cmd number: %d\n", param->cmd_num);
|
||||
|
||||
for(int i = 0; i < param->cmd_num; i++)
|
||||
{
|
||||
plc_print_array("cmd", TestPlcCmd[i].cmd_len, TestPlcCmd[i].cmd);
|
||||
}
|
||||
free(file_buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void PlcCheckParam(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
PlcSocketParamType *param = &plc_socket_demo_data;
|
||||
plc_cmd_index = 0;
|
||||
|
||||
for(i = 0; i < argc; i++)
|
||||
{
|
||||
char *str = argv[i];
|
||||
int is_tcp = 0;
|
||||
char cmd_str[PLC_BIN_CMD_LEN] = {0};
|
||||
|
||||
plc_print("check %d %s\n", i, str);
|
||||
|
||||
#if defined(MOUNT_SDCARD) && defined(LIB_USING_CJSON)
|
||||
if(strncmp(str, "file", 4) == 0)
|
||||
{
|
||||
char file_name[CTL_FILE_NAME_LEN] = {0};
|
||||
if(sscanf(str, "file=%s", file_name) == EOF)
|
||||
{
|
||||
strcpy(file_name, PLC_SOCK_FILE_NAME);
|
||||
}
|
||||
plc_notice("get %s parameter file %s\n", str, file_name);
|
||||
PlcGetParamFromFile(file_name);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if(sscanf(str, "ip=%d.%d.%d.%d",
|
||||
¶m->ip[0],
|
||||
¶m->ip[1],
|
||||
¶m->ip[2],
|
||||
¶m->ip[3]) == 4)
|
||||
{
|
||||
plc_print("find ip %d %d %d %d\n", param->ip[0], param->ip[1], param->ip[2], param->ip[3]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sscanf(str, "port=%d", ¶m->port) == 1)
|
||||
{
|
||||
plc_print("find port %d\n", param->port);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sscanf(str, "tcp=%d", &is_tcp) == 1)
|
||||
{
|
||||
plc_print("find tcp %d\n", is_tcp);
|
||||
param->socket_type = is_tcp ? SOCK_STREAM:SOCK_DGRAM;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sscanf(str, "plc=%d", ¶m->device_type) == 1)
|
||||
{
|
||||
plc_print("find device %d\n", param->device_type);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(sscanf(str, "cmd=%s", cmd_str) == 1)
|
||||
{
|
||||
plc_print("find cmd %s\n", cmd_str);
|
||||
PlcGetParamCmd(cmd_str);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(argc >= 2)
|
||||
{
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d:%d",
|
||||
¶m->ip[0],
|
||||
¶m->ip[1],
|
||||
¶m->ip[2],
|
||||
¶m->ip[3],
|
||||
¶m->port) != EOF)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d",
|
||||
¶m->ip[0],
|
||||
¶m->ip[1],
|
||||
¶m->ip[2],
|
||||
¶m->ip[3]) != EOF)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PlcShowUsage();
|
||||
}
|
||||
}
|
||||
|
||||
void PlcSocketTask(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = LWIP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_TASK_STACK_SIZE;
|
||||
PlcSocketParamType *param = &plc_socket_demo_data;
|
||||
|
||||
PlcCheckParam(argc, argv);
|
||||
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, param->ip);
|
||||
PrivTaskCreate(&th_id, &attr, PlcSocketStart, param);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcSocket, PlcSocketTask, Test PLC Socket);
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file plc_socket.h
|
||||
* @brief Demo for PLC socket communication function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.03.16
|
||||
*/
|
||||
|
||||
#ifndef __PLC_SOCKET_H_
|
||||
#define __PLC_SOCKET_H_
|
||||
|
||||
#define PLC_BIN_CMD_LEN 512
|
||||
|
||||
// for plc socket test bin commands
|
||||
typedef struct
|
||||
{
|
||||
uint16_t delay_ms;
|
||||
uint8_t cmd_len;
|
||||
uint8_t cmd[PLC_BIN_CMD_LEN];
|
||||
}PlcBinCmdType;
|
||||
|
||||
enum PlcDeviceType {
|
||||
PLC_DEV_TYPE_OML = 0,
|
||||
PLC_DEV_TYPE_IPC,
|
||||
PLC_DEV_TYPE_BRL,
|
||||
PLC_DEV_TYPE_SIEMENS,
|
||||
PLC_DEV_TYPE_SIEMENS_1200,
|
||||
PLC_DEV_TYPE_JF_IPC,
|
||||
PLC_DEV_TYPE_HG,
|
||||
/* ...... */
|
||||
PLC_DEV_TYPE_END,
|
||||
};
|
||||
|
||||
#define PLC_IP_LEN 16
|
||||
#define PLC_DEV_NAME_LEN 32
|
||||
#define PLC_RECV_BUF_LEN CTL_FILE_LEN
|
||||
|
||||
typedef struct PlcSocketParamStruct{
|
||||
char ip[PLC_IP_LEN];
|
||||
uint32_t port;
|
||||
uint32_t device_type; //PlcDeviceType
|
||||
uint32_t socket_type; //UDP or TCP
|
||||
char device[PLC_DEV_NAME_LEN];
|
||||
uint32_t cmd_num; // command number
|
||||
uint32_t recv_len; // receive length
|
||||
uint8_t *recv_buf; // receive buffer
|
||||
}PlcSocketParamType;
|
||||
|
||||
//debug command
|
||||
#define plc_print //KPrintf
|
||||
#define plc_error KPrintf
|
||||
#define plc_notice KPrintf
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
SRC_FILES := control.c
|
||||
|
||||
ifeq ($(CONFIG_MOUNT_SDCARD),y)
|
||||
SRC_FILES += control_file.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file control_file.c
|
||||
* @brief control relative file operation
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-17
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cJSON.h"
|
||||
#include "transform.h"
|
||||
#include "control_file.h"
|
||||
|
||||
//json file parameter for PLC socket communication as below:
|
||||
//{
|
||||
// "ip": "192.168.250.6",
|
||||
// "port": 102,
|
||||
// "cmd": [3, 0, 0, 22, 17, 224, 0, 0, 2, 200, 0, 193, 2, 2, 1, 194, 2, 2, 1, 192, 1, 10],
|
||||
// "cmd1": [3, 0, 0, 25, 2, 240, 128, 50, 1, 0, 0, 0, 13, 0, 8, 0, 0, 240, 0, 0, 1, 0, 1, 0, 240], \r\n" \
|
||||
// "cmd2": [3, 0, 0, 31, 2, 240, 128, 50, 1, 0, 0, 51, 1, 0, 14, 0, 0, 4, 1, 18, 10, 16, 2, 0, 210, 0, 52, 132, 0, 0, 0]\r\n" \
|
||||
//}"
|
||||
|
||||
#define TEST_PLC_JSON_TXT \
|
||||
"{ \r\n"\
|
||||
" \"ip\": \"192.168.250.6\", \r\n"\
|
||||
" \"port\": 102, \r\n"\
|
||||
" \"tcp\": 1, \r\n"\
|
||||
" \"cmd\": [3, 0, 0, 22, 17, 224, 0, 0, 2, 200, 0, 193, 2, 2, 1, 194, 2, 2, 1, 192, 1, 10], \r\n"\
|
||||
" \"cmd1\": [3, 0, 0, 25, 2, 240, 128, 50, 1, 0, 0, 0, 13, 0, 8, 0, 0, 240, 0, 0, 1, 0, 1, 0, 240], \r\n" \
|
||||
" \"cmd2\": [3, 0, 0, 31, 2, 240, 128, 50, 1, 0, 0, 51, 1, 0, 14, 0, 0, 4, 1, 18, 10, 16, 2, 0, 210, 0, 52, 132, 0, 0, 0]\r\n" \
|
||||
"}"
|
||||
|
||||
|
||||
CtlPlcSockParamType ctl_file_param;
|
||||
|
||||
FILE *CtlFileInit(char *file)
|
||||
{
|
||||
FILE *fd = NULL;
|
||||
|
||||
#ifdef MOUNT_SDCARD
|
||||
// SD card mount flag 1: OK
|
||||
if(sd_mount_flag == 0)
|
||||
{
|
||||
ctl_error("SD card mount failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = fopen(file, "a+");
|
||||
if(fd == NULL)
|
||||
{
|
||||
ctl_error("open file %s failed\n", file);
|
||||
}
|
||||
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
|
||||
void CtlFileClose(FILE *fd)
|
||||
{
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
void CtlFileRead(FILE *fd, int size, char *buf)
|
||||
{
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
fread(buf, size, 1, fd);
|
||||
ctl_print("read file %d: %.100s\n", size, buf);
|
||||
}
|
||||
|
||||
void CtlFileWrite(FILE *fd, int size, char *buf)
|
||||
{
|
||||
size_t write_size = 0;
|
||||
write_size = fwrite(buf, strlen(buf) + 1, 1, fd);
|
||||
ctl_print("write size %d: %s\n", size, buf);
|
||||
}
|
||||
|
||||
int CtlFileReadWithFilename(char *file, int size, char *buf)
|
||||
{
|
||||
FILE *fd;
|
||||
fd = fopen(file, "r");
|
||||
if(fd == NULL)
|
||||
{
|
||||
ctl_error("open file %s failed\n", file);
|
||||
return EEMPTY;
|
||||
}
|
||||
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
fread(buf, size, 1, fd);
|
||||
ctl_print("read file %d: %.100s\n", size, buf);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
void CtlCreateFileTest(void)
|
||||
{
|
||||
FILE *fd = CtlFileInit(PLC_SOCK_FILE_NAME);
|
||||
if(fd == NULL)
|
||||
return;
|
||||
char *file_buf = TEST_PLC_JSON_TXT;
|
||||
CtlFileWrite(fd, strlen(file_buf), file_buf);
|
||||
CtlFileClose(fd);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
CtlCreateFile, CtlCreateFileTest, Test control file);
|
||||
|
||||
#ifdef LIB_USING_CJSON
|
||||
|
||||
void CtlParseJsonArray(cJSON *dat, int *cmd_len, char *cmd)
|
||||
{
|
||||
int len, i;
|
||||
if(cJSON_IsArray(dat))
|
||||
{
|
||||
len = cJSON_GetArraySize(dat);
|
||||
ctl_print("json cmd %d\n", len);
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
cJSON *cmd_val = cJSON_GetArrayItem(dat, i);
|
||||
if(NULL == cmd_val)
|
||||
continue;
|
||||
ctl_print("0x%x ", cmd_val->valueint);
|
||||
cmd[i] = cmd_val->valueint;
|
||||
}
|
||||
*cmd_len = len;
|
||||
ctl_print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void CtlParseJsonData(char *buf)
|
||||
{
|
||||
cJSON *file_dat = NULL;
|
||||
cJSON *ip_dat = NULL;
|
||||
cJSON *port_dat = NULL;
|
||||
cJSON *tcp_dat = NULL;
|
||||
cJSON *cmd_dat = NULL;
|
||||
char cmd_title[10] = {"cmd"};
|
||||
CtlPlcSockParamType *file_param = &ctl_file_param;
|
||||
|
||||
file_dat = cJSON_Parse(buf);
|
||||
if(file_dat == NULL)
|
||||
{
|
||||
ctl_error("ctrl parse failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ip_dat = cJSON_GetObjectItem(file_dat, "ip");
|
||||
port_dat = cJSON_GetObjectItem(file_dat, "port");
|
||||
tcp_dat = cJSON_GetObjectItem(file_dat, "tcp");
|
||||
|
||||
ctl_print(" ip : %s\n", ip_dat->valuestring);
|
||||
sscanf(ip_dat->valuestring, "%d.%d.%d.%d", &file_param->ip[0],
|
||||
&file_param->ip[1],
|
||||
&file_param->ip[2],
|
||||
&file_param->ip[3]);
|
||||
|
||||
ctl_print(" port: %s %d\n", ip_dat->string, port_dat->valueint);
|
||||
file_param->port = port_dat->valueint;
|
||||
file_param->tcp = tcp_dat->valueint;
|
||||
file_param->cmd_num = 0;
|
||||
|
||||
for(int i = 0; i < CTL_CMD_NUM; i++)
|
||||
{
|
||||
cmd_dat = cJSON_GetObjectItem(file_dat, cmd_title);
|
||||
if(!cmd_dat)
|
||||
break;
|
||||
CtlParseJsonArray(cmd_dat, &file_param->cmd_len[i], file_param->cmd[i]);
|
||||
snprintf(cmd_title, sizeof(cmd_title), "cmd%d", ++file_param->cmd_num);
|
||||
}
|
||||
|
||||
cJSON_Delete(file_dat);
|
||||
}
|
||||
|
||||
void CtlParseFileTest(void)
|
||||
{
|
||||
//for PLC socket parameter file
|
||||
FILE *fd = CtlFileInit(PLC_SOCK_FILE_NAME);
|
||||
if(fd == NULL)
|
||||
{
|
||||
ctl_error("ctl get file %s failed\n", PLC_SOCK_FILE_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
char *file_buf = malloc(CTL_FILE_LEN);
|
||||
|
||||
if(file_buf == NULL)
|
||||
{
|
||||
ctl_error("ctl malloc failed\n");
|
||||
return;
|
||||
}
|
||||
memset(file_buf, 0, CTL_FILE_LEN);
|
||||
CtlFileRead(fd, CTL_FILE_LEN, file_buf);
|
||||
CtlFileClose(fd);
|
||||
CtlParseJsonData(file_buf);
|
||||
free(file_buf);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
CtlParseFile, CtlParseFileTest, Parse control file);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file control_file.h
|
||||
* @brief control relative API
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-17
|
||||
*/
|
||||
|
||||
#ifndef __CONTROL_FILE_H_
|
||||
#define __CONTROL_FILE_H_
|
||||
|
||||
#define CTL_FILE_LEN 1000 // control file size
|
||||
#define CTL_CMD_NUM 10 // support command number
|
||||
#define CTL_CMD_LEN 100 // control command length
|
||||
#define CTL_IP_LEN 32 // IP address length
|
||||
#define CTL_FILE_NAME_LEN 100 // file name length
|
||||
|
||||
#define PLC_SOCK_FILE_NAME "/plc/socket_param.json"
|
||||
|
||||
#define ctl_print //KPrintf
|
||||
#define ctl_error KPrintf
|
||||
|
||||
// for running plc socket
|
||||
typedef struct CtlPlcSockParamStruct
|
||||
{
|
||||
char ip[CTL_IP_LEN];
|
||||
int port;
|
||||
int tcp; // 1: TCP 0: UDP
|
||||
int cmd_num; //command number
|
||||
int cmd_len[CTL_CMD_NUM]; // command length
|
||||
char cmd[CTL_CMD_NUM][CTL_CMD_LEN];
|
||||
}CtlPlcSockParamType;
|
||||
|
||||
extern CtlPlcSockParamType ctl_file_param;
|
||||
extern int sd_mount_flag;
|
||||
|
||||
FILE *CtlFileInit(char *file);
|
||||
void CtlFileClose(FILE *fd);
|
||||
void CtlFileRead(FILE *fd, int size, char *buf);
|
||||
void CtlFileWrite(FILE *fd, int size, char *buf);
|
||||
int CtlFileReadWithFilename(char *file_name, int size, char *buf);
|
||||
|
||||
#ifdef LIB_USING_CJSON
|
||||
void CtlParseJsonData(char *buf);
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -34,6 +34,11 @@ config SENSOR_QS_FX
|
|||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config SENSOR_DEVICE_QS_FX_DEV
|
||||
string "qs-fx device name"
|
||||
default "/dev/ttyS1"
|
||||
---help---
|
||||
If USART1 is selected, then fill in /dev/ttyS1 here.
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/sensor/winddirection/Make.defs
|
||||
############################################################################
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/winddirection/*/Make.defs)
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/sensor/winddirection/qs-fx/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SENSOR_QS_FX),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/winddirection/qs-fx
|
||||
endif
|
|
@ -1,3 +1,11 @@
|
|||
SRC_FILES := qs-fx.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += qs-fx.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := qs-fx.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
|
|
@ -35,6 +35,18 @@ static struct SensorProductInfo info =
|
|||
* @param sdev - sensor device pointer
|
||||
* @return success: 1 , failure: other
|
||||
*/
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_QS_FX_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_QS_FX_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sdev->fd ;
|
||||
}
|
||||
#else
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -64,7 +76,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @description: Read sensor device
|
||||
|
|
|
@ -34,6 +34,11 @@ config SENSOR_QS_FS
|
|||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config SENSOR_DEVICE_QS_FS_DEV
|
||||
string "qs-fx device name"
|
||||
default "/dev/ttyS1"
|
||||
---help---
|
||||
If USART1 is selected, then fill in /dev/ttyS1 here.
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/sensor/windspeed/Make.defs
|
||||
############################################################################
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/windspeed/*/Make.defs)
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/sensor/windspeed/qs-fs/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SENSOR_QS_FS),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/windspeed/qs-fs
|
||||
endif
|
|
@ -1,3 +1,11 @@
|
|||
SRC_FILES := qs-fs.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += qs-fs.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := qs-fs.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
|
|
@ -35,6 +35,17 @@ static struct SensorProductInfo info =
|
|||
* @param sdev - sensor device pointer
|
||||
* @return success: 1 , failure: other
|
||||
*/
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_QS_FS_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_QS_FS_DEV);
|
||||
return -1;
|
||||
}
|
||||
return sdev->fd;
|
||||
}
|
||||
#else
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -65,6 +76,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @description: Read sensor device
|
||||
|
|
|
@ -5,12 +5,12 @@ menu "lib"
|
|||
|
||||
config APP_SELECT_NEWLIB
|
||||
bool "app select newlib"
|
||||
|
||||
|
||||
config APP_SELECT_OTHER_LIB
|
||||
bool "app select other lib"
|
||||
endchoice
|
||||
source "$APP_DIR/lib/cJSON/Kconfig"
|
||||
source "$APP_DIR/lib/queue/Kconfig"
|
||||
source "$APP_DIR/lib/queue/Kconfig"
|
||||
source "$APP_DIR/lib/lvgl/Kconfig"
|
||||
source "$APP_DIR/lib/embedded_database/Kconfig"
|
||||
endmenu
|
||||
|
|
|
@ -10,5 +10,8 @@ ifeq ($(CONFIG_LIB_LV),y)
|
|||
SRC_DIR += lvgl
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIB_USING_CJSON),y)
|
||||
SRC_DIR += cJSON
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := cJSON.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue