-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.h
111 lines (101 loc) · 3.5 KB
/
notifier.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
/*
@file notifier.h
@author Don Thompson (raynham Engineering)
@license GNU (see license.txt)
Notifier class handles user notifications
Handles user alerts via Pushover and communication directly to iPhone app
Copyright (C) 2016 Don Thompson, Raynham Engineering
Raynham MA
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 3 of the License, or
(at your option) 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __NOTIFIER_H__
#define __NOTIFIER_H__
#include "application.h"
#include "util.h"
#include "parms.h"
#include "alarm.h"
#include <queue>
#include <list>
#include <map>
enum {NO_HEADER=0, SHORT_HEADER=1, FULL_HEADER=2};
//Message name conflicts with
struct pMessage {
uint8_t header_style;
int priority;
String message_text;
};
class Notifier {
public:
Notifier(char *lopri_event_name, char *event_name, char *priority_event_name, char *emergency_event_name, Sensor *s) {
// move upd to Alarm class ??
//TODO use array for webhook_id
strcpy(low_pri_webhook_id, lopri_event_name);
strcpy(webhook_id, event_name);
strcpy(priority_webhook_id, priority_event_name);
strcpy(emergency_webhook_id, emergency_event_name);
p_sensor = s;
msg_limit = 0; //limit mesages per hour
secret_timeout = 0; //loop passes to timeout secret
bad_secret_cnt = 0;
alarm_notify_cnt = 0;
alarm_times_notified = 0;
hours_between_alert = ALERT_HOURS;
digitalWrite(MESSAGE_PIN, LOW);
}
void setup();
int status(String command);
int set(String);
String updData();
int setAlarm(String);
int request(String);
int confirm(String);
int do_command(String);
void sendMessage(uint8_t header, int priority, char* msg); //send message to pushover
void sendMessage(uint8_t, int, String);
void queueMessage(uint8_t, int, String); //add message to queue
bool msgqueueEmpty();
void dequeMessage(void); //get next message from queue and send
void hourlyReset();
void pushAlarm(char* msg);
void secret_countdown();
void setStartTime();
void setAlertHours(int h);
uint8_t getAlertHours();
bool checkTime();
private:
const static String commands;
std::map <int, String> command_list;
//std::queue<String> msg_queue;
std::queue<pMessage> message_queue; // replaces msg_queue (with priority)
char low_pri_webhook_id[20];
char webhook_id[20];
char priority_webhook_id[20];
char emergency_webhook_id[20];
char event_message[1000]; //??reduce size of this ??
// to do, clear secret after xx loops ??? DEBUG
int secret;
unsigned int secret_timeout;
uint8_t bad_secret_cnt;
int alarm_times_notified;
int alarm_notify_cnt;
int msg_limit;
int hour = 0;
int minute = 0;
int lasthour = 0; //use -1 to skip startup
int lastminute = 0;
int elapsedminutes = 0;
uint8_t hours_between_alert;
unsigned long lastSync = millis();
Sensor *p_sensor;
Alarm *p_alarm; //??
};
#endif