-
Notifications
You must be signed in to change notification settings - Fork 254
/
GlobalConfigBase.cs
174 lines (172 loc) · 7.05 KB
/
GlobalConfigBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System.Reflection;
using System.Text;
using JT808.Protocol.Formatters;
using JT808.Protocol.Internal;
namespace JT808.Protocol.Interfaces
{
/// <summary>
/// 全局配置基类
/// </summary>
public abstract class GlobalConfigBase : IJT808Config
{
/// <summary>
///
/// </summary>
protected GlobalConfigBase()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
MsgSNDistributed = new DefaultMsgSNDistributedImpl();
Compress = new JT808GZipCompressImpl();
SplitPackageStrategy = new DefaultSplitPackageStrategyImpl();
SkipCRCCode = false;
MsgIdFactory = new JT808MsgIdFactory();
Encoding = Encoding.GetEncoding("GBK");
FormatterFactory = new JT808FormatterFactory();
JT808_0X0200_Custom_Factory = new JT808_0x0200_Custom_Factory();
JT808_0X0200_Factory = new JT808_0x0200_Factory();
JT808_0X8103_Custom_Factory = new JT808_0x8103_Custom_Factory();
JT808_0X8103_Factory = new JT808_0x8103_Factory();
JT808_0x0900_Custom_Factory = new JT808_0x0900_Custom_Factory();
JT808_0x8900_Custom_Factory = new JT808_0x8900_Custom_Factory();
JT808_0x8500_2019_Factory = new JT808_0x8500_2019_Factory();
JT808_CarDVR_Up_Factory = new JT808_CarDVR_Up_Factory();
JT808_CarDVR_Down_Factory = new JT808_CarDVR_Down_Factory();
JT808_0x8105_Cusotm_Factory = new JT808_0x8105_Cusotm_Factory();
TerminalPhoneNoLength = 12;
Trim = true;
}
/// <summary>
/// 配置Id
/// </summary>
public abstract string ConfigId { get; protected set; }
/// <summary>
/// 分布式消息自增流水号
/// </summary>
public virtual IJT808MsgSNDistributed MsgSNDistributed { get; set; }
/// <summary>
/// 压缩
/// </summary>
public virtual IJT808Compress Compress { get; set; }
/// <summary>
/// 808分包策略
/// </summary>
public virtual IJT808SplitPackageStrategy SplitPackageStrategy { get; set; }
/// <summary>
/// 808消息Id工厂
/// </summary>
public virtual IJT808MsgIdFactory MsgIdFactory { get; set; }
/// <summary>
/// GBK编码
/// </summary>
public virtual Encoding Encoding { get; set; }
/// <summary>
/// 跳过校验码验证
/// 默认false
/// </summary>
public virtual bool SkipCRCCode { get; set; }
/// <summary>
/// 序列化器工厂
/// </summary>
public virtual IJT808FormatterFactory FormatterFactory { get; set; }
/// <summary>
/// 0x0200自定义附加信息工厂
/// </summary>
public virtual IJT808_0x0200_Custom_Factory JT808_0X0200_Custom_Factory { get; set; }
/// <summary>
/// 0x0200附加信息工厂
/// </summary>
public virtual IJT808_0x0200_Factory JT808_0X0200_Factory { get; set; }
/// <summary>
/// 0x8103自定义终端参数设置自定义消息工厂
/// </summary>
public virtual IJT808_0x8103_Custom_Factory JT808_0X8103_Custom_Factory { get; set; }
/// <summary>
/// 0x8103终端参数设置消息工厂
/// </summary>
public virtual IJT808_0x8103_Factory JT808_0X8103_Factory { get; set; }
/// <summary>
/// 终端SIM卡长度
/// </summary>
public virtual int TerminalPhoneNoLength { get; set; }
/// <summary>
/// 是否去掉头尾空格
/// </summary>
public virtual bool Trim { get; set; }
/// <summary>
/// 自定义数据上行透传消息工厂
/// </summary>
public virtual IJT808_0x0900_Custom_Factory JT808_0x0900_Custom_Factory { get; set; }
/// <summary>
/// 自定义数据下行透传消息工厂
/// </summary>
public virtual IJT808_0x8900_Custom_Factory JT808_0x8900_Custom_Factory { get; set; }
/// <summary>
/// 车辆控制消息工厂
/// </summary>
public virtual IJT808_0x8500_2019_Factory JT808_0x8500_2019_Factory { get; set; }
/// <summary>
/// JT19056上行消息工厂
/// </summary>
public IJT808_CarDVR_Up_Factory JT808_CarDVR_Up_Factory { get; set; }
/// <summary>
/// JT19056下行消息工厂
/// </summary>
public IJT808_CarDVR_Down_Factory JT808_CarDVR_Down_Factory { get; set; }
/// <summary>
/// 跳过校验码验证
/// 默认false
/// </summary>
public bool SkipCarDVRCRCCode { get; set; }
/// <summary>
/// 终端控制自定义参数命令工厂
/// </summary>
public virtual IJT808_0x8105_Cusotm_Factory JT808_0x8105_Cusotm_Factory { get; set; }
/// <inheritdoc/>
public virtual bool EnableAutoMerge { get; set; }
/// <inheritdoc/>
public double AutoMergeTimeoutSecond { get; set; } = 300;
/// <inheritdoc/>
public IMerger Jt808PackageMerger { get; set; } = new DefaultMerger();
/// <summary>
/// 外部扩展程序集注册
/// </summary>
/// <param name="externalAssemblies"></param>
/// <returns></returns>
public virtual IJT808Config Register(params Assembly[] externalAssemblies)
{
if (externalAssemblies != null)
{
foreach (var easb in externalAssemblies)
{
MsgIdFactory.Register(easb);
FormatterFactory.Register(easb);
JT808_0X0200_Factory.Register(easb);
JT808_0X0200_Custom_Factory.Register(easb);
JT808_0X8103_Factory.Register(easb);
JT808_0X8103_Custom_Factory.Register(easb);
JT808_0x0900_Custom_Factory.Register(easb);
JT808_0x8900_Custom_Factory.Register(easb);
JT808_0x8500_2019_Factory.Register(easb);
JT808_CarDVR_Up_Factory.Register(easb);
JT808_CarDVR_Down_Factory.Register(easb);
JT808_0x8105_Cusotm_Factory.Register(easb);
}
}
return this;
}
/// <summary>
/// 替换原有消息
/// </summary>
/// <typeparam name="TSourceJT808Bodies"></typeparam>
/// <typeparam name="TTargetJT808Bodies"></typeparam>
public void ReplaceMsgId<TSourceJT808Bodies, TTargetJT808Bodies>()
where TSourceJT808Bodies : JT808Bodies
where TTargetJT808Bodies : JT808Bodies, new()
{
TTargetJT808Bodies bodies = new TTargetJT808Bodies();
MsgIdFactory.Map[bodies.MsgId] = bodies;
FormatterFactory.FormatterDict.Remove(typeof(TSourceJT808Bodies).GUID);
FormatterFactory.FormatterDict.Add(typeof(TTargetJT808Bodies).GUID, (IJT808MessagePackFormatter)bodies);
}
}
}