Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

75 строки
2.5 KiB

  1. using JT808.Gateway.Client;
  2. using JT808.Protocol.MessageBody;
  3. using JT808.Protocol.Enums;
  4. using JT808.Protocol.Extensions;
  5. using Microsoft.Extensions.Hosting;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. namespace JT808.Gateway.SimpleClient.Services
  12. {
  13. public class Up2019Service : IHostedService
  14. {
  15. private readonly IJT808TcpClientFactory jT808TcpClientFactory;
  16. public Up2019Service(IJT808TcpClientFactory jT808TcpClientFactory)
  17. {
  18. this.jT808TcpClientFactory = jT808TcpClientFactory;
  19. }
  20. public async Task StartAsync(CancellationToken cancellationToken)
  21. {
  22. string sim = "22222222222";
  23. JT808TcpClient client1 = await jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, "127.0.0.1", 808, JT808Version.JTT2019), cancellationToken);
  24. await Task.Delay(2000);
  25. //1.终端注册
  26. await client1.SendAsync(JT808MsgId.终端注册.Create2019(sim, new JT808_0x0100()
  27. {
  28. PlateNo = "粤A12346",
  29. PlateColor = 2,
  30. AreaID = 0,
  31. CityOrCountyId = 0,
  32. MakerId = "Koike002",
  33. TerminalId = "Koike002",
  34. TerminalModel = "Koike002"
  35. }));
  36. //2.终端鉴权
  37. await client1.SendAsync(JT808MsgId.终端鉴权.Create2019(sim, new JT808_0x0102()
  38. {
  39. Code = "6666",
  40. IMEI="123456",
  41. SoftwareVersion="v1.0.0"
  42. }));
  43. _ = Task.Run(async() =>
  44. {
  45. while (!cancellationToken.IsCancellationRequested)
  46. {
  47. var i = 0;
  48. //3.每5秒发一次
  49. await client1.SendAsync(JT808MsgId.位置信息汇报.Create2019(sim, new JT808_0x0200()
  50. {
  51. Lat = 110000 + i,
  52. Lng = 100000 + i,
  53. GPSTime = DateTime.Now,
  54. Speed = 50,
  55. Direction = 30,
  56. AlarmFlag = 5,
  57. Altitude = 50,
  58. StatusFlag = 10
  59. }));
  60. i++;
  61. await Task.Delay(5000);
  62. }
  63. }, cancellationToken);
  64. }
  65. public Task StopAsync(CancellationToken cancellationToken)
  66. {
  67. return Task.CompletedTask;
  68. }
  69. }
  70. }