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;
            }
        }
    }

  • 相关阅读:
    JSE-1.1.4 内存屏障和CPU缓存
    Ajax
    R手册(Common)--R6 and S4
    掌握 小程序项目新建后的 初始代码 及 git远程管理(2)
    微信小程序 网课学习笔记 开发前的准备工作(1)
    vuex中action如何互相调用
    ajax请求时,请求路径自动拼上页面路径?
    10个免费的CDN
    java面向对象
    java中方法的递归调用
  • 原文地址:https://www.cnblogs.com/sung/p/2651086.html
Copyright © 2011-2022 走看看