예제 #1
0
        // function that receives a card and a system and tells you whether they are compatible
        public bool CheckForMatch(Card card, SystemCard system)
        {
            bool match = true; // true until proven false by tests below

            // Step 1: See whether Sample Rate is adequate
            if (system.DesiredContent == "Frequency")
            {
                // Card must have 2x signal frequency as its sample rate
                if ((system.SignalFrequency * 2) > card.SampleRate)
                {
                    match = false;
                }
            }
            else if (system.DesiredContent == "Waveform")
            {
                // Card must have 10x signal frequency as its sample rate
                if ((system.SignalFrequency * 10) > card.SampleRate)
                {
                    match = false;
                }
            }
            else if (system.DesiredContent == "Level")
            {
                // Card frequency does not matter
            }
            // Step 2: Check for ground loops
            if (system.IsGrounded && (card.TerminalConfig == "Single-Ended"))
            {
                match = false;
            }
            // Step 3: Check for necessary Signal Conditioning
            if ((system.SensorType == "Thermocouple") && (card.SignalConditioning != "CJC"))
            {
                match = false;
            }
            else if ((system.SensorType == "Strain Gauge") && (card.SignalConditioning != "Bridge"))
            {
                match = false;
            }
            else if ((system.SensorType == "IEPE Microphone") && (card.SignalConditioning != "IEPE"))
            {
                match = false;
            }
            // Step 4:  Make sure signal Amplitude can be read
            if (system.SignalAmplitude > card.MeasurementRange)
            {
                match = false;
            }
            return(match);
        }
예제 #2
0
        // Give a list of n sensors in a random order
        public List <SystemCard> GenerateSystemList()
        {
            // get all records and convert them to models
            SensorDatabase database = new SensorDatabase();

            database.OpenConnection();
            List <SensorRecord> records = database.RequestAllSensors();
            List <SystemCard>   cards   = new List <SystemCard>();

            foreach (SensorRecord record in records)
            {
                SystemCard holderCard = new SystemCard();
                holderCard.PopulateSystemFromRecord(record);
                cards.Add(holderCard);
            }
            ShuffleSystemCards(cards);
            return(cards);
        }
예제 #3
0
        private void ShuffleSystemCards(List <SystemCard> list)
        {
            RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
            int n = list.Count;

            while (n > 1)
            {
                byte[] box = new byte[1];
                do
                {
                    provider.GetBytes(box);
                }while (!(box[0] < n * (Byte.MaxValue / n)));
                int k = (box[0] % n);
                n--;
                SystemCard value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
예제 #4
0
        // Given a sensor, give 1 right card and 2 random cards
        public List <Card> DealCardsForSensor(SystemCard system)
        {
            List <Card> cards = ListAllCards();
            // run them through matcher in random order until a match is found
            CardMatcher matcher        = new CardMatcher();
            int         necessaryCards = 3;
            List <Card> dealtCards     = new List <Card>();

            foreach (Card card in cards)
            {
                if (matcher.CheckForMatch(card, system))
                {
                    dealtCards.Add(card);
                }
                else if (necessaryCards > 1)
                {
                    dealtCards.Add(card);
                    necessaryCards--;
                }
            }
            return(dealtCards);
        }