using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using MindWorks.Nimbus;
using Ivi.Driver;

namespace Raytheon.GuidedElectronicsUnit
{
    //public struct SdlcStatus
    public struct SdlcStatus
    {
        public SdlcStatus(uint status)
        {
            DrOverrunError = Convert.ToBoolean(status & (uint)BitMask.DrError);
            RxInhibited = Convert.ToBoolean(status & (uint)BitMask.RxInhibit);
            TxInhibited = Convert.ToBoolean(status & (uint)BitMask.TxInhibit);
            EchoLoopback = Convert.ToBoolean(status & (uint)BitMask.Echo);
            InternalLoopback = Convert.ToBoolean(status & (uint)BitMask.InterruptLB);
            RxMessageAborted = Convert.ToBoolean(status & (uint)BitMask.RxAbort);
            RxMessageFcsError = Convert.ToBoolean(status & (uint)BitMask.RxFcs);
            RxMessageDone = Convert.ToBoolean(status & (uint)BitMask.RxDone);
            RxBadAddrError = Convert.ToBoolean(status & (uint)BitMask.Rba);
            RxFifoOverflowed = Convert.ToBoolean(status & (uint)BitMask.RxFifoOverflow);
            RxFifoEmpty = Convert.ToBoolean(status & (uint)BitMask.RxFifoEmpty);
            RxFifoFull = Convert.ToBoolean(status & (uint)BitMask.RxFifoFull);
            RxActive = Convert.ToBoolean(status & (uint)BitMask.RxActive);
            TxFifoOverflowed = Convert.ToBoolean(status & (uint)BitMask.TxFifoOverflow);
            TxFifoEmpty = Convert.ToBoolean(status & (uint)BitMask.TxFifoEmpty);
            TxFifoFull = Convert.ToBoolean(status & (uint)BitMask.TxFifoFull);
            TxActive = Convert.ToBoolean(status & (uint)BitMask.TxActive);
        }

        #region Private Members

        private enum BitMask
        {
            DrError = 0x00010000,
            RxInhibit = 0x00008000,
            TxInhibit = 0x00004000,
            Echo = 0x00002000,
            InterruptLB = 0x00001000,
            RxAbort = 0x00000800,
            RxFcs = 0x00000400,
            RxDone = 0x00000200,
            Rba = 0x00000100,
            RxFifoOverflow = 0x00000080,
            RxFifoEmpty = 0x00000040,
            RxFifoFull = 0x00000020,
            RxActive = 0x00000010,
            TxFifoOverflow = 0x00000008,
            TxFifoEmpty = 0x00000004,
            TxFifoFull = 0x00000002,
            TxActive = 0x0000001
        }

        #endregion

        public bool DrOverrunError { get; internal set; }

        public bool RxInhibited { get; internal set; }

        public bool EchoLoopback { get; internal set; }

        public bool InternalLoopback { get; internal set; }

        public bool RxMessageAborted { get; internal set; }

        public bool RxMessageFcsError { get; internal set; }

        public bool RxMessageDone { get; internal set; }

        public bool RxBadAddrError { get; internal set; }

        public bool RxFifoOverflowed { get; internal set; }

        public bool RxFifoEmpty { get; internal set; }

        public bool TxInhibited { get; internal set; }

        public bool RxFifoFull { get; internal set; }

        public bool RxActive { get; internal set; }

        public bool TxActive { get; internal set; }

        public bool TxFifoOverflowed { get; internal set; }

        public bool TxFifoEmpty { get; internal set; }

        public bool TxFifoFull { get; internal set; }

    }
}