add XiUOS code #2
|
|
@ -0,0 +1,22 @@
|
|||
menu "Applications"
|
||||
|
||||
menu "config stack size and priority of main task"
|
||||
config MAIN_KTASK_STACK_SIZE
|
||||
int "Set main task stack size"
|
||||
default 1024
|
||||
config MAIN_KTASK_PRIORITY
|
||||
int
|
||||
default 4 if KTASK_PRIORITY_8
|
||||
default 16 if KTASK_PRIORITY_32
|
||||
default 85 if KTASK_PRIORITY_256
|
||||
endmenu
|
||||
|
||||
source "$APP_DIR/Applications/ota/Kconfig"
|
||||
|
||||
source "$APP_DIR/Applications/app_test/Kconfig"
|
||||
source "$APP_DIR/Applications/connection_app/Kconfig"
|
||||
source "$APP_DIR/Applications/control_app/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/Kconfig"
|
||||
source "$APP_DIR/Applications/sensor_app/Kconfig"
|
||||
source "$APP_DIR/Applications/embedded_database_app/Kconfig"
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
############################################################################
|
||||
# APP_Framework/Applications/Make.defs
|
||||
############################################################################
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/general_functions/list
|
||||
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Applications/*/Make.defs)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += framework_init.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_DIR := general_functions app_test
|
||||
|
||||
SRC_FILES := main.c framework_init.c
|
||||
ifeq ($(CONFIG_LIB_LV),y)
|
||||
SRC_DIR += lv_app
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_OTA),y)
|
||||
SRC_DIR += ota
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
|
||||
SRC_DIR += sensor_app
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_CONNECTION),y)
|
||||
SRC_DIR += connection_app
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_KNOWING),y)
|
||||
SRC_DIR += knowing_app
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_CONTROL),y)
|
||||
SRC_DIR += control_app
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
SOURCES = ['framework_init.c']
|
||||
path = [cwd]
|
||||
objs = []
|
||||
group = DefineGroup('sensor', SOURCES, depend = [], CPPPATH = [cwd])
|
||||
objs = objs + group
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
menu "test app"
|
||||
menuconfig USER_TEST
|
||||
bool "Enable application test function "
|
||||
default n
|
||||
|
||||
if USER_TEST
|
||||
config USER_TEST_SPI_FLASH
|
||||
bool "Config test spi flash"
|
||||
default n
|
||||
|
||||
menuconfig USER_TEST_ADC
|
||||
bool "Config test adc"
|
||||
default n
|
||||
if USER_TEST_ADC
|
||||
if ADD_XIZI_FETURES
|
||||
config ADC_DEV_DRIVER
|
||||
string "Set ADC dev path"
|
||||
default "/dev/adc1_dev"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_DAC
|
||||
bool "Config test dac"
|
||||
default n
|
||||
if USER_TEST_DAC
|
||||
if ADD_XIZI_FETURES
|
||||
config DAC_DEV_DRIVER
|
||||
string "Set DAC dev path"
|
||||
default "/dev/dac_dev"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
|
||||
SRC_FILES += test_spi_flash.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
SRC_FILES += test_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_DAC),y)
|
||||
SRC_FILES += test_dac.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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: test_adc.c
|
||||
* @brief: a application of adc function
|
||||
* @version: 1.1
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/1/7
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
void test_adc()
|
||||
{
|
||||
int adc_fd;
|
||||
uint8 adc_channel = 0x0;
|
||||
uint16 adc_sample, adc_value_decimal = 0;
|
||||
float adc_value;
|
||||
|
||||
adc_fd = PrivOpen(ADC_DEV_DRIVER, O_RDWR);
|
||||
if (adc_fd < 0) {
|
||||
printf("open adc fd error %d\n", adc_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = ADC_TYPE;
|
||||
ioctl_cfg.args = &adc_channel;
|
||||
if (0 != PrivIoctl(adc_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
printf("ioctl adc fd error %d\n", adc_fd);
|
||||
PrivClose(adc_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PrivRead(adc_fd, &adc_sample, 2);
|
||||
|
||||
adc_value = (float)adc_sample * (3.3 / 4096);
|
||||
|
||||
adc_value_decimal = (adc_value - (uint16)adc_value) * 1000;
|
||||
|
||||
printf("adc sample %u value integer %u decimal %u\n", adc_sample, (uint16)adc_value, adc_value_decimal);
|
||||
|
||||
PrivClose(adc_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
adc, test_adc, read 3.3 voltage data from adc);
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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: test_dac.c
|
||||
* @brief: a application of dac function
|
||||
* @version: 2.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/1/11
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
void test_dac()
|
||||
{
|
||||
int dac_fd;
|
||||
uint16 dac_set_value = 800;
|
||||
uint16 dac_sample, dac_value_decimal = 0;
|
||||
float dac_value;
|
||||
|
||||
dac_fd = PrivOpen(DAC_DEV_DRIVER, O_RDWR);
|
||||
if (dac_fd < 0) {
|
||||
KPrintf("open dac fd error %d\n", dac_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = DAC_TYPE;
|
||||
ioctl_cfg.args = &dac_set_value;
|
||||
if (0 != PrivIoctl(dac_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
KPrintf("ioctl dac fd error %d\n", dac_fd);
|
||||
PrivClose(dac_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PrivRead(dac_fd, &dac_sample, 2);
|
||||
|
||||
dac_value = (float)dac_sample * (3.3 / 4096);//Vref+ need to be 3.3V
|
||||
|
||||
dac_value_decimal = (dac_value - (uint16)dac_value) * 1000;
|
||||
|
||||
printf("dac sample %u value integer %u decimal %u\n", dac_sample, (uint16)dac_value, dac_value_decimal);
|
||||
|
||||
PrivClose(dac_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
test_dac, test_dac, set digital data to dac);
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2016-09-28 armink first version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_spi_flash.c
|
||||
* @brief support to test spi flash function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-17
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: test_spi_flash.c
|
||||
Description: support spi flash function test
|
||||
Others: add spi flash test cmd from SFUD/blob/master/demo/stm32f2xx_rtt/RT-Thread-2.1.0/components/drivers/spi/spi_flash_sfud.c
|
||||
https://github.com/armink/SFUD/
|
||||
History:
|
||||
1. Date: 2021-05-17
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. support spi flash open, read and write function
|
||||
*************************************************/
|
||||
|
||||
#include <xizi.h>
|
||||
#include <device.h>
|
||||
#include <flash_spi.h>
|
||||
#include <user_api.h>
|
||||
|
||||
#define SPI_FLASH_PATH "/dev/spi1_W25Q64"
|
||||
#define FlashDataPrint(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
|
||||
|
||||
static int spi_flash_fd;
|
||||
|
||||
void FlashOpen(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
spi_flash_fd = open(SPI_FLASH_PATH, O_RDWR);
|
||||
if (spi_flash_fd < 0) {
|
||||
KPrintf("open spi flash fd error %d\n", spi_flash_fd);
|
||||
}
|
||||
|
||||
KPrintf("Spi Flash init succeed\n");
|
||||
|
||||
return;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
FlashOpen, FlashOpen, open spi flash device);
|
||||
|
||||
void FlashRead(int argc, char *argv[])
|
||||
{
|
||||
x_size_t i, j = 0;
|
||||
uint32 addr;
|
||||
uint32 size;
|
||||
uint8 data[16];
|
||||
|
||||
struct BusBlockReadParam read_param;
|
||||
memset(&read_param, 0, sizeof(struct BusBlockReadParam));
|
||||
|
||||
memset(data, 0, 16);
|
||||
|
||||
if (3 != argc) {
|
||||
KPrintf("FlashRead cmd format: FlashRead addr size.\n");
|
||||
return;
|
||||
} else {
|
||||
addr = strtol(argv[1], NULL, 0);
|
||||
size = strtol(argv[2], NULL, 0);
|
||||
|
||||
read_param.buffer = data;
|
||||
read_param.pos = addr;
|
||||
read_param.size = size;
|
||||
|
||||
if (read_param.buffer) {
|
||||
read(spi_flash_fd, &read_param, size);
|
||||
if (size == read_param.read_length) {
|
||||
KPrintf("Read the %s flash data success. Start from 0x%08X, size is %ld. The data is:\n",
|
||||
SPI_FLASH_PATH, addr, size);
|
||||
KPrintf("Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n");
|
||||
for (i = 0; i < size; i += 16) {
|
||||
KPrintf("[%08X] ", addr + i);
|
||||
/* dump hex */
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (i + j < size) {
|
||||
KPrintf("%02X ", data[i + j]);
|
||||
} else {
|
||||
KPrintf(" ");
|
||||
}
|
||||
}
|
||||
/* dump char for hex */
|
||||
for (j = 0; j < 16; j++) {
|
||||
if (i + j < size) {
|
||||
KPrintf("%c", FlashDataPrint(data[i + j]) ? data[i + j] : '.');
|
||||
}
|
||||
}
|
||||
KPrintf("\n");
|
||||
}
|
||||
KPrintf("\n");
|
||||
}
|
||||
} else {
|
||||
KPrintf("SpiFlashRead alloc read buffer failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
FlashRead, FlashRead, read data from spi flash device);
|
||||
|
||||
void FlashWrite(int argc, char *argv[])
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
x_size_t i, j = 0;
|
||||
uint32 addr;
|
||||
uint32 size;
|
||||
uint8 data[16];
|
||||
|
||||
struct BusBlockWriteParam write_param;
|
||||
memset(&write_param, 0, sizeof(struct BusBlockWriteParam));
|
||||
|
||||
memset(data, 0, 16);
|
||||
|
||||
if (argc < 3) {
|
||||
KPrintf("FlashWrite cmd format: FlashWrite addr data.\n");
|
||||
return;
|
||||
} else {
|
||||
addr = strtol(argv[1], NULL, 0);
|
||||
size = argc - 2;
|
||||
|
||||
write_param.buffer = data;
|
||||
write_param.pos = addr;
|
||||
write_param.size = size;
|
||||
|
||||
if (data) {
|
||||
for (i = 0; i < size; i++) {
|
||||
data[i] = strtol(argv[2 + i], NULL, 0);
|
||||
}
|
||||
|
||||
ret = write(spi_flash_fd, &write_param, size);
|
||||
if (EOK == ret) {
|
||||
KPrintf("Write the %s flash data success. Start from 0x%08X, size is %ld.\n",
|
||||
SPI_FLASH_PATH, addr, size);
|
||||
KPrintf("Write data: ");
|
||||
for (i = 0; i < size; i++) {
|
||||
KPrintf("%d ", data[i]);
|
||||
}
|
||||
KPrintf(".\n");
|
||||
}
|
||||
} else {
|
||||
KPrintf("SpiFlashWrite alloc write buffer failed!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
FlashWrite, FlashWrite, write data to spi flash device);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
menu "connection app"
|
||||
|
||||
menuconfig APPLICATION_CONNECTION
|
||||
bool "Using connection apps"
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
SRC_DIR :=
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||
SRC_DIR += socket_demo
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := lwip_tcp_socket_demo.c lwip_udp_socket_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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 lwip_tcp_socket_demo.c
|
||||
* @brief TCP socket demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include "sys_arch.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
|
||||
#define TCP_DEMO_BUF_SIZE 65535
|
||||
|
||||
char tcp_socket_ip[] = {192, 168, 250, 252};
|
||||
u16_t tcp_socket_port = LWIP_TARGET_PORT;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void TCPSocketRecvTask(void *arg)
|
||||
{
|
||||
int fd = -1, clientfd;
|
||||
int recv_len;
|
||||
char *recv_buf;
|
||||
struct sockaddr_in tcp_addr;
|
||||
socklen_t addr_len;
|
||||
|
||||
while(1)
|
||||
{
|
||||
recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE);
|
||||
if (recv_buf == NULL)
|
||||
{
|
||||
lw_error("No memory\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
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(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_error("Unable to bind\n");
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
lw_print("tcp bind success, start to receive.\n");
|
||||
lw_notice("\n\nLocal Port:%d\n\n", tcp_socket_port);
|
||||
|
||||
// setup socket fd as listening mode
|
||||
if (listen(fd, 5) != 0 )
|
||||
{
|
||||
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_notice("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
|
||||
|
||||
while(1)
|
||||
{
|
||||
memset(recv_buf, 0, TCP_DEMO_BUF_SIZE);
|
||||
recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len);
|
||||
if(recv_len > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
}
|
||||
|
||||
void TCPSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if(argc >= 2)
|
||||
{
|
||||
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("TCPSocketRecvTask", TCPSocketRecvTask, 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),
|
||||
TCPSocketRecv, TCPSocketRecvTest, TCP recv echo);
|
||||
|
||||
static void TCPSocketSendTask(void *arg)
|
||||
{
|
||||
int cnt = LWIP_DEMO_TIMES;
|
||||
int fd = -1;
|
||||
char send_msg[128];
|
||||
|
||||
lw_print("%s start\n", __func__);
|
||||
|
||||
memset(send_msg, 0, sizeof(send_msg));
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in tcp_sock;
|
||||
tcp_sock.sin_family = AF_INET;
|
||||
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");
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
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_notice("Send tcp msg: %s ", send_msg);
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void TCPSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
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 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),
|
||||
TCPSocketSend, TCPSocketSendTest, TCP send demo);
|
||||
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* 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 lwip_udp_socket_demo.c
|
||||
* @brief UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
#define UDP_BUF_SIZE 65536
|
||||
|
||||
char udp_socket_ip[] = {192, 168, 250, 252};
|
||||
u16_t udp_socket_port = LWIP_LOCAL_PORT;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void UdpSocketRecvTask(void *arg)
|
||||
{
|
||||
int fd = -1;
|
||||
char *recv_buf;
|
||||
struct sockaddr_in udp_addr, server_addr;
|
||||
int recv_len;
|
||||
socklen_t addr_len;
|
||||
|
||||
while(1)
|
||||
{
|
||||
recv_buf = (char *)malloc(UDP_BUF_SIZE);
|
||||
if(recv_buf == NULL)
|
||||
{
|
||||
lw_error("No memory\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
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(udp_socket_port);
|
||||
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
|
||||
|
||||
if(bind(fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
|
||||
{
|
||||
lw_error("Unable to bind\n");
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
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(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);
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
free(recv_buf);
|
||||
}
|
||||
}
|
||||
|
||||
void UdpSocketRecvTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
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, 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, UdpSocketRecvTest, UDP Receive DEMO);
|
||||
|
||||
static void UdpSocketSendTask(void *arg)
|
||||
{
|
||||
int cnt = LWIP_DEMO_TIMES;
|
||||
char send_str[128];
|
||||
int fd = -1;
|
||||
|
||||
memset(send_str, 0, sizeof(send_str));
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
lw_error("Socket error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in udp_sock;
|
||||
udp_sock.sin_family = AF_INET;
|
||||
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(fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
|
||||
{
|
||||
lw_error("Unable to connect\n");
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
lw_print("UDP connect success, start to send.\n");
|
||||
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(fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
|
||||
lw_notice("Send UDP msg: %s ", send_str);
|
||||
MdelayKTask(1000);
|
||||
}
|
||||
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
void UdpSocketSendTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc >= 2)
|
||||
{
|
||||
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, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, 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),
|
||||
UDPSocketSend, UdpSocketSendTest, UDP send echo);
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
menu "control app"
|
||||
|
||||
menuconfig APPLICATION_CONTROL
|
||||
bool "Using control apps"
|
||||
default n
|
||||
depends on SUPPORT_CONTROL_FRAMEWORK
|
||||
|
||||
endmenu
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
SRC_DIR :=
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||
|
||||
ifeq ($(CONFIG_USING_CONTROL_PLC_OPCUA), y)
|
||||
SRC_DIR += opcua_demo plc_demo
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES :=opcua_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# OPCUA DEMO README
|
||||
|
||||
## 文件说明
|
||||
|
||||
用于OPCUA 相关测试命令演示,需要开启LWIP和OPCUA协议.
|
||||
|
||||
### 命令行
|
||||
|
||||
UaConnect [IP]
|
||||
|
||||
用于测试与OPCUA服务器连接,连接成功应显示OK
|
||||
|
||||
UaObject [IP]
|
||||
|
||||
用于显示对应的OPCUA设备的节点信息
|
||||
|
||||
|
|
@ -0,0 +1,266 @@
|
|||
/*
|
||||
* Copyright (c) 2021 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 opcua_demo.c
|
||||
* @brief Demo for OpcUa function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.11.11
|
||||
*/
|
||||
|
||||
#include <list.h>
|
||||
#include <transform.h>
|
||||
#include "board.h"
|
||||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#define UA_URL_SIZE 100
|
||||
#define UA_STACK_SIZE 4096
|
||||
#define UA_TASK_PRIO 15
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
// to count test
|
||||
static int test_cnt = 0;
|
||||
static int fail_cnt = 0; // count failure times
|
||||
|
||||
char test_ua_ip[] = {192, 168, 250, 2};
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
static void UaConnectTestTask(void* arg)
|
||||
{
|
||||
struct netif net;
|
||||
UA_StatusCode ret;
|
||||
char url[UA_URL_SIZE];
|
||||
memset(url, 0, sizeof(url));
|
||||
|
||||
UA_Client* client = UA_Client_new();
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] tcp client null\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
|
||||
UA_ClientConfig_setDefault(config);
|
||||
|
||||
snprintf(url, sizeof(url), "opc.tcp://%d.%d.%d.%d:4840",
|
||||
test_ua_ip[0], test_ua_ip[1], test_ua_ip[2], test_ua_ip[3]);
|
||||
|
||||
ua_notice("ua connect cnt %d fail %d\n", test_cnt++, fail_cnt ++);
|
||||
ua_notice("ua connect uri: %.*s\n", strlen(url), url);
|
||||
|
||||
ret = UA_Client_connect(client, url);
|
||||
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_error("ua: [%s] connected failed %x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
fail_cnt++;
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("ua connected ok!\n");
|
||||
UA_Client_delete(client);
|
||||
}
|
||||
|
||||
static void UaConnectTest(int argc, char *argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
if(isdigit(argv[1][0]))
|
||||
{
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||
{
|
||||
lw_notice("input wrong ip\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
sys_thread_new("ua test", UaConnectTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
UaConnect, UaConnectTest, Test Opc UA connection);
|
||||
|
||||
void UaBrowserObjectsTestTask(void* param)
|
||||
{
|
||||
ua_notice("ua: [%s] start %d ...\n", __func__, test_cnt++);
|
||||
|
||||
UA_Client* client = UA_Client_new();
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] tcp client NULL\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("--- start read time ---\n", __func__);
|
||||
UaGetServerTime(client);
|
||||
|
||||
ua_notice("--- get server info ---\n", __func__);
|
||||
UaTestBrowserObjects(client);
|
||||
|
||||
/* Clean up */
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
static void* UaBrowserObjectsTest(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
if(isdigit(argv[1][0]))
|
||||
{
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||
{
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
sys_thread_new("ua object", UaBrowserObjectsTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
UaObject, UaBrowserObjectsTest, UaObject [IP]);
|
||||
|
||||
void UaGetInfoTestTask(void* param)
|
||||
{
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_notice("--- Get OPUCA objects ---\n", __func__);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] tcp client null\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("--- interactive server ---\n", __func__);
|
||||
UaTestInteractServer(client);
|
||||
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
void* UaGetInfoTest(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
if(isdigit(argv[1][0]))
|
||||
{
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||
{
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
sys_thread_new("ua info", UaGetInfoTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
UaInfo, UaGetInfoTest, UaInfo [IP]);
|
||||
|
||||
void UaAddNodesTask(void* param)
|
||||
{
|
||||
UA_Client* client = UA_Client_new();
|
||||
ua_notice("ua: [%s] start ...\n", __func__);
|
||||
|
||||
if(client == NULL)
|
||||
{
|
||||
ua_error("ua: [%s] client null\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
UA_ClientConfig* config = UA_Client_getConfig(client);
|
||||
UA_ClientConfig_setDefault(config);
|
||||
UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
|
||||
|
||||
if(ret != UA_STATUSCODE_GOOD)
|
||||
{
|
||||
ua_print("ua: [%s] connect failed %#x\n", __func__, ret);
|
||||
UA_Client_delete(client);
|
||||
return;
|
||||
}
|
||||
|
||||
ua_notice("--- add nodes ---\n", __func__);
|
||||
UaAddNodes(client);
|
||||
|
||||
UA_Client_delete(client); /* Disconnects the client internally */
|
||||
}
|
||||
|
||||
void* UaAddNodesTest(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2)
|
||||
{
|
||||
if(isdigit(argv[1][0]))
|
||||
{
|
||||
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
|
||||
{
|
||||
lw_notice("input wrong ip\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
sys_thread_new("ua add nodes", UaAddNodesTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
UaAdd, UaAddNodesTest, UA Add Nodes);
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := plc_show_demo.c plc_control_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -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)
|
||||
|
|
@ -0,0 +1,354 @@
|
|||
/*
|
||||
* 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_control_demo.c
|
||||
* @brief Demo for PLC control
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.2.22
|
||||
*/
|
||||
|
||||
#include "transform.h"
|
||||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
#include "sys_arch.h"
|
||||
#include "plc_demo.h"
|
||||
|
||||
#define PLC_NS_FORMAT "n%d,%s"
|
||||
|
||||
struct PlcChannel plc_demo_ch;
|
||||
struct PlcDriver plc_demo_drv;
|
||||
struct PlcDevice plc_demo_dev;
|
||||
|
||||
int plc_test_flag = 0;
|
||||
|
||||
PlcCtrlParamType plc_ctrl_param;
|
||||
|
||||
UA_NodeId test_nodeid = {4, UA_NODEIDTYPE_NUMERIC, 5};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void PlcDelay(int sec)
|
||||
{
|
||||
volatile uint32_t i = 0;
|
||||
for (i = 0; i < 100000000 * sec; ++i)
|
||||
{
|
||||
__asm("NOP"); /* delay */
|
||||
}
|
||||
}
|
||||
|
||||
// get NodeId from str
|
||||
void PlcGetTestNodeId(char *str, UA_NodeId *id)
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
plc_print("plc: arg %s\n", str);
|
||||
|
||||
if(sscanf(str, PLC_NS_FORMAT, &id->namespaceIndex, node_str) != EOF)
|
||||
{
|
||||
if(isdigit(node_str[0]))
|
||||
{
|
||||
id->identifierType = UA_NODEIDTYPE_NUMERIC;
|
||||
id->identifier.numeric = atoi(node_str);
|
||||
plc_print("ns %d num %d\n", id->namespaceIndex, id->identifier.numeric);
|
||||
}
|
||||
else
|
||||
{
|
||||
id->identifierType = UA_NODEIDTYPE_STRING;
|
||||
id->identifier.string.length = strlen(node_str);
|
||||
id->identifier.string.data = node_str;
|
||||
plc_print("ns %d str %s\n", id->namespaceIndex, id->identifier.string.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlcDemoChannelDrvInit(void)
|
||||
{
|
||||
static uint8_t init_flag = 0;
|
||||
if(init_flag)
|
||||
return;
|
||||
init_flag = 1;
|
||||
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
|
||||
PlcChannelInit(&plc_demo_ch, PLC_CH_NAME);
|
||||
if(PlcDriverInit(&plc_demo_drv, PLC_DRV_NAME) == EOK)
|
||||
{
|
||||
PlcDriverAttachToChannel(PLC_DRV_NAME, PLC_CH_NAME);
|
||||
}
|
||||
memset(&plc_demo_dev, 0, sizeof(plc_demo_dev));
|
||||
}
|
||||
|
||||
static void PlcGetDemoDev(PlcDeviceType *dev, UA_NodeId *id)
|
||||
{
|
||||
// register plc device
|
||||
dev->state = CHDEV_INIT;
|
||||
strcpy(dev->name, "UA Demo");
|
||||
dev->info.product = "CPU 1215C";
|
||||
dev->info.vendor = "SIEMENS";
|
||||
dev->info.model = "S7-1200";
|
||||
dev->info.id = 123;
|
||||
dev->net = PLC_IND_ENET_OPCUA;
|
||||
|
||||
// register UA parameter
|
||||
if(!dev->priv_data)
|
||||
{
|
||||
dev->priv_data = (UaParamType*)malloc(sizeof(UaParamType));
|
||||
}
|
||||
UaParamType* ua_ptr = dev->priv_data;
|
||||
memset(ua_ptr, 0, sizeof(UaParamType));
|
||||
strcpy(ua_ptr->ua_remote_ip, opc_server_url);
|
||||
ua_ptr->act = UA_ACT_ATTR;
|
||||
memcpy(&ua_ptr->ua_id, id, sizeof(*id));
|
||||
}
|
||||
|
||||
static void PlcCtrlDemoInit(void)
|
||||
{
|
||||
static uint8_t init_flag = 0;
|
||||
|
||||
PlcDemoChannelDrvInit();
|
||||
|
||||
// register plc device
|
||||
PlcGetDemoDev(&plc_demo_dev, &test_nodeid);
|
||||
|
||||
if(init_flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
init_flag = 1;
|
||||
|
||||
if(PlcDevRegister(&plc_demo_dev, NULL, plc_demo_dev.name) != EOK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlcDeviceAttachToChannel(plc_demo_dev.name, PLC_CH_NAME);
|
||||
}
|
||||
|
||||
void PlcReadUATask(void* arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct PlcOps* ops = NULL;
|
||||
char buf[PLC_BUF_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
PlcCtrlDemoInit();
|
||||
ops = plc_demo_dev.ops;
|
||||
ret = ops->open(&plc_demo_dev);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ops->read(&plc_demo_dev, buf, PLC_BUF_SIZE);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] read failed %x\n", __func__, ret);
|
||||
}
|
||||
|
||||
ops->close(&plc_demo_dev);
|
||||
}
|
||||
|
||||
void PlcReadTestShell(int argc, char* argv[])
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
PlcGetTestNodeId(argv[1], &test_nodeid);
|
||||
}
|
||||
|
||||
sys_thread_new("plc read", PlcReadUATask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcRead, PlcReadTestShell, Read PLC);
|
||||
|
||||
void PlcWriteUATask(void* arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct PlcOps* ops = NULL;
|
||||
char buf[PLC_BUF_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
PlcCtrlDemoInit();
|
||||
ops = plc_demo_dev.ops;
|
||||
ret = ops->open(&plc_demo_dev);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = ops->write(&plc_demo_dev, arg, PLC_BUF_SIZE);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] write failed\n", __func__);
|
||||
}
|
||||
|
||||
ops->close(&plc_demo_dev);
|
||||
}
|
||||
|
||||
void PlcWriteTestShell(int argc, char* argv[])
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
static char val_param[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
memset(val_param, 0, sizeof(val_param));
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
PlcGetTestNodeId(argv[1], &test_nodeid);
|
||||
}
|
||||
|
||||
if(argc > 2)
|
||||
{
|
||||
strcpy(val_param, argv[2]);
|
||||
plc_print("write value %s\n", val_param);
|
||||
}
|
||||
|
||||
sys_thread_new("plc write", PlcWriteUATask, val_param, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcWrite, PlcWriteTestShell, Read PLC);
|
||||
|
||||
// test motor
|
||||
// clear parameter
|
||||
// PlcWrite n4,2 0b
|
||||
// PlcWrite n4,3 0b
|
||||
// PlcWrite n4,4 0b
|
||||
// PlcWrite n4,5 0b
|
||||
//
|
||||
// enable
|
||||
// PlcWrite n4,2 1b
|
||||
//
|
||||
// set rotate speed
|
||||
// PlcWrite n4,3 50
|
||||
//
|
||||
// positive turn
|
||||
// PlcWrite n4,4 1b
|
||||
//
|
||||
// reversal turn
|
||||
// PlcWrite n4,5 1b
|
||||
|
||||
static int plc_test_speed = 50;
|
||||
static int plc_test_dir = 1; // direction positive: 1 reversal: 0
|
||||
|
||||
void PlcMotorTestTask(void* arg)
|
||||
{
|
||||
//support node id
|
||||
char *test_nodeid[] = {"n4,2", "n4,3", "n4,4", "n4,5", "n4,7"};
|
||||
// enable -> speed -> positive dir or inversal dir -> stop -> enable
|
||||
char test_sort[] = {0, 4, 2, 1, 0};
|
||||
char test_cmd[][4] = {"1b", "50", "1b", "1b", "0b"};
|
||||
char *test_notice[] = {"Enable Motor", "Set Speed", "Set Forward", "Set Reverse", "Stop Motor"};
|
||||
|
||||
int ret = 0;
|
||||
struct PlcOps* ops = NULL;
|
||||
char buf[PLC_BUF_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
PlcCtrlDemoInit();
|
||||
ops = plc_demo_dev.ops;
|
||||
ret = ops->open(&plc_demo_dev);
|
||||
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] open failed %#x\n", __func__, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
UaParamType* ua_ptr = plc_demo_dev.priv_data;
|
||||
|
||||
// initialize step
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
plc_print("###\n### Clear %s\n###\n", test_notice[i]);
|
||||
PlcGetTestNodeId(test_nodeid[i], &ua_ptr->ua_id);
|
||||
ret = ops->write(&plc_demo_dev, "0b", PLC_BUF_SIZE);
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
|
||||
}
|
||||
PlcDelay(1);
|
||||
}
|
||||
|
||||
if(plc_test_speed != 50)
|
||||
{
|
||||
snprintf(test_cmd[1], 4, "%d", plc_test_speed);
|
||||
}
|
||||
|
||||
if(plc_test_dir == 0) // if not postive, next running
|
||||
test_sort[2] = 3;
|
||||
|
||||
for(int i = 0; i < sizeof(test_sort)/sizeof(test_sort[0]); i++)
|
||||
{
|
||||
PlcGetTestNodeId(test_nodeid[test_sort[i]], &ua_ptr->ua_id);
|
||||
plc_print("###\n### %s\n###\n", test_notice[i]);
|
||||
ret = ops->write(&plc_demo_dev, test_cmd[i], PLC_BUF_SIZE);
|
||||
if(EOK != ret)
|
||||
{
|
||||
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
|
||||
}
|
||||
PlcDelay(1);
|
||||
if(i == 2) // postive
|
||||
{
|
||||
PlcDelay(10);
|
||||
}
|
||||
}
|
||||
ops->close(&plc_demo_dev);
|
||||
plc_test_flag = 0;
|
||||
}
|
||||
|
||||
// get parameter from
|
||||
void PlcGetMotorParam(char *str)
|
||||
{
|
||||
static char node_str[UA_NODE_LEN];
|
||||
memset(node_str, 0, sizeof(node_str));
|
||||
|
||||
plc_print("plc: arg %s\n", str);
|
||||
|
||||
sscanf(str, "speed=%d", &plc_test_speed);
|
||||
sscanf(str, "dir=%d", &plc_test_dir);
|
||||
plc_print("speed is %d\n", plc_test_speed);
|
||||
plc_print("dir is %d\n", plc_test_dir);
|
||||
}
|
||||
|
||||
void PlcMotorTestShell(int argc, char* argv[])
|
||||
{
|
||||
if(plc_test_flag)
|
||||
{
|
||||
plc_print("PLC Motor testing!\n");
|
||||
return;
|
||||
}
|
||||
plc_test_flag = 1;
|
||||
|
||||
if(argc > 1)
|
||||
{
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
PlcGetMotorParam(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
sys_thread_new("plc motor", PlcMotorTestTask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
PlcMotorTest, PlcMotorTestShell, Run motor);
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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_show_demo.c
|
||||
* @brief Demo for PLC information show
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.02.24
|
||||
*/
|
||||
|
||||
#ifndef __PLC_DEMO_H_
|
||||
#define __PLC_DEMO_H_
|
||||
|
||||
#include "plc_channel.h"
|
||||
#include "plc_device.h"
|
||||
|
||||
#define PLC_CH_NAME "PLC"
|
||||
#define PLC_DRV_NAME "OPCUA"
|
||||
|
||||
#define PLC_BUF_SIZE 128
|
||||
|
||||
#define PLC_STACK_SIZE 4096
|
||||
#define PLC_TASK_PRIO 15
|
||||
|
||||
extern struct PlcChannel plc_demo_ch;
|
||||
extern struct PlcDriver plc_demo_drv;
|
||||
extern struct PlcDevice plc_demo_dev;
|
||||
|
||||
void PlcDemoChannelDrvInit(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* 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_show_demo.c
|
||||
* @brief Demo for PLC information show
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.02.24
|
||||
*/
|
||||
|
||||
#include "transform.h"
|
||||
#include "list.h"
|
||||
|
||||
#include "open62541.h"
|
||||
#include "ua_api.h"
|
||||
#include "sys_arch.h"
|
||||
#include "plc_demo.h"
|
||||
|
||||
|
||||
#define PLC_DEMO_NUM 5
|
||||
|
||||
struct PlcDevice plc_demo_array[PLC_DEMO_NUM];
|
||||
|
||||
typedef struct PlcShowParam
|
||||
{
|
||||
int id;
|
||||
char* vector;
|
||||
char* model;
|
||||
char* product;
|
||||
} PlcShowParamType;
|
||||
|
||||
PlcShowParamType plc_demo_param[PLC_NAME_SIZE] =
|
||||
{
|
||||
{1, "SIEMENS", "S7-1500", "CPU 1512SP-1PN"},
|
||||
{2, "SIEMENS", "S7-1200", "CPU 1215C"},
|
||||
{3, "SIEMSNS", "S7-200", "CPU SR60"},
|
||||
{4, "B&R", "X20", "X20 CP1586"},
|
||||
{5, "B&R", "X20", "X20 CP1381"}
|
||||
};
|
||||
|
||||
static char* const channel_type_str[] =
|
||||
{
|
||||
"PLC_Channel",
|
||||
"Unknown"
|
||||
};
|
||||
|
||||
extern DoublelistType plcdev_list;
|
||||
extern DoublelistType ch_linklist;
|
||||
|
||||
/**********************************************************************************************************************/
|
||||
|
||||
void PlcShowTitle(const char* item_array[])
|
||||
{
|
||||
int i = 0, max_len = 65;
|
||||
KPrintf(" %-15s%-15s%-15s%-15s%-20s\n", item_array[0], item_array[1], item_array[2], item_array[3], item_array[4]);
|
||||
|
||||
while(i < max_len)
|
||||
{
|
||||
i++;
|
||||
|
||||
if(max_len == i)
|
||||
{
|
||||
KPrintf("-\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ChDrvType ShowChannelFindDriver(struct Channel* ch)
|
||||
{
|
||||
struct ChDrv* driver = NONE;
|
||||
DoublelistType* node = NONE;
|
||||
DoublelistType* head = &ch->ch_drvlink;
|
||||
|
||||
for(node = head->node_next; node != head; node = node->node_next)
|
||||
{
|
||||
driver = DOUBLE_LIST_ENTRY(node, struct ChDrv, driver_link);
|
||||
return driver;
|
||||
}
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
static void PlcShowDemoInit(void)
|
||||
{
|
||||
static uint8_t init_flag = 0;
|
||||
int i;
|
||||
PlcDemoChannelDrvInit();
|
||||
|
||||
for(i = 0; i < PLC_DEMO_NUM; i++)
|
||||
{
|
||||
// register plc device
|
||||
plc_demo_array[i].state = CHDEV_INIT;
|
||||
snprintf(plc_demo_array[i].name, PLC_NAME_SIZE, "PLC Demo %d", i);
|
||||
plc_demo_array[i].info.vendor = plc_demo_param[i].vector;
|
||||
plc_demo_array[i].info.model = plc_demo_param[i].model;
|
||||
plc_demo_array[i].info.id = plc_demo_param[i].id;
|
||||
plc_demo_array[i].info.product = plc_demo_param[i].product;
|
||||
plc_demo_array[i].net = PLC_IND_ENET_OPCUA;
|
||||
}
|
||||
|
||||
if(init_flag)
|
||||
return;
|
||||
init_flag = 1;
|
||||
|
||||
for(i = 0; i < PLC_DEMO_NUM; i++)
|
||||
{
|
||||
if(PlcDevRegister(&plc_demo_array[i], NULL, plc_demo_array[i].name) == EOK)
|
||||
{
|
||||
PlcDeviceAttachToChannel(plc_demo_array[i].name, PLC_CH_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlcShowChannel(void)
|
||||
{
|
||||
ChannelType ch;
|
||||
ChDrvType driver;
|
||||
ChDevType device;
|
||||
int dev_cnt;
|
||||
DoublelistType* ch_node = NONE;
|
||||
DoublelistType* ch_head = &ch_linklist;
|
||||
const char* item_array[] = {"ch_type", "ch_name", "drv_name", "dev_name", "cnt"};
|
||||
PlcShowDemoInit();
|
||||
PlcShowTitle(item_array);
|
||||
ch_node = ch_head->node_next;
|
||||
|
||||
do
|
||||
{
|
||||
ch = DOUBLE_LIST_ENTRY(ch_node, struct Channel, ch_link);
|
||||
|
||||
if((ch) && (ch->ch_type == CH_PLC_TYPE))
|
||||
{
|
||||
KPrintf("%s", " ");
|
||||
KPrintf("%-15s%-15s",
|
||||
channel_type_str[ch->ch_type],
|
||||
ch->ch_name);
|
||||
|
||||
driver = ShowChannelFindDriver(ch);
|
||||
|
||||
if(driver)
|
||||
{
|
||||
KPrintf("%-15s", driver->drv_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("%-15s", "nil");
|
||||
}
|
||||
|
||||
if(ch->haldev_cnt)
|
||||
{
|
||||
DoublelistType* dev_node = NONE;
|
||||
DoublelistType* dev_head = &ch->ch_devlink;
|
||||
dev_node = dev_head->node_next;
|
||||
dev_cnt = 1;
|
||||
|
||||
while(dev_node != dev_head)
|
||||
{
|
||||
device = DOUBLE_LIST_ENTRY(dev_node, struct ChDev, dev_link);
|
||||
|
||||
if(1 == dev_cnt)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("%46s", " ");
|
||||
|
||||
if(device)
|
||||
{
|
||||
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
dev_cnt++;
|
||||
dev_node = dev_node->node_next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrintf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
ch_node = ch_node->node_next;
|
||||
}
|
||||
while(ch_node != ch_head);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
ShowChannel, PlcShowChannel, Show PLC information);
|
||||
|
||||
void PlcShowDev(void)
|
||||
{
|
||||
PlcDeviceType* plc_dev;
|
||||
ChDrvType driver;
|
||||
ChDevType device;
|
||||
DoublelistType* plc_node = NONE;
|
||||
DoublelistType* plc_head = &plcdev_list;
|
||||
const char* item_array[] = {"device", "vendor", "model", "product", "id"};
|
||||
PlcShowDemoInit();
|
||||
PlcShowTitle(item_array);
|
||||
plc_node = plc_head->node_next;
|
||||
|
||||
do
|
||||
{
|
||||
plc_dev = DOUBLE_LIST_ENTRY(plc_node, struct PlcDevice, link);
|
||||
|
||||
if(plc_dev)
|
||||
{
|
||||
KPrintf("%s", " ");
|
||||
KPrintf("%-15s%-15s%-15s%-15s%-20d",
|
||||
plc_dev->name,
|
||||
plc_dev->info.vendor,
|
||||
plc_dev->info.model,
|
||||
plc_dev->info.product,
|
||||
plc_dev->info.id);
|
||||
KPrintf("\n");
|
||||
}
|
||||
|
||||
plc_node = plc_node->node_next;
|
||||
}
|
||||
while(plc_node != plc_head);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
ShowPlc, PlcShowDev, Show PLC information);
|
||||
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <xizi.h>
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
extern "C" void KPrintf(const char *fmt, ...);
|
||||
|
||||
class Animal //parent class
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual void Eat()
|
||||
{
|
||||
|
||||
KPrintf("eat\n");
|
||||
|
||||
}
|
||||
|
||||
void Sleep()
|
||||
{
|
||||
KPrintf("sleep\n");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class Fish :public Animal //subclass
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
void Eat()
|
||||
{
|
||||
KPrintf("fish eat\n");
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void Doeat(Animal& animal)
|
||||
{
|
||||
animal.Eat();
|
||||
}
|
||||
|
||||
void MemTest2()
|
||||
{
|
||||
int i;
|
||||
char *ptr = NULL; /* memory pointer */
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
/* allocate (1<<i) bytes memory every single time */
|
||||
ptr = (char *)operator new(1 << i);
|
||||
|
||||
/* if allocate successfully */
|
||||
if (ptr != NULL) {
|
||||
KPrintf("get memory :%d byte\n", (1 << i));
|
||||
/* release the memory */
|
||||
operator delete(ptr);
|
||||
KPrintf("free memory :%d byte\n", (1 << i));
|
||||
ptr = NULL;
|
||||
} else {
|
||||
KPrintf("try to get %d byte memory failed!\n", (1 << i));
|
||||
break;
|
||||
//return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OverLoadTest(int a)
|
||||
{
|
||||
KPrintf("output is a int number: %d\n", a);
|
||||
}
|
||||
|
||||
void OverLoadTestDouble(int a,int b )
|
||||
{
|
||||
KPrintf("output is 2 int number: %d and %d\n", a,b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MySwap(T& a, T& b)
|
||||
{
|
||||
T temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
extern "C" int cppmain(void)
|
||||
{
|
||||
MemTest2();
|
||||
|
||||
class Fish fish;
|
||||
Doeat(fish);
|
||||
|
||||
int a = 3;
|
||||
int b = 5;
|
||||
void OverLoadTestDouble(int a, int b);
|
||||
OverLoadTestDouble(a, b);
|
||||
MySwap(a,b);
|
||||
KPrintf("with template the output is: %d and %d\n", a,b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
menuconfig USING_EMBEDDED_DATABASE_APP
|
||||
bool "embedded database app"
|
||||
default n
|
||||
if USING_EMBEDDED_DATABASE_APP
|
||||
source "$APP_DIR/Applications/embedded_database_app/flashdb_app/Kconfig"
|
||||
endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
extern int SensorFrameworkInit(void);
|
||||
extern int AdapterFrameworkInit(void);
|
||||
|
||||
extern int Adapter4GInit(void);
|
||||
extern int AdapterNbiotInit(void);
|
||||
extern int AdapterBlueToothInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
extern int AdapterEthernetInit(void);
|
||||
extern int AdapterEthercatInit(void);
|
||||
extern int AdapterZigbeeInit(void);
|
||||
extern int AdapterLoraInit(void);
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
extern int Hs300xHumidityInit(void);
|
||||
extern int Ps5308Pm1_0Init(void);
|
||||
extern int Ps5308Pm2_5Init(void);
|
||||
extern int Ps5308Pm10Init(void);
|
||||
extern int Zg09Co2Init(void);
|
||||
extern int As830Ch4Init(void);
|
||||
extern int Tb600bIaq10IaqInit(void);
|
||||
extern int Tb600bTvoc10TvocInit(void);
|
||||
extern int Tb600bWqHcho1osInit(void);
|
||||
extern int QsFxWindDirectionInit(void);
|
||||
extern int QsFsWindSpeedInit(void);
|
||||
|
||||
extern int lv_port_init(void);
|
||||
|
||||
typedef int (*InitFunc)(void);
|
||||
struct InitDesc
|
||||
{
|
||||
const char* fn_name;
|
||||
const InitFunc fn;
|
||||
};
|
||||
|
||||
static int AppInitDesc(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
ret = sub_desc[i].fn();
|
||||
printf("initialize %s %s\n",sub_desc[i].fn_name, ret == 0 ? "success" : "failed");
|
||||
if(0 != ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct InitDesc framework[] =
|
||||
{
|
||||
#ifdef SUPPORT_SENSOR_FRAMEWORK
|
||||
{ "sensor_framework", SensorFrameworkInit },
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
{ "connection_framework", AdapterFrameworkInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc sensor_desc[] =
|
||||
{
|
||||
#ifdef SENSOR_DEVICE_D124
|
||||
{ "d124_voice", D124VoiceInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_DEVICE_HS300X
|
||||
#ifdef SENSOR_QUANTITY_HS300X_TEMPERATURE
|
||||
{ "hs300x_temperature", Hs300xTemperatureInit },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_HS300X_HUMIDITY
|
||||
{ "hs300x_humidity", Hs300xHumidityInit },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_PS5308
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM1_0
|
||||
{ "ps5308_pm1_0", Ps5308Pm1_0Init },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM2_5
|
||||
{ "ps5308_pm2_5", Ps5308Pm2_5Init },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM10
|
||||
{ "ps5308_pm10", Ps5308Pm10Init },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_ZG09
|
||||
{ "zg09_co2", Zg09Co2Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FX
|
||||
{ "qs_fx_wind_direction", QsFxWindDirectionInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FS
|
||||
{ "qs_fs_wind_speed", QsFsWindSpeedInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_AS830
|
||||
{ "ch4_as830", As830Ch4Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_IAQ10
|
||||
{ "iaq_tb600b_iaq10", Tb600bIaq10IaqInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_TVOC10
|
||||
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_WQ_HCHO1OS
|
||||
{ "tvoc_tb600b_wq_hcho1os", Tb600bWqHcho1osInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
{ "4G adapter", Adapter4GInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_NB
|
||||
{ "NB adpter", AdapterNbiotInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
||||
{ "zigbee adapter", AdapterZigbeeInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_BLUETOOTH
|
||||
{ "bluetooth adapter", AdapterBlueToothInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_WIFI
|
||||
{ "wifi adapter", AdapterWifiInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERNET
|
||||
{ "ethernet adapter", AdapterEthernetInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERCAT
|
||||
{ "ethercat adapter", AdapterEthercatInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_LORA
|
||||
{ "lora adapter", AdapterLoraInit},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will init sensor framework and all sub sensors
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int SensorDeviceFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "sensor_framework", strlen("sensor_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize sensor_framework success.\n");
|
||||
AppInitDesc(sensor_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init connection framework and all sub components
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int ConnectionDeviceFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "connection_framework", strlen("connection_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize connection_framework success.\n");
|
||||
AppInitDesc(connection_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init system framework
|
||||
*
|
||||
*/
|
||||
int FrameworkInit(void)
|
||||
{
|
||||
#ifdef SUPPORT_SENSOR_FRAMEWORK
|
||||
SensorDeviceFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
ConnectionDeviceFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef LIB_LV
|
||||
lv_port_init();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_DIR := list
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += double_list.c single_list.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := double_list.c single_list.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import os
|
||||
from building import *
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
cwd = GetCurrentDir()
|
||||
DEPENDS = [""]
|
||||
|
||||
SOURCES = ['double_list.c'] + ['single_list.c']
|
||||
path = [cwd]
|
||||
objs = DefineGroup('list', src = SOURCES, depend = DEPENDS,CPPPATH = path)
|
||||
Return("objs")
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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: double_link.c
|
||||
* @brief: functions definition of double list for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/3/15
|
||||
*
|
||||
*/
|
||||
|
||||
#include "list.h"
|
||||
|
||||
void AppInitDoubleList(DoublelistType *list_head)
|
||||
{
|
||||
list_head->node_next = list_head;
|
||||
list_head->node_prev = list_head;
|
||||
}
|
||||
|
||||
void AppDoubleListInsertNodeAfter(DoublelistType *list, DoublelistType *list_node)
|
||||
{
|
||||
list->node_next->node_prev = list_node;
|
||||
list_node->node_next = list->node_next;
|
||||
|
||||
list->node_next = list_node;
|
||||
list_node->node_prev = list;
|
||||
}
|
||||
|
||||
void AppDoubleListInsertNodeBefore(DoublelistType *list, DoublelistType *list_node)
|
||||
{
|
||||
list->node_prev->node_next = list_node;
|
||||
list_node->node_prev = list->node_prev;
|
||||
|
||||
list->node_prev = list_node;
|
||||
list_node->node_next = list;
|
||||
}
|
||||
|
||||
void AppDoubleListRmNode(DoublelistType *list_node)
|
||||
{
|
||||
list_node->node_next->node_prev = list_node->node_prev;
|
||||
list_node->node_prev->node_next = list_node->node_next;
|
||||
|
||||
list_node->node_next = list_node;
|
||||
list_node->node_prev = list_node;
|
||||
}
|
||||
|
||||
int AppIsDoubleListEmpty(const DoublelistType *list)
|
||||
{
|
||||
return list->node_next == list;
|
||||
}
|
||||
|
||||
struct DoublelistNode *AppDoubleListGetHead(const DoublelistType *list)
|
||||
{
|
||||
return AppIsDoubleListEmpty(list) ? NULL : list->node_next;
|
||||
}
|
||||
|
||||
struct DoublelistNode *AppDoubleListGetNext(const DoublelistType *list,
|
||||
const struct DoublelistNode *list_node)
|
||||
{
|
||||
return list_node->node_next == list ? NULL : list_node->node_next;
|
||||
}
|
||||
|
||||
unsigned int AppDoubleListLenGet(const DoublelistType *list)
|
||||
{
|
||||
unsigned int linklist_length = 0;
|
||||
const DoublelistType *tmp_node = list;
|
||||
while (tmp_node->node_next != list)
|
||||
{
|
||||
tmp_node = tmp_node->node_next;
|
||||
linklist_length ++;
|
||||
}
|
||||
|
||||
return linklist_length;
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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: list.h
|
||||
* @brief: function declaration and structure defintion of list
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/6/23
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LIST_H__
|
||||
#define __LIST_H__
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include<stddef.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct DoublelistNode
|
||||
{
|
||||
struct DoublelistNode *node_next;
|
||||
struct DoublelistNode *node_prev;
|
||||
} DoublelistType;
|
||||
|
||||
// Single List
|
||||
typedef struct SinglelistNode
|
||||
{
|
||||
struct SinglelistNode *node_next;
|
||||
} SinglelistType;
|
||||
|
||||
|
||||
#define CONTAINER_OF(item, type, member) \
|
||||
((type *)((char *)(item) - (unsigned long)(&((type *)0)->member)))
|
||||
|
||||
|
||||
#define DOUBLE_LIST_OBJ_INIT(obj) { &(obj), &(obj) }
|
||||
|
||||
void AppInitDoubleList(DoublelistType *linklist_head);
|
||||
void AppDoubleListInsertNodeAfter(DoublelistType *list, DoublelistType *list_node);
|
||||
void AppDoubleListInsertNodeBefore(DoublelistType *list, DoublelistType *list_node);
|
||||
void AppDoubleListRmNode(DoublelistType *list_node);
|
||||
int AppIsDoubleListEmpty(const DoublelistType *list);
|
||||
struct DoublelistNode *AppDoubleLinkListGetHead(const DoublelistType *list);
|
||||
struct DoublelistNode *AppDoubleLinkListGetNext(const DoublelistType *list,
|
||||
const struct DoublelistNode *list_node);
|
||||
unsigned int AppDoubleListLenGet(const DoublelistType *list);
|
||||
|
||||
#define DOUBLE_LIST_ENTRY(item, type, member) \
|
||||
CONTAINER_OF(item, type, member)
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH(item, head) \
|
||||
for (item = (head)->node_next; item != (head); item = item->node_next)
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH_SAFE(item, node_next, head) \
|
||||
for (item = (head)->node_next, node_next = item->node_next; item != (head); \
|
||||
item = node_next, node_next = item->node_next)
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH_ENTRY(item, head, member) \
|
||||
for (item = DOUBLE_LIST_ENTRY((head)->node_next, typeof(*item), member); \
|
||||
&item->member != (head); \
|
||||
item = DOUBLE_LIST_ENTRY(item->member.node_next, typeof(*item), member))
|
||||
|
||||
#define DOUBLE_LIST_FOR_EACH_ENTRY_SAFE(item, node_next, head, member) \
|
||||
for (item = DOUBLE_LIST_ENTRY((head)->node_next, typeof(*item), member), \
|
||||
node_next = DOUBLE_LIST_ENTRY(item->member.node_next, typeof(*item), member); \
|
||||
&item->member != (head); \
|
||||
item = node_next, node_next = DOUBLE_LIST_ENTRY(node_next->member.node_next, typeof(*node_next), member))
|
||||
|
||||
#define DOUBLE_LIST_FIRST_ENTRY(ptr, type, member) \
|
||||
DOUBLE_LIST_ENTRY((ptr)->node_next, type, member)
|
||||
|
||||
#define SINGLE_LIST_OBJ_INIT(obj) { NONE }
|
||||
|
||||
void AppInitSingleList(SinglelistType *list);
|
||||
void AppAppendSingleList(SinglelistType *list, SinglelistType *list_node);
|
||||
void AppSingleListNodeInsert(SinglelistType *list, SinglelistType *list_node);
|
||||
unsigned int AppSingleListGetLen(const SinglelistType *list);
|
||||
SinglelistType *AppSingleListRmNode(SinglelistType *list, SinglelistType *list_node);
|
||||
SinglelistType *AppSingleListGetFirstNode(SinglelistType *list);
|
||||
SinglelistType *AppSingleListGetTailNode(SinglelistType *list);
|
||||
SinglelistType *AppSingleListGetNextNode(SinglelistType *list_node);
|
||||
int AppIsSingleListEmpty(SinglelistType *list);
|
||||
|
||||
#define SINGLE_LIST_ENTRY(node, type, member) \
|
||||
CONTAINER_OF(node, type, member)
|
||||
|
||||
#define SINGLE_LIST_FOR_EACH(item, head) \
|
||||
for (item = (head)->node_next; item != NONE; item = item->node_next)
|
||||
|
||||
#define SINGLE_LIST_FOR_EACH_ENTRY(item, head, member) \
|
||||
for (item = SINGLE_LIST_ENTRY((head)->node_next, typeof(*item), member); \
|
||||
&item->member != (NONE); \
|
||||
item = SINGLE_LIST_ENTRY(item->member.node_next, typeof(*item), member))
|
||||
|
||||
#define SINGLE_LIST_FIRST_ENTRY(ptr, type, member) \
|
||||
SINGLE_LIST_ENTRY((ptr)->node_next, type, member)
|
||||
|
||||
#define SINGLE_LIST_TAIL_ENTRY(ptr, type, member) \
|
||||
SINGLE_LIST_ENTRY(AppSingleListGetTailNode(ptr), type, member)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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: double_link.c
|
||||
* @brief: functions definition of single list for application
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2020/3/15
|
||||
*
|
||||
*/
|
||||
|
||||
#include "list.h"
|
||||
|
||||
void AppInitSingleList(SinglelistType *list)
|
||||
{
|
||||
list->node_next = NULL;
|
||||
}
|
||||
|
||||
void AppAppendSingleList(SinglelistType *list, SinglelistType *list_node)
|
||||
{
|
||||
struct SinglelistNode *node;
|
||||
|
||||
node = list;
|
||||
while (node->node_next) node = node->node_next;
|
||||
|
||||
node->node_next = list_node;
|
||||
list_node->node_next = NULL;
|
||||
}
|
||||
|
||||
void AppSingleListNodeInsert(SinglelistType *list, SinglelistType *list_node)
|
||||
{
|
||||
list_node->node_next = list->node_next;
|
||||
list->node_next = list_node;
|
||||
}
|
||||
|
||||
unsigned int AppSingleListGetLen(const SinglelistType *list)
|
||||
{
|
||||
unsigned int length = 0;
|
||||
const SinglelistType *tmp_list = list->node_next;
|
||||
while (tmp_list != NULL)
|
||||
{
|
||||
tmp_list = tmp_list->node_next;
|
||||
length ++;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
SinglelistType *AppSingleListRmNode(SinglelistType *list, SinglelistType *list_node)
|
||||
{
|
||||
struct SinglelistNode *node = list;
|
||||
while (node->node_next && node->node_next != list_node) node = node->node_next;
|
||||
|
||||
if (node->node_next != (SinglelistType *)0){
|
||||
node->node_next = node->node_next->node_next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
SinglelistType *AppSingleListGetFirstNode(SinglelistType *list)
|
||||
{
|
||||
return list->node_next;
|
||||
}
|
||||
|
||||
SinglelistType *AppSingleListGetTailNode(SinglelistType *list)
|
||||
{
|
||||
while (list->node_next) list = list->node_next;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
SinglelistType *AppSingleListGetNextNode(SinglelistType *list_node)
|
||||
{
|
||||
return list_node->node_next;
|
||||
}
|
||||
|
||||
int AppIsSingleListEmpty(SinglelistType *list)
|
||||
{
|
||||
return list->node_next == NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
menu "knowing app"
|
||||
menuconfig APPLICATION_KNOWING
|
||||
bool "Using knowing apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_KNOWING
|
||||
source "$APP_DIR/Applications/knowing_app/mnist/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_detect_entry/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/iris_ml_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_fft_test/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/image_processing/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/cmsis_5_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/nnom_demo/Kconfig"
|
||||
|
||||
endif
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# Applications/knowing_app/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_APPLICATION_KNOWING),)
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Applications/knowing_app/*/Make.defs)
|
||||
endif
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_DIR := mnist
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
// #include <user_api.h>
|
||||
#include <transform.h>
|
||||
|
||||
extern int FrameworkInit();
|
||||
extern void ApplicationOtaTaskInit(void);
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello, world! \n");
|
||||
FrameworkInit();
|
||||
#ifdef APPLICATION_OTA
|
||||
ApplicationOtaTaskInit();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
// int cppmain(void);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
menu "ota app "
|
||||
menuconfig APPLICATION_OTA
|
||||
bool "Using app bin ota"
|
||||
default n
|
||||
|
||||
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := ota.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# OTA README
|
||||
|
||||
xiuos当前的ota功能允许应用bin文件可以通过4G实现远程的bin文件更新(限制:1、bin文件存放在设备SD卡并且应用从SD卡启动;2、暂且支持4G实现;3、暂时只支持aiit终端;4、只支持xiuos内核)。
|
||||
|
||||
## 文件说明
|
||||
|
||||
| 名称 | 说明 |
|
||||
| -- | -- |
|
||||
| ota.c| xiuos设备OTA代码 |
|
||||
| ota_server.c | pc服务端的实例代码供参考 |
|
||||
|
||||
|
||||
## 使用说明
|
||||
xiuos的应用bin文件更新依赖上层的adapter框架,因此需要在menuconfig同时配置以下选项:
|
||||
1、ota开关APPLICATION_OTA打开;
|
||||
2、adapter的4G功能开关;
|
||||
3、拆分的应用启动SEPARATE_COMPILE开关从SD卡启动的配置开关APP_STARTUP_FROM_SDCARD。
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,411 @@
|
|||
|
||||
/*
|
||||
* 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: ota.c
|
||||
* @brief: a application ota task of system
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/11/3
|
||||
*
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <adapter.h>
|
||||
|
||||
extern int main(void);
|
||||
|
||||
struct ota_header_t
|
||||
{
|
||||
int16 frame_flag; ///< frame start flag 2 Bytes
|
||||
uint8 dev_type; ///< device type
|
||||
uint8 burn_mode; ///< data burn way
|
||||
uint32 total_len; ///< send data total length caculated from each frame_len
|
||||
uint32 dev_hid; ///< device hardware version
|
||||
uint32 dev_sid; ///< device software version
|
||||
char resv[8]; ///< reserve
|
||||
};
|
||||
|
||||
struct ota_frame_t
|
||||
{
|
||||
uint32 frame_id; ///< Current frame id
|
||||
uint32 frame_len; ///< Current frame data length
|
||||
char frame_data[64]; ///< Current frame data,max length 64
|
||||
uint32 crc; ///< Current frame data crc
|
||||
};
|
||||
|
||||
struct ota_data
|
||||
{
|
||||
struct ota_header_t header;
|
||||
struct ota_frame_t frame;
|
||||
char end[4];
|
||||
};
|
||||
|
||||
pthread_t ota_task;
|
||||
pthread_t restart_main;
|
||||
|
||||
/**
|
||||
* @description: CRC16 check
|
||||
* @param data data buffer
|
||||
* @param length data length
|
||||
* @return check code
|
||||
*/
|
||||
uint32_t OtaCrc16(uint8_t * data, uint32_t length)
|
||||
{
|
||||
int j;
|
||||
unsigned int reg_crc=0xFFFF;
|
||||
printf("crc data length[%d] Bytes,",length);
|
||||
|
||||
while (length--) {
|
||||
reg_crc ^= *data++;
|
||||
for (j=0;j<8;j++) {
|
||||
if(reg_crc & 0x01)
|
||||
reg_crc=reg_crc >>1 ^ 0xA001;
|
||||
else
|
||||
reg_crc=reg_crc >>1;
|
||||
}
|
||||
}
|
||||
printf(" crc = [0x%x]\n",reg_crc);
|
||||
return reg_crc;
|
||||
}
|
||||
|
||||
uint32_t FileCrc16(uint8_t * data, uint32_t length, unsigned int last_crc)
|
||||
{
|
||||
int j;
|
||||
//printf("crc data length[%d] Bytes,",length);
|
||||
|
||||
while (length--) {
|
||||
last_crc ^= *data++;
|
||||
for (j=0;j<8;j++) {
|
||||
if(last_crc & 0x01)
|
||||
last_crc = last_crc >>1 ^ 0xA001;
|
||||
else
|
||||
last_crc = last_crc >>1;
|
||||
}
|
||||
}
|
||||
|
||||
//printf(" crc = [0x%x]\n",last_crc);
|
||||
|
||||
return last_crc;
|
||||
}
|
||||
|
||||
|
||||
static int SaveAppBin(int fd, char* buf, int len)
|
||||
{
|
||||
int ret = 0;
|
||||
int fd_t = 0;
|
||||
fd_t = open( BOARD_APP_NAME, O_RDWR | O_APPEND);
|
||||
ret = write(fd, buf, len);
|
||||
if(ret < 0){
|
||||
printf("fd = %d write buf len[%d] failed.ret = %d\n",fd_t,len,ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fd[%d] write buf length[%d] done.\n",fd_t,ret);
|
||||
}
|
||||
|
||||
close(fd_t);
|
||||
}
|
||||
|
||||
static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
|
||||
{
|
||||
int ret = 0;
|
||||
int fd = 0;
|
||||
int len = 0;
|
||||
char *buf = NULL;
|
||||
unsigned int last_crc = 0xffff;
|
||||
unsigned long already_crc_length = 0;
|
||||
|
||||
fd = open( BOARD_APP_NAME, O_RDONLY );
|
||||
if(fd < 0){
|
||||
printf("open %s bin failed.\n",BOARD_APP_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf = PrivMalloc(128);
|
||||
if(NULL == buf)
|
||||
{
|
||||
printf("malloc failed.\n");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* crc check every 1024 Bytes until crc all the total file */
|
||||
while(already_crc_length != total_len)
|
||||
{
|
||||
memset(buf , 0 , 128);
|
||||
len = read(fd, buf, 128);
|
||||
if(len < 0)
|
||||
{
|
||||
printf("file read failed.ret = %d\n",len);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
last_crc = FileCrc16(buf, len, last_crc);
|
||||
already_crc_length += len;
|
||||
printf("read len[%d] Bytes,already_crc_length[%d]\n",len,already_crc_length);
|
||||
}
|
||||
|
||||
|
||||
if (last_crc != crc_check)
|
||||
{
|
||||
printf("file crc error!!! last crc[%x] != check[%x]\n",last_crc,crc_check);
|
||||
ret =-1;
|
||||
}
|
||||
|
||||
PrivFree(buf);
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void RestartApplication(void)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 10;
|
||||
attr.stacksize = 2048;
|
||||
|
||||
while(1)
|
||||
{
|
||||
unsigned long pid = PrivUserTaskSearch();
|
||||
if ((pid > 0) && (pid != pthread_self()))
|
||||
{
|
||||
printf("kill usertask pid[%d]\n",pid);
|
||||
PrivTaskDelete(pid, 0);
|
||||
PrivTaskDelay(1000); /* NOTE:this delay will make a schedule and recycle all user task */
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("restart main.\n");
|
||||
PrivTaskCreate(&restart_main, &attr, (void *)main, NULL);
|
||||
}
|
||||
static int OtaDataRecv(struct Adapter* adapter)
|
||||
{
|
||||
struct ota_data recv_msg;
|
||||
char reply[16] = {0};
|
||||
int ret = 0;
|
||||
int try_times = 10;
|
||||
int fd = 0;
|
||||
int frame_cnt = 0;
|
||||
|
||||
fd = open( BOARD_APP_NAME, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if(fd < 0)
|
||||
{
|
||||
printf("open %s failed\n",BOARD_APP_NAME);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
while(1) {
|
||||
memset(&recv_msg, 0, sizeof(struct ota_data));
|
||||
printf("recv msg...\n");
|
||||
ret = AdapterDeviceRecv(adapter, &recv_msg, sizeof(struct ota_data));
|
||||
if(ret >= 0 && recv_msg.header.frame_flag == 0x5A5A)
|
||||
{
|
||||
if(0 == strncmp("aiit_ota_end",recv_msg.frame.frame_data, strlen("aiit_ota_end")))
|
||||
{
|
||||
printf("total [%d]frames [%d]Bytes crc[%x],receive successful,\n",frame_cnt,recv_msg.header.total_len,recv_msg.frame.crc);
|
||||
if(0 != CrcFileCheck(recv_msg.frame.crc, recv_msg.header.total_len))
|
||||
{
|
||||
printf("crc check %s bin failed.please try again.\n", BOARD_APP_NAME);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
PrivTaskDelay(500);
|
||||
printf("tolal file crc done.send ok\n");
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "ok", strlen("ok"));
|
||||
|
||||
AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
frame_cnt = recv_msg.frame.frame_id;
|
||||
|
||||
if(0 == strncmp("wait_ok_timeout",recv_msg.frame.frame_data, strlen("wait_ok_timeout")))
|
||||
{
|
||||
printf("go to send ok again.\n");
|
||||
goto send_ok_again;
|
||||
|
||||
}
|
||||
|
||||
if (recv_msg.frame.crc == OtaCrc16(recv_msg.frame.frame_data,recv_msg.frame.frame_len))
|
||||
{
|
||||
printf("save current [%d] frame,length[%d] Bytes.\n",frame_cnt,recv_msg.frame.frame_len);
|
||||
for(int i = 0; i < recv_msg.frame.frame_len;i++ ){
|
||||
printf(" %x ",*((char *)&recv_msg.frame.frame_data + i));
|
||||
}
|
||||
printf("\n");
|
||||
SaveAppBin(fd, recv_msg.frame.frame_data, recv_msg.frame.frame_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("current [%d] frame crc check failed,try again!\n",frame_cnt);
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
send_ok_again:
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "ok", strlen("ok"));
|
||||
// PrivTaskDelay(100);
|
||||
|
||||
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
if(ret < 0){
|
||||
printf("send ok failed.\n");
|
||||
goto send_ok_again;
|
||||
}
|
||||
printf("send reply[%s] done.\n",reply);
|
||||
try_times = 10;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
try_again:
|
||||
if(try_times == 0)
|
||||
{
|
||||
printf("oops!!! current [%d] frame try 10 times failed,break out!\n",frame_cnt);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "retry", strlen("retry"));
|
||||
printf("[%d] frame receive failed. retry\n",frame_cnt);
|
||||
AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
try_times--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
|
||||
if(0 == ret) {
|
||||
printf("ota file done,start application.\n");
|
||||
RestartApplication();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *OtaKTaskEntry(void *parameter)
|
||||
{
|
||||
struct ota_data recv_msg;
|
||||
char reply[16] = {0};
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
int len = 0;
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName("4G");
|
||||
uint8 server_addr[64] = "115.238.53.61";
|
||||
uint8 server_port[64] = "9898";
|
||||
|
||||
adapter->socket.socket_id = 0;
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
AdapterDeviceConnect(adapter, CLIENT, server_addr, server_port, IPV4);
|
||||
|
||||
/* using nbiot as connection way*/
|
||||
|
||||
// struct Adapter* adapter = AdapterDeviceFindByName("nbiot");
|
||||
|
||||
// while(1)
|
||||
// {
|
||||
// int connect_times = 5;
|
||||
// ret = AdapterDeviceOpen(adapter);
|
||||
// if(ret < 0)
|
||||
// {
|
||||
// printf("open adapter failed\n");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// connect_again:
|
||||
// connect_times--;
|
||||
// ret = AdapterDeviceConnect(adapter, 1, "115.238.53.61","9898",1);
|
||||
// if(ret < 0)
|
||||
// {
|
||||
// if(connect_times > 0){
|
||||
// goto connect_again;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// AdapterDeviceClose(adapter);
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
PrivTaskDelay(5000);
|
||||
while(1)
|
||||
{
|
||||
memset(&recv_msg, 0, sizeof(struct ota_data));
|
||||
/* step1: Confirm the start signal of transmission*/
|
||||
printf("waiting for start msg...\n");
|
||||
ret = AdapterDeviceRecv(adapter, &recv_msg, sizeof(struct ota_data));
|
||||
for(int i = 0; i < sizeof(struct ota_data);i++ ){
|
||||
printf(" %x ",*((char *)&recv_msg + i));
|
||||
}
|
||||
printf("\n");
|
||||
if(ret >= 0 && recv_msg.header.frame_flag == 0x5A5A)
|
||||
{
|
||||
if (0 == strncmp("aiit_ota_start",recv_msg.frame.frame_data, strlen("aiit_ota_start")))
|
||||
{
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "ready", strlen("ready"));
|
||||
// PrivTaskDelay(3000);
|
||||
printf("receive start signal,send [ready] signal to server\n");
|
||||
send_ready_again:
|
||||
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
if(ret < 0)
|
||||
{
|
||||
goto send_ready_again;
|
||||
}
|
||||
PrivTaskDelay(3000);
|
||||
printf("start receive ota file.\n");
|
||||
/* step2: start receive source bin file of application*/
|
||||
ret = OtaDataRecv(adapter);
|
||||
if (0 != ret)
|
||||
{
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "ota_restart", strlen("ota_restart"));
|
||||
AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(reply, 0, 16);
|
||||
memcpy(reply, "notready", strlen("notready"));
|
||||
printf("ota status:not ready\n");
|
||||
ret = AdapterDeviceSend(adapter, reply, strlen(reply));
|
||||
}
|
||||
PrivTaskDelay(3000); /* check ota signal every 5s */
|
||||
}
|
||||
AdapterDeviceClose(adapter);
|
||||
|
||||
}
|
||||
|
||||
void ApplicationOtaTaskInit(void)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 20;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
PrivTaskCreate(&ota_task, &attr, OtaKTaskEntry, NULL);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,364 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
typedef int BOOL;
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
int serverfd;//服务器socket
|
||||
int clientfd[100000];//客户端的socketfd,100个元素,clientfd[0]~clientfd[99]
|
||||
int size = 99999;//用来控制进入聊天室的人数为50以内
|
||||
int PORT = 9898;//端口号
|
||||
typedef struct sockaddr meng;
|
||||
|
||||
struct ota_header_t
|
||||
{
|
||||
int16_t frame_flag; ///< frame start flag 2 Bytes
|
||||
uint8_t dev_type; ///< device type
|
||||
uint8_t burn_mode; ///< data burn way
|
||||
uint32_t total_len; ///< send data total length caculated from each frame_len
|
||||
uint32_t dev_hid; ///< device hardware version
|
||||
uint32_t dev_sid; ///< device software version
|
||||
char resv[8]; ///< reserve
|
||||
};
|
||||
|
||||
struct ota_frame_t
|
||||
{
|
||||
uint32_t frame_id; ///< Current frame id
|
||||
uint32_t frame_len; ///< Current frame data length
|
||||
char frame_data[64]; ///< Current frame data,max length 224
|
||||
uint32_t crc; ///< Current frame data crc
|
||||
};
|
||||
|
||||
struct ota_data
|
||||
{
|
||||
struct ota_header_t header;
|
||||
struct ota_frame_t frame;
|
||||
char end[4];
|
||||
};
|
||||
|
||||
pthread_t ota_ktask;
|
||||
|
||||
/**
|
||||
* @description: CRC16 check
|
||||
* @param data data buffer
|
||||
* @param length data length
|
||||
* @return check code
|
||||
*/
|
||||
uint32_t OtaCrc16(uint8_t * data, uint32_t length)
|
||||
{
|
||||
int j;
|
||||
unsigned int reg_crc=0xFFFF;
|
||||
|
||||
printf("crc data length[%d] Bytes,",length);
|
||||
|
||||
while (length--) {
|
||||
reg_crc ^= *data++;
|
||||
for (j=0;j<8;j++) {
|
||||
if(reg_crc & 0x01)
|
||||
reg_crc=reg_crc >>1 ^ 0xA001;
|
||||
else
|
||||
reg_crc=reg_crc >>1;
|
||||
}
|
||||
}
|
||||
printf(" crc = [0x%x]\n",reg_crc);
|
||||
return reg_crc;
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
serverfd = socket(PF_INET,SOCK_STREAM,0);
|
||||
|
||||
if (serverfd == -1)
|
||||
{
|
||||
perror("创建socket失败");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//为套接字设置ip协议 设置端口号 并自动获取本机ip转化为网络ip
|
||||
|
||||
struct sockaddr_in addr;//存储套接字的信息
|
||||
addr.sin_family = AF_INET;//地址族
|
||||
addr.sin_port = htons(PORT);//设置server端端口号,你可以随便设置,当sin_port = 0时,系统随机选择一个未被使用的端口号
|
||||
addr.sin_addr.s_addr = htons(INADDR_ANY);//当sin_addr = INADDR_ANY时,表示从本机的任一网卡接收数据
|
||||
|
||||
//绑定套接字
|
||||
// int on = 1;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
if(setsockopt(serverfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0)
|
||||
{
|
||||
perror("端口设置失败");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (bind(serverfd,(meng*)&addr,sizeof(addr)) == -1)
|
||||
{
|
||||
perror("绑定失败");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (listen(serverfd,100) == -1)
|
||||
{//监听最大连接数
|
||||
perror("设置监听失败");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
int OtaFileSend(int fd)
|
||||
{
|
||||
unsigned char buf[32] = { 0 };
|
||||
struct ota_data data;
|
||||
FILE *file_fd;
|
||||
char ch;
|
||||
int length = 0;
|
||||
int try_times = 10;
|
||||
int recv_end_times = 3;
|
||||
int ret = 0;
|
||||
int frame_cnt = 0;
|
||||
int file_length = 0;
|
||||
char * file_buf = NULL;
|
||||
|
||||
file_fd = fopen("/home/aep04/wwg/XiUOS_aiit-arm32-board_app.bin", "r");
|
||||
if (NULL == file_fd){
|
||||
printf("open file failed.\n");
|
||||
return -1;
|
||||
}
|
||||
fseek(file_fd, 0, SEEK_SET);
|
||||
printf("start send file.\n");
|
||||
while(!feof(file_fd))
|
||||
{
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
data.header.frame_flag = 0x5A5A;
|
||||
length = fread( data.frame.frame_data, 1, 64, file_fd );
|
||||
if(length > 0)
|
||||
{
|
||||
printf("read %d Bytes\n",length);
|
||||
data.frame.frame_id = frame_cnt;
|
||||
data.frame.frame_len = length;
|
||||
data.frame.crc = OtaCrc16(data.frame.frame_data, length);
|
||||
file_length += length;
|
||||
}
|
||||
|
||||
send_again:
|
||||
usleep(50000);
|
||||
printf("ota send current[%d] frame.\n",frame_cnt);
|
||||
length = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||
if(length < 0){
|
||||
printf("send [%d] frame faile.go to send again\n",frame_cnt);
|
||||
goto send_again;
|
||||
}
|
||||
|
||||
recv_again:
|
||||
memset(buf, 0, 32);
|
||||
length = recv(fd, buf, sizeof(buf), 0);
|
||||
if(length < 0 ){
|
||||
printf("[%d] frame waiting for ok timeout,receive again.\n",frame_cnt);
|
||||
goto recv_again;
|
||||
}
|
||||
|
||||
printf("receive buf[%s] length = %d\n",buf, length);
|
||||
if(0 == strncmp(buf, "ok", length))
|
||||
{
|
||||
try_times = 10;
|
||||
printf("[%d]frame data send done.\n",frame_cnt);
|
||||
frame_cnt++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(try_times > 0)
|
||||
{
|
||||
try_times--;
|
||||
goto send_again;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("send frame[%d] 10 times failed.\n",frame_cnt);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* finally,crc check total bin file.*/
|
||||
if (ret == 0)
|
||||
{
|
||||
sleep(1);
|
||||
printf("total send file length[%d] Bytes [%d] frames.\n",file_length,frame_cnt);
|
||||
printf("now crc check total bin file.\n");
|
||||
file_buf = malloc(file_length);
|
||||
memset(file_buf, 0, file_length);
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
data.header.frame_flag = 0x5A5A;
|
||||
|
||||
file_fd = fopen("/home/aep04/wwg/XiUOS_aiit-arm32-board_app.bin", "r");
|
||||
if (NULL == file_fd){
|
||||
printf("open file failed.\n");
|
||||
return -1;
|
||||
}
|
||||
fseek(file_fd, 0, SEEK_SET);
|
||||
length = fread(file_buf,1, file_length, file_fd);
|
||||
printf("read file length = %d\n",length);
|
||||
if(length > 0) {
|
||||
data.frame.frame_id = frame_cnt;
|
||||
data.header.total_len = file_length;
|
||||
data.frame.frame_len = strlen("aiit_ota_end");
|
||||
data.frame.crc = OtaCrc16(file_buf, length);
|
||||
memcpy(data.frame.frame_data,"aiit_ota_end",strlen("aiit_ota_end"));
|
||||
}
|
||||
|
||||
send_end_signal:
|
||||
printf("send aiit_ota_end signal.\n");
|
||||
length = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||
if(length < 0){
|
||||
printf("send end signal faile,send end signal again\n");
|
||||
goto send_end_signal;
|
||||
}
|
||||
|
||||
recv_end_signal:
|
||||
memset(buf, 0, 32);
|
||||
length = recv(fd, buf, sizeof(buf), 0);
|
||||
if(length < 0 )
|
||||
{
|
||||
recv_end_times--;
|
||||
printf("end signal waiting for ok timeout,receive again.\n");
|
||||
if(recv_end_times > 0)
|
||||
{
|
||||
goto recv_end_signal;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(0 != strncmp(buf, "ok", length))
|
||||
{
|
||||
printf("error end !!!\n");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
free(file_buf);
|
||||
}
|
||||
|
||||
fclose(file_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* server_thread(void* p)
|
||||
{
|
||||
int fd = *(int*)p;
|
||||
unsigned char buf[32] = { 0 };
|
||||
struct ota_data data;
|
||||
int ret = 0;
|
||||
int length = 0;
|
||||
|
||||
printf("pthread = %d\n",fd);
|
||||
sleep(8);
|
||||
while(1)
|
||||
{
|
||||
memset(&data, 0x0 , sizeof(struct ota_data));
|
||||
data.header.frame_flag = 0x5A5A;
|
||||
memcpy(data.frame.frame_data,"aiit_ota_start",strlen("aiit_ota_start"));
|
||||
data.frame.frame_len = strlen("aiit_ota_start");
|
||||
|
||||
printf("send start signal.\n");
|
||||
ret = send(fd, &data, sizeof(data), MSG_NOSIGNAL);
|
||||
if (ret > 0){
|
||||
printf("send %s[%d] Bytes\n",data.frame.frame_data,ret);
|
||||
}
|
||||
// sleep(1);
|
||||
memset(buf, 0, 32);
|
||||
length = recv(fd, buf, sizeof(buf), 0);
|
||||
if (length <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("recv buf %s length %d\n",buf,length);
|
||||
if(0 == strncmp(buf, "ready", length))
|
||||
{
|
||||
ret = OtaFileSend(fd);
|
||||
if (ret == 0) {
|
||||
printf("ota file send successful.\n");
|
||||
break;
|
||||
} else { /* ota failed then restart the ota process */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("exit fd = %d\n",fd);
|
||||
close(fd);
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void server(void)
|
||||
{
|
||||
printf("ota Server startup\n");
|
||||
while(1)
|
||||
{
|
||||
struct sockaddr_in fromaddr;
|
||||
socklen_t len = sizeof(fromaddr);
|
||||
int fd = accept(serverfd,(meng*)&fromaddr,&len);
|
||||
|
||||
//调用accept进入堵塞状态,等待客户端的连接
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
// printf("The client connection is wrong...\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (i = 0;i < size;i++)
|
||||
{
|
||||
if (clientfd[i] == 0)
|
||||
{
|
||||
//记录客户端的socket
|
||||
clientfd[i] = fd;
|
||||
|
||||
//有客户端连接之后,启动线程给此客户服务
|
||||
pthread_t tid;
|
||||
pthread_create(&tid,0,server_thread,&fd);
|
||||
break;
|
||||
}
|
||||
|
||||
if (size == i)
|
||||
{
|
||||
//发送给客户端说聊天室满了
|
||||
char* str = "Devices full";
|
||||
printf("%s", str);
|
||||
send(fd,str,strlen(str),0);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init();
|
||||
server();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
menu "sensor app"
|
||||
|
||||
menuconfig APPLICATION_SENSOR
|
||||
bool "Using sensor apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR
|
||||
menuconfig APPLICATION_SENSOR_HCHO
|
||||
bool "Using sensor HCHO apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_HCHO
|
||||
config APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS
|
||||
bool "Using sensor TB600B_WQ_HCHO1OS apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_TVOC
|
||||
bool "Using sensor TVOC apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_TVOC
|
||||
config APPLICATION_SENSOR_TVOC_TB600B_TVOC10
|
||||
bool "Using sensor TB600B_TVOC10 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_IAQ
|
||||
bool "Using sensor IAQ apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_IAQ
|
||||
config APPLICATION_SENSOR_IAQ_TB600B_IAQ10
|
||||
bool "Using sensor TB600B_IAQ10 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_CH4
|
||||
bool "Using sensor CH4 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_CH4
|
||||
config APPLICATION_SENSOR_CH4_AS830
|
||||
bool "Using sensor AS830 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_CO2
|
||||
bool "Using sensor CO2 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_CO2
|
||||
config APPLICATION_SENSOR_CO2_ZG09
|
||||
bool "Using sensor ZG09 apps"
|
||||
default n
|
||||
|
||||
config APPLICATION_SENSOR_CO2_G8S
|
||||
bool "Using sensor G8S apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM1_0
|
||||
bool "Using sensor PM1.0 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_PM1_0
|
||||
config APPLICATION_SENSOR_PM1_0_PS5308
|
||||
bool "Using sensor PS5308 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM2_5
|
||||
bool "Using sensor PM2.5 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_PM2_5
|
||||
config APPLICATION_SENSOR_PM2_5_PS5308
|
||||
bool "Using sensor PS5308 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM10
|
||||
bool "Using sensor PM10 apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_PM10
|
||||
config APPLICATION_SENSOR_PM10_PS5308
|
||||
bool "Using sensor PS5308 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_VOICE
|
||||
bool "Using sensor voice apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_VOICE
|
||||
config APPLICATION_SENSOR_VOICE_D124
|
||||
bool "Using sensor D124 apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_TEMPERATURE
|
||||
bool "Using sensor temperature apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_TEMPERATURE
|
||||
config APPLICATION_SENSOR_TEMPERATURE_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_HUMIDITY
|
||||
bool "Using sensor humidity apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_HUMIDITY
|
||||
config APPLICATION_SENSOR_HUMIDITY_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_WINDDIRECTION
|
||||
bool "Using sensor wind direction apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_WINDDIRECTION
|
||||
config APPLICATION_SENSOR_WINDDIRECTION_QS_FX
|
||||
bool "Using sensor QS-FX apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_WINDSPEED
|
||||
bool "Using sensor wind speed apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_WINDSPEED
|
||||
config APPLICATION_SENSOR_WINDSPEED_QS_FS
|
||||
bool "Using sensor QS-FS apps"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_ALTITUDE
|
||||
bool "Using sensor altitude apps"
|
||||
default n
|
||||
|
||||
if APPLICATION_SENSOR_ALTITUDE
|
||||
config APPLICATION_SENSOR_ALTITUDE_BMP180
|
||||
bool "Using sensor BMP180 apps"
|
||||
default n
|
||||
endif
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Applications/sensor_app/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_APPLICATION_SENSOR),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Applications/sensor_app
|
||||
endif
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||
CSRCS += hcho_tb600b_wq_hcho1os.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
|
||||
CSRCS += tvoc_tb600b_tvoc10.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
|
||||
CSRCS += iaq_tb600b_iaq10.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
|
||||
CSRCS += ch4_as830.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
|
||||
CSRCS += co2_zg09.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
|
||||
CSRCS += pm1_0_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
|
||||
CSRCS += pm2_5_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y)
|
||||
CSRCS += pm10_0_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
|
||||
CSRCS += voice_d124.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
|
||||
CSRCS += humidity_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), 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
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||
SRC_FILES += hcho_tb600b_wq_hcho1os.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
|
||||
SRC_FILES += tvoc_tb600b_tvoc10.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
|
||||
SRC_FILES += iaq_tb600b_iaq10.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CH4_AS830), y)
|
||||
SRC_FILES += ch4_as830.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
|
||||
SRC_FILES += co2_zg09.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y)
|
||||
SRC_FILES += co2_g8s.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
|
||||
SRC_FILES += pm1_0_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308), y)
|
||||
SRC_FILES += pm2_5_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM10_PS5308), y)
|
||||
SRC_FILES += pm10_0_ps5308.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_VOICE_D124), y)
|
||||
SRC_FILES += voice_d124.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X), y)
|
||||
SRC_FILES += humidity_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X), y)
|
||||
SRC_FILES += temperature_hs300x.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDDIRECTION_QS_FX), y)
|
||||
SRC_FILES += winddirection_qs_fx.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_WINDSPEED_QS_FS), y)
|
||||
SRC_FILES += windspeed_qs_fs.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_ALTITUDE_BMP180), y)
|
||||
SRC_FILES += altitude_bmp180.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import os
|
||||
from building import *
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
cwd = GetCurrentDir()
|
||||
DEPENDS = ["SUPPORT_SENSOR_FRAMEWORK"]
|
||||
SOURCES = []
|
||||
if GetDepend(['APPLICATION_SENSOR_CO2_ZG09']):
|
||||
SOURCES = ['co2_zg09.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_PM1_0_PS5308']):
|
||||
SOURCES = ['pm1_0_ps5308.c.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_VOICE_D124']):
|
||||
SOURCES = ['voice_d124.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_HUMIDITY_HS300X']):
|
||||
SOURCES = ['humidity_hs300x.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_TEMPERATURE_HS300X']):
|
||||
SOURCES = ['temperature_hs300x.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_CH4_AS830']):
|
||||
SOURCES = ['ch4_as830.c'] + SOURCES
|
||||
if GetDepend(['APPLICATION_SENSOR_HCHO']):
|
||||
SOURCES = ['hcho_tb600b_wq_hcho1os.c'] + SOURCES
|
||||
path = [cwd]
|
||||
objs = DefineGroup('sensor_app', src = SOURCES, depend = DEPENDS,CPPPATH = path)
|
||||
Return("objs")
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 altitude_bmp180.c
|
||||
* @brief BMP180 altitude example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.23
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a altitude
|
||||
* @return 0
|
||||
*/
|
||||
void AltitudeBmp180(void)
|
||||
{
|
||||
int32 altitude;
|
||||
struct SensorQuantity *p_altitude = SensorQuantityFind(SENSOR_QUANTITY_BMP180_ALTITUDE, SENSOR_QUANTITY_ALTITUDE);
|
||||
SensorQuantityOpen(p_altitude);
|
||||
altitude = SensorQuantityRead(p_altitude);
|
||||
|
||||
printf("Altitude Pressure : %d Pa\n", altitude);
|
||||
|
||||
PrivTaskDelay(1000);
|
||||
SensorQuantityClose(p_altitude);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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 ch4_as830.c
|
||||
* @brief CH4 AS830 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.10
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a ch4
|
||||
* @return 0
|
||||
*/
|
||||
void Ch4As830(void)
|
||||
{
|
||||
struct SensorQuantity *ch4 = SensorQuantityFind(SENSOR_QUANTITY_AS830_CH4, SENSOR_QUANTITY_CH4);
|
||||
SensorQuantityOpen(ch4);
|
||||
printf("CH4 : %d %%LTL\n", SensorQuantityRead(ch4));
|
||||
SensorQuantityClose(ch4);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 co2_g8s.c
|
||||
* @brief G8S CO2 example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.23
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a CO2
|
||||
* @return 0
|
||||
*/
|
||||
void Co2G8s(void)
|
||||
{
|
||||
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2);
|
||||
SensorQuantityOpen(co2);
|
||||
printf("CO2 : %d ppm\n", SensorQuantityRead(co2));
|
||||
SensorQuantityClose(co2);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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 co2_zg09.c
|
||||
* @brief ZG09 CO2 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a CO2
|
||||
* @return 0
|
||||
*/
|
||||
void Co2Zg09(void)
|
||||
{
|
||||
struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_ZG09_CO2, SENSOR_QUANTITY_CO2);
|
||||
SensorQuantityOpen(co2);
|
||||
printf("CO2 : %d ppm\n", SensorQuantityRead(co2));
|
||||
SensorQuantityClose(co2);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 hcho_tb600b_wq_hcho1os.c
|
||||
* @brief hcho example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
||||
|
||||
/**
|
||||
* @description: Read a hcho
|
||||
* @return 0
|
||||
*/
|
||||
void HchoTb600bHcho1os(void)
|
||||
{
|
||||
struct SensorQuantity *hcho = SensorQuantityFind(SENSOR_QUANTITY_TB600B_HCHO, SENSOR_QUANTITY_HCHO);
|
||||
SensorQuantityOpen(hcho);
|
||||
int32_t result = 0;
|
||||
|
||||
result = SensorQuantityRead(hcho);
|
||||
|
||||
printf("tvoc concentration is : %dppb\n", result);
|
||||
SensorQuantityClose(hcho);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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 humidity_hs300x.c
|
||||
* @brief HS300x humidity example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a himidity
|
||||
* @return 0
|
||||
*/
|
||||
void HumiHs300x(void)
|
||||
{
|
||||
int i = 0;
|
||||
int32 humidity;
|
||||
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
|
||||
SensorQuantityOpen(humi);
|
||||
for (i = 0; i < 100; i ++) {
|
||||
humidity = SensorQuantityRead(humi);
|
||||
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
|
||||
PrivTaskDelay(5000);
|
||||
}
|
||||
SensorQuantityClose(humi);
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 iaq_tb600b_iaq10.c
|
||||
* @brief iaq10 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
||||
// struct iaq_data {
|
||||
// uint16_t gas;
|
||||
// uint8_t TH;
|
||||
// uint8_t TL;
|
||||
// uint8_t RhH;
|
||||
// uint8_t RhL;
|
||||
// };
|
||||
/**
|
||||
* @description: Read a iaq
|
||||
* @return 0
|
||||
*/
|
||||
void IaqTb600bIaq10(void)
|
||||
{
|
||||
struct SensorQuantity *iaq = SensorQuantityFind(SENSOR_QUANTITY_TB600B_IAQ, SENSOR_QUANTITY_IAQ);
|
||||
SensorQuantityOpen(iaq);
|
||||
int32_t result = 0;
|
||||
|
||||
result = SensorQuantityRead(iaq);
|
||||
|
||||
printf("Gas concentration is : %dppb\n", result);
|
||||
SensorQuantityClose(iaq);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 pm10_0_ps5308.c
|
||||
* @brief PS5308 PM10.0 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a PM10
|
||||
* @return 0
|
||||
*/
|
||||
void Pm100Ps5308(void)
|
||||
{
|
||||
struct SensorQuantity *pm10_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM10, SENSOR_QUANTITY_PM);
|
||||
SensorQuantityOpen(pm10_0);
|
||||
PrivTaskDelay(2000);
|
||||
printf("PM10 : %d ug/m³\n", SensorQuantityRead(pm10_0));
|
||||
SensorQuantityClose(pm10_0);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 pm1_0_ps5308.c
|
||||
* @brief PS5308 PM1.0 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a PM1.0
|
||||
* @return 0
|
||||
*/
|
||||
void Pm10Ps5308(void)
|
||||
{
|
||||
struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM);
|
||||
SensorQuantityOpen(pm1_0);
|
||||
PrivTaskDelay(2000);
|
||||
printf("PM1.0 : %d ug/m³\n", SensorQuantityRead(pm1_0));
|
||||
SensorQuantityClose(pm1_0);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 pm2_5_ps5308.c
|
||||
* @brief PS5308 PM2.5 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.28
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a PM2.5
|
||||
* @return 0
|
||||
*/
|
||||
void Pm25Ps5308(void)
|
||||
{
|
||||
struct SensorQuantity *pm2_5 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM2_5, SENSOR_QUANTITY_PM);
|
||||
SensorQuantityOpen(pm2_5);
|
||||
PrivTaskDelay(2000);
|
||||
printf("PM2.5 : %d ug/m³\n", SensorQuantityRead(pm2_5));
|
||||
SensorQuantityClose(pm2_5);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 temperature_hs300x.c
|
||||
* @brief HS300x temperature example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a temperature
|
||||
* @return 0
|
||||
*/
|
||||
void TempHs300x(void)
|
||||
{
|
||||
int i = 0;
|
||||
int32 temperature;
|
||||
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
|
||||
SensorQuantityOpen(temp);
|
||||
for (i = 0; i < 100; i ++) {
|
||||
temperature = SensorQuantityRead(temp);
|
||||
if (temperature > 0)
|
||||
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
|
||||
else
|
||||
printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10);
|
||||
|
||||
PrivTaskDelay(5000);
|
||||
}
|
||||
|
||||
SensorQuantityClose(temp);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 tvoc_tb600b_tvoc10.c
|
||||
* @brief tvoc10 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
#include <sensor.h>
|
||||
|
||||
|
||||
/**
|
||||
* @description: Read a tvoc
|
||||
* @return 0
|
||||
*/
|
||||
void TvocTb600bTvoc10(void)
|
||||
{
|
||||
struct SensorQuantity *tvoc = SensorQuantityFind(SENSOR_QUANTITY_TB600B_TVOC, SENSOR_QUANTITY_TVOC);
|
||||
SensorQuantityOpen(tvoc);
|
||||
int32_t result = 0;
|
||||
|
||||
result = SensorQuantityRead(tvoc);
|
||||
|
||||
printf("tvoc concentration is : %dppb\n", result);
|
||||
SensorQuantityClose(tvoc);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 voice_d124.c
|
||||
* @brief D124 voice example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a voice
|
||||
* @return 0
|
||||
*/
|
||||
void VoiceD124(void)
|
||||
{
|
||||
struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE);
|
||||
SensorQuantityOpen(voice);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(voice);
|
||||
printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places));
|
||||
SensorQuantityClose(voice);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 winddirection_qs_fx.c
|
||||
* @brief qs-fx wind direction example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a wind direction
|
||||
* @return 0
|
||||
*/
|
||||
void WindDirectionQsFx(void)
|
||||
{
|
||||
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
|
||||
SensorQuantityOpen(wind_direction);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(wind_direction);
|
||||
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
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiOS 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 windspeed_qs_fs.c
|
||||
* @brief qs-fx wind direction example
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.12.14
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a wind speed
|
||||
* @return 0
|
||||
*/
|
||||
void WindSpeedQsFs(void)
|
||||
{
|
||||
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
|
||||
SensorQuantityOpen(wind_speed);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(wind_speed);
|
||||
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
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
menu "Framework"
|
||||
|
||||
config TRANSFORM_LAYER_ATTRIUBUTE
|
||||
bool "support transform layer"
|
||||
default y
|
||||
choice
|
||||
prompt "select os features"
|
||||
default ADD_XIZI_FETURES
|
||||
|
||||
config ADD_XIZI_FETURES
|
||||
bool "add xizi fetures"
|
||||
|
||||
config ADD_NUTTX_FETURES
|
||||
bool "add nuttx fetures"
|
||||
|
||||
config ADD_RTTHREAD_FETURES
|
||||
bool "add rt_thread fetures"
|
||||
endchoice
|
||||
|
||||
|
||||
source "$APP_DIR/Framework/sensor/Kconfig"
|
||||
source "$APP_DIR/Framework/connection/Kconfig"
|
||||
source "$APP_DIR/Framework/knowing/Kconfig"
|
||||
source "$APP_DIR/Framework/control/Kconfig"
|
||||
source "$APP_DIR/Framework/security/Kconfig"
|
||||
|
||||
|
||||
endmenu
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/Make.defs
|
||||
############################################################################
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/transform_layer/nuttx
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/*/Make.defs)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
SRC_DIR := transform_layer
|
||||
|
||||
ifeq ($(CONFIG_SUPPORT_SENSOR_FRAMEWORK),y)
|
||||
SRC_DIR += sensor
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SUPPORT_CONNECTION_FRAMEWORK),y)
|
||||
SRC_DIR += connection
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SUPPORT_KNOWING_FRAMEWORK),y)
|
||||
SRC_DIR += knowing
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SUPPORT_CONTROL_FRAMEWORK),y)
|
||||
SRC_DIR += control
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CRYPTO),y)
|
||||
SRC_DIR += security
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
list = os.listdir(cwd)
|
||||
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(path, 'SConscript'))
|
||||
|
||||
Return('objs')
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
config ADAPTER_EC200T
|
||||
bool "Using 4G adapter device EC200T"
|
||||
default y
|
||||
|
||||
if ADAPTER_EC200T
|
||||
source "$APP_DIR/Framework/connection/4g/ec200t/Kconfig"
|
||||
endif
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/4g/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_CONNECTION_ADAPTER_4G),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/4g
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/connection/4g/*/Make.defs)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += adapter_4g.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter_4g.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_EC200T),y)
|
||||
SRC_DIR += ec200t
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* 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 adapter_4G.c
|
||||
* @brief Implement the connection 4G adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_EC200T
|
||||
extern AdapterProductInfoType Ec200tAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
static int Adapter4GRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_4G_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->net_role = CLIENT;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("Adapter4G register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Adapter4GInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = Adapter4GRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("Adapter4GInit register 4G adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_EC200T
|
||||
AdapterProductInfoType product_info = Ec200tAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("Adapter4GInit ec200t 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;
|
||||
}
|
||||
|
||||
/******************4G TEST*********************/
|
||||
int Adapter4GTest(void)
|
||||
{
|
||||
const char *send_msg = "Adapter_4G Test";
|
||||
char recv_msg[256] = {0};
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
|
||||
|
||||
#ifdef ADAPTER_EC200T
|
||||
//Using Hang Xiao server to test 4G Socket connection
|
||||
uint8 server_addr[64] = "120.76.100.197";
|
||||
uint8 server_port[64] = "10002";
|
||||
|
||||
adapter->socket.socket_id = 0;
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
AdapterDeviceConnect(adapter, CLIENT, server_addr, server_port, IPV4);
|
||||
|
||||
while (1) {
|
||||
AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
|
||||
AdapterDeviceRecv(adapter, recv_msg, 256);
|
||||
printf("4G recv msg %s\n", recv_msg);
|
||||
memset(recv_msg, 0, 256);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Adapter4GTest, Adapter4GTest, show adapter 4G information);
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
config ADAPTER_4G_EC200T
|
||||
string "EC200T adapter name"
|
||||
default "ec200t"
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_EC200T_PWRKEY
|
||||
int "EC200T PWRKEY pin number"
|
||||
default "97"
|
||||
|
||||
config ADAPTER_EC200T_PIN_DRIVER
|
||||
string "EC200T device pin driver path"
|
||||
default "/dev/pin_dev"
|
||||
|
||||
config ADAPTER_EC200T_DRIVER_EXTUART
|
||||
bool "Using extra uart to support 4G"
|
||||
default n
|
||||
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device uart driver path"
|
||||
default "/dev/usart2_dev2"
|
||||
depends on !ADAPTER_EC200T_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_EC200T_DRIVER_EXTUART
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device extra uart driver path"
|
||||
default "/dev/extuart_dev5"
|
||||
|
||||
config ADAPTER_EC200T_DRIVER_EXT_PORT
|
||||
int "if EC200T device using extuart, choose port"
|
||||
default "5"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device uart driver path"
|
||||
default "/dev/ttyS8"
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/4g/ec200t/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_ADAPTER_4G_EC200T),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/4g/ec200t
|
||||
endif
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += ec200t.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := ec200t.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,395 @@
|
|||
/*
|
||||
* 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 ec200t.c
|
||||
* @brief Implement the connection 4G adapter function, using EC200T device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.07.08
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#define EC200T_AT_MODE_CMD "+++"
|
||||
#define EC200T_GET_CCID_CMD "AT+CCID\r\n"
|
||||
#define EC200T_GET_CPIN_CMD "AT+CPIN?\r\n"
|
||||
#define EC200T_GET_CREG_CMD "AT+CREG?\r\n"
|
||||
#define EC200T_OPEN_SOCKET_CMD "AT+QIOPEN=1,%u"
|
||||
#define EC200T_CLOSE_SOCKET_CMD "AT+QICLOSE=%u\r\n"
|
||||
#define EC200T_ACTIVE_PDP_CMD "AT+QIACT=1\r\n"
|
||||
#define EC200T_DEACTIVE_PDP_CMD "AT+QIDEACT=1\r\n"
|
||||
#define EC200T_CFG_TCP_CMD "AT+QICSGP"
|
||||
|
||||
#define EC200T_OK_REPLY "OK"
|
||||
#define EC200T_READY_REPLY "READY"
|
||||
#define EC200T_CREG_REPLY ",1"
|
||||
#define EC200T_CONNECT_REPLY "CONNECT"
|
||||
|
||||
#define TRY_TIMES 10
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static void Ec200tPowerSet(void){ return; }
|
||||
#else
|
||||
static void Ec200tPowerSet(void)
|
||||
{
|
||||
int pin_fd;
|
||||
pin_fd = PrivOpen(ADAPTER_EC200T_PIN_DRIVER, O_RDWR);
|
||||
if (pin_fd < 0) {
|
||||
printf("open %s error\n", ADAPTER_EC200T_PIN_DRIVER);
|
||||
return;
|
||||
}
|
||||
|
||||
struct PinParam pin_param;
|
||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||
pin_param.mode = GPIO_CFG_OUTPUT;
|
||||
pin_param.pin = ADAPTER_EC200T_PWRKEY;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
ioctl_cfg.args = &pin_param;
|
||||
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||
|
||||
struct PinStat pin_stat;
|
||||
pin_stat.pin = ADAPTER_EC200T_PWRKEY;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
PrivTaskDelay(600);//at least 500ms
|
||||
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
PrivClose(pin_fd);
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int Ec200tOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open ec200t serial port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_EC200T_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Ec200tOpen get serial %s fd error\n", ADAPTER_EC200T_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "4G_uart_client";
|
||||
if (0 != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
ATAgentType at_agent = GetATAgent(agent_name);
|
||||
|
||||
adapter->agent = at_agent;
|
||||
}
|
||||
|
||||
PrivTaskDelay(2500);
|
||||
|
||||
ADAPTER_DEBUG("Ec200t open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Ec200tClose(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t ec200t_cmd[64];
|
||||
|
||||
if (!adapter->agent) {
|
||||
printf("Ec200tClose AT agent NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
|
||||
/*step1: serial write "+++", quit transparent mode*/
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
|
||||
/*step2: serial write "AT+QICLOSE", close socket connect before open socket*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_CLOSE_SOCKET_CMD, adapter->socket.socket_id);
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step3: serial write "AT+QIDEACT", close TCP net before open socket*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_DEACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
/*step4: close ec200t serial port*/
|
||||
PrivClose(adapter->fd);
|
||||
|
||||
/*step5: power down ec200t*/
|
||||
Ec200tPowerSet();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args){ return 0;}
|
||||
#else
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
printf("Ec200tIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t baud_rate = *((uint32_t *)args);
|
||||
|
||||
struct SerialDataCfg serial_cfg;
|
||||
memset(&serial_cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
serial_cfg.serial_baud_rate = baud_rate;
|
||||
serial_cfg.serial_data_bits = DATA_BITS_8;
|
||||
serial_cfg.serial_stop_bits = STOP_BITS_1;
|
||||
serial_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
serial_cfg.serial_parity_mode = PARITY_NONE;
|
||||
serial_cfg.serial_bit_order = STOP_BITS_1;
|
||||
serial_cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
#ifdef ADAPTER_EC200T_DRIVER_EXT_PORT
|
||||
serial_cfg.ext_uart_no = ADAPTER_EC200T_DRIVER_EXT_PORT;
|
||||
serial_cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
Ec200tPowerSet();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int ret = 0;
|
||||
int try = 0;
|
||||
uint8_t ec200t_cmd[64];
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
|
||||
/*step1: serial write "+++", quit transparent mode*/
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
|
||||
/*step2: serial write "AT+CCID", get SIM ID*/
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CCID_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step3: serial write "AT+CPIN?", check SIM status*/
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CPIN_CMD, EC200T_READY_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step4: serial write "AT+CREG?", check whether registered to GSM net*/
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CREG_CMD, EC200T_CREG_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step5: serial write "AT+QICSGP", connect to China Mobile using ipv4 or ipv6*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
|
||||
if (IPV4 == ip_type) {
|
||||
strcpy(ec200t_cmd, "AT+QICSGP=1,1,\"CMNET\",\"\",\"\",1\r\n");
|
||||
} else if (IPV6 == ip_type) {
|
||||
strcpy(ec200t_cmd, "AT+QICSGP=1,2,\"CMNET\",\"\",\"\",1\r\n");
|
||||
}
|
||||
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step6: serial write "AT+QICLOSE", close socket connect before open socket*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_CLOSE_SOCKET_CMD, adapter->socket.socket_id);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step7: serial write "AT+QIDEACT", close TCP net before open socket*/
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_DEACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step8: serial write "AT+QIACT", open TCP net*/
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_ACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step9: serial write "AT+QIOPEN", connect socket using TCP*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_OPEN_SOCKET_CMD, adapter->socket.socket_id);
|
||||
strcat(ec200t_cmd, ",\"TCP\",\"");
|
||||
strcat(ec200t_cmd, ip);
|
||||
strcat(ec200t_cmd, "\",");
|
||||
strcat(ec200t_cmd, port);
|
||||
strcat(ec200t_cmd, ",0,2\r\n");
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x43, 0x54);
|
||||
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_CONNECT_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Ec200t connect TCP done\n");
|
||||
|
||||
return 0;
|
||||
|
||||
out:
|
||||
ADAPTER_DEBUG("Ec200t connect TCP failed. Power down\n");
|
||||
Ec200tPowerSet();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Ec200tSend(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)buf, len);
|
||||
} else {
|
||||
printf("Ec200tSend can not find agent\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Ec200tRecv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)buf, len, 6);
|
||||
} else {
|
||||
printf("Ec200tRecv can not find agent\n");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Ec200tDisconnect(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t ec200t_cmd[64];
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
|
||||
/*step1: serial write "+++", quit transparent mode*/
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
|
||||
/*step2: serial write "AT+QICLOSE", close socket connect before open socket*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_CLOSE_SOCKET_CMD, adapter->socket.socket_id);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Ec200t disconnect TCP done\n");
|
||||
|
||||
return 0;
|
||||
|
||||
out:
|
||||
ADAPTER_DEBUG("Ec200t disconnect TCP failed. Power down\n");
|
||||
Ec200tPowerSet();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone ec200t_done =
|
||||
{
|
||||
.open = Ec200tOpen,
|
||||
.close = Ec200tClose,
|
||||
.ioctl = Ec200tIoctl,
|
||||
.setup = NULL,
|
||||
.setdown = NULL,
|
||||
.setaddr = NULL,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = NULL,
|
||||
.netstat = NULL,
|
||||
.connect = Ec200tConnect,
|
||||
.send = Ec200tSend,
|
||||
.recv = Ec200tRecv,
|
||||
.disconnect = Ec200tDisconnect,
|
||||
};
|
||||
|
||||
AdapterProductInfoType Ec200tAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Ec200tAttach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(product_info->model_name, ADAPTER_4G_EC200T);
|
||||
|
||||
product_info->model_done = (void *)&ec200t_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := adapter_5g.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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 adapter_5g.c
|
||||
* @brief Implement the connection 5G adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
*/
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
menuconfig SUPPORT_CONNECTION_FRAMEWORK
|
||||
bool "support connection framework"
|
||||
default n
|
||||
select TRANSFORM_LAYER_ATTRIUBUTE
|
||||
|
||||
if SUPPORT_CONNECTION_FRAMEWORK
|
||||
config CONNECTION_FRAMEWORK_DEBUG
|
||||
bool "Using connection framework debug log function"
|
||||
default y
|
||||
|
||||
menuconfig CONNECTION_INDUSTRIAL_ETHERNET
|
||||
bool "Using industrial ethernet"
|
||||
default n
|
||||
if CONNECTION_INDUSTRIAL_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/industrial_ethernet/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_INDUSTRIAL_FIELDBUS
|
||||
bool "Using industrial fieldbus"
|
||||
default n
|
||||
if CONNECTION_INDUSTRIAL_FIELDBUS
|
||||
source "$APP_DIR/Framework/connection/industrial_fieldbus/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_INDUSTRIAL_WLAN
|
||||
bool "Using industrial wlan"
|
||||
default n
|
||||
if CONNECTION_INDUSTRIAL_WLAN
|
||||
source "$APP_DIR/Framework/connection/industrial_wlan/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_LORA
|
||||
bool "Using lora adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_LORA
|
||||
source "$APP_DIR/Framework/connection/lora/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_4G
|
||||
bool "Using 4G adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_4G
|
||||
source "$APP_DIR/Framework/connection/4g/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_NB
|
||||
bool "Using nbiot adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_NB
|
||||
source "$APP_DIR/Framework/connection/nbiot/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_WIFI
|
||||
bool "Using wifi adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_WIFI
|
||||
source "$APP_DIR/Framework/connection/wifi/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_ETHERNET
|
||||
bool "Using ethernet adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/ethernet/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_BLUETOOTH
|
||||
bool "Using bluetooth adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_BLUETOOTH
|
||||
source "$APP_DIR/Framework/connection/bluetooth/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_ZIGBEE
|
||||
bool "Using zigbee adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_ZIGBEE
|
||||
source "$APP_DIR/Framework/connection/zigbee/Kconfig"
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_ADAPTER_5G
|
||||
bool "Using 5G adapter device"
|
||||
default n
|
||||
if CONNECTION_ADAPTER_5G
|
||||
source "$APP_DIR/Framework/connection/5g/Kconfig"
|
||||
endif
|
||||
endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
############################################################################
|
||||
# APP_Framework/Framework/connection/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SUPPORT_CONNECTION_FRAMEWORK),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/connection/*/Make.defs)
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += adapter.c adapter_agent.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter.c adapter_agent.c
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_ETHERNET),y)
|
||||
SRC_DIR += industrial_ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS),y)
|
||||
SRC_DIR += industrial_fieldbus
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_INDUSTRIAL_WLAN),y)
|
||||
SRC_DIR += industrial_wlan
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
|
||||
SRC_DIR += lora
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
|
||||
SRC_DIR += 4g
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_NB),y)
|
||||
SRC_DIR += nbiot
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_WIFI),y)
|
||||
SRC_DIR += wifi
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERNET),y)
|
||||
SRC_DIR += ethernet
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
|
||||
SRC_DIR += bluetooth
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),y)
|
||||
SRC_DIR += zigbee
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_5G),y)
|
||||
SRC_DIR += 5g
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,903 @@
|
|||
/*
|
||||
* 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 adapter.c
|
||||
* @brief Implement the connection adapter framework management and API
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.05.10
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
static DoublelistType adapter_list;
|
||||
|
||||
static int adapter_list_lock;
|
||||
|
||||
/**
|
||||
* @description: Init adapter framework
|
||||
* @return 0
|
||||
*/
|
||||
int AdapterFrameworkInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
AppInitDoubleList(&adapter_list);
|
||||
|
||||
ret = PrivMutexCreate(&adapter_list_lock, 0);
|
||||
if(ret != 0) {
|
||||
printf("AdapterFrameworkInit mutex create failed.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Find adapter device by name
|
||||
* @param name - name string
|
||||
* @return adapter device pointer
|
||||
*/
|
||||
AdapterType AdapterDeviceFindByName(const char *name)
|
||||
{
|
||||
struct Adapter *ret = NULL;
|
||||
struct DoublelistNode *node;
|
||||
int status = 0;
|
||||
|
||||
if (NULL == name)
|
||||
return NULL;
|
||||
|
||||
status = PrivMutexObtain(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_lock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
DOUBLE_LIST_FOR_EACH(node, &adapter_list) {
|
||||
struct Adapter *adapter = CONTAINER_OF(node,
|
||||
struct Adapter, link);
|
||||
if (0 == strncmp(adapter->name, name, NAME_NUM_MAX)) {
|
||||
ret = adapter;
|
||||
break;
|
||||
}
|
||||
printf("PrivMutexObtain in loop\n");
|
||||
}
|
||||
|
||||
status = PrivMutexAbandon(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_unlock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Register the adapter to the linked list
|
||||
* @param adapter - adapter device pointer
|
||||
* @return success: 0 , failure: -1
|
||||
*/
|
||||
int AdapterDeviceRegister(struct Adapter *adapter)
|
||||
{
|
||||
int status = 0;
|
||||
if (NULL == adapter )
|
||||
return -1;
|
||||
|
||||
if (NULL != AdapterDeviceFindByName(adapter->name)) {
|
||||
printf("%s: sensor with the same name already registered\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = PrivMutexObtain(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_lock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
AppDoubleListInsertNodeAfter(&adapter_list, &adapter->link);
|
||||
|
||||
status = PrivMutexAbandon(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_unlock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
adapter->adapter_status = REGISTERED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Unregister the adapter from the linked list
|
||||
* @param adapter - adapter device pointer
|
||||
* @return 0
|
||||
*/
|
||||
int AdapterDeviceUnregister(struct Adapter *adapter)
|
||||
{
|
||||
int status = 0;
|
||||
if (!adapter)
|
||||
return -1;
|
||||
status = PrivMutexObtain(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_lock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
AppDoubleListRmNode(&adapter->link);
|
||||
|
||||
status = PrivMutexAbandon(&adapter_list_lock);
|
||||
if (status != 0){
|
||||
printf("%s:pthread_mutex_unlock failed, status=%d\n",__func__,status);
|
||||
}
|
||||
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open adapter device
|
||||
* @param name - adapter device name
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceOpen(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (INSTALL == adapter->adapter_status) {
|
||||
printf("Device %s has already been opened. Just return\n", adapter->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->open)
|
||||
return 0;
|
||||
|
||||
result = priv_done->open(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s open success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s open failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->open)
|
||||
return 0;
|
||||
|
||||
result = ip_done->open(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s open success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s open failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close adapter device
|
||||
* @param adapter - adapter device pointer
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceClose(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (UNINSTALL == adapter->adapter_status) {
|
||||
printf("Device %s has already been closed. Just return\n", adapter->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->close)
|
||||
return 0;
|
||||
|
||||
result = priv_done->close(adapter);
|
||||
if (0 == result) {
|
||||
printf("%s successfully closed.\n", adapter->name);
|
||||
adapter->adapter_status = UNINSTALL;
|
||||
} else {
|
||||
printf("Closed %s failure.\n", adapter->name);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->close)
|
||||
return 0;
|
||||
|
||||
result = ip_done->close(adapter);
|
||||
if (0 == result) {
|
||||
printf("%s successfully closed.\n", adapter->name);
|
||||
adapter->adapter_status = UNINSTALL;
|
||||
} else {
|
||||
printf("Closed %s failure.\n", adapter->name);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Configure adapter device
|
||||
* @param adapter - adapter device pointer
|
||||
* @param cmd - command
|
||||
* @param args - command parameter
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceControl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->ioctl)
|
||||
return 0;
|
||||
|
||||
result = priv_done->ioctl(adapter, cmd, args);
|
||||
if (0 == result) {
|
||||
printf("Device %s ioctl success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s ioctl failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->ioctl)
|
||||
return 0;
|
||||
|
||||
result = ip_done->ioctl(adapter, cmd, args);
|
||||
if (0 == result) {
|
||||
printf("Device %s ioctl success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s ioctl failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Receice data from adapter
|
||||
* @param adapter - adapter device pointer
|
||||
* @param dst - buffer to save data
|
||||
* @param len - buffer length
|
||||
* @return gotten data length
|
||||
*/
|
||||
ssize_t AdapterDeviceRecv(struct Adapter *adapter, void *dst, size_t len)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
|
||||
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == priv_done->recv)
|
||||
return -1;
|
||||
|
||||
return priv_done->recv(adapter, dst, len);
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == ip_done->recv)
|
||||
return -1;
|
||||
|
||||
return ip_done->recv(adapter, dst, len);
|
||||
} else {
|
||||
printf("AdapterDeviceRecv net_protocol %d not support\n", adapter->net_protocol);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Send data to adapter
|
||||
* @param adapter - adapter device pointer
|
||||
* @param src - data buffer
|
||||
* @param len - data length
|
||||
* @return length of data written
|
||||
*/
|
||||
ssize_t AdapterDeviceSend(struct Adapter *adapter, const void *src, size_t len)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
|
||||
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == priv_done->send)
|
||||
return -1;
|
||||
|
||||
return priv_done->send(adapter, src, len);
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == ip_done->send)
|
||||
return -1;
|
||||
|
||||
return ip_done->send(adapter, src, len);
|
||||
} else {
|
||||
printf("AdapterDeviceSend net_protocol %d not support\n", adapter->net_protocol);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Connect to a certain ip net, only support IP_PROTOCOL
|
||||
* @param adapter - adapter device pointer
|
||||
* @param ip - connect ip
|
||||
* @param port - connect port
|
||||
* @param ip_type - ip type, IPV4 or IPV6
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
|
||||
printf("AdapterDeviceConnect not suuport private_protocol, please use join\n");
|
||||
return -1;
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == ip_done->connect)
|
||||
return -1;
|
||||
|
||||
return ip_done->connect(adapter, net_role, ip, port, ip_type);
|
||||
} else {
|
||||
printf("AdapterDeviceConnect net_protocol %d not support\n", adapter->net_protocol);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Join to a certain private net, only support PRIVATE_PROTOCOL
|
||||
* @param adapter - adapter device pointer
|
||||
* @param priv_net_group - private net group
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
|
||||
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == priv_done->join)
|
||||
return -1;
|
||||
|
||||
return priv_done->join(adapter, priv_net_group);
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
printf("AdapterDeviceJoin not support ip_protocol, please use connect\n");
|
||||
return -1;
|
||||
} else {
|
||||
printf("AdapterDeviceJoin net_protocol %d not support\n", adapter->net_protocol);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Adapter disconnect from ip net or private net group
|
||||
* @param adapter - adapter device pointer
|
||||
* @param priv_net_group - private net group for PRIVATE_PROTOCOL quit function
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
if (PRIVATE_PROTOCOL == adapter->net_protocol) {
|
||||
struct PrivProtocolDone *priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == priv_done->quit)
|
||||
return -1;
|
||||
|
||||
return priv_done->quit(adapter, priv_net_group);
|
||||
} else if (IP_PROTOCOL == adapter->net_protocol) {
|
||||
struct IpProtocolDone *ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
|
||||
if (NULL == ip_done->disconnect)
|
||||
return -1;
|
||||
|
||||
return ip_done->disconnect(adapter);
|
||||
} else {
|
||||
printf("AdapterDeviceDisconnect net_protocol %d not support\n", adapter->net_protocol);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set up to net
|
||||
* @param adapter - adapter device pointer
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceSetUp(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->setup)
|
||||
return 0;
|
||||
|
||||
result = priv_done->setup(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s setup success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setup failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->setup)
|
||||
return 0;
|
||||
|
||||
result = ip_done->setup(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s setup success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setup failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set down from net
|
||||
* @param adapter - adapter device pointer
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceSetDown(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->setdown)
|
||||
return 0;
|
||||
|
||||
result = priv_done->setdown(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdown success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdown failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->setdown)
|
||||
return 0;
|
||||
|
||||
result = ip_done->setdown(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdown success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdown failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set ip/gateway/netmask address
|
||||
* @param adapter - adapter device pointer
|
||||
* @param ip - ip address
|
||||
* @param gateway - gateway address
|
||||
* @param netmast - netmast address
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->setaddr)
|
||||
return 0;
|
||||
|
||||
result = priv_done->setaddr(adapter, ip, gateway, netmask);
|
||||
if (0 == result) {
|
||||
printf("Device %s setaddr success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setaddr failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->setaddr)
|
||||
return 0;
|
||||
|
||||
result = ip_done->setaddr(adapter, ip, gateway, netmask);
|
||||
if (0 == result) {
|
||||
printf("Device %s setaddr success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setaddr failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set dns function
|
||||
* @param adapter - adapter device pointer
|
||||
* @param dns_addr - dns address
|
||||
* @param dns_count - dns count
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceSetDns(struct Adapter *adapter, const char *dns_addr, uint8 dns_count)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->setdns)
|
||||
return 0;
|
||||
|
||||
result = priv_done->setdns(adapter, dns_addr, dns_count);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdns success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdns failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->setdns)
|
||||
return 0;
|
||||
|
||||
result = ip_done->setdns(adapter, dns_addr, dns_count);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdns success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdns failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set DHCP function
|
||||
* @param adapter - adapter device pointer
|
||||
* @param enable - enable DHCP or not
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceSetDhcp(struct Adapter *adapter, int enable)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->setdhcp)
|
||||
return 0;
|
||||
|
||||
result = priv_done->setdhcp(adapter, enable);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdhcp success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdhcp failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->setdhcp)
|
||||
return 0;
|
||||
|
||||
result = ip_done->setdhcp(adapter, enable);
|
||||
if (0 == result) {
|
||||
printf("Device %s setdhcp success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s setdhcp failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ping function
|
||||
* @param adapter - adapter device pointer
|
||||
* @param destination - the destination ip address
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDevicePing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->ping)
|
||||
return 0;
|
||||
|
||||
result = priv_done->ping(adapter, destination);
|
||||
if (0 == result) {
|
||||
printf("Device %s ping success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s ping failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->ping)
|
||||
return 0;
|
||||
|
||||
result = ip_done->ping(adapter, destination);
|
||||
if (0 == result) {
|
||||
printf("Device %s ping success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s ping failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Show the net status
|
||||
* @param adapter - adapter device pointer
|
||||
* @return success: 0 , failure: other
|
||||
*/
|
||||
int AdapterDeviceNetstat(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
|
||||
struct IpProtocolDone *ip_done = NULL;
|
||||
struct PrivProtocolDone *priv_done = NULL;
|
||||
|
||||
switch (adapter->net_protocol)
|
||||
{
|
||||
case PRIVATE_PROTOCOL:
|
||||
priv_done = (struct PrivProtocolDone *)adapter->done;
|
||||
if (NULL == priv_done->netstat)
|
||||
return 0;
|
||||
|
||||
result = priv_done->netstat(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s netstat success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s netstat failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
case IP_PROTOCOL:
|
||||
ip_done = (struct IpProtocolDone *)adapter->done;
|
||||
if (NULL == ip_done->netstat)
|
||||
return 0;
|
||||
|
||||
result = ip_done->netstat(adapter);
|
||||
if (0 == result) {
|
||||
printf("Device %s netstat success.\n", adapter->name);
|
||||
adapter->adapter_status = INSTALL;
|
||||
} else {
|
||||
if (adapter->fd) {
|
||||
PrivClose(adapter->fd);
|
||||
adapter->fd = 0;
|
||||
}
|
||||
printf("Device %s netstat failed(%d).\n", adapter->name, result);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* 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 adapter.h
|
||||
* @brief Structure and function declarations of the connection adapter framework
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.05.10
|
||||
*/
|
||||
|
||||
#ifndef ADAPTER_H
|
||||
#define ADAPTER_H
|
||||
|
||||
#include <list.h>
|
||||
#include <transform.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ADAPTER_BUFFSIZE 64
|
||||
|
||||
#define ADAPTER_AT_OPERATION 1
|
||||
#define ADAPTER_LWIP_OPERATION 2
|
||||
#define ADAPTER_RAWIP_OPERATION 3
|
||||
|
||||
#ifdef CONNECTION_FRAMEWORK_DEBUG
|
||||
#define ADAPTER_DEBUG printf
|
||||
#else
|
||||
#define ADAPTER_DEBUG
|
||||
#endif
|
||||
|
||||
#define ADAPTER_4G_NAME "4G"
|
||||
#define ADAPTER_BLUETOOTH_NAME "bluetooth"
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet"
|
||||
#define ADAPTER_ETHERCAT_NAME "ethercat"
|
||||
#define ADAPTER_LORA_NAME "lora"
|
||||
#define ADAPTER_NBIOT_NAME "nbiot"
|
||||
#define ADAPTER_WIFI_NAME "wifi"
|
||||
#define ADAPTER_ZIGBEE_NAME "zigbee"
|
||||
|
||||
struct Adapter;
|
||||
struct AdapterProductInfo;
|
||||
typedef struct Adapter *AdapterType;
|
||||
typedef struct AdapterProductInfo *AdapterProductInfoType;
|
||||
|
||||
struct Socket
|
||||
{
|
||||
uint8_t type; ///< socket type:DGRAM->UDP,STREAM->TCP
|
||||
uint8_t protocal; ///< udp or tcp
|
||||
unsigned short listen_port; ///< 0-65535
|
||||
uint8_t socket_id; ///< socket id
|
||||
uint8_t recv_control; ///< receive control
|
||||
uint8_t af_type; ///< IPv4 or IPv6
|
||||
char *src_ip_addr; ///< source P address
|
||||
char *dst_ip_addr; ///< destination IP address
|
||||
};
|
||||
|
||||
enum AdapterType
|
||||
{
|
||||
ADAPTER_TYPE_LORA = 0,
|
||||
ADAPTER_TYPE_4G ,
|
||||
ADAPTER_TYPE_NBIOT ,
|
||||
ADAPTER_TYPE_WIFI ,
|
||||
ADAPTER_TYPE_ETHERNET ,
|
||||
ADAPTER_TYPE_BLUETOOTH ,
|
||||
ADAPTER_TYPE_ZIGBEE ,
|
||||
ADAPTER_TYPE_5G ,
|
||||
};
|
||||
|
||||
enum NetProtocolType
|
||||
{
|
||||
PRIVATE_PROTOCOL = 1,
|
||||
IP_PROTOCOL,
|
||||
PROTOCOL_NONE,
|
||||
};
|
||||
|
||||
enum NetRoleType
|
||||
{
|
||||
CLIENT = 1,
|
||||
SERVER,
|
||||
MASTER,
|
||||
SLAVE,
|
||||
COORDINATOR,
|
||||
ROUTER,
|
||||
END_DEVICE,
|
||||
GATEWAY,
|
||||
ROLE_NONE,
|
||||
};
|
||||
|
||||
enum AdapterStatus
|
||||
{
|
||||
REGISTERED = 1,
|
||||
UNREGISTERED,
|
||||
INSTALL,
|
||||
UNINSTALL,
|
||||
};
|
||||
|
||||
enum IpType
|
||||
{
|
||||
IPV4 = 1,
|
||||
IPV6,
|
||||
};
|
||||
|
||||
struct AdapterData
|
||||
{
|
||||
uint32 len;
|
||||
uint8 *buffer;
|
||||
};
|
||||
|
||||
struct AdapterProductInfo
|
||||
{
|
||||
uint32_t functions;
|
||||
char vendor_name[NAME_NUM_MAX];
|
||||
char model_name[NAME_NUM_MAX];
|
||||
uint32_t work_mode;
|
||||
|
||||
void *model_done;
|
||||
};
|
||||
|
||||
struct IpProtocolDone
|
||||
{
|
||||
int (*open)(struct Adapter *adapter);
|
||||
int (*close)(struct Adapter *adapter);
|
||||
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
|
||||
int (*setup)(struct Adapter *adapter);
|
||||
int (*setdown)(struct Adapter *adapter);
|
||||
int (*setaddr)(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
|
||||
int (*setdns)(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
|
||||
int (*setdhcp)(struct Adapter *adapter, int enable);
|
||||
int (*ping)(struct Adapter *adapter, const char *destination);
|
||||
int (*netstat)(struct Adapter *adapter);
|
||||
int (*connect)(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type);
|
||||
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
|
||||
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
|
||||
int (*disconnect)(struct Adapter *adapter);
|
||||
};
|
||||
|
||||
struct PrivProtocolDone
|
||||
{
|
||||
int (*open)(struct Adapter *adapter);
|
||||
int (*close)(struct Adapter *adapter);
|
||||
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
|
||||
int (*setup)(struct Adapter *adapter);
|
||||
int (*setdown)(struct Adapter *adapter);
|
||||
int (*setaddr)(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
|
||||
int (*setdns)(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
|
||||
int (*setdhcp)(struct Adapter *adapter, int enable);
|
||||
int (*ping)(struct Adapter *adapter, const char *destination);
|
||||
int (*netstat)(struct Adapter *adapter);
|
||||
int (*join)(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
|
||||
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
|
||||
int (*quit)(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
};
|
||||
|
||||
struct Adapter
|
||||
{
|
||||
char name[NAME_NUM_MAX];
|
||||
int fd;
|
||||
|
||||
int product_info_flag;
|
||||
struct AdapterProductInfo *info;
|
||||
ATAgentType agent;
|
||||
|
||||
struct Socket socket;
|
||||
|
||||
int net_role_id;
|
||||
enum NetProtocolType net_protocol;
|
||||
enum NetRoleType net_role;
|
||||
enum AdapterStatus adapter_status;
|
||||
|
||||
char buffer[ADAPTER_BUFFSIZE];
|
||||
|
||||
void *done;
|
||||
void *adapter_param;
|
||||
|
||||
struct DoublelistNode link;
|
||||
};
|
||||
|
||||
/*Init adapter framework*/
|
||||
int AdapterFrameworkInit(void);
|
||||
|
||||
/*Find adapter device by name*/
|
||||
AdapterType AdapterDeviceFindByName(const char *name);
|
||||
|
||||
/*Register the adapter to the linked list*/
|
||||
int AdapterDeviceRegister(struct Adapter *adapter);
|
||||
|
||||
/*Unregister the adapter from the linked list*/
|
||||
int AdapterDeviceUnregister(struct Adapter *adapter);
|
||||
|
||||
/*Open adapter device*/
|
||||
int AdapterDeviceOpen(struct Adapter *adapter);
|
||||
|
||||
/*Close adapter device*/
|
||||
int AdapterDeviceClose(struct Adapter *adapter);
|
||||
|
||||
/*Receice data from adapter*/
|
||||
ssize_t AdapterDeviceRecv(struct Adapter *adapter, void *dst, size_t len);
|
||||
|
||||
/*Send data to adapter*/
|
||||
ssize_t AdapterDeviceSend(struct Adapter *adapter, const void *src, size_t len);
|
||||
|
||||
/*Configure adapter device*/
|
||||
int AdapterDeviceControl(struct Adapter *adapter, int cmd, void *args);
|
||||
|
||||
/*Connect to a certain ip net, only support IP_PROTOCOL*/
|
||||
int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type);
|
||||
|
||||
/*Join to a certain private net, only support PRIVATE_PROTOCOL*/
|
||||
int AdapterDeviceJoin(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
|
||||
/*Adapter disconnect from ip net or private net group*/
|
||||
int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_group);
|
||||
|
||||
/*Set up to net*/
|
||||
int AdapterDeviceSetUp(struct Adapter *adapter);
|
||||
|
||||
/*Set down from net*/
|
||||
int AdapterDeviceSetDown(struct Adapter *adapter);
|
||||
|
||||
/*Set ip/gateway/netmask address*/
|
||||
int AdapterDeviceSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
|
||||
|
||||
/*Set DNS function*/
|
||||
int AdapterDeviceSetDns(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
|
||||
|
||||
/*Set DHCP function*/
|
||||
int AdapterDeviceSetDhcp(struct Adapter *adapter, int enable);
|
||||
|
||||
/*ping function*/
|
||||
int AdapterDevicePing(struct Adapter *adapter, const char *destination);
|
||||
|
||||
/*Show the net status*/
|
||||
int AdapterDeviceNetstat(struct Adapter *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,624 @@
|
|||
/*
|
||||
* 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 xs_adapterAT_client.c
|
||||
* @brief AT proxy, auto receive AT reply and transparency data
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
|
||||
#include <at_agent.h>
|
||||
#include <adapter.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#define AT_CMD_MAX_LEN 128
|
||||
#define AT_AGENT_MAX 2
|
||||
static char send_buf[AT_CMD_MAX_LEN];
|
||||
static uint32_t last_cmd_len = 0;
|
||||
|
||||
static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0};
|
||||
|
||||
unsigned int IpTint(char *ipstr)
|
||||
{
|
||||
if (ipstr == NULL)
|
||||
return 0;
|
||||
|
||||
char *token;
|
||||
unsigned int i = 3, total = 0, cur;
|
||||
|
||||
token = strtok(ipstr, ".");
|
||||
|
||||
while (token != NULL) {
|
||||
cur = atoi(token);
|
||||
if (cur >= 0 && cur <= 255) {
|
||||
total += cur * pow(256, i);
|
||||
}
|
||||
i--;
|
||||
token = strtok(NULL, ".");
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
void SwapStr(char *str, int begin, int end)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = begin, j = end; i <= j; i++, j--) {
|
||||
if (str[i] != str[j]) {
|
||||
str[i] = str[i] ^ str[j];
|
||||
str[j] = str[i] ^ str[j];
|
||||
str[i] = str[i] ^ str[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *IpTstr(unsigned int ipint)
|
||||
{
|
||||
int LEN = 16;
|
||||
char *new = (char *)PrivMalloc(LEN);
|
||||
memset(new, '\0', LEN);
|
||||
new[0] = '.';
|
||||
char token[4];
|
||||
int bt, ed, len, cur;
|
||||
|
||||
while (ipint) {
|
||||
cur = ipint % 256;
|
||||
sprintf(token, "%d", cur);
|
||||
strcat(new, token);
|
||||
ipint /= 256;
|
||||
if (ipint)
|
||||
strcat(new, ".");
|
||||
}
|
||||
|
||||
len = strlen(new);
|
||||
SwapStr(new, 0, len - 1);
|
||||
|
||||
for (bt = ed = 0; ed < len;) {
|
||||
while (ed < len && new[ed] != '.') {
|
||||
ed++;
|
||||
}
|
||||
SwapStr(new, bt, ed - 1);
|
||||
ed += 1;
|
||||
bt = ed;
|
||||
}
|
||||
|
||||
new[len - 1] = '\0';
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
int ParseATReply(char *str, const char *format, ...)
|
||||
{
|
||||
va_list params;
|
||||
int counts = 0;
|
||||
|
||||
va_start(params, format);
|
||||
counts = vsscanf(str, format, params);
|
||||
va_end(params);
|
||||
|
||||
return counts;
|
||||
}
|
||||
|
||||
void ATSprintf(int fd, const char *format, va_list params)
|
||||
{
|
||||
last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params);
|
||||
printf("AT send %s len %u\n",send_buf, last_cmd_len);
|
||||
PrivWrite(fd, send_buf, last_cmd_len);
|
||||
}
|
||||
|
||||
int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...)
|
||||
{
|
||||
if (agent == NULL) {
|
||||
printf("ATAgent is null");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct timespec abstime;
|
||||
|
||||
abstime.tv_sec = timeout_s;
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
agent->receive_mode = AT_MODE;
|
||||
|
||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||
agent->maintain_len = 0;
|
||||
|
||||
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
|
||||
agent->entm_recv_len = 0;
|
||||
|
||||
va_list params;
|
||||
uint32_t cmd_size = 0;
|
||||
uint32_t result = 0;
|
||||
const char *cmd = NULL;
|
||||
|
||||
agent->reply = reply;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
|
||||
if(agent->reply != NULL) {
|
||||
PrivMutexObtain(&agent->lock);
|
||||
reply->reply_len = 0;
|
||||
va_start(params, cmd_expr);
|
||||
ATSprintf(agent->fd, cmd_expr, params);
|
||||
va_end(params);
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != 0) {
|
||||
printf("take sem %d timeout\n",agent->rsp_sem);
|
||||
result = -2;
|
||||
goto __out;
|
||||
}
|
||||
} else {
|
||||
PrivMutexObtain(&agent->lock);
|
||||
va_start(params, cmd_expr);
|
||||
ATSprintf(agent->fd, cmd_expr, params);
|
||||
va_end(params);
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
goto __out;
|
||||
}
|
||||
|
||||
__out:
|
||||
// agent->reply = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check)
|
||||
{
|
||||
int ret = 0;
|
||||
char *result = NULL;
|
||||
if (NULL == agent || NULL == cmd || NULL == check ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ATReplyType reply = CreateATReply(256);
|
||||
if (NULL == reply) {
|
||||
printf("%s %d at_create_resp failed!\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd);
|
||||
if(ret < 0){
|
||||
printf("%s %d ATOrderSend failed.\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
//PrivTaskDelay(3000);
|
||||
|
||||
result = GetReplyText(reply);
|
||||
if (!result) {
|
||||
printf("%s %n get reply failed.\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
printf("[reply result :\n");
|
||||
printf("%s]\n", result);
|
||||
if(!strstr(result, check)) {
|
||||
printf("%s %d check[%s] reply[%s] failed.\n",__func__,__LINE__,check,result);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
__exit:
|
||||
DeleteATReply(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *GetReplyText(ATReplyType reply)
|
||||
{
|
||||
return reply->reply_buffer;
|
||||
}
|
||||
|
||||
int AtSetReplyLrEnd(ATAgentType agent, char enable)
|
||||
{
|
||||
if (!agent) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_lr_end = enable;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch)
|
||||
{
|
||||
if (!agent) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_end_last_char = last_ch;
|
||||
agent->reply_end_char = end_ch;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AtSetReplyCharNum(ATAgentType agent, unsigned int num)
|
||||
{
|
||||
if (!agent) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
agent->reply_char_num = num;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntmSend(ATAgentType agent, const char *data, int len)
|
||||
{
|
||||
char send_buf[128];
|
||||
if(len > 128){
|
||||
printf("send length %d more then max 128 Bytes.\n",len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
memset(send_buf, 0, 128);
|
||||
|
||||
agent->receive_mode = ENTM_MODE;
|
||||
|
||||
memcpy(send_buf, data, len);
|
||||
// memcpy(send_buf + len, "!@", 2);
|
||||
|
||||
PrivWrite(agent->fd, send_buf, len);
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
printf("entm send %s length %d\n",send_buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||
{
|
||||
struct timespec abstime;
|
||||
|
||||
abstime.tv_sec = timeout_s;
|
||||
if(buffer_len > ENTM_RECV_MAX){
|
||||
printf("read length more then max length[%d] Bytes",ENTM_RECV_MAX);
|
||||
return -1;
|
||||
}
|
||||
PrivMutexObtain(&agent->lock);
|
||||
agent->receive_mode = ENTM_MODE;
|
||||
agent->read_len = buffer_len;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
//PrivTaskDelay(1000);
|
||||
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
|
||||
printf("wait sem[%d] timeout\n",agent->entm_rx_notice);
|
||||
return -ERROR;
|
||||
}
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
||||
|
||||
printf("EntmRecv once len %d.\n", agent->entm_recv_len);
|
||||
|
||||
memcpy(rev_buffer, agent->entm_recv_buf, agent->entm_recv_len);
|
||||
|
||||
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
|
||||
agent->entm_recv_len = 0;
|
||||
agent->read_len = 0;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
|
||||
return buffer_len;
|
||||
}
|
||||
|
||||
static int GetCompleteATReply(ATAgentType agent)
|
||||
{
|
||||
uint32_t read_len = 0;
|
||||
char ch = 0, last_ch = 0;
|
||||
bool is_full = false;
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||
agent->maintain_len = 0;
|
||||
|
||||
memset(agent->entm_recv_buf, 0x00, 256);
|
||||
agent->entm_recv_len = 0;
|
||||
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
|
||||
while (1)
|
||||
{
|
||||
PrivRead(agent->fd, &ch, 1);
|
||||
#ifdef CONNECTION_FRAMEWORK_DEBUG
|
||||
if(ch != 0){
|
||||
printf(" %c (0x%x)\n", ch, ch);
|
||||
}
|
||||
#endif
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
if (agent->receive_mode == ENTM_MODE)
|
||||
{
|
||||
if (agent->entm_recv_len < ENTM_RECV_MAX)
|
||||
{
|
||||
agent->entm_recv_buf[agent->entm_recv_len] = ch;
|
||||
agent->entm_recv_len++;
|
||||
|
||||
if(agent->entm_recv_len < agent->read_len){
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ENTM_MODE recv %d Bytes done.\n",agent->entm_recv_len);
|
||||
agent->receive_mode = DEFAULT_MODE;
|
||||
PrivSemaphoreAbandon(&agent->entm_rx_notice);
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("entm_recv_buf is_full ...\n");
|
||||
}
|
||||
}
|
||||
else if (agent->receive_mode == AT_MODE)
|
||||
{
|
||||
if (read_len < agent->maintain_max)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if (((ch == '\n') && (last_ch == '\r') && (agent->reply_lr_end)) ||
|
||||
((ch == agent->reply_end_char) && (agent->reply_end_char) &&
|
||||
(last_ch == agent->reply_end_last_char) && (agent->reply_end_last_char)) ||
|
||||
((read_len == agent->reply_char_num) && (agent->reply_char_num))){
|
||||
if (is_full) {
|
||||
printf("read line failed. The line data length is out of buffer size(%d)!", agent->maintain_max);
|
||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||
agent->maintain_len = 0;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
return -ERROR;
|
||||
}
|
||||
|
||||
printf("GetCompleteATReply done\n");
|
||||
agent->receive_mode = DEFAULT_MODE;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
break;
|
||||
}
|
||||
last_ch = ch;
|
||||
}
|
||||
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
}
|
||||
|
||||
return read_len;
|
||||
}
|
||||
|
||||
ATAgentType GetATAgent(const char *agent_name)
|
||||
{
|
||||
struct ATAgent* result = NULL;
|
||||
for (int i = 0; i < AT_AGENT_MAX; i++) {
|
||||
if (strcmp(at_agent_table[i].agent_name, agent_name) == 0) {
|
||||
result = &at_agent_table[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int DeleteATAgent(ATAgentType agent)
|
||||
{
|
||||
printf("delete agent->at_handler = %d\n",agent->at_handler);
|
||||
if(agent->at_handler > 0){
|
||||
PrivTaskDelete(agent->at_handler, 0);
|
||||
}
|
||||
|
||||
if (agent->fd > 0) {
|
||||
printf("close agent fd = %d\n",agent->fd);
|
||||
PrivClose(agent->fd);
|
||||
}
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
if (agent->lock.sem.semcount > 0) {
|
||||
printf("delete agent lock = %d\n",agent->lock.sem.semcount);
|
||||
PrivMutexDelete(&agent->lock);
|
||||
}
|
||||
#else
|
||||
if (agent->lock) {
|
||||
printf("delete agent lock = %d\n",agent->lock);
|
||||
PrivMutexDelete(&agent->lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (agent->entm_rx_notice) {
|
||||
printf("delete agent entm_rx_notice = %d\n",agent->entm_rx_notice);
|
||||
PrivSemaphoreDelete(&agent->entm_rx_notice);
|
||||
}
|
||||
|
||||
if (agent->rsp_sem) {
|
||||
printf("delete agent rsp_sem = %d\n",agent->rsp_sem);
|
||||
PrivSemaphoreDelete(&agent->rsp_sem);
|
||||
}
|
||||
|
||||
if (agent->maintain_buffer) {
|
||||
PrivFree(agent->maintain_buffer);
|
||||
}
|
||||
|
||||
memset(agent, 0x00, sizeof(struct ATAgent));
|
||||
printf("delete ATagent\n");
|
||||
}
|
||||
|
||||
static void *ATAgentReceiveProcess(void *param)
|
||||
{
|
||||
ATAgentType agent = (ATAgentType)param;
|
||||
const struct at_urc *urc;
|
||||
|
||||
while (1) {
|
||||
if (GetCompleteATReply(agent) > 0)
|
||||
{
|
||||
PrivMutexObtain(&agent->lock);
|
||||
if (agent->reply != NULL){
|
||||
ATReplyType reply = agent->reply;
|
||||
|
||||
agent->maintain_buffer[agent->maintain_len] = '\0';
|
||||
if (agent->maintain_len <= reply->reply_max_len) {
|
||||
memset(reply->reply_buffer, 0 , reply->reply_max_len);
|
||||
memcpy(reply->reply_buffer, agent->maintain_buffer, agent->maintain_len);
|
||||
reply->reply_len = agent->maintain_len;
|
||||
} else {
|
||||
printf("out of memory (%d)!\n", reply->reply_max_len);
|
||||
}
|
||||
|
||||
// agent->reply = NULL;
|
||||
PrivSemaphoreAbandon(&agent->rsp_sem);
|
||||
}
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int ATAgentInit(ATAgentType agent)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
agent->maintain_len = 0;
|
||||
agent->maintain_buffer = (char *)PrivMalloc(agent->maintain_max);
|
||||
|
||||
if (agent->maintain_buffer == NULL) {
|
||||
printf("ATAgentInit malloc maintain_buffer error\n");
|
||||
goto __out;
|
||||
}
|
||||
|
||||
memset(agent->maintain_buffer, 0, agent->maintain_max);
|
||||
|
||||
result = PrivSemaphoreCreate(&agent->entm_rx_notice, 0, 0);
|
||||
if (result < 0) {
|
||||
printf("ATAgentInit create entm sem error\n");
|
||||
goto __out;
|
||||
}
|
||||
printf("create entm_rx_notice_sem %d\n ",agent->entm_rx_notice);
|
||||
result = PrivSemaphoreCreate(&agent->rsp_sem, 0, 0);
|
||||
if (result < 0) {
|
||||
printf("ATAgentInit create rsp sem error\n");
|
||||
goto __out;
|
||||
}
|
||||
printf("create rsp_sem %d\n ",agent->rsp_sem);
|
||||
if(PrivMutexCreate(&agent->lock, 0) < 0) {
|
||||
printf("AdapterFrameworkInit mutex create failed.\n");
|
||||
goto __out;
|
||||
}
|
||||
|
||||
agent->receive_mode = DEFAULT_MODE;
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = 18;
|
||||
attr.stacksize = 4096;
|
||||
|
||||
#else
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = 25;
|
||||
attr.stacksize = 4096;
|
||||
#endif
|
||||
|
||||
PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent);
|
||||
printf("create agent->at_handler = %d\n",agent->at_handler);
|
||||
return result;
|
||||
|
||||
__out:
|
||||
DeleteATAgent(agent);
|
||||
result = -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
|
||||
{
|
||||
int i = 0;
|
||||
int result = 0;
|
||||
int open_result = 0;
|
||||
struct ATAgent *agent = NULL;
|
||||
|
||||
if (GetATAgent(agent_name) != NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
while (i < AT_AGENT_MAX && at_agent_table[i].fd > 0) {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i >= AT_AGENT_MAX) {
|
||||
printf("agent buffer(%d) is full.", AT_AGENT_MAX);
|
||||
result = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
agent = &at_agent_table[i];
|
||||
|
||||
agent->fd = agent_fd;
|
||||
|
||||
strcpy(agent->agent_name, agent_name);
|
||||
|
||||
agent->maintain_max = maintain_max;
|
||||
|
||||
result = ATAgentInit(agent);
|
||||
if (result == 0) {
|
||||
PrivTaskStartup(&agent->at_handler);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ATReplyType CreateATReply(uint32 reply_max_len)
|
||||
{
|
||||
ATReplyType reply = NULL;
|
||||
|
||||
reply = (ATReplyType)PrivMalloc(sizeof(struct ATReply));
|
||||
if (reply == NULL) {
|
||||
printf("no more memory\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(reply, 0, sizeof(struct ATReply));
|
||||
|
||||
reply->reply_max_len = reply_max_len;
|
||||
|
||||
reply->reply_buffer = (char *)PrivMalloc(reply_max_len);
|
||||
if (reply->reply_buffer == NULL) {
|
||||
printf("no more memory\n");
|
||||
PrivFree(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(reply->reply_buffer, 0, reply_max_len);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
void DeleteATReply(ATReplyType reply)
|
||||
{
|
||||
if (reply) {
|
||||
if (reply->reply_buffer) {
|
||||
PrivFree(reply->reply_buffer);
|
||||
reply->reply_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (reply) {
|
||||
PrivFree(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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 xs_adapter_at_agent.h
|
||||
* @brief AT proxy, auto receive AT reply and transparency data
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
#ifndef XS_ADAPTER_AT_CLIENT_H
|
||||
#define XS_ADAPTER_AT_CLIENT_H
|
||||
|
||||
#include <list.h>
|
||||
#include <transform.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define REPLY_TIME_OUT 10
|
||||
|
||||
enum ReceiveMode
|
||||
{
|
||||
DEFAULT_MODE = 0,
|
||||
ENTM_MODE = 1,
|
||||
AT_MODE = 2,
|
||||
};
|
||||
|
||||
struct ATReply
|
||||
{
|
||||
char *reply_buffer;
|
||||
uint32 reply_max_len;
|
||||
uint32 reply_len;
|
||||
};
|
||||
typedef struct ATReply *ATReplyType;
|
||||
|
||||
struct ATAgent
|
||||
{
|
||||
char agent_name[64];
|
||||
int fd;
|
||||
int read_len; ///< control data length of wanting reading
|
||||
|
||||
char *maintain_buffer;
|
||||
uint32 maintain_len;
|
||||
uint32 maintain_max;
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
pthread_mutex_t lock;
|
||||
#else
|
||||
int lock;
|
||||
#endif
|
||||
|
||||
ATReplyType reply;
|
||||
char reply_lr_end;
|
||||
char reply_end_last_char;
|
||||
char reply_end_char;
|
||||
uint32 reply_char_num;
|
||||
int rsp_sem;
|
||||
|
||||
pthread_t at_handler;
|
||||
|
||||
#define ENTM_RECV_MAX 256
|
||||
char entm_recv_buf[ENTM_RECV_MAX];
|
||||
uint32 entm_recv_len;
|
||||
enum ReceiveMode receive_mode;
|
||||
int entm_rx_notice;
|
||||
};
|
||||
typedef struct ATAgent *ATAgentType;
|
||||
|
||||
int EntmSend(ATAgentType agent, const char *data, int len);
|
||||
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s);
|
||||
char *GetReplyText(ATReplyType reply);
|
||||
int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch);
|
||||
int AtSetReplyCharNum(ATAgentType agent, unsigned int num);
|
||||
int AtSetReplyLrEnd(ATAgentType agent, char enable);
|
||||
ATReplyType CreateATReply(uint32 reply_max_len);
|
||||
unsigned int IpTint(char *ipstr);
|
||||
void SwapStr(char *str, int begin, int end);
|
||||
char* IpTstr(unsigned int ipint);
|
||||
ATAgentType GetATAgent(const char *agent_name);
|
||||
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_t timeout_s, ATReplyType reply, const char *cmd_expr, ...);
|
||||
int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
config ADAPTER_HC08
|
||||
bool "Using bluetooth adapter device HC08"
|
||||
default y
|
||||
|
||||
if ADAPTER_HC08
|
||||
source "$APP_DIR/Framework/connection/bluetooth/hc08/Kconfig"
|
||||
endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES := adapter_bluetooth.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_HC08),y)
|
||||
SRC_DIR += hc08
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* 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 adapter_bluetooth.c
|
||||
* @brief Implement the connection bluetooth adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
extern AdapterProductInfoType Hc08Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
static int AdapterBlueToothRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_BLUETOOTH_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterBlueToothRegister register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterBlueToothInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterBlueToothRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterBlueToothInit register BT adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
AdapterProductInfoType product_info = Hc08Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterBlueToothInit hc08 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;
|
||||
}
|
||||
|
||||
/******************4G TEST*********************/
|
||||
int AdapterBlueToothTest(void)
|
||||
{
|
||||
const char *bluetooth_msg = "BT Adapter Test";
|
||||
char bluetooth_recv_msg[128];
|
||||
int len;
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME);
|
||||
|
||||
#ifdef ADAPTER_HC08
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
len = strlen(bluetooth_msg);
|
||||
|
||||
while (1) {
|
||||
AdapterDeviceRecv(adapter, bluetooth_recv_msg, 128);
|
||||
printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg);
|
||||
AdapterDeviceSend(adapter, bluetooth_msg, len);
|
||||
printf("send %s after recv\n", bluetooth_msg);
|
||||
PrivTaskDelay(100);
|
||||
memset(bluetooth_recv_msg, 0, 128);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterBlueToothTest, AdapterBlueToothTest, show adapter BT information);
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
config ADAPTER_BLUETOOTH_HC08
|
||||
string "HC08 adapter name"
|
||||
default "hc08"
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_HC08_RECV_BUFFER_SIZE
|
||||
int "HC08 recv data buffer size"
|
||||
default "128"
|
||||
|
||||
config ADAPTER_HC08_WORK_ROLE
|
||||
string "HC08 work role M(MASTER) or S(SLAVER)"
|
||||
default "M"
|
||||
|
||||
config ADAPTER_HC08_DRIVER_EXTUART
|
||||
bool "Using extra uart to support bluetooth"
|
||||
default n
|
||||
|
||||
config ADAPTER_HC08_DRIVER
|
||||
string "HC08 device uart driver path"
|
||||
default "/dev/uart4_dev4"
|
||||
depends on !ADAPTER_HC08_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_HC08_DRIVER_EXTUART
|
||||
config ADAPTER_HC08_DRIVER
|
||||
string "HC08 device extra uart driver path"
|
||||
default "/dev/extuart_dev7"
|
||||
|
||||
config ADAPTER_HC08_DRIVER_EXT_PORT
|
||||
int "if HC08 device using extuart, choose port"
|
||||
default "7"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := hc08.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,430 @@
|
|||
/*
|
||||
* 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 hc08.c
|
||||
* @brief Implement the connection Bluetooth adapter function, using HC08 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.07.12
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#define HC08_DETECT_CMD "AT"
|
||||
#define HC08_DEFAULT_CMD "AT+DEFAULT"
|
||||
#define HC08_RESET_CMD "AT+RESET"
|
||||
#define HC08_CLEAR_CMD "AT+CLEAR"
|
||||
#define HC08_GET_DEVICE_INFO "AT+RX"
|
||||
|
||||
#define HC08_GET_BAUDRATE_CMD "AT+BAUD=?"
|
||||
#define HC08_SET_BAUDRATE_CMD "AT+BAUD=%u"
|
||||
#define HC08_GET_CONNECTABLE "AT+CONT=?"
|
||||
#define HC08_SET_CONNECTABLE "AT+CONT=%s"
|
||||
#define HC08_GET_ROLE_CMD "AT+ROLE=?"
|
||||
#define HC08_SET_ROLE_CMD "AT+ROLE=%s"
|
||||
#define HC08_GET_ADDR_CMD "AT+ADDR=?"
|
||||
#define HC08_SET_ADDR_CMD "AT+ADDR=%s"
|
||||
#define HC08_GET_NAME_CMD "AT+NAME=%s"
|
||||
#define HC08_SET_NAME_CMD "AT+NAME=?"
|
||||
|
||||
#define HC08_OK_RESP "OK"
|
||||
|
||||
#define HC08_CMD_STR_DEFAULT_SIZE 64
|
||||
#define HC08_RESP_DEFAULT_SIZE 64
|
||||
|
||||
enum Hc08AtCmd
|
||||
{
|
||||
HC08_AT_CMD_DETECT = 0,
|
||||
HC08_AT_CMD_DEFAULT,
|
||||
HC08_AT_CMD_RESET,
|
||||
HC08_AT_CMD_CLEAR,
|
||||
HC08_AT_CMD_GET_DEVICE_INFO,
|
||||
HC08_AT_CMD_GET_BAUDRATE,
|
||||
HC08_AT_CMD_SET_BAUDRATE,
|
||||
HC08_AT_CMD_SET_CONNECTABLE,
|
||||
HC08_AT_CMD_GET_CONNECTABLE,
|
||||
HC08_AT_CMD_SET_ROLE,
|
||||
HC08_AT_CMD_GET_ROLE,
|
||||
HC08_AT_CMD_SET_ADDR,
|
||||
HC08_AT_CMD_GET_ADDR,
|
||||
HC08_AT_CMD_SET_NAME,
|
||||
HC08_AT_CMD_GET_NAME,
|
||||
HC08_AT_CMD_END,
|
||||
};
|
||||
|
||||
static int Hc08CheckMacHex(char *hex, int len)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
if ((hex[i] >= 'A' && hex[i] <= 'F') ||
|
||||
(hex[i] >= 'a' && hex[i] <= 'f') ||
|
||||
(hex[i] >= '0' && hex[i] <= '9'))
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//HC08 AT cmd function
|
||||
static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *param, char *reply_info)
|
||||
{
|
||||
const char *result_buf;
|
||||
char *connectable, *role;
|
||||
unsigned int baudrate;
|
||||
char reply_ok_flag = 1;
|
||||
char cmd_str[HC08_CMD_STR_DEFAULT_SIZE] = {0};
|
||||
|
||||
ATReplyType reply = CreateATReply(64);
|
||||
if (NULL == reply) {
|
||||
printf("Hc08AtConfigure CreateATReply failed !\n");
|
||||
return -ENOMEMORY;
|
||||
}
|
||||
|
||||
switch (hc08_at_cmd)
|
||||
{
|
||||
case HC08_AT_CMD_DETECT:
|
||||
AtSetReplyEndChar(agent, 0x4F, 0x4B);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_DETECT_CMD);
|
||||
break;
|
||||
case HC08_AT_CMD_DEFAULT:
|
||||
AtSetReplyEndChar(agent, 0x4F, 0x4B);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_DEFAULT_CMD);
|
||||
break;
|
||||
case HC08_AT_CMD_RESET:
|
||||
AtSetReplyEndChar(agent, 0x4F, 0x4B);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_RESET_CMD);
|
||||
break;
|
||||
case HC08_AT_CMD_CLEAR:
|
||||
AtSetReplyEndChar(agent, 0x4F, 0x4B);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_CLEAR_CMD);
|
||||
break;
|
||||
case HC08_AT_CMD_GET_DEVICE_INFO:
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_DEVICE_INFO);
|
||||
reply_ok_flag = 0;
|
||||
break;
|
||||
case HC08_AT_CMD_SET_BAUDRATE:
|
||||
baudrate = *(unsigned int *)param;
|
||||
sprintf(cmd_str, HC08_SET_BAUDRATE_CMD, baudrate);
|
||||
strcat(cmd_str, ",N");
|
||||
AtSetReplyEndChar(agent, 0x4E, 0x45);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str);
|
||||
reply_ok_flag = 0;
|
||||
break;
|
||||
case HC08_AT_CMD_GET_BAUDRATE:
|
||||
AtSetReplyEndChar(agent, 0x2C, 0x4E);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_BAUDRATE_CMD);
|
||||
reply_ok_flag = 0;
|
||||
break;
|
||||
case HC08_AT_CMD_SET_CONNECTABLE:
|
||||
connectable = (char *)param;
|
||||
sprintf(cmd_str, HC08_SET_CONNECTABLE, connectable);
|
||||
AtSetReplyEndChar(agent, 0x4F, 0x4B);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str);
|
||||
break;
|
||||
case HC08_AT_CMD_GET_CONNECTABLE:
|
||||
AtSetReplyEndChar(agent, 0x6C, 0x65);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_CONNECTABLE);
|
||||
reply_ok_flag = 0;
|
||||
break;
|
||||
case HC08_AT_CMD_SET_ROLE:
|
||||
role = (char *)param;
|
||||
sprintf(cmd_str, HC08_SET_ROLE_CMD, role);
|
||||
AtSetReplyCharNum(agent, 1);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str);
|
||||
break;
|
||||
case HC08_AT_CMD_GET_ROLE:
|
||||
AtSetReplyCharNum(agent, 1);
|
||||
ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
||||
reply_ok_flag = 0;
|
||||
break;
|
||||
// case HC08_AT_CMD_SET_ADDR:
|
||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_ROLE_CMD);
|
||||
// break;
|
||||
// case HC08_AT_CMD_GET_ADDR:
|
||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD);
|
||||
// reply_ok_flag = 0;
|
||||
// break;
|
||||
// case HC08_AT_CMD_SET_NAME:
|
||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_NAME_CMD);
|
||||
// break;
|
||||
// case HC08_AT_CMD_GET_NAME:
|
||||
// ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_NAME_CMD);
|
||||
// reply_ok_flag = 0;
|
||||
// break;
|
||||
default:
|
||||
printf("hc08 do not support no.%d cmd\n", hc08_at_cmd);
|
||||
DeleteATReply(reply);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PrivTaskDelay(200);
|
||||
|
||||
result_buf = GetReplyText(reply);
|
||||
|
||||
if (reply_ok_flag) {
|
||||
if (!strstr(HC08_OK_RESP, result_buf)) {
|
||||
printf("%u cmd get reply OK failed:get reply %s\n", hc08_at_cmd, result_buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (reply_info) {
|
||||
strncpy(reply_info, result_buf, reply->reply_len);
|
||||
}
|
||||
|
||||
DeleteATReply(reply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Open(struct Adapter *adapter)
|
||||
{
|
||||
if (INSTALL == adapter->adapter_status) {
|
||||
printf("Hc08 has already been open\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//step1: open hc08 serial port
|
||||
adapter->fd = PrivOpen(ADAPTER_HC08_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Hc08Open get serial %s fd error\n", ADAPTER_HC08_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//step2: init AT agent
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "bluetooth_uart_client";
|
||||
printf("InitATAgent agent_name %s fd %u\n", agent_name, adapter->fd);
|
||||
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;
|
||||
|
||||
printf("Hc08Open adapter agent %p\n", adapter->agent);
|
||||
}
|
||||
|
||||
PrivTaskDelay(200);
|
||||
|
||||
ADAPTER_DEBUG("Hc08 open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Close(struct Adapter *adapter)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
printf("Hc08Ioctl only support OPE_INT, do not support %d\n", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char hc08_baudrate[HC08_RESP_DEFAULT_SIZE] = {0};
|
||||
uint32_t baud_rate = *((uint32_t *)args);
|
||||
|
||||
struct SerialDataCfg serial_cfg;
|
||||
memset(&serial_cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
serial_cfg.serial_baud_rate = baud_rate;
|
||||
serial_cfg.serial_data_bits = DATA_BITS_8;
|
||||
serial_cfg.serial_stop_bits = STOP_BITS_1;
|
||||
serial_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
serial_cfg.serial_parity_mode = PARITY_NONE;
|
||||
serial_cfg.serial_bit_order = STOP_BITS_1;
|
||||
serial_cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
#ifdef ADAPTER_HC08_DRIVER_EXT_PORT
|
||||
serial_cfg.ext_uart_no = ADAPTER_HC08_DRIVER_EXT_PORT;
|
||||
serial_cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
//Step1 : detect hc08 serial function
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step2 : set hc08 device serial baud, hc08_set_baud send "AT+BAUD=%s"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_BAUDRATE, args, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PrivTaskDelay(200);
|
||||
|
||||
//Step3 : show hc08 device info, hc08_get send "AT+RX" response device info
|
||||
char device_info[HC08_RESP_DEFAULT_SIZE * 2] = {0};
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_DEVICE_INFO, NULL, device_info) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("Hc08 ioctl done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08SetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
char mac_addr[HC08_RESP_DEFAULT_SIZE] = {0};
|
||||
|
||||
//Step1 : hc08_get_addr send "AT+ADDR=?" response mac "XX,XX,XX,XX,XX,XX"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_ADDR, NULL, mac_addr) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("HC08 old mac addr: %s\n", mac_addr);
|
||||
|
||||
//Step2 : hc08_set_addr send "AT+ADDR=%s" response "OK"
|
||||
if (!Hc08CheckMacHex((char *)gateway, 12)) {
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_ADDR, (void *)gateway, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//Step3 : check mac addr, hc08_get_addr send "AT+ADDR=?" response mac "XX,XX,XX,XX,XX,XX"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_ADDR, NULL, mac_addr) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("HC08 new mac addr: %s\n", mac_addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
char connect_status[HC08_RESP_DEFAULT_SIZE] = {0};
|
||||
|
||||
//Step1 : hc08_detect send "AT" response "OK"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step2 : hc08_set_role send "AT+ROLE=%s" response "OK"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_ROLE, ADAPTER_HC08_WORK_ROLE, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step3 : hc08_connectable send "AT+CONT=0" response "OK"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_CONNECTABLE, "0", NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step4 : check connectable status,hc08_connectable send "AT+CONT=?" response "Connectable"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_CONNECTABLE, NULL, connect_status) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Hc08Connect status %s\n", connect_status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)buf, len);
|
||||
} else {
|
||||
printf("Hc08Send can not find agent\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Hc08Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)buf, len, 40);
|
||||
} else {
|
||||
printf("Hc08Recv can not find agent\n");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Hc08Disconnect(struct Adapter *adapter)
|
||||
{
|
||||
char connect_status[HC08_RESP_DEFAULT_SIZE] = {0};
|
||||
|
||||
//Step1 : hc08_detect send "AT" response "OK"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step2 : hc08_connectable send "AT+CONT=1" response "OK"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_CONNECTABLE, "1", NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Step3 : check connectable status,hc08_connectable send "AT+CONT=?" response "Not-Connectable"
|
||||
if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_CONNECTABLE, NULL, connect_status) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Hc08Disconnect status %s\n", connect_status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone hc08_done =
|
||||
{
|
||||
.open = Hc08Open,
|
||||
.close = Hc08Close,
|
||||
.ioctl = Hc08Ioctl,
|
||||
.setup = NULL,
|
||||
.setdown = NULL,
|
||||
.setaddr = Hc08SetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = NULL,
|
||||
.netstat = NULL,
|
||||
.connect = Hc08Connect,
|
||||
.send = Hc08Send,
|
||||
.recv = Hc08Recv,
|
||||
.disconnect = Hc08Disconnect,
|
||||
};
|
||||
|
||||
AdapterProductInfoType Hc08Attach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Hc08Attach malloc product_info error\n");
|
||||
free(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ("M" == ADAPTER_HC08_WORK_ROLE) {
|
||||
adapter->net_role = MASTER;
|
||||
} else if ("S" == ADAPTER_HC08_WORK_ROLE) {
|
||||
adapter->net_role = SLAVE;
|
||||
} else {
|
||||
adapter->net_role = ROLE_NONE;
|
||||
}
|
||||
|
||||
strcpy(product_info->model_name, ADAPTER_BLUETOOTH_HC08);
|
||||
|
||||
product_info->model_done = (void *)&hc08_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
config ADAPTER_HFA21_ETHERNET
|
||||
help
|
||||
Please check HFA21 can only work for adapter_wifi or adapter_ethernet in the meantime!
|
||||
bool "Using ethernet adapter device HFA21"
|
||||
default n
|
||||
|
||||
if ADAPTER_HFA21_ETHERNET
|
||||
source "$APP_DIR/Framework/connection/ethernet/hfa21_ethernet/Kconfig"
|
||||
endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES := adapter_ethernet.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_HFA21_ETHERNET),y)
|
||||
SRC_DIR += hfa21_ethernet
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* 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 adapter_ethernet.c
|
||||
* @brief Implement the connection ethernet adapter function
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
extern AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
static int AdapterEthernetRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_ETHERNET_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterEthernet register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterEthernetInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
printf("AdapterEthernetInit malloc error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
|
||||
ret = AdapterEthernetRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterEthernetInit register ethernet adapter error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
AdapterProductInfoType product_info = Hfa21EthernetAttach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterEthernetInit hfa21 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;
|
||||
}
|
||||
|
||||
/******************ethernet TEST*********************/
|
||||
int AdapterEthernetTest(void)
|
||||
{
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_ETHERNET_NAME);
|
||||
|
||||
#ifdef ADAPTER_HFA21_ETHERNET
|
||||
|
||||
char ethernet_recv_msg[128] = {0};
|
||||
int i, len = 0;
|
||||
const char *ethernet_msg = "Adapter Ethernet Test";
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
AdapterDeviceSetUp(adapter);
|
||||
|
||||
const char *ip = "10.10.100.50";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = CLIENT;//SERVER
|
||||
enum IpType ip_type = IPV4;
|
||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||
|
||||
printf("ready to test data transfer\n");
|
||||
|
||||
len = strlen(ethernet_msg);
|
||||
for (i = 0;i < 10; i ++) {
|
||||
printf("AdapterEthernetTest send %s\n", ethernet_msg);
|
||||
AdapterDeviceSend(adapter, ethernet_msg, len);
|
||||
PrivTaskDelay(4000);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
AdapterDeviceRecv(adapter, ethernet_recv_msg, 128);
|
||||
printf("AdapterEthernetTest recv %s\n", ethernet_recv_msg);
|
||||
memset(ethernet_recv_msg, 0, 128);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterEthernetTest, AdapterEthernetTest, show adapter ethernet information);
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
config ADAPTER_ETHERNET_HFA21
|
||||
string "HFA21 ETHERNET adapter name"
|
||||
default "hfa21_ethernet"
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXTUART
|
||||
bool "Using extra uart to support ethernet"
|
||||
default n
|
||||
|
||||
config ADAPTER_HFA21_DRIVER
|
||||
string "HFA21 device uart driver path"
|
||||
default "/dev/usart3_dev3"
|
||||
depends on !ADAPTER_HFA21_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_HFA21_DRIVER_EXTUART
|
||||
config ADAPTER_HFA21_DRIVER
|
||||
string "HFA21 device extra uart driver path"
|
||||
default "/dev/extuart_dev6"
|
||||
|
||||
config ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||
int "if HFA21 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 := hfa21_ethernet.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -0,0 +1,453 @@
|
|||
/*
|
||||
* 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 hfa21_ethernet.c
|
||||
* @brief Implement the connection ethernet adapter function, using HFA21 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.10.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#define HFA21_ETHERNET_AT_CMD "+++"
|
||||
#define HFA21_ETHERNET_AT_CONFIRM_CMD "a"
|
||||
#define HFA21_ETHERNET_AT_FCLR_CMD "AT+FCLR\r"
|
||||
#define HFA21_ETHERNET_AT_FEPHY_CMD "AT+FEPHY=on\r"
|
||||
#define HFA21_ETHERNET_AT_ENABLE_WANN_CMD "AT+FVEW=enable\r"
|
||||
#define HFA21_ETHERNET_AT_DISABLE_WANN_CMD "AT+FVEW=disable\r"
|
||||
#define HFA21_ETHERNET_AT_RELD_CMD "AT+RELD\r"
|
||||
#define HFA21_ETHERNET_AT_WMODE_CMD "AT+WMODE\r"
|
||||
#define HFA21_ETHERNET_AT_WANN_CMD "AT+WANN\r"
|
||||
#define HFA21_ETHERNET_AT_SET_WANN_CMD "AT+WANN=%s,%s,%s,%s\r"
|
||||
#define HFA21_ETHERNET_AT_PING_CMD "AT+PING=%s\r"
|
||||
#define HFA21_ETHERNET_AT_NETP_CMD "AT+NETP=%s,%s,%s,%s\r"
|
||||
#define HFA21_ETHERNET_AT_REBOOT_CMD "AT+Z\r"
|
||||
|
||||
#define HFA21_ETHERNET_OK_REPLY "+ok"
|
||||
|
||||
static int Hfa21EthernetSetDown(struct Adapter *adapter_at);
|
||||
|
||||
/**
|
||||
* @description: enter AT command mode
|
||||
* @param at_agent - ethernet device agent pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetInitAtCmd(ATAgentType at_agent)
|
||||
{
|
||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CMD);
|
||||
PrivTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_CONFIRM_CMD);
|
||||
PrivTaskDelay(500);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open HFA21 uart function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthernetOpen(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open hfa21 serial port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_HFA21_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("Hfa21EthernetOpen get serial %s fd error\n", ADAPTER_HFA21_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "ethernet_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("Hfa21Ethernet open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close HFA21 ethernet and uart function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetClose(struct Adapter *adapter)
|
||||
{
|
||||
return Hfa21EthernetSetDown(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: send data to adapter
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSend(struct Adapter *adapter, const void *data, size_t len)
|
||||
{
|
||||
int result = 0;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)data, len);
|
||||
}else {
|
||||
printf("Hfa21EthernetSend can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: receive data from adapter
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param data - data buffer
|
||||
* @param data - data length
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
||||
} else {
|
||||
printf("Hfa21EthernetReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: connnect Ethernet to internet
|
||||
* @param adapter - Ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSetUp(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
AtSetReplyLrEnd(adapter->agent, 1);
|
||||
|
||||
/* wait hfa21 device startup finish */
|
||||
PrivTaskDelay(5000);
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
/*Step2 : FCLR reboot*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FCLR_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step3 : FEPHY enable phy function*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_FEPHY_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step4 : FVEW disable WANN function, ethernet work at LANN mode*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_DISABLE_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step5 : RELD enable F-AT cmd*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_RELD_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step6 : AT+WMODE check work mode, AP or STA*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WMODE_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step7 : AT+WANN check if get ip、netmask、gateway*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step8 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: disconnnect ethernet from internet
|
||||
* @param adapter - ethernet device pointer
|
||||
* @return success: 0
|
||||
*/
|
||||
static int Hfa21EthernetSetDown(struct Adapter *adapter)
|
||||
{
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, HFA21_ETHERNET_AT_FCLR_CMD);
|
||||
PrivTaskDelay(20000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: set ethernet ip/gateway/netmask address(in sta mode) working at WANN mode
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param ip - ip address
|
||||
* @param gateway - gateway address
|
||||
* @param netmask - netmask address
|
||||
* @return success: 0, failure: -ENOMEMORY or -1
|
||||
*/
|
||||
static int Hfa21EthernetSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t hfa21_ethernet_cmd[64];
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step2 : set mode、ip、netmask and gateway*/
|
||||
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_SET_WANN_CMD, "DHCP", ip, netmask, gateway);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step3 : AT+WANN check if set ip、netmask、gateway successfully*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_WANN_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step4 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethernet ping function
|
||||
* @param adapter - ethernet device pointer
|
||||
* @param destination - domain name or ip address
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int Hfa21EthernetPing(struct Adapter *adapter, const char *destination)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
char *ping_result = (char *) PrivCalloc(1, 17);
|
||||
char *dst = (char *) PrivCalloc(1, 17);
|
||||
|
||||
strcpy(dst, destination);
|
||||
strcat(dst, "\r");
|
||||
|
||||
printf("Hfa21EthernetPing [%s]\n", dst);
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
/*Step2 : ping dst ip address*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_PING_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/*Step3 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: ethernet connect function
|
||||
* @param adapter - ethernet 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 Hfa21EthernetConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int ret = 0;
|
||||
char hfa21_ethernet_cmd[128];
|
||||
char net_role_string[7] = {0};
|
||||
|
||||
/*Step1 : enter AT mode*/
|
||||
Hfa21EthernetInitAtCmd(adapter->agent);
|
||||
|
||||
if (CLIENT == net_role) {
|
||||
strcpy(net_role_string, "CLIENT");
|
||||
} else if (SERVER == net_role) {
|
||||
strcpy(net_role_string, "SERVER");
|
||||
} else {
|
||||
printf("Hfa21EthernetConnect do not support %d net type\n", net_role);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (IPV4 == ip_type) {
|
||||
/*to do*/
|
||||
} else if (IPV6 == ip_type) {
|
||||
/*to do*/
|
||||
} else {
|
||||
printf("Hfa21EthernetConnect do not support %d ip type\n", ip_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*Step2 : create tcp connect*/
|
||||
memset(hfa21_ethernet_cmd, 0, sizeof(hfa21_ethernet_cmd));
|
||||
sprintf(hfa21_ethernet_cmd, HFA21_ETHERNET_AT_NETP_CMD, "TCP", net_role_string, port, ip);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, hfa21_ethernet_cmd, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
adapter->net_role = net_role;
|
||||
|
||||
/*Step3 : AT+Z reboot hfa21 device*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, HFA21_ETHERNET_AT_REBOOT_CMD, HFA21_ETHERNET_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
|
||||
return ret;
|
||||
|
||||
__exit:
|
||||
Hfa21EthernetSetDown(adapter);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int Hfa21EthernetIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
printf("Hfa21EthernetIoctl only support OPE_INT, do not support %d\n", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t baud_rate = *((uint32_t *)args);
|
||||
|
||||
struct SerialDataCfg serial_cfg;
|
||||
memset(&serial_cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
serial_cfg.serial_baud_rate = baud_rate;
|
||||
serial_cfg.serial_data_bits = DATA_BITS_8;
|
||||
serial_cfg.serial_stop_bits = STOP_BITS_1;
|
||||
serial_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
serial_cfg.serial_parity_mode = PARITY_NONE;
|
||||
serial_cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||
serial_cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
|
||||
serial_cfg.ext_uart_no = ADAPTER_HFA21_DRIVER_EXT_PORT;
|
||||
serial_cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &serial_cfg;
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
printf("Hfa21EthernetIoctl success\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone hfa21_ethernet_done =
|
||||
{
|
||||
.open = Hfa21EthernetOpen,
|
||||
.close = Hfa21EthernetClose,
|
||||
.ioctl = Hfa21EthernetIoctl,
|
||||
.setup = Hfa21EthernetSetUp,
|
||||
.setdown = Hfa21EthernetSetDown,
|
||||
.setaddr = Hfa21EthernetSetAddr,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = Hfa21EthernetPing,
|
||||
.netstat = NULL,
|
||||
.connect = Hfa21EthernetConnect,
|
||||
.send = Hfa21EthernetSend,
|
||||
.recv = Hfa21EthernetReceive,
|
||||
.disconnect = NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Register ethernet device hfa21
|
||||
* @return success: product_info, failure: NULL
|
||||
*/
|
||||
AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("Hfa21EthernetAttach Attach malloc product_info error\n");
|
||||
PrivFree(product_info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(product_info->model_name, ADAPTER_ETHERNET_HFA21);
|
||||
|
||||
product_info->model_done = (void *)&hfa21_ethernet_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
config CONNECTION_ADAPTER_ETHERCAT
|
||||
bool "Using ethercat on industrial_ethernet adapter device"
|
||||
default n
|
||||
|
||||
if CONNECTION_ADAPTER_ETHERCAT
|
||||
source "$APP_DIR/Framework/connection/industrial_ethernet/ethercat/Kconfig"
|
||||
endif
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERCAT),y)
|
||||
SRC_DIR += ethercat
|
||||
endif
|
||||
|
||||
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