Example #1
0
 private void OnDataReady(Waterfall fall, WaterfallTile tile)
 {
     if (DataReady != null)
     {
         DataReady(fall, tile);
     }
 }
Example #2
0
        private WaterfallTile GenerateTestDataTile()
        {
            WaterfallTile tile = new WaterfallTile();

            tile.Timecode       = test_timecode++;
            tile.FirstPixelFreq = 14.0;
            tile.BinBandwidth   = (0.2 / _width);
            tile.LineDurationMS = 100;
            tile.Width          = (ushort)(_width * 1.2);
            tile.Height         = 1;

            tile.Data = new ushort[tile.Width * tile.Height];

            for (int i = 0; i < tile.Width * tile.Height; i++)
            {
                if (i >= 57 && i <= 60)
                {
                    tile.Data[i] = (ushort)test_random.Next(13000, 50000);
                }
                else
                {
                    tile.Data[i] = (ushort)test_random.Next(13000, 16000);
                }
                //tile.Data[i] = (ushort)(i * 35);
            }

            return(tile);
        }
Example #3
0
 private void RunTestData()
 {
     while (_radio != null)
     {
         WaterfallTile tile = GenerateTestDataTile();
         OnDataReady(this, tile);
         Thread.Sleep((int)tile.LineDurationMS);
     }
 }
Example #4
0
        // Adds a tile from the radio
        internal void AddData(WaterfallTile tile, int packet_count)
        {
            //ushort min = ushort.MaxValue;
            //int min_bin = 0;
            //ushort max = ushort.MinValue;
            //int max_bin = 0;

            //for (int i = 0; i < tile.Data.Length; i++)
            //{
            //    if (tile.Data[i] < min)
            //    {
            //        min = tile.Data[i];
            //        min_bin = i;
            //        if (min == 0)
            //        {
            //            int breaker = 0;
            //        }
            //    }

            //    if (tile.Data[i] > max)
            //    {
            //        max = tile.Data[i];
            //        max_bin = i;
            //    }
            //}

            //Debug.WriteLine("WaterfallTile auto_black: " + tile.AutoBlackLevel + "  min("+min_bin.ToString().PadLeft(4, ' ')+"): "+min + "  delta: " + (min - tile.AutoBlackLevel) + "  max("+max_bin.ToString().PadLeft(4, ' ')+"): " + max);

            //tile.DateTime = DateTime.UtcNow;
            OnDataReady(this, tile);

            FallPacketTotalCount++;
            //normal case -- this is the next packet we are looking for, or it is the first one
            if (packet_count == (last_packet_count + 1) % 16 || last_packet_count == -1)
            {
                // do nothing
            }
            else
            {
                Debug.WriteLine("Fall Packet[0x" + _stream_id.ToString("X") + "]: Expected " + ((last_packet_count + 1) % 16) + "  got " + packet_count);
                FallPacketErrorCount++;
            }
            last_packet_count = packet_count;
        }
        unsafe public VitaWaterfallPacket(byte[] data)
        {
            int  index = 0;
            uint temp  = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));

            index += 4;

            header              = new Header();
            header.pkt_type     = (VitaPacketType)(temp >> 28);
            header.c            = ((temp & 0x08000000) != 0);
            header.t            = ((temp & 0x04000000) != 0);
            header.tsi          = (VitaTimeStampIntegerType)((temp >> 22) & 0x03);
            header.tsf          = (VitaTimeStampFractionalType)((temp >> 20) & 0x03);
            header.packet_count = (byte)((temp >> 16) & 0x0F);
            header.packet_size  = (ushort)(temp & 0xFFFF);

            // if packet is a type with a stream id, read/save it
            if (header.pkt_type == VitaPacketType.IFDataWithStream ||
                header.pkt_type == VitaPacketType.ExtDataWithStream)
            {
                stream_id = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));
                index    += 4;
            }

            if (header.c)
            {
                temp         = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));
                index       += 4;
                class_id.OUI = temp & 0x00FFFFFF;

                temp   = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));
                index += 4;
                class_id.InformationClassCode = (ushort)(temp >> 16);
                class_id.PacketClassCode      = (ushort)temp;
            }

            if (header.tsi != VitaTimeStampIntegerType.None)
            {
                timestamp_int = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));
                index        += 4;
            }

            if (header.tsf != VitaTimeStampFractionalType.None)
            {
                timestamp_frac = ByteOrder.SwapBytes(BitConverter.ToUInt64(data, index));
                index         += 8;
            }

            // allocate the waterfall tile
            tile          = new WaterfallTile();
            tile.DateTime = DateTime.UtcNow;

            // populate the fields of the tile
            Array.Reverse(data, index, 8);
            tile.FirstPixelFreq = BitConverter.ToInt64(data, index);
            index += 8;

            Array.Reverse(data, index, 8);
            tile.BinBandwidth = BitConverter.ToInt64(data, index);
            index            += 8;

            Array.Reverse(data, index, 4);
            tile.LineDurationMS = BitConverter.ToUInt32(data, index);
            index += 4;

            Array.Reverse(data, index, 2);
            tile.Width = BitConverter.ToUInt16(data, index);
            index     += 2;

            Array.Reverse(data, index, 2);
            tile.Height = BitConverter.ToUInt16(data, index);
            index      += 2;

            Array.Reverse(data, index, 4);
            tile.Timecode = BitConverter.ToUInt32(data, index);
            index        += 4;

            Array.Reverse(data, index, 4);
            tile.AutoBlackLevel = BitConverter.ToUInt32(data, index);
            index += 4;

            int payload_bytes = (header.packet_size - 1) * 4; // -1 for header

            switch (header.pkt_type)
            {
            case VitaPacketType.IFDataWithStream:
            case VitaPacketType.ExtDataWithStream:
                payload_bytes -= 4;
                break;
            }

            if (header.c)
            {
                payload_bytes -= 8;
            }
            if (header.tsi != VitaTimeStampIntegerType.None)
            {
                payload_bytes -= 4;
            }
            if (header.tsf != VitaTimeStampFractionalType.None)
            {
                payload_bytes -= 8;
            }
            if (header.t)
            {
                payload_bytes -= 4;
            }

            payload_bytes -= 32; // payload header

            // Data.Length is the number of elements in the ushort Data array
            // and can be sent between multiple packets
            // ushort is 2 bytes

            // Debug.Assert(payload_bytes == tile.Data.Length * sizeof(ushort)); // Fails on resize ?

            // swap the bytes of the payload data
            for (int i = 0; i < tile.Data.Length; i++)
            {
                try
                {
                    Array.Reverse(data, index + i * 2, 2);
                }
                catch (Exception ex)
                {
                    Debug.Print("Exception!!!!! " + ex.ToString());
                }
            }

            //Array.Copy(data, index, payload, 0, payload_bytes);
            if (tile.Data.Length * 2 < payload_bytes)
            {
                payload_bytes = tile.Data.Length * 2;
            }

            try
            {
                Buffer.BlockCopy(data, index, tile.Data, 0, payload_bytes);
            }
            catch
            {
                Debug.WriteLine("BLOCKCOPY EXCPTION!!! tile.Data.Length: " + tile.Data.Length + " payload_bytes: " + payload_bytes + " tile.Data.Length*2= " + tile.Data.Length * 2);
            }

            index += payload_bytes;

            if (header.t)
            {
                temp = ByteOrder.SwapBytes(BitConverter.ToUInt32(data, index));
                trailer.CalibratedTimeEnable    = (temp & 0x80000000) != 0;
                trailer.ValidDataEnable         = (temp & 0x40000000) != 0;
                trailer.ReferenceLockEnable     = (temp & 0x20000000) != 0;
                trailer.AGCMGCEnable            = (temp & 0x10000000) != 0;
                trailer.DetectedSignalEnable    = (temp & 0x08000000) != 0;
                trailer.SpectralInversionEnable = (temp & 0x04000000) != 0;
                trailer.OverrangeEnable         = (temp & 0x02000000) != 0;
                trailer.SampleLossEnable        = (temp & 0x01000000) != 0;

                trailer.CalibratedTimeIndicator    = (temp & 0x00080000) != 0;
                trailer.ValidDataIndicator         = (temp & 0x00040000) != 0;
                trailer.ReferenceLockIndicator     = (temp & 0x00020000) != 0;
                trailer.AGCMGCIndicator            = (temp & 0x00010000) != 0;
                trailer.DetectedSignalIndicator    = (temp & 0x00008000) != 0;
                trailer.SpectralInversionIndicator = (temp & 0x00004000) != 0;
                trailer.OverrangeIndicator         = (temp & 0x00002000) != 0;
                trailer.SampleLossIndicator        = (temp & 0x00001000) != 0;

                trailer.e = (temp & 0x80) != 0;
                trailer.AssociatedContextPacketCount = (byte)(temp & 0xEF);
            }
        }