123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- package kr.co.icontrols.v40ioctl;
- import android.os.Build;
- import android.util.Log;
- import com.util.LogUtil;
- import kr.co.icontrols.wallpadsupport.Version;
- public class V40IF {
- String TAG = "V40IF";
- boolean bLOG = true;
- private void LOG(String log) {
- if (bLOG) Log.v(TAG, log);
- }
- boolean bLOG_DEBUG = false;
- private void LOG_DEBUG(String log) {
- if (bLOG_DEBUG) Log.d(TAG, log);
- }
- boolean bLOG_INFO = true;
- private void LOG_INFO(String log) {
- if (bLOG_INFO) Log.i(TAG, log);
- }
- private V40IOInterface mV40IOIF = null;
- private V40IOInterface2 mV40IOIF_NOUGAT = null;
- public V40IF() {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT = new V40IOInterface2();
- else mV40IOIF = new V40IOInterface();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] V40IF()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public int WpdInterfaceOpen() {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceOpen();
- else return mV40IOIF.WpdInterfaceOpen();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] WpdInterfaceOpen()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public int WpdInterfaceClose() {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceClose();
- else return mV40IOIF.WpdInterfaceClose();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] WpdInterfaceClose()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public int WpdInterfaceControl(int cmd, int arg) {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.WpdInterfaceControl(cmd, arg);
- else return mV40IOIF.WpdInterfaceControl(cmd, arg);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] WpdInterfaceControl(int cmd, int arg)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public void SetMacAddr(String mac) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.SetMacAddr(mac);
- else mV40IOIF.SetMacAddr(mac);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] SetMacAddr(String mac)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void IpAddr(String ip) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.IpAddr(ip);
- else mV40IOIF.IpAddr(ip);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] IpAddr(String ip)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void GatewayIp(String gw) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.GatewayIp(gw);
- else mV40IOIF.GatewayIp(gw);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] GatewayIp(String gw)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void NetMask(String mask) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetMask(mask);
- else mV40IOIF.NetMask(mask);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] NetMask(String mask)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void NetAll(String ip, String mask, String gw, String mac) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetAll(ip, mask, gw, mac);
- else mV40IOIF.NetAll(ip, mask, gw, mac);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] NetAll(String ip, String mask, String gw, String mac)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void LiveUpdate() {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.LiveUpdate();
- else mV40IOIF.LiveUpdate();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] LiveUpdate()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void UsbUpdate() {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.UsbUpdate();
- else mV40IOIF.UsbUpdate();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] UsbUpdate()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public int LcdWakeUp() {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.LcdWakeUp();
- else return mV40IOIF.LcdWakeUp();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] LcdWakeUp()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public void Reboot(int sec) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.Reboot(sec);
- else mV40IOIF.Reboot(sec);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] Reboot(int sec)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void NetDns1(String dns) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetDns1(dns);
- else mV40IOIF.NetDns1(dns);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] NetDns1(String dns)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void NetDns2(String dns) {
- try {
- if (Build.VERSION.SDK_INT > 23) mV40IOIF_NOUGAT.NetDns2(dns);
- else mV40IOIF.NetDns2(dns);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] NetDns2(String dns)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public int sensorread() {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.sensorread();
- else return mV40IOIF.sensorread();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] sensorread()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public int setLcdWakeUp() {
- try {
- if (Build.VERSION.SDK_INT > 23) return mV40IOIF_NOUGAT.LcdWakeUp();
- else return mV40IOIF.LcdWakeUp();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return -99;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setLcdWakeUp()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return -99;
- }
- }
- public void setDns(String dns1, String dns2) {
- try {
- Log.i(TAG, "[setDns] DNS1 : " + dns1 + " / DNS2 : " + dns2);
- NetDns1(dns1);
- NetDns2(dns2);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setDns(String dns1, String dns2)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setV40Reboot(int sec) {
- try {
- Log.i(TAG, "[setV40Reboot] V40 Device will reboot : " +sec + " second !!!");
- Reboot(sec);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setV40Reboot(int sec)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setMACAddress(String strMAC) {
- try {
- Log.i(TAG, "[setMACAddress] strMAC [" + strMAC+ "]");
- SetMacAddr(strMAC);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setMACAddress(String strMAC)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setIPAddress(String strIP) {
- try {
- Log.i(TAG, "[setIPAddress] strIP [" + strIP + "]");
- IpAddr(strIP);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setIPAddress(String strIP)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setNetmaskAddress(String strNetmask) {
- try {
- Log.i(TAG, "[setNetmaskAddress] strNetmask [" + strNetmask + "]");
- NetMask(strNetmask);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setNetmaskAddress(String strNetmask)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setGatewayAddress(String strGateway) {
- try {
- Log.i(TAG, "[setGatewayAddress] strGateway [" + strGateway+ "]");
- GatewayIp(strGateway);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setGatewayAddress(String strGateway)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setNetworkInterface(String strIP, String strNetmask, String strGateway, String strMAC) {
- try {
- Log.i(TAG, "[setNetworkInterface] strIP [" + strIP+ "], strNetmask [" + strNetmask+ "], strGateway [" + strGateway+ "], strMAC [" + strMAC+ "]");
- NetAll(strIP, strNetmask, strGateway, strMAC);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC) {
- try {
- Log.i(TAG, "[setNetworkInterface] strIP [" + strIP+ "], strNetmask [" + strNetmask+ "], strGateway [" + strGateway+ "], strDNS [" + strDNS+ "], strMAC [" + strMAC+ "]");
- IpAddr(strIP);
- NetMask(strNetmask);
- GatewayIp(strGateway);
- // DNS 설정 JNI method는 아직 없음(2018.02.26)
- SetMacAddr(strMAC);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] setNetworkInterface(String strIP, String strNetmask, String strGateway, String strDNS, String strMAC)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- /*
- #define TYPE_GPIO_CMD (0xFF << 8)
- #define TYPE_GPIO2_CMD (0xFE << 8)
- #define IOCTL_LEDNEMR_ONOFF (TYPE_GPIO_CMD|0x02) //LED on/off
- #define IOCTL_EMR_TYPE (TYPE_GPIOS_CMD|0x02) //비상기능 타입
- #define IOCTL_EMR_OFF (TYPE_GPIOS_CMD|0x03) //비상종료
- #define IOCTL_PROX_THR (TYPE_GPIOS_CMD|0x04) //근접센서 감도.
- */
- public static final int TYPE_GPIO_CMD = (0xFF << 8);
- public static final int TYPE_GPIO2_CMD = (0xFE << 8);
- public static final int IOCTL_LEDNEMR_ONOFF = (TYPE_GPIO_CMD | 0x02);
- public static final int IOCTL_EMR_TYPE = (TYPE_GPIO2_CMD | 0x02);
- public static final int IOCTL_EMR_OFF = (TYPE_GPIO2_CMD | 0x03);
- public static final int IOCTL_PROX_THR = (TYPE_GPIO2_CMD | 0x04);
- public void Ctrl_CloseSensor(int value) {
- if (!(value >= 0 && value <= 15)) {
- Log.d(TAG, "[Ctrl_CloseSensor] Value Range Error : " + value);
- return;
- }
- Log.d(TAG, "[Ctrl_CloseSensor] Change Close Value : " + value);
- WpdInterfaceOpen();
- WpdInterfaceControl(IOCTL_PROX_THR, value);
- WpdInterfaceClose();
- }
- public void Ctrl_LCD_WakeUp() {
- Log.d(TAG, "[Ctrl_LCD_WakeUp] LCD Wake Up RUN");
- WpdInterfaceOpen();
- LcdWakeUp();
- WpdInterfaceClose();
- }
- public void Emergency_Type_Set() {
- WpdInterfaceOpen();
- if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
- || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) {
- Log.d(TAG, "[Emergency_Type_Set] V40 - D101 mode");
- WpdInterfaceControl(IOCTL_EMR_TYPE, 0);
- }
- else {
- Log.d(TAG, "[Emergency_Type_Set] A20 - Previous mode");
- WpdInterfaceControl(IOCTL_EMR_TYPE, 1);
- }
- WpdInterfaceClose();
- }
- public void Emergency_LED_On() {
- Log.d(TAG, "[Emergency_LED_On] Emergency LED On&Off START");
- WpdInterfaceOpen();
- WpdInterfaceControl(IOCTL_LEDNEMR_ONOFF, 1);
- WpdInterfaceClose();
- }
- public void Emergency_LED_Off() {
- Log.d(TAG, "[Emergency_LED_On] Emergency LED On&Off END");
- WpdInterfaceOpen();
- WpdInterfaceControl(IOCTL_LEDNEMR_ONOFF, 0);
- if (Version.getModelType() != Version.MODEL_TYPE.IHN_D101 && Version.getModelType() != Version.MODEL_TYPE.IHN_D101_I
- && Version.getModelType() != Version.MODEL_TYPE.IHN_D101K && Version.getModelType() != Version.MODEL_TYPE.IHN_D101K_I) {
- WpdInterfaceControl(IOCTL_EMR_OFF, 0);
- }
- WpdInterfaceClose();
- }
- public void Emergency_LED_blink() {
- }
- public int DoControl(int cmd, int arg) {
- WpdInterfaceOpen();
- int ctr = WpdInterfaceControl( cmd, arg);
- WpdInterfaceClose();
- return ctr;
- }
- public void DoorLockControl(boolean ctr) {
- try {
- if (WpdInterfaceOpen() >= 0) {
- WpdInterfaceControl(0xFF09, (ctr)?1:0);
- WpdInterfaceClose();
- }
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- }
|