zoukankan      html  css  js  c++  java
  • impinj固定式阅读器数据解析中Rfid筛选器实现

    在做物联网仓库管理中用到RFID标签进行盘点和出库扫描检查,其中在仓库门口的impinj固定式阅读器对进出的货物进行检测,在读取rfid时候需要对epc标签进行过滤,实现2个过滤器,第一个是正则过滤,第二个是时间,在60秒内只读取一次,默认tag是一秒读200次,下面是过滤器的实现:输入

    dataSource--tag信息类

    device---设备配置类(包含读取时间和过滤条件的xml,在最后)

           

           

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using log4net;
    using Org.LLRP.LTK.LLRPV1;
    using Org.LLRP.LTK.LLRPV1.DataType;
    using Org.LLRP.LTK.LLRPV1.Impinj;
    using System.Collections.Concurrent;
    using System.Diagnostics;
    using System.Collections.ObjectModel;
    using com.dn.Edgenode.Plugins.Data;
    using com.dn.Edgenode.Plugins.Rfid.Impinj;
    using com.dn.Edgenode.Plugins.Rfid.Impinj.Config;
    using System.Text.RegularExpressions;

    namespace Data
    {
        public class TagFilter : Filter<NormalizedData>
        {
            private static ILog log = log4net.LogManager.GetLogger("com.dn.Edgenode.Log.Engine.Plugin");
            private Dictionary<string, DateTime> tagGroupTimeDic = new Dictionary<string, DateTime>();
            public object device{ get; set; }

            public override Func<NormalizedData, bool> Condition
            {
                get
                {
                    return FilterEpcByConf;
                }
                set
                {
                    throw new NotImplementedException();
                }
            }

            private bool FilterEpcByConf(NormalizedData dataSource)
            {
                ReaderSite rs = this.device as ReaderSite;
                TagData tag = dataSource as TagData;
                string epc = tag.Data["Epc"].ToString();
                bool re = false;

                #region Fiter by Regex rule
                try
                {
                    if (!string.IsNullOrEmpty(rs.ReaderCfg.filter.rule.Value) && rs.ReaderCfg.filter.rule.operation != null)
                    {
                        if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.Submit)
                        {
                            if (!Regex.IsMatch(epc, rs.ReaderCfg.filter.rule.Value))
                            {
                                return false;
                            }
                            else
                            {
                                //do nothing
                            }
                        }
                        else if (rs.ReaderCfg.filter.rule.operation == readerCfgFilterRuleOperation.None)
                        {
                            if (Regex.IsMatch(epc, rs.ReaderCfg.filter.rule.Value))
                            {
                                return false;
                            }
                            else
                            {
                                //do nothing
                            }
                        }
                    }
                }
                catch(Exception ex)
                {
                    log.ErrorFormat("FilterEpcByConf: do fiter by rule error: {0}", ex.Message);
                }
                #endregion

                #region Fiter by Time
                try
                {
                    string[] epcGroup = null;
                    int readingTimeout = 0;
                    //epc not in config ,Submit datas
                    foreach (readerCfgTagGroup rg in rs.ReaderCfg.tagGroups)
                    {
                        if (rg.Enabled == true && rg.Value.Contains(epc))
                        {
                            epcGroup = rg.Value.Split(';');
                            readingTimeout = rg.readingTimeout;
                            break;
                        }
                    }
                    //epc not in config or this tag's tagGroup is disanable ,Submit data
                    if (epcGroup == null || epcGroup.Length == 0)
                    {
                        return true;
                    }

                    if (!tagGroupTimeDic.ContainsKey(epc))
                    {
                        //Submit data
                        re = true;
                        tagGroupTimeDic.Add(epc, DateTime.Now);

                    }
                    else
                    {
                        DateTime dtNow = DateTime.Now;
                        DateTime epcTime = tagGroupTimeDic[epc];
                        //find max time
                        foreach (string epcItem in epcGroup)
                        {
                            if (tagGroupTimeDic.ContainsKey(epcItem))
                            {
                                epcTime = tagGroupTimeDic[epcItem] < epcTime ? tagGroupTimeDic[epcItem] : epcTime;
                            }
                        }
                        //check time
                        if (dtNow.Subtract(epcTime).TotalMilliseconds > readingTimeout)
                        {
                            re = true;
                            foreach (string epcItem in epcGroup)
                            {
                                if (tagGroupTimeDic.ContainsKey(epcItem))
                                {
                                    tagGroupTimeDic.Remove(epcItem);
                                }
                            }
                            tagGroupTimeDic[epc] = dtNow;
                        }
                        else
                        {
                            //do nothing
                            re = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("FilterEpcByConf: do fiter by rule error: {0}", ex.Message);
                }
                #endregion

                return re;
            }
        }
    }

  • 相关阅读:
    PHP 动态执行
    jenkins 'cordova' command not recognised on Jenkins Windows slave
    ionic3 实现扫码功能
    解决ionic3 android 运行出现Application Error
    解决添加codova plugin 编译出现问题:Execution failed for task ':processDebugManifest'.
    菜鸟的 Sass 学习笔记
    解决关于ios访问相机闪退问题
    解决ios关于:ERROR Internal navigation rejected
    Angular4 组件通讯方法大全
    ASP.NET MVC5 使用MiniProfiler 监控MVC性能
  • 原文地址:https://www.cnblogs.com/sung/p/2651086.html
Copyright © 2011-2022 走看看