-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaseStation.java
205 lines (155 loc) · 4.7 KB
/
BaseStation.java
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
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class BaseStation {
// serial number of the base station
int SerialNo;
// map containing deviceID as key and value as security device object
static HashMap<String, SecurityDevice> allDevices;
// keypad object
static WirelessKeypad theKeypad;
// some boolean variables
static boolean isOn;
static boolean isOff;
boolean hasLowBattery;
// If base station is on power saving mode
boolean onBetteryMode;
// Device ID for the base station
int myDeviceID;
/**
* Constructor
*
* @param requires list of all linked devices in the system as a List<>
*/
public BaseStation(List<SecurityDevice> linkedDevice) {
// initialize the hashmap
allDevices = new HashMap<>();
// add all security devices in the map<>
for (SecurityDevice d : linkedDevice) {
allDevices.put(d.deviceID, d);
}
}
/**
* Method to check status of the given device ID
*
* @param DeviceID String type
* @return String representation of the check status
*/
public static String checkStatus(String DeviceID) {
if(allDevices.containsKey(DeviceID)){
// calls the device's check status method
String status = (allDevices.get(DeviceID)).doStatusCheck()+"";
return status;
}
else{
return "Invalid Device ID";
}
}
public boolean activateDevice(int DeviceID) {
// if device is inactive, then activate and return true to notify it is been
// activated
if (!allDevices.get(DeviceID).isConnected) {
allDevices.get(DeviceID).isConnected = true;
return true;
}
// False if it is already activated
return false;
}
public boolean dactivateDevice(int DeviceID) {
// if device is active, then deactivate and return true to notify it is been
// deactivated
if (allDevices.get(DeviceID).isConnected) {
allDevices.get(DeviceID).isConnected = false;
return true;
}
// False if it is already deactivated
return false;
}
public boolean isConnected(int DeviceID) {
// return true if the device is active and false it not.
return allDevices.get(DeviceID).isConnected;
}
/**
* Method to broadcast the message received from securityDevice
*
* @param theMessage the string message, int the id of the device
*/
public void BroadCastMessage(String theMessage, String id) {
theKeypad.displayMessage(theMessage, id);
}
/**
* Method to sendAlert to the wireless keypad
*
* @param theAlert alert message as string
* @param id int id of the device
*/
public static void SendAlert(String theAlert, String id) {
theKeypad.displayAlert(theAlert, id);
}
/**
* Method to change current mode of the system
*
* @param theMode string mode value received from keypad
*/
public static void changeMode(String theMode) {
if ((theMode.toLowerCase()).equals("deactivate")) {
// Iterate over the device and deactivate all of them
for (String key : allDevices.keySet()) {
allDevices.get(key).isConnected = false;
}
} else if ((theMode.toLowerCase()).equals("activate") || (theMode.toLowerCase()).equals("away")) {
// Iterate over the device and activate all of them
for (String key : allDevices.keySet()) {
allDevices.get(key).isConnected = true;
}
} else if ((theMode.toLowerCase()).equals("home")) {
// Iterate over the device and deactivate all of in house camera
for (String key : allDevices.keySet()) {
// only deactivates the in house camera
// if (allDevices.get(key).DeviceName.equals("camera")) {
// allDevices.get(key).isConnected = false;
// }
}
}
}
/**
* Method to get all sync devices with our system
*
* @return list of current sync devices
*/
public List<SecurityDevice> getAllSyncDevices() {
List<SecurityDevice> list = new ArrayList<>();
// iterate over the list of security devices
for (String key : allDevices.keySet()) {
// add to the return list only if the component is active
if (allDevices.get(key).isConnected) {
list.add(allDevices.get(key));
}
}
return list;
}
/**
* method to turn on the base station and on all linked devices
*/
public static void turnOn() {
isOff = false;
isOn = true;
// Iterate over the device and turn on all device
for (String key : allDevices.keySet()) {
allDevices.get(key).isOn = true;
// allDevices.get(key).isOff = false;
}
}
/**
* method to turn off the base station and also off all linked devices
*/
public static void turnOff() {
isOff = true;
isOn = false;
// Iterate over the device and turn on all device
for (String key : allDevices.keySet()) {
allDevices.get(key).isOn = false;
// allDevices.get(key).isOff = true;
}
}
}