Browse Source

add 'TB600B_TVOC10' sensor of tvoc to sensor framework

pull/117/head
Wang_Weigen 8 months ago
parent
commit
19edea21d7
  1. 5
      APP_Framework/Applications/framework_init.c
  2. 10
      APP_Framework/Applications/sensor_app/Kconfig
  3. 4
      APP_Framework/Applications/sensor_app/Makefile
  4. 39
      APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c
  5. 7
      APP_Framework/Framework/sensor/Kconfig
  6. 4
      APP_Framework/Framework/sensor/Makefile
  7. 10
      APP_Framework/Framework/sensor/iaq/tb600b_iaq10/tb600b_iaq10.c
  8. 2
      APP_Framework/Framework/sensor/sensor.h
  9. 43
      APP_Framework/Framework/sensor/tvoc/Kconfig
  10. 5
      APP_Framework/Framework/sensor/tvoc/Makefile
  11. 3
      APP_Framework/Framework/sensor/tvoc/tb600b_tvoc10/Makefile
  12. 227
      APP_Framework/Framework/sensor/tvoc/tb600b_tvoc10/tb600b_tvoc10.c

5
APP_Framework/Applications/framework_init.c

@ -31,6 +31,7 @@ extern int Ps5308Pm1_0Init(void);
extern int Zg09Co2Init(void);
extern int As830Ch4Init(void);
extern int Tb600bIaq10IaqInit(void);
extern int Tb600bTvoc10TvocInit(void);
typedef int (*InitFunc)(void);
struct InitDesc
@ -99,6 +100,10 @@ static struct InitDesc sensor_desc[] =
{ "iaq_tb600b_iaq10", Tb600bIaq10IaqInit },
#endif
#ifdef SENSOR_TB600B_TVOC10
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
#endif
{ "NULL", NULL },
};

10
APP_Framework/Applications/sensor_app/Kconfig

@ -5,6 +5,16 @@ menu "sensor app"
default n
if APPLICATION_SENSOR
menuconfig APPLICATION_SENSOR_TVOC
bool "Using sensor TVOC apps"
default n
if APPLICATION_SENSOR_TVOC
config APPLICATION_SENSOR_TVOC_TB600B_TVOC10
bool "Using sensor TB600B_TVOC10 apps"
default n
endif
menuconfig APPLICATION_SENSOR_IAQ
bool "Using sensor IAQ apps"
default n

4
APP_Framework/Applications/sensor_app/Makefile

@ -1,5 +1,9 @@
SRC_FILES :=
ifeq ($(CONFIG_APPLICATION_SENSOR_TVOC_TB600B_TVOC10), y)
SRC_FILES += tvoc_tb600b_tvoc10.c
endif
ifeq ($(CONFIG_APPLICATION_SENSOR_IAQ_TB600B_IAQ10), y)
SRC_FILES += iaq_tb600b_iaq10.c
endif

39
APP_Framework/Applications/sensor_app/tvoc_tb600b_tvoc10.c

@ -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 tvoc_tb600b_tvoc10.c
* @brief tvoc10 example
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <user_api.h>
#include <sensor.h>
/**
* @description: Read a tvoc
* @return 0
*/
void TvocTb600bTvoc10(void)
{
struct SensorQuantity *tvoc = SensorQuantityFind(SENSOR_QUANTITY_TB600B_TVOC, SENSOR_QUANTITY_TVOC);
SensorQuantityOpen(tvoc);
int32_t result = 0;
result = SensorQuantityRead(tvoc);
printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(tvoc);
}

7
APP_Framework/Framework/sensor/Kconfig

@ -4,6 +4,13 @@ menuconfig SUPPORT_SENSOR_FRAMEWORK
select TRANSFORM_LAYER_ATTRIUBUTE
if SUPPORT_SENSOR_FRAMEWORK
menuconfig SENSOR_TVOC
bool "Using TVOC sensor device"
default n
if SENSOR_TVOC
source "$APP_DIR/Framework/sensor/tvoc/Kconfig"
endif
menuconfig SENSOR_IAQ
bool "Using IAQ sensor device"
default n

4
APP_Framework/Framework/sensor/Makefile

@ -1,5 +1,9 @@
SRC_FILES := sensor.c
ifeq ($(CONFIG_SENSOR_TVOC),y)
SRC_DIR += tvoc
endif
ifeq ($(CONFIG_SENSOR_IAQ),y)
SRC_DIR += iaq
endif

10
APP_Framework/Framework/sensor/iaq/tb600b_iaq10/tb600b_iaq10.c

@ -39,7 +39,7 @@ static struct SensorProductInfo info =
};
/**
* @description: Open AS830 sensor device
* @description: Open tb600b_iaq10 sensor device
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
@ -130,7 +130,7 @@ static struct SensorDone done =
};
/**
* @description: Init AS830 sensor and register
* @description: Init tb600b_iaq10 sensor and register
* @return void
*/
static void SensorDeviceTb600bIaq10Init(void)
@ -159,7 +159,7 @@ static uint8_t getCheckSum(uint8_t *packet)
}
/**
* @description: Analysis AS830 CH4 result
* @description: Analysis tb600b_iaq10 result
* @param quant - sensor quantity pointer
* @return quantity value
*/
@ -185,7 +185,7 @@ static int32_t QuantityRead(struct SensorQuantity *quant)
checksum = getCheckSum(quant->sdev->buffer);
if(checksum == quant->sdev->buffer[12])
{
result.gas = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16)quant->sdev->buffer[7];
result.gas = (uint16_t)quant->sdev->buffer[6] * 256 + (uint16_t)quant->sdev->buffer[7];
result.TH = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))/100;
result.TL = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))%100;
result.RhH = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))/100;
@ -211,7 +211,7 @@ static int32_t QuantityRead(struct SensorQuantity *quant)
}
/**
* @description: Init AS830 CH4 quantity and register
* @description: Init tb600b_iaq10 quantity and register
* @return 0
*/
int Tb600bIaq10IaqInit(void)

2
APP_Framework/Framework/sensor/sensor.h

@ -53,6 +53,7 @@ extern "C" {
#define SENSOR_ABILITY_VOICE ((uint32_t)(1 << SENSOR_QUANTITY_VOICE))
#define SENSOR_ABILITY_CH4 ((uint32_t)(1 << SENSOR_QUANTITY_CH4))
#define SENSOR_ABILITY_IAQ ((uint32_t)(1 << SENSOR_QUANTITY_IAQ))
#define SENSOR_ABILITY_TVOC ((uint32_t)(1 << SENSOR_QUANTITY_TVOC))
struct SensorProductInfo {
uint32_t ability; /* Bitwise OR of sensor ability */
@ -93,6 +94,7 @@ enum SensorQuantityType {
SENSOR_QUANTITY_VOICE,
SENSOR_QUANTITY_CH4,
SENSOR_QUANTITY_IAQ,
SENSOR_QUANTITY_TVOC,
/* ...... */
SENSOR_QUANTITY_END,
};

43
APP_Framework/Framework/sensor/tvoc/Kconfig

@ -0,0 +1,43 @@
config SENSOR_TB600B_TVOC10
bool "Using TB600B TVOC10"
default n
if SENSOR_TB600B_TVOC10
config SENSOR_DEVICE_TB600B_TVOC10
string "tb600b tvoc10 sensor name"
default "tb600b_tvoc10_1"
config SENSOR_QUANTITY_TB600B_TVOC
string "tb600b tvoc10 quantity name"
default "tvoc_1"
if ADD_XIUOS_FETURES
config SENSOR_TB600B_TVOC10_DRIVER_EXTUART
bool "Using extra uart to support tb600b tvoc10"
default y
config SENSOR_DEVICE_TB600B_TVOC10_DEV
string "tb600b tvoc10 device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_TB600B_TVOC10_DRIVER_EXTUART
if SENSOR_TB600B_TVOC10_DRIVER_EXTUART
config SENSOR_DEVICE_TB600B_TVOC10_DEV
string "tb600b tvoc10 device extra uart path"
default "/dev/extuart_dev6"
config SENSOR_DEVICE_TB600B_TVOC10_DEV_EXT_PORT
int "if TB600B_TVOC10 device using extuart, choose port"
default "6"
endif
endif
if ADD_NUTTX_FETURES
endif
if ADD_RTTHREAD_FETURES
endif
endif

5
APP_Framework/Framework/sensor/tvoc/Makefile

@ -0,0 +1,5 @@
ifeq ($(CONFIG_SENSOR_TB600B_TVOC10),y)
SRC_DIR += tb600b_tvoc10
endif
include $(KERNEL_ROOT)/compiler.mk

3
APP_Framework/Framework/sensor/tvoc/tb600b_tvoc10/Makefile

@ -0,0 +1,3 @@
SRC_FILES := tb600b_tvoc10.c
include $(KERNEL_ROOT)/compiler.mk

227
APP_Framework/Framework/sensor/tvoc/tb600b_tvoc10/tb600b_tvoc10.c

@ -0,0 +1,227 @@
/*
* 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 tb600b_tvoc10.c
* @brief tb600b_tvoc10 driver base sensor
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.12.15
*/
#include <sensor.h>
static struct SensorDevice tb600b_tvoc10;
static uint8_t ReadInstruction[9];
static struct SensorProductInfo info =
{
SENSOR_ABILITY_TVOC,
"AQS",
"TB600B_TVOC10",
};
/**
* @description: Open TB600B TVOC10 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_TVOC10_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_TB600B_TVOC10_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_TVOC10_DRIVER_EXTUART
cfg.ext_uart_no = SENSOR_DEVICE_TB600B_TVOC10_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 13 datas*/
ReadInstruction[0] = 0xFF;
ReadInstruction[1] = 0x01;
ReadInstruction[2] = 0x87;
ReadInstruction[3] = 0x00;
ReadInstruction[4] = 0x00;
ReadInstruction[5] = 0x00;
ReadInstruction[6] = 0x00;
ReadInstruction[7] = 0x00;
ReadInstruction[8] = 0x78;
PrivWrite(sdev->fd, ReadInstruction, 9);
for(idx = 0; idx < 13; 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 TVOC10 sensor and register
* @return void
*/
static void SensorDeviceTb600bTvoc10Init(void)
{
tb600b_tvoc10.name = SENSOR_DEVICE_TB600B_TVOC10;
tb600b_tvoc10.info = &info;
tb600b_tvoc10.done = &done;
SensorDeviceRegister(&tb600b_tvoc10);
}
static struct SensorQuantity tb600b_tvoc10_tvoc;
/* 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 TVOC10 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;
uint8_t TH, TL, RhH, RhL;
uint16_t ppb, ugm3;
if (quant->sdev->done->read != NULL) {
if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
len = quant->sdev->done->read(quant->sdev, 13);
if (len == 0)
{
printf("error read data length = 0.\n");
return -1;
}
checksum = getCheckSum(quant->sdev->buffer);
if(checksum == quant->sdev->buffer[12])
{
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];
TH = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))/100;
TL = ((int)((quant->sdev->buffer[8] << 8)|quant->sdev->buffer[9]))%100;
RhH = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))/100;
RhL = ((unsigned int)((quant->sdev->buffer[10] << 8)|quant->sdev->buffer[11]))%100;
printf("tvoc concentration is : %dug/m³(%dppb)\nThe temperature is : %d.%d℃\nThe humidity is : %d.%drh%%\n", ugm3, ppb, TH, TL, RhH, RhL);
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 TVOC10 quantity and register
* @return 0
*/
int Tb600bTvoc10TvocInit(void)
{
SensorDeviceTb600bTvoc10Init();
tb600b_tvoc10_tvoc.name = SENSOR_QUANTITY_TB600B_TVOC;
tb600b_tvoc10_tvoc.type = SENSOR_QUANTITY_TVOC;
tb600b_tvoc10_tvoc.value.decimal_places = 0;
tb600b_tvoc10_tvoc.value.max_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.min_std = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.last_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.max_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.value.min_value = SENSOR_QUANTITY_VALUE_ERROR;
tb600b_tvoc10_tvoc.sdev = &tb600b_tvoc10;
tb600b_tvoc10_tvoc.ReadValue = QuantityRead;
SensorQuantityRegister(&tb600b_tvoc10_tvoc);
return 0;
}
Loading…
Cancel
Save