Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

120 rader
5.4 KiB

  1. using JT809.DotNetty.Core.Clients;
  2. using JT809.DotNetty.Core.Metadata;
  3. using JT809.Protocol.Extensions;
  4. using Microsoft.Extensions.Hosting;
  5. using Microsoft.Extensions.Logging;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using JT809.Protocol.SubMessageBody;
  12. using JT809.Protocol.Metadata;
  13. using JT809.Protocol.MessageBody;
  14. namespace JT809.Inferior.Client
  15. {
  16. public class JT809InferiorService : IHostedService
  17. {
  18. private readonly JT809MainClient mainClient;
  19. private readonly ILogger<JT809InferiorService> logger;
  20. public JT809InferiorService(
  21. ILoggerFactory loggerFactory,
  22. JT809MainClient mainClient)
  23. {
  24. this.mainClient = mainClient;
  25. logger = loggerFactory.CreateLogger<JT809InferiorService>();
  26. }
  27. public Task StartAsync(CancellationToken cancellationToken)
  28. {
  29. //5B0000001F0000053B100201341725010000000000270F00000004E8A6F25D
  30. var connect = mainClient.Login("127.0.0.1", 809, new JT809_0x1001
  31. {
  32. DownLinkIP = "127.0.0.1",
  33. DownLinkPort = 1809,
  34. UserId = 123456,
  35. Password = "12345678"
  36. }).Result;
  37. if (connect)
  38. {
  39. Task.Run(() =>
  40. {
  41. while (true)
  42. {
  43. JT809.Protocol.MessageBody.JT809_0x1200 jT809_0X1200 = new Protocol.MessageBody.JT809_0x1200();
  44. jT809_0X1200.VehicleColor = Protocol.Enums.JT809VehicleColorType.黄色;
  45. jT809_0X1200.VehicleNo = "粤A12345";
  46. jT809_0X1200.SubBusinessType = Protocol.Enums.JT809SubBusinessType.实时上传车辆定位信息;
  47. jT809_0X1200.SubBodies = new JT809_0x1200_0x1202()
  48. {
  49. VehiclePosition = new JT809VehiclePositionProperties
  50. {
  51. Day = (byte)(DateTime.Now.Day),
  52. Month = (byte)(DateTime.Now.Month),
  53. Year = (ushort)(DateTime.Now.Year),
  54. Hour = (byte)(DateTime.Now.Hour),
  55. Minute = (byte)(DateTime.Now.Minute),
  56. Second = (byte)(DateTime.Now.Second),
  57. Alarm = 1,
  58. Direction = 2,
  59. State = 2,
  60. Altitude = 32,
  61. Lat = 122334565,
  62. Lon = 12354563,
  63. Vec1 = 112,
  64. Vec2 = 22,
  65. Vec3 = 12
  66. }
  67. };
  68. var package = JT809.Protocol.Enums.JT809BusinessType.主链路动态信息交换消息.Create(jT809_0X1200);
  69. mainClient.SendAsync(new JT809Response(package, 256));
  70. logger.LogDebug($"Thread:{Thread.CurrentThread.ManagedThreadId}-2s");
  71. Thread.Sleep(2000);
  72. }
  73. });
  74. Task.Run(() =>
  75. {
  76. while (true)
  77. {
  78. JT809.Protocol.MessageBody.JT809_0x1200 jT809_0X1200 = new Protocol.MessageBody.JT809_0x1200();
  79. jT809_0X1200.VehicleColor = Protocol.Enums.JT809VehicleColorType.黄色;
  80. jT809_0X1200.VehicleNo = "粤A12346";
  81. jT809_0X1200.SubBusinessType = Protocol.Enums.JT809SubBusinessType.实时上传车辆定位信息;
  82. jT809_0X1200.SubBodies = new JT809_0x1200_0x1202()
  83. {
  84. VehiclePosition = new JT809VehiclePositionProperties
  85. {
  86. Day = (byte)(DateTime.Now.Day),
  87. Month = (byte)(DateTime.Now.Month),
  88. Year = (byte)(DateTime.Now.Year),
  89. Hour = (byte)(DateTime.Now.Hour),
  90. Minute = (byte)(DateTime.Now.Minute),
  91. Second = (byte)(DateTime.Now.Second),
  92. Alarm = 1,
  93. Direction = 2,
  94. State = 2,
  95. Altitude = 32,
  96. Lat = 122334565,
  97. Lon = 12354563,
  98. Vec1 = 112,
  99. Vec2 = 22,
  100. Vec3 = 12
  101. }
  102. };
  103. var package = JT809.Protocol.Enums.JT809BusinessType.主链路动态信息交换消息.Create(jT809_0X1200);
  104. mainClient.SendAsync(new JT809Response(package, 256));
  105. logger.LogDebug($"Thread:{Thread.CurrentThread.ManagedThreadId}-4s");
  106. Thread.Sleep(4000);
  107. }
  108. });
  109. }
  110. return Task.CompletedTask;
  111. }
  112. public Task StopAsync(CancellationToken cancellationToken)
  113. {
  114. return Task.CompletedTask;
  115. }
  116. }
  117. }