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); }
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); }
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); }
public static byte[] CombinationLoss(List <LossParameter> lossparams) { int index = 0; int losstype = 87381; StringBuilder sb = new StringBuilder(); foreach (LossParameter item in lossparams) { losstype = BinaryHelper.SetIntegeSomeBit(losstype, index, true); index += 2; sb.Append(item.CardNumber); sb.AppendFormat("{0:X2}", SetFunctionParameeter(item.Function)); sb.AppendFormat("{0:yyMM}", item.Time.AddDays(1)); } string content = string.Format("{0:X2}{1:X6}{2}", lossparams.Count, losstype, sb.ToString()); return(PortAgreement.GetLossContent("797979", content)); }
/// <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); }
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()))); }