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 GetSentenceType() { var panspt = new ArraySegment <byte>(Encoding.ASCII.GetBytes("$PANSPT,33,15,1*11\r\n")); var panssy = new ArraySegment <byte>(Encoding.ASCII.GetBytes("$PANSSY,0,2,1,1,10,2,0*2B\r\n")); var panWrong = new ArraySegment <byte>(Encoding.ASCII.GetBytes("$PANXXX,0*2B\r\n")); Assert.AreEqual(UdpSentenceType.PANSPT, UdpSentence.GetSentenceType(panspt), "PANSPT is not recognized"); Assert.AreEqual(UdpSentenceType.PANSSY, UdpSentence.GetSentenceType(panssy), "PANSSY is not recognized"); Assert.AreEqual(UdpSentenceType.Undefined, UdpSentence.GetSentenceType(panWrong), "Wrong is not recognized"); }