IGW300.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. package kr.co.icontrols.wallpadmain.util;
  2. import java.util.List;
  3. import kr.co.icontrols.gledeviceinterface.jni;
  4. import kr.co.icontrols.wallpadmain.declare.Common;
  5. import kr.co.icontrols.wallpadmain.declare.ID;
  6. import kr.co.icontrols.wallpadsupport.Version;
  7. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  8. import com.artncore.WallPadDataMgr.WallpadStatusData;
  9. import com.artncore.deviceinterface.WallPadInterface;
  10. import com.artncore.wallpadapi.DLockAPI;
  11. import com.artncore.wallpadapi.DLockAPI.DOORSTATUS;
  12. import com.artncore.wallpadapi.FP_DlockAPI;
  13. import com.artncore.wallpadapi.IGW200dAPI;
  14. import com.artncore.wallpadapi.IGW300API;
  15. import com.artncore.wallpadapi.WallPadAPI;
  16. import android.app.ActivityManager;
  17. import android.app.ActivityManager.RunningTaskInfo;
  18. import android.content.BroadcastReceiver;
  19. import android.content.ComponentName;
  20. import android.content.Context;
  21. import android.content.Intent;
  22. import android.content.IntentFilter;
  23. import android.os.Handler;
  24. import android.os.Message;
  25. import android.util.Log;
  26. import android.view.KeyEvent;
  27. import com.util.LogUtil;
  28. public class IGW300 {
  29. private Context mContext = null;
  30. private String TAG = "IGW300";
  31. private IGW300API mIGW300API = null;
  32. private WallPadAPI mWallPadAPI = null;
  33. private IGW300API.Data mIGW300API_Data = null;
  34. protected DLockAPI mDLockAPI = null;
  35. private DLockAPI doorLockAPI = null;
  36. private FP_DlockAPI FPdoorLockAPI = null;
  37. public IGW300(Context context , WallPadAPI wapi) {
  38. mContext = context;
  39. mWallPadAPI = wapi;
  40. initIGW300();
  41. registerIGW300InterfaceBR();
  42. getResidentSafetyCheckSetting();
  43. }
  44. public void registerIGW300InterfaceBR() {
  45. Log.i(TAG, "[registerIGW300InterfaceBR] ========== START ==========");
  46. IntentFilter filter = new IntentFilter();
  47. filter.addAction(Common.BR_IGW200FILTER );
  48. filter.addAction(Common.BR_EMER_LED_CONTROL );
  49. filter.addAction(IGW300API.SENSOR_BR_NAME);
  50. filter.addAction(Common.BR_CALLED_CID_ACK);
  51. mContext.registerReceiver(IGW300InterfaceBR, filter);
  52. Log.i(TAG, "[registerIGW300InterfaceBR] ========== END ==========");
  53. }
  54. private void checkSensor() {
  55. if (mIGW300API == null) return;
  56. if (mIGW300API_Data == null) return;
  57. if (Common.GetSensorSampleMode(mContext)) {
  58. // 영업샘플 모드 이면 처리하지 않도록 한다
  59. return;
  60. }
  61. WallpadStatusData mWallpadStatusData = new WallpadStatusData(mContext);
  62. int nAlarmMode = mWallpadStatusData.GetAlarmStatus();
  63. mWallpadStatusData.closeDB();
  64. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(mContext);
  65. int StatusValLadder = mWallpadDeviceSet.GetDeviceSetted("피난사다리");
  66. mWallpadDeviceSet.closeDB();
  67. Log.d(TAG , "[checkSensor] nAlarmMode = " + nAlarmMode);
  68. // 외출이나 재택모드 인 경우 동체와 마그네틱 센서를 감지하도록 한다
  69. // 재택모드인 경우 알람을 바로 발생시키도록 하고...
  70. if (nAlarmMode == WallpadStatusData.GUARD_OUT || nAlarmMode == WallpadStatusData.GUARD_IN) {
  71. Log.d(TAG , "[checkSensor] GUARD_OUT or GUARD_IN");
  72. // 동체
  73. if (mIGW300API_Data.senIn.In_Motion) {
  74. setSendEventBR(WallPadInterface.EVT_SENSOR_MOTIONIN);
  75. }
  76. if (mIGW300API_Data.senIn.Out_Motion) {
  77. setSendEventBR(WallPadInterface.EVT_SENSOR_MOTIONOUT);
  78. }
  79. // 마그네틱
  80. if (mIGW300API_Data.senIn.Magnetic) {
  81. setSendEventBR(WallPadInterface.EVT_SENSOR_MAGNETIC0);
  82. }
  83. }
  84. else {
  85. Log.d(TAG , "[checkSensor] nAlarmMode is not set!!!");
  86. // 정전화면 시험을 위한 임시 코드
  87. }
  88. // APU 감지가 되면 월패드 비상등을 켜도록 한다.
  89. if (mIGW300API_Data.senIn.APU) {
  90. // 월패드 비상등을 켠다. ( 상태를 저장하여 월패드의 화면에 비상등이 표시되면 동기화 시키도록 한다. 무드등으로 쓰는 경우)
  91. // 월패드에 비상등이 달려있지 않고 일체형 조명 제어기를 제어를 하기도 한다. 일체형 조명제어기의 비상전원이 공급되는 경우 ( 설정된 조명제어기를 켜고 끄도록 한다. )
  92. if (Version.getModelType() == Version.MODEL_TYPE.IHN_1020GL) {
  93. WallPadInterface mWallPadInterface = new WallPadInterface();
  94. mWallPadInterface.DoControl(WallPadInterface.IOCTL_MOOD_BACKLIGHT_SET, 255);
  95. }
  96. else if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_LX2
  97. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I
  98. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) {
  99. setSendEventBR(WallPadInterface.EVT_BLACKOUT_OCCURRED);
  100. }
  101. }
  102. else {
  103. // 월패드 비상등을 끈다.
  104. if (Version.getModelType() == Version.MODEL_TYPE.IHN_1020GL) {
  105. WallPadInterface mWallPadInterface = new WallPadInterface();
  106. mWallPadInterface.DoControl(WallPadInterface.IOCTL_MOOD_BACKLIGHT_SET, 0);
  107. }
  108. else if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_LX2
  109. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I
  110. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) {
  111. setSendEventBR(WallPadInterface.EVT_BLACKOUT_RELEASED);
  112. }
  113. }
  114. // 피난사다리 우리집
  115. if (StatusValLadder == WallpadDeviceSet.DEV_DATA_ENABLE) {
  116. if (mIGW300API_Data.senIn.EVAC_Home) {
  117. if (nAlarmMode != WallpadStatusData.ALARM_ARISE && nAlarmMode != WallpadStatusData.ALARM_STOP )
  118. sendLadderEmergencyBR("ladder_Open");
  119. }
  120. // 피난사다리 윗집 - 우리집과 윗집 피난사다리 구분하여 처리하도록한다.
  121. if (mIGW300API_Data.senIn.EVAC_UP) {
  122. if (nAlarmMode != WallpadStatusData.ALARM_ARISE && nAlarmMode != WallpadStatusData.ALARM_STOP )
  123. sendLadderEmergencyBR("upladder_Open");
  124. }
  125. }
  126. }
  127. private int setSendEventBR(int code) {
  128. try {
  129. KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, code);
  130. Intent intent = new Intent("EVENT_DEVICE_CONTROL", null);
  131. intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
  132. intent.putExtra("keycode", code);
  133. mContext.sendBroadcast(intent);
  134. } catch (RuntimeException re) {
  135. LogUtil.errorLogInfo("", TAG, re);
  136. return -100;
  137. }
  138. catch (Exception e) {
  139. Log.e(TAG, "[Exception] setSendEventBR(int code) code = " + code);
  140. //e.printStackTrace();
  141. LogUtil.errorLogInfo("", TAG, e);
  142. return -100;
  143. }
  144. return 0;
  145. }
  146. private void sendLadderEmergencyBR(String detailOption) {
  147. int base = 7000;
  148. int [] Menu_Id_List = { base+11, base+21 , base+31 , base+41};
  149. int Menu_Start_Option = 1;
  150. WallpadStatusData wdb = new WallpadStatusData(mContext);
  151. int AlarmStatus = wdb.GetAlarmStatus();
  152. wdb.closeDB();
  153. boolean MgrAppRun = false;
  154. final String packageNameMgr = "com.artncore.managersetting";
  155. MgrAppRun = getForegroundAPP().equals(packageNameMgr);
  156. if (MgrAppRun) return;
  157. if (AlarmStatus == WallpadStatusData.ALARM_ARISE || AlarmStatus == WallpadStatusData.ALARM_STOP) return;
  158. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(mContext);
  159. int StatusVal = mWallpadDeviceSet.GetDeviceSetted("피난사다리");
  160. String pentHo = mWallpadDeviceSet.getPentHouseHoEscapeLadder();
  161. mWallpadDeviceSet.closeDB();
  162. Log.d(TAG, "[sendLadderEmergencyBR] pentHo [" + pentHo + "]");
  163. if (StatusVal == WallpadDeviceSet.DEV_DATA_NONE || StatusVal == WallpadDeviceSet.DEV_DATA_ENABLE) {
  164. Common.SendAppFinishReqBR(mContext);
  165. Intent newintent = new Intent(Intent.ACTION_MAIN);
  166. newintent.putExtra("MENU_ID_LIST", Menu_Id_List); // KEY : MENU_ID_LIST
  167. newintent.putExtra("MENU_START_ID", Menu_Id_List[3]); // KEY : MENU_START_ID
  168. newintent.putExtra("MENU_START_OPTION", Menu_Start_Option); // KEY : MENU_START_OPTION
  169. newintent.putExtra("MENU_DETAIL_INFO", detailOption);
  170. newintent.setComponent(new ComponentName("kr.co.icontrols.wallpademergency", "kr.co.icontrols.wallpademergency.MainActivity"));
  171. newintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  172. mContext.startActivity(newintent);
  173. }
  174. }
  175. protected String getForegroundAPP() {
  176. try {
  177. ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
  178. List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
  179. ComponentName topActivity=taskInfo.get(0).topActivity;
  180. String str=topActivity.getPackageName();
  181. return str;
  182. } catch (RuntimeException re) {
  183. LogUtil.errorLogInfo("", TAG, re);
  184. return " ";
  185. }
  186. catch (Exception e) {
  187. //e.printStackTrace();
  188. LogUtil.errorLogInfo("", TAG, e);
  189. return " ";
  190. }
  191. }
  192. private WallPadEmerButton mWallPadEmerButton = null;
  193. private boolean bMuticall_Front_Accept = false;
  194. private boolean bMulticall_PSTN_Accept = false;
  195. private boolean bPSTN_Connected = false;
  196. private boolean bMulticall_PSTN_Hold = false;
  197. private boolean bSubphone_Connected = false;
  198. BroadcastReceiver IGW300InterfaceBR = new BroadcastReceiver() {
  199. private boolean bFirst = true;
  200. @Override
  201. public void onReceive(Context context, Intent intent) {
  202. Log.i(TAG, "[IGW300InterfaceBR] intent [" + intent + "]");
  203. String strActionName = intent.getAction();
  204. if (strActionName.equals(IGW300API.SENSOR_BR_NAME)) {
  205. updateDeviceStatus(false);
  206. checkSensor();
  207. }
  208. else if (strActionName.equals(Common.BR_CALLED_CID_ACK)) {
  209. Log.d( TAG , "[IGW300InterfaceBR] BR_CALLED_CID_ACK");
  210. }
  211. else if (strActionName.equals(Common.BR_IGW200FILTER)) {
  212. int kind = intent.getIntExtra("KIND",0);
  213. Log.i(TAG, "[IGW300InterfaceBR] strActionName : " + Common.BR_IGW200FILTER + ", kind : " + kind);
  214. switch (kind) {
  215. case Common.IGW200_DOOR_MONITERING :
  216. ctrlDeviceIO(IGW200dAPI.OUTPUT.VIDEO_SEL, false);
  217. ctrlDeviceIO(IGW200dAPI.OUTPUT.DOOR_POWER, true);
  218. break;
  219. case Common.IGW200_DOOR_CONNECT:
  220. bMuticall_Front_Accept = false;
  221. bSubphone_Connected = false;
  222. ctrlDeviceIO(IGW200dAPI.OUTPUT.BELL_CONT, false);
  223. changeCallPath(IGW200dAPI.TEL_PATH.WPAD_DOOR);
  224. break;
  225. case Common.IGW200_DOOR_SUBPHONE_CONNECT:
  226. bMuticall_Front_Accept = false;
  227. bSubphone_Connected = true;
  228. ctrlDeviceIO(IGW200dAPI.OUTPUT.BELL_CONT, false);
  229. changeCallPath(IGW200dAPI.TEL_PATH.SUB_DOOR);
  230. break;
  231. case Common.IGW200_DOOR_CLOSE:
  232. if (!bMuticall_Front_Accept) {
  233. if (!bPSTN_Connected) {
  234. changeCallPath(IGW200dAPI.TEL_PATH.OFF);
  235. }
  236. ctrlDeviceIO(IGW200dAPI.OUTPUT.DOOR_POWER, false);
  237. ctrlDeviceIO(IGW200dAPI.OUTPUT.BELL_CONT, false);
  238. }
  239. bSubphone_Connected = false;
  240. break;
  241. case Common.IGW200_PSTN_CONNECT:
  242. bPSTN_Connected = true;
  243. bMulticall_PSTN_Hold = false;
  244. bSubphone_Connected = false;
  245. changeCallPath(IGW200dAPI.TEL_PATH.WPAD_TEL);
  246. break;
  247. case Common.IGW200_PSTN_CLOSE:
  248. Log.d( TAG , "[IGW300InterfaceBR] IGW300_PSTN_CLOSE, bMulticall_PSTN_Hold : " + bMulticall_PSTN_Hold);
  249. if (!bMulticall_PSTN_Hold) {
  250. bPSTN_Connected = false;
  251. changeCallPath(IGW200dAPI.TEL_PATH.OFF);
  252. }
  253. else {
  254. bMulticall_PSTN_Hold = false;
  255. }
  256. bSubphone_Connected = false;
  257. break;
  258. case Common.IGW200_MOIP_SUBPHONE_CONNECT:
  259. bSubphone_Connected = true;
  260. changeCallPath(IGW200dAPI.TEL_PATH.MOIP_SUB);
  261. break;
  262. case Common.IGW200_MOIP_CLOSE:
  263. bSubphone_Connected = false;
  264. changeCallPath(IGW200dAPI.TEL_PATH.OFF);
  265. ctrlDeviceIO(IGW200dAPI.OUTPUT.VIDEO_SEL, false);
  266. break;
  267. case Common.IGW200_VIDEO_FRONT:
  268. if (!bSubphone_Connected)
  269. ctrlDeviceIO(IGW200dAPI.OUTPUT.VIDEO_SEL, false);
  270. break;
  271. case Common.IGW200_VIDEO_LOBBY:
  272. if (!bSubphone_Connected)
  273. ctrlDeviceIO(IGW200dAPI.OUTPUT.VIDEO_SEL, true);
  274. break;
  275. case Common.MULTICALL_DOOR_ACCEPT :
  276. bMuticall_Front_Accept = true;
  277. if (bPSTN_Connected) {
  278. changeCallPath(IGW200dAPI.TEL_PATH.OFF);
  279. bPSTN_Connected = false;
  280. }
  281. break;
  282. case Common.MULTICALL_PSTN_ACCEPT :
  283. bMulticall_PSTN_Accept = true;
  284. break;
  285. case Common.MULTICALL_HOLD_DOOR_ACCEPT:
  286. bMuticall_Front_Accept = true;
  287. bMulticall_PSTN_Hold = true;
  288. break;
  289. // case Common.IGW200_EMER_ACK:
  290. // mIGW300API.BathEmerAckRelase();
  291. // mSensorCheckHandler.sendEmptyMessageDelayed(0, 5000);
  292. // break;
  293. case Common.IGW200_SENSOR_CHECK:
  294. Log.d(TAG, "[IGW300InterfaceBR] Common.IGW200_SENSOR_CHECK " );
  295. mSensorCheckHandler.sendEmptyMessageDelayed(0, 500);
  296. mSensorCheckHandler.sendEmptyMessageDelayed(1, 600);
  297. break;
  298. }
  299. }
  300. else if (strActionName.equals(Common.BR_EMER_LED_CONTROL)) {
  301. int kind = intent.getIntExtra("KIND",0);
  302. Log.d( TAG , "[IGW300InterfaceBR] Common.BR_EMER_LED_CONTROL, kind : " + kind);
  303. if (kind == 1) {
  304. if (mWallPadEmerButton == null) {
  305. mWallPadEmerButton = new WallPadEmerButton();
  306. mWallPadEmerButton.start();
  307. }
  308. }
  309. else {
  310. if (mWallPadEmerButton != null) {
  311. mWallPadEmerButton.Exit();
  312. try{Thread.sleep(100);}
  313. catch (RuntimeException re) {
  314. LogUtil.errorLogInfo("", TAG, re);
  315. }
  316. catch (Exception e){
  317. LogUtil.errorLogInfo("", TAG, e);
  318. }
  319. mWallPadEmerButton = null;
  320. }
  321. }
  322. }
  323. }
  324. };
  325. private void initIGW300() {
  326. mIGW300API = mWallPadAPI.Get_IGW300Controller();
  327. mDLockAPI = mWallPadAPI.Get_DLockController();
  328. doorLockAPI = mWallPadAPI.Get_DLockController();
  329. FPdoorLockAPI = mWallPadAPI.Get_FP_DLockController();
  330. if (mIGW300API == null) {
  331. Common.DebugLog("mIGW300API == null");
  332. }
  333. }
  334. public int ctrlDeviceIO(byte kind, boolean OnOff) {
  335. try {
  336. //DebugLogOutput("[ctrlDeviceIO] - Start (" + kind + ", " + OnOff + ")");
  337. Log.d(TAG, "[ctrlDeviceIO] kind :" + kind + " , OnOff :" + OnOff );
  338. if (mIGW300API == null) {
  339. Log.e(TAG, "[ctrlDeviceIO] - mIGW300API unload !!!");
  340. return -1;
  341. }
  342. int ret = mIGW300API.ControlOutput(kind, OnOff);
  343. if (ret < 0) {
  344. Log.e(TAG, "[ctrlDeviceIO] - mIGW300API.ControlOutput() ret = " + ret + " / ErrorCode = " + mIGW300API.ErrorCode.ErrStr());
  345. return -2;
  346. }
  347. } catch (RuntimeException re) {
  348. LogUtil.errorLogInfo("", TAG, re);
  349. return -102;
  350. }catch(Exception e) {
  351. Log.e(TAG, "[ctrlDeviceIO] - [Exception Error] mIGW300API.ControlOutput()");
  352. Log.e(TAG, "[ctrlDeviceIO] - " + e.toString());
  353. //e.printStackTrace();
  354. LogUtil.errorLogInfo("", TAG, e);
  355. return -102;
  356. }
  357. //DebugLogOutput("[ctrlDeviceIO] - OK");
  358. return 0;
  359. }
  360. /**
  361. * 통화체널 설정을 변경한다.
  362. *
  363. * @param ChangePath - (int) 변경할 체널패스 ( {@link IGW200dAPI.TEL_PATH} )
  364. * @return (int) - >=0 : 성공, <0 : 실패
  365. */
  366. public int changeCallPath(byte ChangePath) {
  367. try {
  368. if (mIGW300API == null) {
  369. Log.e(TAG, "[changeCallPath] - mIGW200dAPI unload !!!");
  370. return -1;
  371. }
  372. try {
  373. Log.e(TAG, "[changeCallPath] - -----------------1------ !!!");
  374. int ret = mIGW300API.ControlTelPath(ChangePath);
  375. if (ret < 0) {
  376. Log.e(TAG, "[changeCallPath] - mIGW300API.ControlTelPath(" + ChangePath + ") ret = " + ret + " / ErrorCode = " + mIGW300API.ErrorCode.ErrStr());
  377. return -2;
  378. }
  379. } catch (RuntimeException re) {
  380. LogUtil.errorLogInfo("", TAG, re);
  381. return -102;
  382. }catch(Exception e) {
  383. Log.e(TAG, "[changeCallPath] - [Exception Error] mIGW300API.ControlTelPath()");
  384. Log.e(TAG, "[changeCallPath] - " + e.toString());
  385. //e.printStackTrace();
  386. LogUtil.errorLogInfo("", TAG, e);
  387. return -102;
  388. }
  389. } catch (RuntimeException re) {
  390. LogUtil.errorLogInfo("", TAG, re);
  391. }
  392. catch (Exception e) {
  393. Log.e(TAG, "[changeCallPath] - " + e.toString());
  394. //e.printStackTrace();
  395. LogUtil.errorLogInfo("", TAG, e);
  396. }
  397. return 0;
  398. }
  399. /**
  400. * 제어기 상태를 가져온다.
  401. *
  402. * @param real - (boolean) true : 실시간 , false : 가장최근
  403. * @return (int) - >=0 : 성공, <0 : 실패
  404. */
  405. private int updateDeviceStatus(boolean real) {
  406. // 1. Api Load Check
  407. if (mIGW300API == null) {
  408. Log.e(TAG, "[updateDeviceStatus] - mIGW200dAPI unload !!!");
  409. return -1;
  410. }
  411. // 2. Reflash
  412. try {
  413. int ret = mIGW300API.Refresh(real);
  414. if (ret < 0) {
  415. Log.e(TAG, "[updateDeviceStatus] getState - ret (" + ret + ") ErrorCode = " + mIGW300API.ErrorCode.ErrStr());
  416. return -2;
  417. }
  418. } catch (RuntimeException re) {
  419. LogUtil.errorLogInfo("", TAG, re);
  420. return -102;
  421. }catch(Exception e) {
  422. Log.e(TAG, "[updateDeviceStatus] - [Exception Error] mIGW300API.Refresh(" + real + ")");
  423. Log.e(TAG, "[updateDeviceStatus] - " + e.toString());
  424. //e.printStackTrace();
  425. LogUtil.errorLogInfo("", TAG, e);
  426. return -102;
  427. }
  428. // 3. EMData Copy
  429. mIGW300API_Data = mIGW300API.data;
  430. // 4. Debug msg
  431. Common.DebugLog("---------------------------------------");
  432. Common.DebugLog("[updateDeviceStatus]");
  433. Common.DebugLog("---------------------------------------");
  434. Common.DebugLog("[senIn]");
  435. Common.DebugLog("In_Motion : " + mIGW300API_Data.senIn.In_Motion);
  436. Common.DebugLog("Out_Motion : " + mIGW300API_Data.senIn.Out_Motion);
  437. Common.DebugLog("Magnetic : " + mIGW300API_Data.senIn.Magnetic);
  438. Common.DebugLog("APU : " + mIGW300API_Data.senIn.APU);
  439. Common.DebugLog("EVAC_Home : " + mIGW300API_Data.senIn.EVAC_Home);
  440. Common.DebugLog("EVAC_UP : " + mIGW300API_Data.senIn.EVAC_UP);
  441. Common.DebugLog("---------------------------------------");
  442. Common.DebugLog("[updateDeviceStatus] - OK");
  443. // // 테스트 코드
  444. // if( mIGW200dAPI_Data.senIn.Magnetic == true )
  445. // {
  446. // callEmerAPK( mContext , ID_OLD.SubEmergency.BREAKIN_ALARM , 1 , "IO_Margnetic");
  447. // }
  448. if (nResidentSafetyCheckSetting == WallpadDeviceSet.RESIDENT_SAFETY_CHECK_ENABLE) {
  449. if (mIGW300API_Data.senIn.Magnetic) sendDoorOpenBR();
  450. }
  451. return 0;
  452. }
  453. /**
  454. * Device_BathEmerAckRelase
  455. *
  456. * @return (int) - >=0 : 성공, <0 : 실패
  457. */
  458. // private int Device_BathEmerAckRelase() {
  459. // if (mIGW300API == null) {
  460. // Log.e(TAG, "[Device_BathEmerAckRelase] - mIGW200dAPI unload !!!");
  461. // return -1;
  462. // }
  463. //
  464. // try {
  465. // int ret = mIGW300API.BathEmerAckRelase();
  466. // if (ret < 0) {
  467. // Log.e(TAG, "[Device_BathEmerAckRelase] - mIGW200dAPI.BathEmerAckRelase() ret = " + ret + " / ErrorCode = " + mIGW300API.ErrorCode.ErrStr());
  468. // return -2;
  469. // }
  470. // } catch (RuntimeException re) {
  471. // LogUtil.errorLogInfo("", TAG, re);
  472. // }
  473. // catch (Exception e) {
  474. // Log.e(TAG, "[Device_BathEmerAckRelase] - [Exception Error] mIGW200dAPI.BathEmerAckRelase()");
  475. // Log.e(TAG, "[Device_BathEmerAckRelase] - " + e.toString());
  476. // e.printStackTrace();
  477. // return -102;
  478. // }
  479. // return 0;
  480. // }
  481. // input param
  482. // int nScreen 알람 종류
  483. // int startOption // 발생이냐 1 , 정지냐 2
  484. // int detailOption // 상세 알람 내역
  485. private void callEmerAPK(Context context, int nScreenID , int startOption, String detailInfo ) {
  486. try {
  487. // DB 체크 해서 띄우 도록 한다.
  488. int [] m_EmerMenuList = new int[4];
  489. m_EmerMenuList[0] = ID.LINKEDSCREEN.SubEmergency.EMER_ALARM;
  490. m_EmerMenuList[1] = ID.LINKEDSCREEN.SubEmergency.FIRE_ALARM;
  491. m_EmerMenuList[2] = ID.LINKEDSCREEN.SubEmergency.BREAKIN_ALARM;
  492. m_EmerMenuList[3] = ID.LINKEDSCREEN.SubEmergency.LADDER_ALARM;
  493. Intent intent = new Intent(Intent.ACTION_MAIN);
  494. intent.putExtra(Common.MENU_ID_LIST, m_EmerMenuList); // KEY : MENU_ID_LIST
  495. intent.putExtra(Common.MENU_START_ID, nScreenID); // KEY : MENU_START_ID
  496. intent.putExtra(Common.MENU_START_OPTION, startOption); // KEY : MENU_START_OPTION
  497. intent.putExtra(Common.MENU_DETAIL_INFO, detailInfo);
  498. intent.setComponent(new ComponentName(Common.EMER_ALARM_APK, Common.EMER_ALARM_APK + Common.MAIN_ACTIVITY ));
  499. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  500. context.startActivity(intent);
  501. } catch (RuntimeException re) {
  502. LogUtil.errorLogInfo("", TAG, re);
  503. }
  504. catch (Exception e) {
  505. Log.e(TAG, e.toString());
  506. //e.printStackTrace();
  507. LogUtil.errorLogInfo("", TAG, e);
  508. }
  509. }
  510. // 비상 발생시 월패드 비상버튼 점멸 처리 쓰레드
  511. //
  512. class WallPadEmerButton extends Thread {
  513. private jni mGleInterface = null;
  514. private boolean m_LedOn = false;
  515. private boolean m_ThreadExit = false;
  516. public WallPadEmerButton() {
  517. try { mGleInterface = new jni(); }
  518. catch (RuntimeException re) {
  519. LogUtil.errorLogInfo("", TAG, re);
  520. }
  521. catch (Exception e) {
  522. Log.e("Exception", "[ExceptionError] - onCreate->mGleInterface Create : " + e);
  523. }
  524. }
  525. public void run() {
  526. try {
  527. Common.DebugLog("WallPadEmerButton------ Thread Run");
  528. do {
  529. if (mGleInterface != null) {
  530. if (m_LedOn == false) {
  531. mGleInterface.setEmerLedOnOff(true);
  532. m_LedOn = true;
  533. }
  534. else {
  535. mGleInterface.setEmerLedOnOff(false);
  536. m_LedOn = false;
  537. }
  538. }
  539. for (int i = 0 ; i < 10 ; i++) {
  540. try{Thread.sleep(50);}
  541. catch (RuntimeException re) {
  542. LogUtil.errorLogInfo("", TAG, re);
  543. }
  544. catch (Exception e){
  545. LogUtil.errorLogInfo("", TAG, e);
  546. }
  547. if (m_ThreadExit && mGleInterface!=null) {
  548. mGleInterface.setEmerLedOnOff(false);
  549. return;
  550. }
  551. }
  552. }
  553. while (true);
  554. } catch (RuntimeException re) {
  555. LogUtil.errorLogInfo("", TAG, re);
  556. return;
  557. }
  558. catch (Exception e) {
  559. //e.printStackTrace();
  560. LogUtil.errorLogInfo("", TAG, e);
  561. e.getStackTrace();
  562. return;
  563. }
  564. }
  565. private void Exit()
  566. {
  567. m_ThreadExit = true;
  568. }
  569. }
  570. public boolean checkSensorforOutmode() {
  571. updateDeviceStatus(true);
  572. IGW300API.Data mData = mIGW300API.data;
  573. boolean bInMotionSensor = mData.senIn.In_Motion;
  574. boolean bOutMotionSensor = mData.senIn.Out_Motion;
  575. boolean bMagneticSensor = mData.senIn.Magnetic;
  576. Log.d(TAG, "[checkSensorforOutmode] bInMotionSensor [" + bInMotionSensor + "], bOutMotionSensor [" + bOutMotionSensor + "], bMagneticSensor [" + bMagneticSensor + "]");
  577. // 도어락 상태 추가 체크
  578. byte DoorLockState = DOORSTATUS.Close ;
  579. try
  580. {
  581. WallpadDeviceSet devSet = new WallpadDeviceSet(mContext);
  582. String[] GetValue = devSet.GetSettingData("디지털도어락");
  583. devSet.closeDB();
  584. if (GetValue == null)
  585. {
  586. Log.e("Common", "GetSettingData(디지털도어락) is null");
  587. return false;
  588. }
  589. Log.d("Common", "GetSettingData(디지털도어락) is value : " + GetValue[1]);
  590. if( GetValue[1].indexOf("유선") > 0 )
  591. {
  592. Log.d("Common", "Normal Line Doorlock");
  593. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  594. {
  595. doorLockAPI = mWallPadAPI.Get_DLockController();
  596. doorLockAPI.Refresh(true);
  597. DoorLockState = doorLockAPI.data.DoorStatus;
  598. Log.d(TAG, "Normal Line DoorLock State : ==> " + DoorLockState );
  599. }
  600. }
  601. else if(GetValue[1].indexOf("지문인식") > 0)
  602. {
  603. //FPdoorLockAPI
  604. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  605. {
  606. FPdoorLockAPI = mWallPadAPI.Get_FP_DLockController();
  607. FPdoorLockAPI.Refresh(true);
  608. DoorLockState = FPdoorLockAPI.data.DoorStatus;
  609. Log.d(TAG, "FingerPrint DoorLock State : ==> " + DoorLockState );
  610. }
  611. }
  612. }
  613. catch (RuntimeException re) {
  614. LogUtil.errorLogInfo("", TAG, re);
  615. }
  616. catch (Exception e)
  617. {
  618. //e.printStackTrace();
  619. LogUtil.errorLogInfo("", TAG, e);
  620. }
  621. // 현산향이 무선 도어락이 들어가면서 추가되어야 함
  622. if (Common.isWirelessDoorlock(mContext)) {
  623. DoorLockState = DOORSTATUS.Close;
  624. }
  625. int[] SensorInfoDB;
  626. SensorInfoDB = Common.GetInSensorUseOfNotFromDB(mContext); // 동체감지기 사용여부 확인
  627. Log.w(TAG, "[checkSensorforOutmode] SensorInfoDB.length = " + SensorInfoDB.length);
  628. if (SensorInfoDB[0] == 0) {
  629. // 내부동체가 사용함이면 상태 검사
  630. bInMotionSensor = false;
  631. }
  632. if (SensorInfoDB[1] == 0) {
  633. // 외부동체가 사용함이면 상태 검사
  634. bOutMotionSensor = false;
  635. }
  636. if (bInMotionSensor == false && bOutMotionSensor == false && bMagneticSensor == false && DoorLockState == DOORSTATUS.Close) {
  637. return true;
  638. }
  639. return false;
  640. }
  641. public boolean checkSensorforInmode() {
  642. updateDeviceStatus(true);
  643. IGW300API.Data mData = mIGW300API.data;
  644. boolean bMagneticSensor = mData.senIn.Magnetic;
  645. Log.d(TAG, "[checkSensorforInmode] bMagneticSensor [" + bMagneticSensor + "]");
  646. // 도어락 상태 추가 체크
  647. byte DoorLockState = DOORSTATUS.Close ;
  648. /*try {
  649. if (mWallPadAPI != null && mWallPadAPI.Check_Connect()) {
  650. mDLockAPI = mWallPadAPI.Get_DLockController();
  651. mDLockAPI.Refresh(true);
  652. DoorLockState = mDLockAPI.data.DoorStatus;
  653. Log.d(TAG, "[checkSensorforInmode] DoorLockState [" + DoorLockState + "]");
  654. }
  655. } catch (RuntimeException re) {
  656. LogUtil.errorLogInfo("", TAG, re);
  657. }
  658. catch (Exception e) {
  659. e.printStackTrace();
  660. }*/
  661. try
  662. {
  663. WallpadDeviceSet devSet = new WallpadDeviceSet(mContext);
  664. String[] GetValue = devSet.GetSettingData("디지털도어락");
  665. devSet.closeDB();
  666. if (GetValue == null)
  667. {
  668. Log.e("Common", "GetSettingData(디지털도어락) is null");
  669. return false;
  670. }
  671. Log.d("Common", "GetSettingData(디지털도어락) is value : " + GetValue[1]);
  672. if( GetValue[1].indexOf("유선") > 0 )
  673. {
  674. Log.d("Common", "Normal Line Doorlock");
  675. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  676. {
  677. doorLockAPI = mWallPadAPI.Get_DLockController();
  678. doorLockAPI.Refresh(true);
  679. DoorLockState = doorLockAPI.data.DoorStatus;
  680. Log.d(TAG, "Normal Line DoorLock State : ==> " + DoorLockState );
  681. }
  682. }
  683. else if(GetValue[1].indexOf("지문인식") > 0)
  684. {
  685. //FPdoorLockAPI
  686. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  687. {
  688. FPdoorLockAPI = mWallPadAPI.Get_FP_DLockController();
  689. FPdoorLockAPI.Refresh(true);
  690. DoorLockState = FPdoorLockAPI.data.DoorStatus;
  691. Log.d(TAG, "FingerPrint DoorLock State : ==> " + DoorLockState );
  692. }
  693. }
  694. }
  695. catch (RuntimeException re) {
  696. LogUtil.errorLogInfo("", TAG, re);
  697. }
  698. catch (Exception e)
  699. {
  700. //e.printStackTrace();
  701. LogUtil.errorLogInfo("", TAG, e);
  702. }
  703. // 현산향이 무선 도어락이 들어가면서 추가되어야 함
  704. if (Common.isWirelessDoorlock(mContext)) {
  705. DoorLockState = DOORSTATUS.Close;
  706. }
  707. if (bMagneticSensor == false && DoorLockState == DOORSTATUS.Close) {
  708. return true;
  709. }
  710. return false;
  711. }
  712. private Handler mSensorCheckHandler = new Handler()
  713. {
  714. @Override
  715. public void handleMessage(Message msg)
  716. {
  717. if (msg.what == 0) {
  718. Log.d(TAG, "[mSensorCheckHandler] ");
  719. //얻어오기
  720. checkSensor();
  721. }
  722. else if (msg.what == 1) {
  723. checkGLEDoorlock();
  724. }
  725. }
  726. };
  727. private boolean checkGLEDoorlock() {
  728. byte DoorLockState = DOORSTATUS.Close ;
  729. Log.d(TAG, "[checkGLEDoorlock] ========== START ==========" );
  730. // 현산향이 무선 도어락이 들어가면서 추가되어야 함
  731. if (Common.isWirelessDoorlock(mContext)) {
  732. return true;
  733. }
  734. /*try {
  735. if (mWallPadAPI != null && mWallPadAPI.Check_Connect()) {
  736. mDLockAPI = mWallPadAPI.Get_DLockController();
  737. mDLockAPI.Refresh(true);
  738. DoorLockState = mDLockAPI.data.DoorStatus;
  739. Log.d(TAG, "[checkGLEDoorlock] DoorLockState [" + DoorLockState + "]");
  740. if (DoorLockState != DOORSTATUS.Close) {
  741. setSendEventBR(WallPadInterface.EVT_MAG0);
  742. return true;
  743. }
  744. }
  745. } catch (RuntimeException re) {
  746. LogUtil.errorLogInfo("", TAG, re);
  747. }
  748. catch (Exception e) {
  749. e.printStackTrace();
  750. }*/
  751. try
  752. {
  753. WallpadDeviceSet devSet = new WallpadDeviceSet(mContext);
  754. String[] GetValue = devSet.GetSettingData("디지털도어락");
  755. devSet.closeDB();
  756. if (GetValue == null)
  757. {
  758. Log.e("Common", "GetSettingData(디지털도어락) is null");
  759. return false;
  760. }
  761. Log.d("Common", "GetSettingData(디지털도어락) is value : " + GetValue[1]);
  762. if( GetValue[1].indexOf("유선") > 0 )
  763. {
  764. Log.d("Common", "Normal Line Doorlock");
  765. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  766. {
  767. doorLockAPI = mWallPadAPI.Get_DLockController();
  768. doorLockAPI.Refresh(true);
  769. DoorLockState = doorLockAPI.data.DoorStatus;
  770. Log.d(TAG, "[checkGLEDoorlock] DoorLockState [" + DoorLockState + "]");
  771. if (DoorLockState != DOORSTATUS.Close) {
  772. setSendEventBR(WallPadInterface.EVT_SENSOR_MAGNETIC0);
  773. return true;
  774. }
  775. }
  776. }
  777. else if(GetValue[1].indexOf("지문인식") > 0)
  778. {
  779. //FPdoorLockAPI
  780. if (mWallPadAPI != null && mWallPadAPI.Check_Connect())
  781. {
  782. FPdoorLockAPI = mWallPadAPI.Get_FP_DLockController();
  783. FPdoorLockAPI.Refresh(true);
  784. DoorLockState = FPdoorLockAPI.data.DoorStatus;
  785. Log.d(TAG, "[checkGLEDoorlock] DoorLockState [" + DoorLockState + "]");
  786. if (DoorLockState != DOORSTATUS.Close) {
  787. setSendEventBR(WallPadInterface.EVT_SENSOR_MAGNETIC0);
  788. return true;
  789. }
  790. }
  791. }
  792. }
  793. catch (RuntimeException re) {
  794. LogUtil.errorLogInfo("", TAG, re);
  795. }
  796. catch (Exception e)
  797. {
  798. //e.printStackTrace();
  799. LogUtil.errorLogInfo("", TAG, e);
  800. }
  801. return false;
  802. }
  803. public static int nResidentSafetyCheckSetting = WallpadDeviceSet.RESIDENT_SAFETY_CHECK_DISABLE;
  804. private void getResidentSafetyCheckSetting() {
  805. try {
  806. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(mContext);
  807. nResidentSafetyCheckSetting = mWallpadDeviceSet.getResidentSafetyCheck();
  808. mWallpadDeviceSet.closeDB();
  809. Log.e(TAG, "[getResidentSafetyCheckSetting] nResidentSafetyCheckSetting: " + nResidentSafetyCheckSetting);
  810. } catch (RuntimeException re) {
  811. LogUtil.errorLogInfo("", TAG, re);
  812. } catch (Exception e) {
  813. Log.e(TAG, "[Exception] getResidentSafetyCheckSetting()");
  814. //e.printStackTrace();
  815. LogUtil.errorLogInfo("", TAG, e);
  816. }
  817. }
  818. public void sendDoorOpenBR() {
  819. try {
  820. Intent mIntent = new Intent();
  821. mIntent.setAction(Version.NOTIFY_ACNAME_RESIDENT_SAFETY_CHECK);
  822. mIntent.putExtra(Version.NOTIBR_KIND, Version.NOTIFY_DOOR_OPENED);
  823. mContext.sendBroadcast(mIntent);
  824. } catch (RuntimeException re) {
  825. kr.co.icontrols.wallpadsupport.LogUtil.errorLogInfo("", TAG, re);
  826. } catch (Exception e) {
  827. Log.e(TAG, "[Exception] sendDoorOpenBR()");
  828. //e.printStackTrace();
  829. kr.co.icontrols.wallpadsupport.LogUtil.errorLogInfo("", TAG, e);
  830. }
  831. }
  832. }