using System.Runtime.InteropServices;

namespace skyscraper5.Skyscraper.IO.CrazycatStreamReader
{
    /// <summary>
    /// DVB-S / DVB-S2 / DVB-S2X Tuning data
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct SearchResult
    {
        /// <summary>
        /// Whether a valid signal is present.
        /// </summary>
        public bool Lock;

        /// <summary>
        /// Frequency (Khz)
        /// </summary>
        public int Freq;

        /// <summary>
        /// Polarization
        /// </summary>
        public int Pol;

        /// <summary>
        /// Symbol rate (Sym)
        /// </summary>
        public int SR;

        /// <summary>
        /// Tracking standard
        /// </summary>
        public int StdType;

        /// <summary>
        /// Modulation type
        /// </summary>
        public int ModType;

        public VITERBIRATE_TYPE FEC;

        /// <summary>
        /// Spectral inversion
        /// </summary>
        public int Inversion;

        public int RollOff;

        /// <summary>
        /// Pilot (DVB-S2 only)
        /// </summary>
        public int Pilot;

        /// <summary>
        /// Frame type (DVB-S2 only)
        /// </summary>
        public int Frame;

        /// <summary>
        /// Coding modulation (DVB-S2 only)
        /// </summary>
        public int CodingType;

        /// <summary>
        /// Stream type (DVB-S2 only)
        /// </summary>
        public int StreamType;

        /// <summary>
        /// Multiple Input Streams number. 0 - Single stream, 1-16 - Multiple streams
        /// </summary>
        public int MIS;

        /// <summary>
        /// // Input Streams IDs (DVB-S2 only)
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] IS;

        /// <summary>
        /// Input Stream Synchronisation
        /// </summary>
        public byte ISSYI;

        /// <summary>
        /// Null Packet Deletion
        /// </summary>
        public byte NPD;

        /// <summary>
        /// Physical Layer Scrambling code
        /// </summary>
        public int PLS;

        /// <summary>
        /// Carrier width (Khz)
        /// </summary>
        public int CW;

        // /// <summary>
        // /// BitRate (bit/s)
        // /// </summary>
        //public int BitRate;

        /// <summary>
        /// RF level (dBm, from -100 to 0)
        /// </summary>
        public int RFLevel;

        /// <summary>
        /// Signal/Noise rate (dB)
        /// </summary>
        public double SNR;

        /// <summary>
        /// Bit Error Rate (post FEC)
        /// </summary>
        public double BER;

        /// <summary>
        /// Bit Error Rate (pre FEC)
        /// </summary>
        public double preBER;
    }

    /// <summary>
    /// DVB-S2 specific tuning data
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct S2Mode
    {
        public S2MODCODE modcode;
        public bool pilot;
        public int frameLen;
    }

    /// <summary>
    /// DVB-T2 / DVB-C Tuning data.
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct SearchResult2
    {
        /// <summary>
        /// Whether the tuning is valid. If this is false, there is no channel.
        /// </summary>
        public bool Lock;

        /// <summary>
        /// Frequency (Khz)
        /// </summary>
        public int Freq;

        /// <summary>
        /// Band width (Khz)
        /// </summary>
        public int BW;

        /// <summary>
        /// Symbol rate (Sym)
        /// </summary>
        public int SR;

        /// <summary>
        /// Tracking standard
        /// </summary>
        public int StdType;

        /// <summary>
        /// Modulation type
        /// </summary>
        public int ModType;

        public int FEC;
        public int FECLP;

        /// <summary>
        /// Spectral inversion
        /// </summary>
        public int Inversion;

        /// <summary>
        /// Transmission mode
        /// </summary>
        public int TransMode;

        /// <summary>
        /// Guard interval	
        /// </summary>
        public int Guard;

        public int Hierarchy;

        /// <summary>
        /// Number of elements in the LID array.
        /// </summary>
        public int PLP;

        /// <summary>
        /// ID's of the physical layer pipes.
        /// </summary>
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] LID;

        /// <summary>
        /// Pilot Patern (DVB-T2 only)
        /// </summary>
        public int Pilot;

        /// <summary>
        /// S1 Signaling (DVB-T2 only)
        /// </summary>
        public int S1Type;

        /// <summary>
        /// Payload (DVB-T2/C2 only)
        /// </summary>
        public int Payload;

        /// <summary>
        /// Frame type (DVB-T2 only)
        /// </summary>
        public int Frame;

        /// <summary>
        /// Bw Extended (DVB-T2 only)
        /// </summary>
        public int BwExt;

        /// <summary>
        /// DVB-T2 mode (Base or Lite)
        /// </summary>
        public int ModeT2;

        /// <summary>
        /// DVB-T2 version
        /// </summary>
        public int VerT2;

        /// <summary>
        /// Cell ID (DVB-T/T2)
        /// </summary>
        public int CellID;

        /// <summary>
        /// System/Net ID (DVB-T2)
        /// </summary>
        public int NetID;

        /// <summary>
        /// BitRate (bit/s)
        /// </summary>
        public int BitRate;

        /// <summary>
        /// RF level (dBm, from -100 to 0)
        /// </summary>
        public int RFLevel;

        /// <summary>
        /// Signal/Noise rate (dB)
        /// </summary>
        public double SNR;

        /// <summary>
        /// Bit Error Rate (after FEC)
        /// </summary>
        public double BER;

        /// <summary>
        /// Bit Error Rate (before FEC)
        /// </summary>
        public double preBER;
    }

}
