public void setRS485ConfigEx(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2Rs485ConfigEX config = Util.AllocateStructure <BS2Rs485ConfigEX>();

            for (int i = 0; i < 5; i++)
            {
                config.mode[i] = 1;
            }

            config.numOfChannels                           = 5;
            config.channels[0].baudRate                    = 115200;
            config.channels[0].channelIndex                = 0;
            config.channels[0].useRegistance               = 0;
            config.channels[0].numOfDevices                = 1;
            config.channels[0].slaveDevices[0].deviceID    = 541531029;
            config.channels[0].slaveDevices[0].deviceType  = 9;
            config.channels[0].slaveDevices[0].enableOSDP  = 0;
            config.channels[0].slaveDevices[0].connected   = 1;
            config.channels[0].slaveDevices[0].channelInfo = 0;

            Console.WriteLine("Trying to set RS485ConfigEx configuration.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetRS485ConfigEx(sdkContext, deviceID, ref config);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#2
0
        public static BS2ErrorCode CSP_BS2_GetAll <CSP_T, CXX_T>(IntPtr context, UInt32 deviceId, out CSP_T[] ItemsObj, out UInt32 numItem, FUNC_BS2_GetAll func)
        {
            IntPtr       _itemsObj = IntPtr.Zero;
            UInt32       _itemNum  = 0;
            BS2ErrorCode result    = (BS2ErrorCode)func(context, deviceId, out _itemsObj, out _itemNum);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                numItem  = 0;
                ItemsObj = AllocateStructureArray <CSP_T>(0);
                return(result);
            }

            CSP_T[] _items = AllocateStructureArray <CSP_T> ((int)_itemNum);

            Translator <CXX_T, CSP_T> transItem = new Translator <CXX_T, CSP_T>();
            int    ItemSize   = Marshal.SizeOf(typeof(CXX_T));
            IntPtr curItemObj = _itemsObj;

            for (int idx = 0; idx < _itemNum; ++idx)
            {
                CXX_T item = (CXX_T)Marshal.PtrToStructure(curItemObj, typeof(CXX_T));
                transItem.Translate(ref item, ref _items[idx]);
                curItemObj += ItemSize;
            }

            API.BS2_ReleaseObject(_itemsObj);

            numItem  = _itemNum;
            ItemsObj = _items;
            return(result);
        }
        public void setDataEncryptKey(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to set data encrypt key.");

            Console.WriteLine("If the key change is successful, all users of the device will be deleted.");
            Console.WriteLine("Do you want to continue? [y/n]");
            Console.Write(">>>> ");
            if (Util.IsYes())
            {
                BS2EncryptKey keyInfo = Util.AllocateStructure <BS2EncryptKey>();

                Console.WriteLine("Write please key string.");
                Console.Write(">>>> ");
                string keyString = Console.ReadLine();
                byte[] buff      = Encoding.UTF8.GetBytes(keyString);

                Array.Clear(keyInfo.key, 0, BS2Environment.BS2_ENC_KEY_SIZE);
                Array.Copy(buff, 0, keyInfo.key, 0, keyString.Length);

                BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetDataEncryptKey(sdkContext, deviceID, ref keyInfo);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    return;
                }
            }
        }
        public void setCardConfigEx(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2CardConfigEx config = Util.AllocateStructure <BS2CardConfigEx>();

            config.seos.oid_ADF[0] = 0x01;
            config.seos.oid_ADF[1] = 0x02;

            config.seos.oid_DataObjectID[0] = 0xD0;
            config.seos.oid_DataObjectID[1] = 0xD1;

            config.seos.size_DataObject[0] = 90;
            config.seos.size_DataObject[1] = 100;

            config.seos.primaryKeyAuth[0] = 0x01;
            config.seos.primaryKeyAuth[1] = 0xFE;

            config.seos.secondaryKeyAuth[0] = 0x01;
            config.seos.secondaryKeyAuth[1] = 0x1E;

            Console.WriteLine("Trying to set CardConfigEx configuration.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetCardConfigEx(sdkContext, deviceID, ref config);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
        public void setCard1xConfig(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS1CardConfig card1xConfig = Util.AllocateStructure <BS1CardConfig>();

            card1xConfig.magicNo            = 0;
            card1xConfig.disabled           = 0;
            card1xConfig.useCSNOnly         = 0;
            card1xConfig.bioentryCompatible = 0;
            card1xConfig.useSecondaryKey    = 1;

            card1xConfig.cisIndex              = 0;
            card1xConfig.numOfTemplate         = 1;
            card1xConfig.templateSize          = 32;
            card1xConfig.templateStartBlock[0] = 4;
            card1xConfig.templateStartBlock[1] = 8;
            card1xConfig.templateStartBlock[2] = 12;
            card1xConfig.templateStartBlock[3] = 0;

            Console.WriteLine("Trying to set card1x configuration.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetCard1xConfig(sdkContext, deviceID, ref card1xConfig);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#6
0
        public bool CleanLog(ref UInt32 deviceID)
        {
            _log.InfoFormat("清空设备 {0} 删除所有记录", parseIdToIp(deviceID));
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_ClearLog(sdkContext, deviceID);

            _log.InfoFormat("清空设备 {0} 删除所有记录结果 {1}", parseIdToIp(deviceID), result == BS2ErrorCode.BS_SDK_SUCCESS);
            return(result == BS2ErrorCode.BS_SDK_SUCCESS);
        }
示例#7
0
        public bool RemoveAllUser(ref UInt32 deviceID)
        {
            _log.InfoFormat("从设备 {0} 删除所有用户", parseIdToIp(deviceID));
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_RemoveAllUser(sdkContext, deviceID);

            _log.InfoFormat("从设备 {0} 删除所有用户结果 {1}", parseIdToIp(deviceID), result == BS2ErrorCode.BS_SDK_SUCCESS);
            return(result == BS2ErrorCode.BS_SDK_SUCCESS);
        }
示例#8
0
        public void setAuthGroup(IntPtr sdkContext, uint deviceID, bool isMasterDevice)
        {
            Console.WriteLine("How many auth groups do you want to set? [1(default)-128]");
            Console.Write(">>>> ");
            char[] delimiterChars             = { ' ', ',', '.', ':', '\t' };
            int    amount                     = Util.GetInput(1);
            List <BS2AuthGroup> authGroupList = new List <BS2AuthGroup>();

            for (int idx = 0; idx < amount; ++idx)
            {
                BS2AuthGroup authGroup = Util.AllocateStructure <BS2AuthGroup>();

                Console.WriteLine("Enter a value for auth group[{0}]", idx);
                Console.WriteLine("  Enter the ID for the auth group which you want to set");
                Console.Write("  >>>> ");
                authGroup.id = (UInt32)Util.GetInput();
                Console.WriteLine("  Enter the name for the auth group which you want to set");
                Console.Write("  >>>> ");
                string authGroupName = Console.ReadLine();
                if (authGroupName.Length == 0)
                {
                    Console.WriteLine("  [Warning] auth group name will be displayed as empty.");
                }
                else if (authGroupName.Length > BS2Envirionment.BS2_MAX_AUTH_GROUP_NAME_LEN)
                {
                    Console.WriteLine("  Name of auth group should less than {0} words.", BS2Envirionment.BS2_MAX_AUTH_GROUP_NAME_LEN);
                    return;
                }
                else
                {
                    byte[] authGroupArray = Encoding.UTF8.GetBytes(authGroupName);
                    Array.Clear(authGroup.name, 0, BS2Envirionment.BS2_MAX_AUTH_GROUP_NAME_LEN);
                    Array.Copy(authGroupArray, authGroup.name, authGroupArray.Length);
                }

                authGroupList.Add(authGroup);
            }

            int    structSize          = Marshal.SizeOf(typeof(BS2AuthGroup));
            IntPtr authGroupListObj    = Marshal.AllocHGlobal(structSize * authGroupList.Count);
            IntPtr curAuthGroupListObj = authGroupListObj;

            foreach (BS2AuthGroup item in authGroupList)
            {
                Marshal.StructureToPtr(item, curAuthGroupListObj, false);
                curAuthGroupListObj = (IntPtr)((long)curAuthGroupListObj + structSize);
            }

            Console.WriteLine("Trying to set auth groups to device.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetAuthGroup(sdkContext, deviceID, authGroupListObj, (UInt32)authGroupList.Count);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            Marshal.FreeHGlobal(authGroupListObj);
        }
示例#9
0
        internal void SynDateTime(ref uint deviceID, uint gmtTime)
        {
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetDeviceTime(sdkContext, deviceID, gmtTime);

            if (BS2ErrorCode.BS_SDK_SUCCESS != result)
            {
                _log.ErrorFormat("同步时间失败,设备IP : {0}", parseIdToIp(deviceID));
            }
        }
示例#10
0
        public void removeDoor(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS;

            Console.WriteLine("Do you want to remove all doors? [Y/n]");
            Console.Write(">>>> ");
            if (Util.IsYes())
            {
                Console.WriteLine("Trying to remove all doors from device.");
                result = (BS2ErrorCode)API.BS2_RemoveAllDoor(sdkContext, deviceID);
            }
            else
            {
                Console.WriteLine("Enter the ID of the door which you want to remove: [ID_1,ID_2 ...]");
                Console.Write(">>>> ");
                char[]        delimiterChars = { ' ', ',', '.', ':', '\t' };
                string[]      doorIDs        = Console.ReadLine().Split(delimiterChars);
                List <UInt32> doorIDList     = new List <UInt32>();

                foreach (string doorID in doorIDs)
                {
                    if (doorID.Length > 0)
                    {
                        UInt32 item;
                        if (UInt32.TryParse(doorID, out item))
                        {
                            doorIDList.Add(item);
                        }
                    }
                }

                if (doorIDList.Count > 0)
                {
                    IntPtr doorIDObj    = Marshal.AllocHGlobal(4 * doorIDList.Count);
                    IntPtr curDoorIDObj = doorIDObj;
                    foreach (UInt32 item in doorIDList)
                    {
                        Marshal.WriteInt32(curDoorIDObj, (Int32)item);
                        curDoorIDObj = (IntPtr)((long)curDoorIDObj + 4);
                    }

                    Console.WriteLine("Trying to remove doors from device.");
                    result = (BS2ErrorCode)API.BS2_RemoveDoor(sdkContext, deviceID, doorIDObj, (UInt32)doorIDList.Count);

                    Marshal.FreeHGlobal(doorIDObj);
                }
                else
                {
                    Console.WriteLine("Invalid parameter");
                }
            }

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#11
0
        void getLog(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            const UInt32 defaultLogPageSize = 1024;
            Type         structureType      = typeof(BS2Event);
            int          structSize         = Marshal.SizeOf(structureType);
            bool         getAllLog          = false;
            UInt32       lastEventId        = 0;
            UInt32       amount;
            IntPtr       outEventLogObjs = IntPtr.Zero;
            UInt32       outNumEventLogs = 0;

            cbOnLogReceived = new API.OnLogReceived(NormalLogReceived);

            Console.WriteLine("What is the ID of the last log which you have? [0: None]");
            Console.Write(">>>> ");
            lastEventId = Util.GetInput((UInt32)0);
            Console.WriteLine("How many logs do you want to get? [0: All]");
            Console.Write(">>>> ");
            amount = Util.GetInput((UInt32)0);

            if (amount == 0)
            {
                getAllLog = true;
                amount    = defaultLogPageSize;
            }

            do
            {
                outEventLogObjs = IntPtr.Zero;
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetLog(sdkContext, deviceID, lastEventId, amount, out outEventLogObjs, out outNumEventLogs);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    break;
                }

                if (outNumEventLogs > 0)
                {
                    IntPtr curEventLogObjs = outEventLogObjs;
                    for (UInt32 idx = 0; idx < outNumEventLogs; idx++)
                    {
                        BS2Event eventLog = (BS2Event)Marshal.PtrToStructure(curEventLogObjs, structureType);
                        Console.WriteLine(Util.GetLogMsg(eventLog));
                        curEventLogObjs += structSize;
                        lastEventId      = eventLog.id;
                    }

                    API.BS2_ReleaseObject(outEventLogObjs);
                }

                if (outNumEventLogs < defaultLogPageSize)
                {
                    break;
                }
            }while (getAllLog);
        }
        void unlockDevice(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to unlock device.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_UnlockDevice(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#13
0
        void clearLog(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to clear log.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_ClearLog(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
        void factoryReset(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to reset device to factory settings.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_FactoryReset(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
        public void eraseCard(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to erase card.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_EraseCard(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#16
0
        public void disbleSSL(IntPtr sdkContext, uint deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to disable ssl");

            BS2ErrorCode result = (BS2ErrorCode)API.BS2_DisableSSL(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#17
0
        public void updateSoundResource(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2ResourceElement resourceElement = Util.AllocateStructure <BS2ResourceElement>();

            resourceElement.type = (byte)BS2ResourceTypeEnum.BS2_RESOURCE_TYPE_SOUND;
            Console.WriteLine("How many sound resource do you want to set? [1(default)-3]");
            Console.Write(">>>> ");
            resourceElement.numResData = Util.GetInput(1);

            for (UInt32 idx = 0; idx < resourceElement.numResData; ++idx)
            {
                Console.WriteLine("Enter a value for sound resource[{0}]", idx);
                Console.WriteLine("  Enter index of the sound resource which you want to set [{0} - {1}]", BS2SoundIndexEnum.WELCOME, BS2SoundIndexEnum.AUTH_FAIL);
                Console.Write("  >>>> ");
                resourceElement.resData[idx].index = (byte)Util.GetInput();
                Console.WriteLine("  Enter the path of wave file(*.wav) which you want to update.");
                Console.Write("  >>>> ");
                string waveFilePath = Console.ReadLine();
                if (!File.Exists(waveFilePath))
                {
                    Console.WriteLine("Invalid image file path");
                    return;
                }

                IntPtr waveData    = IntPtr.Zero;
                UInt32 waveDataLen = 0;

                if (Util.LoadBinary(waveFilePath, out waveData, out waveDataLen))
                {
                    resourceElement.resData[idx].data    = waveData;
                    resourceElement.resData[idx].dataLen = waveDataLen;
                }
                else
                {
                    return;
                }
            }

            Console.WriteLine("Trying to update sound resource.");
            cbOnProgressChanged = new API.OnProgressChanged(GeneralProgressChanged);
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_UpdateResource(sdkContext, deviceID, ref resourceElement, 0, cbOnProgressChanged);

            for (UInt32 idx = 0; idx < resourceElement.numResData; ++idx)
            {
                Marshal.FreeHGlobal(resourceElement.resData[idx].data);
            }

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            cbOnProgressChanged = null;
        }
        void setWiegandMultiConfig(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2WiegandMultiConfig wiegandMultiConfig = Util.AllocateStructure <BS2WiegandMultiConfig>();

            for (int i = 0; i < 15; ++i)
            {
                wiegandMultiConfig.formats[i].formatID      = 0;
                wiegandMultiConfig.formats[i].format.length = 0;
                Array.Clear(wiegandMultiConfig.formats[i].format.idFields, 0, 128);
                Array.Clear(wiegandMultiConfig.formats[i].format.parityFields, 0, 128);
                Array.Clear(wiegandMultiConfig.formats[i].format.parityType, 0, 4);
                Array.Clear(wiegandMultiConfig.formats[i].format.parityPos, 0, 4);
            }

            wiegandMultiConfig.formats[0].formatID            = 1;
            wiegandMultiConfig.formats[0].format.length       = 26;
            wiegandMultiConfig.formats[0].format.idFields[28] = 0x01;
            wiegandMultiConfig.formats[0].format.idFields[29] = 0xFE;

            wiegandMultiConfig.formats[0].format.idFields[31 + 29] = 0x01;
            wiegandMultiConfig.formats[0].format.idFields[31 + 30] = 0xFF;
            wiegandMultiConfig.formats[0].format.idFields[31 + 31] = 0xFE;

            wiegandMultiConfig.formats[0].format.parityType[0] = 2;
            wiegandMultiConfig.formats[0].format.parityPos[0]  = 0;

            wiegandMultiConfig.formats[0].format.parityType[1] = 1;
            wiegandMultiConfig.formats[0].format.parityPos[1]  = 25;

            wiegandMultiConfig.formats[0].format.parityType[2] = 0;
            wiegandMultiConfig.formats[0].format.parityPos[2]  = 0;

            wiegandMultiConfig.formats[0].format.parityType[3] = 0;
            wiegandMultiConfig.formats[0].format.parityPos[3]  = 0;

            wiegandMultiConfig.formats[0].format.parityFields[28] = 0x01;
            wiegandMultiConfig.formats[0].format.parityFields[29] = 0xFE;
            wiegandMultiConfig.formats[0].format.parityFields[30] = 0xE0;

            wiegandMultiConfig.formats[0].format.parityFields[31 + 30] = 0x1F;
            wiegandMultiConfig.formats[0].format.parityFields[31 + 31] = 0xFE;

            Console.WriteLine("Trying to set wiegandMultiConfig");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetWiegandMultiConfig(sdkContext, deviceID, ref wiegandMultiConfig);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
            else
            {
                getWiegandMultiConfig(sdkContext, deviceID, true);
            }
        }
        void setTime(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to set device time");

            UInt32       timestamp = Convert.ToUInt32(Util.ConvertToUnixTimestamp(DateTime.Now));
            BS2ErrorCode result    = (BS2ErrorCode)API.BS2_SetDeviceTime(sdkContext, deviceID, timestamp);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#20
0
        public void removeDataEncryptKey(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to remove data encrypt key.");

            BS2ErrorCode result = (BS2ErrorCode)API.BS2_RemoveDataEncryptKey(sdkContext, deviceID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
                return;
            }
        }
示例#21
0
        public void setFaceConfig(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2FaceConfig config = Util.AllocateStructure <BS2FaceConfig>();

            Console.WriteLine("Trying to set FaceConfig configuration.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetFaceConfig(sdkContext, deviceID, ref config);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#22
0
        public void setDoorAlarm(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Enter the ID of the door which you want to set its alarm: [ID_1,ID_2 ...]");
            Console.Write(">>>> ");
            char[]        delimiterChars = { ' ', ',', '.', ':', '\t' };
            string[]      doorIDs        = Console.ReadLine().Split(delimiterChars);
            List <UInt32> doorIDList     = new List <UInt32>();

            foreach (string doorID in doorIDs)
            {
                if (doorID.Length > 0)
                {
                    UInt32 item;
                    if (UInt32.TryParse(doorID, out item))
                    {
                        doorIDList.Add(item);
                    }
                }
            }

            if (doorIDList.Count > 0)
            {
                IntPtr doorIDObj    = Marshal.AllocHGlobal(4 * doorIDList.Count);
                IntPtr curDoorIDObj = doorIDObj;
                foreach (UInt32 item in doorIDList)
                {
                    Marshal.WriteInt32(curDoorIDObj, (Int32)item);
                    curDoorIDObj = (IntPtr)((long)curDoorIDObj + 4);
                }

                Console.WriteLine("Choose the flag for the doors to be released: [0: None(default), 1: Forced open, 2: Held open, 4: APB]");
                Console.Write(">>>> ");
                byte validDoorAlarmFlag = (byte)(BS2DoorAlarmFlagEnum.NONE | BS2DoorAlarmFlagEnum.FORCED_OPEN | BS2DoorAlarmFlagEnum.HELD_OPEN | BS2DoorAlarmFlagEnum.APB);
                byte doorAlarmFlag      = Util.GetInput((byte)BS2DoorAlarmFlagEnum.NONE);

                if ((doorAlarmFlag & ~validDoorAlarmFlag) != 0)
                {
                    Console.WriteLine("Invalid parameter");
                    Marshal.FreeHGlobal(doorIDObj);
                    return;
                }

                Console.WriteLine("Trying to set door alarm.");
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetDoorAlarm(sdkContext, deviceID, doorAlarmFlag, doorIDObj, (UInt32)doorIDList.Count);

                Marshal.FreeHGlobal(doorIDObj);
            }
            else
            {
                Console.WriteLine("Invalid parameter");
            }
        }
示例#23
0
        public void unlockDoor(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Enter the ID of the door which you want to unlock: [ID_1,ID_2 ...]");
            Console.Write(">>>> ");
            char[]        delimiterChars = { ' ', ',', '.', ':', '\t' };
            string[]      doorIDs        = Console.ReadLine().Split(delimiterChars);
            List <UInt32> doorIDList     = new List <UInt32>();

            foreach (string doorID in doorIDs)
            {
                if (doorID.Length > 0)
                {
                    UInt32 item;
                    if (UInt32.TryParse(doorID, out item))
                    {
                        doorIDList.Add(item);
                    }
                }
            }

            if (doorIDList.Count > 0)
            {
                IntPtr doorIDObj    = Marshal.AllocHGlobal(4 * doorIDList.Count);
                IntPtr curDoorIDObj = doorIDObj;
                foreach (UInt32 item in doorIDList)
                {
                    Marshal.WriteInt32(curDoorIDObj, (Int32)item);
                    curDoorIDObj = (IntPtr)((long)curDoorIDObj + 4);
                }

                Console.WriteLine("Choose the flag for the doors to be unlocked: [0: None, 1: By Schedule, 2: By Emergency, 4: By Operator(default)]");
                Console.Write(">>>> ");
                byte validDoorFlag = (byte)(BS2DoorFlagEnum.NONE | BS2DoorFlagEnum.SCHEDULE | BS2DoorFlagEnum.EMERGENCY | BS2DoorFlagEnum.OPERATOR);
                byte doorFlag      = Util.GetInput((byte)BS2DoorFlagEnum.OPERATOR);

                if ((doorFlag & ~validDoorFlag) != 0)
                {
                    Console.WriteLine("Invalid parameter");
                    Marshal.FreeHGlobal(doorIDObj);
                    return;
                }

                Console.WriteLine("Trying to unlock doors.");
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_UnlockDoor(sdkContext, deviceID, doorFlag, doorIDObj, (UInt32)doorIDList.Count);

                Marshal.FreeHGlobal(doorIDObj);
            }
            else
            {
                Console.WriteLine("Invalid parameter");
            }
        }
        public void execute(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice, bool noConnection = false)
        {
            if (noConnection == false)
            {
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetDeviceInfo(sdkContext, deviceID, out deviceInfo);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Can't get device information(errorCode : {0}).", result);
                    return;
                }
            }


            List <KeyValuePair <string, Action <IntPtr, UInt32, bool> > > functionList = getFunctionList(sdkContext, deviceID, isMasterDevice);

            if (functionList.Count > 0)
            {
                int  selection;
                bool running = true;

                while (running)
                {
                    Console.WriteLine("+-----------------------------------------------------------+");
                    int idx = 1;
                    for (; idx <= functionList.Count; ++idx)
                    {
                        Console.WriteLine("|{0,3}. {1,-54}|", idx, functionList[idx - 1].Key);
                    }
                    Console.WriteLine("|{0,3}. Exit                                                  |", idx);
                    Console.WriteLine("+-----------------------------------------------------------+");

                    Console.WriteLine("What would you like to do?");
                    Console.Write(">>>> ");

                    if (Util.GetInput(out selection))
                    {
                        if (selection > 0 && selection <= functionList.Count)
                        {
                            functionList[selection - 1].Value(sdkContext, deviceID, isMasterDevice);
                        }
                        else if (selection == functionList.Count + 1)
                        {
                            running = false;
                        }
                        else
                        {
                            Console.WriteLine("Invalid parameter : {0}", selection);
                        }
                    }
                }
            }
        }
示例#25
0
        public override void execute()
        {
            UInt32       zoneID       = 0;
            BS2ErrorCode handleResult = zoneManager.checkAPBZoneRule(deviceID, userID_1, userID_2, isDualAuth, out zoneID);

            Console.WriteLine("[Server] responded with a status of {0}, zoneID[{6}] : device[{1}] seq[{2}], userID_1[{3}], userID_2[{4}], isDualAuth[{5}]", handleResult, deviceID, seq, userID_1, userID_2, isDualAuth, zoneID);
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_CheckGlobalAPBViolation(sdkContext, deviceID, seq, (int)handleResult, zoneID);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
示例#26
0
        public void setBlacklist(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            bool         isAppend = false;
            BS2ErrorCode result   = BS2ErrorCode.BS_SDK_SUCCESS;

            Console.WriteLine("Do you want to append card to the blacklist? [Y/n]");
            Console.Write(">>>> ");
            if (Util.IsYes())
            {
                isAppend = true;
            }

            Console.WriteLine("How many Blacklists do you want to set? [1(default)-1000]");
            Console.Write(">>>> ");
            int amount = Util.GetInput(1);
            List <BS2BlackList> blackList = new List <BS2BlackList>();

            if (isAppend)
            {
                if (getBlacklist(sdkContext, deviceID, blackList))
                {
                    if (amount + blackList.Count > BS2Envirionment.BS2_MAX_BLACK_LIST_SLOTS)
                    {
                        amount = BS2Envirionment.BS2_MAX_BLACK_LIST_SLOTS - blackList.Count;
                        Console.WriteLine("Blacklist can't exceeds the allowable limit[{0}] => adjust appending count to {1}.", BS2Envirionment.BS2_MAX_BLACK_LIST_SLOTS, amount);
                    }
                }
            }

            scanAndAddBlacklist(sdkContext, deviceID, blackList, amount);

            int    structSize      = Marshal.SizeOf(typeof(BS2BlackList));
            IntPtr blacklistObj    = Marshal.AllocHGlobal(structSize * blackList.Count);
            IntPtr curBlacklistObj = blacklistObj;

            foreach (BS2BlackList item in blackList)
            {
                Marshal.StructureToPtr(item, curBlacklistObj, false);
                curBlacklistObj = (IntPtr)((long)curBlacklistObj + structSize);
            }

            Console.WriteLine("Trying to set blacklists to device.");
            result = (BS2ErrorCode)API.BS2_SetBlackList(sdkContext, deviceID, blacklistObj, (UInt32)blackList.Count);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            Marshal.FreeHGlobal(blacklistObj);
        }
示例#27
0
        public BS2ErrorCode checkAPBZoneRule(UInt32 deviceID, string userID_1, string userID_2, bool isDualAuth, out UInt32 zoneID)
        {
            BS2ErrorCode result = BS2ErrorCode.BS_SDK_SUCCESS;

            if (!inDeviceIDs.Contains(deviceID) && !outDeviceIDs.Contains(deviceID))
            {
                zoneID = 0;
                result = BS2ErrorCode.BS_SDK_SUCCESS;
            }
            else
            {
                //BS_SDK_ERROR_HARD_APB_VIOLATION;
                //BS_SDK_ERROR_SOFT_APB_VIOLATION;
                //BS_SDK_ERROR_HARD_TIMED_APB_VIOLATION;
                //BS_SDK_ERROR_SOFT_TIMED_APB_VIOLATION;
                if (lastDevicePerUser.ContainsKey(userID_1))
                {
                    if (inDeviceIDs.Contains(lastDevicePerUser[userID_1]) && inDeviceIDs.Contains(deviceID))
                    {
                        result = APBZoneType == BS2APBZoneTypeEnum.SOFT ? BS2ErrorCode.BS_SDK_ERROR_SOFT_APB_VIOLATION : BS2ErrorCode.BS_SDK_ERROR_HARD_APB_VIOLATION;
                    }
                    else if (outDeviceIDs.Contains(lastDevicePerUser[userID_1]) && outDeviceIDs.Contains(deviceID))
                    {
                        result = APBZoneType == BS2APBZoneTypeEnum.SOFT ? BS2ErrorCode.BS_SDK_ERROR_SOFT_APB_VIOLATION : BS2ErrorCode.BS_SDK_ERROR_HARD_APB_VIOLATION;
                    }
                    else
                    {
                        result = BS2ErrorCode.BS_SDK_SUCCESS;
                    }
                }
                else
                {
                    //First
                    result = BS2ErrorCode.BS_SDK_SUCCESS;
                }

                zoneID = this.zoneID;

                switch ((BS2ErrorCode)result)
                {
                case BS2ErrorCode.BS_SDK_SUCCESS:
                case BS2ErrorCode.BS_SDK_ERROR_SOFT_APB_VIOLATION:
                case BS2ErrorCode.BS_SDK_ERROR_SOFT_TIMED_APB_VIOLATION:
                    lastDevicePerUser[userID_1] = deviceID;
                    break;
                }
            }

            return(result);
        }
        //void slaveExControl(IntPtr sdkContext, List<BS2Rs485SlaveDeviceEX> slaveDeviceList)
        //{
        //    //TODO implement this section.
        //    foreach (BS2Rs485SlaveDeviceEX slaveDevice in slaveDeviceList)
        //    {
        //        BS2AuthConfig authConfig;
        //        Console.WriteLine("Getting auth config. reader[{0}]", slaveDevice.deviceID);
        //        BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetAuthConfig(sdkContext, slaveDevice.deviceID, out authConfig);
        //        if (result != BS2ErrorCode.BS_SDK_SUCCESS)
        //        {
        //            Console.WriteLine("Get auth config. reader[{0}]-error[{1}].", slaveDevice.deviceID, result);
        //            return;
        //        }
        //        Console.WriteLine("Get auth config. reader[{0}]-AuthMode[{1}].", slaveDevice.deviceID, getAuthInfo(authConfig));
        //    }
        //}

        public void getSlaveExAuthMode(IntPtr sdkContext, UInt32 slaveID)
        {
            BS2AuthConfig authConfig;

            Console.WriteLine("Getting auth config. reader[{0}]", slaveID);
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetAuthConfig(sdkContext, slaveID, out authConfig);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Get auth config. reader[{0}]-error[{1}].", slaveID, result);
                return;
            }
            Console.WriteLine("Get auth config. reader[{0}]-AuthMode[{1}].", slaveID, getAuthInfo(authConfig));
        }
示例#29
0
        void scanAndAddBlacklist(IntPtr sdkContext, UInt32 deviceID, List <BS2BlackList> blackList, int amount)
        {
            cbCardOnReadyToScan = new API.OnReadyToScan(ReadyToScanForCard);
            BS2Card      card          = Util.AllocateStructure <BS2Card>();
            BS2BlackList blacklistItem = Util.AllocateStructure <BS2BlackList>();

            for (int idx = 0; idx < amount; ++idx)
            {
                Console.WriteLine("Trying to scan card.");
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_ScanCard(sdkContext, deviceID, out card, cbCardOnReadyToScan);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    return;
                }
                else if (Convert.ToBoolean(card.isSmartCard))
                {
                    BS2SmartCardData smartCard = Util.ConvertTo <BS2SmartCardData>(card.cardUnion);
                    Array.Copy(smartCard.cardID, blacklistItem.cardID, BS2Envirionment.BS2_CARD_DATA_SIZE);
                    blacklistItem.issueCount = smartCard.header.issueCount;
                }
                else
                {
                    BS2CSNCard csnCard = Util.ConvertTo <BS2CSNCard>(card.cardUnion);
                    Array.Copy(csnCard.data, blacklistItem.cardID, BS2Envirionment.BS2_CARD_DATA_SIZE);
                    blacklistItem.issueCount = 0; //should set count of issue to 0
                }

                bool isDuplicated = false;
                foreach (BS2BlackList item in blackList)
                {
                    if (blacklistItem.cardID.SequenceEqual(item.cardID))
                    {
                        isDuplicated = true;
                        break;
                    }
                }

                if (isDuplicated)
                {
                    Console.WriteLine("Already exist blacklist. try again");
                    --idx;
                    continue;
                }

                blackList.Add(blacklistItem);
            }

            cbCardOnReadyToScan = null;
        }
示例#30
0
        public void getDataEncryptKey(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Trying to get data encrypt key.");

            BS2EncryptKey keyInfo;
            BS2ErrorCode  result = (BS2ErrorCode)API.BS2_GetDataEncryptKey(sdkContext, deviceID, out keyInfo);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
                return;
            }

            print(keyInfo);
        }