123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using HengShan_Pump_TQC_IFSF.MessageEntity.Incoming;
- using Microsoft.CodeAnalysis.CSharp.Syntax;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Edge.Core.Parser.BinaryParser.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using HengShan_Pump_TQC_IFSF.MessageEntity;
- using System.Text;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using HengShan_Pump_TQC_IFSF;
- namespace HengShan_Pump_TQC_IFSF_Test
- {
- [TestClass]
- public class MessageTest
- {
- public static bool ValueEquals(IEnumerable<byte> array1, IEnumerable<byte> array2)
- {
- if (array1 == null && array2 == null)
- {
- return true;
- }
- if ((array1 == null) || (array2 == null))
- {
- return false;
- }
- if (array1.Count() != array2.Count())
- {
- return false;
- }
- if (array1.Equals(array2))
- {
- return true;
- }
- else
- {
- for (int Index = 0; Index < array1.Count(); Index++)
- {
- if (!Equals(array1.ElementAt(Index), array2.ElementAt(Index)))
- {
- return false;
- }
- }
- }
- return true;
- }
- [TestMethod]
- public void TestMethod1()
- {
- List<MessageTemplateBase> continueParseStack = new List<MessageTemplateBase>();
- HengShan_Pump_TQC_IFSF.Parser p = new HengShan_Pump_TQC_IFSF.Parser();
- p.Deserialized += (s, a) =>
- {
- if (a.Extra != null && a.Extra.Length > 0)
- {
- continueParseStack.Add(a.To);
- p.Deserialize(a.Extra);
- }
- else
- {
- continueParseStack.Add(a.To);
- }
- };
- var m = p.Deserialize(("02 01 01 01 00 22 " +
- //M_Lg 89
- "00 59 " +
- //database id 01: CALCULATOR DATABASE
- "01 01 " +
- "02 01 03 04 01 06 05 01 04 08 01 01 09 01 00 0B 01 01 0C 01 00 28 01 57 " +
- " 29 01 57 2A 01 35 2B 01 00 32 03 54 4F 4B 33 03 4D 50 44 34 03 54 51 43 " +
- " 35 0C 31 32 33 34 35 36 37 38 39 30 31 32 " +
- " 36 0C 30 30 30 30 30 30 30 30 31 2E 38 31 39 01 00 3A 06 00 00 00 00 02 32").ToBytes());
- Assert.AreEqual(true, continueParseStack.Count == 1);
- var dbParser = DatabaseDataParser.New().Convert(continueParseStack.Cast<IfsfMessage>().First().RawDatabaseData.ToArray());
- }
- [TestMethod]
- public void TestMethod2()
- {
- List<MessageTemplateBase> continueParseStack = new List<MessageTemplateBase>();
- HengShan_Pump_TQC_IFSF.Parser p = new HengShan_Pump_TQC_IFSF.Parser();
- p.Deserialized += (s, a) =>
- {
- if (a.Extra != null && a.Extra.Length > 0)
- {
- continueParseStack.Add(a.To);
- p.Deserialize(a.Extra);
- }
- else
- {
- continueParseStack.Add(a.To);
- }
- };
- var m = p.Deserialize(("01 01 02 01 02 00 00 03 01 00 01" +
- "" +
- "02 01 01 01 00 20 00 0A 01 00 01 06 00 00 00 00 01 92" +
- "" +
- "01 01 02 01 02 40 00 05 01 00 05 01 31" +
- "" +
- "02 01 01 01 00 E0 00 03 01 00 00" +
- "" +
- "01 01 02 01 02 00 00 03 01 00 05" +
- "" +
- "02 01 01 01 00 20 00 05 01 00 05 01 31" +
- "" +
- "01 01 02 01 02 40 00 05 01 00 04 01 0A" +
- "" +
- "01 01 02 01 02 40 00 05 01 00 04 01 0A" +
- "" +
- "02 01 01 01 00 E0 00 03 01 00 00" +
- "" +
- "01 01 02 01 02 00 00 03 01 00 04" +
- "" +
- "02 01 01 01 00 20 00 05 01 00 04 01 0A" +
- "" +
- "01 01 02 01 02 40 00 06 01 00 0B 02 02 01" +
- "" +
- "02 01 01 01 00 E0 00 03 01 00 00" +
- "" +
- "01 01 02 01 00 00 00 14 01 01 02 04 05 08 09 0B 0C 28 29 2A 2B 32 33 34 35 36 39 3A" +
- "02 01 01 01 00 22 00 59 01 01 02 01 03 04 01 06 05 01 04 08 01 01 09 01 00 0B 01 01 0C 01 00 28 01 57 29 01 57 2A 01 35 2B 01 00 32 03 54 4F 4B 33 03 4D 50 44 34 03 54 51 43 35 0C 31 32 33 34 35 36 37 38 39 30 31 32 36 0C 30 30 30 30 30 30 30 30 31 2E 38 31 39 01 00 3A 06 00 00 00 00 02 32" +
- "01 01 02 01 00 03 00 05 01 21 14 15 16" +
- "01 01 02 01 00 0C 00 05 01 22 14 15 16" +
- "01 01 02 01 00 15 00 05 01 23 14 15 16" +
- "01 01 02 01 00 1E 00 05 01 24 14 15 16" +
- "02 01 01 01 00 3E 00 0C 01 24 14 01 02 15 01 00 16 02 00 00" +
- "01 01 02 01 00 1F 00 05 01 24 14 15 16" +
- "01 01 02 01 00 00 00 05 01 21 14 15 16" +
- "02 01 01 01 00 20 00 0C 01 21 14 01 02 15 01 00 16 02 00 00" +
- "01 01 02 01 00 01 00 05 01 21 14 15 16" +
- "02 01 01 01 00 21 00 0C 01 21 14 01 02 15 01 00 16 02 00 00" +
- "01 01 02 01 00 02 00 03 01 21 16" +
- "01 01 02 01 00 0B 00 05 01 22 14 15 16" +
- "01 01 02 01 00 14 00 05 01 23 14 15 16" +
- "01 01 02 01 00 1D 00 05 01 24 14 15 16" +
- "02 01 01 01 00 3D 00 0C 01 24 14 01 02 15 01 00 16 02 00 00" +
- "01 01 02 01 00 1E 00 05 01 24 14 15 16" +
- "02 01 01 01 00 3E 00 0C 01 24 14 01 02 15 01 00 16 02 00 00" +
- "01 01 02 01 00 1F 00 03 01 24 16" +
- "02 01 01 01 00 3F 00 06 01 24 16 02 00 00" +
- "01 01 02 01 00 18 00 03 01 24 16" +
- "01 01 02 01 00 01 00 03 01 21 16" +
- "02 01 01 01 00 38 00 06 01 24 16 02 00 00" +
- "01 01 02 01 00 02 00 03 01 21 16" +
- "02 01 01 01 00 22 00 06 01 21 16 02 00 00" +
- "01 01 02 01 00 03 00 03 01 21 16" +
- "02 01 01 01 00 23 00 06 01 21 16 02 00 00" +
- "01 01 02 01 00 04 00 03 01 21 16" +
- "02 01 01 01 00 24 00 06 01 21 16 02 00 00" +
- "01 01 02 01 00 0D 00 05 01 22 14 15 16" +
- "01 01 02 01 00 16 00 05 01 23 14 15 16" +
- "02 01 01 01 00 36 00 0C 01 23 14 01 02 15 01 00 16 02 00 00" +
- "02 01 01 01 00 80 00 0C 03 23 41 04 64 00 01 01 04 05 01 02" +
- "02 01 01 01 00 80 00 18 01 24 64 00 14 01 01 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00" +
- "02 01 01 01 00 80 00 18 01 21 64 00 14 01 01 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00" +
- "02 01 01 01 00 80 00 18 01 23 64 00 14 01 02 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00" +
- "02 01 01 01 00 80 00 18 01 24 64 00 14 01 02 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00" +
- "02 01 01 01 00 80 00 0C 03 23 41 04 64 00 01 01 04 05 01 02" +
- "02 01 01 01 00 80 00 18 01 21 64 00 14 01 02 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00" +
- "02 01 01 01 00 80 00 0C 03 24 41 04 64 00 01 01 04 05 01 02" +
- "02 01 01 01 00 80 00 0C 03 21 41 04 64 00 01 01 04 05 01 02" +
- "02 01 01 01 00 80 00 18 01 22 64 00 14 01 01 15 01 00 16 02 00 00 50 08 00 00 00 00 00 00 00 00").ToBytes());
- Assert.AreEqual(true, continueParseStack.Count != 1);
- for (int i = 0; i < continueParseStack.Count; i++)
- {
- Console.WriteLine($"[{i}]: {continueParseStack.ElementAt(i).ToLogString()}");
- var dbParser = DatabaseDataParser.New().Convert(continueParseStack.Cast<IfsfMessage>().ElementAt(i).RawDatabaseData.ToArray());
- Console.WriteLine($"DatabaseType: {dbParser.DatabaseType}: " +
- $"{dbParser.DataIds.Select(di => $"dataEleId: {di.Item1}, dValue: (len: {di.Item2.Length}) {di.Item2.Select(d => d.ToString()).Aggregate("", (acc, n) => acc + " " + n)}").Aggregate((acc, n) => acc + " | " + n)}");
- Console.WriteLine();
- Console.WriteLine();
- }
- }
- [TestMethod]
- public void LonWorksHeartbeatSerializeTestMethod1()
- {
- var heartbeat = new LonWorksHeartbeat(1, 2, 1);
- heartbeat.DeviceStates = new[] { HeartbeatDeviceStatus.EverythingIsFine };
- var parser = new Parser();
- var actual = parser.Serialize(heartbeat);
- var expect = new byte[] { 0x01, 0x02, 0x01, 0x01, 0x00 };
- Assert.IsTrue(ValueEquals(actual, expect));
- }
- [TestMethod]
- public void LonWorksHeartbeatSerializeTestMethod2()
- {
- var heartbeat = new LonWorksHeartbeat(1, 3, 5);
- heartbeat.DeviceStates = new[] { HeartbeatDeviceStatus.EverythingIsFine };
- var parser = new Parser();
- var actual = parser.Serialize(heartbeat);
- var expect = new byte[] { 0x01, 0x03, 0x05, 0x01, 0x00 };
- Assert.IsTrue(ValueEquals(actual, expect));
- }
- }
- }
|