using skyscraper5.Skyscraper.IO.CrazycatStreamReader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.IO.StreamReader.RemoteStreamReaderServer
{
    internal class Test
    {
        public void Run()
        {
            LocalStreamReader localStreamReader = LocalStreamReader.GetInstance();
            if (!localStreamReader.CheckForDVB())
            {
                Console.WriteLine("no tuners!");
            }

            int? targetTuner = null;
            localStreamReader.CheckForDVBExEx((x, y, z) =>
            {
                if (y.Equals("TBS 6903x DVBS/S2 Tuner 0"))
                {
                    targetTuner = x;
                }
            });

            if (!targetTuner.HasValue)
            {
                Console.WriteLine("Didn't find the magic card.");
            }

            if (!localStreamReader.StartDvbEx(targetTuner.Value))
            {
                Console.WriteLine("could not start the card");
            }


            IntPtr blscan2SearchResults = Marshal.AllocHGlobal(128 * 1024);
            int tpNum = 0;

            BlScanCallback blScanCallback = (ref SearchResult result) =>
            {
                Console.WriteLine(result.Freq);
            };

            if (!localStreamReader.SendDiSEqC(2, (DiSEqC_Opcode)0xf2))
            {
                Console.WriteLine("diseqc failed");
            }

            if (!localStreamReader.BLScan2(10700000, 11700000, 0, 9750000, 10600000, 11700000, blscan2SearchResults, ref tpNum, blScanCallback))
            {
                Console.WriteLine("Failed BLScan2");
            }

            if (!localStreamReader.StopDVB())
            {
                Console.WriteLine("Stop DVB failed");
            }
        }
    }
}
