-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathLocalScheduleObject1.py
319 lines (279 loc) · 9.68 KB
/
LocalScheduleObject1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env python
"""
This application creates a series of Local Schedule Objects and then prompts
to test dates and times.
"""
from time import localtime as _localtime
from bacpypes.debugging import bacpypes_debugging, ModuleLogger, xtob
from bacpypes.consolelogging import ConfigArgumentParser
from bacpypes.consolecmd import ConsoleCmd
from bacpypes.core import run
from bacpypes.primitivedata import Null, Integer, Real, Date, Time, CharacterString
from bacpypes.constructeddata import ArrayOf, SequenceOf
from bacpypes.basetypes import (
CalendarEntry,
DailySchedule,
DateRange,
DeviceObjectPropertyReference,
SpecialEvent,
SpecialEventPeriod,
TimeValue,
)
from bacpypes.app import BIPSimpleApplication
from bacpypes.local.device import LocalDeviceObject
from bacpypes.local.schedule import LocalScheduleObject
# some debugging
_debug = 0
_log = ModuleLogger(globals())
# globals
schedule_objects = []
#
# TestConsoleCmd
#
@bacpypes_debugging
class TestConsoleCmd(ConsoleCmd):
def do_test(self, args):
"""test <date> <time>"""
args = args.split()
if _debug:
TestConsoleCmd._debug("do_test %r", args)
date_string, time_string = args
test_date = Date(date_string).value
test_time = Time(time_string).value
for so in schedule_objects:
v, t = so._task.eval(test_date, test_time)
print(so.objectName + ", " + repr(v and v.value) + " until " + str(t))
def do_now(self, args):
"""now"""
args = args.split()
if _debug:
TestConsoleCmd._debug("do_now %r", args)
y = _localtime()
print("y: {}".format(y))
def do_dc(self, args):
"""dc"""
args = args.split()
if _debug:
TestConsoleCmd._debug("do_dc %r", args)
for so in schedule_objects:
print(so.objectName)
so.debug_contents()
#
# __main__
#
def main():
global args, schedule_objects
# parse the command line arguments
parser = ConfigArgumentParser(description=__doc__)
# parse the command line arguments
args = parser.parse_args()
if _debug:
_log.debug("initialization")
if _debug:
_log.debug(" - args: %r", args)
# make a device object
this_device = LocalDeviceObject(ini=args.ini)
if _debug:
_log.debug(" - this_device: %r", this_device)
# make a sample application
this_application = BIPSimpleApplication(this_device, args.ini.address)
#
# Simple daily schedule (actually a weekly schedule with every day
# being identical.
#
so = LocalScheduleObject(
objectIdentifier=("schedule", 1),
objectName="Schedule 1",
presentValue=Integer(8),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
weeklySchedule=ArrayOf(DailySchedule, 7)([
DailySchedule(
daySchedule=[
TimeValue(time=(8, 0, 0, 0), value=Integer(8)),
TimeValue(time=(14, 0, 0, 0), value=Null()),
TimeValue(time=(17, 0, 0, 0), value=Integer(42)),
# TimeValue(time=(0,0,0,0), value=Null()),
]
),
]
* 7),
scheduleDefault=Integer(0),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
#
# A special schedule when the Year 2000 problem was supposed to collapse
# systems, the panic clears ten minutes later when it didn't.
#
so = LocalScheduleObject(
objectIdentifier=("schedule", 2),
objectName="Schedule 2",
presentValue=CharacterString(""),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
exceptionSchedule=ArrayOf(SpecialEvent)([
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(date=Date("2000-01-01").value,),
),
listOfTimeValues=[
TimeValue(time=(0, 0, 0, 0), value=CharacterString("Panic!")),
TimeValue(time=(0, 10, 0, 0), value=Null()),
],
eventPriority=1,
),
]),
scheduleDefault=CharacterString("Don't panic."),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
#
# A special schedule to celebrate Friday.
#
so = LocalScheduleObject(
objectIdentifier=("schedule", 3),
objectName="Schedule 3",
presentValue=CharacterString(""),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
exceptionSchedule=ArrayOf(SpecialEvent)([
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.05"),),
),
listOfTimeValues=[
TimeValue(time=(0, 0, 0, 0), value=CharacterString("It's Friday!")),
],
eventPriority=1,
),
]),
scheduleDefault=CharacterString("Keep working."),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
#
# A schedule object that refers to an AnalogValueObject in the test
# device.
#
so = LocalScheduleObject(
objectIdentifier=("schedule", 4),
objectName="Schedule 4",
presentValue=Real(73.5),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
weeklySchedule=ArrayOf(DailySchedule, 7)([
DailySchedule(
daySchedule=[
TimeValue(time=(9, 0, 0, 0), value=Real(78.0)),
TimeValue(time=(10, 0, 0, 0), value=Null()),
]
),
]
* 7),
scheduleDefault=Real(72.0),
listOfObjectPropertyReferences=SequenceOf(DeviceObjectPropertyReference)(
[
DeviceObjectPropertyReference(
objectIdentifier=("analogValue", 1),
propertyIdentifier="presentValue",
),
]
),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
#
# The beast
#
so = LocalScheduleObject(
objectIdentifier=("schedule", 5),
objectName="Schedule 5",
presentValue=Integer(0),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
exceptionSchedule=ArrayOf(SpecialEvent)([
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=[
TimeValue(time=(5, 0, 0, 0), value=Integer(5)),
TimeValue(time=(6, 0, 0, 0), value=Null()),
],
eventPriority=1,
),
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=[
TimeValue(time=(4, 0, 0, 0), value=Integer(4)),
TimeValue(time=(7, 0, 0, 0), value=Null()),
],
eventPriority=2,
),
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=[
TimeValue(time=(3, 0, 0, 0), value=Integer(3)),
TimeValue(time=(8, 0, 0, 0), value=Null()),
],
eventPriority=3,
),
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=[
TimeValue(time=(2, 0, 0, 0), value=Integer(2)),
TimeValue(time=(9, 0, 0, 0), value=Null()),
],
eventPriority=4,
),
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=[TimeValue(time=(1, 0, 0, 0), value=Integer(1)),],
eventPriority=5,
),
]),
scheduleDefault=Integer(0),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
# list of time values for every five minutes
ltv = []
for hr in range(24):
for mn in range(0, 60, 5):
ltv.append(TimeValue(time=(hr, mn, 0, 0), value=Integer(hr * 100 + mn)))
so = LocalScheduleObject(
objectIdentifier=("schedule", 6),
objectName="Schedule 6",
presentValue=Integer(0),
effectivePeriod=DateRange(startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2),),
exceptionSchedule=ArrayOf(SpecialEvent)([
SpecialEvent(
period=SpecialEventPeriod(
calendarEntry=CalendarEntry(weekNDay=xtob("FF.FF.FF"),),
),
listOfTimeValues=ltv,
eventPriority=1,
),
]),
scheduleDefault=Integer(0),
)
_log.debug(" - so: %r", so)
this_application.add_object(so)
schedule_objects.append(so)
# make sure they are all there
_log.debug(" - object list: %r", this_device.objectList)
TestConsoleCmd()
_log.debug("running")
run()
_log.debug("fini")
if __name__ == "__main__":
main()