| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- package kr.co.icontrols.homeautomation;
- import android.content.Context;
- import android.content.Intent;
- import android.util.Log;
- public class HomeAutomation_Etc
- {
- private static final String TAG = "HomeAutomation_Etc";
- Context context;
-
- /** BR Action Name <br>
- * 본 Action Name을 BroadcastReceiver에 getAction 후 문자열 비교 등록 후 일치 시 사용해야 한다.
- * **/
- public static final String BR_HOME_AUTOMATION_ETC = "BR_HOME_AUTOMATION_ETC";
- public static final String BR_TYPE = "TYPE";
- public static final String BR_TYPE_PASSWORD = "TYPE_PASSWORD";
- public static final String BR_TYPE_REALMETER_YEAR = "TYPE_REALMETER_YEAR";
- public static final String BR_TYPE_REALMETER_MONTH = "TYPE_REALMETER_MONTH";
-
- public static final String BR_TYPE_REALMETER_ELECT = "TYPE_REALMETER_ELECT";
- public static final String BR_TYPE_REALMETER_GAS = "TYPE_REALMETER_GAS";
- public static final String BR_TYPE_REALMETER_WATER = "TYPE_REALMETER_WATER";
- public static final String BR_TYPE_REALMETER_HEATING = "TYPE_REALMETER_HEATING";
- public static final String BR_TYPE_REALMETER_HOTWATER = "TYPE_REALMETER_HOTWATER";
-
- public static final int TYPE_PASSWORD = 0;
- public static final int TYPE_REALMETER_REQUEST = 1;
- public static final int TYPE_REALMETER_REPLY = 2;
-
- /**
- * 생성자
- * **/
- public HomeAutomation_Etc(Context ctx)
- {
- context = ctx;
- Log.d(TAG, "HomeAutomation_Emergency API Start");
- }
-
-
- /**
- * @description
- * 비밀번호 br parsing 함수
- *
- * @return String Password (null인지 비교하고 사용)
- *
- * @param intent -> 수신 받은 intent 원형
- * **/
- public String BR_Parsing_Password(Intent intent)
- {
-
- String Password = intent.getStringExtra(BR_TYPE_PASSWORD);
- if(Password == null)
- {
- Log.e(TAG, "BR_Parsing - Password is error : ");
- return null;
- }
- return Password;
- }
-
- /**
- * @description
- * 원격검침 요청 br parsing 함수
- *
- * @return byte[4] -> 요청 날짜
- *
- * @param intent -> 수신 받은 intent 원형
- * **/
- public byte[] BR_Parsing_RealMeter_request(Intent intent)
- {
- byte[] RetByte = new byte[4];
-
- int Year = intent.getIntExtra(BR_TYPE_REALMETER_YEAR, -999);
- int Month = intent.getIntExtra(BR_TYPE_REALMETER_MONTH, -999);
- if(Year < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_request - Year : " + Year);
- return null;
- }
- if(Month < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_request - Month : " + Month);
- return null;
- }
-
- Year = Year - 2000;
-
- RetByte[0] = (byte) (Year / 10);
- RetByte[1] = (byte) (Year % 10);
- RetByte[2] = (byte) (Month / 10);
- RetByte[3] = (byte) (Month % 10);
-
- return RetByte;
- }
-
- /**
- * @description
- * 원격검침 응답 br parsing 함수
- *
- * @return flaot[5] -> 원격검침 데이터
- *
- * @param intent -> 수신 받은 intent 원형
- * **/
- public double[] BR_Parsing_RealMeter_reply(Intent intent)
- {
- double[] RetByte = new double[5];
-
- double elect = intent.getDoubleExtra(BR_TYPE_REALMETER_ELECT, -999);
- double gas = intent.getDoubleExtra(BR_TYPE_REALMETER_GAS, -999);
- double water = intent.getDoubleExtra(BR_TYPE_REALMETER_WATER, -999);
- double heating = intent.getDoubleExtra(BR_TYPE_REALMETER_HEATING, -999);
- double hotwater = intent.getDoubleExtra(BR_TYPE_REALMETER_HOTWATER, -999);
- if(elect < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_reply - elect : " + elect);
- return null;
- }
- if(gas < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_reply - gas : " + gas);
- return null;
- }
- if(water < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_reply - water : " + water);
- return null;
- }
- if(heating < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_reply - heating : " + heating);
- return null;
- }
- if(hotwater < 0)
- {
- Log.e(TAG, "BR_Parsing_RealMeter_reply - hotwater : " + hotwater);
- return null;
- }
-
- RetByte[0] = elect;
- RetByte[1] = gas;
- RetByte[2] = water;
- RetByte[3] = heating;
- RetByte[4] = hotwater;
-
- return RetByte;
- }
-
-
- /**
- * @description
- * 로비 출입 비밀번호 서비스로 전송
- *
- * @return boolean -> true(정상), false(송신 실패)
- *
- * @param Type - 연동할 종류
- * **/
- public boolean BR_Send_Password(String Password)
- {
- try
- {
- /** param check **/
- // 1. 비밀번호 입력 체크
- if(Password == null)
- {
- Log.e(TAG, "BR_Send - Password is null");
- return false;
- }
-
- if(Password.length() != 4)
- {
- Log.e(TAG, "BR_Send - Password length is error : " + Password);
- return false;
- }
-
- //2. Broadcast 전송
- Intent iIntent = new Intent();
- iIntent.setAction(BR_HOME_AUTOMATION_ETC);
- iIntent.putExtra(BR_TYPE, TYPE_PASSWORD);
- iIntent.putExtra(BR_TYPE_PASSWORD, Password);
- context.sendBroadcast(iIntent);
-
- return true;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- return false;
- }
- }
-
-
- /**
- * @description
- * 원격검침 데이터 요청
- *
- * @return boolean -> true(정상), false(송신 실패)
- *
- * @param Year - 해당 연도
- * @param Month - 해당 월
- * **/
- public boolean BR_Send_RealMeterReqest(int Year, int Month)
- {
- try
- {
- /** param check **/
- // 1. 비밀번호 입력 체크
-
- if((Month < 1) || (Month > 12))
- {
- Log.e(TAG, "BR_Send_RealMeterReqest - Month : " + Month);
- return false;
- }
-
- //2. Broadcast 전송
- Intent iIntent = new Intent();
- iIntent.setAction(BR_HOME_AUTOMATION_ETC);
- iIntent.putExtra(BR_TYPE, TYPE_REALMETER_REQUEST);
- iIntent.putExtra(BR_TYPE_REALMETER_YEAR, Year);
- iIntent.putExtra(BR_TYPE_REALMETER_MONTH, Month);
- context.sendBroadcast(iIntent);
-
- return true;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- return false;
- }
- }
-
- /**
- * @description
- * 원격검침 데이터 응답
- *
- * @return boolean -> true(정상), false(송신 실패)
- *
- * @param double[5] -> 검침 데이터
- * **/
- public boolean BR_Send_RealMeterReply(double[] DoubleArray)
- {
- try
- {
- /** param check **/
- // 1. 비밀번호 입력 체크
-
- if(DoubleArray == null)
- {
- return false;
- }
-
- if(DoubleArray.length != 5)
- {
- Log.e(TAG, "BR_Send_RealMeterReply - FloatArray.length : " + DoubleArray.length);
- return false;
- }
-
- //2. Broadcast 전송
- Intent iIntent = new Intent();
- iIntent.setAction(BR_HOME_AUTOMATION_ETC);
- iIntent.putExtra(BR_TYPE, TYPE_REALMETER_REPLY);
- iIntent.putExtra(BR_TYPE_REALMETER_ELECT, DoubleArray[0]);
- iIntent.putExtra(BR_TYPE_REALMETER_GAS, DoubleArray[1]);
- iIntent.putExtra(BR_TYPE_REALMETER_WATER, DoubleArray[2]);
- iIntent.putExtra(BR_TYPE_REALMETER_HEATING, DoubleArray[3]);
- iIntent.putExtra(BR_TYPE_REALMETER_HOTWATER, DoubleArray[4]);
- context.sendBroadcast(iIntent);
-
- return true;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- return false;
- }
- }
- }
|