添加定时发送用闹钟,默认时间为每小时的一刻钟

This commit is contained in:
CSSC-WORK\murmur 2023-08-22 10:06:12 +08:00
parent f4170d06e6
commit ee3f3302f8
2 changed files with 47 additions and 35 deletions

View File

@ -64,18 +64,23 @@ MSH_CMD_EXPORT(alarm_sample,alarm sample);
void poTT_callback(rt_alarm_t alarm, time_t timestamp) void poTT_callback(rt_alarm_t alarm, time_t timestamp)
{ {
LOG_D("power UP TT."); LOG_D("power UP TT by RTC.");
initTT(); initTT();
setWindowMode(); setWindowMode();
} }
void pdTT_callback(rt_alarm_t alarm, time_t timestamp) void pdTT_callback(rt_alarm_t alarm, time_t timestamp)
{ {
LOG_D("power DOWN TT."); LOG_D("power DOWN TT by RTC.");
deInitTT(); deInitTT();
} }
void poTT2_callback(rt_alarm_t alarm, time_t timestamp)
{
LOG_D("power UP TT by RTC.");
initTT();
}
//每个开窗设置对应两个rtc闹钟一个上电一个下电 //每个开窗设置对应两个rtc闹钟一个上电一个下电
//更新开窗设置前需要先清空闹钟设置。可改为调用rt_alarm_control()修改。 //更新开窗设置前需要先清空闹钟设置。可改为调用rt_alarm_control()修改。
static struct rt_alarm *alarm[4];//支持2组开窗共4个闹钟 static struct rt_alarm *alarm[4+1];//支持2组开窗共4个闹钟,加一个定时发送闹钟
#ifndef al #ifndef al
void InitAlarm() void InitAlarm()
{ {
@ -96,42 +101,49 @@ void InitAlarm()
setup.wktime.tm_sec = 0; //p_tm.tm_sec; setup.wktime.tm_sec = 0; //p_tm.tm_sec;
if (RT_NULL != alarm[0]) if (RT_NULL != alarm[0])
{ {
rt_alarm_delete(alarm[0]); // rt_alarm_delete(alarm[0]); //
} }
alarm[0] = rt_alarm_create(poTT_callback, &setup); alarm[0] = rt_alarm_create(poTT_callback, &setup);
setup.wktime.tm_hour = 2; //开窗1闭合点 setup.wktime.tm_hour = 2; //开窗1闭合点
if (RT_NULL != alarm[1]) if (RT_NULL != alarm[1])
{ {
rt_alarm_delete(alarm[1]); // rt_alarm_delete(alarm[1]); //
} }
alarm[1] = rt_alarm_create(pdTT_callback, &setup); alarm[1] = rt_alarm_create(pdTT_callback, &setup);
setup.wktime.tm_hour = 7; //开窗2开启点 setup.wktime.tm_hour = 7; //开窗2开启点
if (RT_NULL != alarm[2]) if (RT_NULL != alarm[2])
{ {
rt_alarm_delete(alarm[2]); // rt_alarm_delete(alarm[2]); //
} }
alarm[2] = rt_alarm_create(poTT_callback, &setup); alarm[2] = rt_alarm_create(poTT_callback, &setup);
setup.wktime.tm_hour = 8; //开窗2闭合点 setup.wktime.tm_hour = 8; //开窗2闭合点
if (RT_NULL != alarm[3]) if (RT_NULL != alarm[3])
{ {
rt_alarm_delete(alarm[3]); // rt_alarm_delete(alarm[3]); //
} }
alarm[3] = rt_alarm_create(pdTT_callback, &setup); alarm[3] = rt_alarm_create(pdTT_callback, &setup);
setup.flag = RT_ALARM_HOUR;//小时重复
setup.wktime.tm_min = 15; //每小时的1刻钟启动发送
if (RT_NULL != alarm[4])
{
rt_alarm_delete(alarm[4]); //
}
alarm[4] = rt_alarm_create(poTT2_callback, &setup);
for (size_t var = 0; var < 4; var++) { for (size_t var = 0; var < 5; var++) {
if (alarm[var] != RT_NULL) { if (alarm[var] != RT_NULL) {
rt_alarm_start(alarm[var]); rt_alarm_start(alarm[var]);
// LOG_D("alarm %d(%02d:%02d) started.",var+1,alarm[var]->wktime.tm_hour+8,alarm[var]->wktime.tm_min); // LOG_D("alarm %d(%02d:%02d) started.",var+1,alarm[var]->wktime.tm_hour+8,alarm[var]->wktime.tm_min);
}
else {
LOG_E("Failed to start alarm %d.",var+1);
}
} }
else {
LOG_E("Failed to start alarm %d.",var+1);
}
}
} }
#else #else
void updateAlarm(uint8_t *t, size_t len); void updateAlarm(uint8_t *t, size_t len);
@ -202,7 +214,7 @@ void updateAlarm(uint8_t *t, size_t len)
if (alarm[var] != RT_NULL) { if (alarm[var] != RT_NULL) {
rt_alarm_start(alarm[var]); rt_alarm_start(alarm[var]);
// LOG_D("alarm %d started.",var+1); // LOG_D("alarm %d started.",var+1);
LOG_D("alarm %d(%02d:%02d) started.",var+1,alarm[var]->wktime.tm_hour+8,alarm[var]->wktime.tm_min); LOG_D("alarmer %d(%02d:%02d) started.",var+1,alarm[var]->wktime.tm_hour+8,alarm[var]->wktime.tm_min);
} }
else { else {
LOG_E("Failed to start alarm %d.",var+1); LOG_E("Failed to start alarm %d.",var+1);

View File

@ -292,7 +292,7 @@ static void chkAndSendFile_thread_entry()
while (1) while (1)
{ {
// int e; // int e;
LOG_I("等待文件就绪或定时%d分钟超时",scfg.sendInterval); LOG_I("等待发送条件(文件就绪或定时%d分钟超时",scfg.sendInterval);
if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足 RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足
{ {