コード例 #1
0
        public static IcCardParameter TemporaryIcCardContent(byte[] by)
        {
            IcCardParameter parameter = new IcCardParameter();

            if (by.Length < 30)
            {
                return(parameter);
            }
            parameter.IcNumber = Encoding.ASCII.GetString(by, 0, 8);
            string plate = Encoding.Default.GetString(by, 8, 10);

            parameter.Plate = CRegex.IsPlate(plate) ? plate : GetHexStr(@by, 8, 10);
            string time = Encoding.Default.GetString(by, 18, 12);

            parameter.Time = CRegex.IsTime(time) ? DateTime.ParseExact(time, "yyMMddHHmmss", System.Globalization.CultureInfo.InstalledUICulture).ToString() : GetHexStr(@by, 18, 12);
            return(parameter);
        }
コード例 #2
0
ファイル: DataParsing.cs プロジェクト: makejack/TestTools
        public static PortDataParameter Parsing(byte[] by)
        {
            PortDataParameter param = new PortDataParameter()
            {
                Header = by[0],
                End    = by[by.Length - 1],
            };

            if (param.Header == 2)
            {
                param.FunctionAddress = (PortEnums.DealFunctions)by[1];
                param.DeviceAddress   = Utility.HexToInt(by[2], by[3]);
                int command = Utility.HexToInt(by[4], by[5]);
                switch (param.FunctionAddress)
                {
                case PortEnums.DealFunctions.Distance:
                    PortEnums.DistanceCommands dCommand = (PortEnums.DistanceCommands)Utility.HexToInt(by[6], by[7]);
                    param.Command.DCommand = (PortEnums.DCommands)command;
                    switch (dCommand)
                    {
                    case PortEnums.DistanceCommands.WriteAllCard:
                    case PortEnums.DistanceCommands.WriteACard:
                    case PortEnums.DistanceCommands.ReadAllCard:
                    case PortEnums.DistanceCommands.ReadACard:
                    case PortEnums.DistanceCommands.ModifyAllCardPwd:
                        DistanceCardParameter distanceParam = new DistanceCardParameter
                        {
                            Command          = dCommand,
                            AuxiliaryCommand = (PortEnums.AuxiliaryCommands)Utility.HexToInt(by[8], by[9])
                        };
                        if (distanceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            distanceParam.CardNumber        = Encoding.ASCII.GetString(by, 10, 6);
                            distanceParam.CardTypeValue     = Utility.HexToInt(by[16], by[17]);
                            distanceParam.CardTypeParameter = ParsingDistanceCardType(distanceParam.CardTypeValue);
                            distanceParam.Area  = Utility.HexToInt(by[18], by[19]);
                            distanceParam.Start = Utility.HexToInt(by[20], by[21]);
                            distanceParam.Len   = Utility.HexToInt(by[22], by[23]);
                            if (((int)distanceParam.CardTypeParameter.CardType) < 2)
                            {
                                if (dCommand == PortEnums.DistanceCommands.ReadACard || dCommand == PortEnums.DistanceCommands.ReadAllCard)
                                {
                                    if (distanceParam.Len >= 1)
                                    {
                                        distanceParam.FunctionByteValue = Utility.HexToInt(by[24], by[25]);
                                        distanceParam.FunctionByteParam = ParsingDistanceFunctionByte(distanceParam.FunctionByteValue);
                                    }
                                    if (distanceParam.Len >= 3)
                                    {
                                        distanceParam.Count = Utility.HexToInt(by[26], by[27], by[28], by[29]);
                                    }
                                }
                            }
                        }
                        param.DistanceCardParam = distanceParam;
                        break;

                    case PortEnums.DistanceCommands.InitializeDevice:
                        DistanceDeviceParameter deviceParam = new DistanceDeviceParameter()
                        {
                            Command          = dCommand,
                            AuxiliaryCommand = (PortEnums.AuxiliaryCommands)Utility.HexToInt(by[8], by[9]),
                        };
                        param.DistanceDeviceParam = deviceParam;
                        break;
                    }

                    break;

                case PortEnums.DealFunctions.Ic:
                    param.Command.ICommand = (PortEnums.ICommands)command;
                    IcParameter icParam = new IcParameter();
                    switch (param.Command.ICommand)
                    {
                    case PortEnums.ICommands.Read:
                        string icNumber = Encoding.ASCII.GetString(by, 6, 8);
                        icParam.IcNumber = icNumber;
                        string licensePlate = Encoding.Default.GetString(by, 14, 10);
                        icParam.LicensePlate = licensePlate;
                        string   strTime = Encoding.Default.GetString(by, 24, 12);
                        DateTime time    = DateTime.Now;
                        if (CRegex.IsTime(strTime))
                        {
                            time = DateTime.ParseExact(strTime, "yyMMddHHmmss", System.Globalization.CultureInfo.InstalledUICulture);
                        }
                        icParam.Time = time;
                        break;

                    case PortEnums.ICommands.EntryptIcCard:
                    case PortEnums.ICommands.EntryptIcDevice:
                        icParam.Result = Utility.HexToInt(by[6], by[7]) == 0;
                        break;
                    }
                    param.IcParam = icParam;
                    break;

                case PortEnums.DealFunctions.ModularAndVoice:
                    param.Command.MCommand = (PortEnums.MCommands)command;
                    param.ModuleParam      = new ModuleParameter();
                    switch (param.Command.MCommand)
                    {
                    case PortEnums.MCommands.SetModule:
                        param.ModuleParam.Result = by[6] == 89;
                        break;

                    case PortEnums.MCommands.TestCommunication:
                        param.ModuleParam.Result = by[6] == 83;
                        break;
                    }
                    break;

                case PortEnums.DealFunctions.HostResult:
                    param.Command.HCommand = (PortEnums.HCommands)command;
                    param.HostParam        = new HostParameter();
                    switch (param.Command.HCommand)
                    {
                    case PortEnums.HCommands.Search:
                        break;

                    case PortEnums.HCommands.ReadData:
                        break;
                    }
                    break;

                case PortEnums.DealFunctions.HostNoResult:
                case PortEnums.DealFunctions.ProsennelHost:
                    param.Command.HCommand = (PortEnums.HCommands)command;
                    param.HostParam        = new HostParameter();
                    switch (param.Command.HCommand)
                    {
                    case PortEnums.HCommands.Password:
                    case PortEnums.HCommands.Time:
                        param.HostParam.Result = by[12] == 49;
                        break;

                    case PortEnums.HCommands.NumberModify:
                        param.HostParam.Result = by[6] == 49;
                        break;
                    }
                    break;
                }
            }
            else if (param.Header == 10)
            {
                param.DeviceAddress    = Utility.HexToInt(by[1], by[2]);
                param.Command.PCommand = (PortEnums.PCommands)Utility.HexToInt(by[3], by[4]);
                switch (param.Command.PCommand)
                {
                case PortEnums.PCommands.Default:
                    string   strTime  = Encoding.Default.GetString(by, 15, 6);
                    DateTime cardTime = DateTime.MinValue;
                    if (CRegex.IsTime(strTime))
                    {
                        cardTime = DateTime.ParseExact(strTime, "yyMMdd", System.Globalization.CultureInfo.InstalledUICulture);
                    }
                    strTime = Encoding.Default.GetString(by, 21, 6);
                    DateTime systemTime = DateTime.MinValue;
                    if (CRegex.IsTime(strTime))
                    {
                        systemTime = DateTime.ParseExact(strTime, "yyMMdd", System.Globalization.CultureInfo.InstalledUICulture);
                    }
                    param.PersonnelParam = new PersonnelParameter()
                    {
                        CorridorNumber   = Utility.HexToInt(by[5], by[6]),
                        HostNumber       = Utility.HexToInt(by[7], by[8]),
                        CardNumber       = Encoding.ASCII.GetString(by, 9, 6),
                        CardTime         = cardTime,
                        SystemTime       = systemTime,
                        OpenTheDoorState = Utility.HexToInt(by[27], by[28])
                    };
                    break;
                }
            }
            return(param);
        }