Sfoglia il codice sorgente

修复经纬度

tags/v2.6.3
yedajiang44 1 anno fa
parent
commit
d268e05cc7
2 ha cambiato i file con 35 aggiunte e 41 eliminazioni
  1. +15
    -15
      src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs
  2. +20
    -26
      src/JT808.Protocol/MessageBody/JT808_0x0200.cs

+ 15
- 15
src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs Vedi File

@@ -857,9 +857,9 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x18000000;
jT808UploadLocationRequest.StatusFlag = 0b1100;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("0000000118000000FF4580F2F81B0EE40028003C0000180715101010", hex);
Assert.Equal("000000010000000CFF4580F2F81B0EE40028003C0000180715101010", hex);
}
[Fact]
public void LatLngTest1_2()
@@ -887,9 +887,9 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x18000000 | 0x302;
jT808UploadLocationRequest.StatusFlag = 0b1100;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("0000000118000302FF4580F2F81B0EE40028003C0000180715101010", hex);
Assert.Equal("000000010000000CFF4580F2F81B0EE40028003C0000180715101010", hex);
}
[Fact]
public void LatLngTest2_2()
@@ -917,9 +917,9 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x10000000;
jT808UploadLocationRequest.StatusFlag = 0b100;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("0000000110000000FF4580F207E4F11C0028003C0000180715101010", hex);
Assert.Equal("0000000100000004FF4580F207E4F11C0028003C0000180715101010", hex);
}
[Fact]
public void LatTest1_2()
@@ -948,7 +948,7 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 1111;
jT808UploadLocationRequest.StatusFlag = 0b10000;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
});
Assert.Equal(JT808ErrorCode.LatOrLngError, exception.ErrorCode);
@@ -967,17 +967,17 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x10000000 | 0x000300;
jT808UploadLocationRequest.StatusFlag = 0b0100;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("0000000110000300FF4580F207E4F11C0028003C0000180715101010", hex);
Assert.Equal("0000000100000004FF4580F207E4F11C0028003C0000180715101010", hex);
}
[Fact]
public void LatTest3_2()
{
byte[] bodys = "0000000110000300FF4580F207E4F11C0028003C0000180715101010".ToHexBytes();
byte[] bodys = "0000000100000004FF4580F207E4F11C0028003C0000180715101010".ToHexBytes();
JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
Assert.Equal((uint)(0x10000000 | 0x000300), jT808UploadLocationRequest.StatusFlag);
Assert.Equal(0b100u, jT808UploadLocationRequest.StatusFlag);
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
Assert.Equal(-12222222, jT808UploadLocationRequest.Lat);
Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
@@ -997,9 +997,9 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x8000000;
jT808UploadLocationRequest.StatusFlag = 0b1000;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010800000000BA7F0EF81B0EE40028003C0000180715101010", hex);
Assert.Equal("000000010000000800BA7F0EF81B0EE40028003C0000180715101010", hex);
}
[Fact]
public void LngTest1_2()
@@ -1047,9 +1047,9 @@ namespace JT808.Protocol.Test.MessageBody
Direction = 0,
BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
};
jT808UploadLocationRequest.StatusFlag = 0x8000000|0x6601;
jT808UploadLocationRequest.StatusFlag = 0b1000;
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010800660100BA7F0EF81B0EE40028003C0000180715101010", hex);
Assert.Equal("000000010000000800BA7F0EF81B0EE40028003C0000180715101010", hex);
}
[Fact]
public void LngTest3_2()


+ 20
- 26
src/JT808.Protocol/MessageBody/JT808_0x0200.cs Vedi File

@@ -20,7 +20,7 @@ namespace JT808.Protocol.MessageBody
/// <summary>
/// 0x0200
/// </summary>
public ushort MsgId => 0x0200;
public ushort MsgId => 0x0200;
/// <summary>
/// 位置信息汇报
/// </summary>
@@ -115,21 +115,15 @@ namespace JT808.Protocol.MessageBody
JT808_0x0200 jT808_0X0200 = new JT808_0x0200();
jT808_0X0200.AlarmFlag = reader.ReadUInt32();
jT808_0X0200.StatusFlag = reader.ReadUInt32();
if (((jT808_0X0200.StatusFlag >> 28) & 1) == 1)
jT808_0X0200.Lat = reader.ReadInt32();
jT808_0X0200.Lng = reader.ReadInt32();
if (((jT808_0X0200.StatusFlag >> 2) & 1) == 1 && jT808_0X0200.Lat > 0)
{ //南纬 268435456 0x10000000
jT808_0X0200.Lat = (int)reader.ReadUInt32();
jT808_0X0200.Lat = -jT808_0X0200.Lat;
}
else
{
jT808_0X0200.Lat = reader.ReadInt32();
}
if (((jT808_0X0200.StatusFlag >> 27) & 1) == 1)
if (((jT808_0X0200.StatusFlag >> 3) & 1) == 1 && jT808_0X0200.Lng > 0)
{ //西经 134217728 0x8000000
jT808_0X0200.Lng = (int)reader.ReadUInt32();
}
else
{
jT808_0X0200.Lng = reader.ReadInt32();
jT808_0X0200.Lng = -jT808_0X0200.Lng;
}
jT808_0X0200.Altitude = reader.ReadUInt16();
jT808_0X0200.Speed = reader.ReadUInt16();
@@ -251,9 +245,9 @@ namespace JT808.Protocol.MessageBody
reader.Skip(1);
byte attachLen = reader.ReadByte();
int remainLength = reader.ReadCurrentRemainContentLength();
if(remainLength < attachLen)
if (remainLength < attachLen)
{
jT808_0X0200.ExceptionLocationAttachOriginalData.Add(reader.ReadArray(reader.ReaderCount - 2, remainLength+2).ToArray());
jT808_0X0200.ExceptionLocationAttachOriginalData.Add(reader.ReadArray(reader.ReaderCount - 2, remainLength + 2).ToArray());
reader.ReadArray(remainLength);
}
else
@@ -304,7 +298,7 @@ namespace JT808.Protocol.MessageBody
//0x10000000 南纬 134217728
//0x8000000 西经 268435456
//0x18000000 南纬-西经 134217728+268435456
if (((value.StatusFlag >> 28) & 1) == 1)
if (((value.StatusFlag >> 2) & 1) == 1)
{
uint lat = (uint)value.Lat;
writer.WriteUInt32(lat);
@@ -313,11 +307,11 @@ namespace JT808.Protocol.MessageBody
{
if (value.Lat < 0)
{
throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lat {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>28) !=1");
throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lat {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>2) !=1");
}
writer.WriteInt32(value.Lat);
}
if (((value.StatusFlag >> 27) & 1) == 1)
if (((value.StatusFlag >> 3) & 1) == 1)
{
uint lng = (uint)value.Lng;
writer.WriteUInt32(lng);
@@ -326,7 +320,7 @@ namespace JT808.Protocol.MessageBody
{
if (value.Lng < 0)
{
throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lng {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>29) !=1");
throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lng {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>3) !=1");
}
writer.WriteInt32(value.Lng);
}
@@ -376,11 +370,11 @@ namespace JT808.Protocol.MessageBody
item.Value.SerializeExt(ref writer, item.Value, config);
}
}
if (value.UnknownLocationAttachData!=null && value.UnknownLocationAttachData.Count > 0)
if (value.UnknownLocationAttachData != null && value.UnknownLocationAttachData.Count > 0)
{
foreach (var item in value.UnknownLocationAttachData)
{
if(item.Value!=null && item.Value.Length >= 2)
if (item.Value != null && item.Value.Length >= 2)
{
writer.WriteArray(item.Value);
}
@@ -405,11 +399,11 @@ namespace JT808.Protocol.MessageBody
/// <param name="config"></param>
public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
{
JT808_0x0200 value = new ();
JT808_0x0200 value = new();
value.AlarmFlag = reader.ReadUInt32();
writer.WriteNumber($"[{value.AlarmFlag.ReadBinary().ToString()}]报警标志", value.AlarmFlag);
value.StatusFlag = reader.ReadUInt32();
var alarmFlagBits =Convert.ToString(value.AlarmFlag, 2).PadLeft(32, '0').AsSpan();
var alarmFlagBits = Convert.ToString(value.AlarmFlag, 2).PadLeft(32, '0').AsSpan();
writer.WriteStartObject("报警标志对象");
if (reader.Version == JT808Version.JTT2019)
{
@@ -506,7 +500,7 @@ namespace JT808.Protocol.MessageBody
writer.WriteString($"[{StatusFlagBits[30]}]bit1", StatusFlagBits[30] == '0' ? "未定位" : "定位");
writer.WriteString($"[{StatusFlagBits[31]}]bit0", StatusFlagBits[31] == '0' ? "ACC关" : "ACC开");
writer.WriteEndObject();
if (((value.StatusFlag >> 28) & 1) == 1)
if (((value.StatusFlag >> 2) & 1) == 1)
{ //南纬 268435456 0x10000000
value.Lat = (int)reader.ReadUInt32();
writer.WriteNumber($"[{value.Lat.ReadNumber()}]纬度", value.Lat);
@@ -516,7 +510,7 @@ namespace JT808.Protocol.MessageBody
value.Lat = reader.ReadInt32();
writer.WriteNumber($"[{value.Lat.ReadNumber()}]纬度", value.Lat);
}
if (((value.StatusFlag >> 27) & 1) == 1)
if (((value.StatusFlag >> 3) & 1) == 1)
{ //西经 134217728 0x8000000
value.Lng = (int)reader.ReadUInt32();
writer.WriteNumber($"[{value.Lng.ReadNumber()}]经度", value.Lng);
@@ -658,7 +652,7 @@ namespace JT808.Protocol.MessageBody
writer.WriteStartObject();
writer.WriteNumber($"[{attachId.ReadNumber()}]未知附加信息Id", attachId);
writer.WriteNumber($"[{attachLen.ReadNumber()}]未知附加信息长度", attachLen);
if ((attachLen+2) > remainLength)
if ((attachLen + 2) > remainLength)
{
writer.WriteString($"未知附加信息[异常解析]", reader.ReadArray(remainLength).ToArray().ToHexString());
}


Caricamento…
Annulla
Salva