From 5b1e13b46a49c08734951b59b9cb9c422290404e Mon Sep 17 00:00:00 2001 From: pvvx Date: Wed, 16 Feb 2022 17:57:48 +0300 Subject: [PATCH] check option flags --- src/app.c | 8 +++----- src/app.h | 10 ++++------ src/cmd_parser.c | 2 -- src/mi_beacon.c | 11 +++++++++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/app.c b/src/app.c index afdf69ec..e5848d25 100644 --- a/src/app.c +++ b/src/app.c @@ -48,7 +48,7 @@ RAM uint32_t min_step_time_update_lcd; // = cfg.min_step_time_update_lcd * 0.05 RAM uint32_t utc_time_sec; // clock in sec (= 0 1970-01-01 00:00:00) RAM uint32_t utc_time_sec_tick; -#if USE_CLOCK && USE_TIME_ADJUST +#if USE_TIME_ADJUST RAM uint32_t utc_time_tick_step = CLOCK_16M_SYS_TIMER_CLK_1S; // adjust time clock (in 1/16 us for 1 sec) #else #define utc_time_tick_step CLOCK_16M_SYS_TIMER_CLK_1S @@ -89,7 +89,7 @@ const cfg_t def_cfg = { .min_step_time_update_lcd = 49, //x0.05 sec, 2.45 sec .hw_cfg.hwver = 6, #endif -#if USE_FLASH_MEMO || USE_CLOCK +#if USE_FLASH_MEMO .hw_cfg.clock = 1, #endif #if USE_FLASH_MEMO @@ -338,7 +338,7 @@ void user_init_normal(void) {//this will get executed one time after power up memcpy(&cfg, &def_cfg, sizeof(cfg)); if(flash_read_cfg(&cmf, EEP_ID_CMF, sizeof(cmf)) != sizeof(cmf)) memcpy(&cmf, &def_cmf, sizeof(cmf)); -#if USE_CLOCK && USE_TIME_ADJUST +#if USE_TIME_ADJUST if(flash_read_cfg(&utc_time_tick_step, EEP_ID_TIM, sizeof(utc_time_tick_step)) != sizeof(utc_time_tick_step)) utc_time_tick_step = CLOCK_16M_SYS_TIMER_CLK_1S; #endif @@ -526,12 +526,10 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void lcd(void) { //----------------------- main_loop() _attribute_ram_code_ void main_loop(void) { blt_sdk_main_loop(); -#if USE_CLOCK || USE_FLASH_MEMO while(clock_time() - utc_time_sec_tick > utc_time_tick_step) { utc_time_sec_tick += utc_time_tick_step; utc_time_sec++; // + 1 sec } -#endif if (wrk_measure && timer_measure_cb && clock_time() - timer_measure_cb > SENSOR_MEASURING_TIMEOUT) { diff --git a/src/app.h b/src/app.h index 17b0472d..a0f908a4 100644 --- a/src/app.h +++ b/src/app.h @@ -72,9 +72,9 @@ typedef struct __attribute__((packed)) _cfg_t { uint8_t min_step_time_update_lcd; // x0.05 sec, 0.5..12.75 sec (10..255) struct __attribute__((packed)) { uint8_t hwver : 3; // 0 - LYWSD03MMC B1.4, 1 - MHO-C401, 2 - CGG1, 3 - LYWSD03MMC B1.6, 4 - LYWSD03MMC B1.9, 5 - LYWSD03MMC B1.7 - uint8_t clock : 1; // clock - uint8_t memo : 1; // flash write measures - uint8_t trg : 1; // trigger out + uint8_t clock : 1; // uses clock (old version < 3.6) + uint8_t memo : 1; // uses flash write measures + uint8_t trg : 1; // uses trigger out uint8_t mi_beacon : 1; // advertising uses mi crypto beacon uint8_t shtc3 : 1; // =1 - sensor SHTC3, = 0 - sensor SHT4x } hw_cfg; // read only @@ -114,10 +114,8 @@ extern external_data_t ext; extern uint32_t chow_tick_clk; // count chow validity time, in clock extern uint32_t chow_tick_sec; // count chow validity time, in sec -#if USE_CLOCK || USE_FLASH_MEMO extern uint32_t utc_time_sec; // clock in sec (= 0 1970-01-01 00:00:00) -#endif -#if USE_CLOCK && USE_TIME_ADJUST +#if USE_TIME_ADJUST extern uint32_t utc_time_tick_step; // adjust time clock (in 1/16 us for 1 sec) #endif diff --git a/src/cmd_parser.c b/src/cmd_parser.c index 93423064..cecefc7b 100644 --- a/src/cmd_parser.c +++ b/src/cmd_parser.c @@ -424,7 +424,6 @@ __attribute__((optimize("-Os"))) void cmd_parser(void * p) { store_mi_keys(MI_KEYTBIND_SIZE, MI_KEYTBIND_ID, &req->dat[1]); get_mi_keys(MI_KEY_STAGE_TBIND); mi_key_stage = MI_KEY_STAGE_WAIT_SEND; -#if USE_CLOCK || USE_FLASH_MEMO } else if (cmd == CMD_ID_UTC_TIME) { // Get/set utc time if(--len > sizeof(utc_time_sec)) len = sizeof(utc_time_sec); if(len) @@ -441,7 +440,6 @@ __attribute__((optimize("-Os"))) void cmd_parser(void * p) { memcpy(&send_buf[1], &utc_time_tick_step, sizeof(utc_time_tick_step)); olen = sizeof(utc_time_tick_step) + 1; #endif -#endif #if USE_FLASH_MEMO } else if (cmd == CMD_ID_LOGGER && len > 2) { // Read memory measures rd_memo.cnt = req->dat[1] | (req->dat[2] << 8); diff --git a/src/mi_beacon.c b/src/mi_beacon.c index c8ec2235..dcde8ad9 100644 --- a/src/mi_beacon.c +++ b/src/mi_beacon.c @@ -191,8 +191,11 @@ void atc_encrypt_beacon(uint32_t cnt) { p->head.counter = (uint8_t)cnt; data.temp = (measured_data.temp + 25) / 50 + 4000 / 50; data.humi = (measured_data.humi + 25) / 50; - data.bat = battery_level | ((trg.flg.trigger_on)? 0x80 : 0); - + data.bat = battery_level +#if USE_TRIGGER_OUT + | ((trg.flg.trigger_on)? 0x80 : 0) +#endif + ; memcpy(&cbn.MAC, mac_public, sizeof(cbn.MAC)); memcpy(&cbn.head, p, sizeof(cbn.head)); aes_ccm_encrypt_and_tag((const unsigned char *)&bindkey, @@ -220,7 +223,11 @@ void pvvx_encrypt_beacon(uint32_t cnt) { data.temp = measured_data.temp; data.humi = measured_data.humi; data.bat = battery_level; +#if USE_TRIGGER_OUT data.trg = trg.flg_byte; +#else + data.trg = 0; +#endif memcpy(&cbn.MAC, mac_public, sizeof(cbn.MAC)); memcpy(&cbn.head, p, sizeof(cbn.head)); aes_ccm_encrypt_and_tag((const unsigned char *)&bindkey,