Multiprocotol Terminalprogram (BAT)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MultiTerm/MultiTerm.Core/ViewModel/ByteDataViewModel.cs

74 lines
2.1 KiB

using CommunityToolkit.Mvvm.ComponentModel;
using MultiTerm.Protocols.Model;
using System.Text;
namespace MultiTerm.Core.ViewModel;
public partial class ByteDataViewModel : ObservableObject, IDataViewModel, IComparable<ByteDataViewModel>
{
/// <summary>
/// Object of data model.
/// </summary>
private readonly ExtendedByte data;
#region IDataViewModel Implementation
[ObservableProperty]
private int lineIdentifier;
[ObservableProperty]
private TimeOnly time;
[ObservableProperty]
private string displayStringChar = String.Empty;
[ObservableProperty]
private string displayStringHex = String.Empty;
[ObservableProperty]
private string displayStringBin = String.Empty;
#endregion
/// <summary>
/// Allows access to the low level data byte.
/// </summary>
public byte Byte => this.data.Byte;
/// <summary>
/// Instanciates new <see cref="ByteDataViewModel"/>.
/// Initializes internal variables with data according to <paramref name="extendedByte"/>.
/// </summary>
/// <param name="extendedByte">data</param>
/// <param name="lineIdentifier">identifies line in which this byte is located</param>
public ByteDataViewModel(ExtendedByte extendedByte, int lineIdentifier)
{
this.data = extendedByte;
this.lineIdentifier = lineIdentifier;
this.DisplayStringChar = extendedByte.ToCharacterString();
this.DisplayStringHex = extendedByte.ToHexString();
this.DisplayStringBin = extendedByte.ToBinaryString();
this.Time = extendedByte.Time;
}
#region IComparable Implementation
/// <summary>
/// IComparable method. To allow sorting <see cref="ByteDataViewModel"/>
/// </summary>
/// <param name="other">compared element</param>
/// <returns></returns>
public int CompareTo(ByteDataViewModel? other)
{
if(other == null)
return 1;
if (other.Time.Ticks > this.Time.Ticks)
return -1;
else if(this.Time.Ticks > other.Time.Ticks)
return 1;
else // equal
return 0;
}
#endregion
}