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
            }
        }
Exemple #2
0
        public void FixPANSPTModel()
        {
            var model = new UdpPanSpt()
            {
                SectorId     = 33,
                TagsCount    = 1,
                SectorStatus = SectorStatus.Mulfunction
            };
            var service = new UdpRepairService(_dbCache);

            service.FixPANSPT(model);

            Assert.AreEqual(33, model.SectorId);
            Assert.AreEqual(2, model.TagsCount);
            Assert.AreEqual(SectorStatus.Mulfunction, model.SectorStatus);
        }
        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");
        }
 public void FixPANSPT(UdpPanSpt model)
 {
     model.TagsCount = _dbCache.GetSectorTagsAmount(model.SectorId);
 }