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..03bc3952a 100644 --- a/APP_Framework/Applications/sensor_app/Makefile +++ b/APP_Framework/Applications/sensor_app/Makefile @@ -22,6 +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/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..78a965e8d 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,7 +100,11 @@ config SENSOR_G8S endif if ADD_NUTTX_FETURES - + config SENSOR_DEVICE_G8S_DEV + string "CO2 device name" + default "/dev/ttyS3" + ---help--- + If USART1 is selected, then fill in /dev/ttyS1 here. endif if ADD_RTTHREAD_FETURES 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/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..89c7583bc 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; @@ -46,7 +47,20 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) printf("open %s error\n", SENSOR_DEVICE_G8S_DEV); return -1; } - +} + +#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 +81,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) return result; } - +#endif /** * @description: Read sensor device * @param sdev - sensor device pointer @@ -76,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; @@ -140,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) { 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 3e4c8f172..8bc4b8879 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 @@ -1478,6 +1478,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 8d2138e95..a81bb457a 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 @@ -138,6 +138,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 d0e50455a..5a97738fe 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 @@ -624,6 +624,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