using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;


namespace CPF
{
    public static class InstrumentHandler
    {

        public static Timer instrumentTimer = new Timer(new TimerCallback(instrumentTimerCallback), null, -1, -1);

        private static StringBuilder SI = new StringBuilder("Sampling Instruments");
        private static StringBuilder sbTemp = new StringBuilder(256);

        private static StructQueue.qStruct qS = new StructQueue.qStruct();

        public static void init()
        {
            qS.byteArray = new byte[StructQueue.byteArrayWidth];
        }

        public static void sampleInstruments(int stationNum)
        {
            //TODO: Eventually need to sample the instruments per the mission config file

            sbTemp.Clear();
            sbTemp.Append("Sampling Instruments");
            EngrLogger.writeToColumns(sbTemp);

            Optode.doSample();
            FLBB.sendRunCmd();
            //Don't take a PTS sample in ascend mode because SBE41 is in CP mode
            if ((Program.CurrentState == Program.CPFStates.descend) || (Program.CurrentState == Program.CPFStates.anchor) || (Program.CurrentState == Program.CPFStates.deAnchor))
            {
                SBE41.sbe41SamplePTS = true;
            }
        }

        private static void instrumentTimerCallback(object o)
        {
            sampleInstruments(SV.PressureTableNum);
        }
    }

    //Below code is shell for future instrument handler
    //abstract public class InstrumentHandler
    //{
        
    //    public InstrumentHandler()
    //    {
    //        //instrumentTimer = new Timer(new TimerCallback(instrumentTimerCallback), null, TimeSpan.Zero, configFile.instrumentSamplePeriod);
    //    }
    //    public static Timer instrumentTimer = new Timer(new TimerCallback(instrumentTimerCallback), null, TimeSpan.Zero, configFile.instrumentSamplePeriod);
    //    //private static TimeSpan samplePeriod = new TimeSpan(0, 0, 1);
        
    //    public static int sampleInstruments(byte instruments)
    //    {
    //        return (1);
    //    }

    //    private static void instrumentTimerCallback(object o)
    //    {
    //        sampleInstruments(7);
    //    }

    //    public abstract int processSQ(StructQueue.qStruct record);
    //}
}
