public JT808TcpClient(DeviceConfig deviceConfig, IServiceProvider serviceProvider)
        {
            DeviceConfig  = deviceConfig;
            LoggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();
            JT808ClientSendAtomicCounterService    jT808SendAtomicCounterService    = serviceProvider.GetRequiredService <JT808ClientSendAtomicCounterService>();
            JT808ClientReceiveAtomicCounterService jT808ReceiveAtomicCounterService = serviceProvider.GetRequiredService <JT808ClientReceiveAtomicCounterService>();
            IJT808Config jT808Config = serviceProvider.GetRequiredService <IJT808Config>();

            group = new MultithreadEventLoopGroup(1);
            Bootstrap bootstrap = new Bootstrap();

            bootstrap.Group(group);
            bootstrap.Channel <TcpSocketChannel>();
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                bootstrap.Option(ChannelOption.SoReuseport, true);
            }
            bootstrap
            .Option(ChannelOption.SoBacklog, 8192)
            .Handler(new ActionChannelInitializer <IChannel>(channel =>
            {
                channel.Pipeline.AddLast("jt808TcpBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                          Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.BeginFlag }),
                                                                                          Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.EndFlag })));
                channel.Pipeline.AddLast("systemIdleState", new IdleStateHandler(60, deviceConfig.Heartbeat, 3600));
                channel.Pipeline.AddLast("jt808TcpDecode", new JT808ClientTcpDecoder());
                channel.Pipeline.AddLast("jt808TcpEncode", new JT808ClientTcpEncoder(jT808Config, jT808SendAtomicCounterService, LoggerFactory));
                channel.Pipeline.AddLast("jt808TcpClientConnection", new JT808TcpClientConnectionHandler(this));
                channel.Pipeline.AddLast("jt808TcpService", new JT808TcpClientHandler(jT808ReceiveAtomicCounterService, this));
            }));
            clientChannel = bootstrap.ConnectAsync(IPAddress.Parse(DeviceConfig.TcpHost), DeviceConfig.TcpPort).Result;
        }
 public JT808ClientTcpEncoder(
     IJT808Config jT808Config,
     JT808ClientSendAtomicCounterService jT808SendAtomicCounterService, ILoggerFactory loggerFactory)
 {
     logger = loggerFactory.CreateLogger <JT808ClientTcpEncoder>();
     this.jT808SendAtomicCounterService = jT808SendAtomicCounterService;
     JT808Serializer = jT808Config.GetSerializer();
 }