private void FixAndSaveResult(ArraySegment <byte> smgt, UdpPayloadCache outStream) { UdpSentence baseModel = null; try { if (UdpPanSpt.TryParse(smgt, out var sptModel)) { FixPANSPT(sptModel); baseModel = sptModel; } else if (UdpPanSsy.TryParse(smgt, out var ssyModel)) { FixPANSSY(ssyModel); baseModel = ssyModel; } else { OnlySaveResult(smgt, outStream); } if (baseModel != null) { SaveResult(baseModel.ToBytes(), outStream); } } catch { // ignored } }
public void TryParseUdpPanSptSentence() { var model = new UdpPanSpt() { SectorId = 33, TagsCount = 15, SectorStatus = SectorStatus.Ok }; var input = new ArraySegment <byte>(model.ToBytes()); var inputStr = Encoding.ASCII.GetString(model.ToBytes()); var inputStrOrigin = "$PANSPT,33,15,1*11\r\n"; var parsed = UdpPanSpt.TryParse(input, out var result); Assert.IsTrue(parsed, "UdpPanSpt was not parsed"); Assert.IsNotNull(result, "result is null"); Assert.AreEqual(model.SectorId, result.SectorId, "SectorId is not equal"); Assert.AreEqual(model.TagsCount, result.TagsCount, "TagsCount is not equal"); Assert.AreEqual(model.SectorStatus, result.SectorStatus, "TagsCount is not equal"); Assert.AreEqual(inputStrOrigin, inputStr, "Origin is not equal to str from model"); }