Exemple #1
0
 public JT809MainClient(
     IJT809ManualResetEvent jT809ManualResetEvent,
     IServiceProvider provider,
     ILoggerFactory loggerFactory,
     IJT809Config config)
 {
     this.serviceProvider  = provider;
     this.logger           = loggerFactory.CreateLogger <JT809MainClient>();
     this.manualResetEvent = jT809ManualResetEvent;
     this.config           = config;
     group     = new MultithreadEventLoopGroup();
     bootstrap = new Bootstrap();
     bootstrap.Group(group)
     .Channel <TcpSocketChannel>()
     .Option(ChannelOption.TcpNodelay, true)
     .Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
     {
         IChannelPipeline pipeline = channel.Pipeline;
         //下级平台1分钟发送心跳
         //上级平台是3分钟没有发送就断开连接
         using var scope = serviceProvider.CreateScope();
         pipeline.AddLast("jt809MainClientBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                  Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
                                                                                  Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
         pipeline.AddLast("jt809MainClientSystemIdleState", new IdleStateHandler(180, 60, 200));
         pipeline.AddLast("jt809MainClientEncode", scope.ServiceProvider.GetRequiredService <JT809Encoder>());
         pipeline.AddLast("jt809MainClientDecode", scope.ServiceProvider.GetRequiredService <JT809Decoder>());
         pipeline.AddLast("jt809MainClientConnection", scope.ServiceProvider.GetRequiredService <JT809MainClientConnectionHandler>());
         pipeline.AddLast("jt809MainClientServer", scope.ServiceProvider.GetRequiredService <JT809MainClientHandler>());
     }));
 }
Exemple #2
0
 /// <summary>
 /// 初始化消息处理业务
 /// </summary>
 protected JT809InferiorMsgIdReceiveHandlerBase(
     IJT809ManualResetEvent jT809ManualResetEvent,
     ILoggerFactory loggerFactory)
 {
     this.Logger           = loggerFactory.CreateLogger <JT809SuperiorMsgIdReceiveHandlerBase>();
     this.ManualResetEvent = jT809ManualResetEvent;
     HandlerDict           = new Dictionary <JT809BusinessType, Func <JT809Request, JT809Response> >
     {
         { JT809BusinessType.主链路登录应答消息, Msg0x1002 },
         { JT809BusinessType.主链路连接保持应答消息, Msg0x1006 },
         { JT809BusinessType.从链路连接请求消息, Msg0x9001 },
         { JT809BusinessType.从链路注销请求消息, Msg0x9003 },
         { JT809BusinessType.从链路连接保持请求消息, Msg0x9005 }
     };
     SubHandlerDict = new Dictionary <JT809SubBusinessType, Func <JT809Request, JT809Response> >
     {
         //{JT809SubBusinessType.实时上传车辆定位信息, Msg0x1200_0x1202},
     };
 }
 public JT809InferiorMsgIdReceiveDefaultHandler(IJT809ManualResetEvent jT809ManualResetEvent, ILoggerFactory loggerFactory) : base(jT809ManualResetEvent, loggerFactory)
 {
 }