No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

74 líneas
2.4 KiB

  1. using JT808.DotNetty.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.DotNetty.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 Task StartAsync(CancellationToken cancellationToken)
  21. {
  22. string sim = "22222222222";
  23. JT808TcpClient client1 = jT808TcpClientFactory.Create(new JT808DeviceConfig(sim, "127.0.0.1", 808, JT808Version.JTT2019));
  24. //1.终端注册
  25. client1.Send(JT808MsgId.终端注册.Create2019(sim, new JT808_0x0100()
  26. {
  27. PlateNo = "粤A12346",
  28. PlateColor = 2,
  29. AreaID = 0,
  30. CityOrCountyId = 0,
  31. MakerId = "Koike002",
  32. TerminalId = "Koike002",
  33. TerminalModel = "Koike002"
  34. }));
  35. //2.终端鉴权
  36. client1.Send(JT808MsgId.终端鉴权.Create2019(sim, new JT808_0x0102()
  37. {
  38. Code = "6666",
  39. IMEI="123456",
  40. SoftwareVersion="v1.0.0"
  41. }));
  42. Task.Run(() => {
  43. while (true)
  44. {
  45. var i = 0;
  46. //3.每5秒发一次
  47. client1.Send(JT808MsgId.位置信息汇报.Create2019(sim, new JT808_0x0200()
  48. {
  49. Lat = 110000 + i,
  50. Lng = 100000 + i,
  51. GPSTime = DateTime.Now,
  52. Speed = 50,
  53. Direction = 30,
  54. AlarmFlag = 5,
  55. Altitude = 50,
  56. StatusFlag = 10
  57. }));
  58. i++;
  59. Thread.Sleep(5000);
  60. }
  61. });
  62. return Task.CompletedTask;
  63. }
  64. public Task StopAsync(CancellationToken cancellationToken)
  65. {
  66. return Task.CompletedTask;
  67. }
  68. }
  69. }