Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.libertyrider.angel;
- import android.hardware.Sensor;
- import android.util.Log;
- import db$k;
- import org.acra.ACRAConstants;
- public class AlgoChute {
- private static final int DT_MAX_SEUIL_ACC = 500;
- private static final int DT_MAX_SEUIL_VIT = 20000;
- private static final String TAG = "LibertyRider";
- private double accSeuilActivity;
- private Sensor accelerometer;
- private boolean alarmStopAction;
- boolean byPassInitState;
- private double chocSeuil;
- private int countState1;
- private int countState2;
- private int countState3;
- private int countState4;
- private int countTime;
- private double currentAcc;
- private int currentState;
- private long currentTimeAcc;
- private long currentTimeVit;
- private int currentVit;
- private boolean demo_active;
- private boolean erreurUpdateAccEnable;
- private boolean erreurUpdateAccFlag;
- private boolean erreurUpdateVitEnable;
- private boolean erreurUpdateVitFlag;
- private boolean initAlgoTimeFlag;
- private MyAlgoChuteListener listener;
- private String msgDebug;
- private int nbActivity;
- private int nbChoc;
- private int nbChocSeuil;
- private int nbSeuilActivity;
- private int nextState;
- private double previousAcc;
- private int previousState;
- private long previousTimeAcc;
- private long previousTimeVit;
- private int previousVit;
- private int seuilVitRunAlgo;
- private int tempoActivityCheck;
- private int tempoAlarme;
- private int tempoChocCheck;
- private long timeStartActivityCheck;
- private long timeStartAlarme;
- private long timeStartChocCheck;
- private boolean vitEnable;
- public enum DetectionState {
- INIT(-100),
- ERROR(-1),
- IDLE(0),
- RUNNING(1),
- SHOCKED_MOTIONLESS(2),
- SHOCKED_INACTIVITY(3),
- ALARM(4),
- ACCIDENT(5),
- ENDED(6);
- public final int code;
- private DetectionState(int i) {
- this.code = i;
- }
- public static String getName(int i) {
- for (DetectionState detectionState : values()) {
- if (detectionState.code == i) {
- return detectionState.name();
- }
- }
- return "UNKNOWN";
- }
- }
- public interface MyAlgoChuteListener {
- void onCountDown(int i);
- void onLogConsolMsg(String str);
- void onStateAlgoChange(long j, int i, String str);
- }
- public AlgoChute() {
- this.byPassInitState = false;
- this.currentTimeAcc = 0;
- this.previousTimeAcc = 0;
- this.currentTimeVit = 0;
- this.previousTimeVit = 0;
- this.currentAcc = 0.0d;
- this.previousAcc = 0.0d;
- this.currentVit = 0;
- this.previousVit = 0;
- this.nextState = DetectionState.INIT.code;
- this.currentState = DetectionState.INIT.code;
- this.previousState = DetectionState.ERROR.code;
- this.chocSeuil = 0.0d;
- this.tempoChocCheck = 0;
- this.nbChoc = 0;
- this.nbChocSeuil = 0;
- this.timeStartChocCheck = 0;
- this.accSeuilActivity = 0.0d;
- this.tempoActivityCheck = 0;
- this.nbSeuilActivity = 0;
- this.nbActivity = 0;
- this.timeStartActivityCheck = 0;
- this.timeStartAlarme = 0;
- this.tempoAlarme = 0;
- this.alarmStopAction = false;
- this.seuilVitRunAlgo = 0;
- this.vitEnable = true;
- this.initAlgoTimeFlag = false;
- this.countState2 = 0;
- this.countState1 = 0;
- this.countState3 = 0;
- this.countState4 = 0;
- this.accelerometer = null;
- this.countTime = 1;
- this.demo_active = false;
- this.msgDebug = ACRAConstants.DEFAULT_STRING_VALUE;
- this.listener = null;
- algoInitDefaultParameter();
- }
- public AlgoChute(Sensor sensor) {
- this.byPassInitState = false;
- this.currentTimeAcc = 0;
- this.previousTimeAcc = 0;
- this.currentTimeVit = 0;
- this.previousTimeVit = 0;
- this.currentAcc = 0.0d;
- this.previousAcc = 0.0d;
- this.currentVit = 0;
- this.previousVit = 0;
- this.nextState = DetectionState.INIT.code;
- this.currentState = DetectionState.INIT.code;
- this.previousState = DetectionState.ERROR.code;
- this.chocSeuil = 0.0d;
- this.tempoChocCheck = 0;
- this.nbChoc = 0;
- this.nbChocSeuil = 0;
- this.timeStartChocCheck = 0;
- this.accSeuilActivity = 0.0d;
- this.tempoActivityCheck = 0;
- this.nbSeuilActivity = 0;
- this.nbActivity = 0;
- this.timeStartActivityCheck = 0;
- this.timeStartAlarme = 0;
- this.tempoAlarme = 0;
- this.alarmStopAction = false;
- this.seuilVitRunAlgo = 0;
- this.vitEnable = true;
- this.initAlgoTimeFlag = false;
- this.countState2 = 0;
- this.countState1 = 0;
- this.countState3 = 0;
- this.countState4 = 0;
- this.accelerometer = null;
- this.countTime = 1;
- this.demo_active = false;
- this.msgDebug = ACRAConstants.DEFAULT_STRING_VALUE;
- this.listener = null;
- this.accelerometer = sensor;
- algoInitDefaultParameter();
- }
- private void algoInitDefaultParameter() {
- boolean z;
- if (this.demo_active) {
- this.chocSeuil = 5.0d;
- this.tempoChocCheck = 700;
- this.nbChocSeuil = 3;
- this.accSeuilActivity = 11.0d;
- this.tempoActivityCheck = 1000;
- this.nbSeuilActivity = 10;
- } else {
- this.chocSeuil = 20.0d;
- this.tempoChocCheck = ACRAConstants.TOAST_WAIT_DURATION;
- this.nbChocSeuil = 3;
- this.accSeuilActivity = 11.0d;
- this.tempoActivityCheck = ACRAConstants.DEFAULT_CONNECTION_TIMEOUT;
- this.nbSeuilActivity = 10;
- }
- this.tempoAlarme = 30000;
- if (this.demo_active) {
- z = false;
- } else {
- z = true;
- }
- this.vitEnable = z;
- this.seuilVitRunAlgo = 30;
- this.erreurUpdateAccEnable = true;
- this.erreurUpdateAccFlag = false;
- this.erreurUpdateVitEnable = true;
- this.erreurUpdateVitFlag = false;
- Log.v(TAG, "Algo state changed=" + DetectionState.getName(this.currentState));
- }
- public void update(long j, double d, long j2, int i) {
- if (j != this.currentTimeAcc) {
- this.previousTimeAcc = this.currentTimeAcc;
- this.currentTimeAcc = j;
- this.previousAcc = this.currentAcc;
- this.currentAcc = d;
- }
- if (j2 != this.currentTimeVit) {
- this.previousTimeVit = this.currentTimeVit;
- this.currentTimeVit = j2;
- this.previousVit = this.currentVit;
- this.currentVit = i;
- }
- if (((this.currentState >= DetectionState.IDLE.code ? 1 : 0) & (!this.byPassInitState ? 1 : 0)) != 0) {
- if (this.currentTimeAcc - this.previousTimeAcc > 500) {
- this.erreurUpdateAccFlag = true;
- } else {
- this.erreurUpdateAccFlag = false;
- }
- if (this.currentTimeVit - this.previousTimeVit > 20000) {
- this.erreurUpdateVitFlag = true;
- } else {
- this.erreurUpdateVitFlag = false;
- }
- }
- stateMachine();
- }
- private void stateMachine() {
- boolean z;
- int i = 1;
- boolean z2 = this.currentVit > this.seuilVitRunAlgo || !this.vitEnable;
- if (this.erreurUpdateAccFlag && this.erreurUpdateAccEnable) {
- z = false;
- } else {
- z = true;
- }
- this.previousState = this.currentState;
- this.currentState = this.nextState;
- if (this.currentState != this.previousState) {
- Log.v(TAG, "Algo state changed=" + DetectionState.getName(this.currentState));
- this.listener.onLogConsolMsg("State=" + DetectionState.getName(this.currentState));
- this.listener.onStateAlgoChange(this.currentTimeAcc, this.currentState, this.msgDebug);
- this.msgDebug = ACRAConstants.DEFAULT_STRING_VALUE;
- }
- switch (this.currentState) {
- case -100:
- int i2;
- this.nextState = DetectionState.INIT.code;
- if (this.currentTimeAcc != 0) {
- i2 = 1;
- } else {
- i2 = 0;
- }
- if (this.currentTimeVit == 0) {
- i = 0;
- }
- if (((i2 & i) | this.byPassInitState) != 0) {
- this.nextState = DetectionState.IDLE.code;
- }
- case ACRAConstants.DEFAULT_SHARED_PREFERENCES_MODE /*0*/:
- this.nextState = DetectionState.IDLE.code;
- if (z2) {
- this.nextState = DetectionState.RUNNING.code;
- }
- if (!z) {
- this.nextState = DetectionState.ERROR.code;
- }
- case db$k.View_android_focusable /*1*/:
- this.nextState = DetectionState.RUNNING.code;
- if (this.currentState != this.previousState) {
- this.countState1++;
- }
- if (this.currentAcc > this.chocSeuil && z2 && z) {
- this.nextState = 2;
- this.msgDebug = Integer.toString((int) this.currentAcc);
- }
- if (!z2) {
- this.nextState = DetectionState.IDLE.code;
- }
- if (!z) {
- this.nextState = DetectionState.ERROR.code;
- }
- case db$k.View_paddingStart /*2*/:
- this.nextState = 2;
- if (this.currentState != this.previousState) {
- this.timeStartChocCheck = this.currentTimeAcc;
- this.nbChoc = 1;
- Log.v(TAG, "Process choc start");
- this.countState2++;
- }
- if (this.currentTimeAcc - this.timeStartChocCheck >= ((long) this.tempoChocCheck)) {
- Log.v(TAG, "temp=" + Long.toString(this.currentTimeAcc - this.timeStartChocCheck));
- Log.v(TAG, "nbChoc=" + this.nbChoc);
- this.listener.onLogConsolMsg("nbChoc=" + this.nbChoc);
- if (this.nbChoc > this.nbChocSeuil) {
- this.nextState = 3;
- this.msgDebug = "nbChoc=" + Integer.toString(this.nbChoc);
- } else {
- this.nextState = DetectionState.RUNNING.code;
- this.msgDebug = "nbChoc=" + Integer.toString(this.nbChoc);
- }
- this.nbChoc = 0;
- } else if (this.currentAcc > this.chocSeuil) {
- this.nbChoc++;
- }
- case db$k.View_paddingEnd /*3*/:
- this.nextState = 3;
- if (this.currentState != this.previousState) {
- this.timeStartActivityCheck = this.currentTimeAcc;
- Log.v(TAG, "Process activity start");
- this.countState3++;
- }
- if (this.currentTimeAcc - this.timeStartActivityCheck >= ((long) this.tempoActivityCheck)) {
- Log.v(TAG, "temp=" + Long.toString(this.currentTimeAcc - this.timeStartActivityCheck));
- Log.v(TAG, "nbActi=" + this.nbActivity);
- this.listener.onLogConsolMsg("nbActi=" + this.nbActivity);
- if (this.nbActivity < this.nbSeuilActivity) {
- this.nextState = DetectionState.ALARM.code;
- this.msgDebug = "nbActi=" + Integer.toString(this.nbActivity);
- } else {
- this.nextState = DetectionState.RUNNING.code;
- this.msgDebug = "nbActi=" + Integer.toString(this.nbActivity);
- }
- this.nbActivity = 0;
- } else if (this.currentAcc > this.accSeuilActivity) {
- this.nbActivity++;
- }
- case db$k.View_theme /*4*/:
- this.nextState = DetectionState.ALARM.code;
- if (this.currentState != this.previousState) {
- Log.v(TAG, "Alarme Start");
- this.timeStartAlarme = this.currentTimeAcc;
- this.countState4++;
- this.countTime = 1;
- this.listener.onCountDown(this.tempoAlarme / 1000);
- }
- if (this.alarmStopAction) {
- Log.v(TAG, "Alarme Stoped");
- this.nextState = DetectionState.ENDED.code;
- this.alarmStopAction = false;
- return;
- }
- long j = this.currentTimeAcc - this.timeStartAlarme;
- if (j >= ((long) this.tempoAlarme)) {
- Log.v(TAG, "Alarme Finished");
- Log.v(TAG, "temp0=" + Long.toString(this.currentTimeAcc - this.timeStartAlarme));
- this.nextState = DetectionState.ACCIDENT.code;
- } else if (j > ((long) (this.countTime * 1000))) {
- this.countTime++;
- this.listener.onCountDown(((this.tempoAlarme / 1000) - this.countTime) + 1);
- }
- case ACRAConstants.MAX_SEND_REPORTS /*5*/:
- this.nextState = DetectionState.ACCIDENT.code;
- if (this.currentState != this.previousState) {
- Log.v(TAG, "Chute d\u00e9tect\u00e9e");
- this.listener.onLogConsolMsg("chute d\u00e9tect\u00e9e");
- }
- if (this.alarmStopAction) {
- this.nextState = DetectionState.ENDED.code;
- }
- case db$k.Toolbar_contentInsetEnd /*6*/:
- this.nextState = DetectionState.ENDED.code;
- if (this.currentState != this.previousState) {
- Log.v(TAG, "User stop alarme");
- this.listener.onLogConsolMsg("User stop alarme");
- }
- default:
- }
- }
- public void setDemo(boolean z) {
- this.demo_active = z;
- }
- public void setVitCondi(int i) {
- if (i == 1) {
- this.vitEnable = true;
- } else {
- this.vitEnable = false;
- }
- }
- public void setByPassInitSate(boolean z) {
- this.byPassInitState = z;
- }
- public void setVitErreurCondi(int i) {
- if (i == 1) {
- this.erreurUpdateVitEnable = true;
- } else {
- this.erreurUpdateVitEnable = false;
- }
- }
- public void setAccErreurCondi(int i) {
- if (i == 1) {
- this.erreurUpdateAccEnable = true;
- } else {
- this.erreurUpdateAccEnable = false;
- }
- }
- public void setByPassInitState(int i) {
- if (i == 1) {
- this.byPassInitState = true;
- } else {
- this.byPassInitState = false;
- }
- }
- public void setAlgoInit() {
- algoInitDefaultParameter();
- this.previousState = DetectionState.IDLE.code;
- this.currentState = DetectionState.IDLE.code;
- this.nextState = DetectionState.IDLE.code;
- this.previousTimeAcc = 0;
- this.previousTimeVit = 0;
- this.initAlgoTimeFlag = false;
- }
- public void setAlarmeStopAction() {
- this.alarmStopAction = true;
- }
- public int getAlgoChuteState() {
- return this.currentState;
- }
- public String getStatSessionString() {
- return "s1:" + this.countState1 + " s2:" + this.countState2 + " s3:" + this.countState3 + " s4:" + this.countState4;
- }
- public int[] getStatSessionTab() {
- return new int[]{this.countState1, this.countState2, this.countState3, this.countState4};
- }
- public String affAlgoParameter() {
- String str = ACRAConstants.DEFAULT_STRING_VALUE;
- return "cS:" + this.chocSeuil + " cT:" + this.tempoChocCheck + " cN:" + this.nbChocSeuil + " aS:" + this.accSeuilActivity + " aT:" + this.tempoActivityCheck + " aN:" + this.nbSeuilActivity + " eA:" + this.erreurUpdateAccEnable + " eV:" + this.erreurUpdateVitEnable + " vE" + this.vitEnable;
- }
- public void setCustomObjectListener(MyAlgoChuteListener myAlgoChuteListener) {
- this.listener = myAlgoChuteListener;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement