Skip to content

Instantly share code, notes, and snippets.

@RAJMOHANNIRAVATH
Created September 29, 2016 06:47
Show Gist options
  • Save RAJMOHANNIRAVATH/5ae07e75b1bf2d289e5abba90f97c862 to your computer and use it in GitHub Desktop.
Save RAJMOHANNIRAVATH/5ae07e75b1bf2d289e5abba90f97c862 to your computer and use it in GitHub Desktop.
When the declaration of the enumerator makes error
package com.nousappsystems.pumperapp;
import android.annotation.SuppressLint;
import android.widget.Toast;
import java.util.LinkedList;
import java.util.logging.Level;
public class Device {
public static int MAX_DAILY_SCHEDULES = 5;
AppAttribute appAttribute;
DeviceAttribute devattr;
Device(String pumperName, String pumperContact) {
this.appAttribute = new AppAttribute(pumperName);
this.devattr = new DeviceAttribute(pumperContact);
}
public Device() {
}
public enum SensorCode {
DRY_RUN_SENSOR(1),
OVER_LOAD_SENSOR(2),
MANUAL_ON_OFF_SENSOR(3),
VOLTAGE_SENSORS(4),
SINGLE_PHASING_SENSOR(5),
MOTOR_FAULT_SENSOR(6);
final int sensorCode;
SensorCode(int sensorCode) {
this.sensorCode = sensorCode;
}
}
/****
* Here need to add a version code for LivMitr
***/
public enum DeviceSeries { @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@this is my enumerator@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
PUMPER_MODEL_UNKNOWN(0),
PUMPER_PRO_VER1_2(1),
PUMPER_LITE_VER1_1(2),
PUMPER_PRO_VER1_3(3);
//LEVEL_METER(4);
//need to decide whether level meter need another class.
final int deviceSeries;
DeviceSeries(int deviceSeries) {
this.deviceSeries = deviceSeries;
}
}
public enum LineConditionCode {
LINE_CONDITION_OK(0x00),
LINE_CONDITION_OVER_VOLTAGE(0x10),
LINE_CONDITION_LOW_VOLTAGE(0x20),
LINE_CONDITION_POWER_FAILURE(0x30),
LINE_CONDITION_PHASE_POWER_FAILURE(0x40),
LINE_CONDITION_PHASE_REVERSAL(0x50);
final int lineConditionCode;
LineConditionCode(int lineConditionCode) {
this.lineConditionCode = lineConditionCode;
}
int getValue() {
return this.lineConditionCode;
}
}
public enum ManualOperations {
MOTOR_TURNED_ON(0x10),
MOTOR_TURNED_OFF(0x20),
MOTOR_TURN_ON_FAIL(0x30),
MOTOR_TURN_OFF_FAIL(0x40),
MOTOR_AUTO_RESUME(0x50);
final int manualOperationCode;
ManualOperations(int manualOperationCode) {
this.manualOperationCode = manualOperationCode;
}
int getValue() {
return this.manualOperationCode;
}
}
private enum MotorRating {
UNKNOWN_HP(0),
HALF_HP(0.5),
HALF_QUARTER_HP(0.75),
ONE_HP(1),
ONE_HALF_HP(1.5),
TWO_HP(2),
THREE_HP(3),
FOUR_HP(4),
FIVE_HP(5),
SEVEN_HALF_HP(7.5),
TEN_HP(10),
TWELVE_HALF_HP(12.5),
FIFTEEN_HP(15),
TWENTY_HP(20),
TWENTY_FIVE_HP(25),
THIRTY_HP(30),
THIRTY_FIVE_HP(35),
FORTY_HP(40);
private final double rating;
MotorRating(double rating) {
this.rating = rating;
}
double getMotorRating() {
return this.rating;
}
}
private enum SchedulerState {
CONTINUE_DAILY_SCHEDULE_STATE(0),
FINISH_DAILY_SCHEDULE(1),
SKIP_DAILY_SCHEDULE(2),
PAUSE_DAILY_SCHEDULE(3),
RESUME_DAILY_SCHEDULE(4),
END_DAILY_SCHEDULE(5),
CONTINUE_FIXED_SCHEDULE_STATE(0),
START_FIXED_SCHEDULE(0x10),
FINISH_FIXED_SCHEDULE(0x20),
SKIP_FIXED_SCHEDULE(0x30),
PAUSE_FIXED_SCHEDULE(0x40),
RESUME_FIXED_SCHEDULE(0x50),
END_FIXED_SCHEDULE(0x60);
private final int state;
SchedulerState(int state) {
this.state = state;
}
double getSchedulerState() {
return this.state;
}
}
class AppAttribute {
String pumperName;
private boolean isCommnOnGOing;
AppAttribute(String pumperName) {
this.pumperName = pumperName;
}
void setCommnOnGoing(boolean isCommnOnGoing) {
this.isCommnOnGOing = isCommnOnGoing;
}
boolean isCommnOnGoing() {
return this.isCommnOnGOing;
}
}
class DeviceAttribute
{
NousappPumperDeviceAttribute deviceAttributepump;
NousappLevelMeterDeviceAttribute deviceAttributelevel;
DeviceAttribute(String pumperContact){
}
class NousappPumperDeviceAttribute {
// NousappPumperDeviceAttribute deviceAttributepump = new NousappPumperDeviceAttribute();
String pumperContact;
LinkedList<User> users;
User lastRequestedUser;
private boolean isUserAdditionLocked;
private boolean isMotorRunning;
private boolean isAppInSyncWithDevice;
private boolean willAutoResume;
private boolean isAutoStarterModeEnabled;
private boolean isTimePausingEnabled;
PumperNetwork network;
//level level;//edited
VoltageSensors voltageSensors;
SinglePhasingSensor singlePhasingSensor;
ManualOnOffSensor manualOnOffSensor;
DryRunSensor dryRunSensor;
OverloadSensor overloadSensor;
MotorFaultSensor motorFaultSensor;
private CallMode callMode;
private MotorRating motorRating;
private DeviceSeries deviceSeries;
Schedule scheduleList[] = new Schedule[5];
//level level;
NousappPumperDeviceAttribute(String pumperContact) {
this.pumperContact = pumperContact;
//this.level = new level();//edited
this.network = new PumperNetwork();
this.dryRunSensor = new DryRunSensor();
this.manualOnOffSensor = new ManualOnOffSensor();
this.overloadSensor = new OverloadSensor();
this.voltageSensors = new VoltageSensors();
this.singlePhasingSensor = new SinglePhasingSensor();
this.motorFaultSensor = new MotorFaultSensor();
this.users = new LinkedList<User>();
this.motorRating = MotorRating.UNKNOWN_HP;
this.deviceSeries;@@@@@@@@here i am declared the Enumerator@@@@@@@@@@@@How will I declare here every time it gets error@
}
void setDeviceSeries(DeviceSeries deviceSeries) {
this.deviceSeries = deviceSeries;
}
DeviceSeries getDeviceSeries() {
return this.deviceSeries;
}
void setAppSyncWithDevice(boolean isInSync) {
this.isAppInSyncWithDevice = isInSync;
}
boolean isAppInSyncWithDevice() {
return isAppInSyncWithDevice;
}
void setUserAdditionLocked(boolean isLocked) {
this.isUserAdditionLocked = isLocked;
}
boolean isUserAdditionLocked() {
return isUserAdditionLocked;
}
void setMotorRunning(boolean isRunning) {
this.isMotorRunning = isRunning;
}
void setAutoResuming(boolean willResume) {
this.willAutoResume = willResume;
}
boolean willAutoResume() {
return willAutoResume;
}
boolean isMotorRunning() {
return isMotorRunning;
}
void setCallMode(CallMode callMode) {
this.callMode = callMode;
}
void setMotorRating(int index) {
switch (this.deviceSeries) {
case PUMPER_PRO_VER1_2:
switch (index) {
case 1:
this.motorRating = MotorRating.ONE_HP;
break;
case 2:
this.motorRating = MotorRating.ONE_HALF_HP;
break;
case 3:
this.motorRating = MotorRating.TWO_HP;
break;
case 4:
this.motorRating = MotorRating.THREE_HP;
break;
case 5:
this.motorRating = MotorRating.FOUR_HP;
break;
case 6:
this.motorRating = MotorRating.FIVE_HP;
break;
case 7:
this.motorRating = MotorRating.SEVEN_HALF_HP;
break;
case 8:
this.motorRating = MotorRating.TEN_HP;
break;
case 9:
this.motorRating = MotorRating.TWELVE_HALF_HP;
break;
case 10:
this.motorRating = MotorRating.FIFTEEN_HP;
break;
default:
this.motorRating = MotorRating.UNKNOWN_HP;
break;
}
break;
case PUMPER_LITE_VER1_1:
switch (index) {
case 1:
this.motorRating = MotorRating.HALF_HP;
break;
case 2:
this.motorRating = MotorRating.HALF_QUARTER_HP;
break;
case 3:
this.motorRating = MotorRating.ONE_HP;
break;
case 4:
this.motorRating = MotorRating.ONE_HALF_HP;
break;
case 5:
this.motorRating = MotorRating.TWO_HP;
break;
case 6:
this.motorRating = MotorRating.THREE_HP;
break;
default:
this.motorRating = MotorRating.UNKNOWN_HP;
break;
}
break;
case PUMPER_PRO_VER1_3:
switch (index) {
case 1:
this.motorRating = MotorRating.ONE_HP;
break;
case 2:
this.motorRating = MotorRating.ONE_HALF_HP;
break;
case 3:
this.motorRating = MotorRating.TWO_HP;
break;
case 4:
this.motorRating = MotorRating.THREE_HP;
break;
case 5:
this.motorRating = MotorRating.FOUR_HP;
break;
case 6:
this.motorRating = MotorRating.FIVE_HP;
break;
case 7:
this.motorRating = MotorRating.SEVEN_HALF_HP;
break;
case 8:
this.motorRating = MotorRating.TEN_HP;
break;
case 9:
this.motorRating = MotorRating.TWELVE_HALF_HP;
break;
case 10:
this.motorRating = MotorRating.FIFTEEN_HP;
break;
case 11:
this.motorRating = MotorRating.TWENTY_HP;
break;
case 12:
this.motorRating = MotorRating.TWENTY_FIVE_HP;
break;
case 13:
this.motorRating = MotorRating.THIRTY_HP;
break;
case 14:
this.motorRating = MotorRating.THIRTY_FIVE_HP;
break;
case 15:
this.motorRating = MotorRating.FORTY_HP;
break;
default:
this.motorRating = MotorRating.UNKNOWN_HP;
break;
}
break;
default:
break;
}
}
void enableAutoStarter(boolean doEnable) {
this.isAutoStarterModeEnabled = doEnable;
}
void enableTimePause(boolean doEnable) {
this.isTimePausingEnabled = doEnable;
}
double getMotorRatingValue() {
return this.motorRating.getMotorRating();
}
int getMotorRatingIndex() {
switch (this.deviceSeries) {
case PUMPER_LITE_VER1_1:
switch (this.motorRating) {
case HALF_HP:
return 1;
case HALF_QUARTER_HP:
return 2;
case ONE_HP:
return 3;
case ONE_HALF_HP:
return 4;
case TWO_HP:
return 5;
case THREE_HP:
return 6;
default:
return 0;
}
case PUMPER_PRO_VER1_2:
switch (this.motorRating) {
case ONE_HP:
return 1;
case ONE_HALF_HP:
return 2;
case TWO_HP:
return 3;
case THREE_HP:
return 4;
case FOUR_HP:
return 5;
case FIVE_HP:
return 6;
case SEVEN_HALF_HP:
return 7;
case TEN_HP:
return 8;
case TWELVE_HALF_HP:
return 9;
case FIFTEEN_HP:
return 10;
default:
return 0;
}
case PUMPER_PRO_VER1_3:
switch (this.motorRating) {
case ONE_HP:
return 1;
case ONE_HALF_HP:
return 2;
case TWO_HP:
return 3;
case THREE_HP:
return 4;
case FOUR_HP:
return 5;
case FIVE_HP:
return 6;
case SEVEN_HALF_HP:
return 7;
case TEN_HP:
return 8;
case TWELVE_HALF_HP:
return 9;
case FIFTEEN_HP:
return 10;
case TWENTY_HP:
return 11;
case TWENTY_FIVE_HP:
return 12;
case THIRTY_HP:
return 13;
case THIRTY_FIVE_HP:
return 14;
case FORTY_HP:
return 15;
default:
return 0;
}
default:
return 0;
}
}
boolean isMotorRatingUpdated() {
return this.motorRating != MotorRating.UNKNOWN_HP;
}
CallMode getCallMode() {
return callMode;
}
boolean isAutoStarterEnabled() {
return this.isAutoStarterModeEnabled;
}
boolean isTimePauseEnabled() {
return this.isTimePausingEnabled;
}
class User {
String contactNum;//edited by rajmohan if remove the mobile number reinstate previous postion
boolean doDelete;// for develpment Prupuse
User(String contactNum) {
this.contactNum = contactNum;
}
void doDelete(boolean doDelete) { // for develpment Purpuse
this.doDelete = doDelete;
}
}
class PumperNetwork {
private boolean isSimPrepaid;
private String balanceCheckUSSD;
private String prepaidBalance;
PumperNetwork() {
this.isSimPrepaid = false;
}
void setSIMPrepaid(boolean isSimPrepaid) {
this.isSimPrepaid = isSimPrepaid;
}
boolean isSIMPrepaid() {
return isSimPrepaid;
}
void setBalanceCheckUSSD(String balanceCheckUSSD) {
this.balanceCheckUSSD = balanceCheckUSSD;
}
String getBalanceCheckUSSD() {
return balanceCheckUSSD;
}
void setPrepaidBalance(String prepaidBalance) {
this.prepaidBalance = prepaidBalance;
}
String getPrepaidBalance() {
return this.prepaidBalance;
}
}
class Level {
// private boolean isSimPrepaid;
private String setMaxheight;
private String setTankHeight;
private String setMinheight;
private String setVersion;
private String setMode;
private String setCurrentStatus;
private String setCurrentLevel;
private String setDidPumptoRespond;
private String setSafeDelay;
void setVersion(String setVersion) {
this.setVersion = setVersion;
}
String getVersion() {
return setVersion;
}
void setCurrentLevel(String setCurrentLevel) {
this.setCurrentLevel = setCurrentLevel;
}
String getCurrentLevel() {
return setCurrentLevel;
}
void setSafeDelay(String setSafeDelay) {
this.setSafeDelay = setSafeDelay;
}
void setMode(String setMode) {
this.setMode = setMode;
}
void setCurrentStatus(String setCurrentStatus) {
this.setCurrentStatus = setCurrentStatus;
}
void setTankHeight(String setTankHeight) {
this.setTankHeight = setTankHeight;
}
void setMinheight(String setMinheight) {
this.setMinheight = setMinheight;
}
void setMaxheight(String setMaxheight) {
this.setMaxheight = setMaxheight;
}
void setDidPumptoRespond(String setDidPumptoRespond) {
this.setDidPumptoRespond = setDidPumptoRespond;
}
String getMode() {
return setMode;
}
String getCurrentStatus() {
return setCurrentStatus;
}
String getTankHeight() {
return setTankHeight;
}
String getMinheight() {
return setMinheight;
}
String getMaxheight() {
return setMaxheight;
}
String getDifPumptoRespond() {
return setDidPumptoRespond;
}
String getSafeDelay() {
return setSafeDelay;
}
}
//Moved to LevelMeter.java
class PumperSensor {
protected boolean isEnabled;
protected boolean isTriggered;
protected int extraInfo;
void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
void setExtraInfo(int extraInfo) {
this.extraInfo = extraInfo;
}
boolean isEnabled() {
return isEnabled;
}
}
class VoltageSensors extends PumperSensor {
VoltageSensors() {
this.setEnabled(false);
}
}
class SinglePhasingSensor extends PumperSensor {
SinglePhasingSensor() {
this.setEnabled(false);
}
}
class FireSensor extends PumperSensor {
FireSensor() {
this.setEnabled(false);
}
}
class ManualOnOffSensor extends PumperSensor {
ManualOnOffSensor() {
this.setEnabled(false);
}
}
class DryRunSensor extends PumperSensor {
DryRunSensor() {
this.setEnabled(false);
}
}
class OverloadSensor extends PumperSensor {
OverloadSensor() {
this.setEnabled(false);
}
}
class MotorFaultSensor extends PumperSensor {
MotorFaultSensor() {
this.setEnabled(false);
}
}
@SuppressLint("NewApi")
class Schedule {
int scheduleID;
int scheduleStartHour;
int scheduleStartMin;
int scheduleDuration;
int cyclicRunDuration;
int cyclicStopDuration;
String scheduleDurationUnit;
int scheduleStopHour;
int scheduleStopMin;
boolean isScheduleEnabled;
// private AlarmManager turnONAlarmManager;
// private AlarmManager turnOFFAlarmManager;
// private PendingIntent turnONAlarmManagerPendingIntent;
// private PendingIntent turnOFFAlarmManagerPendingIntent;
// private boolean enabled;
Schedule(int scheduleID, int scheduleStartHour, int scheduleStartMin, int scheduleDuration, String runTimeUnit) {
this.scheduleID = scheduleID;
this.scheduleStartHour = scheduleStartHour;
this.scheduleStartMin = scheduleStartMin;
this.scheduleDuration = scheduleDuration;
this.scheduleDurationUnit = runTimeUnit;
if (this.scheduleDurationUnit.equals("Hour")) {
this.scheduleStopHour = (this.scheduleStartHour + scheduleDuration) % 24;
this.scheduleStopMin = this.scheduleStartMin;
} else {
this.scheduleStopHour = ((this.scheduleStartHour + ((this.scheduleStartMin + this.scheduleDuration) / 60)) % 24);
this.scheduleStopMin = (this.scheduleStartMin + (scheduleDuration % 60)) % 60;
}
}
public void setCyclicSchedule(int cyclicRunDuration, int cyclicStopDuration) {
this.cyclicRunDuration = cyclicRunDuration;
this.cyclicStopDuration = cyclicStopDuration;
}
public void setEnabled(boolean enable) {
this.isScheduleEnabled = enable;
}
public boolean isEnabled() {
return this.isScheduleEnabled;
}
/*
@SuppressLint("NewApi") private void setAlarm(Context mContext) {
Calendar currentCalendar;
Calendar OnTimeCalendar;
Calendar OffTimeCalendar;
Intent onIntent;
Intent offIntent;
turnONAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
turnOFFAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
currentCalendar = Calendar.getInstance();
OnTimeCalendar = Calendar.getInstance();
OffTimeCalendar = Calendar.getInstance();
currentCalendar.setTimeInMillis(System.currentTimeMillis());
OnTimeCalendar.setTimeInMillis(System.currentTimeMillis());
OffTimeCalendar.setTimeInMillis(System.currentTimeMillis());
onIntent = new Intent(mContext, SystemReceivers.class);
offIntent = new Intent(mContext, SystemReceivers.class);
onIntent.setAction("pumper.intent.action.TURN_PUMPER_ON");
onIntent.putExtra("PUMPER_NAME", pumperName);
offIntent.setAction("pumper.intent.action.TURN_PUMPER_OFF");
offIntent.putExtra("PUMPER_NAME", pumperName);
turnONAlarmManagerPendingIntent = PendingIntent.getBroadcast(mContext, 0, onIntent, android.app.PendingIntent.FLAG_ONE_SHOT);
turnOFFAlarmManagerPendingIntent = PendingIntent.getBroadcast(mContext, 0, offIntent, android.app.PendingIntent.FLAG_CANCEL_CURRENT);
OnTimeCalendar.set(Calendar.HOUR_OF_DAY, onHour);
OnTimeCalendar.set(Calendar.MINUTE, onMin);
OnTimeCalendar.set(Calendar.SECOND, 0);
OffTimeCalendar.set(Calendar.HOUR_OF_DAY, offHour);
OffTimeCalendar.set(Calendar.MINUTE, offMin);
OffTimeCalendar.set(Calendar.SECOND, 0);
if (OnTimeCalendar.before(currentCalendar) || OnTimeCalendar.equals(currentCalendar)) {
OnTimeCalendar.set(Calendar.DAY_OF_MONTH, OnTimeCalendar.get(Calendar.DAY_OF_MONTH) + 1);
}
turnONAlarmManager.setExact(AlarmManager.RTC_WAKEUP, OnTimeCalendar.getTimeInMillis(), turnONAlarmManagerPendingIntent);
//turnONAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, OnTimeCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, turnONAlarmManagerPendingIntent);
// Toast.makeText(mContext, "Turn ON at: " + OnTimeCalendar.getTime().toString(), Toast.LENGTH_SHORT).show();
if (OffTimeCalendar.before(currentCalendar) || OffTimeCalendar.equals(currentCalendar)) {
OffTimeCalendar.set(Calendar.DAY_OF_MONTH, OffTimeCalendar.get(Calendar.DAY_OF_MONTH) + 1);
}
turnOFFAlarmManager.setExact(AlarmManager.RTC_WAKEUP, OffTimeCalendar.getTimeInMillis(), turnOFFAlarmManagerPendingIntent);
// Toast.makeText(mContext, "Turn OFF at: " + OffTimeCalendar.getTime().toString(), Toast.LENGTH_SHORT).show();
}
private void cancelAlarm() {
if ((turnONAlarmManager != null) && (turnONAlarmManagerPendingIntent != null)) {
turnONAlarmManager.cancel(turnONAlarmManagerPendingIntent);
}
if ((turnOFFAlarmManager != null) && (turnOFFAlarmManagerPendingIntent != null)) {
turnOFFAlarmManager.cancel(turnOFFAlarmManagerPendingIntent);
}
}*/
}
}
class NousappLevelMeterDeviceAttribute {
NousappLevelMeterDeviceAttribute deviceAttributelevel =new NousappLevelMeterDeviceAttribute();
public void NousappLevelMeterDeviceAttribute() {
}
}
}
enum CallMode {
STATUS_MODE (0),
TOGGLE_MODE (1),
MISSED_CALL_MODE (2);
private final int callMode;
CallMode(int callMode) {
this.callMode = callMode;
}
double getCallMode() {
return this.callMode;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment