Selaa lähdekoodia

修改FixedByteLength增加TIME的长度,并在Formatter中写入Header的TIME字段

pull/2/head
算神 5 vuotta sitten
vanhempi
commit
71bd619e00
6 muutettua tiedostoa jossa 42 lisäystä ja 32 poistoa
  1. +11
    -9
      src/JT809.Protocol/Formatters/JT809HeaderFormatter.cs
  2. +8
    -6
      src/JT809.Protocol/Formatters/JT809HeaderPackageFormatter.cs
  3. +10
    -6
      src/JT809.Protocol/Formatters/JT809PackageFormatter.cs
  4. +8
    -6
      src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1001_Formatter.cs
  5. +1
    -1
      src/JT809.Protocol/JT809.Protocol.csproj
  6. +4
    -4
      src/JT809.Protocol/JT809Header.cs

+ 11
- 9
src/JT809.Protocol/Formatters/JT809HeaderFormatter.cs Näytä tiedosto

@@ -15,15 +15,17 @@ namespace JT809.Protocol.Formatters

public JT809Header Deserialize(ref JT809MessagePackReader reader, IJT809Config config)
{
JT809Header jT809Header = new JT809Header();
jT809Header.MsgLength = reader.ReadUInt32();
jT809Header.MsgSN = reader.ReadUInt32();
jT809Header.BusinessType = reader.ReadUInt16();
jT809Header.MsgGNSSCENTERID = reader.ReadUInt32();
jT809Header.Version = new JT809Header_Version(reader.ReadArray(JT809Header_Version.FixedByteLength));
jT809Header.EncryptFlag = (JT809Header_Encrypt)reader.ReadByte();
jT809Header.EncryptKey = reader.ReadUInt32();
jT809Header.Time = reader.ReadUTCDateTime();
JT809Header jT809Header = new JT809Header
{
MsgLength = reader.ReadUInt32(),
MsgSN = reader.ReadUInt32(),
BusinessType = reader.ReadUInt16(),
MsgGNSSCENTERID = reader.ReadUInt32(),
Version = new JT809Header_Version(reader.ReadArray(JT809Header_Version.FixedByteLength)),
EncryptFlag = (JT809Header_Encrypt)reader.ReadByte(),
EncryptKey = reader.ReadUInt32(),
Time = reader.ReadUTCDateTime()
};
return jT809Header;
}



+ 8
- 6
src/JT809.Protocol/Formatters/JT809HeaderPackageFormatter.cs Näytä tiedosto

@@ -19,12 +19,14 @@ namespace JT809.Protocol.Formatters
// 1.2. 验证校验码
if (!reader.CheckXorCodeVali)
{
throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode.ToString()}!={reader.RealCheckXorCode.ToString()}");
throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode}!={reader.RealCheckXorCode}");
}
}
JT809HeaderPackage jT809Package = new JT809HeaderPackage();
// 2.读取起始头
jT809Package.BeginFlag = reader.ReadStart();
JT809HeaderPackage jT809Package = new JT809HeaderPackage
{
// 2.读取起始头
BeginFlag = reader.ReadStart()
};
// 3.初始化消息头
try
{
@@ -32,7 +34,7 @@ namespace JT809.Protocol.Formatters
}
catch (Exception ex)
{
throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex);
throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength()}", ex);
}
// 5.数据体处理
// 5.1 判断是否有数据体(总长度-固定长度)> 0
@@ -56,7 +58,7 @@ namespace JT809.Protocol.Formatters
}
catch (Exception ex)
{
throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex);
throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength()}", ex);
}
}
jT809Package.CRCCode = reader.CalculateCheckXorCode;


+ 10
- 6
src/JT809.Protocol/Formatters/JT809PackageFormatter.cs Näytä tiedosto

@@ -23,12 +23,14 @@ namespace JT809.Protocol.Formatters
// 1.2. 验证校验码
if (!reader.CheckXorCodeVali)
{
throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode.ToString()}!={reader.RealCheckXorCode.ToString()}");
throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode}!={reader.RealCheckXorCode}");
}
}
JT809Package jT809Package = new JT809Package();
// 2.读取起始头
jT809Package.BeginFlag = reader.ReadStart();
JT809Package jT809Package = new JT809Package
{
// 2.读取起始头
BeginFlag = reader.ReadStart()
};
// 3.初始化消息头
try
{
@@ -36,7 +38,7 @@ namespace JT809.Protocol.Formatters
}
catch (Exception ex)
{
throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex);
throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength()}", ex);
}
// 5.数据体处理
// 5.1 判断是否有数据体(总长度-固定长度)> 0
@@ -69,7 +71,7 @@ namespace JT809.Protocol.Formatters
}
catch (Exception ex)
{
throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex);
throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength()}", ex);
}
}
jT809Package.CRCCode = reader.CalculateCheckXorCode;
@@ -98,6 +100,8 @@ namespace JT809.Protocol.Formatters
writer.WriteByte((byte)value.Header.EncryptFlag);
// 2.7.数据加密密钥
writer.WriteUInt32(value.Header.EncryptKey);
// 2.8 发送消息时系统UTC时间
writer.WriteUTCDateTime(value.Header.Time);
// 3.写入数据体
// 3.1.记录当前开始位置
int startIndex = writer.GetCurrentPosition();


+ 8
- 6
src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1001_Formatter.cs Näytä tiedosto

@@ -15,12 +15,14 @@ namespace JT809.Protocol.Formatters.MessageBodyFormatters

public JT809_0x1001 Deserialize(ref JT809MessagePackReader reader, IJT809Config config)
{
JT809_0x1001 jT809_0X1001 = new JT809_0x1001();
jT809_0X1001.UserId = reader.ReadUInt32();
jT809_0X1001.Password = reader.ReadString(8);
jT809_0X1001.MsgGNSSCENTERID = reader.ReadUInt32();
jT809_0X1001.DownLinkIP = reader.ReadString(32);
jT809_0X1001.DownLinkPort = reader.ReadUInt16();
JT809_0x1001 jT809_0X1001 = new JT809_0x1001
{
UserId = reader.ReadUInt32(),
Password = reader.ReadString(8),
MsgGNSSCENTERID = reader.ReadUInt32(),
DownLinkIP = reader.ReadString(32),
DownLinkPort = reader.ReadUInt16()
};
return jT809_0X1001;
}



+ 1
- 1
src/JT809.Protocol/JT809.Protocol.csproj Näytä tiedosto

@@ -14,7 +14,7 @@
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl>
<license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.1.4</Version>
<Version>2.1.5</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>


+ 4
- 4
src/JT809.Protocol/JT809Header.cs Näytä tiedosto

@@ -12,14 +12,14 @@ namespace JT809.Protocol
{
/// <summary>
/// 固定为22个字节长度
/// <para>MSG LENGTH + MSG_SN + MSG_ID + MSG_GNSSCENTERID + VERSION_FLAG + ENCRYPT_FLAG + ENCRYPT_KEY</para>
/// <para>4 + 4 + 2 + 4 + 3 + 1 + 4 = 22</para>
/// <para>MSG LENGTH + MSG_SN + MSG_ID + MSG_GNSSCENTERID + VERSION_FLAG + ENCRYPT_FLAG + ENCRYPT_KEY + TIME</para>
/// <para>4 + 4 + 2 + 4 + 3 + 1 + 4 + 8 = 30</para>
/// </summary>
public const int FixedByteLength = 22;
public const int FixedByteLength = 30;
/// <summary>
/// 数据长度(包括头标识、数据头、数据体和尾标识)
/// <para>头标识 + 数据头 + 数据体 + 尾标识</para>
/// <para>1 + 22 + n + 1</para>
/// <para>1 + 30 + n + 1</para>
/// </summary>
public uint MsgLength { get; set; }
/// <summary>


Ladataan…
Peruuta
Tallenna