Exemplo n.º 1
0
        public static List <WattsMessageData> GenerateWattsMessageData()
        {
            List <WattsMessageData> messageDataList = new List <WattsMessageData>();
            DateTime timeStamp = DateTime.Now;

            //for (int sensor = 0; sensor < XmlParser.MaxSensors; sensor++)
            for (int sensor = 0; sensor < 1; sensor++)
            {
                for (int channel = 1; channel < XmlParser.MaxChannels + 1; channel++)
                {
                    double temp  = RandomNumber(21, 23);
                    int    watts = 0;
                    switch (channel)
                    {
                    case 1:
                        watts = RandomNumber(25, 75);
                        break;

                    case 2:
                        watts = RandomNumber(125, 175);
                        break;

                    case 3:
                        watts = RandomNumber(225, 275);
                        break;
                    }
                    WattsMessageData messageData
                        = new WattsMessageData(timeStamp, temp, sensor, channel, watts);
                    messageDataList.Add(messageData);
                }
            }
            return(messageDataList);
        }
Exemplo n.º 2
0
        } // end parseMessage

        // parse watts channels in watts message and fill array LastWatts
        // for this sensor
        private void ParseWattsMessage(XPathNavigator navigator)
        {
            XPathNavigator testNav;

            // which sensor is it?
            testNav = navigator.SelectSingleNode(SensorPath);
            if (testNav == null)
            {
                throw new Exception("Unexpected XML message format: no sensor information");
            }
            int sensor = testNav.ValueAsInt;

            if (sensor > maxSensors - 1) // check this because maxSensors is configurable
            {
                return;
            }

            // parse watts channels
            for (int channel = 1; channel < maxChannels + 1; channel++)
            {
                testNav = navigator.SelectSingleNode
                              (ChannelPath + (channel).ToString() + "/watts");

                if (testNav != null)
                {
                    // fill WattsMessageData with data from xml message and add it to queue
                    int watts = testNav.ValueAsInt;
                    WattsMessageData messageData
                        = new WattsMessageData(LastTime, LastTemp, sensor, channel, watts);
                    wattsDataQueue.Enqueue(messageData);
                }
            }
        } // end parseWattsMessage