Skip to content

Commit

Permalink
check option flags
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Feb 16, 2022
1 parent 5d3aa6b commit 5b1e13b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/mi_beacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5b1e13b

Please sign in to comment.