package kr.co.icontrols.ilp300_700.global;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import java.net.Socket;

import kr.co.icontrols.iencryptor.aes128.AES_128;
import kr.co.icontrols.iencryptor.aes128.AES_128.ENCRYPTTYPE;
import kr.co.icontrols.ilp300_700.MainActivity;
import kr.co.icontrols.ilp300_700.R;
import kr.co.icontrols.ilp300_700.call.CallManager.CALLTYPE;
import kr.co.icontrols.ilp300_700.ethernet.EthernetCtrl;
import kr.co.icontrols.ilp300_700.ethernet.iMAPCommon.iMAPResult;
import kr.co.icontrols.ilp300_700.ethernet.iMAPServer;
import kr.co.icontrols.ilp300_700.global.Configure.ConfigValue;
import kr.co.icontrols.ilp300_700.global.Configure.SetValue;
import kr.co.icontrols.ilp300_700.global.DataClasses.AccessKeyInfo;
import kr.co.icontrols.ilp300_700.global.DataClasses.MultiReaderKeyInfo;
import kr.co.icontrols.ilp300_700.global.DataClasses.STDReaderKeyInfo;
import kr.co.icontrols.ilp300_700.global.Declare.AccessValues;
import kr.co.icontrols.ilp300_700.global.Declare.DeviceType;
import kr.co.icontrols.ilp300_700.global.Enumeration.ACCESSKEYTYPE;
import kr.co.icontrols.ilp300_700.imap.MakeiMAPMSG;
import kr.co.icontrols.ilp300_700.imap.Request_get_accesskey_info;
import kr.co.icontrols.ilp300_700.imap.Request_save_lobby_access;
import kr.co.icontrols.ilp300_700.imap.Request_save_uidcard_access;
import kr.co.icontrols.ilp300_700.imap.Request_save_vcard_access;
import kr.co.icontrols.ilp300_700.imap.iMAPResultCtrl;
import kr.co.icontrols.ilp300_700.rfreader.STDAccessKeyManager;
import kr.co.icontrols.ilp300_700.rfreader.STDAccessKeyManager.AccessKey_STD;
import kr.co.icontrols.ilp300_700.rfreader.UIDAccessKeyManager;
import kr.co.icontrols.ilp300_700.serialport.HDCStandardReaderSerial;

public class LobbyAccessCtrl {

    static String TAG = "LobbyAccessCtrl";

    static boolean bLOG = true;   // true, false
    static boolean bLOG_DEBUG = false;   // true, false
    static boolean bLOG_INFO = true;   // true, false
    static Context mContext;
    String mRemoteIP;

    private static void LOG(String log) {
        if (bLOG) Log.v(TAG, log);
    }

    private static void LOG_DEBUG(String log) {
        if (bLOG_DEBUG) Log.d(TAG, log);
    }

    private static void LOG_INFO(String log) {
        if (bLOG_INFO) Log.i(TAG, log);
    }

    // Context 전달
    public static boolean setLobbyAccessCtrlContext(Context context) {
        try {
            mContext = context;
            return true;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setLobbyAccessCtrlContext(context) " + e);
            e.printStackTrace();
            return false;
        }
    }

    public static void playMentAfterMsg(String strAction, iMAPResult Result) {
        try {
            // 택배연동시 관리PC의 응답을 받아 택배수신여부를 음성으로 출력하는 함수
            if (ConfigValue.eParcelLink == SetValue.TRUE) {
                if (Result == iMAPResult.OK) {
                    if (strAction.equalsIgnoreCase(AccessValues.pass)) MainActivity.mSound.PlayMent_lobby(R.raw.dooropen);
                } else if (Result == iMAPResult.Parcel) {
                    if (strAction.equalsIgnoreCase(AccessValues.pass)) MainActivity.mSound.PlayMent_lobby(R.raw.packagearrived);
                } else {
                    // 단지관리PC와 통신이 안되는 경우
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] playMentAfterMsg(strAction, Result)");
            e.printStackTrace();
        }
    }

    /* [START] Standard Key(I-Park Card) Access Control */
    public static ACCESSKEYTYPE classifyKeyType(STDReaderKeyInfo Info) {
        try {
            if (Info.getIDType() == (byte) 0x00) {
                // 세대키
                if (Integer.parseInt(Info.getDong()) != 0 && Integer.parseInt(Info.getHo()) != 0) {
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.RESIDENCE.toString() + "]");
                    return ACCESSKEYTYPE.RESIDENCE;
                }
                return ACCESSKEYTYPE.ERROR;
            } else if (Info.getIDType() == (byte) 0x01) {
                // 관리자키
                if (Integer.parseInt(Info.getDong()) != 0 && Integer.parseInt(Info.getHo()) == 0 && Integer.parseInt(Info.getKeyNo()) != 0) {
                    // 동 관리자키
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.ADMIN_DONG.toString() + "]");
                    return ACCESSKEYTYPE.ADMIN_DONG;
                } else if (Integer.parseInt(Info.getDong()) == 0 && Integer.parseInt(Info.getHo()) == 0 && Integer.parseInt(Info.getKeyNo()) != 0) {
                    // 전체 관리자키
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.ADMIN_ENTIRE.toString() + "]");
                    return ACCESSKEYTYPE.ADMIN_ENTIRE;
                }
                return ACCESSKEYTYPE.ERROR;
            } else if (Info.getIDType() == (byte) 0x02) {
                // 방문자키
                if (Integer.parseInt(Info.getDong()) != 0 && Integer.parseInt(Info.getHo()) != 0) {
                    // 세대 방문자키
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.VISITOR_RESIDENCE.toString() + "]");
                    return ACCESSKEYTYPE.VISITOR_RESIDENCE;
                } else if (Integer.parseInt(Info.getDong()) == 0 && Integer.parseInt(Info.getHo()) == 0 && Integer.parseInt(Info.getKeyNo()) != 0) {
                    // 동 방문자키
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.VISITOR_ADMIN_DONG.toString() + "]");
                    return ACCESSKEYTYPE.VISITOR_ADMIN_DONG;
                } else if (Integer.parseInt(Info.getDong()) != 0 && Integer.parseInt(Info.getHo()) == 0 && Integer.parseInt(Info.getKeyNo()) != 0) {
                    // 전체 방문자키
                    LOG_DEBUG("[classifyKeyType] PassType [" + ACCESSKEYTYPE.VISITOR_ADMIN_ENTIRE.toString() + "]");
                    return ACCESSKEYTYPE.VISITOR_ADMIN_ENTIRE;
                }
                return ACCESSKEYTYPE.ERROR;
            } else {
                return ACCESSKEYTYPE.ERROR;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] classifyKeyType(Info) : " + e);
            e.printStackTrace();
            return ACCESSKEYTYPE.ERROR;
        }
    }

    public static void ctrlAccessSTDRFKey(STDReaderKeyInfo Info) {
        try {
            LOG_DEBUG("[ctrlAccessSTDRFKey] Sitecode [" + Info.getSitecode() + "]");
            LOG_DEBUG("[ctrlAccessSTDRFKey] Dong [" + Info.getDong() + "], Ho [" + Info.getHo() + "]");
            LOG_DEBUG("[ctrlAccessSTDRFKey] IDNo [" + Info.getKeyNo() + "], IssueCnt [" + Info.getIssueCnt() + "], IDType [" + Info.getIDType() + "]");

            if (ConfigValue.eLPRole == SetValue.LPRole_CarGate) {
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                LOG("[ctrlAccessSTDRFKey] This lobbyphone set as cargate lobbyphone!!");
                return;
            }

            ACCESSKEYTYPE ePassType = classifyKeyType(Info);

            if (ePassType == ACCESSKEYTYPE.RESIDENCE) {   // 세대키
                if (ConfigValue.eRFAccessLevel == SetValue.Level_Line) {
                    ctrlAccessSTDRFKey_Residence_Line(Info);
                } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Dong) {
                    ctrlAccessSTDRFKey_Residence_Dong(Info);
                } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Entire) {
                    ctrlAccessSTDRFKey_Residence_Entire(Info);
                } else {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eRFAccessLevel is wrong!!");
                    return;
                }
            } else if (ePassType == ACCESSKEYTYPE.ADMIN_DONG) {   // 동 관리자키
                ctrlAccessSTDRFKey_Admin_Dong(Info);
            } else if (ePassType == ACCESSKEYTYPE.ADMIN_ENTIRE) {   // 전차 관리자키
                ctrlAccessSTDRFKey_Admin_Entire(Info);
            } else if (ePassType == ACCESSKEYTYPE.VISITOR_RESIDENCE) {   // 세대 방문자
                if (ConfigValue.eACULinkEnable == SetValue.TRUE) {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eACULinkEnable is TRUE!!");
                    LOG("[ctrlAccessSTDRFKey] This is not yet supported!!");
                    ctrlAccessSTDRFKey_Visitor_Residence(Info);
                } else {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eACULinkEnable is FALSE!!");
                    return;
                }
            } else if (ePassType == ACCESSKEYTYPE.VISITOR_ADMIN_DONG) {   // 동 관리자키
                if (ConfigValue.eACULinkEnable == SetValue.TRUE) {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eACULinkEnable is TRUE!!");
                    LOG("[ctrlAccessSTDRFKey] This is not yet supported!!");
                    ctrlAccessSTDRFKey_Visitor_Dong(Info);
                } else {
                    LOG("[ctrlAccessSTDRFPass] ConfigValue.eACULinkEnable is FALSE!!");
                    return;
                }
            } else if (ePassType == ACCESSKEYTYPE.VISITOR_ADMIN_ENTIRE) {   // 전체 관리자키
                if (ConfigValue.eACULinkEnable == SetValue.TRUE) {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eACULinkEnable is TRUE!!");
                    LOG("[ctrlAccessSTDRFKey] This is not yet supported!!");
                    ctrlAccessSTDRFKey_Visitor_Entire(Info);
                } else {
                    LOG("[ctrlAccessSTDRFKey] ConfigValue.eACULinkEnable is FALSE!!");
                    return;
                }
            } else {
                LOG("[ctrlAccessSTDRFKey] ePassType is wrong!! - ePassType [" + ePassType + "]");
                return;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Residence_Line(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Residence_Line] ===== START =====");
            if (ConfigValue.LineInfo.getCnt() == 0) {
                LOG("[ctrlAccessSTDRFKey_Residence_Line] There is no line info!!");
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                return;
            }

            String strResiIPAddress = EthernetCtrl.makeIPAddress(DeviceType.RESIDENCE, Info.getDong(), Info.getHo());
            if (strResiIPAddress == null) {
                LOG("[ctrlAccessSTDRFKey_Residence_Line] strResiIPAddress is null!!");
                return;
            }

            int nDong = Integer.parseInt(Info.getDong());
            int nHo = Integer.parseInt(Info.getHo());
            int nHo_Head = nHo / 100;
            int nHo_Tail = nHo % 100;
            int nIDNo = Integer.parseInt(Info.getKeyNo());
            int nIssueCnt = Integer.parseInt(Info.getIssueCnt());

            if (!ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Residence_Line] Sitecode is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail_site, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                return;
            }

            if (!ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                // 차단 : 동 다름
                LOG("[ctrlAccessSTDRFKey_Residence_Line] Dong is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                return;
            }

            if (!Global.isExistResi(nHo)) {
                // 차단 : 세대 없음
                LOG("[ctrlAccessSTDRFKey_Residence_Line] Residence does not exist!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                return;
            }

            if (nIDNo == 0) {
                // 차단 : 사용하지 않는 카드번호
                LOG("[ctrlAccessSTDRFKey_Residence_Line] nIDNo is 0!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                return;
            }

            //LOG("[ctrlAccessSTDRFKey_Residence_Line] KSJ " +AccessKey_STD.aResiKey[nHo_Head][nHo_Tail]);

            if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == 0) {
                // 차단
                LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is 0!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                return;
            }
            else
            {
                LOG("[ctrlAccessSTDRFKey_Residence_Line] OK!!");
                if (ConfigValue.eParcelLink == SetValue.TRUE) {
                    Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
                } else {
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                }
                sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                Global.sendElevCallRequest(Integer.toString(nDong), Integer.toString(nHo), true);
                return;
            }


//            if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
//                if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == 0) {
//                    // 차단
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is 0!!");
//                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                    sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    return;
//                } else if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == nIssueCnt) {
//                    // 통과
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] OK!!");
//                    if (ConfigValue.eParcelLink == SetValue.TRUE) {
//                        Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
//                    } else {
//                        Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
//                    }
//                    sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    Global.sendElevCallRequest(Integer.toString(nDong), Integer.toString(nHo), true);
//                    return;
//                } else if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] + 1 == nIssueCnt) {
//                    // 통과 : 업데이트
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] OK!! (UPDATE)");
//
//                    if (!STDAccessKeyManager.updateResiAccessKey(nDong, nHo, nIssueCnt)) {
//                        // 업데이트에 실패하면 차단한다.
//                        LOG("[ctrlAccessSTDRFKey_Residence_Line] Fail from STDAccessKeyManager.updateResiAccessKey(nDong, nHo, nIssueCnt)");
//                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                        sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                        return;
//                    }
//
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] Residence Pass Info Updated!!");
//                    // 업데이트 성공 후 키정보 비교
//                    if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == nIssueCnt) {
//                        LOG("[ctrlAccessSTDRFKey_Residence_Line] OK!! (After UPDATE)");
//                        if (ConfigValue.eParcelLink == SetValue.TRUE) {
//                            Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
//                        } else {
//                            Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
//                        }
//                        sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                        Global.sendElevCallRequest(Integer.toString(nDong), Integer.toString(nHo), true);
//                        // 동일그룹내 로비폰과 업데이트 키정보 공유 및 동기화한다.
//                        Global.sendSTDRFKeyInfo(AccessValues.card, nDong, nHo, nIssueCnt);
//                        return;
//                    } else {
//                        LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is wrong!! (After UPDATE)");
//                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                        sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                        return;
//                    }
//                } else {
//                    // 차단
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is wrong!!");
//                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                    sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    return;
//                }
//            }
//            //메인서버가 2.0이 아닌 경우, AccessKey 관련 수정 코드 적용. 0인 경우 차단, 0보다 크면 통과, 0보다 작으면 차단으로 적용함.
//            else {
//                if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == 0) {
//                    // 차단
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is 0!!");
//                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                    sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    return;
//                } else if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] > 0) {
//                    // 통과
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] OK!!");
//                    if (ConfigValue.eParcelLink == SetValue.TRUE) {
//                        Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
//                    } else {
//                        Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
//                    }
//                    sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    Global.sendElevCallRequest(Integer.toString(nDong), Integer.toString(nHo), true);
//                    return;
//                } else {
//                    // 차단
//                    LOG("[ctrlAccessSTDRFKey_Residence_Line] nIssueCnt is wrong!!");
//                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
//                    sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
//                    return;
//                }
//            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Residence_Line(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Residence_Dong(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Residence_Dong] ===== START =====");

            String strResiIPAddress = EthernetCtrl.makeIPAddress(DeviceType.RESIDENCE, Info.getDong(), Info.getHo());
            if (strResiIPAddress == null) {
                LOG("[ctrlAccessSTDRFKey_Residence_Dong] strResiIPAddress is null!!");
                return;
            }

            int nDong = Integer.parseInt(Info.getDong());
            int nHo = Integer.parseInt(Info.getHo());
            int nIDNo = Integer.parseInt(Info.getKeyNo());
            int nIssueCnt = Integer.parseInt(Info.getIssueCnt());

            if (ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                if (ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                    // 통과
                    LOG("[ctrlAccessSTDRFKey_Residence_Dong] OK!!");
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                    sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                    Global.sendElevCallRequest("null", "null", true);
                } else {
                    // 차단 : 동 다름
                    LOG("[ctrlAccessSTDRFKey_Residence_Dong] Dong is wrong!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                }
            } else {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Residence_Dong] Sitecode is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail_site, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Residence_Dong(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Residence_Entire(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Residence_Entire] ===== START =====");

            String strResiIPAddress = EthernetCtrl.makeIPAddress(DeviceType.RESIDENCE, Info.getDong(), Info.getHo());
            if (strResiIPAddress == null) {
                LOG("[ctrlAccessSTDRFKey_Residence_Entire] strResiIPAddress is null!!");
                return;
            }

            int nDong = Integer.parseInt(Info.getDong());
            int nHo = Integer.parseInt(Info.getHo());
            int nIDNo = Integer.parseInt(Info.getKeyNo());
            int nIssueCnt = Integer.parseInt(Info.getIssueCnt());

            if (ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                // 통과
                LOG("[ctrlAccessSTDRFKey_Residence_Entire] OK!!");
                Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                sendLobbyAccessLog(AccessValues.pass, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
                Global.sendElevCallRequest("null", "null", true);
            } else {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Residence_Entire] Sitecode is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail_site, AccessValues.card, strResiIPAddress, "null", nDong, nHo, nIDNo, nIssueCnt, "null");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Residence_Entire(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Admin_Dong(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Admin_Dong] ===== START =====");

            int nDong = Integer.parseInt(Info.getDong());
            int nIDNo = Integer.parseInt(Info.getKeyNo());
            int nIssueCnt = Integer.parseInt(Info.getIssueCnt());

            if (!ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Admin_Dong] Sitecode is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail_site, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                return;
            }

            if (!ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                // 차단 : 동 다름
                LOG("[ctrlAccessSTDRFKey_Admin_Dong] Dong is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                return;
            }

            if (nIDNo == 0) {
                // 차단 : 사용하지 않는 카드번호
                LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIDNo is 0!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                return;
            }
            if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
                if (AccessKey_STD.aDongAdminKey[nIDNo] == 0) {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIssueCnt is 0!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    return;
                } else if (AccessKey_STD.aDongAdminKey[nIDNo] == nIssueCnt) {
                    // 통과
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] OK!!");
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                    sendLobbyAccessLog(AccessValues.pass, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    Global.sendElevCallRequest("null", "null", true);
                    return;
                } else if (AccessKey_STD.aDongAdminKey[nIDNo] + 1 == nIssueCnt) {

                    // 통과 : 업데이트
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] OK!! (UPDATE)");

                    if (!STDAccessKeyManager.updateDongAdminAccessKey(nIDNo, nIssueCnt)) {
                        // 업데이트에 실패하면 차단한다.
                        LOG("[ctrlAccessSTDRFKey_Admin_Dong] Fail from STDAccessKeyManager.updateDongAdminAccessKey(...)");
                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                        sendLobbyAccessLog(AccessValues.pass, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                        return;
                    }

                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] Dong Admin Pass Info Updated!!");
                    // 업데이트 성공 후 키정보 비교
                    if (AccessKey_STD.aDongAdminKey[nIDNo] == nIssueCnt) {
                        LOG("[ctrlAccessSTDRFKey_Admin_Dong] OK!! (After UPDATE)");
                        Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                        sendLobbyAccessLog(AccessValues.pass, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                        Global.sendElevCallRequest("null", "null", true);
                        // 동일그룹내 로비폰과 업데이트 키정보 공유 및 동기화한다.
                        Global.sendSTDRFKeyInfo(AccessValues.dcard, nDong, 0, nIssueCnt);
                        return;
                    } else {
                        // 차단
                        LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIssueCnt is wrong!! (After UPDATE)");
                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                        sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                        return;
                    }
                } else {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIssueCnt is wrong!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    return;
                }
            }
            //메인서버가 2.0이 아닌 경우, AccessKey 관련 수정 코드 적용. 0인 경우 차단, 0보다 크면 통과, 0보다 작으면 차단으로 적용함
            else {
                if (AccessKey_STD.aDongAdminKey[nIDNo] == 0) {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIssueCnt is 0!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    return;
                } else if (AccessKey_STD.aDongAdminKey[nIDNo] > 0) {
                    // 통과
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] OK!!");
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                    sendLobbyAccessLog(AccessValues.pass, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    Global.sendElevCallRequest("null", "null", true);
                    return;
                } else {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Dong] nIssueCnt is wrong!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.dcard, "null", "null", nDong, 0, nIDNo, nIssueCnt, "null");
                    return;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Admin_Dong(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Admin_Entire(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Admin_Entire] ===== START =====");

            int nIDNo = Integer.parseInt(Info.getKeyNo());
            int nIssueCnt = Integer.parseInt(Info.getIssueCnt());

            if (!ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Admin_Entire] Sitecode is wrong!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail_site, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                return;
            }

            if (nIDNo == 0) {
                // 차단 : 사용하지 않는 카드번호
                LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIDNo is 0!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                return;
            }
            if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
                if (AccessKey_STD.aEntireAdminKey[nIDNo] == 0) {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIssueCnt is 0!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    return;
                } else if (AccessKey_STD.aEntireAdminKey[nIDNo] == nIssueCnt) {
                    // 통과
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] OK!!");
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                    sendLobbyAccessLog(AccessValues.pass, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    Global.sendElevCallRequest("null", "null", true);
                    return;
                } else if (AccessKey_STD.aEntireAdminKey[nIDNo] + 1 == nIssueCnt) {

                    // 통과 : 업데이트
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] OK!! (UPDATE)");

                    if (!STDAccessKeyManager.updateEntireAdminAccessKey(nIDNo, nIssueCnt)) {
                        // 업데이트에 실패하면 차단한다.
                        LOG("[ctrlAccessSTDRFKey_Admin_Entire] False from STDAccessKeyManager.updateEntireAdminAccessKey(...)");
                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                        sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                        return;
                    }

                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] Entire Admin Pass Info Updated!!");
                    // 업데이트 성공 후 키정보 비교
                    if (AccessKey_STD.aEntireAdminKey[nIDNo] == nIssueCnt) {
                        LOG("[ctrlAccessSTDRFKey_Admin_Entire] OK!! (After UPDATE)");
                        Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                        sendLobbyAccessLog(AccessValues.pass, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                        Global.sendElevCallRequest("null", "null", true);
                        // 동일그룹내 로비폰과 업데이트 키정보 공유 및 동기화한다.
                        Global.sendSTDRFKeyInfo(AccessValues.mcard, 0, 0, nIssueCnt);
                        return;
                    } else {
                        // 차단
                        LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIssueCnt is wrong!! (After UPDATE)");
                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                        sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                        return;
                    }
                } else {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIssueCnt is wrong!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    return;
                }
            }
            //메인서버가 2.0이 아닌 경우, AccessKey 관련 수정 코드 적용. 0인 경우 차단, 0보다 크면 통과, 0보다 작으면 차단으로 적용함
            else {
                if (AccessKey_STD.aEntireAdminKey[nIDNo] == 0) {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIssueCnt is 0!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    return;
                } else if (AccessKey_STD.aEntireAdminKey[nIDNo] > 0) {
                    // 통과
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] OK!!");
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                    sendLobbyAccessLog(AccessValues.pass, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    Global.sendElevCallRequest("null", "null", true);
                    return;
                } else {
                    // 차단
                    LOG("[ctrlAccessSTDRFKey_Admin_Entire] nIssueCnt is wrong!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog(AccessValues.fail, AccessValues.mcard, "null", "null", 0, 0, nIDNo, nIssueCnt, "null");
                    return;
                }
            }

        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Admin_Entire(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Visitor_Residence(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Visitor_Residence] ===== START =====");

            if (ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                if (ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                    int nHo = Integer.parseInt(Info.getHo());
                    if (Global.isExistResi(nHo)) {
                        int nHo_Head = nHo / 100;
                        int nHo_Tail = nHo % 100;
                        int nIssueCnt = Integer.parseInt(Info.getIssueCnt());
                        if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == 0) {
                            // 차단
                        } else if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] == nIssueCnt) {
                            // 통과
                        } else if (AccessKey_STD.aResiKey[nHo_Head][nHo_Tail] + 1 == nIssueCnt) {
                            // 통과 : 업데이트
                        } else {
                            // 차단
                            LOG("[ctrlAccessSTDRFKey_Visitor_Residence] nIssueCnt is wrong!!");
                        }
                    } else {
                        // 차단 : 세대 없음
                        LOG("[ctrlAccessSTDRFKey_Visitor_Residence] Residence does not exist!!");
                    }
                } else {
                    // 차단 : 동 다름
                    LOG("[ctrlAccessSTDRFKey_Visitor_Residence] Dong is wrong!!");
                }
            } else {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Visitor_Residence] Sitecode is wrong!!");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Visitor_Residence(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Visitor_Dong(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Visitor_Dong] ===== START =====");

            if (ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                if (ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                    int nIDNo = Integer.parseInt(Info.getKeyNo());
                    int nIDIssueCnt = Integer.parseInt(Info.getIssueCnt());
                    if (AccessKey_STD.aDongAdminKey[nIDNo] == 0) {
                        // 차단
                    } else if (AccessKey_STD.aDongAdminKey[nIDNo] == nIDIssueCnt) {
                        // 통과
                    } else if (AccessKey_STD.aDongAdminKey[nIDNo] + 1 == nIDIssueCnt) {
                        // 통과 : 업데이트
                    } else {
                        // 차단
                    }
                } else {
                    // 차단 : 동 다름
                    LOG("[ctrlAccessSTDRFKey_Visitor_Dong] Dong is wrong!!");
                }
            } else {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Visitor_Dong] Sitecode is wrong!!");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Visitor_Dong(Info)");
            e.printStackTrace();
        }
    }

    private static void ctrlAccessSTDRFKey_Visitor_Entire(STDReaderKeyInfo Info) {
        try {
            LOG("[ctrlAccessSTDRFKey_Visitor_Entire] ===== START =====");

            if (ConfigValue.strSitecode.equalsIgnoreCase(Info.getSitecode())) {
                if (ConfigValue.strDevice_Dong.equalsIgnoreCase(Info.getDong())) {
                    int nIDNo = Integer.parseInt(Info.getKeyNo());
                    int nIDIssueCnt = Integer.parseInt(Info.getIssueCnt());
                    if (AccessKey_STD.aEntireAdminKey[nIDNo] == 0) {
                        // 차단
                    } else if (AccessKey_STD.aEntireAdminKey[nIDNo] == nIDIssueCnt) {
                        // 통과
                    } else if (AccessKey_STD.aEntireAdminKey[nIDNo] + 1 == nIDIssueCnt) {
                        // 통과 : 업데이트
                    } else {
                        // 차단
                    }
                } else {
                    // 차단 : 동 다름
                    LOG("[ctrlAccessSTDRFKey_Visitor_Entire] Dong is wrong!!");
                }
            } else {
                // 차단 : 현장코드 다름
                LOG("[ctrlAccessSTDRFKey_Visitor_Entire] Sitecode is wrong!!");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSTDRFKey_Visitor_Entire(Info)");
            e.printStackTrace();
        }
    }
    /* [END] Standard Key(I-Park Card) Access Control */

    /* [START] Smart Key Access Control */
    public static void ctrlAccessSmartKey(MultiReaderKeyInfo KeyInfo) {
        try {
            LOG_INFO("[ctrlAccessSmartKey] UID [" + KeyInfo.getUID() + "], SN [" + KeyInfo.getSN() + "]");
            LOG_INFO("[ctrlAccessSmartKey] Sitecode [" + KeyInfo.getSitecode() + "], Dong [" + KeyInfo.getDong() + "], Ho [" + KeyInfo.getHo() + "]");
            LOG_INFO("[ctrlAccessSmartKey] IDNo [" + KeyInfo.getKeyNo() + "], IssueCnt [" + KeyInfo.getIssueCnt() + "], IDType [" + KeyInfo.getIDType() + "]");
            LOG_INFO("[ctrlAccessSmartKey] Direction [" + KeyInfo.getDirection() + "]");

            if (ConfigValue.eLPRole == SetValue.LPRole_CarGate) {
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                LOG("[ctrlAccessSmartKey] This lobbyphone set as cargate lobbyphone!!");
                return;
            }

            // 스마트키 이동방향 확인
            if (KeyInfo.getDirection() != 0x01) {
                LOG_INFO("[ctrlAccessSmartKey] SmartKey direction is inside to outside!! Dinied!!");
                sendReplySmartKeyResult(KeyInfo, false);
                return;
            }

            int nKeyCnt = UIDAccessKeyManager.isKeyExist(KeyInfo.getUID());
            LOG_INFO("[ctrlAccessSmartKey] nKeyCnt [" + nKeyCnt + "]");
            if (nKeyCnt == 0) {
                // 키가 존재하지 않는 경우
                LOG_INFO("[ctrlAccessSmartKey] No Key!! [1]");
                if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] doesn't exist!!!");
                Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                sendLobbyAccessLog_SmartKey(AccessValues.fail, "null", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                sendReplySmartKeyResult(KeyInfo, false);
                return;
            } else if (nKeyCnt > 1) {
                // 중복된 키가 존재하는 경우
                LOG_INFO("[ctrlAccessSmartKey] Duplicated Key!! [1]");
                if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] duplicated!!! nKeyCnt : " + nKeyCnt);
                Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                sendLobbyAccessLog_SmartKey(AccessValues.fail, "null", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                sendReplySmartKeyResult(KeyInfo, false);
                return;
            } else if (nKeyCnt == 1) {
                // 키가 존재하는 경우
                AccessKeyInfo DBKeyInfo = new AccessKeyInfo();
                DBKeyInfo = UIDAccessKeyManager.getDBKey(KeyInfo.getUID());
                if (DBKeyInfo.getUID().equalsIgnoreCase("NONE")) {
                    LOG_INFO("[ctrlAccessSmartKey] No Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail, "NONE", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }
                if (DBKeyInfo.getUID().equalsIgnoreCase("DUPLICATED")) {
                    LOG_INFO("[ctrlAccessSmartKey] Duplicated Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail, "DUPLICATED", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                // Compare KeyInfo from DB with KeyInfo from RFReader
                if (!checkAccessPolicy(DBKeyInfo.getKeyType(), DBKeyInfo.getDong(), DBKeyInfo.getHo())) {
                    LOG_INFO("[ctrlAccessSmartKey] Access Denied by access control policy!!");
                    if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] denied by policy!!!");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.deny, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                if (!DBKeyInfo.getSN().equalsIgnoreCase(KeyInfo.getSN())) {
                    LOG_INFO("[ctrlAccessSmartKey] Different KeyInfo -> SN");
                    if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] SN is wrong!!!");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                if (!ConfigValue.strSitecode.equals(KeyInfo.getSitecode())) {
                    LOG_INFO("[ctrlAccessSmartKey] Different KeyInfo -> Sitecode");
                    if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] sitecode is wrong!!!");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail_site, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                if (!ConfigValue.strDevice_Dong.equals(KeyInfo.getDong())) {
                    LOG_INFO("[ctrlAccessSmartKey] Different KeyInfo -> Dong");
                    if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] dong is wrong!!!");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                if (!DBKeyInfo.getKeyNo().equals(KeyInfo.getKeyNo())) {
                    LOG_INFO("[ctrlAccessSmartKey] Different KeyInfo -> KeyNo");
                    if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] KeyNo is wrong!!!");
                    Global.ctrlLobbyDoorNMent(false, false, 0, true, false);
                    sendLobbyAccessLog_SmartKey(AccessValues.fail, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                    sendReplySmartKeyResult(KeyInfo, false);
                    return;
                }

                // Access Request Accepted!!
                if (Global.bSmartKeyTestMode) sendHandlerMsg(HANDLERMSG.SHOW_SMARTKEY_TOASTMSG, 0, 0, "[SmartKey] access accepted!!!");
                if (ConfigValue.eParcelLink == SetValue.TRUE) {
                    Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, true, false);
                } else {
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, true, false);
                }

                sendLobbyAccessLog_SmartKey(AccessValues.pass, DBKeyInfo.getKeyType(), KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), KeyInfo.getIssueCnt(), AccessValues.IPARK_SmartKey);
                sendReplySmartKeyResult(KeyInfo, true);

                if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.hkey)) {
                    Global.sendElevCallRequest(DBKeyInfo.getDong(), DBKeyInfo.getHo(), true);
                } else if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.dkey) || DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.mkey)) {
                    Global.sendElevCallRequest("null", "null", true);
                }

            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessSmartKey(Info)");
            e.printStackTrace();
        }
    }

    private static boolean checkAccessPolicy(String strKeyType, String strDong, String strHo) {
        try {
            LOG("[checkAccessPolicy] strKeyType [" + strKeyType + "], strDong [" + strDong + "], Ho [" + strHo + "]");

            if (strKeyType.equalsIgnoreCase(AccessValues.hkey)) {
                if (ConfigValue.eRFAccessLevel == SetValue.Level_Line) {
                    if (!ConfigValue.strDevice_Dong.equals(strDong)) {
                        // 동정보 비교
                        LOG_INFO("[checkAccessPolicy] Dong is different!!");
                        return false;
                    }
                    if (!Global.isExistResi(Integer.parseInt(strHo))) {
                        // 세대 존재 유무 확인
                        LOG_INFO("[checkAccessPolicy] Ho is not exist!!");
                        return false;
                    }
                    return true;
                } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Dong) {
                    if (!ConfigValue.strDevice_Dong.equals(strDong)) {
                        // 동정보 비교
                        LOG_INFO("[checkAccessPolicy] Dong is different!!");
                        return false;
                    }
                    return true;
                } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Entire) {
                    return true;
                } else {
                    return false;
                }
            } else if (strKeyType.equalsIgnoreCase(AccessValues.dkey)) {
                if (!ConfigValue.strDevice_Dong.equals(strDong)) {
                    LOG_INFO("[checkAccessPolicy] Dong is different!!");
                    return false;
                }
                return true;
            } else if (strKeyType.equalsIgnoreCase(AccessValues.mkey)) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] checkAccessPolicy(strKeyType, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    private static boolean checkAccessPolicy(String strDong, String strHo) {
        try {
            LOG("[checkAccessPolicy] strDong [" + strDong + "], Ho [" + strHo + "]");

            if (ConfigValue.eRFAccessLevel == SetValue.Level_Line) {
                if (!ConfigValue.strDevice_Dong.equals(strDong)) {
                    // 동정보 비교
                    LOG_INFO("[checkAccessPolicy] Dong is different!!");
                    return false;
                }
                if (!Global.isExistResi(Integer.parseInt(strHo))) {
                    // 세대 존재 유무 확인
                    LOG_INFO("[checkAccessPolicy] Ho dose not exist!!");
                    return false;
                }
                return true;
            } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Dong) {
                if (!ConfigValue.strDevice_Dong.equals(strDong)) {
                    // 동정보 비교
                    LOG_INFO("[checkAccessPolicy] Dong is different!!");
                    return false;
                }
                return true;
            } else if (ConfigValue.eRFAccessLevel == SetValue.Level_Entire) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] checkAccessPolicy(String strDong, String strHo)");
            e.printStackTrace();
            return false;
        }
    }

    public static void sendReplySmartKeyResult(MultiReaderKeyInfo Info, boolean bPass) {
        try {
            LOG("[sendReplyStartKey] ===== START =====");
            byte[] hReplyData = new byte[22];

            byte[] hSitecode = Global.StringToHex(Info.getSitecode());
            byte[] hUID = AES_128.Encrypt(ENCRYPTTYPE.NORMAL, Global.StringToHex(Info.getUID()));
            byte[] hDong = Global.StringToHex(Info.getSitecode());
            byte[] hHo = Global.StringToHex(Info.getSitecode());
            byte hKeyNo = (byte) Integer.parseInt(Info.getKeyNo());
            byte hKeyType = Info.getIDType();
            byte hDirection = Info.getDirection();
            byte hAccessResult = 0x02;
            if (bPass) hAccessResult = 0x01;
            else hAccessResult = 0x02;

            hReplyData[0] = hUID[0];
            hReplyData[1] = hUID[1];
            hReplyData[2] = hUID[2];
            hReplyData[3] = hUID[3];
            hReplyData[4] = 0x00;
            hReplyData[5] = 0x00;
            hReplyData[6] = 0x00;
            hReplyData[7] = 0x00;
            hReplyData[8] = hSitecode[0];
            hReplyData[9] = hSitecode[1];
            hReplyData[10] = hSitecode[2];
            hReplyData[11] = hSitecode[3];
            hReplyData[12] = hDong[0];
            hReplyData[13] = hDong[1];
            hReplyData[14] = hHo[0];
            hReplyData[15] = hHo[1];
            hReplyData[16] = hKeyNo;
            hReplyData[17] = 0x00;
            hReplyData[18] = 0x00;
            hReplyData[19] = hAccessResult;
            hReplyData[20] = hKeyType;
            hReplyData[21] = hDirection;

            HDCStandardReaderSerial.sendReplySmartKeyAccess(bPass, hReplyData);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendReplySmartKey(Info, bPass)");
            e.printStackTrace();
        }
    }
    /* [END] Smart Key Access Control */

    /* [START] Mifare Key Access Control */
    public static void ctrlAccessMifareKey(MultiReaderKeyInfo KeyInfo) {
        try {
            LOG_INFO("[ctrlAccessMifareKey] UID [" + KeyInfo.getUID() + "], SN [" + KeyInfo.getSN() + "]");

            if (ConfigValue.eLPRole == SetValue.LPRole_CarGate) {
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                LOG("[ctrlAccessMifareKey] This lobbyphone set as cargate lobbyphone!!");
                return;
            }

            int nKeyCnt = UIDAccessKeyManager.isKeyExist(KeyInfo.getUID());
            LOG_INFO("[ctrlAccessMifareKey] nKeyCnt [" + nKeyCnt + "]");
            if (nKeyCnt == 0) {
                // 키가 존재하지 않는 경우
                LOG_INFO("[ctrlAccessMifareKey] No Key!! [1]");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_Mifare(AccessValues.fail, "NONE", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), AccessValues.Mifare);
                return;
            } else if (nKeyCnt > 1) {
                // 중복된 키가 존재하는 경우
                LOG_INFO("[ctrlAccessMifareKey] Duplicated Key!! [1]");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_Mifare(AccessValues.fail, "DUPLICATED", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), AccessValues.Mifare);
                return;
            } else if (nKeyCnt == 1) {
                // 키가 존재하는 경우
                AccessKeyInfo DBKeyInfo = new AccessKeyInfo();
                DBKeyInfo = UIDAccessKeyManager.getDBKey(KeyInfo.getUID());
                if (DBKeyInfo.getUID().equalsIgnoreCase("NONE")) {
                    LOG_INFO("[ctrlAccessMifareKey] No Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_Mifare(AccessValues.fail, "NONE", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), AccessValues.Mifare);
                    return;
                }
                if (DBKeyInfo.getUID().equalsIgnoreCase("DUPLICATED")) {
                    LOG_INFO("[ctrlAccessMifareKey] Duplicated Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_Mifare(AccessValues.fail, "DUPLICATED", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), KeyInfo.getKeyNo(), AccessValues.Mifare);
                    return;
                }

                // Compare KeyInfo from DB with KeyInfo from RFReader
                if (!checkAccessPolicy(DBKeyInfo.getKeyType(), DBKeyInfo.getDong(), DBKeyInfo.getHo())) {
                    LOG_INFO("[ctrlAccessMifareKey] Access Denied by access control policy!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_Mifare(AccessValues.deny, DBKeyInfo.getKeyType(), DBKeyInfo.getUID(), DBKeyInfo.getSN(), DBKeyInfo.getDong(), DBKeyInfo.getHo(), DBKeyInfo.getKeyNo(), AccessValues.Mifare);
                    return;
                }

                // Access Request Accepted!!
                if (ConfigValue.eParcelLink == SetValue.TRUE) {
                    Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
                } else {
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                }

                sendLobbyAccessLog_Mifare(AccessValues.pass, DBKeyInfo.getKeyType(), DBKeyInfo.getUID(), DBKeyInfo.getSN(), DBKeyInfo.getDong(), DBKeyInfo.getHo(), DBKeyInfo.getKeyNo(), AccessValues.Mifare);

                if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.hkey)) {
                    Global.sendElevCallRequest(DBKeyInfo.getDong(), DBKeyInfo.getHo(), true);
                }
                else if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.dkey) || DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.mkey)) {
                    Global.sendElevCallRequest("null", "null", true);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessMifareKey(Info)");
            e.printStackTrace();
        }
    }

    public static void ctrlAccessExternalMifareKey(MultiReaderKeyInfo KeyInfo) {
        try {
            LOG_INFO("[ctrlAccessExternalMifareKey] UID [" + KeyInfo.getUID() + "], SN [" + KeyInfo.getSN() + "]");
            if (ConfigValue.eExternalOnePassLink != SetValue.TRUE) {
                // 타사 원패스 연동
                LOG_INFO("[ctrlAccessExternalMifareKey] ExternalOnePassLink is not set!!");
                return;
            }

            if (ConfigValue.eLPRole == SetValue.LPRole_CarGate) {
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                LOG("[ctrlAccessExternalMifareKey] This lobbyphone set as cargate lobbyphone!!");
                return;
            }

            send_get_accesskey_info_request_UID(KeyInfo.getUID());

        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessExternalMifareKey(MultiReaderKeyInfo KeyInfo)");
            e.printStackTrace();
        }
    }

    public static boolean send_get_accesskey_info_request_UID(final String strUID) {
        try {
            final Request_get_accesskey_info get_accesskey_info = new Request_get_accesskey_info();
            if (get_accesskey_info.send_get_accesskey_info_request_UID(ConfigValue.strMonitoringPCIPAddress, strUID, "null")) {
                get_accesskey_info.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_get_accesskey_info_request_UID] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            procAccessCtrlExternalMifareKeybyReply(get_accesskey_info);
                        }
                        else {
                            Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                            sendLobbyAccessLog_Mifare(AccessValues.fail, "NONE", strUID, "", "", "", "", AccessValues.Mifare);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_get_accesskey_info_request_UID(final String strUID)");
            e.printStackTrace();
            return false;
        }
    }

    public static void procAccessCtrlExternalMifareKeybyReply(Request_get_accesskey_info get_accesskey_info) {
        try {
            LOG_INFO("[procAccessCtrlExternalMifareKeybyReply]");

            String strKeyType = "", strKeyDong = "", strKeyHo = "", strKeyCnt = "";
            String strKeyIndex = "", strKeySN = "", strKeyUID = "", strKeyNo = "", strKeyIssueCnt = "", strKeyIssuedDate = "", strKeyMessage = "";
            byte IDType = (byte) 0x00;   // 0x00 : 입주자 카드, 0x01 : 마스터 카드, 0x02 : 방문자 카드

            strKeyType = get_accesskey_info.getItemValue("key_type");
            if (strKeyType.equalsIgnoreCase(AccessValues.hkey)) IDType = (byte) 0x00;
            else IDType = (byte) 0x01;
            get_accesskey_info.setItem(strKeyType + "_info");
            strKeyDong = get_accesskey_info.getAttributeValue(0, "dong");
            strKeyHo = get_accesskey_info.getAttributeValue(0, "ho");
            strKeyCnt = get_accesskey_info.getAttributeValue(0, "count");

            get_accesskey_info.setItem("key_info");
            strKeyIndex = get_accesskey_info.getAttributeValue(0, "index");
            strKeySN = get_accesskey_info.getAttributeValue(0, "sn");
            strKeyUID = get_accesskey_info.getAttributeValue(0, "uid");
            strKeyNo = get_accesskey_info.getAttributeValue(0, "key_num");
            strKeyIssueCnt = get_accesskey_info.getAttributeValue(0, "issue_cnt");
            strKeyIssuedDate = get_accesskey_info.getAttributeValue(0, "issued_date");
            strKeyMessage = get_accesskey_info.getAttributeValue(0, "message");

            Log.i(TAG, "[procAccessCtrlExternalMifareKeybyReply] strKeyType [" + strKeyType + "], strKeyDong [" + strKeyDong + "], strKeyHo [" + strKeyHo + "], strKeyCnt [" + strKeyCnt + "]");
            Log.i(TAG, "[procAccessCtrlExternalMifareKeybyReply] strKeyIndex [" + strKeyIndex + "], strKeySN [" + strKeySN + "], strKeyUID [" + strKeyUID + "], strKeyNo [" + strKeyNo + "], " +
                    "strKeyIssueCnt [" + strKeyIssueCnt + "], strKeyIssuedDate [" + strKeyIssuedDate + "], strKeyMessage [" + strKeyMessage + "]");

            // 지원하는 키인지 확인한다.
            if (!(strKeyType.equalsIgnoreCase(AccessValues.hkey)
                    || strKeyType.equalsIgnoreCase(AccessValues.dkey)
                    || strKeyType.equalsIgnoreCase(AccessValues.mkey))) {
                Log.w(TAG, "[procAccessCtrlExternalMifareKeybyReply] KeyType is wrong!!! -> " + strKeyType);
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_Mifare(AccessValues.deny, strKeyType, strKeyUID, strKeySN, strKeyDong, strKeyHo, strKeyNo, AccessValues.Mifare);
                return;
            }

            if (!checkAccessPolicy(strKeyType, strKeyDong, strKeyHo)) {
                Log.w(TAG, "[procAccessCtrlExternalMifareKeybyReply] Access Denied by access control policy!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_Mifare(AccessValues.deny, strKeyType, strKeyUID, strKeySN, strKeyDong, strKeyHo, strKeyNo, AccessValues.Mifare);
                return;
            }

            // Access Request Accepted!!
            if (ConfigValue.eParcelLink == SetValue.TRUE) {
                Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
            }
            else {
                Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
            }

            sendLobbyAccessLog_Mifare(AccessValues.pass, strKeyType, strKeyUID, strKeySN, strKeyDong, strKeyHo, strKeyNo, AccessValues.Mifare);

            if (strKeyType.equalsIgnoreCase(AccessValues.hkey)) {
                Global.sendElevCallRequest(strKeyDong, strKeyHo, true);
            }
            else if (strKeyType.equalsIgnoreCase(AccessValues.dkey) || strKeyType.equalsIgnoreCase(AccessValues.mkey)) {
                Global.sendElevCallRequest("null", "null", true);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessMifareKey(Info)");
            e.printStackTrace();
        }
    }
    /* [END] Mifare Key Access Control */

    /* [START] TMoney Key Access Control */
    public static void ctrlAccessTMoneyKey(MultiReaderKeyInfo KeyInfo) {
        try {
            LOG_INFO("[ctrlAccessTMoneyKey] UID [" + KeyInfo.getUID() + "], SN [" + KeyInfo.getSN() + "]");

            if (ConfigValue.eLPRole == SetValue.LPRole_CarGate) {
                MainActivity.mSound.PlayMent_lobby(R.raw.confirmsetting);
                LOG("[ctrlAccessTMoneyKey] This lobbyphone set as cargate lobbyphone!!");
                return;
            }

            int nKeyCnt = UIDAccessKeyManager.isKeyExist(KeyInfo.getUID());
            LOG_INFO("[ctrlAccessTMoneyKey] nKeyCnt [" + nKeyCnt + "]");
            if (nKeyCnt == 0) {
                // 키가 존재하지 않는 경우
                LOG_INFO("[ctrlAccessTMoneyKey] No Key!! [1]");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_TMoney(AccessValues.fail, "NONE", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), AccessValues.TMoney);
                return;
            } else if (nKeyCnt > 1) {
                // 중복된 키가 존재하는 경우
                LOG_INFO("[ctrlAccessTMoneyKey] Duplicated Key!! [1]");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_TMoney(AccessValues.fail, "DUPLICATED", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), AccessValues.TMoney);
                return;
            } else if (nKeyCnt == 1) {
                // 키가 존재하는 경우
                AccessKeyInfo DBKeyInfo = new AccessKeyInfo();
                DBKeyInfo = UIDAccessKeyManager.getDBKey(KeyInfo.getUID());
                if (DBKeyInfo.getUID().equalsIgnoreCase("NONE")) {
                    LOG_INFO("[ctrlAccessTMoneyKey] No Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_TMoney(AccessValues.fail, "NONE", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), AccessValues.TMoney);
                    return;
                }
                if (DBKeyInfo.getUID().equalsIgnoreCase("DUPLICATED")) {
                    LOG_INFO("[ctrlAccessTMoneyKey] Duplicated Key!! [2]");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_TMoney(AccessValues.fail, "DUPLICATED", KeyInfo.getUID(), KeyInfo.getSN(), KeyInfo.getDong(), KeyInfo.getHo(), AccessValues.TMoney);
                    return;
                }

                // Compare KeyInfo from DB with KeyInfo from RFReader
                if (!checkAccessPolicy(DBKeyInfo.getKeyType(), DBKeyInfo.getDong(), DBKeyInfo.getHo())) {
                    LOG_INFO("[ctrlAccessTMoneyKey] Access Denied by access control policy!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_TMoney(AccessValues.deny, DBKeyInfo.getKeyType(), DBKeyInfo.getUID(), DBKeyInfo.getSN(), DBKeyInfo.getDong(), DBKeyInfo.getHo(), AccessValues.TMoney);
                    return;
                }

                // Access Request Accepted!!
                if (ConfigValue.eParcelLink == SetValue.TRUE) {
                    Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
                } else {
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                }

                sendLobbyAccessLog_TMoney(AccessValues.pass, DBKeyInfo.getKeyType(), DBKeyInfo.getUID(), DBKeyInfo.getSN(), DBKeyInfo.getDong(), DBKeyInfo.getHo(), AccessValues.TMoney);

                if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.hkey)) {
                    Global.sendElevCallRequest(DBKeyInfo.getDong(), DBKeyInfo.getHo(), true);
                } else if (DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.dkey) || DBKeyInfo.getKeyType().equalsIgnoreCase(AccessValues.mkey)) {
                    Global.sendElevCallRequest("null", "null", true);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessMifareKey(Info)");
            e.printStackTrace();
        }
    }
    /* [END] TMoney Key Access Control */

    /* [START] Call Access Control */
    public static String strLobbyOpenRequestIP = null;
    public static void ctrlAccessbyCall(Socket Sock, String strRemoteSender) {
        try {
            // 통화상대와 IP 정보를 비교한다.
            String strDong = null, strHo = null, strIP = null;

            LOG("[ctrlAccessbyCall] Sock = " + Sock + ", strRemoteSender = " + strRemoteSender);
            if (strLobbyOpenRequestIP == null) {
                strLobbyOpenRequestIP = Sock.getInetAddress().getHostAddress();
                Log.w(TAG, "[ctrlAccessbyCall] strLobbyOpenRequestIP [" + strLobbyOpenRequestIP +"]");
            }
            else {
                Log.w(TAG, "[ctrlAccessbyCall] ctrlAccessbyCall function has done!!!");
                iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_lobby_open(false));
                return;
            }

            if (strRemoteSender.matches(".*경비.*")) {
                // 경비실에서 문을 열어줌
                Global.stopMelodyRepeat();
                Global.changeVolumeMoIPMode(CALLTYPE.NONE);
                Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_lobby_open(true));
                sendLobbyAccessLog(AccessValues.pass, AccessValues.call, EthernetCtrl.getRemoteIPAddress(Sock), strRemoteSender, 0, 0, 0, 0, "null");
                Global.sendElevCallRequest("null", "null", true);
                MainActivity.mCallController.setDelayQuitMoIPCall(MainActivity.mCallController.SEC_DOOROPEN_DELAYQUITCALL);
            }
            else if (strRemoteSender.matches(".*동.*") && strRemoteSender.matches(".*호.*")) {
                // 세대인 경우 택배를 확인합니다.
                Global.stopMelodyRepeat();
                Global.changeVolumeMoIPMode(CALLTYPE.NONE);
                if (ConfigValue.eParcelLink == SetValue.TRUE) {
                    // 택배 연동
                    Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
                }
                else {
                    // 택배 미연동
                    Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
                }
//                Log.d(TAG, "[ctrlAccessbyCall] getRemoteIPAddress [" + EthernetCtrl.getRemoteIPAddress(Sock) + "]");
                MainActivity.mCallController.setDelayQuitMoIPCall(MainActivity.mCallController.SEC_DOOROPEN_DELAYQUITCALL);
                iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_lobby_open(true));
                sendLobbyAccessLog(AccessValues.pass, AccessValues.call, EthernetCtrl.getRemoteIPAddress(Sock), strRemoteSender, 0, 0, 0, 0, "null");
                sendElevCallRequestbyCall(EthernetCtrl.getRemoteIPAddress(Sock));



//                iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_lobby_open(true));
//
//                strDong = strRemoteSender.split(" ")[0];
//                strHo = strRemoteSender.split(" ")[1];
//                strIP = EthernetCtrl.makeIPAddress(DeviceType.RESIDENCE, strDong.substring(0, strDong.length() - 1), strHo.substring(0, strHo.length() - 1));
//                Log.d(TAG, "[ctrlAccessbyCall] strDong [" + strDong +"], strHo [" + strHo + "], strIP [" + strIP + "]");
//
//                sendLobbyAccessLog(AccessValues.pass, AccessValues.call, strIP, strRemoteSender, 0, 0, 0, 0, "null");
//                sendElevCallRequestbyCall(strIP);
//                MainActivity.mCallController.setDelayQuitMoIPCall(MainActivity.mCallController.SEC_DOOROPEN_DELAYQUITCALL);
            }
            else {
                Global.stopMelodyRepeat();
                Global.changeVolumeMoIPMode(CALLTYPE.NONE);
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_lobby_open(false));
                sendLobbyAccessLog(AccessValues.fail, AccessValues.call, strIP, strRemoteSender, 0, 0, 0, 0, "null");
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessbyCall(Sock, SetSender)");
            e.printStackTrace();
        }
    }

    private static void sendElevCallRequestbyCall(String strIP) {
        try {
            // Send elev_call.request by extracting from IP address
            LOG("[sendElevCallRequestbyCall] strIP [" + strIP + "]");
            String[] strParse_01 = strIP.split("\\.");
            String strDong = Integer.toString(((Integer.parseInt(ConfigValue.strDevice_Dong) / 100) * 100) + Integer.parseInt(strParse_01[1]));
            String strHo = strParse_01[2] + Global.ZeroPadding_Head(2, strParse_01[3]);
            Global.sendElevCallRequest(strDong, strHo, true);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendElevCallRequestbyCall(strIP)");
            e.printStackTrace();
        }
    }
    /* [END] Call Access Control */

    /* [START] Bio-information Access Control */
    public static void ctrlAccessBioInformation(String strRecogType, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName) {
        try {
            LOG("[ctrlAccessBioInformation] strRecogType [" + strRecogType + "], strRecogResult [" + strRecogResult + "], strRecogReason [" + strRecogReason + "], strOwnerID [" + strOwnerID + "], strOwnerName [" + strOwnerName + "]");

            String[] straID;
            String strIDType = "", strIDDong = "", strIDHo = "", strIDNo = "";

            try {
                straID = strOwnerID.split(":");
                strIDType = straID[0];
                straID = straID[1].split("-");
                strIDDong = straID[0];
                strIDHo = straID[1];
                strIDNo = straID[2];
                LOG("[ctrlAccessBioInformation] strIDType [" + strIDType + "], strIDDong [" + strIDDong + "], strIDHo [" + strIDHo + "], strIDNo [" + strIDNo + "]");
            } catch (Exception e) {
                Log.e(TAG, "[Exception] ctrlAccessBioInformation(String strRecogType, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName)");
                Log.e(TAG, "[Exception] Parsing error!! -> parsing target is strOwnerID");
            }

            // 인증여부 확인
            if (!strRecogResult.equals(Declare.BioInfoResult.ACCEPTED.toString().toLowerCase())) {
                Log.w(TAG, "[ctrlAccessBioInformation] strRecogResult is not accepted!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_BioInfo(AccessValues.fail, AccessValues.fingerprint.toLowerCase(), strRecogResult, strRecogReason, strOwnerID, strOwnerName);
                return;
            }

            // 등록여부 확인
            if (!strRecogReason.equals(Declare.BioInfoReason.LISTED.toString().toLowerCase())) {
                Log.w(TAG, "[ctrlAccessBioInformation] strRecogReason is not listed!!");
                Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                sendLobbyAccessLog_BioInfo(AccessValues.fail, AccessValues.fingerprint.toLowerCase(), strRecogResult, strRecogReason, strOwnerID, strOwnerName);
                return;
            }

            // 출입정책 확인
            if (strIDType.equalsIgnoreCase(Declare.BioInfoOwner.RESIDENT.toString().toLowerCase())) {
                if (!checkAccessPolicy(strIDDong, strIDHo)) {
                    Log.w(TAG, "[ctrlAccessBioInformation] Denied by policy!!");
                    Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                    sendLobbyAccessLog_BioInfo(AccessValues.fail, AccessValues.fingerprint.toLowerCase(), strRecogResult, strRecogReason, strOwnerID, strOwnerName);
                    return;
                }
            }
            else if (strIDType.equalsIgnoreCase(Declare.BioInfoOwner.VISITOR.toString().toLowerCase())) {
                if (!strIDDong.equalsIgnoreCase("0") && !strIDHo.equalsIgnoreCase("0")) {
                    // 세대방문자
                    if (!checkAccessPolicy(strIDDong, strIDHo)) {
                        Log.w(TAG, "[ctrlAccessBioInformation] Denied by policy!!");
                        Global.ctrlLobbyDoorNMent(false, true, 0, false, false);
                        sendLobbyAccessLog_BioInfo(AccessValues.fail, AccessValues.fingerprint.toLowerCase(), strRecogResult, strRecogReason, strOwnerID, strOwnerName);
                        return;
                    }
                }
            }

            // 출입 성공
            if (ConfigValue.eParcelLink == SetValue.TRUE) {
                // 택배 연동
                Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
            } else {
                // 택배 미연동
                Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
            }

            sendLobbyAccessLog_BioInfo(AccessValues.pass, AccessValues.fingerprint.toLowerCase(), strRecogResult, strRecogReason, strOwnerID, strOwnerName);

            Global.sendElevCallRequest(strIDDong, strIDHo, true);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessBioInformation(String strRecogType, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName)");
            e.printStackTrace();
        }
    }
    /* [END] Bio-information Access Control */

    /* [START] OnePass Access Control */

    /*
    * 원패스 관련코드
    * 원패스 동작 시나리오
        1. 스마트폰에서 로비폰 비콘 수신하면 원패스 서버로 문열림 요청 메시지를 전송 (UUID, 별명 포함)
        2. 서버는 휴대폰의 UUID와 별명, 출입하고자 하는 로비폰의 IP를 월패드로 전송
        3. 월패드는 수신된 UUID를 DB검색하여 출입여부 결정
        4. 결정된 출입여부를 해당 로비폰으로 전송
        5. 로비폰은 출입여부에 따라 아래와 같이 동작
            - 성공 : 외부 센서가 감지되면 로비폰 문열림 (내부센서 감지시 무시), 단지서버로 출입이력 전송
            - 실패 : 단지서버로 출입이력 전송 (출입 실패)
            - 외부, 내부 센서를 통해 진행방향을 판단하며, 내부->외부로 이동하는 경우 문을 열지 않음

    * 로비폰 세부 시나리오
        1. 월패드로부터 출입요청이 수신된 시간을 기록
        2. 외부센서 감지시 출입요청 시간과 센서감지시간의 차(X)가 일정범위내에 속하면 문열림 동작 수행함
            - X는 기본 5초로 하며, 설정가능하도록 한다.
    */
    public static long lOnePassAvailableTime = 0;

    public static void ctrlOnePassAccess() {
        try {
            Log.w(TAG, "[ctrlOnePassAccess] The door open by OnePass!!!");
            if (ConfigValue.eParcelLink == SetValue.TRUE) {
                Global.ctrlLobbyDoorNMent(true, false, ConfigValue.nDoorOpenDuration, false, false);
            } else {
                Global.ctrlLobbyDoorNMent(true, true, ConfigValue.nDoorOpenDuration, false, false);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlOnePassAccess()");
            e.printStackTrace();
        }
    }

    public static void ctrlAccessOnePass(String strAction, String strWallPadIP, int nDong, int nHo, String strName, String strMessage) {
        try {
            LOG("[ctrlAccessOnePass] strAction [" + strAction + "], strWallPadIP [" + strWallPadIP + "], nDong [" + nDong + "], nHo [" + nHo + "], strName [" + strName + "]");
            if (Global.bOnePassTestMode) MainActivity.mSound.Play_lobby(R.raw.onepass);

            if (strAction.equalsIgnoreCase("ok")) {
                MainActivity.setOnePassRequestedTime();
                sendLobbyAccessLog_OnePass(AccessValues.pass, AccessValues.onepass, strWallPadIP, nDong, nHo, strName);
            }
            else if (strAction.equalsIgnoreCase("fail")) {
                Global.ctrlLobbyDoorNMent(false, true, 0, true, false);
                sendLobbyAccessLog_OnePass(AccessValues.fail, AccessValues.onepass, strWallPadIP, nDong, nHo, strName);
            }
            else if (strAction.equalsIgnoreCase("deny")) {
                Global.ctrlLobbyDoorNMent(false, true, 0, true, false);
                sendLobbyAccessLog_OnePass(AccessValues.deny, AccessValues.onepass, strWallPadIP, nDong, nHo, strName);
            }
            else {
                Global.ctrlLobbyDoorNMent(false, true, 0, true, false);
                sendLobbyAccessLog_OnePass(AccessValues.fail, AccessValues.onepass, strWallPadIP, nDong, nHo, strName);
            }

        } catch (Exception e) {
            Log.e(TAG, "[Exception] ctrlAccessOnePass(String strAction, String strTryby, String strWallPadIP, int nDong, int nHo, String strName)");
            e.printStackTrace();
        }
    }

    /* [END] OnePass Access Control */

    /* [START] Send Lobby Access Log */
    public static void sendLobbyAccessLog(String sAction, String sTryby, String CounterpartIPAddress, String strRemoteSender, int nDong, int nHo, int nCardNo, int nIssueCnt, String strAccessPW) {
        try {
            LOG("[sendLobbyAccessLog] sAction [" + sAction + "], sTryby [" + sTryby + "], CounterpartIPAddress [" + CounterpartIPAddress + "], strRemoteSender [" + strRemoteSender + "]");
            LOG("[sendLobbyAccessLog] nDong [" + nDong + "], nHo [" + nHo + "], nCardNo [" + nCardNo + "], nIssueCnt [" + nIssueCnt + "], strAccessPW [" + strAccessPW + "]");
            String strLogMsg = "";
            String strAccessResult = "";
            String strFailReason = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                strAccessResult = "성공";
            } else if (sAction.equalsIgnoreCase(AccessValues.fail)) {
                strAccessResult = "차단";
                strFailReason = " - " + strAccessPW;
            } else if (sAction.equalsIgnoreCase(AccessValues.fail_site)) {
                strAccessResult = "차단(현장코드)";
                strFailReason = " - " + strAccessPW;
            } else if (sAction.equalsIgnoreCase(AccessValues.deny)) {
                strAccessResult = "차단(정책)";
                strFailReason = " - " + strAccessPW;
            } else {
                strAccessResult = "NONE";
            }

            if (sTryby.equalsIgnoreCase(AccessValues.mpasswd)) {
                strLogMsg = "공용 출입비밀번호에 의한 출입 " + strAccessResult + strFailReason;
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.call)) {
                strLogMsg = strRemoteSender + "에 의한 문열림 " + strAccessResult + strFailReason;
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.onepass)) {
                strLogMsg = nDong + "동 " + nHo + "호 원패스에 의한 출입 " + strAccessResult + " - " + strAccessPW;
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.card)) {
                strLogMsg = nDong + "동 " + nHo + "호 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.dcard)) {
                strLogMsg = nDong + "동 마스터 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_lobby_access_request(sAction, sTryby, nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.mcard)) {
                strLogMsg = "단지 마스터 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_lobby_access_request(sAction, sTryby, nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.passwd)) {
                strLogMsg = "세대비밀번호에 의한 출입 " + strAccessResult + strFailReason;
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.adminpw)) {
                strLogMsg = "관리자 출입비밀번호에 의한 출입 " + strAccessResult + strFailReason;
                send_save_lobby_access_request(sAction, sTryby, CounterpartIPAddress, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.V_hcard)) {
                strLogMsg = nDong + "동 " + nHo + "호 방문자 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_vcard_access(sAction, sTryby, Integer.toString(nDong), Integer.toString(nHo), nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.V_dcard)) {
                strLogMsg = nDong + "동 방문자 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_vcard_access(sAction, sTryby, Integer.toString(nDong), Integer.toString(nHo), nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.V_mcard)) {
                strLogMsg = "단지 방문자 카드에 의한 출입 " + strAccessResult + " - " + nCardNo + "번 카드 " + nIssueCnt + "번째";
                send_save_vcard_access(sAction, sTryby, Integer.toString(nDong), Integer.toString(nHo), nCardNo, nIssueCnt, strLogMsg);
            } else if (sTryby.equalsIgnoreCase(AccessValues.card_fail)) {
                strLogMsg = "알수없는 카드에 의한 출입 " + strAccessResult + " :: [동:" + nDong + "], [호: " + nHo + "], [카드번호: " + nCardNo + "], [발급횟수: " + nIssueCnt + "]";
                send_save_lobby_access_request(sAction, sTryby, nCardNo, nIssueCnt, strLogMsg);
            } else {
                LOG("[sendLobbyAccessLog] sTryby is wrong : " + sTryby);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog(String sAction, String sTryby, String CounterpartIPAddress, String strRemoteSender, int nDong, int nHo, int nCardNo, int nIssueCnt, String strAccessPW)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_OnePass(String sAction, String sTryby, String sWallPadIP, int nDong, int nHo, String strAccessPW) {
        try {
            LOG("[sendLobbyAccessLog] sAction [" + sAction + "], sTryby [" + sTryby + "], sWallPadIP [" + sWallPadIP + "]");
            LOG("[sendLobbyAccessLog] nDong [" + nDong + "], nHo [" + nHo + "], strAccessPW [" + strAccessPW + "]");
            String strLogMsg = "";
            String strAccessResult = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                strAccessResult = "요청";
            }
            else if (sAction.equalsIgnoreCase(AccessValues.fail)) {
                strAccessResult = "차단";
            }
            else if (sAction.equalsIgnoreCase(AccessValues.deny)) {
                strAccessResult = "차단(정책)";
            }
            else {
                strAccessResult = "NONE";
            }

            if (sTryby.equalsIgnoreCase(AccessValues.onepass)) {
                strLogMsg = nDong + "동 " + nHo + "호 원패스에 의한 출입 " + strAccessResult + " - " + strAccessPW;
                send_save_lobby_access_request_OnePass(sAction, sTryby, sWallPadIP, strLogMsg);
            }
            else {
                LOG("[sendLobbyAccessLog] sTryby is wrong : " + sTryby);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_OnePass(String sAction, String sTryby, String sWallPadIP, int nDong, int nHo, String strAccessPW)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_BioInfo(String strAction, String strTryby, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName) {
        try {
            LOG("[sendLobbyAccessLog_BioInfo] strAction [" + strAction + "], strTryby [" + strTryby + "], strRecogResult [" + strRecogResult + "], strRecogReason [" + strRecogReason + "], strOwnerID [" + strOwnerID + "], strOwnerName [" + strOwnerName + "]");
            String strLogMsg = "";
            String strOwnerResult = "";
            String strAccessResult = "";
            String strTailInfo = "";
            String strOwnerType = "";

            String[] straID;
            String strIDType = "", strIDDong = "", strIDHo = "", strIDNo = "";

            try {
                if (strOwnerID.equalsIgnoreCase("null")) {
                    strOwnerType = "알수없는자";
                    strIDDong = "none";
                    strIDHo = "none";
                    strIDNo = "none";
                }
                else {
                    straID = strOwnerID.split(":");
                    strIDType = straID[0];
                    straID = straID[1].split("-");
                    strIDDong = straID[0];
                    strIDHo = straID[1];
                    strIDNo = straID[2];
                }
            } catch (Exception e) {
                Log.e(TAG, "[Exception] sendLobbyAccessLog(String sAction, String sTryby, String CounterpartIPAddress, String strRemoteSender, int nDong, int nHo, int nCardNo, int nIssueCnt, String strAccessPW)");
                e.printStackTrace();
                strOwnerType = "알수없는자";
                strIDDong = "none";
                strIDHo = "none";
                strIDNo = "none";
            }

            LOG("[sendLobbyAccessLog_BioInfo] strIDType [" + strIDType + "], strIDDong [" + strIDDong + "], strIDHo [" + strIDHo + "], strIDNo [" + strIDNo + "]");
            if (strIDType.equals(Declare.BioInfoOwner.RESIDENT.toString().toLowerCase())) {
                strOwnerType = "입주자";
                strOwnerResult = strIDDong + "동 " + strIDHo + "호 " + strIDNo + "번째 " + strOwnerType;
            }
            else if (strIDType.equals(Declare.BioInfoOwner.ZONEMASTER.toString().toLowerCase())) {
                strOwnerType = "동관리자";
                strOwnerResult = strIDDong + "동 " + strIDNo + "번째 " + strOwnerType;
            }
            else if (strIDType.equals(Declare.BioInfoOwner.ENTIREMASTER.toString().toLowerCase())) {
                strOwnerType = "단지관리자";
                strOwnerResult = strIDNo + "번째 " + strOwnerType;
            }
            else if (strIDType.equals(Declare.BioInfoOwner.VISITOR.toString().toLowerCase())) {
                strOwnerType = "방문자";
                strOwnerResult = strIDDong + "동 " + strIDHo + "호 " + strIDNo + "번째 " + strOwnerType;
            }
            else {
                strOwnerType = "알수없는자";
                strOwnerResult = strOwnerType;
            }


           if (strAction.equalsIgnoreCase(AccessValues.pass)) {
               if (strRecogReason.equalsIgnoreCase(Declare.BioInfoReason.LISTED.toString().toLowerCase())) {
                   strAccessResult = "성공";
                   strTailInfo = " [" + strOwnerName + "]";
               }
            } else if (strAction.equalsIgnoreCase(AccessValues.fail)) {
               if (strRecogReason.equalsIgnoreCase(Declare.BioInfoReason.UNLISTED.toString().toLowerCase())) {
                   strAccessResult = "차단 (미등록)";
                   strTailInfo = " [" + strOwnerName + "]";
               }
               else if (strRecogReason.equalsIgnoreCase(Declare.BioInfoReason.POLICY.toString().toLowerCase())) {
                   strAccessResult = "차단 (출입정책)";
                   strTailInfo = " [" + strOwnerName + "]";
               }
               else {
                   strAccessResult = "차단";
                   strTailInfo = " [" + strOwnerName + "]";
               }
            } else {
                strAccessResult = "NONE";
            }

            if (strTryby.equalsIgnoreCase(AccessValues.fingerprint)) {
                strLogMsg = strOwnerResult + " 지문에 의한 출입 " + strAccessResult + strTailInfo;
                send_save_lobby_access_request(strAction, strTryby, strRecogResult, strRecogReason, strOwnerID, strOwnerName, strLogMsg);
            } else if (strTryby.equalsIgnoreCase(AccessValues.iris)) {
                strLogMsg = strOwnerResult + " 홍채에 의한 출입 " + strAccessResult + strTailInfo;
                send_save_lobby_access_request(strAction, strTryby, strRecogResult, strRecogReason, strOwnerID, strOwnerName, strLogMsg);
            } else if (strTryby.equalsIgnoreCase(AccessValues.vein)) {
                strLogMsg = strOwnerResult + " 정맥에 의한 출입 " + strAccessResult + strTailInfo;
                send_save_lobby_access_request(strAction, strTryby, strRecogResult, strRecogReason, strOwnerID, strOwnerName, strLogMsg);
            } else if (strTryby.equalsIgnoreCase(AccessValues.face)) {
                strLogMsg = strOwnerResult + " 안면에 의한 출입 " + strAccessResult + strTailInfo;
                send_save_lobby_access_request(strAction, strTryby, strRecogResult, strRecogReason, strOwnerID, strOwnerName, strLogMsg);
            } else {
                LOG("[sendLobbyAccessLog_BioInfo] strTryby is wrong : " + strTryby);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_BioInfo(String sAction, String sTryby, String CounterpartIPAddress, String strRemoteSender, int nDong, int nHo, int nCardNo, int nIssueCnt, String strAccessPW)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_TMoney(String sAction, String sCardRole, String sUID, String sSN, String sDong, String sHo, String sCardType) {
        try {
            LOG("[sendLobbyAccessLog_TMoney] sAction [" + sAction + "], sCardRole [" + sCardRole + "]");
            LOG("[sendLobbyAccessLog_TMoney] sUID [" + sUID + "], sSN [" + sSN + "]");
            LOG("[sendLobbyAccessLog_TMoney] sDong [" + sDong + "], sHo [" + sHo + "], sCardType [" + sCardType + "]");

            if (!sCardType.equalsIgnoreCase(AccessValues.TMoney)) {
                LOG("[sendLobbyAccessLog_TMoney] CardType is diffrent!! : " + sCardType);
                return;
            }

            String strAccessMsg = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 성공 [T-Money]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 마스터 카드에 의한 출입 성공 [T-Money]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = "단지 마스터 카드에 의한 출입 성공 [T-Money]";
                } else {
                    strAccessMsg = "알수없는 카드에 의한 출입 성공 [T-Money]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.fail) || sAction.equalsIgnoreCase(AccessValues.deny)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 차단 [T-Money]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 마스터 카드에 의한 출입 차단 [T-Money]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = "단지 마스터 카드에 의한 출입 차단 [T-Money]";
                } else {
                    strAccessMsg = "등록되지 않은 카드에 의한 출입 차단 [T-Money]";
                }
            } else {
                strAccessMsg = "ERROR";
            }

            send_save_uidcard_access_request(sAction, sCardRole, sDong, sHo, sCardType, sSN, sUID, strAccessMsg);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_TMoney(...)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_IPARKNFC(String sAction, String sCardRole, String sUID, String sSN, String sDong, String sHo, String sCardType) {
        try {
            LOG("[sendLobbyAccessLog_IPARKNFC] sAction [" + sAction + "], sCardRole [" + sCardRole + "]");
            LOG("[sendLobbyAccessLog_IPARKNFC] sUID [" + sUID + "], sSN [" + sSN + "]");
            LOG("[sendLobbyAccessLog_IPARKNFC] sDong [" + sDong + "], sHo [" + sHo + "], sCardType [" + sCardType + "]");

            if (!sCardType.equalsIgnoreCase(AccessValues.IPARK_NFC)) {
                LOG("[sendLobbyAccessLog_IPARKNFC] CardType is diffrent!! : " + sCardType);
                return;
            }

            String strAccessMsg = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 성공 [I-PARK NFC: " + sUID + "]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 마스터 카드에 의한 출입 성공 [I-PARK NFC: " + sUID + "]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = "단지 마스터 카드에 의한 출입 성공 [I-PARK NFC: " + sUID + "]";
                } else {
                    strAccessMsg = "알수없는 카드에 의한 출입 성공 [I-PARK NFC: " + sUID + "]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.fail) || sAction.equalsIgnoreCase(AccessValues.deny)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 차단 [I-PARK NFC: " + sUID + "]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 마스터 카드에 의한 출입 차단 [I-PARK NFC: " + sUID + "]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = "단지 마스터 카드에 의한 출입 차단 [I-PARK NFC: " + sUID + "]";
                } else {
                    strAccessMsg = "등록되지 않은 카드에 의한 출입 차단 [I-PARK NFC: " + sUID + "]";
                }
            } else {
                strAccessMsg = "ERROR";
            }

            send_save_uidcard_access_request(sAction, sCardRole, sDong, sHo, sCardType, sSN, sUID, strAccessMsg);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_IPARKNFC(...)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_SmartKey(String sAction, String sCardRole, String sUID, String sSN, String sDong, String sHo, String sCardNo, String sIssueCnt, String sCardType) {
        try {
            LOG("[sendLobbyAccessLog_SmartKey] sAction [" + sAction + "], sCardRole [" + sCardRole + "], sUID [" + sUID + "], sSN [" + sSN + "]");
            LOG("[sendLobbyAccessLog_SmartKey] sDong [" + sDong + "], sHo [" + sHo + "], sCardType [" + sCardType + "], sIssueCnt [" + sIssueCnt + "], sCardType [" + sCardType + "]");

            if (!sCardType.equalsIgnoreCase(AccessValues.IPARK_SmartKey)) {
                LOG("[sendLobbyAccessLog_SmartKey] CardType is diffrent!! : " + sCardType);
                return;
            }

            String strAccessMsg = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 성공 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 마스터 카드에 의한 출입 성공 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = "단지 마스터 카드에 의한 출입 성공 [SmartKey]";
                } else {
                    strAccessMsg = "알수없는 카드에 의한 출입 성공 [SmartKey]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.fail)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 차단 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 " + sCardNo + "번 마스터 카드에 의한 출입 차단 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = sCardNo + "번 단지 마스터 카드에 의한 출입 차단 [SmartKey]";
                } else {
                    strAccessMsg = "등록되지 않은 카드에 의한 출입 차단 [SmartKey]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.fail_site)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 차단 [SmartKey - Sitecode]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 " + sCardNo + "번 마스터 카드에 의한 출입 차단 [SmartKey - Sitecode]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = sCardNo + "번 단지 마스터 카드에 의한 출입 차단 [SmartKey - Sitecode]";
                } else {
                    strAccessMsg = "등록되지 않은 카드에 의한 출입 차단 [SmartKey - Sitecode]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.deny)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 카드에 의한 출입 거절 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 " + sCardNo + "번 마스터 카드에 의한 출입 거절 [SmartKey]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = sCardNo + "번 단지 마스터 카드에 의한 출입 거절 [SmartKey]";
                } else {
                    strAccessMsg = "등록되지 않은 카드에 의한 출입 거절 [SmartKey]";
                }
            } else {
                strAccessMsg = "ERROR";
            }

            send_save_uidcard_access_request(sAction, sCardRole, sDong, sHo, sCardType, sSN, sUID, strAccessMsg);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_SmartKey(...)");
            e.printStackTrace();
        }
    }

    public static void sendLobbyAccessLog_Mifare(String sAction, String sCardRole, String sUID, String sSN, String sDong, String sHo, String sCardNo, String sCardType) {
        try {
            LOG("[sendLobbyAccessLog_Mifare] sAction [" + sAction + "], sCardRole [" + sCardRole + "], sDong [" + sDong + "], sHo [" + sHo + "]");
            LOG("[sendLobbyAccessLog_Mifare] sUID [" + sUID + "], sSN [" + sSN + "]");
            LOG("[sendLobbyAccessLog_Mifare] sCardNo [" + sCardNo + "], sCardType [" + sCardType + "]");

            if (!sCardType.equalsIgnoreCase(AccessValues.Mifare)) {
                LOG("[sendLobbyAccessLog_Mifare] CardType is diffrent!! : " + sCardType);
                return;
            }

            String strAccessMsg = "";

            if (sAction.equalsIgnoreCase(AccessValues.pass)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 " + sCardNo + "번 카드에 의한 출입 성공 [Mifare]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 " + sCardNo + "번 마스터 카드에 의한 출입 성공 [Mifare]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = sCardNo + "번 단지 마스터 카드에 의한 출입 성공 [Mifare]";
                } else {
                    strAccessMsg = "알수없는 카드에 의한 출입 성공 [Mifare]";
                }
            } else if (sAction.equalsIgnoreCase(AccessValues.fail) || sAction.equalsIgnoreCase(AccessValues.deny)) {
                if (sCardRole.equalsIgnoreCase(AccessValues.hkey)) {
                    strAccessMsg = sDong + "동 " + sHo + "호 " + sCardNo + "번 카드에 의한 출입 차단 [Mifare]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.dkey)) {
                    strAccessMsg = sDong + "동 " + sCardNo + "번 마스터 카드에 의한 출입 차단 [Mifare]";
                } else if (sCardRole.equalsIgnoreCase(AccessValues.mkey)) {
                    strAccessMsg = sCardNo + "번 단지 마스터 카드에 의한 출입 차단 [Mifare]";
                } else {
                    strAccessMsg = "알수없는 카드에 의한 출입 차단 [Mifare]";
                }
            } else {
                strAccessMsg = "ERROR";
            }

            send_save_uidcard_access_request(sAction, sCardRole, sDong, sHo, sCardType, sSN, sUID, strAccessMsg);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendLobbyAccessLog_Mifare(...)");
            e.printStackTrace();
        }
    }

    // 원패스, 통화, 비밀번호 출입시
    public static boolean send_save_lobby_access_request_OnePass(final String strAction, final String strTryby, String strWherefrom, String strMessage) {
        try {
            Request_save_lobby_access save_lobby_access = new Request_save_lobby_access();
            if (save_lobby_access.send_save_lobby_access_request(strAction, strTryby, strWherefrom, strMessage)) {
                save_lobby_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_lobby_access_request_OnePass] (onResult) eResult =" + eResult);
//                        if (eResult == iMAPResult.OK) {
//                            if (!strTryby.equalsIgnoreCase(AccessValues.onepass)) playMentAfterMsg(strAction, eResult);
//                        } else if (eResult == iMAPResult.Parcel) {
//                            playMentAfterMsg(strAction, eResult);
//                        } else {
//                            playMentAfterMsg(strAction, eResult);
//                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }

    // 통화, 비밀번호 출입시
    public static boolean send_save_lobby_access_request(final String strAction, final String strTryby, String strWherefrom, String strMessage) {
        try {
            Request_save_lobby_access save_lobby_access = new Request_save_lobby_access();
            if (save_lobby_access.send_save_lobby_access_request(strAction, strTryby, strWherefrom, strMessage)) {
                save_lobby_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_lobby_access_request] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            playMentAfterMsg(strAction, eResult);
                        } else if (eResult == iMAPResult.Parcel) {
                            playMentAfterMsg(strAction, eResult);
                        } else {
                            playMentAfterMsg(strAction, eResult);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }

    // 세대카드 출입시
    public static boolean send_save_lobby_access_request(final String strAction, String strTryby, String strResiAddrIP, int nHCardNo, int nHCardCnt, String strMessage) {
        try {
            Request_save_lobby_access save_lobby_access = new Request_save_lobby_access();
            if (save_lobby_access.send_save_lobby_access_request(strAction, strTryby, strResiAddrIP, nHCardNo, nHCardCnt, strMessage)) {
                save_lobby_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_lobby_access_request] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            playMentAfterMsg(strAction, eResult);
                        } else if (eResult == iMAPResult.Parcel) {
                            playMentAfterMsg(strAction, eResult);
                        } else {
                            playMentAfterMsg(strAction, eResult);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }

    // 관리자카드 출입시
    public static boolean send_save_lobby_access_request(final String strAction, String strTryby, int nMCardNo, int nMCardCnt, String strMessage) {
        try {
            Request_save_lobby_access save_lobby_access = new Request_save_lobby_access();
            if (save_lobby_access.send_save_lobby_access_request(strAction, strTryby, nMCardNo, nMCardCnt, strMessage)) {
                save_lobby_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_lobby_access_request] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            playMentAfterMsg(strAction, eResult);
                        } else if (eResult == iMAPResult.Parcel) {
                            playMentAfterMsg(strAction, eResult);
                        } else {
                            playMentAfterMsg(strAction, eResult);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }

    // 생체정보 출입시
    public static boolean send_save_lobby_access_request(final String strAction, String strTryby, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName, String strMessage) {
        try {
            Request_save_lobby_access save_lobby_access = new Request_save_lobby_access();
            if (save_lobby_access.send_save_lobby_access_request(strAction, strTryby, strRecogResult, strRecogReason, strOwnerID, strOwnerName, strMessage)) {
                save_lobby_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_lobby_access_request] (onResult) eResult =" + eResult);
                        playMentAfterMsg(strAction, eResult);
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }

    // 방문자카드 출입시
    public static boolean send_save_vcard_access(final String strAction, String strDistinct, String strDong, String strHo, int nVCardNo, int nVCardCnt, String strMessage) {
        try {
            Request_save_vcard_access save_vcard_access = new Request_save_vcard_access();
            if (save_vcard_access.send_save_vcard_access_request(strAction, strDistinct, strDong, strHo, nVCardNo, nVCardCnt, strMessage)) {
                save_vcard_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_vcard_access] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            playMentAfterMsg(strAction, eResult);
                        } else if (eResult == iMAPResult.Parcel) {
                            playMentAfterMsg(strAction, eResult);
                        } else {
                            playMentAfterMsg(strAction, eResult);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_vcard_access(...)");
            e.printStackTrace();
            return false;
        }
    }

    // UID 카드 출입시 (T-Money, I-PARK NFC, SmartKey, Mifare)
    public static boolean send_save_uidcard_access_request(final String strAction, String strDistinct, String strID_High, String strID_Low, String strCardType, String strSN, String strUID, String strMessage) {
        try {
            Request_save_uidcard_access save_uidcard_access = new Request_save_uidcard_access();
            if (save_uidcard_access.send_save_uidcard_access_request(strAction, strDistinct, strID_High, strID_Low, strCardType, strSN, strUID, strMessage)) {
                save_uidcard_access.setResultCtrl(new iMAPResultCtrl() {

                    @Override
                    public void onResult(iMAPResult eResult) {
                        LOG_INFO("[send_save_uidcard_access_request] (onResult) eResult =" + eResult);
                        if (eResult == iMAPResult.OK) {
                            playMentAfterMsg(strAction, eResult);
                        } else if (eResult == iMAPResult.Parcel) {
                            playMentAfterMsg(strAction, eResult);
                        } else {
                            playMentAfterMsg(strAction, eResult);
                        }
                    }
                });
                return true;
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_save_lobby_access_request(Info)");
            e.printStackTrace();
            return false;
        }
    }
    /* [END] Send Lobby Access Log */


    public final class HANDLERMSG {
        public final static int AUTOSCREENCHANGE = 110;
        public final static int CANCEL_AUTOSCREENCHANGE = 120;
        public final static int ON_ALARM = 130;
        public final static int ON_MAIN = 140;
        public final static int REMOVE_VIDEO_COVER = 150;
        public final static int SHOW_VIDEO_COVER = 160;
        public final static int CLEAR_ALL_CALL = 170;
        public final static int START_CHATMODE = 180;
        public final static int STOP_CHATMODE = 190;
        public final static int START_IMAPSERVER = 200;
        public final static int SEND_HEARTBEAT_NOTICE = 210;
        public final static int START_FINGERPRINTSERVICE = 220;
        public final static int IMG_ON_EMERGENCY = 230;
        public final static int IMG_OFF_EMERGENCY = 240;
        public final static int IMG_ON_RFREADERERROR = 250;
        public final static int IMG_OFF_RFREADERERROR = 260;
        public final static int CTRL_ONEPASSDOOROPEN = 270;
        public final static int SHOW_SMARTKEY_TOASTMSG = 280;
        public final static int RUN_GOOGLE_LAUNCHER = 900;
        public final static int SYSTEM_REBOOT = 1000;
    }

    public static Handler LobbyAccessCtrlHandler = new Handler(Looper.getMainLooper()) {
        public void handleMessage(Message msg) {
            LOG("[MainHandler] MainHandler : what [" + msg.what + "], arg1 [" + msg.arg1 + "], arg2 [" + msg.arg2 + "]");
            switch (msg.what) {

                case HANDLERMSG.SHOW_SMARTKEY_TOASTMSG:
                    if (Global.bSmartKeyTestMode) Toast.makeText(mContext, (String) msg.obj, Toast.LENGTH_LONG).show();
                    break;

                default:
                    LOG("LobbyAccessCtrlHandler : " + msg.what);
                    break;
            }
        }
    };

    public void sendHandlerMsg(int what, int arg1, int arg2) {
        try {
            LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]");
            Message HandleMsg = LobbyAccessCtrlHandler.obtainMessage();
            HandleMsg.what = what;
            HandleMsg.arg1 = arg1;
            HandleMsg.arg2 = arg2;
            LobbyAccessCtrlHandler.sendMessage(HandleMsg);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendHandlerMsg(int what, int arg1, int arg2)");
            e.printStackTrace();
        }
    }

    public static void sendHandlerMsg(int what, int arg1, int arg2, Object obj) {
        try {
            LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]");
            Message HandleMsg = LobbyAccessCtrlHandler.obtainMessage();
            HandleMsg.what = what;
            HandleMsg.arg1 = arg1;
            HandleMsg.arg2 = arg2;
            HandleMsg.obj = obj;
            LobbyAccessCtrlHandler.sendMessage(HandleMsg);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendHandlerMsg(int what, int arg1, int arg2, Object obj)");
            e.printStackTrace();
        }
    }

    public void sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay) {
        try {
            LOG("[sendHandlerMsgDelayed] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], delay [" + delay + "]");
            Message HandleMsg = LobbyAccessCtrlHandler.obtainMessage();
            HandleMsg.what = what;
            HandleMsg.arg1 = arg1;
            HandleMsg.arg2 = arg2;
            LobbyAccessCtrlHandler.sendMessageDelayed(HandleMsg, delay);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay)");
            e.printStackTrace();
        }
    }


}