forked from xuos/xiuos
add 'TB600B_WQ_HCHO1OS' sensor of hcho to sensor framework
This commit is contained in:
parent
19edea21d7
commit
db225df433
|
@ -32,6 +32,7 @@ extern int Zg09Co2Init(void);
|
||||||
extern int As830Ch4Init(void);
|
extern int As830Ch4Init(void);
|
||||||
extern int Tb600bIaq10IaqInit(void);
|
extern int Tb600bIaq10IaqInit(void);
|
||||||
extern int Tb600bTvoc10TvocInit(void);
|
extern int Tb600bTvoc10TvocInit(void);
|
||||||
|
extern int Tb600bWqHcho1osInit(void);
|
||||||
|
|
||||||
typedef int (*InitFunc)(void);
|
typedef int (*InitFunc)(void);
|
||||||
struct InitDesc
|
struct InitDesc
|
||||||
|
@ -104,6 +105,10 @@ static struct InitDesc sensor_desc[] =
|
||||||
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
|
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SENSOR_TB600B_WQ_HCHO1OS
|
||||||
|
{ "tvoc_tb600b_wq_hcho1os", Tb600bWqHcho1osInit },
|
||||||
|
#endif
|
||||||
|
|
||||||
{ "NULL", NULL },
|
{ "NULL", NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,16 @@ menu "sensor app"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
if APPLICATION_SENSOR
|
if APPLICATION_SENSOR
|
||||||
|
menuconfig APPLICATION_SENSOR_HCHO
|
||||||
|
bool "Using sensor HCHO apps"
|
||||||
|
default n
|
||||||
|
|
||||||
|
if APPLICATION_SENSOR_HCHO
|
||||||
|
config APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS
|
||||||
|
bool "Using sensor TB600B_WQ_HCHO1OS apps"
|
||||||
|
default n
|
||||||
|
endif
|
||||||
|
|
||||||
menuconfig APPLICATION_SENSOR_TVOC
|
menuconfig APPLICATION_SENSOR_TVOC
|
||||||
bool "Using sensor TVOC apps"
|
bool "Using sensor TVOC apps"
|
||||||
default n
|
default n
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
SRC_FILES :=
|
SRC_FILES :=
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||||
|
SRC_FILES += hcho_tb600b_wq_hcho1os.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
|
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
|
||||||
SRC_FILES += tvoc_tb600b_tvoc10.c
|
SRC_FILES += tvoc_tb600b_tvoc10.c
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file hcho_tb600b_wq_hcho1os.c
|
||||||
|
* @brief hcho example
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021.12.15
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <user_api.h>
|
||||||
|
#include <sensor.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Read a hcho
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
void HchoTb600bHcho1os(void)
|
||||||
|
{
|
||||||
|
struct SensorQuantity *hcho = SensorQuantityFind(SENSOR_QUANTITY_TB600B_HCHO, SENSOR_QUANTITY_HCHO);
|
||||||
|
SensorQuantityOpen(hcho);
|
||||||
|
int32_t result = 0;
|
||||||
|
|
||||||
|
result = SensorQuantityRead(hcho);
|
||||||
|
|
||||||
|
printf("tvoc concentration is : %dppb\n", result);
|
||||||
|
SensorQuantityClose(hcho);
|
||||||
|
}
|
|
@ -4,6 +4,13 @@ menuconfig SUPPORT_SENSOR_FRAMEWORK
|
||||||
select TRANSFORM_LAYER_ATTRIUBUTE
|
select TRANSFORM_LAYER_ATTRIUBUTE
|
||||||
|
|
||||||
if SUPPORT_SENSOR_FRAMEWORK
|
if SUPPORT_SENSOR_FRAMEWORK
|
||||||
|
menuconfig SENSOR_HCHO
|
||||||
|
bool "Using HCHO sensor device"
|
||||||
|
default n
|
||||||
|
if SENSOR_HCHO
|
||||||
|
source "$APP_DIR/Framework/sensor/hcho/Kconfig"
|
||||||
|
endif
|
||||||
|
|
||||||
menuconfig SENSOR_TVOC
|
menuconfig SENSOR_TVOC
|
||||||
bool "Using TVOC sensor device"
|
bool "Using TVOC sensor device"
|
||||||
default n
|
default n
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
SRC_FILES := sensor.c
|
SRC_FILES := sensor.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SENSOR_HCHO),y)
|
||||||
|
SRC_DIR += hcho
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SENSOR_TVOC),y)
|
ifeq ($(CONFIG_SENSOR_TVOC),y)
|
||||||
SRC_DIR += tvoc
|
SRC_DIR += tvoc
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
config SENSOR_TB600B_WQ_HCHO1OS
|
||||||
|
bool "Using TB600B WQ_HCHO1OS"
|
||||||
|
default n
|
||||||
|
|
||||||
|
if SENSOR_TB600B_WQ_HCHO1OS
|
||||||
|
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS
|
||||||
|
string "tb600b wq_hcho1os sensor name"
|
||||||
|
default "tb600b_wq_hcho1os_1"
|
||||||
|
|
||||||
|
config SENSOR_QUANTITY_TB600B_HCHO
|
||||||
|
string "tb600b wq_hcho1os quantity name"
|
||||||
|
default "hcho_1"
|
||||||
|
|
||||||
|
if ADD_XIUOS_FETURES
|
||||||
|
config SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
|
||||||
|
bool "Using extra uart to support tb600b wq_hcho1os"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV
|
||||||
|
string "tb600b wq_hcho1os device uart path"
|
||||||
|
default "/dev/uart2_dev2"
|
||||||
|
depends on !SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
|
||||||
|
|
||||||
|
if SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
|
||||||
|
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV
|
||||||
|
string "tb600b wq_hcho1os device extra uart path"
|
||||||
|
default "/dev/extuart_dev5"
|
||||||
|
|
||||||
|
config SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV_EXT_PORT
|
||||||
|
int "if TB600B_WQ_HCHO1OS device using extuart, choose port"
|
||||||
|
default "5"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ADD_NUTTX_FETURES
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ADD_RTTHREAD_FETURES
|
||||||
|
|
||||||
|
endif
|
||||||
|
endif
|
|
@ -0,0 +1,5 @@
|
||||||
|
ifeq ($(CONFIG_SENSOR_TB600B_WQ_HCHO1OS),y)
|
||||||
|
SRC_DIR += tb600b_wq_hcho1os
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,3 @@
|
||||||
|
SRC_FILES := tb600b_wq_hcho1os.c
|
||||||
|
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* 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 wq_hcho1os.c
|
||||||
|
* @brief wq_hcho1os driver base sensor
|
||||||
|
* @version 1.0
|
||||||
|
* @author AIIT XUOS Lab
|
||||||
|
* @date 2021.12.15
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sensor.h>
|
||||||
|
|
||||||
|
static struct SensorDevice wq_hcho1os;
|
||||||
|
static uint8_t ReadInstruction[9];
|
||||||
|
|
||||||
|
static struct SensorProductInfo info =
|
||||||
|
{
|
||||||
|
SENSOR_ABILITY_HCHO,
|
||||||
|
"AQS",
|
||||||
|
"TB600B_WQ_HCHO1OS",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Open TB600B WQ_HCHO1OS sensor device
|
||||||
|
* @param sdev - sensor device pointer
|
||||||
|
* @return success: 1 , failure: other
|
||||||
|
*/
|
||||||
|
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
sdev->fd = PrivOpen(SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV, O_RDWR);
|
||||||
|
if (sdev->fd < 0) {
|
||||||
|
printf("open %s error\n", SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SerialDataCfg cfg;
|
||||||
|
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||||
|
cfg.serial_data_bits = DATA_BITS_8;
|
||||||
|
cfg.serial_stop_bits = STOP_BITS_1;
|
||||||
|
cfg.serial_buffer_size = 128;
|
||||||
|
cfg.serial_parity_mode = PARITY_NONE;
|
||||||
|
cfg.serial_bit_order = 0;
|
||||||
|
cfg.serial_invert_mode = 0;
|
||||||
|
#ifdef SENSOR_TB600B_WQ_HCHO1OS_DRIVER_EXTUART
|
||||||
|
cfg.ext_uart_no = SENSOR_DEVICE_TB600B_WQ_HCHO1OS_DEV_EXT_PORT;
|
||||||
|
cfg.port_configure = PORT_CFG_INIT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct PrivIoctlCfg ioctl_cfg;
|
||||||
|
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||||
|
ioctl_cfg.args = &cfg;
|
||||||
|
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 get data length
|
||||||
|
*/
|
||||||
|
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||||
|
{
|
||||||
|
uint8_t tmp = 0;
|
||||||
|
uint8_t idx = 0;
|
||||||
|
|
||||||
|
/* this instruction will read gas with temperature and humidity,return 9 datas*/
|
||||||
|
ReadInstruction[0] = 0xFF;
|
||||||
|
ReadInstruction[1] = 0x01;
|
||||||
|
ReadInstruction[2] = 0x86;
|
||||||
|
ReadInstruction[3] = 0x00;
|
||||||
|
ReadInstruction[4] = 0x00;
|
||||||
|
ReadInstruction[5] = 0x00;
|
||||||
|
ReadInstruction[6] = 0x00;
|
||||||
|
ReadInstruction[7] = 0x00;
|
||||||
|
ReadInstruction[8] = 0x79;
|
||||||
|
|
||||||
|
PrivWrite(sdev->fd, ReadInstruction, 9);
|
||||||
|
|
||||||
|
for(idx = 0; idx < 9; idx++)
|
||||||
|
{
|
||||||
|
if (PrivRead(sdev->fd, &tmp, 1) == 1) {
|
||||||
|
sdev->buffer[idx] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: Read sensor device
|
||||||
|
* @param sdev - sensor device pointer
|
||||||
|
* @param len - the length of the read data
|
||||||
|
* @return get data length
|
||||||
|
*/
|
||||||
|
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
|
||||||
|
{
|
||||||
|
return PrivWrite(sdev->fd, buf, len);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct SensorDone done =
|
||||||
|
{
|
||||||
|
SensorDeviceOpen,
|
||||||
|
NULL,
|
||||||
|
SensorDeviceRead,
|
||||||
|
SensorDeviceWrite,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Init TB600B WQ_HCHO1OS sensor and register
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
static void SensorDeviceTb600bHcho1osInit(void)
|
||||||
|
{
|
||||||
|
wq_hcho1os.name = SENSOR_DEVICE_TB600B_WQ_HCHO1OS;
|
||||||
|
wq_hcho1os.info = &info;
|
||||||
|
wq_hcho1os.done = &done;
|
||||||
|
|
||||||
|
SensorDeviceRegister(&wq_hcho1os);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct SensorQuantity wq_hcho1os_hcho;
|
||||||
|
|
||||||
|
/* check data*/
|
||||||
|
static uint8_t getCheckSum(uint8_t *packet)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t checksum = 0;
|
||||||
|
for( i = 1; i < 12; i++)
|
||||||
|
{
|
||||||
|
checksum += packet[i];
|
||||||
|
}
|
||||||
|
checksum = ~checksum + 1;
|
||||||
|
|
||||||
|
return checksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Analysis TB600B WQ_HCHO1OS result
|
||||||
|
* @param quant - sensor quantity pointer
|
||||||
|
* @return quantity value
|
||||||
|
*/
|
||||||
|
static int32_t QuantityRead(struct SensorQuantity *quant)
|
||||||
|
{
|
||||||
|
if (!quant)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
uint32_t len = 0;
|
||||||
|
uint8_t checksum = 0;
|
||||||
|
uint16_t ppb, ugm3;
|
||||||
|
|
||||||
|
if (quant->sdev->done->read != NULL) {
|
||||||
|
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
|
||||||
|
len = quant->sdev->done->read(quant->sdev, 9);
|
||||||
|
if (len == 0)
|
||||||
|
{
|
||||||
|
printf("error read data length = 0.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
checksum = getCheckSum(quant->sdev->buffer);
|
||||||
|
if(checksum == quant->sdev->buffer[8])
|
||||||
|
{
|
||||||
|
ugm3 = (uint16_t)quant->sdev->buffer[2] * 256 + (uint16_t)quant->sdev->buffer[3];
|
||||||
|
ppb = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16_t)quant->sdev->buffer[7];
|
||||||
|
|
||||||
|
printf("Formaldehyde concentration is : %dug/m³(%dppb)\n", ugm3, ppb);
|
||||||
|
return ppb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("This reading is wrong\n");
|
||||||
|
return SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE)
|
||||||
|
{
|
||||||
|
printf("Please set passive mode.\n");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
printf("%s don't have read done.\n", quant->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Init TB600B WQ_HCHO1OS quantity and register
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
int Tb600bWqHcho1osInit(void)
|
||||||
|
{
|
||||||
|
SensorDeviceTb600bHcho1osInit();
|
||||||
|
|
||||||
|
wq_hcho1os_hcho.name = SENSOR_QUANTITY_TB600B_HCHO;
|
||||||
|
wq_hcho1os_hcho.type = SENSOR_QUANTITY_HCHO;
|
||||||
|
wq_hcho1os_hcho.value.decimal_places = 0;
|
||||||
|
wq_hcho1os_hcho.value.max_std = SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
wq_hcho1os_hcho.value.min_std = SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
wq_hcho1os_hcho.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
wq_hcho1os_hcho.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
wq_hcho1os_hcho.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
|
||||||
|
wq_hcho1os_hcho.sdev = &wq_hcho1os;
|
||||||
|
wq_hcho1os_hcho.ReadValue = QuantityRead;
|
||||||
|
|
||||||
|
SensorQuantityRegister(&wq_hcho1os_hcho);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -54,6 +54,7 @@ extern "C" {
|
||||||
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
|
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
|
||||||
#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ))
|
#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ))
|
||||||
#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC))
|
#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC))
|
||||||
|
#define SENSOR_ABILITY_HCHO ((uint32_t)(1 << SENSOR_QUANTITY_HCHO))
|
||||||
|
|
||||||
struct SensorProductInfo {
|
struct SensorProductInfo {
|
||||||
uint32_t ability; /* Bitwise OR of sensor ability */
|
uint32_t ability; /* Bitwise OR of sensor ability */
|
||||||
|
|
Loading…
Reference in New Issue