You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
2.7 KiB

  1. using JT808.Gateway.Client;
  2. using JT808.Protocol.MessageBody;
  3. using Microsoft.Extensions.Hosting;
  4. using Microsoft.Extensions.Logging;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using JT808.Gateway.GrpcService;
  12. using static JT808.Gateway.GrpcService.JT808Gateway;
  13. using Google.Protobuf;
  14. using System.Text.Json;
  15. using JT808.Protocol.Extensions;
  16. namespace JT808.Gateway.SimpleClient.Services
  17. {
  18. public class GrpcClientService : IHostedService
  19. {
  20. private readonly ILogger logger;
  21. private readonly JT808GatewayClient client;
  22. public GrpcClientService(
  23. ILoggerFactory loggerFactory,
  24. JT808GatewayClient jT808GatewayClient)
  25. {
  26. this.client = jT808GatewayClient;
  27. logger = loggerFactory.CreateLogger("GrpcClientService");
  28. }
  29. public Task StartAsync(CancellationToken cancellationToken)
  30. {
  31. Task.Run(() => {
  32. //while (!cancellationToken.IsCancellationRequested)
  33. //{
  34. Thread.Sleep(1000 * 10);
  35. var result1 = client.GetTcpAtomicCounter(new Empty());
  36. var result2 = client.GetUdpAtomicCounter(new Empty());
  37. var result3 = client.GetTcpSessionAll(new Empty());
  38. var result4 = client.GetUdpSessionAll(new Empty());
  39. var result5 = client.UnificationSend(new UnificationSendRequest()
  40. {
  41. TerminalPhoneNo= "12345678910",
  42. Data= ByteString.CopyFrom("7E 02 00 00 26 12 34 56 78 90 12 00 7D 02 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes())
  43. });
  44. var result6 = client.RemoveSessionByTerminalPhoneNo(new SessionRemoveRequest()
  45. {
  46. TerminalPhoneNo= "12345678910"
  47. });
  48. logger.LogDebug(JsonSerializer.Serialize(result1));
  49. logger.LogDebug(JsonSerializer.Serialize(result2));
  50. logger.LogDebug(JsonSerializer.Serialize(result3));
  51. logger.LogDebug(JsonSerializer.Serialize(result4));
  52. logger.LogDebug(JsonSerializer.Serialize(result5));
  53. logger.LogDebug(JsonSerializer.Serialize(result6));
  54. //}
  55. }, cancellationToken);
  56. return Task.CompletedTask;
  57. }
  58. public Task StopAsync(CancellationToken cancellationToken)
  59. {
  60. return Task.CompletedTask;
  61. }
  62. }
  63. }