選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

69 行
2.9 KiB

  1. using JT808.Protocol.Extensions.GPS51.MessageBody;
  2. using JT808.Protocol.MessageBody;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System;
  5. using System.Collections.Generic;
  6. using Xunit;
  7. namespace JT808.Protocol.Extensions.GPS51.Test
  8. {
  9. public class JT808_0x0200_0xe2_Test
  10. {
  11. JT808Serializer JT808Serializer;
  12. public JT808_0x0200_0xe2_Test()
  13. {
  14. ServiceCollection serviceDescriptors = new ServiceCollection();
  15. serviceDescriptors.AddJT808Configure()
  16. .AddGPS51Configure();
  17. IJT808Config jT808Config = serviceDescriptors.BuildServiceProvider().GetRequiredService<IJT808Config>();
  18. JT808Serializer = new JT808Serializer(jT808Config);
  19. }
  20. [Fact]
  21. public void Serializer()
  22. {
  23. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  24. {
  25. AlarmFlag = 1,
  26. Altitude = 40,
  27. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  28. Lat = 12222222,
  29. Lng = 132444444,
  30. Speed = 60,
  31. Direction = 0,
  32. StatusFlag = 2,
  33. CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>()
  34. };
  35. jT808UploadLocationRequest.CustomLocationAttachData.Add(JT808_GPS51_Constants.JT808_0x0200_0xe2, new JT808_0x0200_0xe2
  36. {
  37. AttachInfoId = 0xe2,
  38. AttachInfoLength = 1,
  39. Version = "123123"
  40. });
  41. var hex = JT808Serializer.Serialize<JT808_0x0200>(jT808UploadLocationRequest).ToHexString();
  42. Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C0000180715101010E206313233313233", hex);
  43. }
  44. [Fact]
  45. public void Deserialize()
  46. {
  47. var jt808_0x0200 = JT808Serializer.Deserialize<JT808_0x0200>("000000010000000200BA7F0E07E4F11C0028003C0000180715101010E206313233313233".ToHexBytes());
  48. jt808_0x0200.CustomLocationAttachData.TryGetValue(JT808_GPS51_Constants.JT808_0x0200_0xe2, out var value);
  49. var jt808_0x0200_0xe2 = value as JT808_0x0200_0xe2;
  50. Assert.Equal("123123", jt808_0x0200_0xe2.Version);
  51. }
  52. [Fact]
  53. public void Deserialize1()
  54. {
  55. //gps51 demo
  56. var jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808Package>("7e02004043010000086061575429591701bc00000000000c00030158ae9606c9069600000000006b21091717255901040000000130011931010a610204dce21547423230312d47534d2d32313030312d312e312e31c57e".ToHexBytes());
  57. var body0200 = jT808UploadLocationRequest.Bodies as JT808_0x0200;
  58. body0200.CustomLocationAttachData.TryGetValue(JT808_GPS51_Constants.JT808_0x0200_0xe2 ,out var value);
  59. var jt808_0x0200_0xe2 = value as JT808_0x0200_0xe2;
  60. Assert.Equal("GB201-GSM-21001-1.1.1", jt808_0x0200_0xe2.Version);
  61. }
  62. }
  63. }