Exemplo n.º 1
0
 public int CompareTo(object obj)
 {
     if (obj is ValueCount)
     {
         ValueCount c = obj as ValueCount;
         return(this.value.CompareTo(c.value));
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 2
0
        //阻尼器振动的频谱UDP报文
        public void frequencyspectrum(String[] data)
        {
            int sid = Convert.ToInt32(data[1]);

            if (!dataDic.ContainsKey(sid))
            {
                dataDic[sid] = new List <ValueCount>();
            }


            List <ValueCount> VCdata = new List <ValueCount>();

            for (int i = 3; i < data.Length - 1; i += 2)
            {
                //转换频率
                var value = (Convert.ToDouble(data[i]) * 25) / 2048.0;
                //10.5Hz以上的的频率,不计入计算范围
                if (value < fout)
                {
                    ValueCount valueCount = new ValueCount(value, Convert.ToInt32(data[i + 1]));
                    VCdata.Add(valueCount);
                }
            }
            var cc = VCdata.OrderByDescending(x => x.count).Take(fcount);

            lock (dataDic)//锁
            {
                dataDic[sid].AddRange(cc);

                if (dataDic[sid].Count >= zcount * fcount)
                {
                    var res = algorithm(dataDic[sid], sid);
                    dataDic[sid].RemoveRange(0, fcount);
                    SendFrequencySpectrum(res, sid);
                }
            }
        }