diff --git a/APP_Framework/Applications/sensor_app/Kconfig b/APP_Framework/Applications/sensor_app/Kconfig index 12eaa816b..fbab69a78 100755 --- a/APP_Framework/Applications/sensor_app/Kconfig +++ b/APP_Framework/Applications/sensor_app/Kconfig @@ -53,6 +53,10 @@ menu "sensor app" config APPLICATION_SENSOR_CO2_ZG09 bool "Using sensor ZG09 apps" default n + + config APPLICATION_SENSOR_CO2_G8S + bool "Using sensor G8S apps" + default n endif menuconfig APPLICATION_SENSOR_PM1_0 diff --git a/APP_Framework/Applications/sensor_app/Makefile b/APP_Framework/Applications/sensor_app/Makefile index 857d11d75..54daa1592 100644 --- a/APP_Framework/Applications/sensor_app/Makefile +++ b/APP_Framework/Applications/sensor_app/Makefile @@ -74,6 +74,10 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y) SRC_FILES += co2_zg09.c endif + ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y) + SRC_FILES += co2_g8s.c + endif + ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) SRC_FILES += pm1_0_ps5308.c endif diff --git a/APP_Framework/Applications/sensor_app/co2_g8s.c b/APP_Framework/Applications/sensor_app/co2_g8s.c new file mode 100644 index 000000000..684a63d7a --- /dev/null +++ b/APP_Framework/Applications/sensor_app/co2_g8s.c @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file co2_g8s.c + * @brief G8S CO2 example + * @version 1.1 + * @author AIIT XUOS Lab + * @date 2021.12.23 + */ + +#include +#include + +/** + * @description: Read a CO2 + * @return 0 + */ +void Co2G8s(void) +{ + struct SensorQuantity *co2 = SensorQuantityFind(SENSOR_QUANTITY_G8S_CO2, SENSOR_QUANTITY_CO2); + SensorQuantityOpen(co2); + printf("CO2 : %d ppm\n", SensorQuantityRead(co2)); + SensorQuantityClose(co2); +} \ No newline at end of file diff --git a/APP_Framework/Framework/sensor/co2/Kconfig b/APP_Framework/Framework/sensor/co2/Kconfig index 5b5701d41..da5581985 100644 --- a/APP_Framework/Framework/sensor/co2/Kconfig +++ b/APP_Framework/Framework/sensor/co2/Kconfig @@ -46,3 +46,46 @@ config SENSOR_ZG09 endif endif + +config SENSOR_G8S + bool "Using g8-s" + default n + + if SENSOR_G8S + config SENSOR_DEVICE_G8S + string "g8-s sensor name" + default "g8-s" + + config SENSOR_QUANTITY_G8S_CO2 + string "g8-s quantity name" + default "co2_2" + + if ADD_XIZI_FETURES + config SENSOR_G8S_DRIVER_EXTUART + bool "Using extra uart to support g8-s" + default n + + config SENSOR_DEVICE_G8S_DEV + string "g8-s device uart path" + default "/dev/uart2_dev2" + depends on !SENSOR_G8S_DRIVER_EXTUART + + if SENSOR_G8S_DRIVER_EXTUART + config SENSOR_DEVICE_G8S_DEV + string "g8-s device extra uart path" + default "/dev/extuart_dev4" + + config SENSOR_DEVICE_G8S_DEV_EXT_PORT + int "if g8-s device using extuart, choose port" + default "4" + endif + endif + + if ADD_NUTTX_FETURES + + endif + + if ADD_RTTHREAD_FETURES + + endif + endif diff --git a/APP_Framework/Framework/sensor/co2/Makefile b/APP_Framework/Framework/sensor/co2/Makefile index 40ab8d769..ba645d10d 100644 --- a/APP_Framework/Framework/sensor/co2/Makefile +++ b/APP_Framework/Framework/sensor/co2/Makefile @@ -2,4 +2,8 @@ ifeq ($(CONFIG_SENSOR_ZG09),y) SRC_DIR += zg09 endif +ifeq ($(CONFIG_SENSOR_G8S),y) + SRC_DIR += g8s +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/sensor/co2/SConscript b/APP_Framework/Framework/sensor/co2/SConscript new file mode 100644 index 000000000..f307e3f70 --- /dev/null +++ b/APP_Framework/Framework/sensor/co2/SConscript @@ -0,0 +1,14 @@ +import os +Import('RTT_ROOT') +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(path, 'SConscript')) + +Return('objs') diff --git a/APP_Framework/Framework/sensor/co2/g8s/Makefile b/APP_Framework/Framework/sensor/co2/g8s/Makefile new file mode 100644 index 000000000..933351bcd --- /dev/null +++ b/APP_Framework/Framework/sensor/co2/g8s/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := g8s.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/sensor/co2/g8s/SConscript b/APP_Framework/Framework/sensor/co2/g8s/SConscript new file mode 100644 index 000000000..9e8be22d6 --- /dev/null +++ b/APP_Framework/Framework/sensor/co2/g8s/SConscript @@ -0,0 +1,10 @@ +from building import * +import os + +cwd = GetCurrentDir() +src = [] +if GetDepend(['SENSOR_G8S']): + src += ['g8s.c'] +group = DefineGroup('sensor co2 g8s', src, depend = [], CPPPATH = [cwd]) + +Return('group') \ No newline at end of file diff --git a/APP_Framework/Framework/sensor/co2/g8s/g8s.c b/APP_Framework/Framework/sensor/co2/g8s/g8s.c new file mode 100644 index 000000000..b46b54971 --- /dev/null +++ b/APP_Framework/Framework/sensor/co2/g8s/g8s.c @@ -0,0 +1,187 @@ +/* +* 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 g8s.c + * @brief G8S CO2 driver base sensor + * @version 1.1 + * @author AIIT XUOS Lab + * @date 2021.12.23 + */ + +#include +#include + +static uint8_t g8s_read_instruction[8] = {0x52, 0x36, 0x09, 0x37, 0x38, 0x0D, 0x0A}; + +static struct SensorDevice g8s; + +static struct SensorProductInfo info = +{ + SENSOR_ABILITY_CO2, + "senTec", + "G8S", +}; + +/** + * @description: Open G8S 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_G8S_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_G8S_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_G8S_DRIVER_EXTUART + cfg.ext_uart_no = SENSOR_DEVICE_G8S_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; + + PrivWrite(sdev->fd, g8s_read_instruction, sizeof(g8s_read_instruction)); + + if (PrivRead(sdev->fd, sdev->buffer, len) < 0) + return -1; + + return 0; +} + +static struct SensorDone done = +{ + SensorDeviceOpen, + NULL, + SensorDeviceRead, + NULL, + NULL, +}; + +/** + * @description: Init G8S sensor and register + * @return void + */ +static void SensorDeviceG8sInit(void) +{ + g8s.name = SENSOR_DEVICE_G8S; + g8s.info = &info; + g8s.done = &done; + g8s.status = SENSOR_DEVICE_PASSIVE; + + SensorDeviceRegister(&g8s); +} + +static struct SensorQuantity g8s_co2; + +/** + * @description: Analysis G8S CO2 result + * @param quant - sensor quantity pointer + * @return quantity value + */ +static int32_t QuantityRead(struct SensorQuantity *quant) +{ + if (!quant) + return -1; + + int i, ascii_length; + int32_t result = 0; + uint8_t result_ascii[9], result_hex[9]; + + memset(result_ascii, 0, 9); + memset(result_hex, 0, 9); + + if (quant->sdev->done->read != NULL) { + if(quant->sdev->status == SENSOR_DEVICE_PASSIVE) { + quant->sdev->done->read(quant->sdev, 9); + + for (i = 0; i < 9; i ++) { + if (0x09 == quant->sdev->buffer[i]) { + ascii_length = i; + break; + } + result_ascii[i] = quant->sdev->buffer[i]; + } + + if (8 == ascii_length) { + for (i = 0; i < ascii_length; i ++) { + result_hex[i] = result_ascii[i] - 0x30; + result += result_hex[i] * pow(10, ascii_length - 1 - i); + } + return result; + } else { + printf("This reading is wrong\n"); + result = SENSOR_QUANTITY_VALUE_ERROR; + return result; + } + } + 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 G8S CO2 quantity and register + * @return 0 + */ +int G8sCo2Init(void) +{ + SensorDeviceG8sInit(); + + g8s_co2.name = SENSOR_QUANTITY_G8S_CO2; + g8s_co2.type = SENSOR_QUANTITY_CO2; + g8s_co2.value.decimal_places = 0; + g8s_co2.value.max_std = 2000; + g8s_co2.value.min_std = 0; + g8s_co2.value.last_value = SENSOR_QUANTITY_VALUE_ERROR; + g8s_co2.value.max_value = SENSOR_QUANTITY_VALUE_ERROR; + g8s_co2.value.min_value = SENSOR_QUANTITY_VALUE_ERROR; + g8s_co2.sdev = &g8s; + g8s_co2.ReadValue = QuantityRead; + + SensorQuantityRegister(&g8s_co2); + + return 0; +} \ No newline at end of file diff --git a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c index 706c8958a..e999b7800 100644 --- a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c +++ b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c @@ -69,28 +69,11 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { -#ifdef ADD_NUTTX_FETURES - int ret; - ret = PrivRead(sdev->fd, sdev->buffer, len); - if (ret != len ){ - perror("Failed to read data!\n"); - return -1; - } - - return 0; -#else - //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) + if (PrivRead(sdev->fd, sdev->buffer, len) < 0) return -1; return 0; -#endif } static struct SensorDone done = diff --git a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c index a3a80acbd..a758ab437 100644 --- a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c +++ b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c @@ -68,28 +68,11 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { -#ifdef ADD_NUTTX_FETURES - int ret; - ret = PrivRead(sdev->fd, sdev->buffer, len); - if (ret != len ){ - perror("Failed to read data!\n"); - return -1; - } - - return 0; -#else - //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) + if (PrivRead(sdev->fd, sdev->buffer, len) < 0) return -1; return 0; -#endif } static struct SensorDone done =