-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlarmSystem.h
More file actions
187 lines (131 loc) · 4.7 KB
/
Copy pathAlarmSystem.h
File metadata and controls
187 lines (131 loc) · 4.7 KB
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
/*
* AlarmSystem.h
*
* Created on: 21 juil. 2015
* Author: horfee
*/
#ifndef ALARMSYSTEM_H_
#define ALARMSYSTEM_H_
#define VERSION "1.0.0"
#include <vector>
#include <ctime>
#include <thread>
#include "devices/AllDevices.h"
#include "Property.h"
#include "actions/Action.h"
#include "Mode.h"
#include "NetworkModule.h"
#include "SIM800Module.h"
#ifdef WIRINGPI
#include "RCReceiverTransmitter.h"
#else
#include "RF433Module.h"
#endif
namespace alarmpi {
class Action;
class ActivateModeAction;
class NotInConfigModeException: public exception {};
class ModeAlreadyExistsException: public exception {};
class InvalidModeException: public exception{};
class PropertyAlreadyExistsException: public exception {};
class AlarmDeviceAlreadyExistsException: public exception {};
class ActionAlreadyExistsException: public exception {};
class InvalidPasswordException: public exception {};
class UnknownModeException: public exception {};
typedef std::tuple<Device*, Mode*, Action*> Association;
class AlarmSystem: public NetworkModule, private SIM800ModuleListener,
#ifdef WIRINGPI
private RCMessageListener
#else
private RF433MessageListener
#endif
{
friend class ActivateModeAction;
public:
AlarmSystem();
virtual ~AlarmSystem();
const std::vector<Action*> getActions() const;
const std::vector<Device*> getDevices() const;
const std::map<int, time_t> getDetectedDevices() const;
const std::vector<std::string> availablePhoneNumbers() const;
const std::vector<Mode*> getModes() const;
const std::vector<std::string> getPhones() const;
const std::vector<Property*> getProperties() const;
const std::vector<Association> getAssociations() const;
std::string activeMode() const;
void activateMode(std::string mode, std::string password);
void setConfigMode(std::string encPassword);
bool isConfigMode() const;
/*********** Available when in config mode */
void addAction(Action* toAdd);
void removeAction(Action* toRemove);
void associateActionAndMode(Device* device, Action* action, Mode* mode);
void removeAssociation(Device* device, Mode* mode);
void addDevice(Device* toAdd);
void removeDevice(Device* toRemove);
void addMode(Mode* mode);
void removeMode(Mode* toRemove);
void addPhoneNumber(std::string phoneNumber, int order = -1);
void removePhoneNumber(std::string phoneNumber);
void addProperty(Property* toAdd);
void removeProperty(Property* toRemove);
// std::vector<alarmpi::WifiDesc> listWifi() const;
// std::string getCurrentESSI() const;
// bool connectToWifi(std::string essid, std::string password) const;
// bool createAccessPoint(std::string essid, std::string password);
// std::vector<std::string> ipAddresses() const;
// bool isConnectedToNetwork() const;
// void addNetworkListener(NetworkListener* listener);
// void removeNetworkListener(NetworkListener* listener);
/*********** End of available when in config mode */
void sendRFMessage(ActionnableDevice* bell, int data) const;
void sendSMS(std::string message) const;
void callPhones() const;
void sendMail(std::string recipient, std::string object, std::string message) const;
Device* getDevice(int id) const;
Property* getProperty(std::string propertyName) const;
int getPhone(std::string phone) const;
Mode* getMode(std::string mode) const;
Action* getAction(std::string name) const;
Action* getAssociation(int deviceId, std::string mode) const;
bool testPassword(std::string password) const;
void changePassword(std::string password, std::string newPassword);
void simulateSignalReceived(std::string signal);
std::string getVersion() const;
bool mustStopActionThreads();
protected:
virtual void loadConfiguration();
virtual void onSignalReceived(int value);
virtual void onMessageReceived(int messageId);
virtual void onIncomingCall(std::string callingNumber);
std::vector<Property*> properties;
std::vector<std::string> phoneNumbers;
private:
void cleanUpDetectedDevices();
virtual void saveConfiguration();
Property* getPassword() const;
std::vector<Device*> devices;
std::map<int, time_t> detectedDevices;
std::vector<Mode*> modes;
std::string currentMode;
#ifdef WIRINGPI
RCReceiverTransmitter* wirelessModule;
#else
RF433Module* rf433Module;
#endif
std::vector<Action*> actions;
std::map<std::tuple<int, std::string>, std::string> devicesModesActionsAssociations;
std::thread* detectedDevicesCleanUpThread;
SIM800Module* gsmModule;
std::atomic<bool> bMustStopActionThreads;
std::atomic<int> nbActionThreads;
//// std::vector<std::thread *> actionThreads;
// std::mutex actionThreadsMutex;
// std::mutex actionThreadMustStopMutex;
NetworkModule wifi;
void stopActionThreads() ;
Mode* getConfigMode() const;
Mode* getInactiveMode() const;
};
} /* namespace alarmpi */
#endif /* ALARMSYSTEM_H_ */