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.

57 lines
1.7 KiB

using HybirdFrameworkCore.Autofac.Attribute;
6 months ago
using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.Common;
using Service.Car.Common;
namespace Service.Car.Msg;
6 months ago
public class BaseMsg : IToBytes
{
[Property(0, 8 * 3)] public byte[] StartChar { get; set; } = CarConst.StartChar;
[Property(24, 16)] public ushort Length { get; set; }
[Property(40, 8)] public byte Cmd { get; set; }
[Property(48, 17 * 8)] public string CarNo { get; set; }
/// <summary>
/// Byte[0] yearH200x14
/// Byte[1] yearL (20) 0x14
/// Byte[2] mon
/// Byte[3] day
/// Byte[4] Hour
/// Byte[5] min
/// Byte[6] sec
/// Byte[7] 无
/// </summary>
[Property(184, 8)]
public byte YearH { get; set; }
[Property(184 + 8, 8)] public byte YearL { get; set; }
[Property(184 + 2 * 8, 8)] public byte Month { get; set; }
[Property(184 + 3 * 8, 8)] public byte Day { get; set; }
[Property(184 + 4 * 8, 8)] public byte Hour { get; set; }
[Property(184 + 5 * 8, 8)] public byte Min { get; set; }
[Property(184 + 6 * 8, 8)] public byte Second { get; set; }
public void InitCurrentTime()
{
DateTime now = DateTime.Now;
var num = now.Year;
var d = num / 1000; //千
var c = (num - d * 1000) / 100;
var b = (num - d * 1000 - c * 100) / 10;
var a = num % 10;
YearH = (byte)(d * 10 + c);
YearL = (byte)(b * 10 + a);
Month = (byte)now.Month;
Day = (byte)now.Day;
Hour = (byte)now.Hour;
Min = (byte)now.Minute;
Second = (byte)now.Second;
}
public byte[] ToBytes()
{
6 months ago
return ModelConvert.Encode(this);
}
}