Exemplo n.º 1
0
 public DataInfo Clone()
 {
     DataInfo /*clone (returned)*/ cln =
             new DataInfo(LineData.Length, XRayInfo, NumberOfBytesPerPixel);
     Debug.Assert(cln.NumberOfBytesPerPixel == NumberOfBytesPerPixel);
     for (int /*pixel index*/ ix = 0; ix < LineData.Length; ix++)
         if (LineData[ix] != null)
             cln.LineData[ix] = new Pixel(LineData[ix].Value);
         else
             Debug.Assert(cln.LineData[ix] == null);
     Debug.Assert(cln.TotalBytesReceived == 0);
     return cln;
 }
Exemplo n.º 2
0
 public void AddDataLine(ref DataInfo dataInfo) { IncomingData.TryAdd(dataInfo, AppConfiguration.DataLineProcessTimeout); }
Exemplo n.º 3
0
        private void DataHarvest(byte[] rawData, ref Dictionary<uint, AllLineData> stagedLines, int ncbIndex)
        {
#if false
            ushort StartNumOfDetectors = BitConverter.ToUInt16(rawData, 4);
            if (ncbIndex == 0 && StartNumOfDetectors == 0)
            {
                Array.Reverse(rawData, 0, 4);
                CurrentLineId = BitConverter.ToUInt32(rawData, 0);
            }
#endif

            // Decode the data into a header.
            DataPacketHeader packetHeader = new DataPacketHeader();
            packetHeader = packetHeader.Deserialize(rawData);

            //bUInt32 currLineId = packetHeader.LineID;

            if (ncbIndex == 0 && packetHeader.StartNumOfDetectors == 0)
                CurrentLineId = packetHeader.LineID; /*currLineId*/

            //Logger.LogInfo(String.Format("NCB Index = {0}, Start Num = {1}, End Num = {2}", (int)ncbIndex, packetHeader.StartNumOfDetectors, packetHeader.EndNumOfDetectors));

            if (SourcesSynchronized)
            {
                if (!stagedLines.ContainsKey(packetHeader.LineID))
                {
                    DataInfo[] lineArr = new DataInfo[NCBCount];

                    AllLineData allData = new AllLineData();

                    allData.LineID = packetHeader.LineID;
                    allData.LineTimeStamp = DateTime.UtcNow.Ticks;
                    allData.DataComplete = new bool[NCBCount];
                    allData.BytesRecieved = new int[NCBCount];
                    allData.NCBData = lineArr;

                    for (int ix = 0; ix < NCBCount; ix++)
                    {
                        lineArr[ix] = new DataInfo(_ncbChannelCount[ix], packetHeader.EnergyAndPulsewidth, (byte)ImageBytesPerPixel);
                        allData.DataComplete[ix] = false;
                    }

                    stagedLines.Add(packetHeader.LineID, allData);
                }

                DataInfo currentNCBDataLine = stagedLines[packetHeader.LineID].NCBData[ncbIndex];
                int size = (int)((packetHeader.EndNumOfDetectors - packetHeader.StartNumOfDetectors + 1) * packetHeader.NumBytesPerPixel);
                int linePixelIndex = packetHeader.StartNumOfDetectors;

                //if(linePixelIndex == 2336)
                //      Logger.LogInfo(String.Format("NCB Index = {0}, Line Id = {1}, LinePixelIndex = {2}, Start Num = {3}, End Num = {4}", (int)ncbIndex, CurrentLineId, linePixelIndex, packetHeader.StartNumOfDetectors, packetHeader.EndNumOfDetectors));

                for (int index = 0; index < size; index += packetHeader.NumBytesPerPixel)
                {
                    if (currentNCBDataLine.LineData[linePixelIndex] == null)
                    {
                        currentNCBDataLine.TotalBytesReceived += packetHeader.NumBytesPerPixel;
                        currentNCBDataLine.LineData[linePixelIndex] = PixelConverter.BytesToPixel(packetHeader.ChData, index, _bytesPerPixel);
                        int offset = 8 * (_bytesPerPixel - (int)_imageBytesPerPixel);
                        currentNCBDataLine.LineData[linePixelIndex].Value = currentNCBDataLine.LineData[linePixelIndex++].Value >> offset;
                    }
                }

                stagedLines[packetHeader.LineID].BytesRecieved[ncbIndex] = currentNCBDataLine.TotalBytesReceived;

                //if (linePixelIndex == 2336)
                //    Logger.LogInfo(String.Format("Data Complete for Line Id = {0}", CurrentLineId));

                if ((currentNCBDataLine.TotalBytesReceived / packetHeader.NumBytesPerPixel) >= (_ncbChannelCount[ncbIndex]))
                {
                    stagedLines[packetHeader.LineID].DataComplete[ncbIndex] = true;

                    bool IsLineComplete = true;

                    for (int i = 0; i < NCBCount; i++)
                    {
                        IsLineComplete &= stagedLines[packetHeader.LineID].DataComplete[i];
                    }

                    if (IsLineComplete)
                    {
                        DataInfo currentDataLine = new DataInfo(PixelsPerColumn, currentNCBDataLine.XRayInfo, currentNCBDataLine.NumberOfBytesPerPixel);

                        linePixelIndex = 0;

                        for (int i = 0; i < NCBCount; i++)
                        {
                            for (int index = 0; index < stagedLines[packetHeader.LineID].NCBData[i].LineData.Length; index++)
                            {
                                if (i == 0)
                                {
                                    if (index == ReferenceSensorCount)
                                        index += ReferenceSensorCount;
                                }
                                else
                                {
                                    if (index == 0)
                                        index += ReferenceSensorCount;
                                }

                                currentDataLine.LineData[linePixelIndex] = stagedLines[packetHeader.LineID].NCBData[i].LineData[index];
                                linePixelIndex++;
                            }

                            stagedLines[packetHeader.LineID].NCBData[i].Dispose();
                        }

                        //add this line to the data collection
                        _rawDataCollection.TryAdd(currentDataLine, 500);

                        stagedLines.Remove(packetHeader.LineID);
                        DataGatherTrace--;
                    }

                    List<uint> keysToRemove = new List<uint>();

                    foreach (KeyValuePair<uint, AllLineData> aLine in stagedLines)
                    {
                        //Check if the line is not complete in 200,000 (20 ms - unit is 100 ns)
                        if (DateTime.UtcNow.Ticks > aLine.Value.LineTimeStamp + 500000)
                        {
                            keysToRemove.Add(aLine.Key);
                        }
                    }

                    //                    foreach (KeyValuePair<uint, AllLineData> aLine in stagedLines)

                    String removedLineIndices = "Removing old line index: ";

                    foreach (uint key in keysToRemove)
                    {
                        //Logger.LogInfo(String.Format("Removing old line index: {0}, Bytes Received = {1},{2}", identity, 
                        //                               stagedLines[identity].NCBData[0].TotalBytesReceived, 
                        //                               stagedLines[identity].NCBData[1].TotalBytesReceived));
                        removedLineIndices += String.Format("{0}, ", key);

                        for (int i = 0; i < NCBCount; i++)
                        {
                            stagedLines[key].NCBData[i].Dispose();
                        }

                        stagedLines.Remove(key);
                    }

                    if (keysToRemove.Count > 0)
                    {
                        //bLogger.LogInfo(removedLineIndices);
                        keysToRemove.Clear();
                    }
                }
            }
        }