Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

75 rindas
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. Thread.Sleep(5000);
  25. //1.终端注册
  26. client1.Send(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. client1.Send(JT808MsgId.终端鉴权.Create2019(sim, new JT808_0x0102()
  38. {
  39. Code = "6666",
  40. IMEI="123456",
  41. SoftwareVersion="v1.0.0"
  42. }));
  43. Task.Run(() => {
  44. while (true)
  45. {
  46. var i = 0;
  47. //3.每5秒发一次
  48. client1.Send(JT808MsgId.位置信息汇报.Create2019(sim, new JT808_0x0200()
  49. {
  50. Lat = 110000 + i,
  51. Lng = 100000 + i,
  52. GPSTime = DateTime.Now,
  53. Speed = 50,
  54. Direction = 30,
  55. AlarmFlag = 5,
  56. Altitude = 50,
  57. StatusFlag = 10
  58. }));
  59. i++;
  60. Thread.Sleep(5000);
  61. }
  62. });
  63. return Task.CompletedTask;
  64. }
  65. public Task StopAsync(CancellationToken cancellationToken)
  66. {
  67. return Task.CompletedTask;
  68. }
  69. }
  70. }