public EF_Identification(byte[] value, short cardType) { this.cardType = cardType; cardIdentification = new CardIdentification(HexBytes.arrayCopy(value, 0, 65), cardType); if (EquipmentType.COMPANY_CARD == cardType) { companyCardHolderIdentification = new CompanyCardHolderIdentification(HexBytes.arrayCopy(value, 65, value.Length - 65)); structureSize = CompanyCardHolderIdentification.structureSize; } else if (EquipmentType.CONTROL_CARD == cardType) { controlCardHolderIdentification = new ControlCardHolderIdentification(HexBytes.arrayCopy(value, 65, value.Length - 65)); structureSize = ControlCardApplicationIdentification.structureSize; } else if (EquipmentType.DRIVER_CARD == cardType) { driverCardHolderIdentification = new DriverCardHolderIdentification(HexBytes.arrayCopy(value, 65, 78)); structureSize = DriverCardHolderIdentification.structureSize; } else if (EquipmentType.WORKSHOP_CARD == cardType) { workshopCardHolderIdentification = new WorkshopCardHolderIdentification(HexBytes.arrayCopy(value, 65, value.Length - 65)); structureSize = WorkshopCardHolderIdentification.structureSize; } else { //Error!!! } }
public Vehicle_Activities(byte[] value) { int offset1 = 7; downloadedDayDate = new TimeReal(HexBytes.arrayCopy(value, 0, 4)); odoMeterValueMidnight = new OdometerShort(HexBytes.arrayCopy(value, 4, 3)); int offset2 = 2 + HexBytes.convertIntoUnsigned2ByteInt(HexBytes.arrayCopy(value, offset1, 2)) * VuCardIWRecord.structureSize; vuCardIWData = new VuCardIWData(HexBytes.arrayCopy(value, offset1, offset2)); int offset3 = 2 + HexBytes.convertIntoUnsigned2ByteInt(HexBytes.arrayCopy(value, offset1 + offset2, 2)) * ActivityChangeInfo.structureSize; vuActivityDailyData = new VuActivityDailyData(HexBytes.arrayCopy(value, offset1 + offset2, offset3), downloadedDayDate); int offset4 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1 + offset2 + offset3]) * VuPlaceDailyWorkPeriodRecord.structureSize; vuPlaceDailyWorkPeriodData = new VuPlaceDailyWorkPeriodData(HexBytes.arrayCopy(value, offset1 + offset2 + offset3, offset4)); int offset5 = 2 + HexBytes.convertIntoUnsigned2ByteInt(HexBytes.arrayCopy(value, offset1 + offset2 + offset3 + offset4, 2)) * SpecificConditionRecord.structureSize; vuSpecificConditionData = new VuSpecificConditionData(HexBytes.arrayCopy(value, offset1 + offset2 + offset3 + offset4, offset5)); structureSize = offset1 + offset2 + offset3 + offset4 + offset5; }
public Vehicle_Detailed_Speed(byte[] value) { int offset1 = HexBytes.convertIntoUnsigned2ByteInt(HexBytes.arrayCopy(value, 0, 2)) * VuDetailedSpeedBlock.structureSize; vuDetailedSpeedData = new VuDetailedSpeedData(value); size = offset1; }
/// <summary> /// construct the word from the entire enumeration /// </summary> /// <param name="source"></param> public Word(IEnumerable <byte> source) { foreach (byte b in source) { Length++; HexBytes.Add(new HexByte(b)); } }
/// <summary> /// constructor: take a word from the enumeration @start for length bytes /// </summary> /// <param name="buffer"></param> /// <param name="start"></param> /// <param name="length"></param> public Word(IEnumerable <byte> buffer, int start, int length) { foreach (byte b in buffer.Skip(start).Take(length)) { Length++; HexBytes.Add(new HexByte(b)); } }
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) { int b = hexBytes.TryReadByte(valueIndex); if (b < 0) { return(WriteInvalid(dest)); } return(WriteFormattedValue(dest, b.ToString(culture))); }
public EF_Application_Identification(byte[] value) { // size = value.length; cardType = HexBytes.convertIntoUnsigned1ByteInt(value[0]); switch (cardType) { case 1: //DRIVER_CARD { driverCardApplicationIdentification = new DriverCardApplicationIdentification(value); cardStructureVersion = driverCardApplicationIdentification.cardStructureVersion.Get_CardStructureVersion_Bytes(); noOfEventsPerType = driverCardApplicationIdentification.noOfEventsPerType.noOfEventsPerType; noOfFaultsPerType = driverCardApplicationIdentification.noOfFaultsPerType.noOfFaultsPerType; activityStructureLength = driverCardApplicationIdentification.activityStructureLength.cardActivityLengthRange; noOfCardVehicleRecords = driverCardApplicationIdentification.noOfCardVehicleRecords.noOfCardVehicleRecords; noOfCardPlaceRecords = driverCardApplicationIdentification.noOfCardPlaceRecords.noOfCardPlaceRecords; } break; case 2: //WORKSHOP_CARD { workshopCardApplicationIdentification = new WorkshopCardApplicationIdentification(value); cardStructureVersion = workshopCardApplicationIdentification.cardStructureVersion.Get_CardStructureVersion_Bytes(); noOfEventsPerType = workshopCardApplicationIdentification.noOfEventsPerType.noOfEventsPerType; noOfFaultsPerType = workshopCardApplicationIdentification.noOfFaultsPerType.noOfFaultsPerType; activityStructureLength = workshopCardApplicationIdentification.activityStructureLength.cardActivityLengthRange; noOfCardVehicleRecords = workshopCardApplicationIdentification.noOfCardVehicleRecords.noOfCardVehicleRecords; noOfCardPlaceRecords = workshopCardApplicationIdentification.noOfCardPlaceRecords.noOfCardPlaceRecords; noOfCalibrationRecords = workshopCardApplicationIdentification.noOfCalibrationRecords.noOfCalibrationRecords; } break; case 3: //CONTROL_CARD { controlCardApplicationIdentification = new ControlCardApplicationIdentification(value); cardStructureVersion = controlCardApplicationIdentification.cardStructureVersion.Get_CardStructureVersion_Bytes(); noOfControlActivityRecords = controlCardApplicationIdentification.noOfControlActivityRecords.noOfControlActivityRecords; } break; case 4: //COMPANY_CARD { companyCardApplicationIdentification = new CompanyCardApplicationIdentification(value); cardStructureVersion = companyCardApplicationIdentification.cardStructureVersion.Get_CardStructureVersion_Bytes(); noOfCompanyActivityRecords = companyCardApplicationIdentification.noOfCompanyActivityRecords.noOfCompanyActivityRecords; } break; default: break; } }
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) { int b = hexBytes.TryReadByte(valueIndex); if (b < 0) { return(WriteInvalid(dest)); } WriteHexByte(dest, flags, (byte)b); return(0); }
public Vehicle_Technical_Data(byte[] value) { int offset1 = 116 + 20; vuIdentification = new VuIdentification(HexBytes.arrayCopy(value, 0, 116)); sensorPaired = new SensorPaired(HexBytes.arrayCopy(value, 116, 20)); int offset2 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[136]) * VuCalibrationRecord.structureSize; vuCalibrationData = new VuCalibrationData(HexBytes.arrayCopy(value, 136, offset2)); size = offset1 + offset2; }
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) { int b = hexBytes.TryReadByte(valueIndex); if (b < 0) { return(WriteInvalid(dest)); } for (int i = 0; i < 8; i++, b <<= 1) { dest.Append((b & 0x80) != 0 ? '1' : '0'); } return(0); }
public HexBufferLineImpl(HexBufferLineFormatter hexBufferLineFormatter, HexPosition lineNumber, ReadOnlyCollection <HexColumnType> columnOrder, HexBufferSpan bufferSpan, HexBytes hexBytes, string text, bool isOffsetColumnPresent, bool isValuesColumnPresent, bool isAsciiColumnPresent, HexPosition logicalOffset, HexCellCollection valueCells, HexCellCollection asciiCells, VST.Span offsetSpan, VST.Span fullValuesSpan, VST.Span visibleValuesSpan, VST.Span fullAsciiSpan, VST.Span visibleAsciiSpan) { if (hexBufferLineFormatter == null) { throw new ArgumentNullException(nameof(hexBufferLineFormatter)); } if (columnOrder == null) { throw new ArgumentNullException(nameof(columnOrder)); } if (bufferSpan.IsDefault) { throw new ArgumentException(); } if (hexBytes.IsDefault) { throw new ArgumentException(); } if (text == null) { throw new ArgumentNullException(nameof(text)); } if (valueCells.IsDefault) { throw new ArgumentNullException(nameof(valueCells)); } if (asciiCells.IsDefault) { throw new ArgumentNullException(nameof(asciiCells)); } LineProvider = hexBufferLineFormatter; LineNumber = lineNumber; ColumnOrder = columnOrder; BufferSpan = bufferSpan; HexBytes = hexBytes; Text = text; IsOffsetColumnPresent = isOffsetColumnPresent; IsValuesColumnPresent = isValuesColumnPresent; IsAsciiColumnPresent = isAsciiColumnPresent; LogicalOffset = logicalOffset; ValueCells = valueCells; AsciiCells = asciiCells; this.offsetSpan = offsetSpan; this.fullValuesSpan = fullValuesSpan; this.visibleValuesSpan = visibleValuesSpan; this.fullAsciiSpan = fullAsciiSpan; this.visibleAsciiSpan = visibleAsciiSpan; }
public Vehicle_Overview(byte[] value) { int offset1 = 194 + 194 + 17 + 1 + 14 + 4 + 4 + 4 + 1 + 4 + 18 + 36; memberStateCertificate = new MemberStateCertificate(HexBytes.arrayCopy(value, 0, 194)); vuCertificate = new VuCertificate(HexBytes.arrayCopy(value, 194, 194)); vehicleIdentificationNumber = new VehicleIdentificationNumber(HexBytes.arrayCopy(value, 388, 17)); vehicleRegistrationIdentification = new VehicleRegistrationIdentification(HexBytes.arrayCopy(value, 405, 15)); currentDateTime = new CurrentDateTime(HexBytes.arrayCopy(value, 420, 4)); vuDownloadablePeriod = new VuDownloadablePeriod(HexBytes.arrayCopy(value, 424, 8)); cardSlotsStatus = new CardSlotsStatus(value[432]); vuDownloadActivityData = new VuDownloadActivityData(HexBytes.arrayCopy(value, 433, 58)); int offset2 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1]) * VuCompanyLocksRecord.structureSize; vuCompanyLocksData = new VuCompanyLocksData(HexBytes.arrayCopy(value, offset1, offset2)); int offset3 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1 + offset2]) * VuControlActivityRecord.structureSize; vuControlActivityData = new VuControlActivityData(HexBytes.arrayCopy(value, offset1 + offset2, offset3)); size = offset1 + offset2 + offset3; }
public Vehicle_Events_And_Faults(byte[] value) { int offset1 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[0]) * VuFaultRecord.structureSize; vuFaultData = new VuFaultData(HexBytes.arrayCopy(value, 0, offset1)); int offset2 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1]) * VuEventRecord.structureSize; vuEventData = new VuEventData(HexBytes.arrayCopy(value, offset1, offset2)); int offset3 = 9; vuOverSpeedingControlData = new VuOverSpeedingControlData(HexBytes.arrayCopy(value, offset1 + offset2, offset3)); int offset4 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1 + offset2 + offset3]) * VuOverSpeedingEventRecord.structureSize; vuOverSpeedingEventData = new VuOverSpeedingEventData(HexBytes.arrayCopy(value, offset1 + offset2 + offset3, offset4)); int offset5 = 1 + HexBytes.convertIntoUnsigned1ByteInt(value[offset1 + offset2 + offset3 + offset4]) * VuTimeAdjustmentRecord.structureSize; vuTimeAdjustmentData = new VuTimeAdjustmentData(HexBytes.arrayCopy(value, offset1 + offset2 + offset3 + offset4, offset5)); structureSize = offset1 + offset2 + offset3 + offset4 + offset5; }
public string Should_convert_bytes_to_hex_string(HexBytes hexBytes) { return(hexBytes.Bytes.ToHexString(hexBytes.Caps, hexBytes.Min, hexBytes.SpaceEveryByte, hexBytes.TrimZeros)); }
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) => FormatDouble(dest, flags, hexBytes.TryReadDouble(valueIndex));
HexCell[] WriteValues(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan) { Debug.Assert(showValues); cellList.Clear(); int fullStart = CurrentTextIndex; ulong cellCount = bytesPerLine / (ulong)valueFormatter.ByteCount; var flags = valuesLowerCaseHex ? HexValueFormatterFlags.LowerCaseHex : HexValueFormatterFlags.None; var pos = visibleBytesSpan.Start; var end = visibleBytesSpan.Start + bytesPerLine; int? visStart = null; int? visEnd = null; int cellPos = 0; for (ulong i = 0; i < cellCount; i++) { if (i != 0) { stringBuilder.Append(' '); } int groupIndex = (cellPos / groupSizeInBytes) & 1; HexBufferSpan bufferSpan; int cellStart = CurrentTextIndex; int spaces; if (visibleBytesSpan.Contains(pos)) { if (visStart == null) { visStart = CurrentTextIndex; } long valueIndex = (long)(pos - visibleBytesSpan.Start).ToUInt64(); spaces = valueFormatter.FormatValue(stringBuilder, hexBytes, valueIndex, flags); var endPos = HexPosition.Min(endPosition, pos + (ulong)valueFormatter.ByteCount); bufferSpan = new HexBufferSpan(new HexBufferPoint(buffer, pos), new HexBufferPoint(buffer, endPos)); } else { if (visStart != null && visEnd == null) { visEnd = CurrentTextIndex; } stringBuilder.Append(' ', valueFormatter.FormattedLength); spaces = valueFormatter.FormattedLength; bufferSpan = default; } if (cellStart + valueFormatter.FormattedLength != CurrentTextIndex) { throw new InvalidOperationException(); } var textSpan = VST.Span.FromBounds(cellStart + spaces, CurrentTextIndex); var cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex); VST.Span separatorSpan; if (i + 1 < cellCount) { separatorSpan = new VST.Span(CurrentTextIndex, 1); } else { separatorSpan = new VST.Span(CurrentTextIndex, 0); } var cellFullSpan = VST.Span.FromBounds(cellStart, separatorSpan.End); cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, textSpan, cellSpan, separatorSpan, cellFullSpan)); pos += (ulong)valueFormatter.ByteCount; cellPos += valueFormatter.ByteCount; } if (pos != end) { throw new InvalidOperationException(); } if (visStart != null && visEnd == null) { visEnd = CurrentTextIndex; } visibleSpan = visStart == null ? default : VST.Span.FromBounds(visStart.Value, visEnd.Value); fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex); if (ValuesSpan != fullSpan) { throw new InvalidOperationException(); } return(cellList.ToArray()); }
/// <summary> /// Formats the value and returns the number of spaces that were inserted before the number /// so exactly <see cref="FormattedLength"/> characters were written to <paramref name="dest"/> /// </summary> /// <param name="dest">Destination string builder</param> /// <param name="hexBytes">Bytes</param> /// <param name="valueIndex">Index of value in <paramref name="hexBytes"/></param> /// <param name="flags">Flags</param> /// <returns></returns> public abstract int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags);
HexCell[] WriteAscii(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan) { Debug.Assert(showAscii); cellList.Clear(); int fullStart = CurrentTextIndex; int?visStart = null; int?visEnd = null; var pos = visibleBytesSpan.Start; int cellPos = 0; for (ulong i = 0; i < bytesPerLine; i++, pos++) { int groupIndex = (cellPos / groupSizeInBytes) & 1; HexBufferSpan bufferSpan; int cellStart = CurrentTextIndex; if (visibleBytesSpan.Contains(pos)) { if (visStart == null) { visStart = CurrentTextIndex; } long index = (long)(pos - visibleBytesSpan.Start).ToUInt64(); int b = hexBytes.TryReadByte(index); if (b < 0) { stringBuilder.Append('?'); } else if (b < 0x20 || b > 0x7E) { stringBuilder.Append('.'); } else { stringBuilder.Append((char)b); } bufferSpan = new HexBufferSpan(buffer, new HexSpan(pos, 1)); } else { if (visStart != null && visEnd == null) { visEnd = CurrentTextIndex; } stringBuilder.Append(' '); bufferSpan = default; } var cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex); var separatorSpan = new VST.Span(cellSpan.End, 0); cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, cellSpan, cellSpan, separatorSpan, cellSpan)); cellPos++; } if ((ulong)fullStart + bytesPerLine != (ulong)CurrentTextIndex) { throw new InvalidOperationException(); } if (visStart != null && visEnd == null) { visEnd = CurrentTextIndex; } visibleSpan = visStart == null ? default : VST.Span.FromBounds(visStart.Value, visEnd.Value); fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex); if (AsciiSpan != fullSpan) { throw new InvalidOperationException(); } return(cellList.ToArray()); }
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) => FormatHexUInt32(dest, flags, hexBytes.TryReadUInt32BigEndian(valueIndex));
public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags) => FormatDecimalInt64(dest, flags, hexBytes.TryReadInt64BigEndian(valueIndex));
public string Should_convert_bytes_to_hex_string(HexBytes hexBytes) { return hexBytes.Bytes.ToHexString(hexBytes.Caps, hexBytes.Min, hexBytes.SpaceEveryByte, hexBytes.TrimZeros); }