Przeglądaj źródła

增加808接口配置属性是否需要去0判断

tags/v2.1.3^0
smallchi 5 lat temu
rodzic
commit
973bf71b87
9 zmienionych plików z 30 dodań i 13 usunięć
  1. +1
    -1
      src/JT808.Protocol/Formatters/JT808HeaderFormatter.cs
  2. +1
    -1
      src/JT808.Protocol/Formatters/JT808HeaderPackageFormatter.cs
  3. +1
    -1
      src/JT808.Protocol/Formatters/JT808PackageFormatter.cs
  4. +1
    -1
      src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x0107_Formatter.cs
  5. +4
    -1
      src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs
  6. +2
    -0
      src/JT808.Protocol/Interfaces/GlobalConfigBase.cs
  7. +6
    -0
      src/JT808.Protocol/Interfaces/IJT808Config.cs
  8. +3
    -3
      src/JT808.Protocol/JT808HeaderMessageBodyProperty.cs
  9. +11
    -5
      src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs

+ 1
- 1
src/JT808.Protocol/Formatters/JT808HeaderFormatter.cs Wyświetl plik

@@ -20,7 +20,7 @@ namespace JT808.Protocol.Formatters
// 2.消息体属性
jT808Header.MessageBodyProperty = new JT808HeaderMessageBodyProperty(reader.ReadUInt16());
// 3.终端手机号
jT808Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength);
jT808Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength, config.Trim);
jT808Header.MsgNum = reader.ReadUInt16();
// 4.判断有无分包
if (jT808Header.MessageBodyProperty.IsPackage)


+ 1
- 1
src/JT808.Protocol/Formatters/JT808HeaderPackageFormatter.cs Wyświetl plik

@@ -32,7 +32,7 @@ namespace JT808.Protocol.Formatters
// 3.2.1.解包消息体属性
jT808Package.Header.MessageBodyProperty = new JT808HeaderMessageBodyProperty(messageBodyPropertyValue);
// 3.3.读取终端手机号
jT808Package.Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength);
jT808Package.Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength, config.Trim);
// 3.4.读取消息流水号
jT808Package.Header.MsgNum = reader.ReadUInt16();
// 3.5.判断有无分包


+ 1
- 1
src/JT808.Protocol/Formatters/JT808PackageFormatter.cs Wyświetl plik

@@ -34,7 +34,7 @@ namespace JT808.Protocol.Formatters
// 3.2.读取消息体属性
jT808Package.Header.MessageBodyProperty=new JT808HeaderMessageBodyProperty(reader.ReadUInt16());
// 3.3.读取终端手机号
jT808Package.Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength);
jT808Package.Header.TerminalPhoneNo = reader.ReadBCD(config.TerminalPhoneNoLength, config.Trim);
// 3.4.读取消息流水号
jT808Package.Header.MsgNum= reader.ReadUInt16();
// 3.5.判断有无分包


+ 1
- 1
src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x0107_Formatter.cs Wyświetl plik

@@ -15,7 +15,7 @@ namespace JT808.Protocol.Formatters.MessageBodyFormatters
jT808_0X0107.MakerId = reader.ReadString(5);
jT808_0X0107.TerminalModel = reader.ReadString(20);
jT808_0X0107.TerminalId = reader.ReadString(7);
jT808_0X0107.Terminal_SIM_ICCID = reader.ReadBCD(10);
jT808_0X0107.Terminal_SIM_ICCID = reader.ReadBCD(10, config.Trim);
jT808_0X0107.Terminal_Hardware_Version_Length = reader.ReadByte();
jT808_0X0107.Terminal_Hardware_Version_Num = reader.ReadString(jT808_0X0107.Terminal_Hardware_Version_Length);
jT808_0X0107.Terminal_Firmware_Version_Length = reader.ReadByte();


+ 4
- 1
src/JT808.Protocol/Formatters/MessageBodyFormatters/JT808_0x8103_Formatter.cs Wyświetl plik

@@ -36,7 +36,10 @@ namespace JT808.Protocol.Formatters.MessageBodyFormatters
}
}
}
catch (Exception ex) { }
catch (Exception ex)
{
}
return jT808_0x8103;
}



+ 2
- 0
src/JT808.Protocol/Interfaces/GlobalConfigBase.cs Wyświetl plik

@@ -23,6 +23,7 @@ namespace JT808.Protocol.Interfaces
JT808_0X8103_Custom_Factory = new JT808_0x8103_Custom_Factory();
JT808_0X8103_Factory = new JT808_0x8103_Factory();
TerminalPhoneNoLength = 12;
Trim = true;
}
public abstract string ConfigId { get; }
public virtual IJT808MsgSNDistributed MsgSNDistributed { get; set; }
@@ -37,6 +38,7 @@ namespace JT808.Protocol.Interfaces
public virtual IJT808_0x8103_Custom_Factory JT808_0X8103_Custom_Factory { get; set; }
public virtual IJT808_0x8103_Factory JT808_0X8103_Factory { get; set; }
public virtual int TerminalPhoneNoLength { get; set; }
public virtual bool Trim { get; set; }
public virtual IJT808Config Register(params Assembly[] externalAssemblies)
{
if (externalAssemblies != null)


+ 6
- 0
src/JT808.Protocol/Interfaces/IJT808Config.cs Wyświetl plik

@@ -59,6 +59,12 @@ namespace JT808.Protocol
/// </summary>
bool SkipCRCCode { get; set; }
/// <summary>
/// ReadBCD是否需要去0操作
/// 默认是去0
/// 注意:有时候对协议来说是有意义的0
/// </summary>
bool Trim { get; set; }
/// <summary>
/// 设备终端号(默认12位)
/// </summary>
int TerminalPhoneNoLength { get; set; }


+ 3
- 3
src/JT808.Protocol/JT808HeaderMessageBodyProperty.cs Wyświetl plik

@@ -51,12 +51,12 @@ namespace JT808.Protocol
{
// 1.是否分包
int tmpIsPacke = 0;
// 2.是否加密
int tmpEncrypt = 0;
if (IsPackage)
{
tmpIsPacke = 1 << 13;
}
// 2.是否加密
int tmpEncrypt;
// 2.3.数据加密方式
switch (Encrypt)
{
@@ -64,7 +64,7 @@ namespace JT808.Protocol
tmpEncrypt = 0;
break;
case JT808EncryptMethod.RSA:
tmpEncrypt=1 << 10;
tmpEncrypt = 1 << 10;
break;
default:
tmpEncrypt = 0;


+ 11
- 5
src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs Wyświetl plik

@@ -25,8 +25,8 @@ namespace JT808.Protocol.MessagePack
/// 主要用来一次性读取所有数据体内容操作
/// </summary>
private bool _decoded;
private static byte[] decode7d01 = new byte[] { 0x7d, 0x01 };
private static byte[] decode7d02 = new byte[] { 0x7d, 0x02 };
private static readonly byte[] decode7d01 = new byte[] { 0x7d, 0x01 };
private static readonly byte[] decode7d02 = new byte[] { 0x7d, 0x02 };
/// <summary>
/// 解码(转义还原),计算校验和
/// </summary>
@@ -308,7 +308,7 @@ namespace JT808.Protocol.MessagePack
}
return d;
}
public string ReadBCD(int len)
public string ReadBCD(int len , bool trim = true)
{
int count = len / 2;
var readOnlySpan = GetReadOnlySpan(count);
@@ -317,8 +317,14 @@ namespace JT808.Protocol.MessagePack
{
bcdSb.Append(readOnlySpan[i].ToString("X2"));
}
// todo:对于协议来说这个0是有意义的,下个版本在去掉
return bcdSb.ToString().TrimStart('0');
if (trim)
{
return bcdSb.ToString().TrimStart('0');
}
else
{
return bcdSb.ToString();
}
}
private ReadOnlySpan<byte> GetReadOnlySpan(int count)
{


Ładowanie…
Anuluj
Zapisz