From 6948474c894f3ce8f667eb348cac1fddfc9259cd Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 1 Dec 2016 16:52:18 -0800 Subject: [PATCH 01/20] gas sensor fw update - initial commit - not tested --- kitsune/commands.c | 1 + kitsune/i2c_cmd.c | 191 ++++++++++++++++++++++++++++++++++++++++++--- kitsune/i2c_cmd.h | 1 + 3 files changed, 180 insertions(+), 13 deletions(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index 9ba7721c..8c14b7e6 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -2054,6 +2054,7 @@ tCmdLineEntry g_sCmdTable[] = { { "thp", Cmd_read_temp_hum_press, "" }, { "tv", Cmd_meas_TVOC, "" }, {"tvenv", Cmd_set_tvenv, ""}, + {"tvfw",cmd_tvoc_fw_update, ""}, { "uv", Cmd_read_uv, "" }, { "light", Cmd_readlight, "" }, diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 5d13ce0b..daed5f76 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -523,14 +523,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"); @@ -539,11 +543,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); @@ -551,11 +555,11 @@ 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]); if (b[0] == 0x02 && b[1] == 0x4) { @@ -588,7 +592,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; @@ -602,9 +606,9 @@ int get_tvoc(int * tvoc, int * eco2, int * current, int * voltage, int temp, uns assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); 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], @@ -621,8 +625,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; @@ -654,6 +658,167 @@ 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); + } + + return status_reg_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; +} + +inline static int _tvoc_erase_app(void){ + + uint8_t erase_cmd[5] = {0xF1, 0xE7, 0xA7, 0xE6, 0x09 }; + + assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); + + (I2C_IF_Write(tvoc_i2c_addr, erase_cmd, 5, 1)); + xSemaphoreGiveRecursive(i2c_smphr); + + vTaskDelay(500); + + return ( (_tvoc_read_status_reg() & APP_VALID_MASK == 0x00) ? 0:-1); +} + +inline static int _tvoc_program_app(const char* file){ + + return 0; +} + +inline static int _tvoc_verify_app(void){ + + uint8_t verify_cmd[1] = {0xF3 }; + assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); + + (I2C_IF_Write(tvoc_i2c_addr, verify_cmd, 1, 1)); + + xSemaphoreGiveRecursive(i2c_smphr); + + vTaskDelay(100); + + return ( (_tvoc_read_status_reg() & APP_VALID_MASK == 0x00) ? 0:-1); +} + +inline static 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]; +} + +inline static uint8_t _tvoc_get_fw_boot_version(void){ + + uint8_t fw_boot_ver_cmd[2] = {0x23, 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], 1)); + + xSemaphoreGiveRecursive(i2c_smphr); + } + + return fw_boot_ver_cmd[1]; + + return 0; +} +// CCS811 firmware update +// Returns 0 if firmware update is successful, -1 otherwise +int tvoc_fw_update(const char* file) +{ + int ret_val = 0; + + if( !file ){ + ret_val = -5; + goto tvoc_fail; + } + + LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x- \n", + _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + + // reset CCS811 + if(_tvoc_reset()){ + ret_val = -2; + goto tvoc_fail; + } + + vTaskDelay(100); + + // erase application + if(_tvoc_erase_app()){ + ret_val = -3; + goto tvoc_fail; + } + + // read binary and write to CCS811 + if(_tvoc_program_app(file)){ + ret_val = -1; + goto tvoc_fail; + } + + // verify + if(!_tvoc_verify_app()){ + LOGI("*TVOC FW UPDATE SUCCESSFUL* \n -HW version: 0x%x. FW Boot Version: 0x%x- \n", + _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + return 0; + } + else{ + ret_val = -4; + goto tvoc_fail; + } + +tvoc_fail: + LOGE("*TVOC FW UPDATE NOT SUCCESSFUL - %d* \n",ret_val); + return ret_val; +} + + +// Cmd to firmware update CCS811 +int cmd_tvoc_fw_update(int argc, char *argv[]) { + + if(argc < 2) { + LOGE("Usage: tvfw $full_path_to_file"); + return -1; + } + + return tvoc_fw_update(argv[1]); +} + +/******************************************************************************** + * 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 5ac8524b..8808ba87 100644 --- a/kitsune/i2c_cmd.h +++ b/kitsune/i2c_cmd.h @@ -31,6 +31,7 @@ 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_fw_update(int argc, char *argv[]); int init_humid_sensor(); int init_temp_sensor(); From 05e251b8c8ffdfaadaffd89fdd73d40644ea5751 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Wed, 4 Jan 2017 08:00:01 +0530 Subject: [PATCH 02/20] comments --- kitsune/i2c_cmd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index daed5f76..6a37808a 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -705,6 +705,12 @@ inline static int _tvoc_erase_app(void){ inline static int _tvoc_program_app(const char* file){ + // File open + + //loop: + // read bytes + + // Write return 0; } From 024a23bdde82f5d9e0044e4f167250b73affda3c Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 11:23:05 +0530 Subject: [PATCH 03/20] can program, ver doesn't update --- kitsune/commands.c | 2 ++ kitsune/i2c_cmd.c | 77 ++++++++++++++++++++++++++++++++++++++-------- kitsune/i2c_cmd.h | 2 ++ 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index edfb45a8..c3c5974c 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -2057,6 +2057,8 @@ tCmdLineEntry g_sCmdTable[] = { { "tv", Cmd_meas_TVOC, "" }, {"tvenv", Cmd_set_tvenv, ""}, {"tvfw",cmd_tvoc_fw_update, ""}, + {"tvver",cmd_tvoc_get_ver, ""}, + {"tvgets",cmd_tvoc_status, ""}, { "uv", Cmd_read_uv, "" }, { "light", Cmd_readlight, "" }, diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 6706020d..6bb31b59 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -393,6 +393,7 @@ inline static uint8_t _tvoc_read_status_reg(void){ xSemaphoreGiveRecursive(i2c_smphr); } + LOGI("TV: status reg: %x\n",status_reg_cmd[1]); return status_reg_cmd[1]; } @@ -421,17 +422,48 @@ inline static int _tvoc_erase_app(void){ vTaskDelay(500); - return ( (_tvoc_read_status_reg() & APP_VALID_MASK == 0x00) ? 0:-1); + int ret = _tvoc_read_status_reg() & APP_VALID_MASK; + LOGI("TV:erase ret:%d, APP_VALID_MASK: %d\n",ret, APP_VALID_MASK); + + if(ret) return -1; + else return 0; } +#define PATH_BUF_MAX_SIZE (64) +#include "ff.h" +#include "hellofilesystem.h" inline static int _tvoc_program_app(const char* file){ + uint32_t bytes_to_read=0, bytes_read=0; + uint8_t i2c_payload[9] = {0}; + FRESULT res; + FIL fp = {0}; + + //open file for read + res = hello_fs_open(&fp, file, FA_READ); + if (res) { + LOGE("TV: error opening file for read %d\n", res); + return res; + } + + // read into SHA + bytes_to_read = 8; + i2c_payload[0] = 0xF2; + res = hello_fs_read(&fp,&i2c_payload[1],bytes_to_read, &bytes_read); + + LOGI("TV: program start.\n"); + while ( (bytes_to_read == bytes_read) && (res == FR_OK) ) { - // File open - //loop: - // read bytes + assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); - // Write + (I2C_IF_Write(tvoc_i2c_addr, i2c_payload, 9, 1)); + xSemaphoreGiveRecursive(i2c_smphr); + + + res = hello_fs_read(&fp,&i2c_payload[1],bytes_to_read, &bytes_read); + } + LOGI("TV: program done. Bytes read: %d, res:%d\n", bytes_read, res); + hello_fs_close(&fp); return 0; } @@ -446,7 +478,7 @@ inline static int _tvoc_verify_app(void){ vTaskDelay(100); - return ( (_tvoc_read_status_reg() & APP_VALID_MASK == 0x00) ? 0:-1); + return ( (_tvoc_read_status_reg() & APP_VALID_MASK) ? 0:-1); } inline static uint8_t _tvoc_get_hw_version(void){ @@ -466,19 +498,19 @@ inline static uint8_t _tvoc_get_hw_version(void){ inline static uint8_t _tvoc_get_fw_boot_version(void){ - uint8_t fw_boot_ver_cmd[2] = {0x23, 0xFF}; + 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], 1)); + (I2C_IF_Read(tvoc_i2c_addr, &fw_boot_ver_cmd[1], 2)); xSemaphoreGiveRecursive(i2c_smphr); } + LOGI("FW: 0x%x%x\n",fw_boot_ver_cmd[1], fw_boot_ver_cmd[2] ); return fw_boot_ver_cmd[1]; - return 0; } // CCS811 firmware update // Returns 0 if firmware update is successful, -1 otherwise @@ -486,14 +518,15 @@ int tvoc_fw_update(const char* file) { int ret_val = 0; + LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x- \n", + _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + + if( !file ){ ret_val = -5; goto tvoc_fail; } - LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x- \n", - _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); - // reset CCS811 if(_tvoc_reset()){ ret_val = -2; @@ -502,6 +535,8 @@ int tvoc_fw_update(const char* file) vTaskDelay(100); + LOGI("TV: Bootloader Mode: %x\n",_tvoc_read_status_reg()); + // erase application if(_tvoc_erase_app()){ ret_val = -3; @@ -514,6 +549,7 @@ int tvoc_fw_update(const char* file) goto tvoc_fail; } + // verify if(!_tvoc_verify_app()){ LOGI("*TVOC FW UPDATE SUCCESSFUL* \n -HW version: 0x%x. FW Boot Version: 0x%x- \n", @@ -542,6 +578,23 @@ int cmd_tvoc_fw_update(int argc, char *argv[]) { return tvoc_fw_update(argv[1]); } +// 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- \n", + _tvoc_get_hw_version(), _tvoc_get_fw_boot_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; +} + /******************************************************************************** * GAS SENSOR CCS811 - END ********************************************************************************/ diff --git a/kitsune/i2c_cmd.h b/kitsune/i2c_cmd.h index af1720f7..dc8f4653 100644 --- a/kitsune/i2c_cmd.h +++ b/kitsune/i2c_cmd.h @@ -33,6 +33,8 @@ 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_fw_update(int argc, char *argv[]); +int cmd_tvoc_get_ver(int argc, char *argv[]); +int cmd_tvoc_status(int argc, char *argv[]); int init_humid_sensor(); int init_temp_sensor(); From bb1444393c779ca4a4e206285440e4700899297b Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 12:07:04 +0530 Subject: [PATCH 04/20] add fw app version --- kitsune/i2c_cmd.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 6bb31b59..6d1f5e5c 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -508,9 +508,26 @@ inline static uint8_t _tvoc_get_fw_boot_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } - LOGI("FW: 0x%x%x\n",fw_boot_ver_cmd[1], fw_boot_ver_cmd[2] ); + LOGI("FW Boot: 0x%x%x\n",fw_boot_ver_cmd[1], fw_boot_ver_cmd[2] ); return fw_boot_ver_cmd[1]; +} + +inline static uint8_t _tvoc_get_fw_app_version(void){ + + uint8_t fw_app_ver_cmd[3] = {0x25, 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); + } + + LOGI("FW APP: 0x%x%x\n",fw_app_ver_cmd[1], fw_app_ver_cmd[2] ); + return fw_app_ver_cmd[1]; + } // CCS811 firmware update // Returns 0 if firmware update is successful, -1 otherwise @@ -518,8 +535,8 @@ int tvoc_fw_update(const char* file) { int ret_val = 0; - LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x- \n", - _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + LOGI("*TVOC FW UPDATE* \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()); if( !file ){ @@ -552,8 +569,15 @@ int tvoc_fw_update(const char* file) // verify if(!_tvoc_verify_app()){ - LOGI("*TVOC FW UPDATE SUCCESSFUL* \n -HW version: 0x%x. FW Boot Version: 0x%x- \n", - _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + LOGI("*TVOC FW UPDATE* \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()); + + // reset CCS811 + if(_tvoc_reset()){ + ret_val = -2; + goto tvoc_fail; + } + return 0; } else{ @@ -581,8 +605,8 @@ int cmd_tvoc_fw_update(int argc, char *argv[]) { // 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- \n", - _tvoc_get_hw_version(), _tvoc_get_fw_boot_version()); + LOGI("*TVOC FW UPDATE* \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; } From ce5571a84a716c78df1ee206e028c4cef90f76c6 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 12:17:22 +0530 Subject: [PATCH 05/20] fix app version, get err id --- kitsune/commands.c | 1 + kitsune/i2c_cmd.c | 27 ++++++++++++++++++++++++++- kitsune/i2c_cmd.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index c3c5974c..a5273b47 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -2059,6 +2059,7 @@ tCmdLineEntry g_sCmdTable[] = { {"tvfw",cmd_tvoc_fw_update, ""}, {"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 6d1f5e5c..39c80813 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -398,6 +398,23 @@ inline static uint8_t _tvoc_read_status_reg(void){ } +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); + } + + LOGI("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 }; @@ -515,7 +532,7 @@ inline static uint8_t _tvoc_get_fw_boot_version(void){ inline static uint8_t _tvoc_get_fw_app_version(void){ - uint8_t fw_app_ver_cmd[3] = {0x25, 0xFF, 0xFF}; + uint8_t fw_app_ver_cmd[3] = {0x24, 0xFF, 0xFF}; if(xSemaphoreTakeRecursive(i2c_smphr, 30000)){ @@ -619,6 +636,14 @@ int cmd_tvoc_status(int argc, char *argv[]) { 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 ********************************************************************************/ diff --git a/kitsune/i2c_cmd.h b/kitsune/i2c_cmd.h index dc8f4653..8258ca61 100644 --- a/kitsune/i2c_cmd.h +++ b/kitsune/i2c_cmd.h @@ -35,6 +35,7 @@ int Cmd_set_tvenv(int argc, char * argv[]); int cmd_tvoc_fw_update(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(); From 6df05ecd2a5ae851b07eb6052054460776e1cc4e Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 12:30:18 +0530 Subject: [PATCH 06/20] init tvoc after fw update --- kitsune/i2c_cmd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 39c80813..16c97f92 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -595,6 +595,8 @@ int tvoc_fw_update(const char* file) goto tvoc_fail; } + init_tvoc(0x30); + return 0; } else{ From 24a27151da41e18c8c72108bd7edea4d1ddaa788 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 12:37:22 +0530 Subject: [PATCH 07/20] debug comments --- kitsune/i2c_cmd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 16c97f92..f1254953 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -393,7 +393,10 @@ inline static uint8_t _tvoc_read_status_reg(void){ xSemaphoreGiveRecursive(i2c_smphr); } +#if DBG_TVOC LOGI("TV: status reg: %x\n",status_reg_cmd[1]); +#endif + return status_reg_cmd[1]; } @@ -410,7 +413,10 @@ inline static uint8_t _tvoc_read_err_id(void){ xSemaphoreGiveRecursive(i2c_smphr); } +#if DBG_TVOC LOGI("TV: err id: %x\n",err_id_cmd[1]); +#endif + return err_id_cmd[1]; } @@ -440,7 +446,10 @@ inline static int _tvoc_erase_app(void){ vTaskDelay(500); int ret = _tvoc_read_status_reg() & APP_VALID_MASK; + +#if DBG_TVOC LOGI("TV:erase ret:%d, APP_VALID_MASK: %d\n",ret, APP_VALID_MASK); +#endif if(ret) return -1; else return 0; @@ -525,7 +534,10 @@ inline static uint8_t _tvoc_get_fw_boot_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } +#if DBG_TVOC LOGI("FW Boot: 0x%x%x\n",fw_boot_ver_cmd[1], fw_boot_ver_cmd[2] ); +#endif + return fw_boot_ver_cmd[1]; } @@ -542,7 +554,10 @@ inline static uint8_t _tvoc_get_fw_app_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } +#if DBG_TVOC LOGI("FW APP: 0x%x%x\n",fw_app_ver_cmd[1], fw_app_ver_cmd[2] ); +#endif + return fw_app_ver_cmd[1]; } @@ -569,7 +584,9 @@ int tvoc_fw_update(const char* file) vTaskDelay(100); +#if DBG_TVOC LOGI("TV: Bootloader Mode: %x\n",_tvoc_read_status_reg()); +#endif // erase application if(_tvoc_erase_app()){ From 912be89ad9adea5467abca14f7c12faaad451680 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 10 Jan 2017 17:58:28 +0530 Subject: [PATCH 08/20] 16bit ver, reset tvoc_wa, dbg logs --- kitsune/i2c_cmd.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index f1254953..df9ab3d9 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -282,11 +282,14 @@ int init_tvoc(int measmode) { (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; @@ -393,9 +396,7 @@ inline static uint8_t _tvoc_read_status_reg(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if DBG_TVOC - LOGI("TV: status reg: %x\n",status_reg_cmd[1]); -#endif + DBG_TVOC("TV: status reg: %x\n",status_reg_cmd[1]); return status_reg_cmd[1]; @@ -413,9 +414,7 @@ inline static uint8_t _tvoc_read_err_id(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if DBG_TVOC - LOGI("TV: err id: %x\n",err_id_cmd[1]); -#endif + DBG_TVOC("TV: err id: %x\n",err_id_cmd[1]); return err_id_cmd[1]; @@ -447,9 +446,7 @@ inline static int _tvoc_erase_app(void){ int ret = _tvoc_read_status_reg() & APP_VALID_MASK; -#if DBG_TVOC - LOGI("TV:erase ret:%d, APP_VALID_MASK: %d\n",ret, APP_VALID_MASK); -#endif + DBG_TVOC("TV:erase ret:%d, APP_VALID_MASK: %d\n",ret, APP_VALID_MASK); if(ret) return -1; else return 0; @@ -522,7 +519,7 @@ inline static uint8_t _tvoc_get_hw_version(void){ return hw_ver_cmd[1]; } -inline static uint8_t _tvoc_get_fw_boot_version(void){ +inline static uint16_t _tvoc_get_fw_boot_version(void){ uint8_t fw_boot_ver_cmd[3] = {0x23, 0xFF, 0xFF}; @@ -534,15 +531,15 @@ inline static uint8_t _tvoc_get_fw_boot_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if DBG_TVOC - LOGI("FW Boot: 0x%x%x\n",fw_boot_ver_cmd[1], fw_boot_ver_cmd[2] ); +#if 1 + LOGI("FW Boot: 0x%x\n",fw_boot_ver_cmd[1]<<8 | fw_boot_ver_cmd[2] ); #endif - return fw_boot_ver_cmd[1]; + return (fw_boot_ver_cmd[1]<<8) | fw_boot_ver_cmd[2]; } -inline static uint8_t _tvoc_get_fw_app_version(void){ +inline static uint16_t _tvoc_get_fw_app_version(void){ uint8_t fw_app_ver_cmd[3] = {0x24, 0xFF, 0xFF}; @@ -554,11 +551,11 @@ inline static uint8_t _tvoc_get_fw_app_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if DBG_TVOC - LOGI("FW APP: 0x%x%x\n",fw_app_ver_cmd[1], fw_app_ver_cmd[2] ); +#if 1 + LOGI("FW APP: 0x%x\n",(fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2] ); #endif - return fw_app_ver_cmd[1]; + return (fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2]; } // CCS811 firmware update @@ -584,9 +581,7 @@ int tvoc_fw_update(const char* file) vTaskDelay(100); -#if DBG_TVOC - LOGI("TV: Bootloader Mode: %x\n",_tvoc_read_status_reg()); -#endif + DBG_TVOC("TV: Bootloader Mode: %x\n",_tvoc_read_status_reg()); // erase application if(_tvoc_erase_app()){ @@ -641,7 +636,7 @@ int cmd_tvoc_fw_update(int argc, char *argv[]) { // Cmd to get hardware and fw version of CCS811 int cmd_tvoc_get_ver(int argc, char *argv[]) { - LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x, FW App Version: 0x%x- \n", + 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; From 4727c155cc782d08770db56576f06b1253f1f191 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 23 Jan 2017 14:21:01 -0800 Subject: [PATCH 09/20] text --- kitsune/i2c_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index df9ab3d9..e76456f9 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -598,7 +598,7 @@ int tvoc_fw_update(const char* file) // verify if(!_tvoc_verify_app()){ - LOGI("*TVOC FW UPDATE* \n -Current HW version: 0x%x. FW Boot Version: 0x%x, FW App Version: 0x%x- \n", + LOGI("*TVOC FW UPDATE DONE* \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()); // reset CCS811 From 5f6c00f4ce68e1da99016e40effd5a18a676b04d Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 23 Jan 2017 14:21:34 -0800 Subject: [PATCH 10/20] updated proto fields for tvoc fw update --- kitsune/protobuf/periodic.pb.c | 17 +++++++++++++---- kitsune/protobuf/periodic.pb.h | 32 +++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/kitsune/protobuf/periodic.pb.c b/kitsune/protobuf/periodic.pb.c index 01094822..221e4393 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 Jan 23 14:16:44 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_fw_data, keyword_stats, &periodic_data_tvoc_fw_fields), PB_LAST_FIELD }; @@ -46,6 +47,14 @@ const pb_field_t periodic_data_light_data_fields[8] = { PB_LAST_FIELD }; +const pb_field_t periodic_data_tvoc_fw_fields[5] = { + PB_FIELD( 1, BOOL , OPTIONAL, STATIC , FIRST, periodic_data_tvoc_fw, update_tvoc_fw, update_tvoc_fw, 0), + PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, tvoc_app_fw_version, update_tvoc_fw, 0), + PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, tvoc_boot_fw_version, tvoc_app_fw_version, 0), + PB_FIELD( 4, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, 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 +84,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_fw_data) < 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_tvoc_fw_batched_periodic_data_batched_periodic_data_wifi_access_point) #endif #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) @@ -86,7 +95,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_fw_data) < 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_tvoc_fw_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..7aea4cce 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 Jan 23 14:16:44 2017. */ #ifndef PB_PERIODIC_PB_H_INCLUDED #define PB_PERIODIC_PB_H_INCLUDED @@ -60,6 +60,17 @@ typedef struct _periodic_data_light_data { int32_t uv_count; } periodic_data_light_data; +typedef struct _periodic_data_tvoc_fw { + bool has_update_tvoc_fw; + bool update_tvoc_fw; + 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_tvoc_fw; + typedef struct _periodic_data { bool has_unix_time; int32_t unix_time; @@ -105,17 +116,21 @@ typedef struct _periodic_data { int32_t light_duration_ms; bool has_keyword_stats; KeywordStats keyword_stats; + bool has_tvoc_fw_data; + periodic_data_tvoc_fw tvoc_fw_data; } 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_tvoc_fw_init_default} #define periodic_data_light_data_init_default {0, 0, 0, false, 0, false, 0, false, 0, false, 0} +#define periodic_data_tvoc_fw_init_default {false, 0, 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_tvoc_fw_init_zero} #define periodic_data_light_data_init_zero {0, 0, 0, false, 0, false, 0, false, 0, false, 0} +#define periodic_data_tvoc_fw_init_zero {false, 0, 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} @@ -138,6 +153,10 @@ typedef struct _periodic_data { #define periodic_data_light_data_clear_tag 5 #define periodic_data_light_data_lux_count_tag 6 #define periodic_data_light_data_uv_count_tag 7 +#define periodic_data_tvoc_fw_update_tvoc_fw_tag 1 +#define periodic_data_tvoc_fw_tvoc_app_fw_version_tag 2 +#define periodic_data_tvoc_fw_tvoc_boot_fw_version_tag 3 +#define periodic_data_tvoc_fw_tvoc_hw_version_tag 4 #define periodic_data_unix_time_tag 1 #define periodic_data_light_tag 2 #define periodic_data_temperature_tag 3 @@ -160,16 +179,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_fw_data_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_tvoc_fw_fields[5]; 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 (335 + KeywordStats_size) #define periodic_data_light_data_size 77 +#define periodic_data_tvoc_fw_size 20 #define batched_periodic_data_wifi_access_point_size 52 #ifdef __cplusplus From decebc4960832564f862d639453e5b8dbbd443c0 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 23 Jan 2017 14:29:43 -0800 Subject: [PATCH 11/20] moved update_tvoc_fw to sync response proto --- kitsune/protobuf/periodic.pb.c | 17 +++++++------- kitsune/protobuf/periodic.pb.h | 35 +++++++++++++---------------- kitsune/protobuf/sync_response.pb.c | 5 +++-- kitsune/protobuf/sync_response.pb.h | 11 +++++---- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/kitsune/protobuf/periodic.pb.c b/kitsune/protobuf/periodic.pb.c index 221e4393..ea72833f 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 Mon Jan 23 14:16:44 2017. */ +/* Generated by nanopb-0.3.1 at Mon Jan 23 14:27:04 2017. */ #include "periodic.pb.h" @@ -32,7 +32,7 @@ const pb_field_t periodic_data_fields[24] = { 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_fw_data, keyword_stats, &periodic_data_tvoc_fw_fields), + PB_FIELD( 28, MESSAGE , OPTIONAL, STATIC , OTHER, periodic_data, tvoc_ver, keyword_stats, &periodic_data_tvoc_version_fields), PB_LAST_FIELD }; @@ -47,11 +47,10 @@ const pb_field_t periodic_data_light_data_fields[8] = { PB_LAST_FIELD }; -const pb_field_t periodic_data_tvoc_fw_fields[5] = { - PB_FIELD( 1, BOOL , OPTIONAL, STATIC , FIRST, periodic_data_tvoc_fw, update_tvoc_fw, update_tvoc_fw, 0), - PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, tvoc_app_fw_version, update_tvoc_fw, 0), - PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, tvoc_boot_fw_version, tvoc_app_fw_version, 0), - PB_FIELD( 4, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_fw, tvoc_hw_version, tvoc_boot_fw_version, 0), +const pb_field_t periodic_data_tvoc_version_fields[4] = { + PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, periodic_data_tvoc_version, tvoc_app_fw_version, tvoc_app_fw_version, 0), + PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_version, tvoc_boot_fw_version, tvoc_app_fw_version, 0), + PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_version, tvoc_hw_version, tvoc_boot_fw_version, 0), PB_LAST_FIELD }; @@ -84,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(periodic_data, tvoc_fw_data) < 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_tvoc_fw_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_ver) < 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_tvoc_version_batched_periodic_data_batched_periodic_data_wifi_access_point) #endif #if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) @@ -95,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(periodic_data, tvoc_fw_data) < 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_tvoc_fw_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_ver) < 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_tvoc_version_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 7aea4cce..ca921bce 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 Mon Jan 23 14:16:44 2017. */ +/* Generated by nanopb-0.3.1 at Mon Jan 23 14:27:04 2017. */ #ifndef PB_PERIODIC_PB_H_INCLUDED #define PB_PERIODIC_PB_H_INCLUDED @@ -60,16 +60,14 @@ typedef struct _periodic_data_light_data { int32_t uv_count; } periodic_data_light_data; -typedef struct _periodic_data_tvoc_fw { - bool has_update_tvoc_fw; - bool update_tvoc_fw; +typedef struct _periodic_data_tvoc_version { 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_tvoc_fw; +} periodic_data_tvoc_version; typedef struct _periodic_data { bool has_unix_time; @@ -116,21 +114,21 @@ typedef struct _periodic_data { int32_t light_duration_ms; bool has_keyword_stats; KeywordStats keyword_stats; - bool has_tvoc_fw_data; - periodic_data_tvoc_fw tvoc_fw_data; + bool has_tvoc_ver; + periodic_data_tvoc_version tvoc_ver; } 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, false, periodic_data_tvoc_fw_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_tvoc_version_init_default} #define periodic_data_light_data_init_default {0, 0, 0, false, 0, false, 0, false, 0, false, 0} -#define periodic_data_tvoc_fw_init_default {false, 0, false, 0, false, 0, false, 0} +#define periodic_data_tvoc_version_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, false, periodic_data_tvoc_fw_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_tvoc_version_init_zero} #define periodic_data_light_data_init_zero {0, 0, 0, false, 0, false, 0, false, 0, false, 0} -#define periodic_data_tvoc_fw_init_zero {false, 0, false, 0, false, 0, false, 0} +#define periodic_data_tvoc_version_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} @@ -153,10 +151,9 @@ typedef struct _periodic_data { #define periodic_data_light_data_clear_tag 5 #define periodic_data_light_data_lux_count_tag 6 #define periodic_data_light_data_uv_count_tag 7 -#define periodic_data_tvoc_fw_update_tvoc_fw_tag 1 -#define periodic_data_tvoc_fw_tvoc_app_fw_version_tag 2 -#define periodic_data_tvoc_fw_tvoc_boot_fw_version_tag 3 -#define periodic_data_tvoc_fw_tvoc_hw_version_tag 4 +#define periodic_data_tvoc_version_tvoc_app_fw_version_tag 1 +#define periodic_data_tvoc_version_tvoc_boot_fw_version_tag 2 +#define periodic_data_tvoc_version_tvoc_hw_version_tag 3 #define periodic_data_unix_time_tag 1 #define periodic_data_light_tag 2 #define periodic_data_temperature_tag 3 @@ -179,19 +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_fw_data_tag 28 +#define periodic_data_tvoc_ver_tag 28 /* Struct field encoding specification for nanopb */ 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_tvoc_fw_fields[5]; +extern const pb_field_t periodic_data_tvoc_version_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 (335 + KeywordStats_size) +#define periodic_data_size (333 + KeywordStats_size) #define periodic_data_light_data_size 77 -#define periodic_data_tvoc_fw_size 20 +#define periodic_data_tvoc_version_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..fd139cc0 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 Jan 23 14:27:04 2017. */ #include "sync_response.pb.h" @@ -31,7 +31,7 @@ const pb_field_t SyncResponse_fields[18] = { PB_LAST_FIELD }; -const pb_field_t SyncResponse_FileDownload_fields[12] = { +const pb_field_t SyncResponse_FileDownload_fields[13] = { PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, SyncResponse_FileDownload, host, host, 0), PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, url, host, 0), PB_FIELD( 3, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, sd_card_filename, url, 0), @@ -43,6 +43,7 @@ const pb_field_t SyncResponse_FileDownload_fields[12] = { PB_FIELD( 9, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, sd_card_path, serial_flash_path, 0), PB_FIELD( 10, BYTES , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, sha1, sd_card_path, 0), PB_FIELD( 11, INT32 , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, file_size, sha1, 0), + PB_FIELD( 12, BOOL , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, update_tvoc_fw, file_size, 0), PB_LAST_FIELD }; diff --git a/kitsune/protobuf/sync_response.pb.h b/kitsune/protobuf/sync_response.pb.h index 061563e4..0ee987df 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 Jan 23 14:27:04 2017. */ #ifndef PB_SYNC_RESPONSE_PB_H_INCLUDED #define PB_SYNC_RESPONSE_PB_H_INCLUDED @@ -77,6 +77,8 @@ typedef struct _SyncResponse_FileDownload { SyncResponse_FileDownload_sha1_t sha1; bool has_file_size; int32_t file_size; + bool has_update_tvoc_fw; + bool update_tvoc_fw; } SyncResponse_FileDownload; typedef struct _SyncResponse_FlashAction { @@ -179,7 +181,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; /* Initializer values for message structs */ #define SyncResponse_init_default {false, SyncResponse_Alarm_init_default, false, SyncResponse_WhiteNoise_init_default, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_default, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_default, false, 0} -#define SyncResponse_FileDownload_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} +#define SyncResponse_FileDownload_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0, false, 0} #define SyncResponse_Alarm_init_default {false, 0, false, 0, false, 1, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_default {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} #define SyncResponse_WhiteNoise_init_default {false, 0, false, 0, false, 0} @@ -188,7 +190,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_PillSettings_init_default {false, "", false, 0} #define BatchedPillSettings_init_default {0, {SyncResponse_PillSettings_init_default, SyncResponse_PillSettings_init_default}} #define SyncResponse_init_zero {false, SyncResponse_Alarm_init_zero, false, SyncResponse_WhiteNoise_init_zero, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_zero, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_zero, false, 0} -#define SyncResponse_FileDownload_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} +#define SyncResponse_FileDownload_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0, false, 0} #define SyncResponse_Alarm_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_zero {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} #define SyncResponse_WhiteNoise_init_zero {false, 0, false, 0, false, 0} @@ -215,6 +217,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_FileDownload_sd_card_path_tag 9 #define SyncResponse_FileDownload_sha1_tag 10 #define SyncResponse_FileDownload_file_size_tag 11 +#define SyncResponse_FileDownload_update_tvoc_fw_tag 12 #define SyncResponse_FlashAction_red_tag 1 #define SyncResponse_FlashAction_green_tag 2 #define SyncResponse_FlashAction_blue_tag 3 @@ -256,7 +259,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; /* Struct field encoding specification for nanopb */ extern const pb_field_t SyncResponse_fields[18]; -extern const pb_field_t SyncResponse_FileDownload_fields[12]; +extern const pb_field_t SyncResponse_FileDownload_fields[13]; extern const pb_field_t SyncResponse_Alarm_fields[7]; extern const pb_field_t SyncResponse_PairingAction_fields[3]; extern const pb_field_t SyncResponse_WhiteNoise_fields[4]; From 8fb35d7d0a16c5fe0da60e54d1af61f56f06daad Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 23 Jan 2017 14:44:55 -0800 Subject: [PATCH 12/20] update fw from download task --- kitsune/fatfs_cmd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kitsune/fatfs_cmd.c b/kitsune/fatfs_cmd.c index 8aaa957d..b7dd19aa 100644 --- a/kitsune/fatfs_cmd.c +++ b/kitsune/fatfs_cmd.c @@ -999,6 +999,8 @@ xQueueHandle download_queue = 0; hlo_stream_t * hlo_http_get_opt(hlo_stream_t * sock, const char * host, const char * endpoint); +int tvoc_fw_update(const char* file); + void file_download_task( void * params ) { SyncResponse_FileDownload download_info; unsigned char top_sha_cache[SHA1_SIZE]; @@ -1194,6 +1196,14 @@ void file_download_task( void * params ) { LOGI( "reset nwp\n" ); nwp_reset(); } + if(download_info.has_update_tvoc_fw && download_info.update_tvoc_fw ) { + // Update TVOC firmware + LOGI("Update TVOC fw \n"); + int err_code = tvoc_fw_update(filename); + if( err_code ) { + LOGE("TVOC firmware update not successful %d\n", err_code); + } + } next_one: free_download_info(&download_info); continue; From a296b6efdce6a34dd2f8442c8ac44b8721abd09f Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 23 Jan 2017 16:57:48 -0800 Subject: [PATCH 13/20] tvoc ver in periodic upload --- kitsune/commands.c | 8 ++++++++ kitsune/i2c_cmd.c | 13 +++++++------ kitsune/i2c_cmd.h | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index a5273b47..5d767e14 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_ver = true; + data->tvoc_ver.has_tvoc_app_fw_version = true; + data->tvoc_ver.tvoc_app_fw_version = tvoc_get_fw_app_version(); + data->tvoc_ver.has_tvoc_boot_fw_version = true; + data->tvoc_ver.tvoc_boot_fw_version = tvoc_get_fw_boot_version(); + data->tvoc_ver.has_tvoc_hw_version = true; + data->tvoc_ver.tvoc_hw_version = tvoc_get_hw_version(); } } } diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index e76456f9..39795082 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -504,7 +504,7 @@ inline static int _tvoc_verify_app(void){ return ( (_tvoc_read_status_reg() & APP_VALID_MASK) ? 0:-1); } -inline static uint8_t _tvoc_get_hw_version(void){ +uint8_t tvoc_get_hw_version(void){ uint8_t hw_ver_cmd[2] = {0x21, 0xFF}; @@ -519,7 +519,7 @@ inline static uint8_t _tvoc_get_hw_version(void){ return hw_ver_cmd[1]; } -inline static uint16_t _tvoc_get_fw_boot_version(void){ +uint16_t tvoc_get_fw_boot_version(void){ uint8_t fw_boot_ver_cmd[3] = {0x23, 0xFF, 0xFF}; @@ -539,7 +539,7 @@ inline static uint16_t _tvoc_get_fw_boot_version(void){ } -inline static uint16_t _tvoc_get_fw_app_version(void){ +uint16_t tvoc_get_fw_app_version(void){ uint8_t fw_app_ver_cmd[3] = {0x24, 0xFF, 0xFF}; @@ -558,6 +558,7 @@ inline static uint16_t _tvoc_get_fw_app_version(void){ return (fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2]; } + // CCS811 firmware update // Returns 0 if firmware update is successful, -1 otherwise int tvoc_fw_update(const char* file) @@ -565,7 +566,7 @@ int tvoc_fw_update(const char* file) int ret_val = 0; LOGI("*TVOC FW UPDATE* \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()); + tvoc_get_hw_version(), tvoc_get_fw_boot_version(), tvoc_get_fw_app_version()); if( !file ){ @@ -599,7 +600,7 @@ int tvoc_fw_update(const char* file) // verify if(!_tvoc_verify_app()){ LOGI("*TVOC FW UPDATE DONE* \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()); + tvoc_get_hw_version(), tvoc_get_fw_boot_version(), tvoc_get_fw_app_version()); // reset CCS811 if(_tvoc_reset()){ @@ -637,7 +638,7 @@ int cmd_tvoc_fw_update(int argc, char *argv[]) { 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()); + tvoc_get_hw_version(), tvoc_get_fw_boot_version(), tvoc_get_fw_app_version()); return 0; } diff --git a/kitsune/i2c_cmd.h b/kitsune/i2c_cmd.h index 8258ca61..c3cfa10c 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, From a12cadd906295d6c09a28cca1cb7f14caf339684 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Mon, 30 Jan 2017 15:03:54 -0800 Subject: [PATCH 14/20] tvfw cmd options --- kitsune/i2c_cmd.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 39795082..b5bd990e 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -452,7 +452,7 @@ inline static int _tvoc_erase_app(void){ else return 0; } -#define PATH_BUF_MAX_SIZE (64) +#define BIN_FILENAME_LENGTH (64) #include "ff.h" #include "hellofilesystem.h" inline static int _tvoc_program_app(const char* file){ @@ -561,19 +561,35 @@ uint16_t tvoc_get_fw_app_version(void){ // CCS811 firmware update // Returns 0 if firmware update is successful, -1 otherwise -int tvoc_fw_update(const char* file) +int tvoc_fw_update(const char* path, const char* filename) { int ret_val = 0; + char bin_file[BIN_FILENAME_LENGTH]; LOGI("*TVOC FW UPDATE* \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()); - if( !file ){ + if( !filename || !path ){ ret_val = -5; goto tvoc_fail; } + if(strlen(path) + strlen(filename) + 1 + 1 > BIN_FILENAME_LENGTH) + { + ret_val = -6; + goto tvoc_fail; + } + + strncpy(bin_file,path,BIN_FILENAME_LENGTH); + if(strcmp("/", bin_file)) + { + strcat(bin_file, "/"); + } + strncat(bin_file, filename, BIN_FILENAME_LENGTH); + + LOGI("TVOC FW Filename:%s\n",bin_file); + // reset CCS811 if(_tvoc_reset()){ ret_val = -2; @@ -591,7 +607,7 @@ int tvoc_fw_update(const char* file) } // read binary and write to CCS811 - if(_tvoc_program_app(file)){ + if(_tvoc_program_app(bin_file)){ ret_val = -1; goto tvoc_fail; } @@ -626,12 +642,25 @@ int tvoc_fw_update(const char* file) // Cmd to firmware update CCS811 int cmd_tvoc_fw_update(int argc, char *argv[]) { - if(argc < 2) { - LOGE("Usage: tvfw $full_path_to_file"); + if(argc < 4) { + LOGE("Usage: tvfw <1-update directly, 2-update via task> \n"); return -1; } - return tvoc_fw_update(argv[1]); + if(atoi(argv[1]) == 1){ + // update firmware using filename and path + tvoc_fw_update(argv[2],argv[3]); + } + else if(atoi(argv[1]) == 2) { + // Update firmware using file download task + + } + else { + LOGE("Usage: tvfw <1-update directly, 2-update via task> \n"); + return -1; + } + + return 0; } // Cmd to get hardware and fw version of CCS811 From 158ffa522178404cdbfa625c0a0ad2c47567905c Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Tue, 31 Jan 2017 12:50:29 -0800 Subject: [PATCH 15/20] Fix function --- kitsune/fatfs_cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kitsune/fatfs_cmd.c b/kitsune/fatfs_cmd.c index b7dd19aa..a80281d7 100644 --- a/kitsune/fatfs_cmd.c +++ b/kitsune/fatfs_cmd.c @@ -999,7 +999,7 @@ xQueueHandle download_queue = 0; hlo_stream_t * hlo_http_get_opt(hlo_stream_t * sock, const char * host, const char * endpoint); -int tvoc_fw_update(const char* file); +int tvoc_fw_update(const char* path, const char* filename); void file_download_task( void * params ) { SyncResponse_FileDownload download_info; @@ -1199,7 +1199,7 @@ void file_download_task( void * params ) { if(download_info.has_update_tvoc_fw && download_info.update_tvoc_fw ) { // Update TVOC firmware LOGI("Update TVOC fw \n"); - int err_code = tvoc_fw_update(filename); + int err_code = tvoc_fw_update(path, filename); if( err_code ) { LOGE("TVOC firmware update not successful %d\n", err_code); } From 6218fc5d4d516fd12b4552f779faa1e2c5359ee6 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 2 Feb 2017 11:11:07 -0800 Subject: [PATCH 16/20] updated for only periodic version upload --- kitsune/protobuf/periodic.pb.c | 2 +- kitsune/protobuf/periodic.pb.h | 2 +- kitsune/protobuf/sync_response.pb.c | 5 ++--- kitsune/protobuf/sync_response.pb.h | 11 ++++------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/kitsune/protobuf/periodic.pb.c b/kitsune/protobuf/periodic.pb.c index ea72833f..17ab5ed9 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 Mon Jan 23 14:27:04 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:06:48 2017. */ #include "periodic.pb.h" diff --git a/kitsune/protobuf/periodic.pb.h b/kitsune/protobuf/periodic.pb.h index ca921bce..9bc5812f 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 Mon Jan 23 14:27:04 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:06:48 2017. */ #ifndef PB_PERIODIC_PB_H_INCLUDED #define PB_PERIODIC_PB_H_INCLUDED diff --git a/kitsune/protobuf/sync_response.pb.c b/kitsune/protobuf/sync_response.pb.c index fd139cc0..2bc4b616 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 Mon Jan 23 14:27:04 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:06:49 2017. */ #include "sync_response.pb.h" @@ -31,7 +31,7 @@ const pb_field_t SyncResponse_fields[18] = { PB_LAST_FIELD }; -const pb_field_t SyncResponse_FileDownload_fields[13] = { +const pb_field_t SyncResponse_FileDownload_fields[12] = { PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, SyncResponse_FileDownload, host, host, 0), PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, url, host, 0), PB_FIELD( 3, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, sd_card_filename, url, 0), @@ -43,7 +43,6 @@ const pb_field_t SyncResponse_FileDownload_fields[13] = { PB_FIELD( 9, STRING , OPTIONAL, CALLBACK, OTHER, SyncResponse_FileDownload, sd_card_path, serial_flash_path, 0), PB_FIELD( 10, BYTES , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, sha1, sd_card_path, 0), PB_FIELD( 11, INT32 , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, file_size, sha1, 0), - PB_FIELD( 12, BOOL , OPTIONAL, STATIC , OTHER, SyncResponse_FileDownload, update_tvoc_fw, file_size, 0), PB_LAST_FIELD }; diff --git a/kitsune/protobuf/sync_response.pb.h b/kitsune/protobuf/sync_response.pb.h index 0ee987df..c28b7cc9 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 Mon Jan 23 14:27:04 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:06:49 2017. */ #ifndef PB_SYNC_RESPONSE_PB_H_INCLUDED #define PB_SYNC_RESPONSE_PB_H_INCLUDED @@ -77,8 +77,6 @@ typedef struct _SyncResponse_FileDownload { SyncResponse_FileDownload_sha1_t sha1; bool has_file_size; int32_t file_size; - bool has_update_tvoc_fw; - bool update_tvoc_fw; } SyncResponse_FileDownload; typedef struct _SyncResponse_FlashAction { @@ -181,7 +179,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; /* Initializer values for message structs */ #define SyncResponse_init_default {false, SyncResponse_Alarm_init_default, false, SyncResponse_WhiteNoise_init_default, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_default, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_default, false, 0} -#define SyncResponse_FileDownload_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0, false, 0} +#define SyncResponse_FileDownload_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} #define SyncResponse_Alarm_init_default {false, 0, false, 0, false, 1, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_default {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} #define SyncResponse_WhiteNoise_init_default {false, 0, false, 0, false, 0} @@ -190,7 +188,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_PillSettings_init_default {false, "", false, 0} #define BatchedPillSettings_init_default {0, {SyncResponse_PillSettings_init_default, SyncResponse_PillSettings_init_default}} #define SyncResponse_init_zero {false, SyncResponse_Alarm_init_zero, false, SyncResponse_WhiteNoise_init_zero, false, 0, false, (SyncResponse_RoomConditions)0, {{NULL}, NULL}, false, 0, false, AudioControl_init_zero, false, {0, {0}}, false, 0, {{NULL}, NULL}, false, 0, false, 0, false, 0, false, "", false, (SyncResponse_RoomConditions)0, false, AudioFeaturesControl_init_zero, false, 0} -#define SyncResponse_FileDownload_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0, false, 0} +#define SyncResponse_FileDownload_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, 0, false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, {0, {0}}, false, 0} #define SyncResponse_Alarm_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, ""} #define SyncResponse_PairingAction_init_zero {{{NULL}, NULL}, false, (SyncResponse_PairingAction_ActionType)0} #define SyncResponse_WhiteNoise_init_zero {false, 0, false, 0, false, 0} @@ -217,7 +215,6 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; #define SyncResponse_FileDownload_sd_card_path_tag 9 #define SyncResponse_FileDownload_sha1_tag 10 #define SyncResponse_FileDownload_file_size_tag 11 -#define SyncResponse_FileDownload_update_tvoc_fw_tag 12 #define SyncResponse_FlashAction_red_tag 1 #define SyncResponse_FlashAction_green_tag 2 #define SyncResponse_FlashAction_blue_tag 3 @@ -259,7 +256,7 @@ extern const int32_t SyncResponse_Alarm_ringtone_id_default; /* Struct field encoding specification for nanopb */ extern const pb_field_t SyncResponse_fields[18]; -extern const pb_field_t SyncResponse_FileDownload_fields[13]; +extern const pb_field_t SyncResponse_FileDownload_fields[12]; extern const pb_field_t SyncResponse_Alarm_fields[7]; extern const pb_field_t SyncResponse_PairingAction_fields[3]; extern const pb_field_t SyncResponse_WhiteNoise_fields[4]; From a22a7c8ae75620b5da42618c107da96273744dd8 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 2 Feb 2017 11:15:32 -0800 Subject: [PATCH 17/20] removed fw updated related code --- kitsune/fatfs_cmd.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/kitsune/fatfs_cmd.c b/kitsune/fatfs_cmd.c index a80281d7..afaa9d4b 100644 --- a/kitsune/fatfs_cmd.c +++ b/kitsune/fatfs_cmd.c @@ -1196,14 +1196,6 @@ void file_download_task( void * params ) { LOGI( "reset nwp\n" ); nwp_reset(); } - if(download_info.has_update_tvoc_fw && download_info.update_tvoc_fw ) { - // Update TVOC firmware - LOGI("Update TVOC fw \n"); - int err_code = tvoc_fw_update(path, filename); - if( err_code ) { - LOGE("TVOC firmware update not successful %d\n", err_code); - } - } next_one: free_download_info(&download_info); continue; From e30ab13005ef301555ae8f0b0ade4dff494c75c8 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 2 Feb 2017 11:41:49 -0800 Subject: [PATCH 18/20] updated protobuf --- kitsune/commands.c | 14 +++++------ kitsune/protobuf/periodic.pb.c | 16 ++++++------- kitsune/protobuf/periodic.pb.h | 44 +++++++++++++++++----------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/kitsune/commands.c b/kitsune/commands.c index 7165e4c4..6d4d4dfb 100644 --- a/kitsune/commands.c +++ b/kitsune/commands.c @@ -1299,13 +1299,13 @@ void sample_sensor_data(periodic_data* data,NetStats_t * keyword_net_stats) data->has_co2 = true; data->co2 = eco2; - data->has_tvoc_ver = true; - data->tvoc_ver.has_tvoc_app_fw_version = true; - data->tvoc_ver.tvoc_app_fw_version = tvoc_get_fw_app_version(); - data->tvoc_ver.has_tvoc_boot_fw_version = true; - data->tvoc_ver.tvoc_boot_fw_version = tvoc_get_fw_boot_version(); - data->tvoc_ver.has_tvoc_hw_version = true; - data->tvoc_ver.tvoc_hw_version = tvoc_get_hw_version(); + 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(); } } } diff --git a/kitsune/protobuf/periodic.pb.c b/kitsune/protobuf/periodic.pb.c index 17ab5ed9..2ede6b8e 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 Thu Feb 02 11:06:48 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:37:12 2017. */ #include "periodic.pb.h" @@ -32,7 +32,7 @@ const pb_field_t periodic_data_fields[24] = { 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_ver, keyword_stats, &periodic_data_tvoc_version_fields), + PB_FIELD( 28, MESSAGE , OPTIONAL, STATIC , OTHER, periodic_data, tvoc_version, keyword_stats, &periodic_data_TvocVersion_fields), PB_LAST_FIELD }; @@ -47,10 +47,10 @@ const pb_field_t periodic_data_light_data_fields[8] = { PB_LAST_FIELD }; -const pb_field_t periodic_data_tvoc_version_fields[4] = { - PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, periodic_data_tvoc_version, tvoc_app_fw_version, tvoc_app_fw_version, 0), - PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_version, tvoc_boot_fw_version, tvoc_app_fw_version, 0), - PB_FIELD( 3, UINT32 , OPTIONAL, STATIC , OTHER, periodic_data_tvoc_version, tvoc_hw_version, tvoc_boot_fw_version, 0), +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 }; @@ -83,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(periodic_data, tvoc_ver) < 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_tvoc_version_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) @@ -94,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(periodic_data, tvoc_ver) < 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_tvoc_version_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 9bc5812f..e1785252 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 Thu Feb 02 11:06:48 2017. */ +/* Generated by nanopb-0.3.1 at Thu Feb 02 11:37:12 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; @@ -60,15 +69,6 @@ typedef struct _periodic_data_light_data { int32_t uv_count; } periodic_data_light_data; -typedef struct _periodic_data_tvoc_version { - 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_tvoc_version; - typedef struct _periodic_data { bool has_unix_time; int32_t unix_time; @@ -114,21 +114,21 @@ typedef struct _periodic_data { int32_t light_duration_ms; bool has_keyword_stats; KeywordStats keyword_stats; - bool has_tvoc_ver; - periodic_data_tvoc_version tvoc_ver; + 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, false, periodic_data_tvoc_version_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_tvoc_version_init_default {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, false, periodic_data_tvoc_version_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_tvoc_version_init_zero {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} @@ -144,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 @@ -151,9 +154,6 @@ typedef struct _periodic_data { #define periodic_data_light_data_clear_tag 5 #define periodic_data_light_data_lux_count_tag 6 #define periodic_data_light_data_uv_count_tag 7 -#define periodic_data_tvoc_version_tvoc_app_fw_version_tag 1 -#define periodic_data_tvoc_version_tvoc_boot_fw_version_tag 2 -#define periodic_data_tvoc_version_tvoc_hw_version_tag 3 #define periodic_data_unix_time_tag 1 #define periodic_data_light_tag 2 #define periodic_data_temperature_tag 3 @@ -176,19 +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_ver_tag 28 +#define periodic_data_tvoc_version_tag 28 /* Struct field encoding specification for nanopb */ 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_tvoc_version_fields[4]; +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 (333 + KeywordStats_size) #define periodic_data_light_data_size 77 -#define periodic_data_tvoc_version_size 18 +#define periodic_data_TvocVersion_size 18 #define batched_periodic_data_wifi_access_point_size 52 #ifdef __cplusplus From 6429bfc300f6e8bf3f62a9bec656ff800a56c5fe Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 2 Feb 2017 12:01:55 -0800 Subject: [PATCH 19/20] remove unused --- kitsune/i2c_cmd.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 820e4076..3efb75e4 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -557,9 +557,7 @@ uint16_t tvoc_get_fw_boot_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if 1 - LOGI("FW Boot: 0x%x\n",fw_boot_ver_cmd[1]<<8 | fw_boot_ver_cmd[2] ); -#endif + 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]; @@ -577,9 +575,7 @@ uint16_t tvoc_get_fw_app_version(void){ xSemaphoreGiveRecursive(i2c_smphr); } -#if 1 - LOGI("FW APP: 0x%x\n",(fw_app_ver_cmd[1] << 8) | fw_app_ver_cmd[2] ); -#endif + 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]; @@ -668,23 +664,14 @@ int tvoc_fw_update(const char* path, const char* filename) // Cmd to firmware update CCS811 int cmd_tvoc_fw_update(int argc, char *argv[]) { - if(argc < 4) { - LOGE("Usage: tvfw <1-update directly, 2-update via task> \n"); + if(argc < 3) { + LOGE("Usage: tvfw \n"); return -1; } - if(atoi(argv[1]) == 1){ - // update firmware using filename and path - tvoc_fw_update(argv[2],argv[3]); - } - else if(atoi(argv[1]) == 2) { - // Update firmware using file download task + // update firmware using filename and path + tvoc_fw_update(argv[1],argv[2]); - } - else { - LOGE("Usage: tvfw <1-update directly, 2-update via task> \n"); - return -1; - } return 0; } From 1c292aab090bcb9e25d8553533e41697a0659305 Mon Sep 17 00:00:00 2001 From: Divya Kamath Date: Thu, 2 Feb 2017 15:53:56 -0800 Subject: [PATCH 20/20] Updated init tvoc - removed status register read before boot since the register contents are garbage - added check for app valid. if sensor is in a bad state after a fw update, the status register read after boot will indicate the same - use Uartprintf instead of LOGI because init_tvoc is called before uart logger init --- kitsune/i2c_cmd.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/kitsune/i2c_cmd.c b/kitsune/i2c_cmd.c index 3efb75e4..53fed8db 100644 --- a/kitsune/i2c_cmd.c +++ b/kitsune/i2c_cmd.c @@ -249,20 +249,13 @@ int Cmd_read_temp_hum_press(int argc, char *argv[]) { ********************************************************************************/ bool tvoc_wa = false; uint8_t tvoc_i2c_addr = 0x5A; +bool tvoc_app_fw_invalid = false; int init_tvoc(int measmode) { unsigned char b[2]; - assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); - b[0] = 0; - (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); - (I2C_IF_Read(tvoc_i2c_addr, b, 1)); + assert(xSemaphoreTakeRecursive(i2c_smphr, 30000)); - if( !(b[0] & 0x10) ) { - LOGE("no valid fw for TVOC\n"); - xSemaphoreGiveRecursive(i2c_smphr); - return -1; - } - //boot + //boot sensor and start application b[0] = 0xf4; (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); vTaskDelay(100); @@ -270,26 +263,36 @@ int init_tvoc(int measmode) { (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"); + UARTprintf("fail to boot TVOC\n"); xSemaphoreGiveRecursive(i2c_smphr); return -1; } + if( !(b[0] & 0x10) ) { + UARTprintf("no valid fw for TVOC\n"); + tvoc_app_fw_invalid = true; + xSemaphoreGiveRecursive(i2c_smphr); + return -1; + } + + tvoc_app_fw_invalid = false; + + // Set Measure Mode b[0] = 1; b[1] = measmode; (I2C_IF_Write(tvoc_i2c_addr, b, 2, 1)); + // Read sensor firmware version b[0] = 0x24; (I2C_IF_Write(tvoc_i2c_addr, b, 1, 1)); (I2C_IF_Read(tvoc_i2c_addr, b, 2)); - - 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; - } + UARTprintf("TVOC FW %d.%d.%d\n",(b[0]>>4) & 0xf,b[0] & 0xf, b[1]); + if (b[0] == 0x02 && b[1] == 0x4) { + UARTprintf("apply TVOC FW 0.2.4 workaround\n"); + tvoc_wa = true; + } + else { + tvoc_wa = false; + } xSemaphoreGiveRecursive(i2c_smphr); return 0;