From 21dce4f25e3b987fc32ee1a47cad66ab04b6b483 Mon Sep 17 00:00:00 2001 From: zhr <412870397@qq.com> Date: Tue, 26 Jul 2022 18:43:39 +0800 Subject: [PATCH 1/2] add g8s sensor support Nuttx on stm32f407-discovery --- APP_Framework/Applications/framework_init.c | 5 ++++ .../Applications/sensor_app/Makefile | 4 ++++ .../Applications/sensor_app/co2_g8s.c | 6 +++-- APP_Framework/Framework/sensor/co2/Kconfig | 24 ++++++++++++++++++- .../Framework/sensor/co2/g8s/Makefile | 14 +++++++++-- APP_Framework/Framework/sensor/co2/g8s/g8s.c | 23 +++++++++++++++++- .../app_match_nuttx/apps/nshlib/Kconfig | 4 ++++ .../app_match_nuttx/apps/nshlib/nsh.h | 4 ++++ .../apps/nshlib/nsh_Applicationscmd.c | 15 ++++++++++++ .../app_match_nuttx/apps/nshlib/nsh_command.c | 4 ++++ 10 files changed, 97 insertions(+), 6 deletions(-) diff --git a/APP_Framework/Applications/framework_init.c b/APP_Framework/Applications/framework_init.c index 2d08c4b46..9612fd635 100644 --- a/APP_Framework/Applications/framework_init.c +++ b/APP_Framework/Applications/framework_init.c @@ -32,6 +32,7 @@ extern int Ps5308Pm1_0Init(void); extern int Ps5308Pm2_5Init(void); extern int Ps5308Pm10Init(void); extern int Zg09Co2Init(void); +extern int G8sCo2Init(void); extern int As830Ch4Init(void); extern int Tb600bIaq10IaqInit(void); extern int Tb600bTvoc10TvocInit(void); @@ -106,6 +107,10 @@ static struct InitDesc sensor_desc[] = { "zg09_co2", Zg09Co2Init }, #endif +#ifdef SENSOR_G8S + { "g8s_co2", G8sCo2Init }, +#endif + #ifdef SENSOR_QS_FX { "qs_fx_wind_direction", QsFxWindDirectionInit }, #endif diff --git a/APP_Framework/Applications/sensor_app/Makefile b/APP_Framework/Applications/sensor_app/Makefile index 76fd4e16c..15d1c9691 100644 --- a/APP_Framework/Applications/sensor_app/Makefile +++ b/APP_Framework/Applications/sensor_app/Makefile @@ -23,6 +23,10 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) CSRCS += co2_zg09.c endif + ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y) + CSRCS += co2_g8s.c + endif + ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) CSRCS += 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 index 684a63d7a..d19a25ab2 100644 --- a/APP_Framework/Applications/sensor_app/co2_g8s.c +++ b/APP_Framework/Applications/sensor_app/co2_g8s.c @@ -17,8 +17,10 @@ * @author AIIT XUOS Lab * @date 2021.12.23 */ - -#include +// +#ifdef ADD_XIZI_FETURES +# include +#endif #include /** diff --git a/APP_Framework/Framework/sensor/co2/Kconfig b/APP_Framework/Framework/sensor/co2/Kconfig index e4c4c430f..8efcaa1f1 100644 --- a/APP_Framework/Framework/sensor/co2/Kconfig +++ b/APP_Framework/Framework/sensor/co2/Kconfig @@ -64,6 +64,7 @@ config SENSOR_ZG09 endif endif + config SENSOR_G8S bool "Using g8-s" default n @@ -99,10 +100,31 @@ config SENSOR_G8S endif if ADD_NUTTX_FETURES - + config SENSOR_DEVICE_G8S_DEV + string "CO2 device name" + default "/dev/ttyS1" + ---help--- + If USART1 is selected, then fill in /dev/ttyS1 here. endif if ADD_RTTHREAD_FETURES + config SENSOR_G8S_DRIVER_EXTUART + bool "Using extra uart to support g8-s" + default y + 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 G8S device using extuart, choose port" + default "4" + endif endif endif diff --git a/APP_Framework/Framework/sensor/co2/g8s/Makefile b/APP_Framework/Framework/sensor/co2/g8s/Makefile index 933351bcd..e4b77f31a 100644 --- a/APP_Framework/Framework/sensor/co2/g8s/Makefile +++ b/APP_Framework/Framework/sensor/co2/g8s/Makefile @@ -1,3 +1,13 @@ -SRC_FILES := g8s.c +include $(KERNEL_ROOT)/.config + +ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) + include $(APPDIR)/Make.defs + CSRCS += g8s.c + include $(APPDIR)/Application.mk +endif + +ifeq ($(CONFIG_ADD_XIZI_FETURES),y) + SRC_FILES := g8s.c + include $(KERNEL_ROOT)/compiler.mk +endif -include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/sensor/co2/g8s/g8s.c b/APP_Framework/Framework/sensor/co2/g8s/g8s.c index b46b54971..a5122a131 100644 --- a/APP_Framework/Framework/sensor/co2/g8s/g8s.c +++ b/APP_Framework/Framework/sensor/co2/g8s/g8s.c @@ -37,6 +37,7 @@ static struct SensorProductInfo info = * @param sdev - sensor device pointer * @return success: 1 , failure: other */ +#ifdef ADD_NUTTX_FETURES static int SensorDeviceOpen(struct SensorDevice *sdev) { int result = 0; @@ -47,6 +48,26 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) return -1; } + + result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE); + if (result != 0){ + printf("SensorDeviceOpen:ioctl failed, status=%d\n", result); + } + + return result; +} +#else +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; @@ -67,7 +88,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) return result; } - +#endif /** * @description: Read sensor device * @param sdev - sensor device pointer diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig index 45d4e93e5..c750eace7 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/Kconfig @@ -571,6 +571,10 @@ config NSH_DISABLE_CO2ZG09 bool "Disable the sensor zg09." default n +config NSH_DISABLE_CO2G8S + bool "Disable the sensor g8-s." + default n + config NSH_DISABLE_PM1_0PS5308 bool "Disable the pm1.0 function of the sensor ps5308." default n diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h index 366bab399..4b0285e87 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh.h @@ -1474,6 +1474,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb, int cmd_Co2Zg09(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_APPLICATION_SENSOR_CO2_G8S) && !defined(CONFIG_NSH_DISABLE_CO2G8S) + int cmd_Co2G8S(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308) int cmd_Pm10Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c index 34fb18629..12ff74aa2 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_Applicationscmd.c @@ -125,6 +125,21 @@ int cmd_Co2Zg09(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_Co2g8s + ****************************************************************************/ + +#if defined(CONFIG_APPLICATION_SENSOR_CO2_G8S) && !defined(CONFIG_NSH_DISABLE_CO2G8S) +extern void Co2G8s(void); +int cmd_Co2G8S(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, "Hello, world!\n"); + FrameworkInit(); + Co2G8s(); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_Pm10Ps5308 ****************************************************************************/ diff --git a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c index 79ee7365d..489a15a9e 100644 --- a/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c +++ b/Ubiquitous/Nuttx_Fusion_XiUOS/app_match_nuttx/apps/nshlib/nsh_command.c @@ -620,6 +620,10 @@ static const struct cmdmap_s g_cmdmap[] = { "zg09", cmd_Co2Zg09, 1, 1, "[get the concentration of co2 with sensor ZG09.]" }, #endif +#if defined(CONFIG_APPLICATION_SENSOR_CO2_G8S) && !defined(CONFIG_NSH_DISABLE_CO2G8S) + { "g8s", cmd_Co2G8S, 1, 1, "[get the concentration of co2 with sensor G8S.]" }, +#endif + #if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308) { "pm1.0", cmd_Pm10Ps5308, 1, 1, "[get pm1.0 with sensor Ps5308.]" }, #endif From 0b0b4c24edec0637f2203d08f724ced4efbb0455 Mon Sep 17 00:00:00 2001 From: zhr <412870397@qq.com> Date: Thu, 28 Jul 2022 14:21:49 +0800 Subject: [PATCH 2/2] add g8s sensor support Nuttx on stm32f407-discovery --- .../Applications/sensor_app/Makefile | 3 +- APP_Framework/Framework/sensor/co2/Kconfig | 19 +--------- .../Framework/sensor/co2/g8s/Make.defs | 6 ++++ APP_Framework/Framework/sensor/co2/g8s/g8s.c | 36 ++++++++++--------- 4 files changed, 28 insertions(+), 36 deletions(-) create mode 100644 APP_Framework/Framework/sensor/co2/g8s/Make.defs diff --git a/APP_Framework/Applications/sensor_app/Makefile b/APP_Framework/Applications/sensor_app/Makefile index 15d1c9691..03bc3952a 100644 --- a/APP_Framework/Applications/sensor_app/Makefile +++ b/APP_Framework/Applications/sensor_app/Makefile @@ -22,10 +22,11 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) CSRCS += co2_zg09.c endif - + ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y) CSRCS += co2_g8s.c endif + ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) CSRCS += pm1_0_ps5308.c diff --git a/APP_Framework/Framework/sensor/co2/Kconfig b/APP_Framework/Framework/sensor/co2/Kconfig index 8efcaa1f1..78a965e8d 100644 --- a/APP_Framework/Framework/sensor/co2/Kconfig +++ b/APP_Framework/Framework/sensor/co2/Kconfig @@ -102,29 +102,12 @@ config SENSOR_G8S if ADD_NUTTX_FETURES config SENSOR_DEVICE_G8S_DEV string "CO2 device name" - default "/dev/ttyS1" + default "/dev/ttyS3" ---help--- If USART1 is selected, then fill in /dev/ttyS1 here. endif if ADD_RTTHREAD_FETURES - config SENSOR_G8S_DRIVER_EXTUART - bool "Using extra uart to support g8-s" - default y - 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 G8S device using extuart, choose port" - default "4" - endif endif endif diff --git a/APP_Framework/Framework/sensor/co2/g8s/Make.defs b/APP_Framework/Framework/sensor/co2/g8s/Make.defs new file mode 100644 index 000000000..f14b14928 --- /dev/null +++ b/APP_Framework/Framework/sensor/co2/g8s/Make.defs @@ -0,0 +1,6 @@ +############################################################################ +# APP_Framework/Framework/sensor/co2/g8s/Make.defs +############################################################################ +ifneq ($(CONFIG_SENSOR_G8S),) +CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/g8s +endif diff --git a/APP_Framework/Framework/sensor/co2/g8s/g8s.c b/APP_Framework/Framework/sensor/co2/g8s/g8s.c index a5122a131..89c7583bc 100644 --- a/APP_Framework/Framework/sensor/co2/g8s/g8s.c +++ b/APP_Framework/Framework/sensor/co2/g8s/g8s.c @@ -47,15 +47,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) printf("open %s error\n", SENSOR_DEVICE_G8S_DEV); return -1; } - - - result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE); - if (result != 0){ - printf("SensorDeviceOpen:ioctl failed, status=%d\n", result); - } - - return result; } + #else static int SensorDeviceOpen(struct SensorDevice *sdev) { @@ -97,10 +90,9 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { - uint8_t tmp = 0; PrivWrite(sdev->fd, g8s_read_instruction, sizeof(g8s_read_instruction)); - + PrivTaskDelay(500); if (PrivRead(sdev->fd, sdev->buffer, len) < 0) return -1; @@ -161,16 +153,26 @@ static int32_t QuantityRead(struct SensorQuantity *quant) 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 { + if (ascii_length == 0){ + printf("This reading is wrong\n"); + result = SENSOR_QUANTITY_VALUE_ERROR; + return result; + + }else{ + + 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; + } } if (quant->sdev->status == SENSOR_DEVICE_ACTIVE) {