public class Model
extends java.util.Observable
Modifier and Type | Field and Description |
---|---|
static int |
ALERT_COOLING
The Cooling Alert Level : 0
|
static int |
ALERT_HEATING
The HEATING AlertLevel : 2
|
static int |
ALERT_IDLE
The IDLE Alert Level : 1
|
static int |
ALERT_OVERHEATING
The OVERHEATING (When the temperature is over the threshold) AlertLevel:
3
|
static java.lang.String |
APPNAME
The name of the app
|
static int |
BAUDRATE
The communication baudrate
|
static int |
MAX_ALERT_LVL
Represent the biggest alertLevel : 3
|
static int |
MIN_ALERT_LVL
Represent the smallest alertLevel : 0
|
Constructor and Description |
---|
Model()
Empty Model constructor.
|
Model(int currentTemperature,
int thresholdTemperature)
Model constructor with current and threshold temperature.
|
Model(int currentTemperature,
int thresholdTemperature,
int alertLevel)
Full Model constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addAlertLevelToHistory(java.util.Date date,
int alertLevel)
Add a record of alertLevel to the history at the current date
|
void |
addAlertLevelToHistory(int alertLevel)
Add a record of alertLevel to the history at the current date
|
void |
addTemperatureToHistory(java.util.Date date,
int temperature)
Add a temperature at the given date to the temperature history
|
void |
addTemperatureToHistory(int currentTemperature)
Add a temperature to the temperature history
|
void |
checkAlertLevel()
Check and update the alertlevel by comparing the currentTemperature and
the current threshold temparature
|
int |
getAlertLevel()
Get the current AlertLevel
|
int |
getAlertLevelFromHistory(java.util.Date date)
getAlertLevelFromHistory return the AlertLevel at a date
|
java.util.LinkedHashMap<java.util.Date,java.lang.Integer> |
getAlertLevelHistory()
Get the alert level history
|
int |
getCurrentTemperature()
Get the currentTemperature
|
java.io.InputStream |
getDownlink()
Get the downlink
|
java.util.Enumeration |
getEnumCOMPort()
Get the list of avaliable COM ports
|
gnu.io.CommPortIdentifier |
getSerialPortId()
Get the identifier of the connected COM port
|
int |
getTemperatureFromHistory(java.util.Date date)
Get the temperature at a given date
|
java.util.LinkedHashMap<java.util.Date,java.lang.Integer> |
getTemperaturesHistory()
Get the temperature history
|
int |
getThresholdTemperature()
Get the threshold temperature (Temperature when the alert will be
triggered)
|
java.io.OutputStream |
getUplink()
Get the uplink
|
java.io.PrintWriter |
getUplinkWriter()
Get the uplinkWriter
|
boolean |
isAlertLevelCorrect(int alertLevel)
Check if the given alertLevel is correct
|
boolean |
isConnected()
Check the connection
|
void |
setAlertLevel(int alertLevel)
Set the alertLevel and record it on the AlertLevelHistory HashMap
|
void |
setConnected(boolean connected)
Set the connection status
|
void |
setCurrentTemperature(int currentTemperature)
Set the currentTemperature and record it on the temperaturesHistory's
HashMap
|
void |
setDownlink(java.io.InputStream downlink)
Set the downlink
|
void |
setEnumCOMPort(java.util.Enumeration enumCOMPort)
Set the list of avaliable COM ports
|
void |
setSerialPortId(gnu.io.CommPortIdentifier serialPortId)
Set the identifier of the connected COM port
|
void |
setThresholdTemperature(int thresholdTemperature)
Set the threshold temperature (Temperature when the alert will be
triggered)
|
void |
setUplink(java.io.OutputStream uplink)
Set the uplink
|
void |
setUplinkWriter(java.io.PrintWriter uplinkWriter)
Set the uplinkWriter
|
java.lang.String |
toString() |
public static final java.lang.String APPNAME
public static final int BAUDRATE
public static final int MIN_ALERT_LVL
public static final int MAX_ALERT_LVL
public static final int ALERT_COOLING
public static final int ALERT_IDLE
public static final int ALERT_HEATING
public static final int ALERT_OVERHEATING
public Model()
public Model(int currentTemperature, int thresholdTemperature, int alertLevel) throws UnknowAlertLevelException
currentTemperature
- Must be an int and be the current temperature
given by the sensorsthresholdTemperature
- Must be an int and be the temperature who
trigger the alertalertLevel
- int Must be greater than 0 and
smaller than 3UnknowAlertLevelException
- When the alertLevel parametter is
strictly smaller than 0 or stritly bigger than
3public Model(int currentTemperature, int thresholdTemperature)
currentTemperature
- Must be an int and be the current temperature
given by the sensorsthresholdTemperature
- Must be an int and be the temperature who
trigger the alertpublic java.io.PrintWriter getUplinkWriter()
public void setUplinkWriter(java.io.PrintWriter uplinkWriter)
uplinkWriter
- PrintWriterpublic java.io.OutputStream getUplink()
public void setUplink(java.io.OutputStream uplink)
uplink
- OutputStreampublic java.io.InputStream getDownlink()
public void setDownlink(java.io.InputStream downlink)
downlink
- InputStreampublic boolean isConnected()
public void setConnected(boolean connected)
connected
- booleanpublic gnu.io.CommPortIdentifier getSerialPortId()
public void setSerialPortId(gnu.io.CommPortIdentifier serialPortId)
serialPortId
- ComPortIdentifier the id of the connected COM portpublic java.util.Enumeration getEnumCOMPort()
public void setEnumCOMPort(java.util.Enumeration enumCOMPort)
enumCOMPort
- Enumeration List of avaliable COM portspublic int getCurrentTemperature()
public void setCurrentTemperature(int currentTemperature)
currentTemperature
- int The current temperaturepublic int getThresholdTemperature()
public void setThresholdTemperature(int thresholdTemperature)
thresholdTemperature
- int The threshold temperature (Temperature
when the alert will be triggered)public void checkAlertLevel()
public int getAlertLevel()
public void setAlertLevel(int alertLevel) throws UnknowAlertLevelException
public java.util.LinkedHashMap<java.util.Date,java.lang.Integer> getAlertLevelHistory() throws EmptyHistoryException
EmptyHistoryException
- when there is no AlertLevel recorded yet.public final void addAlertLevelToHistory(int alertLevel) throws UnknowAlertLevelException
public final void addAlertLevelToHistory(java.util.Date date, int alertLevel) throws UnknowAlertLevelException
public int getAlertLevelFromHistory(java.util.Date date) throws NoHistoryDataAvaliableException
date
- Date Must be in the pastNoHistoryDataAvaliableException
- when there is no entry at the
given datepublic java.util.LinkedHashMap<java.util.Date,java.lang.Integer> getTemperaturesHistory() throws EmptyHistoryException
EmptyHistoryException
- when there is no temperature recorded yetpublic int getTemperatureFromHistory(java.util.Date date) throws NoHistoryDataAvaliableException
date
- Must be a date in the pastNoHistoryDataAvaliableException
- when there is no temperature
recorded at the given datepublic final void addTemperatureToHistory(int currentTemperature)
currentTemperature
- int The currentTemperaturepublic void addTemperatureToHistory(java.util.Date date, int temperature)
date
- Date when the temperature was settemperature
- The Temperature at the datepublic boolean isAlertLevelCorrect(int alertLevel)
public java.lang.String toString()
toString
in class java.lang.Object