Skip to content

Commit

Permalink
1.增加部分gps51的扩展id
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallChi committed Jan 15, 2024
1 parent 4234c83 commit e2ba47a
Show file tree
Hide file tree
Showing 12 changed files with 563 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\JT808.Protocol.Extensions.GPS51\JT808.Protocol.Extensions.GPS51.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using JT808.Protocol.Extensions.GPS51.MessageBody;
using JT808.Protocol.MessageBody;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Xunit;

namespace JT808.Protocol.Extensions.GPS51.Test
{
public class JT808_0x0200_0x2B_Ext_Test
{
JT808Serializer JT808Serializer;
public JT808_0x0200_0x2B_Ext_Test()
{
ServiceCollection serviceDescriptors = new ServiceCollection();
serviceDescriptors.AddJT808Configure()
.AddGPS51Configure();

IJT808Config jT808Config = serviceDescriptors.BuildServiceProvider().GetRequiredService<IJT808Config>();
JT808Serializer = new JT808Serializer(jT808Config);
}
[Fact]
public void Serializer()
{
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
{
AlarmFlag = 1,
Altitude = 40,
GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
Lat = 12222222,
Lng = 132444444,
Speed = 60,
Direction = 0,
StatusFlag = 2,
CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>()
};
jT808UploadLocationRequest.CustomLocationAttachData.Add(JT808_GPS51_Constants.JT808_0x0200_0x2B, new JT808_0x0200_0x2B_Ext
{
AttachInfoId = 0x2b,
AttachInfoLength = 4,
Oils = new List<ushort> {
12,34
}
});
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C00001807151010102B04000C0022", hex);
}
[Fact]
public void Deserialize()
{
var jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808Package>("7e020000470412106280030233000000000000200201d365df072f15d500280000002d21091719155801040002a10f2a0200042b049203a46f520103eb06000100ce0a5730011b31010951080000000000000000ca7e".ToHexBytes());
var body0200 = jT808UploadLocationRequest.Bodies as JT808_0x0200;
body0200.CustomLocationAttachData.TryGetValue(JT808_GPS51_Constants.JT808_0x0200_0x2B, out var value);
var jt808_0x0200_0x2b = value as JT808_0x0200_0x2B_Ext;
//2b049203a46f
Assert.Equal(0x9203, jt808_0x0200_0x2b.Oils[0]);
Assert.Equal(0xa46f, jt808_0x0200_0x2b.Oils[1]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using JT808.Protocol.Extensions.GPS51.MessageBody;
using JT808.Protocol.MessageBody;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Xunit;

namespace JT808.Protocol.Extensions.GPS51.Test
{
public class JT808_0x0200_0x51_Test
{
JT808Serializer JT808Serializer;
public JT808_0x0200_0x51_Test()
{
ServiceCollection serviceDescriptors = new ServiceCollection();
serviceDescriptors.AddJT808Configure()
.AddGPS51Configure();

IJT808Config jT808Config = serviceDescriptors.BuildServiceProvider().GetRequiredService<IJT808Config>();
JT808Serializer = new JT808Serializer(jT808Config);
}
[Fact]
public void Serializer()
{
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
{
AlarmFlag = 1,
Altitude = 40,
GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
Lat = 12222222,
Lng = 132444444,
Speed = 60,
Direction = 0,
StatusFlag = 2,
CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>()
};
jT808UploadLocationRequest.CustomLocationAttachData.Add(JT808_GPS51_Constants.JT808_0x0200_0x51, new JT808_0x0200_0x51
{
AttachInfoId = 0x2b,
AttachInfoLength = 4,
Temperatures = new List<short> {
12,-34
}
});
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C00001807151010102B04000C0022", hex);
}
[Fact]
public void Deserialize()
{
var jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808Package>("7e020000470158666660580571000000000000000201d59c1c06a36599006e0000000021091719313901040000eb8830011d3101192a0200005201002b040000000051080134011a04f604f6eb06000400ce04f8847e".ToHexBytes());
var body0200 = jT808UploadLocationRequest.Bodies as JT808_0x0200;
body0200.CustomLocationAttachData.TryGetValue(JT808_GPS51_Constants.JT808_0x0200_0x51, out var value);
var jt808_0x0200_0x51 = value as JT808_0x0200_0x51;
//2b049203a46f
Assert.Equal(0x0134, jt808_0x0200_0x51.Temperatures[0]);
Assert.Equal(0x011A, jt808_0x0200_0x51.Temperatures[1]);
Assert.Equal(0x04F6, jt808_0x0200_0x51.Temperatures[2]);
Assert.Equal(0x04F6, jt808_0x0200_0x51.Temperatures[3]);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using JT808.Protocol.Extensions.GPS51.Enums;
using JT808.Protocol.Extensions.GPS51.MessageBody;
using JT808.Protocol.Interfaces;
using JT808.Protocol.MessageBody;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace JT808.Protocol.Extensions.GPS51
{
/// <summary>
/// GPS51 extension JT/T808
/// </summary>
public static class DependencyInjectionExtensions
{
/// <summary>
/// 注册GPS51扩展JT/T808
/// Register GPS51 extension JT/T808
/// </summary>
/// <param name="jT808Builder"></param>
/// <returns></returns>
public static IJT808Builder AddGPS51Configure(this IJT808Builder jT808Builder)
{
jT808Builder.Config.JT808_0X0200_Factory.Map.Remove(JT808_GPS51_Constants.JT808_0x0200_0x2B);
jT808Builder.Config.Register(Assembly.GetExecutingAssembly());
return jT808Builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace JT808.Protocol.Extensions.GPS51.Enums
{
/// <summary>
/// 主动拍照策略
/// Active photo taking strategy
/// </summary>
public enum ActivePhotographyStrategyType:byte
{
/// <summary>
/// 不开启
/// Is not enabled
/// </summary>
not_enabled = 0x00,
/// <summary>
/// 定时拍照
/// Camera Timer
/// </summary>
camera_timer = 0x01,
/// <summary>
/// 定距拍照
/// Distance take photos
/// </summary>
distance_take_photos = 0x02,
/// <summary>
/// 保留
/// reserve
/// </summary>
reserve = 0x03,
/// <summary>
/// 不修改参数
/// Do not Modify parameters
/// </summary>
not_modify_parameters = 0xFF
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\JT808.Protocol\JT808.Protocol.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace JT808.Protocol.Extensions.GPS51
{
/// <summary>
/// 主动安全常量
/// </summary>
public static class JT808_GPS51_Constants
{
/// <summary>
/// 附加信息ID 多路油耗模拟量,
/// 2*N
/// 例子报文:2b049203a46f
/// 解析结果为:2路 模拟量分别为37379 42095
/// </summary>
public const byte JT808_0x0200_0x2B = 0x2b;
/// <summary>
/// 附加信息ID 2个字节一组温度 0.1度 ffff 代表无效,
/// 2*N
/// 04F6代表未接或者传感器掉电,
/// 第16位代表正负温度 51080134011A04F604F6
/// 308=30.8度 282=28.2度 8050=-80=-8度
/// </summary>
public const byte JT808_0x0200_0x51 = 0x51;
/// <summary>
/// 附加信息ID
/// 1
/// 正反转 0:未知;1:正转(空车)2:反转(重车);3:停转
/// 例子解析为:03
/// </summary>
public const byte JT808_0x0200_0x52 = 0x52;
/// <summary>
/// 附加信息ID
/// 1+7*N
/// Wifi数据:第1个字节wifi个数,后面为n个wifi数据;
/// WIFI数据:6字节 wifiMac 1字节 信号强度
/// </summary>
public const byte JT808_0x0200_0x54 = 0x54;
/// <summary>
/// 载重扩展 8
/// 1/10千克 8 字节
/// </summary>
public const uint JT808_0x0200_0x55 = 0x55;
/// <summary>
/// 湿度,
/// 2*N
/// 精度0.1,0fff 代表无效数据,例子数据: 0012 表示:1.8%
/// </summary>
public const uint JT808_0x0200_0x58 = 0x58;
/// <summary>
/// 电压,
/// 2
/// 单位0.01V,例子报文:61021d74,解析结果7540,最终电压75.40V
/// </summary>
public const uint JT808_0x0200_0x61 = 0x61;
/// <summary>
/// 基站编码
/// 4+7*N
/// 的格式为 MCC MNC LAC CI Signal 2-2-2-4-1-2-4-1,
/// 其中MCC 2个字节国家编码,MNC 为 2个字节网络编码,LAC为 2个字节地区编码,
/// CI 为 4个字节蜂窝 ID ,
/// 信号强度 1字节,
/// 单基站可以不用信号强度 1cc-0-696a-863a8d0-0
/// </summary>
public const uint JT808_0x0200_0xe1 = 0xe1;
/// <summary>
/// 版本号,
/// N
/// 开机或者重连第一条上报,例子结果:GB201-GSM-21001-1.1.1
/// </summary>
public const byte JT808_0x0200_0xe2 = 0xe2;
/// <summary>
/// iccid,
/// 20
/// 一般开机或者重连第一条0200位置信息上报,
/// 例子报文:f1143839383630343032313032303930393737303032,
/// 解析结果为:89860402102090977002
/// </summary>
public const byte JT808_0x0200_0xf1 = 0xf1;
/// <summary>
/// IMEI数据:
/// 8字节,
/// 第1位为0,后面15位为imei的16进制数据
/// </summary>
public const byte JT808_0x0200_0xf6 = 0xf6;
/// <summary>
/// 4
/// 第0位:震动报警
/// 第1位:拆除报警 例子:第0位:震动报警 fa0400000001 第1位:拆除报警 fa0400000002
/// 第2位:进入深度休眠 fa0400000004
/// 第3位:急加速 fa0400000008
/// 第4位:急减速 fa0400000010
/// 第5位:急转弯 fa0400000020
/// 第6位:acc开报警 fa0400000040
/// 第7位:acc关报警 fa0400000080
/// 第8位:内部电池电量低fa0400000100
/// 第9位:人为关机
/// 第10位:低电关机
/// </summary>
public const byte JT808_0x0200_0xfa = 0xfa;
/// <summary>
/// 4
/// 电量百分比和外部电压,
/// 电压精度0.01V,充电状态0未充电 1充电中,没有的数据传00
/// 例子:fb045F050701
/// 解析结果:电量百分比5F=95 电压:0507=1287 最终显示为12.87V 01:充电中
/// </summary>
public const byte JT808_0x0200_0xfb = 0xfb;
/// <summary>
///
/// </summary>
/// <returns></returns>
public static Assembly GetCurrentAssembly()
{
return Assembly.GetExecutingAssembly();
}
}
}
Loading

0 comments on commit e2ba47a

Please sign in to comment.