fix APP_Framework bugs,include sensor framework and Applications
it is OK
This commit is contained in:
commit
cc6c459e7b
|
@ -4,14 +4,6 @@ menu "test app"
|
|||
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
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
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
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#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
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
SRC_DIR :=wifi_demo
|
||||
SRC_DIR :=
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES := client.c gateway.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,108 +0,0 @@
|
|||
#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");
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#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");
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES := bluetooth_receive_demo.c bluetooth_send_demo.c
|
||||
# zigbee_send_demo.c zigbee_receive_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES := ethernet_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,197 +0,0 @@
|
|||
/*
|
||||
* 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);
|
||||
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES :=nbiot_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES :=wifi_demo.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,223 +0,0 @@
|
|||
/*
|
||||
* 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 <at_agent.h>
|
||||
#include <adapter.h>
|
||||
|
||||
void SendWiftMsg(int argc, char *argv[])
|
||||
{
|
||||
char wifi_msg[128];
|
||||
int len;
|
||||
if (argc >= 1) {
|
||||
memset(wifi_msg, 0, 128);
|
||||
strncpy(wifi_msg, argv[1], (len = strlen(argv[1])));
|
||||
printf("SendWiftMsg(%s).\n", wifi_msg);
|
||||
}
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
AdapterDeviceSend(adapter, wifi_msg, len);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), SendWiftMsg, SendWiftMsg, SendWiftMsg);
|
||||
|
||||
void RecvWifiMsg()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
while (1) {
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
if (EOK == AdapterDeviceRecv(adapter, wifi_recv_msg, 128)) {
|
||||
printf("wifi_recv_msg (%s)\n", wifi_recv_msg);
|
||||
} else {
|
||||
printf("wifi_recv_msg failed .\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), RecvWifiMsg, RecvWifiMsg, RecvWifiMsg);
|
||||
|
||||
void SetUpWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
if (EOK == AdapterDeviceSetUp(adapter)) {
|
||||
printf("SetUpWifi success \n");
|
||||
} else {
|
||||
printf("SetUpWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetUpWifi, SetUpWifi, SetUpWifi);
|
||||
|
||||
void SetDownWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDeviceSetDown(adapter)) {
|
||||
printf("SetDownWifi success \n");
|
||||
} else {
|
||||
printf("SetDownWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetDownWifi, SetDownWifi, SetDownWifi);
|
||||
|
||||
void SetAddrWifi()
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if(EOK == AdapterDeviceSetAddr(adapter, "192.168.66.253", "255.255.255.0", "192.168.66.1")){
|
||||
printf("SetAddrWifi success \n");
|
||||
} else {
|
||||
printf("SetAddrWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), SetAddrWifi, SetAddrWifi, SetAddrWifi);
|
||||
|
||||
void PingWifi()
|
||||
{
|
||||
char wifi_recv_msg[128];
|
||||
memset(wifi_recv_msg, 0, sizeof(wifi_recv_msg));
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
//www.baidu.com
|
||||
char *ip_str = "36.152.44.95";
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDevicePing(adapter, ip_str)) {
|
||||
printf("PingWifi success \n");
|
||||
} else {
|
||||
printf("PingWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), PingWifi, PingWifi, PingWifi);
|
||||
|
||||
void NetstatWifi()
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDeviceNetstat(adapter)) {
|
||||
printf("NetstatWifi success \n");
|
||||
} else {
|
||||
printf("NetstatWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), NetstatWifi, NetstatWifi, NetstatWifi);
|
||||
|
||||
int ConnectWifi()
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
||||
const char *ip = "192.168.66.33";
|
||||
const char *port = "12345";
|
||||
enum NetRoleType net_role = CLIENT;
|
||||
enum IpType ip_type = IPV4;
|
||||
|
||||
if (!adapter) {
|
||||
printf("ATAdapterFind failed .\n");
|
||||
}
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
|
||||
if (EOK == AdapterDeviceConnect(adapter, net_role, ip, port, ip_type)) {
|
||||
printf("ConnectWifi success \n");
|
||||
} else {
|
||||
printf("ConnectWifi failed \n");
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0), ConnectWifi, ConnectWifi, ConnectWifi);
|
||||
|
||||
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 Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
// AdapterDeviceOpen(adapter);
|
||||
|
||||
printf("Waiting for msg...\n");
|
||||
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
UserTaskDelay(100);
|
||||
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "a");
|
||||
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,cmd);
|
||||
UserTaskDelay(2500);
|
||||
|
||||
ATOrderSend(adapter->agent,REPLY_TIME_OUT, NULL,"AT+Z\r");
|
||||
UserTaskDelay(5000);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(0), AtTestCmdWifi, AtTestCmdWifi, AtTestCmdWifi);
|
|
@ -1,3 +0,0 @@
|
|||
SRC_FILES := zigbee_receive_demo.c
|
||||
# zigbee_send_demo.c zigbee_receive_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
|
|
@ -27,9 +27,14 @@
|
|||
*/
|
||||
void HumiHs300x(void)
|
||||
{
|
||||
int i = 0;
|
||||
int32 humidity;
|
||||
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);
|
||||
for (i = 0; i < 100; i ++) {
|
||||
humidity = SensorQuantityRead(humi);
|
||||
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
|
||||
PrivTaskDelay(5000);
|
||||
}
|
||||
SensorQuantityClose(humi);
|
||||
}
|
|
@ -27,12 +27,20 @@
|
|||
*/
|
||||
void TempHs300x(void)
|
||||
{
|
||||
int i = 0;
|
||||
int32 temperature;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, TempHs300x, TempHs300x, TempHs300x function);
|
||||
|
|
|
@ -40,6 +40,10 @@ 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;
|
||||
|
|
|
@ -43,6 +43,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
int result = 0;
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_ZG09_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||
|
|
|
@ -16,6 +16,10 @@ config SENSOR_HS300X
|
|||
config SENSOR_DEVICE_HS300X_DEV
|
||||
string "HS300x device name"
|
||||
default "/dev/i2c1_dev0"
|
||||
|
||||
config SENSOR_DEVICE_HS300X_I2C_ADDR
|
||||
hex "HS300x device i2c address"
|
||||
default 0x44
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
|
|
@ -32,28 +32,43 @@ static struct SensorProductInfo info =
|
|||
/**
|
||||
* @description: Open HS300x sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @return 1
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result;
|
||||
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
|
||||
|
||||
return 0;
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
|
||||
ioctl_cfg.args = &i2c_dev_addr;
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Read sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @param len - the length of the read data
|
||||
* @return success: 1 , failure: -1
|
||||
* @return success: 0 , failure: -1
|
||||
*/
|
||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
{
|
||||
//send i2c device start signal and address, need to implemente in OS i2c driver
|
||||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
|
||||
PrivTaskDelay(50);
|
||||
|
||||
//Read i2c device data from i2c device address
|
||||
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -58,6 +58,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
PrivMutexCreate(&buff_lock, 0);
|
||||
|
||||
sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_PS5308_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||
|
|
|
@ -16,6 +16,10 @@ config SENSOR_HS300X
|
|||
config SENSOR_DEVICE_HS300X_DEV
|
||||
string "HS300x device name"
|
||||
default "/dev/i2c1_dev0"
|
||||
|
||||
config SENSOR_DEVICE_HS300X_I2C_ADDR
|
||||
hex "HS300x device i2c address"
|
||||
default 0x44
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
|
|
@ -32,28 +32,42 @@ static struct SensorProductInfo info =
|
|||
/**
|
||||
* @description: Open HS300x sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @return 1
|
||||
* @return success : 0 error : -1
|
||||
*/
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result;
|
||||
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
|
||||
ioctl_cfg.args = &i2c_dev_addr;
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Read sensor device
|
||||
* @param sdev - sensor device pointer
|
||||
* @param len - the length of the read data
|
||||
* @return success: 1 , failure: -1
|
||||
* @return success: 0 , failure: -1
|
||||
*/
|
||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
{
|
||||
//send i2c device start signal and address, need to implemente in OS i2c driver
|
||||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
|
||||
PrivTaskDelay(50);
|
||||
|
||||
//Read i2c device data from i2c device address
|
||||
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
|
||||
return -1;
|
||||
|
||||
|
@ -101,6 +115,7 @@ static int32_t ReadTemperature(struct SensorQuantity *quant)
|
|||
if (quant->sdev->done->read != NULL) {
|
||||
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
||||
quant->sdev->done->read(quant->sdev, 4);
|
||||
PrivTaskDelay(50);
|
||||
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
|
||||
result = ((quant->sdev->buffer[2] << 8 | quant->sdev->buffer[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0;
|
||||
|
||||
|
|
|
@ -59,6 +59,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
PrivMutexCreate(&buff_lock, 0);
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("open %s error\n", SENSOR_DEVICE_D124_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||
|
|
|
@ -151,6 +151,9 @@ int PrivIoctl(int fd, int cmd, void *args)
|
|||
case PIN_TYPE:
|
||||
ret = PrivPinIoctl(fd, cmd, ioctl_cfg->args);
|
||||
break;
|
||||
case I2C_TYPE:
|
||||
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -604,6 +604,41 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(i2c_drv);
|
||||
|
||||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
|
||||
|
||||
if (configure_info->private_data) {
|
||||
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
KPrintf("I2cInit need set i2c dev addr\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
|
||||
|
||||
switch (configure_info->configure_cmd)
|
||||
{
|
||||
case OPE_INT:
|
||||
ret = I2cInit(i2c_drv, configure_info);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the i2c device operations*/
|
||||
static const struct I2cDevDone i2c_dev_done =
|
||||
{
|
||||
|
@ -681,6 +716,8 @@ int Stm32HwI2cInit(void)
|
|||
#ifdef BSP_USING_I2C1
|
||||
I2cGpioInit(&i2c_bus_param);
|
||||
|
||||
i2c_driver.configure = I2cDrvConfigure;
|
||||
|
||||
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
|
|
|
@ -512,6 +512,41 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(i2c_drv);
|
||||
|
||||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
|
||||
|
||||
if (configure_info->private_data) {
|
||||
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
KPrintf("I2cInit need set i2c dev addr\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
|
||||
|
||||
switch (configure_info->configure_cmd)
|
||||
{
|
||||
case OPE_INT:
|
||||
ret = I2cInit(i2c_drv, configure_info);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the i2c device operations*/
|
||||
static const struct I2cDevDone i2c_dev_done =
|
||||
{
|
||||
|
@ -589,6 +624,8 @@ int HwI2cInit(void)
|
|||
#ifdef BSP_USING_I2C1
|
||||
I2cGpioInit(&i2c_bus_param);
|
||||
|
||||
i2c_driver.configure = I2cDrvConfigure;
|
||||
|
||||
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
|
|
|
@ -500,6 +500,41 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(i2c_drv);
|
||||
|
||||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
|
||||
|
||||
if (configure_info->private_data) {
|
||||
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
KPrintf("I2cInit need set i2c dev addr\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
|
||||
|
||||
switch (configure_info->configure_cmd)
|
||||
{
|
||||
case OPE_INT:
|
||||
ret = I2cInit(i2c_drv, configure_info);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the i2c device operations*/
|
||||
static const struct I2cDevDone i2c_dev_done =
|
||||
{
|
||||
|
@ -577,6 +612,8 @@ int HwI2cInit(void)
|
|||
#ifdef BSP_USING_I2C1
|
||||
I2cGpioInit(&i2c_bus_param);
|
||||
|
||||
i2c_driver.configure = I2cDrvConfigure;
|
||||
|
||||
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
|
|
|
@ -600,6 +600,41 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(i2c_drv);
|
||||
|
||||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev;
|
||||
|
||||
if (configure_info->private_data) {
|
||||
i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
KPrintf("I2cInit need set i2c dev addr\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
|
||||
|
||||
switch (configure_info->configure_cmd)
|
||||
{
|
||||
case OPE_INT:
|
||||
ret = I2cInit(i2c_drv, configure_info);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the i2c device operations*/
|
||||
static const struct I2cDevDone i2c_dev_done =
|
||||
{
|
||||
|
@ -677,6 +712,8 @@ int Stm32HwI2cInit(void)
|
|||
#ifdef BSP_USING_I2C1
|
||||
I2cGpioInit(&i2c_bus_param);
|
||||
|
||||
i2c_driver.configure = I2cDrvConfigure;
|
||||
|
||||
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
|
|
|
@ -64,6 +64,8 @@ int I2cDriverInit(struct I2cDriver *i2c_driver, const char *driver_name)
|
|||
|
||||
i2c_driver->driver.private_data = i2c_driver->private_data;
|
||||
|
||||
i2c_driver->driver.configure = i2c_driver->configure;
|
||||
|
||||
ret = I2cDriverRegister(&i2c_driver->driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("I2cDriverInit DriverRegister error %u\n", ret);
|
||||
|
|
|
@ -37,7 +37,7 @@ static uint32 I2cDeviceWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)dev;
|
||||
struct I2cDataStandard i2c_msg;
|
||||
|
||||
i2c_msg.addr = I2C_SLAVE_ADDR;
|
||||
i2c_msg.addr = i2c_dev->i2c_dev_addr;
|
||||
i2c_msg.flags = I2C_WR;
|
||||
i2c_msg.buf = NONE;
|
||||
i2c_msg.len = 0;
|
||||
|
@ -55,7 +55,7 @@ static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)dev;
|
||||
struct I2cDataStandard i2c_msg;
|
||||
|
||||
i2c_msg.addr = I2C_SLAVE_ADDR;
|
||||
i2c_msg.addr = i2c_dev->i2c_dev_addr;
|
||||
i2c_msg.flags = I2C_RD;
|
||||
i2c_msg.buf = read_param->buffer;
|
||||
i2c_msg.len = read_param->size;
|
||||
|
|
|
@ -55,6 +55,8 @@ struct I2cDriver
|
|||
{
|
||||
struct Driver driver;
|
||||
|
||||
uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info);
|
||||
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define I2C_SLAVE_ADDR 0x44
|
||||
#define I2C_WR 0x0000
|
||||
#define I2C_RD (1u << 0)
|
||||
#define I2C_ADDR_10BIT (1u << 2)
|
||||
|
@ -61,7 +60,7 @@ struct I2cHardwareDevice
|
|||
struct HardwareDev haldev;
|
||||
const struct I2cDevDone *i2c_dev_done;
|
||||
|
||||
void *private_data;
|
||||
uint16 i2c_dev_addr;
|
||||
};
|
||||
|
||||
/*Register the I2C device*/
|
||||
|
|
Loading…
Reference in New Issue