From 7b2310c1e085c2916982a8e2401293201762440c Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Thu, 27 Jul 2023 09:34:00 +0800 Subject: [PATCH] add isInWindowZone() function --- applications/alarmer.c | 59 ++++++++++++++++++++++++++++++++++++++++++ applications/main.c | 50 +++-------------------------------- applications/uart_3S.c | 2 +- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/applications/alarmer.c b/applications/alarmer.c index c3324cd..04bb25b 100644 --- a/applications/alarmer.c +++ b/applications/alarmer.c @@ -231,5 +231,64 @@ void startAlarm() } } } + +/** + * check if in the WINs zone + * @return 1-in,0-not in + */ +int isInWindowZone() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + time_t now = (long) tv.tv_sec; +// LOG_D("now = %ld", now); + + struct tm *alBegin = &alarm[0]->wktime; + alBegin->tm_hour += 8; + time_t tBegin = mktime(alBegin); + struct tm *alEnd = &alarm[1]->wktime; + alEnd->tm_hour += 8; + time_t tEnd = mktime(alEnd); +// LOG_D("%ld-%ld", (long)tBegin,(long)tEnd); + + uint8_t isIn1 = (now > tBegin && now < tEnd); + + + alBegin = &alarm[2]->wktime; + alBegin->tm_hour += 8; + tBegin = mktime(alBegin); + alEnd = &alarm[3]->wktime; + alEnd->tm_hour += 8; + tEnd = mktime(alEnd); +// LOG_D("%ld-%ld", (long)tBegin,(long)tEnd); + uint8_t isIn2 = (now > tBegin && now < tEnd); + + if (isIn1 || isIn2) + { + LOG_D("is in window zone."); + return 1; + } + else { + return 0; + } +} + +//读取系统毫秒级时间 +//long getCurrentTime() +// +//{ +// +//struct timeval tv; +// +//gettimeofday(&tv,NULL); +// +//LOG_D("ms=%lld", tv.tv_sec * 1000 + tv.tv_usec / 1000); +// +//LOG_D("Current time: %ld.%06ld\n", tv.tv_sec, tv.tv_usec); +// +//} + //MSH_CMD_EXPORT(stopAlarm,stop); //MSH_CMD_EXPORT(startAlarm,start); +//MSH_CMD_EXPORT(isInWindow,isInWindow); +//MSH_CMD_EXPORT(getCurrentTime,getCurrentTime); diff --git a/applications/main.c b/applications/main.c index 2c28f85..a378f44 100644 --- a/applications/main.c +++ b/applications/main.c @@ -39,7 +39,10 @@ int main(void) rt_pin_write(TR485_RE, PIN_LOW); // rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH // rt_pin_write(TT_EN, PIN_HIGH);//关闭TT + if (isInWindowZone()) {//开机检查是否在开窗区间内,是则给TT开机 + pwTT_thread_entry("1"); + } @@ -72,53 +75,6 @@ int main(void) return RT_EOK; } //fastlz_test -c demo.bin f.bin -#ifdef DEMO -void pfdemo(void) -{ -// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); -// char *f = "1023_05_19_15_29_59_254.txt"; -// char *f = "2023_05_19_15_29_59_255.txt"; - char *f = "2023_06_16_10_28_00_123.bin"; - static rt_uint8_t d[10][200] = { }; - static rt_uint8_t s[10] = { }; - rt_uint8_t len = 0; - LOG_D("%p--%p",d,s); - LOG_I("pack %s ...",f); - len = pack_File(f, 0, d, s); - rt_kprintf("len is %d\n", len); - if (len) - { - for (size_t var = 0; var < len; var++) { - LOG_HEX("d",27,d[var],s[var]); - } -// LOG_HEX("pkdata:",27,d[0],s[0]); -// LOG_D("%p--%p",d,s); -// LOG_D("%d--%d--%02X",len,s[0],d[0][0]); - LOG_I("Done."); - } -} -void pp(int argc, char **argv) -{ -// if (argc == 2) - { - /* 创建线程 */ - rt_thread_t thread = rt_thread_create("pmsg2", pfdemo, RT_NULL, 1024 * 10, 25, 10); - /* 创建成功则启动线程 */ - if (thread != RT_NULL) - { - rt_thread_startup(thread); - // rt_kprintf("done"); - } - else - { - LOG_E("thread 'pmsg' create failure."); - return RT_ERROR; - } -} -} - -MSH_CMD_EXPORT(pp, 打包文件。); -#endif INIT_APP_EXPORT(main); diff --git a/applications/uart_3S.c b/applications/uart_3S.c index ec8d601..f310960 100644 --- a/applications/uart_3S.c +++ b/applications/uart_3S.c @@ -177,7 +177,7 @@ static int uart_dma_sample(int argc, char *argv[]) #endif /* 创建定时器1 周期定时器 */ timer1 = rt_timer_create("rxtimer", timeout1, - RT_NULL, rt_tick_from_millisecond(40*1000), + RT_NULL, rt_tick_from_millisecond(5*60*1000), RT_TIMER_FLAG_PERIODIC);