SmallChi 7 лет назад
Родитель
Сommit
120d78efc0
5 измененных файлов: 57 добавлений и 3 удалений
  1. +1
    -1
      src/JT809.Protocol/Encrypt/JT809EncryptImpl.cs
  2. +11
    -0
      src/JT809.Protocol/Enums/ErrorCode.cs
  3. +25
    -0
      src/JT809.Protocol/Exceptions/JT809Exception.cs
  4. +4
    -1
      src/JT809.Protocol/ProtocolPacket/Header.cs
  5. +16
    -1
      src/JT809.Protocol/ProtocolPacket/Package.cs

+ 1
- 1
src/JT809.Protocol/Encrypt/JT809EncryptImpl.cs Просмотреть файл

@@ -36,6 +36,6 @@ namespace JT809.Protocol.Encrypt
Config.Key = Config.IA1 * (Config.Key % mkey) + Config.IC1;
buffer[idx] ^= (byte)((Config.Key >> 20) & 0xFF);
}
}
}
}
}

+ 11
- 0
src/JT809.Protocol/Enums/ErrorCode.cs Просмотреть файл

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.Protocol.Enums
{
public enum ErrorCode
{
CRC16CheckInvalid = 1001
}
}

+ 25
- 0
src/JT809.Protocol/Exceptions/JT809Exception.cs Просмотреть файл

@@ -0,0 +1,25 @@
using JT809.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.Protocol.Exceptions
{
public class JT809Exception:Exception
{
private readonly ErrorCode errorCode;

public JT809Exception(ErrorCode errorCode) : base(errorCode.ToString())
{
this.errorCode = errorCode;
}

public JT809Exception(ErrorCode errorCode, string message) : base(message)
{
this.errorCode = errorCode;
}


public ErrorCode ErrorCode => errorCode;
}
}

+ 4
- 1
src/JT809.Protocol/ProtocolPacket/Header.cs Просмотреть файл

@@ -42,12 +42,15 @@ namespace JT809.Protocol.ProtocolPacket
/// </summary>
public uint GNSSCENTERID { get; set; }
public Version Version { get; private set; }
public EncryptOpitions EncryptOpitions { get; private set; }
public EncryptOpitions EncryptOpition { get; private set; }
/// <summary>
/// 数据加密的密匙,长度为 4 个字节。
/// </summary>
public uint EncryptKey { get; private set; } = 0X00;
public Header(byte[] buffer) : base(buffer) { CounterOnRecieveGenerater++; }
protected override void InitializeProperties(object[] properties, int startIndex)
{
throw new NotImplementedException();


+ 16
- 1
src/JT809.Protocol/ProtocolPacket/Package.cs Просмотреть файл

@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using JT809.Protocol.Enums;
using JT809.Protocol.Exceptions;
using JT809.Protocol.ProtocolPacket.Extensions;
namespace JT809.Protocol.ProtocolPacket
@@ -39,7 +41,20 @@ namespace JT809.Protocol.ProtocolPacket
var content01 = this.UnEscape(content00);
var crc16 = this.CRC16_CCITT(content01, 0, content01.Length - Crc16ByteLength);
CRC16 = BitConverter.ToUInt16(new[] { content01[content01.Length - 1], content01[content01.Length - 2] }, 0);
if (CRC16 != crc16) throw new InvalidDataException("CRC16 check invalid.");
if (CRC16 != crc16) throw new JT809Exception(ErrorCode.CRC16CheckInvalid);
Header = new Header(content01);
var bodyBuffer00 = new byte[content01.Length - Header.HeaderFixedByteLength - Crc16ByteLength];
Array.Copy(content01, Header.HeaderFixedByteLength, bodyBuffer00, 0, bodyBuffer00.Length);
//Default
byte[] bodyBuffer01 = bodyBuffer00;
switch (Header.EncryptOpition)
{
case EncryptOpitions.None:
break;
case EncryptOpitions.Common:
// bodyBuffer01 = this.EncryptExt(Header.KeyForCommonEncrypt, bodyBuffer01, bodyBuffer01.Length, Config.Value.ServiceGB809Info.MasterLinkInfo.M1, Config.Value.ServiceGB809Info.MasterLinkInfo.IA1, Config.Value.ServiceGB809Info.MasterLinkInfo.IC1);
break;
}
}
protected override void OnWriteToBuffer(BinaryWriter writer)


Загрузка…
Отмена
Сохранить