using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CPF;
using System.Text;
using Microsoft.SPOT;
using System.Threading;
using HWModules;
using SWModules;

namespace CPFUnitTests
{
    [TestClass]
    public class UnitTestIridiumCSQPolling
    {

        /// <summary>
        /// Test zmodem send using the bluetooth serial port, but plug it into a linux tty login.
        /// if no login is provided, the attempt should fail gracefully. 
        /// </summary>
        /// 
       
        private static int utcount;
        [TestMethod]
        public void TestIridium_BidirectionalTransfer()
        {
            Init();
            int resp = 0;
            bool carrier = false;

            //Connect

            Thread.Sleep(1000); // enough time for the cbst message to come in
            imodem.sendNoEcho();
            Thread.Sleep(1000); // enough time for the cbst message to come in
            imodem.SelectBearerServiceType(NAL_A3LAR.CallSpeed.BPS9600V110);
            Thread.Sleep(1000); // enough time for the cbst message to come in
            var btOn = false;
            var btOnOff = 8;
            var btct = 0;

            if (btOn)
            {
                mother.EnableChannelPower(MotherBoard.ChannelNames.BluetoothChannel);
                var bt = BTConsole.Instance;
                bt.init();

                EngrLogger.SendConsoleLine += bt.SendLine;
            }
            else
                mother.DisableChannelPower(MotherBoard.ChannelNames.BluetoothChannel);
            while (true)
            {
                if (btOn)
                    Debug.Print("BTON");
                else
                    Debug.Print("BTOFF");

                imodem.sendCSQ();
                Thread.Sleep(10000); // enough time for the cbst message to come in
                mother.ToggleDebugLED();
                messageQueue.processQMaxLimit();
            }
        }


        private static MessageQueue messageQueue;
        private static IridiumModem1 imodem;
        private static MotherBoard mother;

        static bool runonce = false;
        public void Init()
        {
            if (!runonce)
            {
                imodem = IridiumModem1.Instance;
                mother = MotherBoard.Instance;
                mother.EnableChannelPower(MotherBoard.ChannelNames.IridiumChannel);
                messageQueue = MessageQueue.Instance;
                runonce = true;
                EngrLogger.Comment("Initializing Iridium Modem");
                imodem.simpleInit();
                imodem.powerUp();
            }
        }
    }
}
