Esempio n. 1
0
        private DaqData ProcessPacket(List <DaqDataPacket> packets, DaqDataPacket packet)
        {
            DaqData result = null;

            if (packet.DataType == DaqDataType.DAQ_DATA)
            {
                packets.Add(packet);
                if (lastGaps != null && packets.Count == PacketCountFor1Sec)
                {
                    result = PopAndProcessAsyncPackets(packets);
                }
            }
            else if (packet.DataType == DaqDataType.GAP_DATA)
            {
                if (lastGaps == null)
                {
                    //연결 후 처음 gap 받은 시점(이전의 DAQ_DATA는 미완성 데이타)
                    packets.Clear();
                }

                var gapAndRpm = packet.ToWords();
                lastGaps = gapAndRpm.Take(8).Select(w => ConvertGap(w)).ToArray();
                lastRpm1 = ConvertRpm(packet.Bytes, 16);
                lastRpm2 = ConvertRpm(packet.Bytes, 20);
            }
            return(result);
        }
Esempio n. 2
0
        public DaqData FetchData()
        {
            List <DaqDataPacket> packets = new List <DaqDataPacket>();
            DaqData result = null;

            while (result == null)
            {
                var packet = DaqDataPacket.RecvDataPacket(this, qs, "fetch", trace);
                result = ProcessPacket(packets, packet);
            }
            return(result);
        }
Esempio n. 3
0
        private DaqData PopAndProcessAsyncPackets(List <DaqDataPacket> packets)
        {
            var now = DateTime.UtcNow;

            trace.Send("PopAndProcessAsyncPackets");
            trace.Send("Elapsed - " + (now - lastProcessTime).TotalMilliseconds + " miliseconds");

            DaqData data = new DaqData();

            //var gapAndRpm = packet.ToWords();
            //data.ChannelsGap = gapAndRpm.Take(8).Select(w => ConvertGap(w)).ToArray();
            //data.Rpm1 = ConvertRpm(packet.Bytes, 16);
            //data.Rpm2 = ConvertRpm(packet.Bytes, 20);
            data.ChannelsGap = lastGaps;
            data.Rpm1        = lastRpm1;
            data.Rpm2        = lastRpm2;

            var totalDataCount = packets.Sum(p => p.Bytes.Length) / 2;  //byte니까 2로 나눔
            var iCurDataIndex  = 0;

            for (int iPacket = 0; iPacket < packets.Count; iPacket++)
            {
                var interleaved = packets[iPacket].ToShorts();

                for (int iCh = 0; iCh < 8; iCh++)
                {
                    if (data.ChannelsAsyncs[iCh] == null)
                    {
                        data.ChannelsAsyncs[iCh] = new float[totalDataCount / 8];
                    }

                    for (int i = 0; i < interleaved.Length / 8; i++)
                    {
                        data.ChannelsAsyncs[iCh][iCurDataIndex + i] = ConvertAsync(interleaved[i * 8 + iCh], iCh);
                    }
                }

                iCurDataIndex += interleaved.Length / 8;
            }

            lastProcessTime = now;
            return(data);
        }