Exemple #1
0
 public MeasureManager()
 {
     _packetSize = Int32.Parse(ConfigurationManager.AppSettings["PacketSize"].ToString());
     _measureIntervall = decimal.Parse(ConfigurationManager.AppSettings["MeasureIntervallInSeconds"].ToString());
     _windDirectionDisplacement = decimal.Parse(ConfigurationManager.AppSettings["WindDirectionDisplacement"].ToString());
     _msbFactor = 256M;
     IsReady = false;
     _measures = new List<Measure>();
     _measure = new Measure();
 }
        public bool SendData(Measure pMeasure)
        {
            string version = ConfigurationManager.AppSettings["WindComVersion"].ToString();
            string stationId = ConfigurationManager.AppSettings["WindComStationId"].ToString();
            string stationCC = ConfigurationManager.AppSettings["WindComStationCC"].ToString();
            string userAgent = ConfigurationManager.AppSettings["WindComUserAgent"].ToString();
            string serverBaseUrl = ConfigurationManager.AppSettings["WindComBaseUrl"].ToString();

            WebClient client = new WebClient();
            client.Headers.Add("user-agent", userAgent);

            String url = serverBaseUrl;
            url += "v=" + version;
            url += "&ID=" + stationId;
            url += "&CC=" + stationCC;
            url += "&Wind=" + pMeasure.WindSpeedAverageAsString;
            url += "&WindStDev=" + "";
            url += "&WindMin=" + pMeasure.WindSpeedMinimumAsString;
            url += "&WindMax=" + pMeasure.WindSpeedMaximumAsString;
            url += "&Dir=" + pMeasure.WindDirectionAsString;
            url += "&DirV=" + "";
            url += "&DirStDev=" + "";
            url += "&Temp1=" + pMeasure.TemperatureAsString;
            url += "&Battery=" + pMeasure.BatteryVoltageAsString;

            Stream data = null;
            string s = string.Empty;
            StreamReader reader = null;
            try
            {
                data = client.OpenRead(url);
                reader = new StreamReader(data);
                s = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Error, ex.Message, ex);
                //throw;
            }
            finally
            {
                if (data != null)
                {
                    data.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }

            logger.Log(LogLevel.Info, url);

            return s.Contains("OK");
        }
Exemple #3
0
        public void Add(byte[] pMeasure)
        {
            if (pMeasure.Length == _packetSize)
            {
                Measure m = new Measure();
                m.WindSpeedAverage = CalculateWindSpeedAverage(ToDec(pMeasure[8]), ToDec(pMeasure[9]));
                WindMSB = pMeasure[8].ToString();
                WindLSB = pMeasure[9].ToString();
                WindMinMSB = pMeasure[14].ToString();
                WindMinLSB = pMeasure[15].ToString();
                WindMaxMSB = pMeasure[12].ToString();
                WindMaxLSB = pMeasure[13].ToString();
                m.WindSpeedMinimum = CalculateWindSpeedMinimum(ToDec(pMeasure[14]), ToDec(pMeasure[15]));
                m.WindSpeedMaximum = CalculateWindSpeedMaximum(ToDec(pMeasure[12]), ToDec(pMeasure[13]));
                m.WindDirection = CalculateWindDirection(ToDec(pMeasure[50]), ToDec(pMeasure[51]));
                m.Temperature = CalculateTemperature(ToDec(pMeasure[64]), ToDec(pMeasure[65]));
                m.BatteryVoltage = CalculateBatteryVoltage(ToDec(pMeasure[44]), ToDec(pMeasure[45]));

                _measure = m;
                _measures.Add(m);
                IsReady = true;
            }
            else
            {
                IsReady = false;
            }
        }