123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876 |
- using Edge.Core.Parser.BinaryParser.Util;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Collections.Generic;
- using System.Linq;
- using ZhongSheng_NonIC_Pump;
- namespace ZhongSheng_NonIC_Pump_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 Checksum_TestMethod1()
- {
- var data = new byte[] { 0x01, 0xFF, 0x01, 0x08, 0x30, 0x20, 0x19, 0x12, 0x01, 0x23, 0x59, 0x59 };
- var expect = 0x18;
- var actual = Parser.CaculateCheckSum(data);
- Assert.AreEqual(expect, actual);
- }
- [TestMethod]
- public void MessageCutter_TestMethod1()
- {
- var data = new byte[] { 0xFA, 0x01, 0xFF, 0x01, 0x08, 0x30, 0x20, 0x19, 0x12, 0x01, 0x23, 0x59, 0x59, 0x00 };
- var msgCutter = new MessageCutter();
- byte[] validMsg = null;
- msgCutter.OnMessageCut += (_, __) => { validMsg = msgCutter.Message; };
- msgCutter.Feed(data);
- Assert.IsNotNull(validMsg);
- Assert.AreEqual(true, ValueEquals(validMsg, data), "the actual is: 0x" + validMsg.ToHexLogString());
- }
- [TestMethod]
- public void MessageCutter_TestMethod2()
- {
- var data = new byte[] { 0x00, 0x01, 0x02, 0xFA, 0x01, 0xFF, 0x01, 0x01, 0x30, 0x00 };
- var msgCutter = new MessageCutter();
- byte[] validMsg = null;
- msgCutter.OnMessageCut += (_, __) => { validMsg = msgCutter.Message; };
- msgCutter.Feed(data);
- Assert.IsNotNull(validMsg);
- Assert.AreEqual(true, ValueEquals(validMsg, data.Skip(3)), "the actual is: 0x" + validMsg.ToHexLogString());
- }
- [TestMethod]
- public void MessageCutter_TestMethod3()
- {
- var data = new byte[] { 0x00,
- 0xFA, 0x01, 0xFF, 0x01, 0x01, 0x30, 0x00,
- 0x01, 0x02,
- 0xFA, 0x01, 0xFF, 0x01, 0x02, 0x30, 0x31, 0x00 };
- var msgCutter = new MessageCutter();
- List<byte[]> validMsgs = new List<byte[]>();
- msgCutter.OnMessageCut += (_, __) => { validMsgs.Add(msgCutter.Message); };
- msgCutter.Feed(data);
- Assert.AreEqual(2, validMsgs.Count);
- Assert.AreEqual(true, ValueEquals(validMsgs[0], new byte[] { 0xFA, 0x01, 0xFF, 0x01, 0x01, 0x30, 0x00 }), "the actual[0] is: 0x" + validMsgs[0].ToHexLogString());
- Assert.AreEqual(true, ValueEquals(validMsgs[1], new byte[] { 0xFA, 0x01, 0xFF, 0x01, 0x02, 0x30, 0x31, 0x00 }), "the actual[1] is: 0x" + validMsgs[1].ToHexLogString());
- }
- [TestMethod]
- public void GenericInquiryRequest_TestMethod1()
- {
- var msg = new GenericInquiryRequest(new System.DateTime(2019, 12, 1, 23, 59, 59));
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 1;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] { 0xFA, 0x01, 0xFF, 0x01, 0x08, 0x30, 0x20, 0x19, 0x12, 0x01, 0x23, 0x59, 0x59, 0x18 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void PumpInIdleResponse_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x08,
- //command code
- 0x31,
- 0x00,
- 0x18 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw);
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual is PumpInIdleResponse);
- }
- [TestMethod]
- public void PumpInOperationResponse_FuellingState_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0E,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x01,
- //状态字 枪号 金额(带2位小数) 升数(带2位小数) 价格(带2位小数)
- 0x01, 0x01, 0x00,0x00,0x00,0x01, 0x00,0x00,0x02, 0x00,0x00,0x03,
- //checksum
- 0x00
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.PumpStateBlocks == null);
- Assert.IsTrue(actual.FuellingDataBlocks.Count() == 1);
- Assert.IsTrue(actual.FuellingDataBlocks.First().NozzleNumber == 1);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Amount == 1);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Volume == 2);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Price == 3);
- }
- [TestMethod]
- public void PumpInOperationResponse_FuellingState_TestMethod2()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0E,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x01,
- //状态字 枪号 金额(带2位小数) 升数(带2位小数) 价格(带2位小数)
- 0x01, 0x09, 0x00,0x00,0x00,0x05, 0x00,0x00,0x06, 0x00,0x00,0x07,
- //checksum
- 0x00
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.PumpStateBlocks == null);
- Assert.IsTrue(actual.FuellingDataBlocks.Count() == 1);
- Assert.IsTrue(actual.FuellingDataBlocks.First().NozzleNumber == 9);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Amount == 5);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Volume == 6);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Price == 7);
- }
- [TestMethod]
- public void PumpInOperationResponse_FuellingState_TestMethod3()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0E,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x02,
- //状态字 枪号 金额(带2位小数) 升数(带2位小数) 价格(带2位小数)
- 0x01, 0x08, 0x00,0x00,0x00,0x05, 0x00,0x00,0x06, 0x00,0x00,0x07,
- //状态字 枪号 金额(带2位小数) 升数(带2位小数) 价格(带2位小数)
- 0x01, 0x09, 0x00,0x00,0x00,0x07, 0x00,0x00,0x08, 0x00,0x00,0x09,
- //checksum
- 0x00
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.PumpStateBlocks == null);
- Assert.IsTrue(actual.FuellingDataBlocks.Count() == 2);
- Assert.IsTrue(actual.FuellingDataBlocks.First().NozzleNumber == 8);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Amount == 5);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Volume == 6);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Price == 7);
- Assert.IsTrue(actual.FuellingDataBlocks.Skip(1).First().NozzleNumber == 9);
- Assert.IsTrue(actual.FuellingDataBlocks.Skip(1).First().Amount == 7);
- Assert.IsTrue(actual.FuellingDataBlocks.Skip(1).First().Volume == 8);
- Assert.IsTrue(actual.FuellingDataBlocks.Skip(1).First().Price == 9);
- }
- [TestMethod]
- public void PumpInOperationResponse_PumpState_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0E,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x01,
- //状态字 枪号 支付模式 枪状态 授权状态
- 0x02, 0x01, 0x04, 0x00, 0x00,
- //checksum
- 0x00
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FuellingDataBlocks == null);
- Assert.IsTrue(actual.PumpStateBlocks != null);
- Assert.IsTrue(actual.PumpStateBlocks.Count() == 1);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleNumber == 1);
- Assert.IsTrue(actual.PumpStateBlocks.First().AuthMode == PumpAuthModeEnum.需中控授权模式);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleLiftState == NozzleLiftStateEnum.未提);
- Assert.IsTrue(actual.PumpStateBlocks.First().PumpAuthorizeState == PumpAuthorizeStateEnum.未授权);
- }
- [TestMethod]
- public void PumpInOperationResponse_PumpState_TestMethod2()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0E,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x02,
- //状态字 枪号 支付模式 枪状态 授权状态
- 0x02, 0x01, 0x00, 0x01, 0x01,
- //状态字 枪号 支付模式 枪状态 授权状态
- 0x02, 0x03, 0x04, 0x02, 0x00,
- //checksum
- 0x00
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FuellingDataBlocks == null);
- Assert.IsTrue(actual.PumpStateBlocks != null);
- Assert.IsTrue(actual.PumpStateBlocks.Count() == 2);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleNumber == 1);
- Assert.IsTrue(actual.PumpStateBlocks.First().AuthMode == PumpAuthModeEnum.自授权模式);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleLiftState == NozzleLiftStateEnum.已提);
- Assert.IsTrue(actual.PumpStateBlocks.First().PumpAuthorizeState == PumpAuthorizeStateEnum.授权成功);
- Assert.IsTrue(actual.PumpStateBlocks.Skip(1).First().NozzleNumber == 3);
- Assert.IsTrue(actual.PumpStateBlocks.Skip(1).First().AuthMode == PumpAuthModeEnum.自授权模式);
- Assert.IsTrue(actual.PumpStateBlocks.Skip(1).First().NozzleLiftState == NozzleLiftStateEnum.第二条枪提起);
- Assert.IsTrue(actual.PumpStateBlocks.Skip(1).First().PumpAuthorizeState == PumpAuthorizeStateEnum.未授权);
- }
- [TestMethod]
- public void PumpInOperationResponse_PumpState_TestMethod3()
- {
- //0xFA E0 FF 0B 15 31
- //02
- //02 01 00 00 00 00 00
- //01 02 00 00 00 00 00 00 00 00 03 20
- //08
- var raw = new byte[] {
- 0xFA, 0xE0, 0xFF,
- // frameNo.
- 0x0B,
- //length code
- 0x15,
- //command code
- 0x31,
- //信息计数n(1字节)
- 0x02,
- //状态字 枪号 支付模式 状态 枪状态 授权状态
- 0x02, 0x01, 0x00, 0x00,0x00, 0x00, 0x00,
- //状态字 枪号 金额 升数 价格
- 0x01, 0x02, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00, 0x00, 0x03, 0x20,
- //checksum
- 0x20
- };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpInOperationResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.PumpStateBlocks != null);
- Assert.IsTrue(actual.PumpStateBlocks.Count() == 1);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleNumber == 1);
- Assert.IsTrue(actual.PumpStateBlocks.First().AuthMode == PumpAuthModeEnum.自授权模式);
- Assert.IsTrue(actual.PumpStateBlocks.First().NozzleLiftState == NozzleLiftStateEnum.未提);
- Assert.IsTrue(actual.PumpStateBlocks.First().PumpAuthorizeState == PumpAuthorizeStateEnum.未授权);
- Assert.IsTrue(actual.FuellingDataBlocks != null);
- Assert.IsTrue(actual.FuellingDataBlocks.Count() == 1);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Amount == 0);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Volume == 0);
- Assert.IsTrue(actual.FuellingDataBlocks.First().Price == (3 * 16 * 16 + 2 * 16));
- }
- [TestMethod]
- public void PumpNotifyTransactionDoneEvent_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x30,
- //command code
- 0x32,
- //交易金额 交易油量 交易单价 交易时间
- 0x00,0x00,0x00,0x01, 0x00,0x00,0x02, 0x00,0x00,0x03, 0x20,0x20,0x01,0x08,0x16,0x17,0x59,
- //交易枪号 油量总量 金额总量 支付模式
- 0x09, 0x00,0x00,0x00,0x04, 0x00,0x00,0x00,0x00,0x05, 0x06,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as PumpNotifyTransactionDoneEvent;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.交易金额 == 1);
- Assert.IsTrue(actual.交易油量 == 2);
- Assert.IsTrue(actual.交易单价 == 3);
- Assert.IsTrue(actual.交易时间_Raw == "20200108161759");
- Assert.IsTrue(actual.交易时间 == new System.DateTime(2020, 01, 08, 16, 17, 59));
- Assert.IsTrue(actual.交易枪号 == 9);
- Assert.IsTrue(actual.油量总量 == 4);
- Assert.IsTrue(actual.金额总量 == 5);
- Assert.IsTrue(actual.支付模式 == 6);
- }
- [TestMethod]
- public void AckPumpTransactionRequest_TestMethod1()
- {
- var msg = new AckPumpTransactionRequest(9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] { 0xFA, 0x01, 0xFF, 0x09,
- 0x02,
- 0x32, 0x00, 0x0F };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void ReadPumpAccumulatorResponse_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x30,
- //command code
- 0x33,
- //信息计数n
- 0x01,
- //枪号
- 0x03,
- //金额累计(带2位小数)
- 0x00,0x00,0x00,0x00,0x05,
- //油量累计(带2位小数)
- 0x00,0x00,0x00,0x09,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as ReadPumpAccumulatorResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.信息计数 == 1);
- Assert.IsTrue(actual.NozzleAndAccumulators != null);
- Assert.IsTrue(actual.NozzleAndAccumulators.Count == 1);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().枪号 == 3);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().金额累计 == 5);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().油量累计 == 9);
- }
- [TestMethod]
- public void ReadPumpAccumulatorResponse_TestMethod2()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x30,
- //command code
- 0x33,
- //信息计数n
- 0x02,
- //枪号
- 0x03,
- //金额累计(带2位小数)
- 0x00,0x00,0x00,0x00,0x05,
- //油量累计(带2位小数)
- 0x00,0x00,0x00,0x09,
- //枪号
- 0x04,
- //金额累计(带2位小数)
- 0x00,0x00,0x00,0x00,0x06,
- //油量累计(带2位小数)
- 0x00,0x00,0x00,0x07,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as ReadPumpAccumulatorResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.信息计数 == 2);
- Assert.IsTrue(actual.NozzleAndAccumulators != null);
- Assert.IsTrue(actual.NozzleAndAccumulators.Count == 2);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().枪号 == 3);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().金额累计 == 5);
- Assert.IsTrue(actual.NozzleAndAccumulators.First().油量累计 == 9);
- Assert.IsTrue(actual.NozzleAndAccumulators.Skip(1).First().枪号 == 4);
- Assert.IsTrue(actual.NozzleAndAccumulators.Skip(1).First().金额累计 == 6);
- Assert.IsTrue(actual.NozzleAndAccumulators.Skip(1).First().油量累计 == 7);
- }
- [TestMethod]
- public void ChangePumpPriceRequest_TestMethod1()
- {
- var msg = new ChangePumpPriceRequest(2, 9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x06,
- //有效数据
- 0x34, 0x01, 0x02,0x00,0x00,0x09,
- //数据校验
- 0x3B };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void ChangePumpPriceRequest_TestMethod2()
- {
- var msg = new ChangePumpPriceRequest(
- new[] {
- new NozzleAndPrice() {
- 枪号 = 4,
- 油价 = 6},
- new NozzleAndPrice() {
- 枪号 = 5,
- 油价 = 7},
- new NozzleAndPrice() {
- 枪号 = 6,
- 油价 = 8},
- });
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x0E,
- //有效数据
- 0x34, 0x03, 0x04,0x00,0x00,0x06, 0x05,0x00,0x00,0x07, 0x06,0x00,0x00,0x08,
- //数据校验
- 0x5E };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void StartPumpRequest_TestMethod1()
- {
- var msg = new StartPumpRequest(2, StartPumpRequest.PresetType.定金额加油, 9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x07,
- //有效数据
- 0x35, 0x02, 0x02, 0x00,0x00,0x00,0x09,
- //数据校验
- 0x3E };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void StartPumpRequest_TestMethod2()
- {
- var msg = new StartPumpRequest(2, StartPumpRequest.PresetType.定油量体积加油, 9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x07,
- //有效数据
- 0x35, 0x02, 0x01, 0x00,0x00,0x00,0x09,
- //数据校验
- 0x39 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void StartPumpRequest_TestMethod3()
- {
- var msg = new StartPumpRequest(2, StartPumpRequest.PresetType.随意加油, 9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x07,
- //有效数据
- 0x35, 0x02, 0x00, 0x00,0x00,0x00,0x09,
- //数据校验
- 0x38 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void DisplayInfoRequest_TestMethod1()
- {
- var msg = new DisplayInfoRequest(2, "000", "123");
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x09,
- //有效数据
- 0x37, 0x02, 0x30,0x30,0x30, 0x03, 0x31,0x32,0x33,
- //数据校验
- 0x0A };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void DisplayInfoRequest_TestMethod2()
- {
- var msg = new DisplayInfoRequest(9, "000", "12345");
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x0B,
- //有效数据
- 0x37, 0x09, 0x30,0x30,0x30, 0x05, 0x31,0x32,0x33,0x34,0x35,
- //数据校验
- 0x68 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void SetPumpConfigRequest_TestMethod1()
- {
- var msg = new SetPumpConfigRequest(SetPumpConfigRequest.ParameterTableTypeEnum.TableA,
- new[] {
- new NozzleConfig() {
- 枪号 = 9,
- 参数列表 = "12345"
- }
- });
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x09,
- //有效数据 参数列表A: 0x01 枪号1
- 0x52, 0x01, 0x01, 0x09, 0x31,0x32,0x33,0x34,0x35,
- //数据校验
- 0x1B };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void SetPumpConfigRequest_TestMethod2()
- {
- var msg = new SetPumpConfigRequest(SetPumpConfigRequest.ParameterTableTypeEnum.TableB,
- new[] {
- new NozzleConfig() {
- 枪号 = 9,
- 参数列表 = "23456"
- }
- });
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x09,
- //有效数据 参数列表A: 0x01 枪号1
- 0x52, 0x01, 0x02, 0x09, 0x32,0x33,0x34,0x35,0x36,
- //数据校验
- 0x1D };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void SetPumpConfigRequest_TestMethod3()
- {
- var msg = new SetPumpConfigRequest(SetPumpConfigRequest.ParameterTableTypeEnum.TableA,
- new[] {
- new NozzleConfig() {
- 枪号 = 7,
- 参数列表 = "12345"
- },
- new NozzleConfig() {
- 枪号 = 8,
- 参数列表 = "23456"
- }
- });
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x0F,
- //有效数据 参数列表A: 0x01 枪号1 枪号2
- 0x52, 0x01, 0x01, 0x07, 0x31,0x32,0x33,0x34,0x35, 0x08, 0x32,0x33,0x34,0x35,0x36,
- //数据校验
- 0x6A };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void AckSetPumpConfigResponse_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x02,
- //command code
- 0x52,
- //参数[0x01 +状态(1BIN)] 参数状态为0x00表示设置成功,其他表示失败
- 0x01, 0x00,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as AckSetPumpConfigResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FrameSeqNo == 0x01);
- Assert.IsTrue(actual.状态 == 0x00);
- }
- [TestMethod]
- public void AckSetPumpConfigResponse_TestMethod2()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x29,
- //length code
- 0x02,
- //command code
- 0x52,
- //参数[0x01 +状态(1BIN)] 参数状态为0x00表示设置成功,其他表示失败
- 0x01, 0x99,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as AckSetPumpConfigResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FrameSeqNo == 0x29);
- Assert.IsTrue(actual.状态 == 0x99);
- }
- [TestMethod]
- public void ReadPumpConfigRequest_TestMethod1()
- {
- var msg = new ReadPumpConfigRequest(SetPumpConfigRequest.ParameterTableTypeEnum.TableA, 9);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x04,
- //有效数据 参数[0x02+ 参数列表类型X(1BIN) + 枪数(1BCD)
- 0x52, 0x02, 0x01, 0x09,
- //数据校验
- 0x31 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void ReadPumpConfigRequest_TestMethod2()
- {
- var msg = new ReadPumpConfigRequest(SetPumpConfigRequest.ParameterTableTypeEnum.TableB, 4);
- msg.TargetAddress = 1;
- msg.SourceAddress = 0xFF;
- msg.FrameSeqNo = 3;
- var parser = new Parser();
- var actual = parser.Serialize(msg);
- var expect = new byte[] {
- //数据包头, 目标地址, 源地址, 帧号/控制
- 0xFA, 0x01, 0xFF, 0x03,
- //有效数据长度
- 0x04,
- //有效数据 参数[0x02+ 参数列表类型X(1BIN) + 枪数(1BCD)
- 0x52, 0x02, 0x02, 0x04,
- //数据校验
- 0x35 };
- Assert.AreEqual(true, ValueEquals(expect, actual), "the actual is: 0x" + actual.ToHexLogString());
- }
- [TestMethod]
- public void ReadPumpConfigResponse_TestMethod1()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x0A,
- //command code
- 0x52,
- //参数[0x02+ 参数列表类型X(1BIN) +枪数(1BCD)+ 枪号1(1BCD)+ 参数列表(5BCD)
- 0x02, 0x01, 0x01, 0x07, 0x31,0x32,0x33,0x34,0x35,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as ReadPumpConfigResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FrameSeqNo == 0x01);
- Assert.IsTrue(actual.参数列表类型 == SetPumpConfigRequest.ParameterTableTypeEnum.TableA);
- Assert.IsNotNull(actual.NozzleConfigs);
- Assert.IsTrue(actual.NozzleConfigs.Count == 1);
- Assert.IsTrue(actual.NozzleConfigs.First().枪号 == 7);
- Assert.IsTrue(actual.NozzleConfigs.First().参数列表 == "12345");
- }
- [TestMethod]
- public void ReadPumpConfigResponse_TestMethod2()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x01,
- //length code
- 0x10,
- //command code
- 0x52,
- //参数[0x02+ 参数列表类型X(1BIN) +枪数(1BCD)+ 枪号1(1BCD)+ 参数列表(5BCD)
- 0x02, 0x01, 0x01, 0x07, 0x31,0x32,0x33,0x34,0x35,
- //枪号2(1BCD)+ 参数列表(5BCD)
- 0x08, 0x32,0x33,0x34,0x35,0x36,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as ReadPumpConfigResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FrameSeqNo == 0x01);
- Assert.IsTrue(actual.参数列表类型 == SetPumpConfigRequest.ParameterTableTypeEnum.TableA);
- Assert.IsNotNull(actual.NozzleConfigs);
- Assert.IsTrue(actual.NozzleConfigs.Count == 2);
- Assert.IsTrue(actual.NozzleConfigs.First().枪号 == 7);
- Assert.IsTrue(actual.NozzleConfigs.First().参数列表 == "12345");
- Assert.IsTrue(actual.NozzleConfigs.Skip(1).First().枪号 == 8);
- Assert.IsTrue(actual.NozzleConfigs.Skip(1).First().参数列表 == "23456");
- }
- [TestMethod]
- public void ReadPumpConfigResponse_TestMethod3()
- {
- var raw = new byte[] {
- 0xFA, 0x01, 0xFF,
- // frameNo.
- 0x04,
- //length code
- 0x10,
- //command code
- 0x52,
- //参数[0x02+ 参数列表类型X(1BIN) +枪数(1BCD)+ 枪号1(1BCD)+ 参数列表(5BCD)
- 0x02, 0x02, 0x01, 0x10, 0x31,0x32,0x33,0x34,0x35,
- //枪号2(1BCD)+ 参数列表(5BCD)
- 0x18, 0x32,0x33,0x34,0x35,0x36,
- //checksum
- 0x00 };
- var parser = new Parser();
- var actual = parser.Deserialize(raw) as ReadPumpConfigResponse;
- Assert.IsNotNull(actual);
- Assert.IsTrue(actual.FrameSeqNo == 0x04);
- Assert.IsTrue(actual.参数列表类型 == SetPumpConfigRequest.ParameterTableTypeEnum.TableB);
- Assert.IsNotNull(actual.NozzleConfigs);
- Assert.IsTrue(actual.NozzleConfigs.Count == 2);
- Assert.IsTrue(actual.NozzleConfigs.First().枪号 == 10);
- Assert.IsTrue(actual.NozzleConfigs.First().参数列表 == "12345");
- Assert.IsTrue(actual.NozzleConfigs.Skip(1).First().枪号 == 18);
- Assert.IsTrue(actual.NozzleConfigs.Skip(1).First().参数列表 == "23456");
- }
- //from real site log
- [TestMethod]
- public void WildResponse_TestMethod1()
- {
- var raw = "FA E0 FF 10 0C 31 02 02 01 03 00 00 02 02 03 00 00 0A".ToBytes();
- var parser = new Parser();
- var actual = parser.Deserialize(raw);
- }
- }
- }
|