aqhome-react: fixed unit timeprogram.
This commit is contained in:
@@ -29,8 +29,8 @@
|
||||
|
||||
#define AQHOMEREACT_UNIT_TIMEPROGRAM_OUTSLOT_OUTPUT 0
|
||||
|
||||
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_MIN 60 /* 1h */
|
||||
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_SEC (61*60) /* 61m */
|
||||
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEFORNEXT_MINS 60 /* 1h */
|
||||
#define AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEEVERY_SECS (15*60) /* 15m */
|
||||
|
||||
#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 _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);
|
||||
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;
|
||||
|
||||
now=time(NULL);
|
||||
if (now-xunit->lastCreateTime>AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_SEC) {
|
||||
rv=_addActionsForNextMinutes(xunit->nextAddTime,
|
||||
AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEINTERVAL_MIN,
|
||||
if ((now-xunit->lastCreateTime)>AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEEVERY_SECS) {
|
||||
rv=_addActionsForNextMinutes(xunit,
|
||||
AQHOMEREACT_UNIT_TIMEPROGRAM_CREATEFORNEXT_MINS,
|
||||
xunit->ruleList,
|
||||
xunit->actionList);
|
||||
if (rv<0) {
|
||||
@@ -208,7 +208,7 @@ int _checkAndAddActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
|
||||
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);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
@@ -250,7 +250,7 @@ int _handlePendingActions(AQHREACT_UNIT *unit, AQHREACT_UNIT_TIMEPROGRAM *xunit)
|
||||
nextAction=ModuleTimerAction_List_Next(action);
|
||||
if (action->triggerTime<nowInt64) {
|
||||
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);
|
||||
ModuleTimerAction_free(action);
|
||||
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 i;
|
||||
GWEN_TIMESTAMP *tsWork;
|
||||
|
||||
tsWork=GWEN_Timestamp_NowInLocalTime();
|
||||
for (i=0; i<minutes; i++) {
|
||||
const AQHREACT_PRGRULE *rule;
|
||||
int64_t triggerTime;
|
||||
if (GWEN_Timestamp_Compare(tsWork, xunit->nextAddTime)==1) {
|
||||
int64_t triggerTime;
|
||||
const AQHREACT_PRGRULE *rule;
|
||||
|
||||
triggerTime=GWEN_Timestamp_toInt64(ts);
|
||||
triggerTime=GWEN_Timestamp_toInt64(tsWork);
|
||||
|
||||
rule=AQHREACT_PrgRule_List_First(ruleList);
|
||||
while(rule) {
|
||||
if (AQHREACT_PrgRule_Matches(rule,
|
||||
GWEN_Timestamp_GetMinute(ts),
|
||||
GWEN_Timestamp_GetHour(ts),
|
||||
GWEN_Timestamp_GetDay(ts),
|
||||
GWEN_Timestamp_GetMonth(ts),
|
||||
GWEN_Timestamp_GetWeekDay(ts))>0) {
|
||||
MODULE_TIMER_ACTION *act;
|
||||
rule=AQHREACT_PrgRule_List_First(ruleList);
|
||||
while(rule) {
|
||||
if (AQHREACT_PrgRule_Matches(rule,
|
||||
GWEN_Timestamp_GetMinute(tsWork),
|
||||
GWEN_Timestamp_GetHour(tsWork),
|
||||
GWEN_Timestamp_GetDay(tsWork),
|
||||
GWEN_Timestamp_GetMonth(tsWork),
|
||||
GWEN_Timestamp_GetWeekDay(tsWork))>0) {
|
||||
MODULE_TIMER_ACTION *act;
|
||||
|
||||
DBG_INFO(NULL, "- rule matches for %s, creating action", GWEN_Timestamp_GetString(ts));
|
||||
act=ModuleTimerAction_new(triggerTime, AQHREACT_PrgRule_GetValue(rule));
|
||||
ModuleTimerAction_List_Add(act, actionList);
|
||||
actionsAdded=1;
|
||||
}
|
||||
rule=AQHREACT_PrgRule_List_Next(rule);
|
||||
} /* while */
|
||||
|
||||
GWEN_Timestamp_AddSeconds(ts, 60); /* next min */
|
||||
DBG_ERROR(NULL, "- rule matches for %s, creating action", GWEN_Timestamp_GetString(tsWork));
|
||||
act=ModuleTimerAction_new(triggerTime, AQHREACT_PrgRule_GetValue(rule));
|
||||
ModuleTimerAction_List_Add(act, actionList);
|
||||
actionsAdded=1;
|
||||
}
|
||||
rule=AQHREACT_PrgRule_List_Next(rule);
|
||||
} /* while */
|
||||
}
|
||||
GWEN_Timestamp_AddSeconds(tsWork, 60); /* next min */
|
||||
} /* for */
|
||||
GWEN_Timestamp_free(xunit->nextAddTime);
|
||||
xunit->nextAddTime=tsWork;
|
||||
|
||||
return actionsAdded?1:0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user