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.

69 rindas
2.3 KiB

  1. using JT808.Protocol.Interfaces;
  2. using JT808.Protocol.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Text;
  7. using Xunit;
  8. using JT808.Protocol.MessageBody;
  9. using JT808.Protocol.Internal;
  10. namespace JT808.Protocol.Test.Simples
  11. {
  12. public class Demo1
  13. {
  14. public JT808Serializer JT808Serializer;
  15. public Demo1()
  16. {
  17. IJT808Config jT808Config = new DefaultGlobalConfig();
  18. JT808Serializer = new JT808Serializer(jT808Config);
  19. }
  20. [Fact]
  21. public void Test1()
  22. {
  23. JT808Package jT808Package = new JT808Package();
  24. jT808Package.Header = new JT808Header
  25. {
  26. MsgId = Enums.JT808MsgId._0x0200.ToUInt16Value(),
  27. ManualMsgNum = 126,
  28. TerminalPhoneNo = "123456789012"
  29. };
  30. JT808_0x0200 jT808_0x0200 = new JT808_0x0200
  31. {
  32. AlarmFlag = 1,
  33. Altitude = 40,
  34. GPSTime = DateTime.Parse("2018-10-15 10:10:10"),
  35. Lat = 12222222,
  36. Lng = 132444444,
  37. Speed = 60,
  38. Direction = 0,
  39. StatusFlag = 2,
  40. BasicLocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  41. };
  42. jT808_0x0200.BasicLocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  43. {
  44. Mileage = 100
  45. });
  46. jT808_0x0200.BasicLocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  47. {
  48. Oil = 125
  49. });
  50. jT808Package.Bodies = jT808_0x0200;
  51. byte[] data = JT808Serializer.Serialize(jT808Package);
  52. var hex = data.ToHexString();
  53. //"7E020000261234567890120001000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D016C7E"
  54. Assert.Equal("7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E", hex);
  55. // 输出结果Hex:
  56. // 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
  57. }
  58. }
  59. }