Esempio n. 1
0
        private static string PlateNumberToHex(string platenumber)
        {
            StringBuilder sb    = new StringBuilder();
            int           index = 0;

            platenumber = platenumber.PadRight(8, '~');
            if (platenumber[0] == 'W' && platenumber[1] == 'J')
            {
                if (platenumber.Length != 7)
                {
                    sb.Append($"{36:X2}");
                    index = 2;
                }
            }
            for (int i = index; i < platenumber.Length; i++)
            {
                string strChar = platenumber[i].ToString();
                if (CRegex.IsChinese(strChar))
                {
                    int province = (int)Enum.Parse(typeof(PlateProvinces.Provinces), strChar);
                    sb.Append($"{province:X2}");
                }
                else
                {
                    sb.Append($"{Encoding.ASCII.GetBytes(strChar)[0]:X2}");
                }
            }
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 将车牌号的汉字转成编号
        /// </summary>
        /// <param name="lprnumber"></param>
        private static string GetLprNumber(string lprnumber)
        {
            StringBuilder sb    = new StringBuilder();
            int           index = 0;

            lprnumber = lprnumber.PadRight(8, '~');
            if (lprnumber[0] == 'W' && lprnumber[1] == 'J')
            {
                if (lprnumber.Length != 7)
                {
                    sb.AppendFormat("{0:X2}", 36);
                    index = 2;
                }
            }
            for (int a = index; a < lprnumber.Length; a++)
            {
                if (CRegex.GetChinese(lprnumber[a].ToString()))
                {
                    PlateProvinces.Provinces lpr = (PlateProvinces.Provinces)Enum.Parse(typeof(PlateProvinces.Provinces), lprnumber[a].ToString());
                    int str = (int)lpr;
                    sb.AppendFormat("{0:X2}", str);
                }
                else
                {
                    sb.AppendFormat("{0:X2}", Encoding.ASCII.GetBytes(lprnumber[a].ToString())[0]);
                }
            }
            return(sb.ToString());
        }
Esempio n. 3
0
        private static string GetPlateNumber(string platenumber)
        {
            StringBuilder sb    = new StringBuilder();
            int           index = 0;

            platenumber = platenumber.PadRight(8, '~');
            if (platenumber[0] == 'W' && platenumber[1] == 'J')
            {
                if (platenumber.Length != 7)
                {
                    sb.AppendFormat("{0:X2}", 36);
                    index = 2;
                }
            }
            for (int a = index; a < platenumber.Length; a++)
            {
                string strchar = platenumber[a].ToString();
                if (CRegex.IsChinese(strchar))
                {
                    PlateProvinces.Provinces provincenumber = (PlateProvinces.Provinces)Enum.Parse(typeof(PlateProvinces.Provinces), strchar);
                    sb.AppendFormat("{0:X2}", (int)provincenumber);
                }
                else
                {
                    sb.AppendFormat("{0:X2}", Encoding.ASCII.GetBytes(strchar)[0]);
                }
            }
            return(sb.ToString());
        }
Esempio n. 4
0
 public static int BinaryToInt(string str)
 {
     if (string.IsNullOrEmpty(str))
     {
         throw new ArgumentNullException();
     }
     if (!CRegex.IsBinary(str))
     {
         throw new ArgumentException();
     }
     return(Convert.ToInt32(str, 2));
 }
Esempio n. 5
0
 public static int StrToInt(string str)
 {
     if (string.IsNullOrEmpty(str))
     {
         throw new ArgumentNullException();
     }
     if (!CRegex.IsDecimal(str))
     {
         throw new ArgumentException();
     }
     return(Convert.ToInt32(str));
 }
Esempio n. 6
0
 public static string BinaryToHex(string str)
 {
     if (string.IsNullOrEmpty(str))
     {
         throw new ArgumentNullException();
     }
     if (!CRegex.IsBinary(str))
     {
         throw new ArgumentException();
     }
     return(string.Format("{0:X2}", Convert.ToInt32(str, 2)));
 }
Esempio n. 7
0
        public static string HexToBinary(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                throw new ArgumentNullException();
            }
            if (!CRegex.IsHex(str))
            {
                throw new ArgumentException();
            }
            int value = Convert.ToInt32(str, 16);

            return(Convert.ToString(value, 2).PadLeft(8, '0'));
        }
Esempio n. 8
0
 private static byte[] LincensePlateToByte(string licenseplate)
 {
     byte[] by = new byte[9];
     Encoding.Default.GetBytes(licenseplate, 0, licenseplate.Length, by, 0);
     if (licenseplate.Length == 7)
     {
         string charlicenseplate = licenseplate[6].ToString();
         if (CRegex.IsChinese(charlicenseplate))
         {
             by[7] = (byte)(PlateProvinces.Provinces)Enum.Parse(typeof(PlateProvinces.Provinces), charlicenseplate);
         }
         by[8] = 126;
     }
     //by[9] = 48;
     return(by);
 }
Esempio n. 9
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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public static string GetModuleUpdateContent(byte[] by)
        {
            string str = GetLicensePlate(by, 0, 10);

            return(CRegex.IsPlate(str) ? str : string.Empty);
        }