std::vector<xml_element> elems;
std::vector<xml_element> recur;
std::map<String, String> attr;
-
+ std::map<String, String> start_attr;
+
attr = x.attributes();
elems = x["start"];
start_time = elems[0].content();
+ start_attr = elems[0].attributes();
+ //minimum_time = start_attr[String("minimum_time")];
+ minimum_time = elems[0].attribute("minimum_time");
elems = x["action"];
for (unsigned int i = 0; i < elems.size(); i++)
xml_text += seq->ToXML();
-/*
- for (act = sequence.begin(); act != sequence.end(); act++)
- {
- xml_text += " <action>";
- xml_text += (*act)->command_line();
- xml_text += "</action>\n";
- }
-*/
xml_text += " </event>\n";
return xml_text;
void Event::add_action(String command)
{
- String to_execute, parameters;
- int separation;
seq->add_action(command);
- separation = command.index(' ');
- if (separation > 0)
- {
- to_execute = command(0, separation);
- parameters = command << separation + 1;
- }
- else
- {
- to_execute = command;
- }
-
- if (to_execute == "lightcontrol")
- {
- Lightstep *act;
- act = new Lightstep;
-
- act->set_parameters(parameters);
- sequence.push_back(act);
- }
- else if (to_execute == "curtain")
- {
- Curtainstep *act;
- act = new Curtainstep;
-
- act->set_parameters(parameters);
- sequence.push_back(act);
- }
- else if (to_execute == "sleep")
- {
- Sleepstep *act;
- act = new Sleepstep;
-
- act->set_parameters(parameters);
- sequence.push_back(act);
- }
- else if (to_execute == "cancel")
- {
- Cancelstep *act;
- act = new Cancelstep;
-
- act->set_parameters(parameters);
- sequence.push_back(act);
- }
- else if (to_execute == "exit")
- {
- Exitstep *act;
- act = new Exitstep;
- sequence.push_back(act);
- }
- else
- {
- Log << "Action " + to_execute + " not recognized";
- }
}
void _run_(Sequence * sequence)
return seq;
}
+UTC clip_time(UTC t, String minimum)
+{
+ //std::cout << "Minimum_time = \"" << minimum << "\"\n"; // DEBUG
+
+ if (minimum != "")
+ {
+ hour t_min(minimum);
+
+ if (hour(t) < t_min)
+ {
+ t = UTC(date(t), t_min);
+ }
+ }
+
+ return t;
+}
+
UTC Event::next_occurance(UTC after, Location loc)
{
UTC next;
{
hour sunrise_at = loc.calculate_sunrise(date(after));
next = loc.utc_to_localtime(date(after), sunrise_at);
+ next = clip_time(next, minimum_time);
+ if (next <= after)
+ {
+ // Today's sunrise already passed. Calculate for tomorrow
+
+ sunrise_at = loc.calculate_sunrise(date(after) + 1);
+ next = loc.utc_to_localtime(date(after) + 1, sunrise_at);
+ next = clip_time(next, minimum_time);
+ }
+ //Log << " sunrise time = " + sunrise_at.format();
+ //Log << " next sunrise after " + after.format() + " is " + next.format();
}
else if (start_time == "sunset")
{
hour sunset_at = loc.calculate_sunset(date(after));
next = loc.utc_to_localtime(date(after), sunset_at);
+ next = clip_time(next, minimum_time);
+ if (next <= after)
+ {
+ // Today's sunset already passed. Calculate for tomorrow
+
+ sunset_at = loc.calculate_sunset(date(after) + 1);
+ next = loc.utc_to_localtime(date(after) + 1, sunset_at);
+ next = clip_time(next, minimum_time);
+ }
+ //Log << " sunset time = " + sunset_at.format();
+ //Log << " next sunset after " + after.format() + " is " + next.format();
}
else
{
next = start_time;
}
- if (pattern != "none")
+ if (pattern == "weekdays")
+ {
+ while (next <= after || weekdays.find(date(next).WeekDay()) == weekdays.end())
+ {
+ next += UTC(date(1, 0, 0), hour(0));
+ }
+ }
+ else if (pattern != "none")
{
while (next <= after)
{
- if (pattern == "weekdays")
- {
- while (next <= after || weekdays.find(date(next).WeekDay()) == weekdays.end())
- {
- next += UTC(date(1, 0, 0), hour(0));
- }
- }
- else
- {
- next += recurrance_interval;
- }
+ next += recurrance_interval;
}
}
{
String label;
String start_time;
+ String minimum_time;
String pattern; // for recurrance
UTC recurrance_interval;
TESTS = lightctrl lightctrl-oor lightctrl-fade \
wakeup_load_events sunrise_test event_recurrance event_run_sequence \
- wakeup_winter sunset_winter wakeup_spring \
+ wakeup_winter sunset_winter wakeup_spring wakeup_summer sunset_summer \
check_output
-# wakeup_summer
AM_CPPFLAGS = -I../src
LDADD = -lTachyon -lACL
sunrise_test_SOURCES = sunrise_test.cpp ../src/sunrise.cpp
log_retime_SOURCES = log_retime.cpp
+
+clean-local:
+ rm -f *.pid *.run *.log *.log2 *.log.test
--- /dev/null
+#!/bin/bash
+#
+# Test the wakeup sequence in winter.
+#
+set -m
+PATH=../src:$PATH
+
+# Reset the lights and clear the log files
+
+lightcontrol -r 0 -g 0 -b 0 -w 0
+> lightcontrol.log
+> wakeup.log
+
+ln -f -s wakeup_empty.xml wakeup_link.xml
+
+wakeup &
+sleep 1
+
+read TACHYON_NAME <wakeup.run
+Time=`date --date '2020-06-18 15:00' +%s`
+tachyon -t $Time $TACHYON_NAME
+tachyon -a 1000 $TACHYON_NAME
+
+ln -f -s sunset_alarms.xml wakeup_link.xml
+
+kill -HUP `cat wakeup.pid`
+
+fg %1
+#kill `cat wakeup.pid`
+
+# Remove timestamps from the log.
+cut -c 22- wakeup.log >sunset_summer.log.test
+
+diff sunset_summer.log.test sunset_summer.log.expect
+
+
+exit $?
--- /dev/null
+ wakeup started
+ Reading alarms from wakeup_link.xml
+ SIGHUP received.
+ Reading alarms from wakeup_link.xml
+ Alarm sunset triggered at 2020-06-18 21:54:19
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-18 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-18 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm sunset triggered at 2020-06-19 21:54:25
+ [lights_off] Stopping sequence
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-19 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-19 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm sunset triggered at 2020-06-20 21:54:28
+ [lights_off] Stopping sequence
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-20 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-20 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm sunset triggered at 2020-06-21 21:54:28
+ [lights_off] Stopping sequence
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-21 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-21 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm sunset triggered at 2020-06-22 21:54:25
+ [lights_off] Stopping sequence
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-22 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-22 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm sunset triggered at 2020-06-23 21:54:19
+ [lights_off] Stopping sequence
+ [sunset] Executing curtain -c 1 -t
+ [sunset] Executing lightcontrol -b 99 -w 50
+ Alarm evening_dim triggered at 2020-06-23 22:00:00
+ [sunset] Stopping sequence
+ [evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
+ Alarm lights_off triggered at 2020-06-23 22:30:00
+ [evening_dim] Stopping sequence
+ [lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
+ Alarm end_test triggered at 2020-06-24 11:00:00
+ [lights_off] Stopping sequence
+ [end_test] Executing exit
Alarm lights_off triggered at 2020-12-17 22:30:00
[evening_dim] Stopping sequence
[lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
- Alarm sunset triggered at 2020-12-18 16:27:00
+ Alarm sunset triggered at 2020-12-18 16:26:53
[lights_off] Stopping sequence
[sunset] Executing curtain -c 1 -t
[sunset] Executing lightcontrol -b 99 -w 50
Alarm lights_off triggered at 2020-12-18 22:30:00
[evening_dim] Stopping sequence
[lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
- Alarm sunset triggered at 2020-12-19 16:26:53
+ Alarm sunset triggered at 2020-12-19 16:26:48
[lights_off] Stopping sequence
[sunset] Executing curtain -c 1 -t
[sunset] Executing lightcontrol -b 99 -w 50
Alarm lights_off triggered at 2020-12-19 22:30:00
[evening_dim] Stopping sequence
[lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
- Alarm sunset triggered at 2020-12-20 16:26:48
+ Alarm sunset triggered at 2020-12-20 16:26:47
[lights_off] Stopping sequence
[sunset] Executing curtain -c 1 -t
[sunset] Executing lightcontrol -b 99 -w 50
Alarm lights_off triggered at 2020-12-20 22:30:00
[evening_dim] Stopping sequence
[lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
- Alarm sunset triggered at 2020-12-21 16:26:47
+ Alarm sunset triggered at 2020-12-21 16:26:48
[lights_off] Stopping sequence
[sunset] Executing curtain -c 1 -t
[sunset] Executing lightcontrol -b 99 -w 50
Alarm lights_off triggered at 2020-12-21 22:30:00
[evening_dim] Stopping sequence
[lights_off] Executing lightcontrol -b 0 -f 1800 -a 1000
- Alarm sunset triggered at 2020-12-22 16:26:48
- [lights_off] Stopping sequence
- [sunset] Executing curtain -c 1 -t
Alarm sunset triggered at 2020-12-22 16:26:53
- [sunset] Stopping sequence
+ [lights_off] Stopping sequence
[sunset] Executing curtain -c 1 -t
[sunset] Executing lightcontrol -b 99 -w 50
- [sunset] Executing lightcontrol -b 99 -w 50
- [sunset] Executing lightcontrol -b 99 -w 50
Alarm evening_dim triggered at 2020-12-22 22:00:00
[sunset] Stopping sequence
[evening_dim] Executing lightcontrol -b 50 -w 0 -f 900 -a 1000
<action>lightcontrol -w 10 -f 300 -a 1000</action>
</event>
<event id='sunrise'>
- <start>sunrise</start>
+ <start minimum_time="06:00:05">sunrise</start>
<action>cancel lightson_workdays</action>
<action>curtain -o 2 -t</action>
<action>lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000</action>
Alarm lightson_workdays triggered at 2020-05-13 06:00:00
[open_curtains] Stopping sequence
[lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
- Alarm sunrise triggered at 2020-05-13 06:00:03
+ Alarm sunrise triggered at 2020-05-13 06:00:05
[lightson_workdays] Stopping sequence
[sunrise] Executing cancel lightson_workdays
[sunrise] Executing curtain -o 2 -t
sleep 1
read TACHYON_NAME <wakeup.run
-Time=`date --date '2020-06-17 05:00' +%s`
+Time=`date --date '2020-06-18 04:00' +%s`
tachyon -t $Time $TACHYON_NAME
-tachyon -a 100 $TACHYON_NAME
+tachyon -a 1000 $TACHYON_NAME
ln -f -s wakeup_alarms.xml wakeup_link.xml
-wakeup started
-Reading alarms from wakeup_link.xml
-SIGHUP received.
-Reading alarms from wakeup_link.xml
-Alarm sunrise triggered at 2020-06-17 05:27:06
-Executing curtain -o 2 -t
-Executing lightcontrol -r 0 -g 0 -w 0 -f 2
-Alarm open_curtains triggered at 2020-06-17 09:00:00
-Executing curtain -o 1 -t
-Alarm end_test triggered at 2020-06-17 11:00:00
-Executing exit
+ wakeup started
+ Reading alarms from wakeup_link.xml
+ SIGHUP received.
+ Reading alarms from wakeup_link.xml
+ Alarm lightson_workdays triggered at 2020-06-18 06:00:00
+ [lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
+ Alarm sunrise triggered at 2020-06-18 06:00:05
+ [lightson_workdays] Stopping sequence
+ [sunrise] Executing cancel lightson_workdays
+ [sunrise] Executing curtain -o 2 -t
+ [sunrise] Executing lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000
+ Alarm open_curtains triggered at 2020-06-18 09:00:00
+ [sunrise] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm lightson_workdays triggered at 2020-06-19 06:00:00
+ [open_curtains] Stopping sequence
+ [lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
+ Alarm sunrise triggered at 2020-06-19 06:00:05
+ [lightson_workdays] Stopping sequence
+ [sunrise] Executing cancel lightson_workdays
+ [sunrise] Executing curtain -o 2 -t
+ [sunrise] Executing lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000
+ Alarm open_curtains triggered at 2020-06-19 09:00:00
+ [sunrise] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm open_curtains triggered at 2020-06-20 09:00:00
+ [open_curtains] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm open_curtains triggered at 2020-06-21 09:00:00
+ [open_curtains] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm lightson_workdays triggered at 2020-06-22 06:00:00
+ [open_curtains] Stopping sequence
+ [lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
+ Alarm sunrise triggered at 2020-06-22 06:00:05
+ [lightson_workdays] Stopping sequence
+ [sunrise] Executing cancel lightson_workdays
+ [sunrise] Executing curtain -o 2 -t
+ [sunrise] Executing lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000
+ Alarm open_curtains triggered at 2020-06-22 09:00:00
+ [sunrise] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm lightson_workdays triggered at 2020-06-23 06:00:00
+ [open_curtains] Stopping sequence
+ [lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
+ Alarm sunrise triggered at 2020-06-23 06:00:05
+ [lightson_workdays] Stopping sequence
+ [sunrise] Executing cancel lightson_workdays
+ [sunrise] Executing curtain -o 2 -t
+ [sunrise] Executing lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000
+ Alarm open_curtains triggered at 2020-06-23 09:00:00
+ [sunrise] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm lightson_workdays triggered at 2020-06-24 06:00:00
+ [open_curtains] Stopping sequence
+ [lightson_workdays] Executing lightcontrol -r 10 -f 300 -a 1000
+ Alarm sunrise triggered at 2020-06-24 06:00:05
+ [lightson_workdays] Stopping sequence
+ [sunrise] Executing cancel lightson_workdays
+ [sunrise] Executing curtain -o 2 -t
+ [sunrise] Executing lightcontrol -r 0 -g 0 -w 0 -f 100 -a 1000
+ Alarm open_curtains triggered at 2020-06-24 09:00:00
+ [sunrise] Stopping sequence
+ [open_curtains] Executing curtain -o 1 -t
+ Alarm end_test triggered at 2020-06-24 11:00:00
+ [open_curtains] Stopping sequence
+ [end_test] Executing exit