aqhome-react: fixed unit timeprogram.

This commit is contained in:
Martin Preuss
2025-04-21 00:29:53 +02:00
parent b4d71a0fad
commit eea0a66b84

View File

@@ -29,8 +29,8 @@
#define AQHOMEREACT_UNIT_TIMEPROGRAM_OUTSLOT_OUTPUT 0 #define AQHOMEREACT_UNIT_TIMEPROGRAM_OUTSLOT_OUTPUT 0
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_MIN 60 /* 1h */ #define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEFORNEXT_MINS 60 /* 1h */
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_SEC (61*60) /* 61m */ #define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEEVERY_SECS (15*60) /* 15m */
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CHECKINTERVAL_SEC 60 /* 1m */ #define AQHOMEREACT_UNIT_TIMEPROGRAM_CHECKINTERVAL_SEC 60 /* 1m */
@@ -51,7 +51,7 @@ static int _cbProcess(AQHREACT_UNIT *unit);
static int _readRules(AQHREACT_UNIT *unit); static int _readRules(AQHREACT_UNIT *unit);
static int _checkAndAddActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit); static int _checkAndAddActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit);
static int _addActionsForNextMinutes(GWEN_TIMESTAMP *ts, int minutes, static int _addActionsForNextMinutes(AQHREACT_UNIT_TIMEPROGRAM *xunit, int minutes,
const AQHREACT_PRGRULE_LIST *ruleList, MODULE_TIMER_ACTION_LIST *actionList); const AQHREACT_PRGRULE_LIST *ruleList, MODULE_TIMER_ACTION_LIST *actionList);
static int _handlePendingActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit); static int _handlePendingActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit);
@@ -194,9 +194,9 @@ int _checkAndAddActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
int rv; int rv;
now=time(NULL); now=time(NULL);
if (now-xunit->lastCreateTime>AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_SEC) { if ((now-xunit->lastCreateTime)>AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEEVERY_SECS) {
rv=_addActionsForNextMinutes(xunit->nextAddTime, rv=_addActionsForNextMinutes(xunit,
AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_MIN, AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEFORNEXT_MINS,
xunit->ruleList, xunit->ruleList,
xunit->actionList); xunit->actionList);
if (rv<0) { if (rv<0) {
@@ -208,7 +208,7 @@ int _checkAndAddActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
xunit->lastCreateTime=now; xunit->lastCreateTime=now;
} }
if (now-xunit->lastCheckTime>AQHOMEREACT_UNIT_TIMEPROGRAM_CHECKINTERVAL_SEC) { if ((now-xunit->lastCheckTime)>AQHOMEREACT_UNIT_TIMEPROGRAM_CHECKINTERVAL_SEC) {
rv=_handlePendingActions(unit, xunit); rv=_handlePendingActions(unit, xunit);
if (rv<0) { if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv); DBG_INFO(NULL, "here (%d)", rv);
@@ -250,7 +250,7 @@ int _handlePendingActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
nextAction=ModuleTimerAction_List_Next(action); nextAction=ModuleTimerAction_List_Next(action);
if (action->triggerTime<nowInt64) { if (action->triggerTime<nowInt64) {
ModuleTimerAction_List_Del(action); ModuleTimerAction_List_Del(action);
DBG_INFO(NULL, "Sending output value %.2f", action->value); DBG_ERROR(NULL, "Sending output value %.2f", action->value);
AQHREACT_Unit_OutputDoubleData(unit, outputPort, action->value); AQHREACT_Unit_OutputDoubleData(unit, outputPort, action->value);
ModuleTimerAction_free(action); ModuleTimerAction_free(action);
valueSent=1; valueSent=1;
@@ -265,37 +265,45 @@ int _handlePendingActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
int _addActionsForNextMinutes(GWEN_TIMESTAMP *ts, int minutes, const AQHREACT_PRGRULE_LIST *ruleList, MODULE_TIMER_ACTION_LIST *actionList) int _addActionsForNextMinutes(AQHREACT_UNIT_TIMEPROGRAM *xunit,
int minutes,
const AQHREACT_PRGRULE_LIST *ruleList,
MODULE_TIMER_ACTION_LIST *actionList)
{ {
int actionsAdded=0; int actionsAdded=0;
int i; int i;
GWEN_TIMESTAMP *tsWork;
tsWork=GWEN_Timestamp_NowInLocalTime();
for (i=0; i<minutes; i++) { for (i=0; i<minutes; i++) {
const AQHREACT_PRGRULE *rule; if (GWEN_Timestamp_Compare(tsWork, xunit->nextAddTime)==1) {
int64_t triggerTime; int64_t triggerTime;
const AQHREACT_PRGRULE *rule;
triggerTime=GWEN_Timestamp_toInt64(ts); triggerTime=GWEN_Timestamp_toInt64(tsWork);
rule=AQHREACT_PrgRule_List_First(ruleList); rule=AQHREACT_PrgRule_List_First(ruleList);
while(rule) { while(rule) {
if (AQHREACT_PrgRule_Matches(rule, if (AQHREACT_PrgRule_Matches(rule,
GWEN_Timestamp_GetMinute(ts), GWEN_Timestamp_GetMinute(tsWork),
GWEN_Timestamp_GetHour(ts), GWEN_Timestamp_GetHour(tsWork),
GWEN_Timestamp_GetDay(ts), GWEN_Timestamp_GetDay(tsWork),
GWEN_Timestamp_GetMonth(ts), GWEN_Timestamp_GetMonth(tsWork),
GWEN_Timestamp_GetWeekDay(ts))>0) { GWEN_Timestamp_GetWeekDay(tsWork))>0) {
MODULE_TIMER_ACTION *act; MODULE_TIMER_ACTION *act;
DBG_INFO(NULL, "- rule matches for %s, creating action", GWEN_Timestamp_GetString(ts)); DBG_ERROR(NULL, "- rule matches for %s, creating action", GWEN_Timestamp_GetString(tsWork));
act=ModuleTimerAction_new(triggerTime, AQHREACT_PrgRule_GetValue(rule)); act=ModuleTimerAction_new(triggerTime, AQHREACT_PrgRule_GetValue(rule));
ModuleTimerAction_List_Add(act, actionList); ModuleTimerAction_List_Add(act, actionList);
actionsAdded=1; actionsAdded=1;
} }
rule=AQHREACT_PrgRule_List_Next(rule); rule=AQHREACT_PrgRule_List_Next(rule);
} /* while */ } /* while */
}
GWEN_Timestamp_AddSeconds(ts, 60); /* next min */ GWEN_Timestamp_AddSeconds(tsWork, 60); /* next min */
} /* for */ } /* for */
GWEN_Timestamp_free(xunit->nextAddTime);
xunit->nextAddTime=tsWork;
return actionsAdded?1:0; return actionsAdded?1:0;
} }