-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlarmManager.h
152 lines (126 loc) · 5.8 KB
/
AlarmManager.h
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
// The file AlarmManager.h is part of RPIalarm.
// Copyright (C) 2018 Thomas Vickers
//
// RPIalarm 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 3 of the License, or
// (at your option) any later version.
//
// RPIalarm 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 RPIalarm. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "stdafx.h"
#include "Config.h"
#include <time.h>
static const int ALERT_MSG_SIZE = 256; // max size of alert text sent as email/sms
// pin functions returned by validatePin
enum {
PIN_FUNC_NONE = 0,
PIN_FUNC_DISARM = 1,
PIN_FUNC_AWAY = 2,
PIN_FUNC_STAY = 3,
PIN_FUNC_MAX = 4, // ?
PIN_FUNC_TEST = 5,
PIN_FUNC_BYPASS = 6,
PIN_FUNC_INSTANT = 7,
PIN_FUNC_CODE = 8,
PIN_FUNC_CHIME = 9
};
// modes for armed
enum {
DISARMED = 0,
ARMED_STAY,
ARMED_AWAY,
ARMED_BYPASS // same as ARMED_STAY, but with a loop bypassed
};
// elapsed time struct
struct t_ElapsedTime {
int secs;
int mins;
int hours;
int days;
};
class AlarmManager
{
public:
AlarmManager(void) {}; // constructor
~AlarmManager(void) {}; // destructor
void init(Config * pConfig);
bool checkLoops(uint32_t * prevLoopMask);
bool checkTimeouts(void);
void processKeyMsg(const char * buf, int bufLen);
void makeF7msg(char * buf, int hour, int min, bool altText);
void sendAlertMsg(const char * msg);
const char * getSockMsg(int hour, int min);
void setLastMsgTime(void);
uint32_t getLastMsgTime(void)
{
return lastMsgTime;
}
bool getAltTextActive(void)
{
return altTextActive;
}
static uint32_t getTimestamp(void);
static t_ElapsedTime * elapsedTime(time_t start);
private:
uint8_t getPinDigits(int kp);
uint8_t getPinDigits(void);
uint32_t readLoops(void);
bool checkPinTimeout(uint32_t ms);
bool processTimeouts(uint32_t ms);
bool setPinDigit(int keypad, uint8_t digit, uint32_t ms);
void clearPin(void);
bool pinPrompt(void);
void setAlarm(void);
void setDisarm(void);
void setTone(uint8_t val);
void setTempMsg(const char * s1, const char * s2);
void updateState(void);
void turnOnBacklight(void);
void displayOpenLoops(void);
int validatePin(uint8_t * func);
int loopIndex(uint32_t mask);
uint8_t zone; // byte 0-FF
uint8_t tone; // (nibble) 0-7 valid
bool chime; // true - chime active
bool ready; // true - ready LED lit
uint8_t armed; // false - disarmed, othewise armed
bool power; // true - AC power present
bool backlight; // true - LCD backlight lit
bool alarm; // if true, alarm is sounding
bool armTimeoutActive; // arm delay while leaving active
bool disarmTimeoutActive; // disarm delay while entering active
bool altTextActive; // add alt F7 message
bool tmpTextActive; // momentary message is active
uint8_t pinDigits[MAX_KEYPADS]; // number of pin digits entered
uint8_t timeoutRemain; // number of seconds that remain in timeout
uint32_t timeoutStart; // ms timestamp of timeout start
uint32_t lastMsgTime; // ms timestamp of last F7 message sent
uint32_t backlightOnTime; // ms timestamp of turning on backlight
uint32_t lastPinRecv; // ms timestamp of last keypad key recv
uint32_t chimeMsgTime; // ms timestamp of msg with chime tone set
uint32_t tmpMsgTime; // ms timestamp when temp msg set
uint32_t loopMask; // sensor loop mask
uint8_t pinCode[MAX_KEYPADS][MAX_PIN_DIGITS]; // current pin code entered
char line1[17]; // line1 text (16 chars + NULL)
char line2[17]; // line2 text (16 chars + NULL)
char altLine1[17]; // alt line1 text (16 chars + NULL)
char altLine2[17]; // alt line2 text (16 chars + NULL)
char tempLine1[17]; // momentary message line1
char tempLine2[17]; // momentary message line2
Config * pConfig; // pointer to config class
Loop * pLoop; // pointer to sense loop class array
int loopCount; // number of sense loops
Pin * pPin; // pointer to array of pin number classes
int userCount; // number of user pin numbers
int sirenGpioPin; // gpio pin for siren output
time_t startTime; // alarm init time
char lastAlertMsg[ALERT_MSG_SIZE]; // last alert msg sent
uint32_t lastAlertTime;
};