diff --git a/kitsune/commands.c b/kitsune/commands.c index eb7d803d..13c140b0 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -1298,6 +1298,14 @@ void sample_sensor_data(periodic_data* data,NetStats_t * keyword_net_stats) data->tvoc = tvoc; data->has_co2 = true; data->co2 = eco2; + + data->has_tvoc_version = true; + data->tvoc_version.has_tvoc_app_fw_version = true; + data->tvoc_version.tvoc_app_fw_version = tvoc_get_fw_app_version(); + data->tvoc_version.has_tvoc_boot_fw_version = true; + data->tvoc_version.tvoc_boot_fw_version = tvoc_get_fw_boot_version(); + data->tvoc_version.has_tvoc_hw_version = true; + data->tvoc_version.tvoc_hw_version = tvoc_get_hw_version(); } } } @@ -2057,6 +2065,9 @@ tCmdLineEntry g_sCmdTable[] = { { "thp", Cmd_read_temp_hum_press, "" }, { "tv", Cmd_meas_TVOC, "" }, {"tvenv", Cmd_set_tvenv, ""}, + {"tvver",cmd_tvoc_get_ver, ""}, + {"tvgets",cmd_tvoc_status, ""}, + {"tverr",cmd_tvoc_errid, ""}, { "uv", Cmd_read_uv, "" }, { "light", Cmd_readlight, "" }, diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 3f9d06d3..faf33b89 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -244,14 +244,18 @@ int Cmd_read_temp_hum_press(int argc, char *argv[]) { return SUCCESS; } +/******************************************************************************** + * GAS SENSOR CCS811 - BEGIN + ********************************************************************************/ bool tvoc_wa = false; +uint8_t tvoc_i2c_addr = 0x5A; int init_tvoc(int measmode) { unsigned char b[2]; assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); b[0] = 0; - (I2C_IF_Write(0x5a, b, 1, 1)); - (I2C_IF_Read(0x5a, b, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, b, 1)); if( !(b[0] & 0x10) ) { LOGE("no valid fw for TVOC\n"); @@ -260,11 +264,11 @@ int init_tvoc(int measmode) { } //boot b[0] = 0xf4; - (I2C_IF_Write(0x5a, b, 1, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); vTaskDelay(100); b[0] = 0; - (I2C_IF_Write(0x5a, b, 1, 1)); - (I2C_IF_Read(0x5a, b, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, b, 1)); if( !(b[0] & 0x90) ) { LOGE("fail to boot TVOC\n"); xSemaphoreGiveRecursive(i2c_smphr); @@ -272,17 +276,20 @@ int init_tvoc(int measmode) { } b[0] = 1; b[1] = measmode; - (I2C_IF_Write(0x5a, b, 2, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 2, 1)); b[0] = 0x24; - (I2C_IF_Write(0x5a, b, 1, 1)); - (I2C_IF_Read(0x5a, b, 2)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, b, 2)); - LOGE("TVOC FW %d.%d.%d\n",(b[0]>>4) & 0xf,b[0] & 0xf, b[1]); + LOGI("TVOC FW %d.%d.%d\n",(b[0]>>4) & 0xf,b[0] & 0xf, b[1]); if (b[0] == 0x02 && b[1] == 0x4) { LOGE("apply TVOC FW 0.2.4 workaround\n"); tvoc_wa = true; } + else { + tvoc_wa = false; + } xSemaphoreGiveRecursive(i2c_smphr); return 0; @@ -309,7 +316,7 @@ static int set_tvoc_env(int temp, unsigned int humid){ b[3] |= 1; } b[4] = 0; - (I2C_IF_Write(0x5a, b, 5, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 5, 1)); vTaskDelay(10); xSemaphoreGiveRecursive(i2c_smphr); return 0; @@ -349,9 +356,9 @@ int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, uns * read alg_result_data */ b[0] = 2; - (I2C_IF_Write(0x5a, b, 1, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); memset(b,0, sizeof(b)); - (I2C_IF_Read(0x5a, b, 8)); + (I2C_IF_Read(tvoc_i2c_addr, b, 8)); DBG_TVOC("%x:%x:%x:%x:%x:%x:%x:%x\n", b[0],b[1],b[2],b[3],b[4],b[5], @@ -368,8 +375,8 @@ int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, uns if( b[4] & 0x01 ) { LOGE("TVOC error %x ", b[5] ); b[0] = 0xe0; - (I2C_IF_Write(0x5a, b, 1, 1)); - (I2C_IF_Read(0x5a, b, 1)); + (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, b, 1)); LOGE("%x\n", b[0]); xSemaphoreGiveRecursive(i2c_smphr); return -1; @@ -401,6 +408,137 @@ int Cmd_meas_TVOC(int argc, char *argv[]) { } return -1; } + +#define APP_VALID_MASK (0x1 << 4) +inline static uint8_t _tvoc_read_status_reg(void){ + + uint8_t status_reg_cmd[2] = {0x00, 0xFF}; + + if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ + + (I2C_IF_Write(tvoc_i2c_addr, status_reg_cmd, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, &status_reg_cmd[1], 1)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + DBG_TVOC("TV: status reg: %x\n",status_reg_cmd[1]); + + return status_reg_cmd[1]; + +} + +inline static uint8_t _tvoc_read_err_id(void){ + + uint8_t err_id_cmd[2] = {0xE0, 0xFF}; + + if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ + + (I2C_IF_Write(tvoc_i2c_addr, err_id_cmd, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, &err_id_cmd[1], 1)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + DBG_TVOC("TV: err id: %x\n",err_id_cmd[1]); + + return err_id_cmd[1]; + +} + +inline static int _tvoc_reset(void){ + + uint8_t sw_reset_cmd[5] = {0xFF, 0x11, 0xE5, 0x72, 0x8A }; + + assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); + + (I2C_IF_Write(tvoc_i2c_addr, sw_reset_cmd, 5, 1)); + vTaskDelay(10); + xSemaphoreGiveRecursive(i2c_smphr); + + return 0; +} + +uint8_t tvoc_get_hw_version(void){ + + uint8_t hw_ver_cmd[2] = {0x21, 0xFF}; + + if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ + + (I2C_IF_Write(tvoc_i2c_addr, hw_ver_cmd, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, &hw_ver_cmd[1], 1)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + return hw_ver_cmd[1]; +} + +uint16_t tvoc_get_fw_boot_version(void){ + + uint8_t fw_boot_ver_cmd[3] = {0x23, 0xFF, 0xFF}; + + if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ + + (I2C_IF_Write(tvoc_i2c_addr, fw_boot_ver_cmd, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, &fw_boot_ver_cmd[1], 2)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + DBG_TVOC("FW Boot: 0x%x\n",fw_boot_ver_cmd[1]<<8 | fw_boot_ver_cmd[2] ); + + return (fw_boot_ver_cmd[1]<<8) | fw_boot_ver_cmd[2]; + +} + +uint16_t tvoc_get_fw_app_version(void){ + + uint8_t fw_app_ver_cmd[3] = {0x24, 0xFF, 0xFF}; + + if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ + + (I2C_IF_Write(tvoc_i2c_addr, fw_app_ver_cmd, 1, 1)); + (I2C_IF_Read(tvoc_i2c_addr, &fw_app_ver_cmd[1], 2)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + DBG_TVOC("FW APP: 0x%x\n",(fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2] ); + + return (fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2]; + +} + +// Cmd to get hardware and fw version of CCS811 +int cmd_tvoc_get_ver(int argc, char *argv[]) { + + LOGI("*TVOC VERSION* \n -Current HW version: 0x%x. FW Boot Version: 0x%x, FW App Version: 0x%x- \n", + tvoc_get_hw_version(), tvoc_get_fw_boot_version(), tvoc_get_fw_app_version()); + + return 0; +} + +// Cmd to get hardware and fw version of CCS811 +int cmd_tvoc_status(int argc, char *argv[]) { + + LOGI("*TVOC STATUS REG* %x\n", _tvoc_read_status_reg()); + + return 0; +} + +// Cmd to get TVOC error id +int cmd_tvoc_errid(int argc, char *argv[]) { + + LOGI("*TVOC ERR ID* %x\n", _tvoc_read_err_id()); + + return 0; +} + +/******************************************************************************** + * GAS SENSOR CCS811 - END + ********************************************************************************/ + static bool haz_tmg4903() { unsigned char b[2]={0}; b[0] = 0x92; diff --git a/kitsune/i2c_cmd.h b/kitsune/i2c_cmd.h index 9f570930..75cdaa14 100644 --- a/kitsune/i2c_cmd.h +++ b/kitsune/i2c_cmd.h @@ -23,6 +23,10 @@ int get_ir( int * ir ); int get_rgb_prox( int * w, int * r, int * g, int * bl, int * p ); int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, unsigned int humid ); +uint8_t tvoc_get_hw_version(void); +uint16_t tvoc_get_fw_boot_version(void); +uint16_t tvoc_get_fw_app_version(void); + typedef enum { ZOPT_UV = 0, ZOPT_ALS = 1, @@ -32,6 +36,9 @@ int Cmd_read_uv(int argc, char *argv[]); int Cmd_uvr(int argc, char *argv[]); int Cmd_uvw(int argc, char *argv[]); int Cmd_set_tvenv(int argc, char * argv[]); +int cmd_tvoc_get_ver(int argc, char *argv[]); +int cmd_tvoc_status(int argc, char *argv[]); +int cmd_tvoc_errid(int argc, char *argv[]); int init_humid_sensor(); int init_temp_sensor(); diff --git a/kitsune/protobuf/periodic.pb.c b/kitsune/protobuf/periodic.pb.c index 01094822..4afdfd32 100644 --- a/kitsune/protobuf/periodic.pb.c +++ b/kitsune/protobuf/periodic.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.1 at Wed Oct 19 09:11:39 2016. */ +/* Generated by nanopb-0.3.1 at Mon Feb 06 11:39:23 2017. */ #include "periodic.pb.h" @@ -9,7 +9,7 @@ -const pb_field_t periodic_data_fields[23] = { +const pb_field_t periodic_data_fields[24] = { PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, periodic_data, unix_time, unix_time, 0), PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, periodic_data, light, unix_time, 0), PB_FIELD( 3, INT32 , OPTIONAL, STATIC , OTHER, periodic_data, temperature, light, 0), @@ -32,6 +32,7 @@ const pb_field_t periodic_data_fields[23] = { PB_FIELD( 25, MESSAGE , OPTIONAL, STATIC , OTHER, periodic_data, light_sensor, co2, &periodic_data_light_data_fields), PB_FIELD( 26, INT32 , OPTIONAL, STATIC , OTHER, periodic_data, light_duration_ms, light_sensor, 0), PB_FIELD( 27, MESSAGE , OPTIONAL, STATIC , OTHER, periodic_data, keyword_stats, light_duration_ms, &KeywordStats_fields), + PB_FIELD( 28, MESSAGE , OPTIONAL, STATIC , OTHER, periodic_data, tvoc_version, keyword_stats, &periodic_data_TvocVersion_fields), PB_LAST_FIELD }; @@ -46,6 +47,13 @@ const pb_field_t periodic_data_light_data_fields[8] = { PB_LAST_FIELD }; +const pb_field_t periodic_data_TvocVersion_fields[4] = { + PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, periodic_data_TvocVersion, tvoc_app_fw_version, tvoc_app_fw_version, 0), + PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_TvocVersion, tvoc_boot_fw_version, tvoc_app_fw_version, 0), + PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_TvocVersion, tvoc_hw_version, tvoc_boot_fw_version, 0), + PB_LAST_FIELD +}; + const pb_field_t batched_periodic_data_fields[9] = { PB_FIELD( 1, MESSAGE , REPEATED, CALLBACK, FIRST, batched_periodic_data, data, data, &periodic_data_fields), PB_FIELD( 2, STRING , REQUIRED, CALLBACK, OTHER, batched_periodic_data, device_id, data, 0), @@ -75,7 +83,7 @@ const pb_field_t batched_periodic_data_wifi_access_point_fields[4] = { * numbers or field sizes that are larger than what can fit in 8 or 16 bit * field descriptors. */ -PB_STATIC_ASSERT((pb_membersize(periodic_data, light_sensor) < 65536 && pb_membersize(periodic_data, keyword_stats) < 65536 && pb_membersize(batched_periodic_data, data) < 65536 && pb_membersize(batched_periodic_data, scan) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_periodic_data_periodic_data_light_data_batched_periodic_data_batched_periodic_data_wifi_access_point) +PB_STATIC_ASSERT((pb_membersize(periodic_data, light_sensor) < 65536 && pb_membersize(periodic_data, keyword_stats) < 65536 && pb_membersize(periodic_data, tvoc_version) < 65536 && pb_membersize(batched_periodic_data, data) < 65536 && pb_membersize(batched_periodic_data, scan) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_periodic_data_periodic_data_light_data_periodic_data_TvocVersion_batched_periodic_data_batched_periodic_data_wifi_access_point) #endif #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) @@ -86,7 +94,7 @@ PB_STATIC_ASSERT((pb_membersize(periodic_data, light_sensor) < 65536 && pb_membe * numbers or field sizes that are larger than what can fit in the default * 8 bit descriptors. */ -PB_STATIC_ASSERT((pb_membersize(periodic_data, light_sensor) < 256 && pb_membersize(periodic_data, keyword_stats) < 256 && pb_membersize(batched_periodic_data, data) < 256 && pb_membersize(batched_periodic_data, scan) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_periodic_data_periodic_data_light_data_batched_periodic_data_batched_periodic_data_wifi_access_point) +PB_STATIC_ASSERT((pb_membersize(periodic_data, light_sensor) < 256 && pb_membersize(periodic_data, keyword_stats) < 256 && pb_membersize(periodic_data, tvoc_version) < 256 && pb_membersize(batched_periodic_data, data) < 256 && pb_membersize(batched_periodic_data, scan) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_periodic_data_periodic_data_light_data_periodic_data_TvocVersion_batched_periodic_data_batched_periodic_data_wifi_access_point) #endif diff --git a/kitsune/protobuf/periodic.pb.h b/kitsune/protobuf/periodic.pb.h index 33fffa48..c6a4711d 100644 --- a/kitsune/protobuf/periodic.pb.h +++ b/kitsune/protobuf/periodic.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.1 at Wed Oct 19 09:11:39 2016. */ +/* Generated by nanopb-0.3.1 at Mon Feb 06 11:39:23 2017. */ #ifndef PB_PERIODIC_PB_H_INCLUDED #define PB_PERIODIC_PB_H_INCLUDED @@ -46,6 +46,15 @@ typedef struct _batched_periodic_data_wifi_access_point { batched_periodic_data_wifi_access_point_AntennaType antenna; } batched_periodic_data_wifi_access_point; +typedef struct _periodic_data_TvocVersion { + bool has_tvoc_app_fw_version; + uint32_t tvoc_app_fw_version; + bool has_tvoc_boot_fw_version; + uint32_t tvoc_boot_fw_version; + bool has_tvoc_hw_version; + uint32_t tvoc_hw_version; +} periodic_data_TvocVersion; + typedef struct _periodic_data_light_data { int32_t r; int32_t g; @@ -105,17 +114,21 @@ typedef struct _periodic_data { int32_t light_duration_ms; bool has_keyword_stats; KeywordStats keyword_stats; + bool has_tvoc_version; + periodic_data_TvocVersion tvoc_version; } periodic_data; /* Default values for struct fields */ /* Initializer values for message structs */ -#define periodic_data_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, periodic_data_light_data_init_default, false, 0, false, KeywordStats_init_default} +#define periodic_data_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, periodic_data_light_data_init_default, false, 0, false, KeywordStats_init_default, false, periodic_data_TvocVersion_init_default} #define periodic_data_light_data_init_default {0, 0, 0, false, 0, false, 0, false, 0, false, 0} +#define periodic_data_TvocVersion_init_default {false, 0, false, 0, false, 0} #define batched_periodic_data_init_default {{{NULL}, NULL}, {{NULL}, NULL}, 0, false, 0, false, "", false, "", {{NULL}, NULL}, false, 0} #define batched_periodic_data_wifi_access_point_init_default {false, "", false, 0, false, (batched_periodic_data_wifi_access_point_AntennaType)0} -#define periodic_data_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, periodic_data_light_data_init_zero, false, 0, false, KeywordStats_init_zero} +#define periodic_data_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, periodic_data_light_data_init_zero, false, 0, false, KeywordStats_init_zero, false, periodic_data_TvocVersion_init_zero} #define periodic_data_light_data_init_zero {0, 0, 0, false, 0, false, 0, false, 0, false, 0} +#define periodic_data_TvocVersion_init_zero {false, 0, false, 0, false, 0} #define batched_periodic_data_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, 0, false, 0, false, "", false, "", {{NULL}, NULL}, false, 0} #define batched_periodic_data_wifi_access_point_init_zero {false, "", false, 0, false, (batched_periodic_data_wifi_access_point_AntennaType)0} @@ -131,6 +144,9 @@ typedef struct _periodic_data { #define batched_periodic_data_wifi_access_point_ssid_tag 1 #define batched_periodic_data_wifi_access_point_rssi_tag 2 #define batched_periodic_data_wifi_access_point_antenna_tag 3 +#define periodic_data_TvocVersion_tvoc_app_fw_version_tag 1 +#define periodic_data_TvocVersion_tvoc_boot_fw_version_tag 2 +#define periodic_data_TvocVersion_tvoc_hw_version_tag 3 #define periodic_data_light_data_r_tag 1 #define periodic_data_light_data_g_tag 2 #define periodic_data_light_data_b_tag 3 @@ -160,16 +176,19 @@ typedef struct _periodic_data { #define periodic_data_light_sensor_tag 25 #define periodic_data_light_duration_ms_tag 26 #define periodic_data_keyword_stats_tag 27 +#define periodic_data_tvoc_version_tag 28 /* Struct field encoding specification for nanopb */ -extern const pb_field_t periodic_data_fields[23]; +extern const pb_field_t periodic_data_fields[24]; extern const pb_field_t periodic_data_light_data_fields[8]; +extern const pb_field_t periodic_data_TvocVersion_fields[4]; extern const pb_field_t batched_periodic_data_fields[9]; extern const pb_field_t batched_periodic_data_wifi_access_point_fields[4]; /* Maximum encoded size of messages (where known) */ -#define periodic_data_size (312 + KeywordStats_size) +#define periodic_data_size (333 + KeywordStats_size) #define periodic_data_light_data_size 77 +#define periodic_data_TvocVersion_size 18 #define batched_periodic_data_wifi_access_point_size 52 #ifdef __cplusplus diff --git a/kitsune/protobuf/sync_response.pb.c b/kitsune/protobuf/sync_response.pb.c index aaad95cb..d1258f23 100644 --- a/kitsune/protobuf/sync_response.pb.c +++ b/kitsune/protobuf/sync_response.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.1 at Tue Dec 20 17:34:23 2016. */ +/* Generated by nanopb-0.3.1 at Mon Feb 06 11:39:23 2017. */ #include "sync_response.pb.h" diff --git a/kitsune/protobuf/sync_response.pb.h b/kitsune/protobuf/sync_response.pb.h index 061563e4..5ab10572 100644 --- a/kitsune/protobuf/sync_response.pb.h +++ b/kitsune/protobuf/sync_response.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.1 at Tue Dec 20 17:34:23 2016. */ +/* Generated by nanopb-0.3.1 at Mon Feb 06 11:39:23 2017. */ #ifndef PB_SYNC_RESPONSE_PB_H_INCLUDED #define PB_SYNC_RESPONSE_PB_H_INCLUDED