V40IF.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. package kr.co.icontrols.v40ioctl;
  2. import android.os.Build;
  3. import android.util.Log;
  4. import com.util.LogUtil;
  5. import kr.co.icontrols.wallpadsupport.Version;
  6. public class V40IF {
  7. String TAG = "V40IF";
  8. boolean bLOG = true;
  9. private void LOG(String log) {
  10. if (bLOG) Log.v(TAG, log);
  11. }
  12. boolean bLOG_DEBUG = false;
  13. private void LOG_DEBUG(String log) {
  14. if (bLOG_DEBUG) Log.d(TAG, log);
  15. }
  16. boolean bLOG_INFO = true;
  17. private void LOG_INFO(String log) {
  18. if (bLOG_INFO) Log.i(TAG, log);
  19. }
  20. private V40IOInterface mV40IOIF = null;
  21. private V40IOInterface2 mV40IOIF_NOUGAT = null;
  22. public V40IF() {
  23. try {
  24. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT = new V40IOInterface2();
  25. else mV40IOIF = new V40IOInterface();
  26. } catch (RuntimeException re) {
  27. LogUtil.errorLogInfo("", TAG, re);
  28. } catch (Exception e) {
  29. Log.e(TAG, "[Exception] V40IF()");
  30. //e.printStackTrace();
  31. LogUtil.errorLogInfo("", TAG, e);
  32. }
  33. }
  34. public int WpdInterfaceOpen() {
  35. try {
  36. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceOpen();
  37. else return mV40IOIF.WpdInterfaceOpen();
  38. } catch (RuntimeException re) {
  39. LogUtil.errorLogInfo("", TAG, re);
  40. return -99;
  41. } catch (Exception e) {
  42. Log.e(TAG, "[Exception] WpdInterfaceOpen()");
  43. //e.printStackTrace();
  44. LogUtil.errorLogInfo("", TAG, e);
  45. return -99;
  46. }
  47. }
  48. public int WpdInterfaceClose() {
  49. try {
  50. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceClose();
  51. else return mV40IOIF.WpdInterfaceClose();
  52. } catch (RuntimeException re) {
  53. LogUtil.errorLogInfo("", TAG, re);
  54. return -99;
  55. } catch (Exception e) {
  56. Log.e(TAG, "[Exception] WpdInterfaceClose()");
  57. //e.printStackTrace();
  58. LogUtil.errorLogInfo("", TAG, e);
  59. return -99;
  60. }
  61. }
  62. public int WpdInterfaceControl(int cmd, int arg) {
  63. try {
  64. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceControl(cmd, arg);
  65. else return mV40IOIF.WpdInterfaceControl(cmd, arg);
  66. } catch (RuntimeException re) {
  67. LogUtil.errorLogInfo("", TAG, re);
  68. return -99;
  69. } catch (Exception e) {
  70. Log.e(TAG, "[Exception] WpdInterfaceControl(int cmd, int arg)");
  71. //e.printStackTrace();
  72. LogUtil.errorLogInfo("", TAG, e);
  73. return -99;
  74. }
  75. }
  76. public void SetMacAddr(String mac) {
  77. try {
  78. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.SetMacAddr(mac);
  79. else mV40IOIF.SetMacAddr(mac);
  80. } catch (RuntimeException re) {
  81. LogUtil.errorLogInfo("", TAG, re);
  82. } catch (Exception e) {
  83. Log.e(TAG, "[Exception] SetMacAddr(String mac)");
  84. //e.printStackTrace();
  85. LogUtil.errorLogInfo("", TAG, e);
  86. }
  87. }
  88. public void IpAddr(String ip) {
  89. try {
  90. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.IpAddr(ip);
  91. else mV40IOIF.IpAddr(ip);
  92. } catch (RuntimeException re) {
  93. LogUtil.errorLogInfo("", TAG, re);
  94. } catch (Exception e) {
  95. Log.e(TAG, "[Exception] IpAddr(String ip)");
  96. //e.printStackTrace();
  97. LogUtil.errorLogInfo("", TAG, e);
  98. }
  99. }
  100. public void GatewayIp(String gw) {
  101. try {
  102. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.GatewayIp(gw);
  103. else mV40IOIF.GatewayIp(gw);
  104. } catch (RuntimeException re) {
  105. LogUtil.errorLogInfo("", TAG, re);
  106. } catch (Exception e) {
  107. Log.e(TAG, "[Exception] GatewayIp(String gw)");
  108. //e.printStackTrace();
  109. LogUtil.errorLogInfo("", TAG, e);
  110. }
  111. }
  112. public void NetMask(String mask) {
  113. try {
  114. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetMask(mask);
  115. else mV40IOIF.NetMask(mask);
  116. } catch (RuntimeException re) {
  117. LogUtil.errorLogInfo("", TAG, re);
  118. } catch (Exception e) {
  119. Log.e(TAG, "[Exception] NetMask(String mask)");
  120. //e.printStackTrace();
  121. LogUtil.errorLogInfo("", TAG, e);
  122. }
  123. }
  124. public void NetAll(String ip, String mask, String gw, String mac) {
  125. try {
  126. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetAll(ip, mask, gw, mac);
  127. else mV40IOIF.NetAll(ip, mask, gw, mac);
  128. } catch (RuntimeException re) {
  129. LogUtil.errorLogInfo("", TAG, re);
  130. } catch (Exception e) {
  131. Log.e(TAG, "[Exception] NetAll(String ip, String mask, String gw, String mac)");
  132. //e.printStackTrace();
  133. LogUtil.errorLogInfo("", TAG, e);
  134. }
  135. }
  136. public void LiveUpdate() {
  137. try {
  138. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.LiveUpdate();
  139. else mV40IOIF.LiveUpdate();
  140. } catch (RuntimeException re) {
  141. LogUtil.errorLogInfo("", TAG, re);
  142. } catch (Exception e) {
  143. Log.e(TAG, "[Exception] LiveUpdate()");
  144. //e.printStackTrace();
  145. LogUtil.errorLogInfo("", TAG, e);
  146. }
  147. }
  148. public void UsbUpdate() {
  149. try {
  150. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.UsbUpdate();
  151. else mV40IOIF.UsbUpdate();
  152. } catch (RuntimeException re) {
  153. LogUtil.errorLogInfo("", TAG, re);
  154. } catch (Exception e) {
  155. Log.e(TAG, "[Exception] UsbUpdate()");
  156. //e.printStackTrace();
  157. LogUtil.errorLogInfo("", TAG, e);
  158. }
  159. }
  160. public int LcdWakeUp() {
  161. try {
  162. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.LcdWakeUp();
  163. else return mV40IOIF.LcdWakeUp();
  164. } catch (RuntimeException re) {
  165. LogUtil.errorLogInfo("", TAG, re);
  166. return -99;
  167. } catch (Exception e) {
  168. Log.e(TAG, "[Exception] LcdWakeUp()");
  169. //e.printStackTrace();
  170. LogUtil.errorLogInfo("", TAG, e);
  171. return -99;
  172. }
  173. }
  174. public void Reboot(int sec) {
  175. try {
  176. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.Reboot(sec);
  177. else mV40IOIF.Reboot(sec);
  178. } catch (RuntimeException re) {
  179. LogUtil.errorLogInfo("", TAG, re);
  180. } catch (Exception e) {
  181. Log.e(TAG, "[Exception] Reboot(int sec)");
  182. //e.printStackTrace();
  183. LogUtil.errorLogInfo("", TAG, e);
  184. }
  185. }
  186. public void NetDns1(String dns) {
  187. try {
  188. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetDns1(dns);
  189. else mV40IOIF.NetDns1(dns);
  190. } catch (RuntimeException re) {
  191. LogUtil.errorLogInfo("", TAG, re);
  192. } catch (Exception e) {
  193. Log.e(TAG, "[Exception] NetDns1(String dns)");
  194. //e.printStackTrace();
  195. LogUtil.errorLogInfo("", TAG, e);
  196. }
  197. }
  198. public void NetDns2(String dns) {
  199. try {
  200. if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetDns2(dns);
  201. else mV40IOIF.NetDns2(dns);
  202. } catch (RuntimeException re) {
  203. LogUtil.errorLogInfo("", TAG, re);
  204. } catch (Exception e) {
  205. Log.e(TAG, "[Exception] NetDns2(String dns)");
  206. //e.printStackTrace();
  207. LogUtil.errorLogInfo("", TAG, e);
  208. }
  209. }
  210. public int sensorread() {
  211. try {
  212. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.sensorread();
  213. else return mV40IOIF.sensorread();
  214. } catch (RuntimeException re) {
  215. LogUtil.errorLogInfo("", TAG, re);
  216. return -99;
  217. } catch (Exception e) {
  218. Log.e(TAG, "[Exception] sensorread()");
  219. //e.printStackTrace();
  220. LogUtil.errorLogInfo("", TAG, e);
  221. return -99;
  222. }
  223. }
  224. public int setLcdWakeUp() {
  225. try {
  226. if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.LcdWakeUp();
  227. else return mV40IOIF.LcdWakeUp();
  228. } catch (RuntimeException re) {
  229. LogUtil.errorLogInfo("", TAG, re);
  230. return -99;
  231. } catch (Exception e) {
  232. Log.e(TAG, "[Exception] setLcdWakeUp()");
  233. //e.printStackTrace();
  234. LogUtil.errorLogInfo("", TAG, e);
  235. return -99;
  236. }
  237. }
  238. public void setDns(String dns1, String dns2) {
  239. try {
  240. Log.i(TAG, "[setDns] DNS1 : " + dns1 + " / DNS2 : " + dns2);
  241. NetDns1(dns1);
  242. NetDns2(dns2);
  243. } catch (RuntimeException re) {
  244. LogUtil.errorLogInfo("", TAG, re);
  245. } catch (Exception e) {
  246. Log.e(TAG, "[Exception] setDns(String dns1, String dns2)");
  247. //e.printStackTrace();
  248. LogUtil.errorLogInfo("", TAG, e);
  249. }
  250. }
  251. public void setV40Reboot(int sec) {
  252. try {
  253. Log.i(TAG, "[setV40Reboot] V40 Device will reboot : " +sec + " second !!!");
  254. Reboot(sec);
  255. } catch (RuntimeException re) {
  256. LogUtil.errorLogInfo("", TAG, re);
  257. } catch (Exception e) {
  258. Log.e(TAG, "[Exception] setV40Reboot(int sec)");
  259. //e.printStackTrace();
  260. LogUtil.errorLogInfo("", TAG, e);
  261. }
  262. }
  263. public void setMACAddress(String strMAC) {
  264. try {
  265. Log.i(TAG, "[setMACAddress] strMAC [" + strMAC+ "]");
  266. SetMacAddr(strMAC);
  267. } catch (RuntimeException re) {
  268. LogUtil.errorLogInfo("", TAG, re);
  269. } catch (Exception e) {
  270. Log.e(TAG, "[Exception] setMACAddress(String strMAC)");
  271. //e.printStackTrace();
  272. LogUtil.errorLogInfo("", TAG, e);
  273. }
  274. }
  275. public void setIPAddress(String strIP) {
  276. try {
  277. Log.i(TAG, "[setIPAddress] strIP [" + strIP + "]");
  278. IpAddr(strIP);
  279. } catch (RuntimeException re) {
  280. LogUtil.errorLogInfo("", TAG, re);
  281. } catch (Exception e) {
  282. Log.e(TAG, "[Exception] setIPAddress(String strIP)");
  283. //e.printStackTrace();
  284. LogUtil.errorLogInfo("", TAG, e);
  285. }
  286. }
  287. public void setNetmaskAddress(String strNetmask) {
  288. try {
  289. Log.i(TAG, "[setNetmaskAddress] strNetmask [" + strNetmask + "]");
  290. NetMask(strNetmask);
  291. } catch (RuntimeException re) {
  292. LogUtil.errorLogInfo("", TAG, re);
  293. } catch (Exception e) {
  294. Log.e(TAG, "[Exception] setNetmaskAddress(String strNetmask)");
  295. //e.printStackTrace();
  296. LogUtil.errorLogInfo("", TAG, e);
  297. }
  298. }
  299. public void setGatewayAddress(String strGateway) {
  300. try {
  301. Log.i(TAG, "[setGatewayAddress] strGateway [" + strGateway+ "]");
  302. GatewayIp(strGateway);
  303. } catch (RuntimeException re) {
  304. LogUtil.errorLogInfo("", TAG, re);
  305. } catch (Exception e) {
  306. Log.e(TAG, "[Exception] setGatewayAddress(String strGateway)");
  307. //e.printStackTrace();
  308. LogUtil.errorLogInfo("", TAG, e);
  309. }
  310. }
  311. public void setNetworkInterface(String strIP, String strNetmask, String strGateway, String strMAC) {
  312. try {
  313. Log.i(TAG, "[setNetworkInterface] strIP [" + strIP+ "], strNetmask [" + strNetmask+ "], strGateway [" + strGateway+ "], strMAC [" + strMAC+ "]");
  314. NetAll(strIP, strNetmask, strGateway, strMAC);
  315. } catch (RuntimeException re) {
  316. LogUtil.errorLogInfo("", TAG, re);
  317. } catch (Exception e) {
  318. Log.e(TAG, "[Exception] setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC)");
  319. //e.printStackTrace();
  320. LogUtil.errorLogInfo("", TAG, e);
  321. }
  322. }
  323. public void setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC) {
  324. try {
  325. Log.i(TAG, "[setNetworkInterface] strIP [" + strIP+ "], strNetmask [" + strNetmask+ "], strGateway [" + strGateway+ "], strDNS [" + strDNS+ "], strMAC [" + strMAC+ "]");
  326. IpAddr(strIP);
  327. NetMask(strNetmask);
  328. GatewayIp(strGateway);
  329. // DNS 설정 JNI method는 아직 없음(2018.02.26)
  330. SetMacAddr(strMAC);
  331. } catch (RuntimeException re) {
  332. LogUtil.errorLogInfo("", TAG, re);
  333. } catch (Exception e) {
  334. Log.e(TAG, "[Exception] setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC)");
  335. //e.printStackTrace();
  336. LogUtil.errorLogInfo("", TAG, e);
  337. }
  338. }
  339. /*
  340. #define TYPE_GPIO_CMD (0xFF << 8)
  341. #define TYPE_GPIO2_CMD (0xFE << 8)
  342. #define IOCTL_LEDNEMR_ONOFF (TYPE_GPIO_CMD|0x02) //LED on/off
  343. #define IOCTL_EMR_TYPE (TYPE_GPIOS_CMD|0x02) //비상기능 타입
  344. #define IOCTL_EMR_OFF (TYPE_GPIOS_CMD|0x03) //비상종료
  345. #define IOCTL_PROX_THR (TYPE_GPIOS_CMD|0x04) //근접센서 감도.
  346. */
  347. public static final int TYPE_GPIO_CMD = (0xFF << 8);
  348. public static final int TYPE_GPIO2_CMD = (0xFE << 8);
  349. public static final int IOCTL_LEDNEMR_ONOFF = (TYPE_GPIO_CMD | 0x02);
  350. public static final int IOCTL_EMR_TYPE = (TYPE_GPIO2_CMD | 0x02);
  351. public static final int IOCTL_EMR_OFF = (TYPE_GPIO2_CMD | 0x03);
  352. public static final int IOCTL_PROX_THR = (TYPE_GPIO2_CMD | 0x04);
  353. public void Ctrl_CloseSensor(int value) {
  354. if (!(value >= 0 && value <= 15)) {
  355. Log.d(TAG, "[Ctrl_CloseSensor] Value Range Error : " + value);
  356. return;
  357. }
  358. Log.d(TAG, "[Ctrl_CloseSensor] Change Close Value : " + value);
  359. WpdInterfaceOpen();
  360. WpdInterfaceControl(IOCTL_PROX_THR, value);
  361. WpdInterfaceClose();
  362. }
  363. public void Ctrl_LCD_WakeUp() {
  364. Log.d(TAG, "[Ctrl_LCD_WakeUp] LCD Wake Up RUN");
  365. WpdInterfaceOpen();
  366. LcdWakeUp();
  367. WpdInterfaceClose();
  368. }
  369. public void Emergency_Type_Set() {
  370. WpdInterfaceOpen();
  371. if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
  372. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) {
  373. Log.d(TAG, "[Emergency_Type_Set] V40 - D101 mode");
  374. WpdInterfaceControl(IOCTL_EMR_TYPE, 0);
  375. }
  376. else {
  377. Log.d(TAG, "[Emergency_Type_Set] A20 - Previous mode");
  378. WpdInterfaceControl(IOCTL_EMR_TYPE, 1);
  379. }
  380. WpdInterfaceClose();
  381. }
  382. public void Emergency_LED_On() {
  383. Log.d(TAG, "[Emergency_LED_On] Emergency LED On&Off START");
  384. WpdInterfaceOpen();
  385. WpdInterfaceControl(IOCTL_LEDNEMR_ONOFF, 1);
  386. WpdInterfaceClose();
  387. }
  388. public void Emergency_LED_Off() {
  389. Log.d(TAG, "[Emergency_LED_On] Emergency LED On&Off END");
  390. WpdInterfaceOpen();
  391. WpdInterfaceControl(IOCTL_LEDNEMR_ONOFF, 0);
  392. if (Version.getModelType() != Version.MODEL_TYPE.IHN_D101 && Version.getModelType() != Version.MODEL_TYPE.IHN_D101_I
  393. && Version.getModelType() != Version.MODEL_TYPE.IHN_D101K && Version.getModelType() != Version.MODEL_TYPE.IHN_D101K_I) {
  394. WpdInterfaceControl(IOCTL_EMR_OFF, 0);
  395. }
  396. WpdInterfaceClose();
  397. }
  398. public void Emergency_LED_blink() {
  399. }
  400. public int DoControl(int cmd, int arg) {
  401. WpdInterfaceOpen();
  402. int ctr = WpdInterfaceControl( cmd, arg);
  403. WpdInterfaceClose();
  404. return ctr;
  405. }
  406. public void DoorLockControl(boolean ctr) {
  407. try {
  408. if (WpdInterfaceOpen() >= 0) {
  409. WpdInterfaceControl(0xFF09, (ctr)?1:0);
  410. WpdInterfaceClose();
  411. }
  412. } catch (RuntimeException re) {
  413. LogUtil.errorLogInfo("", TAG, re);
  414. } catch (Exception e) {
  415. //e.printStackTrace();
  416. LogUtil.errorLogInfo("", TAG, e);
  417. }
  418. }
  419. }