add isInWindowZone() function

This commit is contained in:
CSSC-WORK\murmur 2023-07-27 09:34:00 +08:00
parent 78abcf0b1a
commit 7b2310c1e0
3 changed files with 63 additions and 48 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);