您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

655 行
33 KiB

  1. using JT808.Protocol.Enums;
  2. using JT808.Protocol.Exceptions;
  3. using JT808.Protocol.Extensions;
  4. using JT808.Protocol.Interfaces;
  5. using JT808.Protocol.Internal;
  6. using JT808.Protocol.MessageBody;
  7. using JT808.Protocol.Test.JT808LocationAttach;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Threading.Tasks;
  14. using Xunit;
  15. namespace JT808.Protocol.Test.MessageBody
  16. {
  17. public class JT808_0x0200Test
  18. {
  19. JT808Serializer JT808Serializer;
  20. public JT808_0x0200Test()
  21. {
  22. IJT808Config jT808Config = new DefaultGlobalConfig();
  23. jT808Config.JT808_0X0200_Custom_Factory.SetMap<JT808LocationAttachImpl0x06>();
  24. JT808Serializer = new JT808Serializer(jT808Config);
  25. }
  26. [Fact]
  27. public void Test1()
  28. {
  29. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  30. {
  31. AlarmFlag = 1,
  32. Altitude = 40,
  33. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  34. Lat = 12222222,
  35. Lng = 132444444,
  36. Speed = 60,
  37. Direction = 0,
  38. StatusFlag = 2,
  39. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  40. };
  41. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  42. {
  43. Mileage = 100
  44. });
  45. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  46. {
  47. Oil = 55
  48. });
  49. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  50. Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037", hex);
  51. }
  52. [Fact]
  53. public void Parallel_Test1_1()
  54. {
  55. ConcurrentBag<string> hexs = new ConcurrentBag<string>();
  56. Parallel.For(1, 20, new ParallelOptions
  57. {
  58. MaxDegreeOfParallelism=5
  59. }, (i) =>
  60. {
  61. JT808Package jT808Package = new JT808Package();
  62. jT808Package.Header = new JT808Header
  63. {
  64. MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(),
  65. ManualMsgNum = (ushort)i,
  66. TerminalPhoneNo = "1122334455"+i.ToString(),
  67. };
  68. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  69. {
  70. AlarmFlag = 1,
  71. Altitude = 40,
  72. GPSTime = DateTime.Parse("2018-07-15 10:10:10").AddSeconds(i),
  73. Lat = 12222222,
  74. Lng = 132444444,
  75. Speed = 60,
  76. Direction = 0,
  77. StatusFlag = 2,
  78. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  79. };
  80. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  81. {
  82. Mileage = 100
  83. });
  84. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  85. {
  86. Oil = 55
  87. });
  88. jT808Package.Bodies = jT808UploadLocationRequest;
  89. var hex = JT808Serializer.Serialize(jT808Package).ToHexString();
  90. hexs.Add(hex);
  91. });
  92. //7E02000026 112233445519 0013 000000010000000200BA7F0E07E4F11C0028003C0000 180715101029 01040000006402020037987E,
  93. //7E02000026 112233445518 0012 000000010000000200BA7F0E07E4F11C0028003C0000 180715101028 01040000006402020037997E,
  94. //7E02000026 112233445517 0011 000000010000000200BA7F0E07E4F11C0028003C0000 180715101027 010400000064020200379A7E,
  95. //7E02000026 112233445516 0010 000000010000000200BA7F0E07E4F11C0028003C0000 180715101026 010400000064020200379B7E,
  96. //7E02000026 112233445515 000F 000000010000000200BA7F0E07E4F11C0028003C0000 180715101025 01040000006402020037847E,
  97. //7E02000026 112233445514 000E 000000010000000200BA7F0E07E4F11C0028003C0000 180715101024 01040000006402020037857E,
  98. //7E02000026 112233445513 000D 000000010000000200BA7F0E07E4F11C0028003C0000 180715101023 01040000006402020037867E,
  99. //7E02000026 112233445512 000C 000000010000000200BA7F0E07E4F11C0028003C0000 180715101022 01040000006402020037877E,
  100. //7E02000026 112233445511 000B 000000010000000200BA7F0E07E4F11C0028003C0000 180715101021 01040000006402020037807E,
  101. //7E02000026 112233445510 000A 000000010000000200BA7F0E07E4F11C0028003C0000 180715101020 01040000006402020037817E,
  102. //7E02000026 011223344559 0009 000000010000000200BA7F0E07E4F11C0028003C0000 180715101019 01040000006402020037A27E,
  103. //7E02000026 011223344558 0008 000000010000000200BA7F0E07E4F11C0028003C0000 180715101018 01040000006402020037A37E,
  104. //7E02000026 011223344557 0007 000000010000000200BA7F0E07E4F11C0028003C0000 180715101017 01040000006402020037AC7E,
  105. //7E02000026 011223344556 0006 000000010000000200BA7F0E07E4F11C0028003C0000 180715101016 01040000006402020037AD7E,
  106. //7E02000026 011223344555 0005 000000010000000200BA7F0E07E4F11C0028003C0000 180715101015 01040000006402020037AE7E,
  107. //7E02000026 011223344554 0004 000000010000000200BA7F0E07E4F11C0028003C0000 180715101014 01040000006402020037AF7E,
  108. //7E02000026 011223344553 0003 000000010000000200BA7F0E07E4F11C0028003C0000 180715101013 01040000006402020037A87E,
  109. //7E02000026 011223344552 0002 000000010000000200BA7F0E07E4F11C0028003C0000 180715101012 01040000006402020037A97E,
  110. //7E02000026 011223344551 0001 000000010000000200BA7F0E07E4F11C0028003C0000 180715101011 01040000006402020037AA7E,
  111. //7E02000026 011223344550 0001 000000010000000200BA7F0E07E4F11C0028003C0000 180715101010 01040000006402020037AA7E
  112. //7E02000026 011223344550 0000 000000010000000200BA7F0E07E4F11C0028003C0000 180715101010 01040000006402020037AB7E,
  113. string result = "7E020000260112233445500000000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037AB7E,7E020000260112233445570007000000010000000200BA7F0E07E4F11C0028003C000018071510101701040000006402020037AC7E,7E020000260112233445560006000000010000000200BA7F0E07E4F11C0028003C000018071510101601040000006402020037AD7E,7E020000260112233445550005000000010000000200BA7F0E07E4F11C0028003C000018071510101501040000006402020037AE7E,7E020000260112233445540004000000010000000200BA7F0E07E4F11C0028003C000018071510101401040000006402020037AF7E,7E020000261122334455190013000000010000000200BA7F0E07E4F11C0028003C000018071510102901040000006402020037987E,7E020000261122334455180012000000010000000200BA7F0E07E4F11C0028003C000018071510102801040000006402020037997E,7E020000261122334455170011000000010000000200BA7F0E07E4F11C0028003C0000180715101027010400000064020200379A7E,7E020000261122334455160010000000010000000200BA7F0E07E4F11C0028003C0000180715101026010400000064020200379B7E,7E02000026112233445515000F000000010000000200BA7F0E07E4F11C0028003C000018071510102501040000006402020037847E,7E02000026112233445514000E000000010000000200BA7F0E07E4F11C0028003C000018071510102401040000006402020037857E,7E02000026112233445513000D000000010000000200BA7F0E07E4F11C0028003C000018071510102301040000006402020037867E,7E02000026112233445512000C000000010000000200BA7F0E07E4F11C0028003C000018071510102201040000006402020037877E,7E020000260112233445530003000000010000000200BA7F0E07E4F11C0028003C000018071510101301040000006402020037A87E,7E020000260112233445520002000000010000000200BA7F0E07E4F11C0028003C000018071510101201040000006402020037A97E,7E020000260112233445510001000000010000000200BA7F0E07E4F11C0028003C000018071510101101040000006402020037AA7E,7E02000026112233445511000B000000010000000200BA7F0E07E4F11C0028003C000018071510102101040000006402020037807E,7E02000026112233445510000A000000010000000200BA7F0E07E4F11C0028003C000018071510102001040000006402020037817E,7E020000260112233445590009000000010000000200BA7F0E07E4F11C0028003C000018071510101901040000006402020037A27E,7E020000260112233445580008000000010000000200BA7F0E07E4F11C0028003C000018071510101801040000006402020037A37E";
  114. //7E020000260112233445500001000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037AA7E
  115. List<string> resultHexs = result.Split(',').ToList();
  116. string hexStr = string.Join(',', hexs);
  117. foreach (var item in hexs)
  118. {
  119. Assert.Contains(item, resultHexs);
  120. }
  121. }
  122. [Fact]
  123. public void Test2()
  124. {
  125. byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37".ToHexBytes();
  126. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  127. Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag);
  128. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  129. Assert.Equal(12222222, jT808UploadLocationRequest.Lat);
  130. Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
  131. Assert.Equal(60, jT808UploadLocationRequest.Speed);
  132. Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag);
  133. Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage);
  134. Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil);
  135. }
  136. [Fact]
  137. public void Test2_1()
  138. {
  139. byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37".ToHexBytes();
  140. string json = JT808Serializer.Analyze<JT808_0x0200>(bodys);
  141. }
  142. [Fact]
  143. public void Test3()
  144. {
  145. //00 00 00 01
  146. //00 00 00 02
  147. //00 BA 7F 0E
  148. //07 E4 F1 1C
  149. //00 28
  150. //00 3C
  151. //00 00
  152. //18 07 15 10 10 10
  153. //01
  154. // 04
  155. // 00 00 00 64
  156. //02
  157. // 02
  158. // 00 37
  159. //06
  160. // 0D
  161. // 00 00 00 12 01 73 6D 61 6C 6C 63 68 69"
  162. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  163. {
  164. AlarmFlag = 1,
  165. Altitude = 40,
  166. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  167. Lat = 12222222,
  168. Lng = 132444444,
  169. Speed = 60,
  170. Direction = 0,
  171. StatusFlag = 2,
  172. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>(),
  173. JT808CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>()
  174. };
  175. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  176. {
  177. Mileage = 100
  178. });
  179. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  180. {
  181. Oil = 55
  182. });
  183. jT808UploadLocationRequest.JT808CustomLocationAttachData.Add(0x06, new JT808LocationAttachImpl0x06
  184. {
  185. Age = 18,
  186. Gender = 1,
  187. UserName = "smallchi"
  188. });
  189. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  190. Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037060D0000001201736D616C6C636869", hex);
  191. }
  192. [Fact]
  193. public void Test4()
  194. {
  195. // 1.添加自定义附加信息扩展 AddJT808LocationAttachMethod
  196. byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 06 0D 00 00 00 12 01 73 6D 61 6C 6C 63 68 69".ToHexBytes();
  197. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  198. Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag);
  199. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  200. Assert.Equal(12222222, jT808UploadLocationRequest.Lat);
  201. Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
  202. Assert.Equal(60, jT808UploadLocationRequest.Speed);
  203. Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag);
  204. Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage);
  205. Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil);
  206. var jT808LocationAttachImpl0x06 = (JT808LocationAttachImpl0x06)jT808UploadLocationRequest.JT808CustomLocationAttachData[0x06];
  207. Assert.Equal(18, jT808LocationAttachImpl0x06.Age);
  208. Assert.Equal(1, jT808LocationAttachImpl0x06.Gender);
  209. Assert.Equal("smallchi", jT808LocationAttachImpl0x06.UserName);
  210. }
  211. [Fact]
  212. public void Test5_1()
  213. {
  214. JT808Package jT808Package = new JT808Package();
  215. jT808Package.Header = new JT808Header
  216. {
  217. MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(),
  218. MsgNum = 8888,
  219. TerminalPhoneNo = "112233445566",
  220. //MessageBodyProperty=new JT808MessageBodyProperty(38),
  221. };
  222. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  223. {
  224. AlarmFlag = 1,
  225. Altitude = 40,
  226. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  227. Lat = 12222222,
  228. Lng = 132444444,
  229. Speed = 60,
  230. Direction = 0,
  231. StatusFlag = 2,
  232. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  233. };
  234. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  235. {
  236. Mileage = 100
  237. });
  238. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  239. {
  240. Oil = 55
  241. });
  242. jT808Package.Bodies = jT808UploadLocationRequest;
  243. var hex = JT808Serializer.Serialize(jT808Package).ToHexString();
  244. }
  245. [Fact]
  246. public void Test5()
  247. {
  248. //7E
  249. //02 00
  250. //00 33
  251. //11 22 33 44 55 66
  252. //22 B8
  253. //00 00 00 01
  254. //00 00 00 02
  255. //00 BA 7F 0E
  256. //07 E4 F1 1C
  257. //00 28
  258. //00 3C
  259. //00 00
  260. //18 07 15 10 10 10
  261. //01
  262. // 04
  263. // 00 00 00 64
  264. //02
  265. // 02
  266. // 00 37
  267. //42 7E
  268. byte[] bytes = "7E 02 00 00 26 11 22 33 44 55 66 22 B8 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 57 7E".ToHexBytes();
  269. var jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes);
  270. Assert.Equal(Enums.JT808MsgId.位置信息汇报.ToValue(), jT808Package.Header.MsgId);
  271. Assert.Equal(38, jT808Package.Header.MessageBodyProperty.DataLength);
  272. Assert.Equal(8888, jT808Package.Header.MsgNum);
  273. Assert.Equal("112233445566", jT808Package.Header.TerminalPhoneNo);
  274. Assert.False(jT808Package.Header.MessageBodyProperty.IsPackage);
  275. Assert.Equal(0, jT808Package.Header.PackageIndex);
  276. Assert.Equal(0, jT808Package.Header.PackgeCount);
  277. Assert.Equal(JT808EncryptMethod.None, jT808Package.Header.MessageBodyProperty.Encrypt);
  278. JT808_0x0200 jT808UploadLocationRequest = (JT808_0x0200)jT808Package.Bodies;
  279. Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag);
  280. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  281. Assert.Equal(12222222, jT808UploadLocationRequest.Lat);
  282. Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
  283. Assert.Equal(60, jT808UploadLocationRequest.Speed);
  284. Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag);
  285. Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage);
  286. Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil);
  287. }
  288. [Fact]
  289. public void Test_all_attcahids()
  290. {
  291. JT808Package jT808Package = new JT808Package();
  292. jT808Package.Header = new JT808Header
  293. {
  294. MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(),
  295. ManualMsgNum = 8888,
  296. TerminalPhoneNo = "112233445566",
  297. };
  298. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200();
  299. jT808UploadLocationRequest.AlarmFlag = 1;
  300. jT808UploadLocationRequest.Altitude = 40;
  301. jT808UploadLocationRequest.GPSTime = DateTime.Parse("2018-07-15 10:10:10");
  302. jT808UploadLocationRequest.Lat = 12222222;
  303. jT808UploadLocationRequest.Lng = 132444444;
  304. jT808UploadLocationRequest.Speed = 60;
  305. jT808UploadLocationRequest.Direction = 0;
  306. jT808UploadLocationRequest.StatusFlag = 2;
  307. jT808UploadLocationRequest.JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>();
  308. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01
  309. {
  310. Mileage = 100
  311. });
  312. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02
  313. {
  314. Oil = 55
  315. });
  316. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x03, new JT808_0x0200_0x03
  317. {
  318. Speed = 56
  319. });
  320. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x04, new JT808_0x0200_0x04
  321. {
  322. EventId = 1
  323. });
  324. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x11, new JT808_0x0200_0x11
  325. {
  326. AreaId = 1,
  327. JT808PositionType = Enums.JT808PositionType.圆形区域
  328. });
  329. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x12, new JT808_0x0200_0x12
  330. {
  331. AreaId = 1,
  332. JT808PositionType = Enums.JT808PositionType.圆形区域,
  333. Direction = Enums.JT808DirectionType.出
  334. });
  335. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x13, new JT808_0x0200_0x13
  336. {
  337. DrivenRoute = Enums.JT808DrivenRouteType.过长,
  338. DrivenRouteId = 2,
  339. Time = 34
  340. });
  341. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x25, new JT808_0x0200_0x25
  342. {
  343. CarSignalStatus = 23
  344. });
  345. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x2A, new JT808_0x0200_0x2A
  346. {
  347. IOStatus = 244
  348. });
  349. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x2B, new JT808_0x0200_0x2B
  350. {
  351. Analog = 242
  352. });
  353. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x30, new JT808_0x0200_0x30
  354. {
  355. WiFiSignalStrength = 0x02
  356. });
  357. jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x31, new JT808_0x0200_0x31
  358. {
  359. GNSSCount = 0x05
  360. });
  361. jT808Package.Bodies = jT808UploadLocationRequest;
  362. var hex = JT808Serializer.Serialize(jT808Package).ToHexString();
  363. Assert.Equal("7E0200005C11223344556622B8000000010000000200BA7F0E07E4F11C0028003C00001807151010100104000000640202003703020038040200011105010000000112060100000001011307000000020022012504000000172A0200F42B04000000F2300102310105167E", hex);
  364. //7E0200005C11223344556622B8000000010000000200BA7F0E07E4F11C0028003C00001807151010100104000000640202003703020038040200011105010000000112060100000001011307000000020022012504000000172A0200F42B04000000F2300102310105167E
  365. //7E
  366. //02 00
  367. //00 5C
  368. //11 22 33 44 55 66
  369. //22 B8
  370. //00 00 00 01
  371. //00 00 00 02
  372. //00 BA 7F 0E
  373. //07 E4 F1 1C
  374. //00 28
  375. //00 3C
  376. //00 00
  377. //18 07 15 10 10 10
  378. //01
  379. // 04
  380. // 00 00 00 64
  381. //02
  382. // 02
  383. // 00 37
  384. //03
  385. // 02
  386. // 00 38
  387. //04
  388. // 02
  389. // 00 01
  390. //11
  391. // 05
  392. // 01 00 00 00 01
  393. //12
  394. // 06
  395. // 01 00 00 00 01 01
  396. //13
  397. // 07
  398. // 00 00 00 02 00 22 01
  399. //25
  400. // 04
  401. // 00 00 00 17
  402. //2A
  403. // 02
  404. // 00 F4
  405. //2B
  406. // 04
  407. // 00 00 00 F2
  408. //30
  409. // 01
  410. // 02
  411. //31
  412. // 01
  413. // 05
  414. //16
  415. //7E
  416. }
  417. [Fact]
  418. public void LatLngTest1_1()
  419. {
  420. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  421. {
  422. AlarmFlag = 1,
  423. Altitude = 40,
  424. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  425. Lat = -12222222,
  426. Lng = -132444444,
  427. Speed = 60,
  428. Direction = 0,
  429. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  430. };
  431. jT808UploadLocationRequest.StatusFlag = 0x18000000;
  432. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  433. Assert.Equal("0000000118000000FF4580F2F81B0EE40028003C0000180715101010", hex);
  434. }
  435. [Fact]
  436. public void LatLngTest1_2()
  437. {
  438. byte[] bodys = "0000000118000000FF4580F2F81B0EE40028003C0000180715101010".ToHexBytes();
  439. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  440. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  441. Assert.Equal(402653184u, jT808UploadLocationRequest.StatusFlag);
  442. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  443. Assert.Equal(-12222222, jT808UploadLocationRequest.Lat);
  444. Assert.Equal(-132444444, jT808UploadLocationRequest.Lng);
  445. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  446. }
  447. [Fact]
  448. public void LatLngTest2_1()
  449. {
  450. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  451. {
  452. AlarmFlag = 1,
  453. Altitude = 40,
  454. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  455. Lat = -12222222,
  456. Lng = -132444444,
  457. Speed = 60,
  458. Direction = 0,
  459. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  460. };
  461. jT808UploadLocationRequest.StatusFlag = 0x18000000 | 0x302;
  462. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  463. Assert.Equal("0000000118000302FF4580F2F81B0EE40028003C0000180715101010", hex);
  464. }
  465. [Fact]
  466. public void LatLngTest2_2()
  467. {
  468. byte[] bodys = "0000000118000302FF4580F2F81B0EE40028003C0000180715101010".ToHexBytes();
  469. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  470. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  471. Assert.Equal((uint)(0x18000000 | 0x302), jT808UploadLocationRequest.StatusFlag);
  472. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  473. Assert.Equal(-12222222, jT808UploadLocationRequest.Lat);
  474. Assert.Equal(-132444444, jT808UploadLocationRequest.Lng);
  475. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  476. }
  477. [Fact]
  478. public void LatTest1_1()
  479. {
  480. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  481. {
  482. AlarmFlag = 1,
  483. Altitude = 40,
  484. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  485. Lat = -12222222,
  486. Lng = 132444444,
  487. Speed = 60,
  488. Direction = 0,
  489. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  490. };
  491. jT808UploadLocationRequest.StatusFlag = 0x10000000;
  492. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  493. Assert.Equal("0000000110000000FF4580F207E4F11C0028003C0000180715101010", hex);
  494. }
  495. [Fact]
  496. public void LatTest1_2()
  497. {
  498. byte[] bodys = "0000000110000000FF4580F207E4F11C0028003C0000180715101010".ToHexBytes();
  499. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  500. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  501. Assert.Equal((uint)0x10000000, jT808UploadLocationRequest.StatusFlag);
  502. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  503. Assert.Equal(-12222222, jT808UploadLocationRequest.Lat);
  504. Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
  505. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  506. }
  507. [Fact]
  508. public void LatTest2()
  509. {
  510. JT808Exception exception= Assert.Throws<JT808Exception>(() => {
  511. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  512. {
  513. AlarmFlag = 1,
  514. Altitude = 40,
  515. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  516. Lat = -12222222,
  517. Lng = 132444444,
  518. Speed = 60,
  519. Direction = 0,
  520. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  521. };
  522. jT808UploadLocationRequest.StatusFlag = 1111;
  523. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  524. });
  525. Assert.Equal(JT808ErrorCode.LatOrLngError, exception.ErrorCode);
  526. }
  527. [Fact]
  528. public void LatTest3_1()
  529. {
  530. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  531. {
  532. AlarmFlag = 1,
  533. Altitude = 40,
  534. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  535. Lat = -12222222,
  536. Lng = 132444444,
  537. Speed = 60,
  538. Direction = 0,
  539. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  540. };
  541. jT808UploadLocationRequest.StatusFlag = 0x10000000 | 0x000300;
  542. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  543. Assert.Equal("0000000110000300FF4580F207E4F11C0028003C0000180715101010", hex);
  544. }
  545. [Fact]
  546. public void LatTest3_2()
  547. {
  548. byte[] bodys = "0000000110000300FF4580F207E4F11C0028003C0000180715101010".ToHexBytes();
  549. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  550. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  551. Assert.Equal((uint)(0x10000000 | 0x000300), jT808UploadLocationRequest.StatusFlag);
  552. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  553. Assert.Equal(-12222222, jT808UploadLocationRequest.Lat);
  554. Assert.Equal(132444444, jT808UploadLocationRequest.Lng);
  555. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  556. }
  557. [Fact]
  558. public void LngTest1_1()
  559. {
  560. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  561. {
  562. AlarmFlag = 1,
  563. Altitude = 40,
  564. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  565. Lat = 12222222,
  566. Lng = -132444444,
  567. Speed = 60,
  568. Direction = 0,
  569. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  570. };
  571. jT808UploadLocationRequest.StatusFlag = 0x8000000;
  572. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  573. Assert.Equal("000000010800000000BA7F0EF81B0EE40028003C0000180715101010", hex);
  574. }
  575. [Fact]
  576. public void LngTest1_2()
  577. {
  578. byte[] bodys = "000000010800000000BA7F0EF81B0EE40028003C0000180715101010".ToHexBytes();
  579. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  580. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  581. Assert.Equal((uint)0x8000000, jT808UploadLocationRequest.StatusFlag);
  582. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  583. Assert.Equal(12222222, jT808UploadLocationRequest.Lat);
  584. Assert.Equal(-132444444, jT808UploadLocationRequest.Lng);
  585. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  586. }
  587. [Fact]
  588. public void LngTest2()
  589. {
  590. JT808Exception exception = Assert.Throws<JT808Exception>(() => {
  591. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  592. {
  593. AlarmFlag = 1,
  594. Altitude = 40,
  595. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  596. Lat = 12222222,
  597. Lng = -132444444,
  598. Speed = 60,
  599. Direction = 0,
  600. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  601. };
  602. jT808UploadLocationRequest.StatusFlag = 1111;
  603. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  604. });
  605. Assert.Equal(JT808ErrorCode.LatOrLngError, exception.ErrorCode);
  606. }
  607. [Fact]
  608. public void LngTest3_1()
  609. {
  610. JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200
  611. {
  612. AlarmFlag = 1,
  613. Altitude = 40,
  614. GPSTime = DateTime.Parse("2018-07-15 10:10:10"),
  615. Lat = 12222222,
  616. Lng = -132444444,
  617. Speed = 60,
  618. Direction = 0,
  619. JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>()
  620. };
  621. jT808UploadLocationRequest.StatusFlag = 0x8000000|0x6601;
  622. var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
  623. Assert.Equal("000000010800660100BA7F0EF81B0EE40028003C0000180715101010", hex);
  624. }
  625. [Fact]
  626. public void LngTest3_2()
  627. {
  628. byte[] bodys = "000000010800660100BA7F0EF81B0EE40028003C0000180715101010".ToHexBytes();
  629. JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys);
  630. Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag);
  631. Assert.Equal((uint)(0x8000000 | 0x6601), jT808UploadLocationRequest.StatusFlag);
  632. Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime);
  633. Assert.Equal(12222222, jT808UploadLocationRequest.Lat);
  634. Assert.Equal(-132444444, jT808UploadLocationRequest.Lng);
  635. Assert.Equal(60, jT808UploadLocationRequest.Speed); //‭402653184‬
  636. }
  637. }
  638. }