forked from xuos/xiuos
delete original app contents of xiuos
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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 10 if KTASK_PRIORITY_32
|
||||
default 85 if KTASK_PRIORITY_256
|
||||
endmenu
|
||||
|
||||
menuconfig APPLICATION_SENSOR
|
||||
bool "Using sensor apps"
|
||||
default n
|
||||
select PERCEPTION_SENSORDEVICE
|
||||
|
||||
if APPLICATION_SENSOR
|
||||
menuconfig APPLICATION_SENSOR_CO2
|
||||
bool "Using sensor CO2 apps"
|
||||
default n
|
||||
select PERCEPTION_CO2
|
||||
|
||||
if APPLICATION_SENSOR_CO2
|
||||
config APPLICATION_SENSOR_CO2_ZG09
|
||||
bool "Using sensor ZG09 apps"
|
||||
default n
|
||||
select PERCEPTION_ZG09
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_PM1_0
|
||||
bool "Using sensor PM1.0 apps"
|
||||
default n
|
||||
select PERCEPTION_PM
|
||||
|
||||
if APPLICATION_SENSOR_PM1_0
|
||||
config APPLICATION_SENSOR_PM1_0_PS5308
|
||||
bool "Using sensor PS5308 apps"
|
||||
default n
|
||||
select PERCEPTION_PS5308
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_VOICE
|
||||
bool "Using sensor voice apps"
|
||||
default n
|
||||
select PERCEPTION_VOICE
|
||||
|
||||
if APPLICATION_SENSOR_VOICE
|
||||
config APPLICATION_SENSOR_VOICE_D124
|
||||
bool "Using sensor D124 apps"
|
||||
default n
|
||||
select PERCEPTION_D124
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_HUMIDITY
|
||||
bool "Using sensor humidity apps"
|
||||
default n
|
||||
select PERCEPTION_HUMIDITY
|
||||
|
||||
if APPLICATION_SENSOR_HUMIDITY
|
||||
config APPLICATION_SENSOR_HUMIDITY_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
select PERCEPTION_HS300X
|
||||
endif
|
||||
|
||||
menuconfig APPLICATION_SENSOR_TEMPERATURE
|
||||
bool "Using sensor temperature apps"
|
||||
default n
|
||||
select PERCEPTION_TEMPERATURE
|
||||
|
||||
if APPLICATION_SENSOR_TEMPERATURE
|
||||
config APPLICATION_SENSOR_TEMPERATURE_HS300X
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
select PERCEPTION_HS300X
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig CONNECTION_COMMUNICATION_ZIGBEE
|
||||
bool "enable zigbee demo"
|
||||
default n
|
||||
select CONFIG_CONNECTION_COMMUNICATION_ZIGBEE
|
||||
if CONNECTION_COMMUNICATION_ZIGBEE
|
||||
source "$KERNEL_DIR/framework/connection/Adapter/zigbee/Kconfig"
|
||||
endif
|
||||
|
||||
|
||||
|
||||
source "$APP_DIR/Applications/app_test/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -1,5 +1,45 @@
|
||||
SRC_FILES := main.c
|
||||
|
||||
SRC_DIR := general_functions
|
||||
|
||||
SRC_FILES := main.c framework_init.c
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SDIO), y)
|
||||
SRC_FILES += sd_card_mount.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RESOURCES_SPI_SD), y)
|
||||
SRC_FILES += spi_sd_card_mount.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BOOTSTART_LORA_NET_SAMPLE), y)
|
||||
SRC_DIR += connection_demo/adhoc_lora_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ZIGBEE), y)
|
||||
SRC_DIR += connection_demo/zigbee_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ETHERNET), y)
|
||||
SRC_DIR += connection_demo/ethernet_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_WIFI), y)
|
||||
SRC_DIR += connection_demo/wifi_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y)
|
||||
SRC_DIR += connection_demo/nbiot_demo
|
||||
endif
|
||||
|
||||
# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y)
|
||||
# SRC_DIR += connection_demo/4G_demo
|
||||
# endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BLUETOOTH), y)
|
||||
SRC_DIR += connection_demo/bluetooth_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR),y)
|
||||
SRC_DIR += sensor_app
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
18
APP_Framework/Applications/app_test/Kconfig
Normal file
18
APP_Framework/Applications/app_test/Kconfig
Normal file
@@ -0,0 +1,18 @@
|
||||
menuconfig USER_TEST
|
||||
bool "Enable application test function "
|
||||
default n
|
||||
|
||||
if USER_TEST
|
||||
config USER_TEST_LORA_ADHOC
|
||||
bool "Config test lora adhoc"
|
||||
default n
|
||||
|
||||
config USER_TEST_SPI_LORA
|
||||
bool "Config test spi lora"
|
||||
default n
|
||||
|
||||
config USER_TEST_SPI_FLASH
|
||||
bool "Config test spi flash"
|
||||
default n
|
||||
|
||||
endif
|
||||
15
APP_Framework/Applications/app_test/Makefile
Normal file
15
APP_Framework/Applications/app_test/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_LORA_ADHOC),y)
|
||||
SRC_FILES += test_adhoc_lora.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SPI_LORA),y)
|
||||
SRC_FILES += test_spi_lora.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
|
||||
SRC_FILES += test_spi_flash.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
20
APP_Framework/Applications/app_test/test_adhoc_lora.c
Normal file
20
APP_Framework/Applications/app_test/test_adhoc_lora.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <xiuos.h>
|
||||
|
||||
extern void net_lora_client(int argc, char *argv[]);
|
||||
extern void net_lora_gateway(int argc, char *argv[]);
|
||||
|
||||
void demo_lora_adhoc()
|
||||
{
|
||||
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_CLIENT
|
||||
char pgk_count[32];
|
||||
char* param[3];
|
||||
param[0] = "xxx";
|
||||
param[1] = CONNECTION_COMMUNICATION_LORA_CLIENT_NAME;
|
||||
itoa(CONNECTION_COMMUNICATION_LORA_CLIENT_PKG_COUNT, pgk_count, 10);
|
||||
param[2] = pgk_count;
|
||||
net_lora_client(2, param);
|
||||
#endif
|
||||
#ifdef CONNECTION_COMMUNICATION_SET_AS_LORA_GATEWAY
|
||||
net_lora_gateway(0, 0);
|
||||
#endif
|
||||
}
|
||||
175
APP_Framework/Applications/app_test/test_spi_flash.c
Normal file
175
APP_Framework/Applications/app_test/test_spi_flash.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* File : spi_flash_sfud.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* 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 <xiuos.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,3 @@
|
||||
SRC_FILES := client.c gateway.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,108 @@
|
||||
#include <user_api.h>
|
||||
#include <string.h>
|
||||
#include <xs_adapter_lora.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char client_name[DEVNAME_LEN_MAX] = "lora_dev_123";
|
||||
|
||||
void success_cb(void *param)
|
||||
{
|
||||
printf("success_cb, param = %s\n", param);
|
||||
}
|
||||
|
||||
void invert_param(void *param)
|
||||
{
|
||||
printf("success_cb02 invoke, invert bool param.\n");
|
||||
bool *bparam = (bool *)param;
|
||||
if (*bparam)
|
||||
{
|
||||
*bparam = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*bparam = true;
|
||||
}
|
||||
}
|
||||
|
||||
void net_lora_client(int argc, char *argv[])
|
||||
{
|
||||
int pkg_count = 10;
|
||||
if (argc >= 1)
|
||||
{
|
||||
memset(client_name, 0, DEVNAME_LEN_MAX);
|
||||
strncpy(client_name, argv[1], strlen(argv[1]));
|
||||
printf("lora client set clientName(%s).\n", client_name);
|
||||
}
|
||||
|
||||
if (argc >= 2)
|
||||
{
|
||||
pkg_count = atoi(argv[2]);
|
||||
printf("lora client set pkg_count(%d).\n", pkg_count);
|
||||
}
|
||||
|
||||
// 1.Create an adapter for a specific agreement (LORA)
|
||||
static struct AdapterLora lora_adapter;
|
||||
memset(&lora_adapter, 0, sizeof(lora_adapter));
|
||||
struct AdapterDone lora_example_done = {
|
||||
.NetAiitOpen = LoraAdapterOpen,
|
||||
.NetAiitClose = LoraAdapterCose,
|
||||
.NetAiitSend = LoraAdapterSendc2g,
|
||||
.NetAiitReceive = NULL,
|
||||
.NetAiitJoin = LoraAdapterJoin,
|
||||
.NetAiitIoctl = NULL,
|
||||
};
|
||||
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
|
||||
lora_adapter.name = client_name; // Set adapter name
|
||||
lora_adapter.spi_lora_fd = -1; // Set adapter information
|
||||
lora_adapter.deve_ui = "xxx";
|
||||
lora_adapter.app_key = "yyy";
|
||||
|
||||
// 2.Register the adapter in the list
|
||||
LoraAdapterInit();
|
||||
LoraAdapterRegister((adapter_t)&lora_adapter);
|
||||
|
||||
// 3.Find from the list of registered adapters
|
||||
adapter_t padapter = LoraAdapterFind(client_name);
|
||||
if (NONE == padapter)
|
||||
{
|
||||
printf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4.Open adapter
|
||||
if (0 != padapter->done.NetAiitOpen(padapter))
|
||||
{
|
||||
printf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 5.Join the specified network segment as client
|
||||
printf("NetAiitJoin start. \n");
|
||||
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_SLAVE, CONNECTION_COMMUNICATION_LORA_NET_ID);
|
||||
printf("NetAiitJoin end. \n");
|
||||
|
||||
// 6.Point to point sending data to gateway
|
||||
int i = 0;
|
||||
while (i < pkg_count)
|
||||
{
|
||||
char data[120] = {0};
|
||||
sprintf(data, "***** I am %s, data_num = %d ******" ,client_name, i);
|
||||
|
||||
bool v = false;
|
||||
padapter->done.NetAiitSend(padapter, data, strlen(data) + 1, true, 10000, 0, invert_param, &v, NULL);
|
||||
while (!v) // Asynchronous analog synchronization
|
||||
{
|
||||
UserTaskDelay(100);
|
||||
}
|
||||
printf("send success(main thread)... %s\n" ,data);
|
||||
|
||||
i++;
|
||||
UserTaskDelay(800); // Contract interval
|
||||
}
|
||||
printf("all pkg send success(main thread), quit.\n");
|
||||
|
||||
padapter->done.NetAiitClose(padapter);
|
||||
printf("client quit.\n");
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <user_api.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_lora.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
|
||||
extern DoubleLinklistType online_user_head;
|
||||
|
||||
void net_lora_gateway(int argc, char *argv[])
|
||||
{
|
||||
// 1.New specific agreement (LORA) adapter
|
||||
static struct AdapterLora lora_adapter;
|
||||
memset(&lora_adapter, 0, sizeof(lora_adapter));
|
||||
struct AdapterDone lora_example_done = {
|
||||
.NetAiitOpen = LoraAdapterOpen,
|
||||
.NetAiitClose = NULL,
|
||||
.NetAiitSend = NULL,
|
||||
.NetAiitReceive = LoraAdapterReceive,
|
||||
.NetAiitJoin = LoraAdapterJoin,
|
||||
.NetAiitIoctl = NULL,
|
||||
};
|
||||
lora_adapter.parent.done = lora_example_done; // Bind adapter operation
|
||||
lora_adapter.name = "lora_dev_456"; // Set adapter name
|
||||
lora_adapter.spi_lora_fd = -1; // Set adapter information
|
||||
lora_adapter.deve_ui = "xxx";
|
||||
lora_adapter.app_key = "yyy";
|
||||
|
||||
// 2.Register the adapter in the list
|
||||
LoraAdapterInit();
|
||||
LoraAdapterRegister((adapter_t)&lora_adapter);
|
||||
|
||||
// 3.Find from the list of registered adapters
|
||||
adapter_t padapter = LoraAdapterFind("lora_dev_456");
|
||||
if (NONE == padapter)
|
||||
{
|
||||
printf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4.Open adapter
|
||||
if (0 != padapter->done.NetAiitOpen(padapter))
|
||||
{
|
||||
printf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 5.Join the specified network segment as gateway
|
||||
padapter->done.NetAiitJoin(padapter, ROLE_TYPE_MASTER, CONNECTION_COMMUNICATION_LORA_NET_ID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void net_lora_connectedlist(int argc, char *argv[])
|
||||
{
|
||||
DoubleLinklistType* pNode;
|
||||
printf("******** connected users *********\n");
|
||||
DOUBLE_LINKLIST_FOR_EACH(pNode, &online_user_head)
|
||||
{
|
||||
OnlineUser* pUser =CONTAINER_OF(pNode, OnlineUser, link);
|
||||
printf("%s\n", pUser->user_name);
|
||||
}
|
||||
printf("*********************************\n");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := bluetooth_receive_demo.c bluetooth_send_demo.c
|
||||
# zigbee_send_demo.c zigbee_receive_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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: bluetooth_receive_demo.c
|
||||
* @brief: using bluetooth to receive message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/4/30
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_bluetooth.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <user_api.h>
|
||||
#include <string.h>
|
||||
static int re_sem;
|
||||
|
||||
static int buff_sem;
|
||||
|
||||
|
||||
/*Critical zone protection function for*/
|
||||
void BluetoothWait(char *rev_buffer)
|
||||
{
|
||||
while(1){
|
||||
if (strlen(rev_buffer)>1){
|
||||
UserSemaphoreAbandon(re_sem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* receive message from another bluetooth device*/
|
||||
void BluetoothReceiveDemo(int argc, char *argv[])
|
||||
{
|
||||
adapter_t padapter = BluetoothAdapterFind("Bluetooth");
|
||||
if (NONE == padapter){
|
||||
KPrintf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
KPrintf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char rev_buffer[NAME_NUM_MAX];
|
||||
/* Initialize semaphore */
|
||||
re_sem = UserSemaphoreCreate(0);
|
||||
/* receive buffer from serial port */
|
||||
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
|
||||
BluetoothWait(rev_buffer);
|
||||
UserSemaphoreObtain(re_sem,-1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
for (int i=0;i<strlen(rev_buffer);i++)
|
||||
{
|
||||
if(rev_buffer[i] != 0Xff)
|
||||
printf("%c",rev_buffer[i]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
BluetoothReceiveDemo, BluetoothReceiveDemo, bluetooth receive function );
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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: bluetooth_send_demo.c
|
||||
* @brief: using bluetooth to send message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/4/30
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_bluetooth.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
adapter_t padapter;
|
||||
/* a demo function to send message through command line using bluetooth*/
|
||||
/* first open bluetooth to start demo*/
|
||||
void BluetoothOpenDemo()
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
// adapter_t padapter = BluetoothAdapterFind("Bluetoot");
|
||||
padapter = BluetoothAdapterFind("Bluetooth");
|
||||
if (NONE == padapter){
|
||||
printf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
printf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
BluetoothOpenDemo, BluetoothOpenDemo, bluetooth send function );
|
||||
#endif
|
||||
|
||||
void BluetoothSendDemo(int argc, char *argv[])
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
bool v = false;
|
||||
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
|
||||
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
BluetoothSendDemo, BluetoothSendDemo, bluetooth send function );
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := ethernet_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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 ethernet_demo.c
|
||||
* @brief Demo for ethernet function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_ethernet.h>
|
||||
|
||||
static bool opened = false;
|
||||
|
||||
void OpenEthernetMsg()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SendEthernetMsg(int argc, char *argv[])
|
||||
{
|
||||
char ethernet_msg[128];
|
||||
if (argc >= 1){
|
||||
memset(ethernet_msg, 0, 128);
|
||||
strncpy(ethernet_msg, argv[1], strlen(argv[1]));
|
||||
printf("SendEthernetMsg(%s).\n", ethernet_msg);
|
||||
}
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, ethernet_msg, strlen(ethernet_msg), true, 1000, 0, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void RecvEthernetMsg()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
while (1){
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, ethernet_recv_msg, 128, 40000, true, NULL))
|
||||
printf("ethernet_recv_msg (%s)\n", ethernet_recv_msg);
|
||||
else
|
||||
printf("ethernet_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
|
||||
void DhcpEthernet()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK != at_adapter->atdone.ATOperateDHCP(at_adapter, 1))
|
||||
printf("EthernetNetstat failed \n");
|
||||
}
|
||||
|
||||
void PingEthernet()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
char *ip_str = "192.168.250.250";
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK == at_adapter->atdone.ATPing(at_adapter, ip_str, &result))
|
||||
printf("EthernetPing success (%s)\n", result.ip_addr.ipv4);
|
||||
else
|
||||
printf("EthernetPing failed \n");
|
||||
}
|
||||
|
||||
void SetUpEthernet()
|
||||
{
|
||||
char ethernet_recv_msg[128];
|
||||
memset(ethernet_recv_msg, 0, sizeof(ethernet_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter))
|
||||
printf("EthernetSetUp success (%s)\n", result.ip_addr.ipv4);
|
||||
else
|
||||
printf("EthernetSetUp failed \n");
|
||||
}
|
||||
|
||||
void NetstatEthernet()
|
||||
{
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
if (!at_adapter)
|
||||
printf("ATAdapterFind failed .\n");
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
|
||||
printf("EthernetNetstat failed \n");
|
||||
}
|
||||
|
||||
void AtTestCmdEthernet(int argc, char *argv[])
|
||||
{
|
||||
char cmd[64];
|
||||
if (argc >= 1){
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
strncpy(cmd, argv[1], strlen(argv[1]));
|
||||
printf("AT cmd send(%s).\n", cmd);
|
||||
}
|
||||
|
||||
strcat(cmd,"\r");
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(ETHERNET_ADAPTER_ID);
|
||||
|
||||
if (!opened){
|
||||
opened = true;
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
// Send hfa21 handshake, start cmd mode.
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES :=nbiot_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 nbiot_demo.c
|
||||
* @brief Demo for NBIoT function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_at_agent.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_nbiot.h>
|
||||
|
||||
extern void RegisterAdapterNBIoT(void);
|
||||
|
||||
void NbiotEnable(void)
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(NBIOT_ADAPTER_ID);
|
||||
|
||||
UserTaskDelay(5000);
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->atdone.ATSocketCreate(at_adapter, 1, SOCKET_TYPE_STREAM, NET_TYPE_AF_INET);
|
||||
UserTaskDelay(1000);
|
||||
|
||||
struct AddressIpv4 addr;
|
||||
addr.ipv4 = IpTint("115.236.53.226");
|
||||
at_adapter->atdone.ATSocketConnect(at_adapter, 1, addr, 8989, 0);
|
||||
|
||||
int socket_fd = 1;
|
||||
int count = 0;
|
||||
|
||||
while (1) {
|
||||
UserTaskDelay(1000);
|
||||
at_adapter->parent.done.NetAiitSend((struct Adapter *)at_adapter, "AB30313233", 5, 0, 0, 0, 0, 0, &socket_fd);
|
||||
count++;
|
||||
if (count == 10)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES :=wifi_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
179
APP_Framework/Applications/connection_demo/wifi_demo/wifi_demo.c
Normal file
179
APP_Framework/Applications/connection_demo/wifi_demo/wifi_demo.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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 wifi_demo.c
|
||||
* @brief Demo for wifi function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.22
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <xs_adapter_at_wifi.h>
|
||||
|
||||
void SendWiftMsg(int argc, char *argv[])
|
||||
{
|
||||
char wifi_msg[128];
|
||||
if (argc >= 1) {
|
||||
memset(wifi_msg, 0, 128);
|
||||
strncpy(wifi_msg, argv[1], strlen(argv[1]));
|
||||
printf("SendWiftMsg(%s).\n", wifi_msg);
|
||||
}
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
at_adapter->parent.done.NetAiitSend(&at_adapter->parent, wifi_msg, strlen(wifi_msg), true, 1000, 0, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void RecvWifiMsg()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
while (1) {
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, wifi_recv_msg, 128, 40000, true, NULL)) {
|
||||
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
|
||||
} else {
|
||||
printf("wifi_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetAddrWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateAddr(at_adapter, IpTint("10.10.100.222"), IpTint("255.255.255.0"), IpTint("255.255.255.0")))
|
||||
printf("WifiSetAddr failed \n");
|
||||
}
|
||||
|
||||
void DhcpWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if(EOK != at_adapter->atdone.ATOperateDHCP(at_adapter,1))
|
||||
printf("WifiDHCP failed \n");
|
||||
}
|
||||
|
||||
void PingWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT *at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
//www.baidu.com
|
||||
char *ip_str = "36.152.44.95";
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
at_adapter->atdone.ATPing(at_adapter, ip_str, &result);
|
||||
}
|
||||
|
||||
void SetUpWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
struct PingResult result;
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if (EOK == at_adapter->atdone.ATOperateUp(at_adapter)) {
|
||||
printf("WifiSetUp success (%s)\n", result.ip_addr.ipv4);
|
||||
} else {
|
||||
printf("WifiSetUp failed \n");
|
||||
}
|
||||
}
|
||||
|
||||
void NetstatWifi()
|
||||
{
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
if (!at_adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
if (EOK != at_adapter->atdone.ATNetstat(at_adapter))
|
||||
printf("WifiNetstat failed \n");
|
||||
}
|
||||
|
||||
void AtTestCmdWifi(int argc, char *argv[])
|
||||
{
|
||||
char cmd[64];
|
||||
if (argc >= 1) {
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
strncpy(cmd, argv[1], strlen(argv[1]));
|
||||
printf("AT cmd send(%s).\n", cmd);
|
||||
}
|
||||
|
||||
strcat(cmd,"\r");
|
||||
struct AdapterAT* at_adapter = ATAdapterFind(WIFI_ADAPTER_ID);
|
||||
at_adapter->parent.done.NetAiitOpen(&at_adapter->parent);
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(at_adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := zigbee_receive_demo.c
|
||||
# zigbee_send_demo.c zigbee_receive_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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: zigbee_receive_demo.c
|
||||
* @brief: using zigbee to receive message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/4/30
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_zigbee.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <user_api.h>
|
||||
#include <string.h>
|
||||
static int re_sem;
|
||||
|
||||
static int buff_sem;
|
||||
|
||||
|
||||
/*Critical zone protection function for*/
|
||||
void ZigbeeWait(char *rev_buffer)
|
||||
{
|
||||
while(1){
|
||||
if (strlen(rev_buffer)>1){
|
||||
UserSemaphoreAbandon(re_sem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* receive message from another zigbee device*/
|
||||
void ZigbeeReceiveDemo(int argc, char *argv[])
|
||||
{
|
||||
adapter_t padapter = ZigbeeAdapterFind("zigbee");
|
||||
if (NONE == padapter){
|
||||
KPrintf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
KPrintf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char rev_buffer[NAME_NUM_MAX];
|
||||
/* Initialize semaphore */
|
||||
re_sem = UserSemaphoreCreate(0);
|
||||
/* receive buffer from serial port */
|
||||
padapter->done.NetAiitReceive(padapter,rev_buffer,strlen(rev_buffer),10000,false,NULL);
|
||||
ZigbeeWait(rev_buffer);
|
||||
UserSemaphoreObtain(re_sem,-1);
|
||||
|
||||
|
||||
printf("\n");
|
||||
for (int i=0;i<strlen(rev_buffer);i++)
|
||||
{
|
||||
if(rev_buffer[i] != 0Xff)
|
||||
printf("%c",rev_buffer[i]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeReceiveDemo, ZigbeeReceiveDemo, zigbee receive function );
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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: zigbee_send_demo.c
|
||||
* @brief: using zigbee to send message
|
||||
* @version: 1.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2021/4/30
|
||||
*
|
||||
*/
|
||||
#include <xs_adapter_zigbee.h>
|
||||
#include <string.h>
|
||||
#include <xs_klist.h>
|
||||
#include <xs_adapter_manager.h>
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
adapter_t padapter;
|
||||
/* a demo function to send message through command line using zigbee*/
|
||||
/* first open zigbee to start demo*/
|
||||
void ZigbeeOpenDemo()
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
// adapter_t padapter = ZigbeeAdapterFind("zigbee");
|
||||
padapter = ZigbeeAdapterFind("zigbee");
|
||||
if (NONE == padapter){
|
||||
printf("adapter find failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Open adapter*/
|
||||
if (0 != padapter->done.NetAiitOpen(padapter)){
|
||||
printf("adapter open failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeOpenDemo, ZigbeeOpenDemo, zigbee send function );
|
||||
#endif
|
||||
|
||||
void ZigbeeSendDemo(int argc, char *argv[])
|
||||
{
|
||||
/*Find from the list of registered adapters*/
|
||||
bool v = false;
|
||||
padapter->done.NetAiitSend(padapter, argv[1], strlen(argv[1]) ,true,10000,0, NULL,&v,NULL);
|
||||
|
||||
|
||||
}
|
||||
#ifndef SEPARATE_COMPILE
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
ZigbeeSendDemo, ZigbeeSendDemo, zigbee send function );
|
||||
#endif
|
||||
|
||||
|
||||
116
APP_Framework/Applications/cppmain.cpp
Normal file
116
APP_Framework/Applications/cppmain.cpp
Normal file
@@ -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 <xiuos.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;
|
||||
}
|
||||
162
APP_Framework/Applications/framework_init.c
Normal file
162
APP_Framework/Applications/framework_init.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
extern int SensorFrameworkInit(void);
|
||||
extern int RegisterAdapterEthernet(void);
|
||||
extern int RegisterAdapterWifi(void);
|
||||
extern int RegisterAdapterZigbee(void);
|
||||
extern int RegisterAdapterNBIoT(void);
|
||||
extern int RegisterAdapterBluetooth(void);
|
||||
extern int LoraSx12xxSpiDeviceInit();
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
extern int Hs300xHumidityInit(void);
|
||||
extern int Ps5308Pm1_0Init(void);
|
||||
extern int Zg09Co2Init(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 SENSOR_SENSORDEVICE
|
||||
{ "perception_framework", SensorFrameworkInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc perception_desc[] =
|
||||
{
|
||||
#ifdef PERCEPTION_D124
|
||||
{ "d124_voice", D124VoiceInit },
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_HS300X
|
||||
#ifdef SENSOR_QUANTITY_HS300X_TEMPERATURE
|
||||
{ "hs300x_temperature", Hs300xTemperatureInit },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_HS300X_HUMIDITY
|
||||
{ "hs300x_humidity", Hs300xHumidityInit },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_PS5308
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM1_0
|
||||
{ "ps5308_pm1_0", Ps5308Pm1_0Init },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PERCEPTION_ZG09
|
||||
{ "zg09_co2", Zg09Co2Init },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_COMMUNICATION_ETHERNET
|
||||
{ "ethernet adpter", RegisterAdapterEthernet },
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_WIFI
|
||||
{ "wifi adpter", RegisterAdapterWifi },
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_LORA
|
||||
{ "lora adpter", LoraSx12xxSpiDeviceInit},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_ZIGBEE
|
||||
{ "zigbee adpter", RegisterAdapterZigbee},
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_COMMUNICATION_NB_IOT
|
||||
{ "NB-IoT adpter", RegisterAdapterNBIoT},
|
||||
#endif
|
||||
#ifdef CONNECTION_COMMUNICATION_BLUETOOTH
|
||||
{ "bluetooth adpter", RegisterAdapterBluetooth},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will init perception framework and all sub perception sensors
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int PerceptionFrameworkInit(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, "perception_framework", strlen("perception_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize perception_framework success.\n");
|
||||
AppInitDesc(perception_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init connection framework and all sub components
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int ConnectionFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
return AppInitDesc(connection_desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init system framework
|
||||
*
|
||||
*/
|
||||
int FrameworkInit()
|
||||
{
|
||||
#ifdef SENSOR_SENSORDEVICE
|
||||
PerceptionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef CONNECTION_ADAPTER
|
||||
ConnectionFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -14,8 +14,14 @@
|
||||
#include <string.h>
|
||||
#include <user_api.h>
|
||||
|
||||
extern int FrameworkInit();
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("hello world\n");
|
||||
printf("Hello, world!\n");
|
||||
FrameworkInit();
|
||||
return 0;
|
||||
}
|
||||
// int cppmain(void);
|
||||
|
||||
|
||||
|
||||
41
APP_Framework/Applications/sd_card_mount.c
Normal file
41
APP_Framework/Applications/sd_card_mount.c
Normal file
@@ -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 sd_card_mount.c
|
||||
* @brief Mount SD card when opened SDIO
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.19
|
||||
*/
|
||||
|
||||
#include "user_api/switch_api/user_api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(FS_VFS)
|
||||
#include <iot-vfs.h>
|
||||
|
||||
/**
|
||||
* @description: Mount SD card
|
||||
* @return 0
|
||||
*/
|
||||
int MountSDCard(void)
|
||||
{
|
||||
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, FSTYPE_FATFS, "/") == 0)
|
||||
DBG("sd card mount to '/'");
|
||||
else
|
||||
SYS_WARN("sd card mount to '/' failed!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),MountSDCard, MountSDCard, MountSDCard );
|
||||
23
APP_Framework/Applications/sensor_app/Makefile
Normal file
23
APP_Framework/Applications/sensor_app/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y)
|
||||
SRC_FILES += co2_zg09.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y)
|
||||
SRC_FILES += pm1_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
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
34
APP_Framework/Applications/sensor_app/co2_zg09.c
Normal file
34
APP_Framework/Applications/sensor_app/co2_zg09.c
Normal file
@@ -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_zg09.c
|
||||
* @brief ZG09 CO2 example
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.23
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#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);
|
||||
}
|
||||
35
APP_Framework/Applications/sensor_app/humidity_hs300x.c
Normal file
35
APP_Framework/Applications/sensor_app/humidity_hs300x.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a himidity
|
||||
* @return 0
|
||||
*/
|
||||
void HumiHs300x(void)
|
||||
{
|
||||
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
|
||||
SensorQuantityOpen(humi);
|
||||
int32 humidity = SensorQuantityRead(humi);
|
||||
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
|
||||
SensorQuantityClose(humi);
|
||||
}
|
||||
35
APP_Framework/Applications/sensor_app/pm1_0_ps5308.c
Normal file
35
APP_Framework/Applications/sensor_app/pm1_0_ps5308.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#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);
|
||||
UserTaskDelay(2000);
|
||||
printf("PM1.0 : %d ug/m³\n", SensorQuantityRead(pm1_0));
|
||||
SensorQuantityClose(pm1_0);
|
||||
}
|
||||
38
APP_Framework/Applications/sensor_app/temperature_hs300x.c
Normal file
38
APP_Framework/Applications/sensor_app/temperature_hs300x.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <user_api.h>
|
||||
#include <sensor.h>
|
||||
|
||||
/**
|
||||
* @description: Read a temperature
|
||||
* @return 0
|
||||
*/
|
||||
void TempHs300x(void)
|
||||
{
|
||||
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
|
||||
SensorQuantityOpen(temp);
|
||||
int32 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);
|
||||
SensorQuantityClose(temp);
|
||||
}
|
||||
36
APP_Framework/Applications/sensor_app/voice_d124.c
Normal file
36
APP_Framework/Applications/sensor_app/voice_d124.c
Normal file
@@ -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 <user_api.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);
|
||||
UserTaskDelay(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);
|
||||
}
|
||||
46
APP_Framework/Applications/spi_sd_card_mount.c
Normal file
46
APP_Framework/Applications/spi_sd_card_mount.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 spi_sd_card_mount.c
|
||||
* @brief Mount SD card when opened SPI SD card
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.04.01
|
||||
*/
|
||||
|
||||
#include "user_api/switch_api/user_api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(FS_VFS)
|
||||
#include <iot-vfs.h>
|
||||
|
||||
/**
|
||||
* @description: Mount SD card
|
||||
* @return 0
|
||||
*/
|
||||
int MountSDCard(void)
|
||||
{
|
||||
struct Bus *spi_bus;
|
||||
spi_bus = BusFind(SPI_BUS_NAME_1);
|
||||
|
||||
if (NONE == SpiSdInit(spi_bus, SPI_1_DEVICE_NAME_0, SPI_1_DRV_NAME, SPI_SD_NAME)) {
|
||||
KPrintf("MountSDCard SpiSdInit error!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (EOK == MountFilesystem(SPI_BUS_NAME_1, SPI_SD_NAME, SPI_1_DRV_NAME, FSTYPE_FATFS, "/"))
|
||||
KPrintf("SPI SD card fatfs mounted\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user