|
|
|
|
@@ -103,6 +103,8 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
public SdData mSdData = null;
|
|
|
|
|
public String mSdDataSourceName = "undefined"; // The name of the data soruce specified in the preferences.
|
|
|
|
|
private boolean mLatchAlarms = false;
|
|
|
|
|
private int mLatchAlarmPeriod = 0;
|
|
|
|
|
private LatchAlarmTimer mLatchAlarmTimer = null;
|
|
|
|
|
private boolean mCancelAudible = false;
|
|
|
|
|
public boolean mAudibleAlarm = false;
|
|
|
|
|
private boolean mAudibleWarning = false;
|
|
|
|
|
@@ -171,7 +173,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
//int i = 5/0; // Force exception to test handler.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a wake lock, but don't use it until the service is started.
|
|
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
|
|
|
|
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
|
|
|
|
@@ -300,6 +301,8 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
mCancelAudibleTimer = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stop the Cancel Alarm Latch timer
|
|
|
|
|
stopLatchTimer();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Cancel the notification.
|
|
|
|
|
@@ -384,7 +387,8 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process the data received from the SdData source.
|
|
|
|
|
* Process the data received from the SdData source. On exit, the mSdData structure is populated with
|
|
|
|
|
* the appropriate data.
|
|
|
|
|
*
|
|
|
|
|
* @param sdData
|
|
|
|
|
*/
|
|
|
|
|
@@ -393,23 +397,25 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
if (sdData.alarmState == 0) {
|
|
|
|
|
if ((!mLatchAlarms) ||
|
|
|
|
|
(mLatchAlarms &&
|
|
|
|
|
(!sdData.alarmStanding && !sdData.fallAlarmStanding))) {
|
|
|
|
|
(!mSdData.alarmStanding && !mSdData.fallAlarmStanding))) {
|
|
|
|
|
sdData.alarmPhrase = "OK";
|
|
|
|
|
sdData.alarmStanding = false;
|
|
|
|
|
sdData.fallAlarmStanding = false;
|
|
|
|
|
showNotification(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (sdData.alarmState == 6) { // manual mute from watch buttons.
|
|
|
|
|
// Handle manual mute from watch buttons.
|
|
|
|
|
if (sdData.alarmState == 6) {
|
|
|
|
|
sdData.alarmPhrase = "MUTE";
|
|
|
|
|
sdData.alarmStanding = false;
|
|
|
|
|
sdData.fallAlarmStanding = false;
|
|
|
|
|
showNotification(0);
|
|
|
|
|
}
|
|
|
|
|
// Handle warning alarm state
|
|
|
|
|
if (sdData.alarmState == 1) {
|
|
|
|
|
if ((!mLatchAlarms) ||
|
|
|
|
|
(mLatchAlarms &&
|
|
|
|
|
(!sdData.alarmStanding && !sdData.fallAlarmStanding))) {
|
|
|
|
|
(!mSdData.alarmStanding && !mSdData.fallAlarmStanding))) {
|
|
|
|
|
sdData.alarmPhrase = "WARNING";
|
|
|
|
|
sdData.alarmStanding = false;
|
|
|
|
|
sdData.fallAlarmStanding = false;
|
|
|
|
|
@@ -425,7 +431,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
showNotification(1);
|
|
|
|
|
}
|
|
|
|
|
// respond to normal alarms (2) and manual alarms (5)
|
|
|
|
|
if ((sdData.alarmState == 2) || (sdData.alarmState == 5) || (sdData.alarmStanding)) {
|
|
|
|
|
if ((sdData.alarmState == 2) || (sdData.alarmState == 5)) {
|
|
|
|
|
sdData.alarmPhrase = "ALARM";
|
|
|
|
|
sdData.alarmStanding = true;
|
|
|
|
|
if (mLogAlarms) {
|
|
|
|
|
@@ -452,7 +458,9 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
mSMSTime = tnow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
startLatchTimer();
|
|
|
|
|
}
|
|
|
|
|
// Handle fall alarm
|
|
|
|
|
if ((sdData.alarmState == 3) || (sdData.fallAlarmStanding)) {
|
|
|
|
|
sdData.alarmPhrase = "FALL";
|
|
|
|
|
sdData.fallAlarmStanding = true;
|
|
|
|
|
@@ -617,6 +625,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onSdLocationReceived - called with the best estimate location after mLocationReceiver times out.
|
|
|
|
|
*
|
|
|
|
|
* @param ll - location (may be null if no location found)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@@ -665,6 +674,38 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Start the timer that will automatically re-set a latched alarm after a given period.
|
|
|
|
|
*/
|
|
|
|
|
private void startLatchTimer() {
|
|
|
|
|
if (mLatchAlarms) {
|
|
|
|
|
if (mLatchAlarmTimer != null) {
|
|
|
|
|
Log.v(TAG, "startLatchTimer -timer already running - cancelling it");
|
|
|
|
|
mLatchAlarmTimer.cancel();
|
|
|
|
|
mLatchAlarmTimer = null;
|
|
|
|
|
}
|
|
|
|
|
Log.v(TAG, "startLatchTimer() - starting alarm latch release timer to time out in " + mLatchAlarmPeriod + " sec");
|
|
|
|
|
// set timer to timeout after mLatchAlarmPeriod, and Tick() function to be called every second.
|
|
|
|
|
mLatchAlarmTimer =
|
|
|
|
|
new LatchAlarmTimer(mLatchAlarmPeriod * 1000, 1000);
|
|
|
|
|
mLatchAlarmTimer.start();
|
|
|
|
|
} else {
|
|
|
|
|
Log.v(TAG, "startLatchTimer() - Latch Alarms disabled - not doing anything");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Cancel the automatic de-latch timer - called from onDestroy, or if the AcceptAlarm button is pressed.
|
|
|
|
|
*/
|
|
|
|
|
private void stopLatchTimer() {
|
|
|
|
|
if (mLatchAlarmTimer != null) {
|
|
|
|
|
Log.v(TAG, "stopLatchTimer(): cancelling LatchAlarm timer");
|
|
|
|
|
mLatchAlarmTimer.cancel();
|
|
|
|
|
mLatchAlarmTimer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set the alarm standing flags to false to allow alarm phase to reset to current value.
|
|
|
|
|
*/
|
|
|
|
|
@@ -672,6 +713,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
Log.v(TAG, "acceptAlarm()");
|
|
|
|
|
mSdData.alarmStanding = false;
|
|
|
|
|
mSdData.fallAlarmStanding = false;
|
|
|
|
|
stopLatchTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -767,6 +809,16 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
Log.v(TAG, "updatePrefs() - DataSource = " + mSdDataSourceName);
|
|
|
|
|
mLatchAlarms = SP.getBoolean("LatchAlarms", false);
|
|
|
|
|
Log.v(TAG, "updatePrefs() - mLatchAlarms = " + mLatchAlarms);
|
|
|
|
|
// Parse the LatchAlarmPeriod setting.
|
|
|
|
|
try {
|
|
|
|
|
String latchAlarmPeriodStr = SP.getString("LatchAlarmTimerPeriod", "30");
|
|
|
|
|
mLatchAlarmPeriod = Integer.parseInt(latchAlarmPeriodStr);
|
|
|
|
|
Log.v(TAG, "updatePrefs() - mLatchAlarmTimerPeriod = " + mLatchAlarmPeriod);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Log.v(TAG, "updatePrefs() - Problem with LatchAlarmTimerPeriod preference!");
|
|
|
|
|
Toast toast = Toast.makeText(getApplicationContext(), "Problem Parsing LatchAlarmTimerPeriod Preference", Toast.LENGTH_SHORT);
|
|
|
|
|
toast.show();
|
|
|
|
|
}
|
|
|
|
|
mAudibleFaultWarning = SP.getBoolean("AudibleFaultWarning", true);
|
|
|
|
|
Log.v(TAG, "updatePrefs() - mAuidbleFaultWarning = " + mAudibleFaultWarning);
|
|
|
|
|
// Parse the faultTimer period setting.
|
|
|
|
|
@@ -805,7 +857,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write data to SD card alarm log
|
|
|
|
|
*/
|
|
|
|
|
@@ -856,6 +907,32 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Latch alarm in alarm state for a given period (mLatchAlarmPeriod seconds) after the alarm is raised.
|
|
|
|
|
* This is to ensure multiple Alarm annunciations even if only a single Alarm signal is received.
|
|
|
|
|
*/
|
|
|
|
|
private class LatchAlarmTimer extends CountDownTimer {
|
|
|
|
|
public LatchAlarmTimer(long startTime, long interval) {
|
|
|
|
|
super(startTime, interval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// called after startTime ms.
|
|
|
|
|
@Override
|
|
|
|
|
public void onFinish() {
|
|
|
|
|
Log.v(TAG, "LatchAlarmTimer.onFinish()");
|
|
|
|
|
// Do the equivalent of accept alarm push button.
|
|
|
|
|
acceptAlarm();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called every 'interval' ms.
|
|
|
|
|
@Override
|
|
|
|
|
public void onTick(long timeRemaining) {
|
|
|
|
|
Log.v(TAG, "LatchAlarmTimer.onTick() - time remaining = " + timeRemaining / 1000 + " sec");
|
|
|
|
|
alarmBeep();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Temporary cancel audible alarms, for the period specified by the
|
|
|
|
|
* CancelAudiblePeriod setting.
|
|
|
|
|
|