-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathalarms.py
64 lines (56 loc) · 2.38 KB
/
alarms.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
# *****BatteryMonitor main file batteries.py*****
# Copyright (C) 2014 Simon Richard Matthews
# Project loaction https://github.com/simat/BatteryMonitor
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#!/usr/bin/python
import sys
from time import localtime
import serial
import binascii
from config import config
#self.summary=summary
import logger
log = logger.logging.getLogger(__name__)
log.setLevel(logger.logging.INFO)
log.addHandler(logger.alarmfile)
class Alarms:
# Initialise and compile alarms
def __init__(self,batdata,summary):
self.summary=summary
self.alarmtriggered={}
for i in config['alarms']:
self.alarmtriggered[i]=False
exec(config['alarms'][i][0])
log.info('alarm {} initialised'.format(i))
# config['alarms'][i][1] = compile(config['alarms'][i][1], '<string>', 'exec')
# config['alarms'][i][2] = compile(config['alarms'][i][2], '<string>', 'exec')
# config['alarms'][i][3] = compile(config['alarms'][i][3], '<string>', 'exec')
# config['alarms'][i][4] = compile(config['alarms'][i][4], '<string>', 'exec')
def scanalarms(self,batdata):
# self.timedate = localtime()
# print (self.timedate.tm_hour)
for i in config['alarms']:
if not self.alarmtriggered[i]:
exec(config['alarms'][i][1])
# log.debug('{}{}{}'.format(self.test,batdata.maxcellv,batdata.lastmaxcellv))
if self.test:
# sys.stderr.write('Alarm 1 triggered')
log.info('alarm {} triggered'.format(i))
self.alarmtriggered[i]=True
exec(config['alarms'][i][2])
if self.alarmtriggered[i]:
exec(config['alarms'][i][3])
if self.test:
log.info('alarm {} reset'.format(i))
self.alarmtriggered[i]=False
exec(config['alarms'][i][4])