HomeAutomation_Etc.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package kr.co.icontrols.homeautomation;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.util.Log;
  5. public class HomeAutomation_Etc
  6. {
  7. private static final String TAG = "HomeAutomation_Etc";
  8. Context context;
  9. /** BR Action Name <br>
  10. * 본 Action Name을 BroadcastReceiver에 getAction 후 문자열 비교 등록 후 일치 시 사용해야 한다.
  11. * **/
  12. public static final String BR_HOME_AUTOMATION_ETC = "BR_HOME_AUTOMATION_ETC";
  13. public static final String BR_TYPE = "TYPE";
  14. public static final String BR_TYPE_PASSWORD = "TYPE_PASSWORD";
  15. public static final String BR_TYPE_REALMETER_YEAR = "TYPE_REALMETER_YEAR";
  16. public static final String BR_TYPE_REALMETER_MONTH = "TYPE_REALMETER_MONTH";
  17. public static final String BR_TYPE_REALMETER_ELECT = "TYPE_REALMETER_ELECT";
  18. public static final String BR_TYPE_REALMETER_GAS = "TYPE_REALMETER_GAS";
  19. public static final String BR_TYPE_REALMETER_WATER = "TYPE_REALMETER_WATER";
  20. public static final String BR_TYPE_REALMETER_HEATING = "TYPE_REALMETER_HEATING";
  21. public static final String BR_TYPE_REALMETER_HOTWATER = "TYPE_REALMETER_HOTWATER";
  22. public static final int TYPE_PASSWORD = 0;
  23. public static final int TYPE_REALMETER_REQUEST = 1;
  24. public static final int TYPE_REALMETER_REPLY = 2;
  25. /**
  26. * 생성자
  27. * **/
  28. public HomeAutomation_Etc(Context ctx)
  29. {
  30. context = ctx;
  31. Log.d(TAG, "HomeAutomation_Emergency API Start");
  32. }
  33. /**
  34. * @description
  35. * 비밀번호 br parsing 함수
  36. *
  37. * @return String Password (null인지 비교하고 사용)
  38. *
  39. * @param intent -> 수신 받은 intent 원형
  40. * **/
  41. public String BR_Parsing_Password(Intent intent)
  42. {
  43. String Password = intent.getStringExtra(BR_TYPE_PASSWORD);
  44. if(Password == null)
  45. {
  46. Log.e(TAG, "BR_Parsing - Password is error : ");
  47. return null;
  48. }
  49. return Password;
  50. }
  51. /**
  52. * @description
  53. * 원격검침 요청 br parsing 함수
  54. *
  55. * @return byte[4] -> 요청 날짜
  56. *
  57. * @param intent -> 수신 받은 intent 원형
  58. * **/
  59. public byte[] BR_Parsing_RealMeter_request(Intent intent)
  60. {
  61. byte[] RetByte = new byte[4];
  62. int Year = intent.getIntExtra(BR_TYPE_REALMETER_YEAR, -999);
  63. int Month = intent.getIntExtra(BR_TYPE_REALMETER_MONTH, -999);
  64. if(Year < 0)
  65. {
  66. Log.e(TAG, "BR_Parsing_RealMeter_request - Year : " + Year);
  67. return null;
  68. }
  69. if(Month < 0)
  70. {
  71. Log.e(TAG, "BR_Parsing_RealMeter_request - Month : " + Month);
  72. return null;
  73. }
  74. Year = Year - 2000;
  75. RetByte[0] = (byte) (Year / 10);
  76. RetByte[1] = (byte) (Year % 10);
  77. RetByte[2] = (byte) (Month / 10);
  78. RetByte[3] = (byte) (Month % 10);
  79. return RetByte;
  80. }
  81. /**
  82. * @description
  83. * 원격검침 응답 br parsing 함수
  84. *
  85. * @return flaot[5] -> 원격검침 데이터
  86. *
  87. * @param intent -> 수신 받은 intent 원형
  88. * **/
  89. public double[] BR_Parsing_RealMeter_reply(Intent intent)
  90. {
  91. double[] RetByte = new double[5];
  92. double elect = intent.getDoubleExtra(BR_TYPE_REALMETER_ELECT, -999);
  93. double gas = intent.getDoubleExtra(BR_TYPE_REALMETER_GAS, -999);
  94. double water = intent.getDoubleExtra(BR_TYPE_REALMETER_WATER, -999);
  95. double heating = intent.getDoubleExtra(BR_TYPE_REALMETER_HEATING, -999);
  96. double hotwater = intent.getDoubleExtra(BR_TYPE_REALMETER_HOTWATER, -999);
  97. if(elect < 0)
  98. {
  99. Log.e(TAG, "BR_Parsing_RealMeter_reply - elect : " + elect);
  100. return null;
  101. }
  102. if(gas < 0)
  103. {
  104. Log.e(TAG, "BR_Parsing_RealMeter_reply - gas : " + gas);
  105. return null;
  106. }
  107. if(water < 0)
  108. {
  109. Log.e(TAG, "BR_Parsing_RealMeter_reply - water : " + water);
  110. return null;
  111. }
  112. if(heating < 0)
  113. {
  114. Log.e(TAG, "BR_Parsing_RealMeter_reply - heating : " + heating);
  115. return null;
  116. }
  117. if(hotwater < 0)
  118. {
  119. Log.e(TAG, "BR_Parsing_RealMeter_reply - hotwater : " + hotwater);
  120. return null;
  121. }
  122. RetByte[0] = elect;
  123. RetByte[1] = gas;
  124. RetByte[2] = water;
  125. RetByte[3] = heating;
  126. RetByte[4] = hotwater;
  127. return RetByte;
  128. }
  129. /**
  130. * @description
  131. * 로비 출입 비밀번호 서비스로 전송
  132. *
  133. * @return boolean -> true(정상), false(송신 실패)
  134. *
  135. * @param Type - 연동할 종류
  136. * **/
  137. public boolean BR_Send_Password(String Password)
  138. {
  139. try
  140. {
  141. /** param check **/
  142. // 1. 비밀번호 입력 체크
  143. if(Password == null)
  144. {
  145. Log.e(TAG, "BR_Send - Password is null");
  146. return false;
  147. }
  148. if(Password.length() != 4)
  149. {
  150. Log.e(TAG, "BR_Send - Password length is error : " + Password);
  151. return false;
  152. }
  153. //2. Broadcast 전송
  154. Intent iIntent = new Intent();
  155. iIntent.setAction(BR_HOME_AUTOMATION_ETC);
  156. iIntent.putExtra(BR_TYPE, TYPE_PASSWORD);
  157. iIntent.putExtra(BR_TYPE_PASSWORD, Password);
  158. context.sendBroadcast(iIntent);
  159. return true;
  160. }
  161. catch(Exception e)
  162. {
  163. e.printStackTrace();
  164. return false;
  165. }
  166. }
  167. /**
  168. * @description
  169. * 원격검침 데이터 요청
  170. *
  171. * @return boolean -> true(정상), false(송신 실패)
  172. *
  173. * @param Year - 해당 연도
  174. * @param Month - 해당 월
  175. * **/
  176. public boolean BR_Send_RealMeterReqest(int Year, int Month)
  177. {
  178. try
  179. {
  180. /** param check **/
  181. // 1. 비밀번호 입력 체크
  182. if((Month < 1) || (Month > 12))
  183. {
  184. Log.e(TAG, "BR_Send_RealMeterReqest - Month : " + Month);
  185. return false;
  186. }
  187. //2. Broadcast 전송
  188. Intent iIntent = new Intent();
  189. iIntent.setAction(BR_HOME_AUTOMATION_ETC);
  190. iIntent.putExtra(BR_TYPE, TYPE_REALMETER_REQUEST);
  191. iIntent.putExtra(BR_TYPE_REALMETER_YEAR, Year);
  192. iIntent.putExtra(BR_TYPE_REALMETER_MONTH, Month);
  193. context.sendBroadcast(iIntent);
  194. return true;
  195. }
  196. catch(Exception e)
  197. {
  198. e.printStackTrace();
  199. return false;
  200. }
  201. }
  202. /**
  203. * @description
  204. * 원격검침 데이터 응답
  205. *
  206. * @return boolean -> true(정상), false(송신 실패)
  207. *
  208. * @param double[5] -> 검침 데이터
  209. * **/
  210. public boolean BR_Send_RealMeterReply(double[] DoubleArray)
  211. {
  212. try
  213. {
  214. /** param check **/
  215. // 1. 비밀번호 입력 체크
  216. if(DoubleArray == null)
  217. {
  218. return false;
  219. }
  220. if(DoubleArray.length != 5)
  221. {
  222. Log.e(TAG, "BR_Send_RealMeterReply - FloatArray.length : " + DoubleArray.length);
  223. return false;
  224. }
  225. //2. Broadcast 전송
  226. Intent iIntent = new Intent();
  227. iIntent.setAction(BR_HOME_AUTOMATION_ETC);
  228. iIntent.putExtra(BR_TYPE, TYPE_REALMETER_REPLY);
  229. iIntent.putExtra(BR_TYPE_REALMETER_ELECT, DoubleArray[0]);
  230. iIntent.putExtra(BR_TYPE_REALMETER_GAS, DoubleArray[1]);
  231. iIntent.putExtra(BR_TYPE_REALMETER_WATER, DoubleArray[2]);
  232. iIntent.putExtra(BR_TYPE_REALMETER_HEATING, DoubleArray[3]);
  233. iIntent.putExtra(BR_TYPE_REALMETER_HOTWATER, DoubleArray[4]);
  234. context.sendBroadcast(iIntent);
  235. return true;
  236. }
  237. catch(Exception e)
  238. {
  239. e.printStackTrace();
  240. return false;
  241. }
  242. }
  243. }