Beispiel #1
0
        private static int SetFunctionParameeter(FunctionByteParameter?parameter)
        {
            int functionbyte = 0;

            if (parameter == null)
            {
                return(-1);
            }
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 7, parameter.Value.Loss != 0);
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 6, parameter.Value.Synchronous != 0);
            if (parameter.Value.RegistrationType == CardType.SingleCard)
            {
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, true);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, false);
            }
            else if (parameter.Value.RegistrationType == CardType.CombinationCard)
            {
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, false);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, false);
            }
            else
            {
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, true);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, false);
            }
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 4, parameter.Value.ParkingRestrictions != 0);
            for (int i = 0; i < 2; i++)
            {
                int vicecountbinary = BinaryHelper.GetIntegerSomeBit(parameter.Value.ViceCardCount - 1, i);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 3 - i, vicecountbinary != 0);
            }
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 0, parameter.Value.InOutState != 0);
            return(functionbyte);
        }
Beispiel #2
0
        private static int SetTypeParameter(DistanceParameterContent parameter, object obj)
        {
            int type = 0;

            if (parameter.Type != null)
            {
                type = 1;
                if (parameter.Function != null || obj != null)
                {
                    type = 2;
                }
                type = BinaryHelper.SetIntegeSomeBit(type, 7, parameter.Type.Value.Lock != 0);
                if (parameter.Type.Value.Distance > 0)
                {
                    type = BinaryHelper.SetIntegeSomeBit(type, 6, true);
                    for (int i = 0; i < 2; i++)
                    {
                        int distancebinary = BinaryHelper.GetIntegerSomeBit(parameter.Type.Value.Distance - 1, i);
                        type = BinaryHelper.SetIntegeSomeBit(type, 5 - i, distancebinary != 0);
                    }
                }
                else
                {
                    type = BinaryHelper.SetIntegeSomeBit(type, 6, false);
                }
            }
            return(type);
        }
Beispiel #3
0
        private static int SetCardFunctionByte(FunctionByteParameter param)
        {
            int functionbyte = BinaryHelper.SetIntegeSomeBit(0, 7, param.Loss == 1);

            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 6, param.Synchronous == 1);
            switch (param.RegistrationType)
            {
            case CardTypes.SingleCard:
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, true);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, false);
                break;

            case CardTypes.CombinationCard:
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, false);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, false);
                break;

            default:
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 5, false);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 1, true);
                break;
            }
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 4, param.ParkingRestrictions != 0);
            for (int i = 0; i < 2; i++)
            {
                int vicebinary = BinaryHelper.GetIntegerSomeBit(param.ViceCardCount, i);
                functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 3 - i, vicebinary != 0);
            }
            functionbyte = BinaryHelper.SetIntegeSomeBit(functionbyte, 0, param.InOutState != 0);
            return(functionbyte);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        /// <param name="num">0 写入数据  1 写入类型 2 写入数据和类型</param>
        /// <returns></returns>
        public static int SetCardTypeByte(DistanceTypeParameter param, int num)
        {
            int typebyte = num;

            typebyte = BinaryHelper.SetIntegeSomeBit(typebyte, 7, param.Lock != 0);
            if (param.Distance < 4)
            {
                typebyte = BinaryHelper.SetIntegeSomeBit(typebyte, 6, true);
                for (int i = 0; i < 2; i++)
                {
                    int distance = BinaryHelper.GetIntegerSomeBit(param.Distance, i);
                    typebyte = BinaryHelper.SetIntegeSomeBit(typebyte, 4 + i, distance != 0);
                }
            }
            else
            {
                typebyte = BinaryHelper.SetIntegeSomeBit(typebyte, 6, false);
            }
            return(typebyte);
        }
Beispiel #5
0
        public static FunctionByteParameter DistanceFunctionByte(int functionbyte)
        {
            FunctionByteParameter parameter = new FunctionByteParameter();

            parameter.Loss        = BinaryHelper.GetIntegerSomeBit(functionbyte, 7);
            parameter.Synchronous = BinaryHelper.GetIntegerSomeBit(functionbyte, 6);
            int registrationtype = BinaryHelper.GetIntegerSomeBit(functionbyte, 5);

            if (registrationtype == 0)
            {
                parameter.RegistrationType = BinaryHelper.GetIntegerSomeBit(functionbyte, 1) == 1 ? CardType.LPRCard : CardType.CombinationCard;
            }
            else
            {
                parameter.RegistrationType = CardType.SingleCard;
            }
            parameter.ParkingRestrictions = BinaryHelper.GetIntegerSomeBit(functionbyte, 4);
            parameter.ViceCardCount       = BinaryHelper.GetBitToInt(functionbyte, 2, 2);
            parameter.InOutState          = BinaryHelper.GetIntegerSomeBit(functionbyte, 0);
            return(parameter);
        }
Beispiel #6
0
        public static DistanceTypeParameter DistanceType(int type)
        {
            DistanceTypeParameter parameter = new DistanceTypeParameter();

            parameter.Battry = BinaryHelper.GetIntegerSomeBit(type, 3);
            int cardtype = BinaryHelper.GetBitToInt(type, 0, 3);

            if (cardtype == 0)
            {
                cardtype           = BinaryHelper.GetBitToInt(type, 4, 4);
                parameter.CardType = (CardTypes)(cardtype += 1);
            }
            else
            {
                if (cardtype == 1 || cardtype == 5)
                {
                    parameter.CardType = (CardTypes)0;
                }
                else if (cardtype == 2)
                {
                    parameter.CardType = (CardTypes)1;
                }
                else if (cardtype == 3 || cardtype == 7)
                {
                    parameter.CardType = (CardTypes)3;
                }
            }
            parameter.Lock     = BinaryHelper.GetIntegerSomeBit(type, 7);
            parameter.Distance = BinaryHelper.GetIntegerSomeBit(type, 6);
            if (parameter.Distance == 1)
            {
                parameter.Distance = BinaryHelper.GetBitToInt(type, 4, 2);
                //parameter.Distance += 1;
            }
            else
            {
                parameter.Distance = 4;
            }
            return(parameter);
        }
Beispiel #7
0
        public static byte[] SetLossCard(LossCardDataParam[] param)
        {
            StringBuilder sb       = new StringBuilder();
            int           datatype = 16777215;
            int           cardtype = 1;
            int           index    = 23;

            foreach (LossCardDataParam item in param)
            {
                cardtype = item.CardType != CardTypes.ViceCard ? 2 : 1;
                for (int i = 0; i < 2; i++)
                {
                    int typebinary = BinaryHelper.GetIntegerSomeBit(cardtype, i);
                    datatype = BinaryHelper.SetIntegeSomeBit(datatype, index - i, typebinary != 0);
                }
                index -= 2;
                sb.Append(item.CardNumber);
                sb.AppendFormat("{0:X2}", BinaryHelper.SetIntegeSomeBit(item.Functionbyte, 7, true));
                sb.AppendFormat("{0:yyMM}", item.CardTime.AddMonths(1));
            }
            return(PortAgreement.GetDistanceContent("797979", 0, string.Format("{0:X2}{1:X6}{2}", param.Length, datatype, sb.ToString())));
        }