コード例 #1
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateConfig(IHttpContext context)
        {
            var json = "";
            JsonCalibrationSettingsData settings;
            var invC = new CultureInfo("");

            try
            {
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                settings = json.FromJson <JsonCalibrationSettingsData>();
            }
            catch (Exception ex)
            {
                var msg = "Error de-serializing Calibration Settings JSON: " + ex.Message;
                cumulus.LogMessage(msg);
                cumulus.LogDebugMessage("Calibration Data: " + json);
                context.Response.StatusCode = 500;
                return(msg);
            }

            try
            {
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.Calib.Press.Offset   = Convert.ToDouble(settings.pressure.offset, invC);
                cumulus.Calib.Temp.Offset    = Convert.ToDouble(settings.temp.offset, invC);
                cumulus.Calib.InTemp.Offset  = Convert.ToDouble(settings.tempin.offset, invC);
                cumulus.Calib.Hum.Offset     = settings.hum.offset;
                cumulus.Calib.WindDir.Offset = settings.winddir.offset;
                cumulus.Calib.Solar.Offset   = Convert.ToDouble(settings.solar.offset);
                cumulus.Calib.UV.Offset      = Convert.ToDouble(settings.uv.offset, invC);
                cumulus.Calib.WetBulb.Offset = Convert.ToDouble(settings.wetbulb.offset, invC);

                // multipliers
                cumulus.Calib.Press.Mult     = Convert.ToDouble(settings.pressure.multiplier, invC);
                cumulus.Calib.WindSpeed.Mult = Convert.ToDouble(settings.windspd.multiplier, invC);
                cumulus.Calib.WindGust.Mult  = Convert.ToDouble(settings.gust.multiplier, invC);
                cumulus.Calib.Temp.Mult      = Convert.ToDouble(settings.temp.multiplier, invC);
                cumulus.Calib.Temp.Mult2     = Convert.ToDouble(settings.temp.multiplier2, invC);
                cumulus.Calib.Hum.Mult       = Convert.ToDouble(settings.hum.multiplier, invC);
                cumulus.Calib.Hum.Mult2      = Convert.ToDouble(settings.hum.multiplier2, invC);
                cumulus.Calib.Rain.Mult      = Convert.ToDouble(settings.rain.multiplier, invC);
                cumulus.Calib.Solar.Mult     = Convert.ToDouble(settings.solar.multiplier, invC);
                cumulus.Calib.UV.Mult        = Convert.ToDouble(settings.uv.multiplier, invC);
                cumulus.Calib.WetBulb.Mult   = Convert.ToDouble(settings.wetbulb.multiplier, invC);

                // spike removal
                cumulus.Spike.TempDiff      = Convert.ToDouble(settings.temp.spike, invC);
                cumulus.Spike.HumidityDiff  = Convert.ToDouble(settings.hum.spike, invC);
                cumulus.Spike.WindDiff      = Convert.ToDouble(settings.windspd.spike, invC);
                cumulus.Spike.GustDiff      = Convert.ToDouble(settings.gust.spike, invC);
                cumulus.Spike.MaxHourlyRain = Convert.ToDouble(settings.rain.spikehour, invC);
                cumulus.Spike.MaxRainRate   = Convert.ToDouble(settings.rain.spikerate, invC);
                cumulus.Spike.PressDiff     = Convert.ToDouble(settings.pressure.spike, invC);

                // limits
                cumulus.Limit.TempHigh  = Convert.ToDouble(settings.temp.limitmax, invC);
                cumulus.Limit.TempLow   = Convert.ToDouble(settings.temp.limitmin, invC);
                cumulus.Limit.DewHigh   = Convert.ToDouble(settings.dewpt.limitmax, invC);
                cumulus.Limit.PressHigh = Convert.ToDouble(settings.pressure.limitmax, invC);
                cumulus.Limit.PressLow  = Convert.ToDouble(settings.pressure.limitmin, invC);
                cumulus.Limit.WindHigh  = Convert.ToDouble(settings.gust.limitmax, invC);

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarm.Triggered = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage("Error setting Calibration settings: " + ex.Message);
                cumulus.LogDebugMessage("Calibration Data: " + json);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #2
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateCalibrationConfig(IHttpContext context)
        {
            try
            {
                var InvC = new CultureInfo("");
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = JsonConvert.DeserializeObject <JsonCalibrationSettingsData>(json);
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.PressOffset   = Convert.ToDouble(settings.offsets.pressure, InvC);
                cumulus.TempOffset    = Convert.ToDouble(settings.offsets.temperature, InvC);
                cumulus.InTempoffset  = Convert.ToDouble(settings.offsets.indoortemp, InvC);
                cumulus.HumOffset     = settings.offsets.humidity;
                cumulus.WindDirOffset = settings.offsets.winddir;
                cumulus.SolarOffset   = Convert.ToDouble(settings.offsets.solar);
                cumulus.UVOffset      = Convert.ToDouble(settings.offsets.uv, InvC);
                cumulus.WetBulbOffset = Convert.ToDouble(settings.offsets.wetbulb, InvC);

                // multipliers
                cumulus.PressMult     = Convert.ToDouble(settings.multipliers.pressure, InvC);
                cumulus.WindSpeedMult = Convert.ToDouble(settings.multipliers.windspeed, InvC);
                cumulus.WindGustMult  = Convert.ToDouble(settings.multipliers.windgust, InvC);
                cumulus.TempMult      = Convert.ToDouble(settings.multipliers.outdoortemp, InvC);
                cumulus.HumMult       = Convert.ToDouble(settings.multipliers.humidity, InvC);
                cumulus.RainMult      = Convert.ToDouble(settings.multipliers.rainfall, InvC);
                cumulus.SolarMult     = Convert.ToDouble(settings.multipliers.solar, InvC);
                cumulus.UVMult        = Convert.ToDouble(settings.multipliers.uv, InvC);
                cumulus.WetBulbMult   = Convert.ToDouble(settings.multipliers.wetbulb, InvC);

                // spike removal
                cumulus.SpikeTempDiff      = Convert.ToDouble(settings.spikeremoval.outdoortemp, InvC);
                cumulus.SpikeHumidityDiff  = Convert.ToDouble(settings.spikeremoval.humidity, InvC);
                cumulus.SpikeWindDiff      = Convert.ToDouble(settings.spikeremoval.windspeed, InvC);
                cumulus.SpikeGustDiff      = Convert.ToDouble(settings.spikeremoval.windgust, InvC);
                cumulus.SpikeMaxHourlyRain = Convert.ToDouble(settings.spikeremoval.maxhourlyrain, InvC);
                cumulus.SpikeMaxRainRate   = Convert.ToDouble(settings.spikeremoval.maxrainrate, InvC);
                cumulus.SpikePressDiff     = Convert.ToDouble(settings.spikeremoval.pressure, InvC);

                // limits
                cumulus.LimitTempHigh  = Convert.ToDouble(settings.limits.temphigh, InvC);
                cumulus.LimitTempLow   = Convert.ToDouble(settings.limits.templow, InvC);
                cumulus.LimitDewHigh   = Convert.ToDouble(settings.limits.dewhigh, InvC);
                cumulus.LimitPressHigh = Convert.ToDouble(settings.limits.presshigh, InvC);
                cumulus.LimitPressLow  = Convert.ToDouble(settings.limits.presslow, InvC);
                cumulus.LimitWindHigh  = Convert.ToDouble(settings.limits.windhigh, InvC);

                cumulus.ErrorLogSpikeRemoval = settings.log;

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarmState = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }
コード例 #3
0
        //public string UpdateCalibrationConfig(HttpListenerContext context)
        public string UpdateCalibrationConfig(IHttpContext context)
        {
            try
            {
                var invC = new CultureInfo("");
                var data = new StreamReader(context.Request.InputStream).ReadToEnd();

                var json = WebUtility.UrlDecode(data.Substring(5));

                // de-serialize it to the settings structure
                var settings = json.FromJson <JsonCalibrationSettingsData>();
                // process the settings
                cumulus.LogMessage("Updating calibration settings");

                // offsets
                cumulus.Calib.Press.Offset   = Convert.ToDouble(settings.offsets.pressure, invC);
                cumulus.Calib.Temp.Offset    = Convert.ToDouble(settings.offsets.temperature, invC);
                cumulus.Calib.InTemp.Offset  = Convert.ToDouble(settings.offsets.indoortemp, invC);
                cumulus.Calib.Hum.Offset     = settings.offsets.humidity;
                cumulus.Calib.WindDir.Offset = settings.offsets.winddir;
                cumulus.Calib.Solar.Offset   = Convert.ToDouble(settings.offsets.solar);
                cumulus.Calib.UV.Offset      = Convert.ToDouble(settings.offsets.uv, invC);
                cumulus.Calib.WetBulb.Offset = Convert.ToDouble(settings.offsets.wetbulb, invC);

                // multipliers
                cumulus.Calib.Press.Mult     = Convert.ToDouble(settings.multipliers.pressure, invC);
                cumulus.Calib.WindSpeed.Mult = Convert.ToDouble(settings.multipliers.windspeed, invC);
                cumulus.Calib.WindGust.Mult  = Convert.ToDouble(settings.multipliers.windgust, invC);
                cumulus.Calib.Temp.Mult      = Convert.ToDouble(settings.multipliers.outdoortemp, invC);
                cumulus.Calib.Temp.Mult2     = Convert.ToDouble(settings.multipliers.outdoortemp2, invC);
                cumulus.Calib.Hum.Mult       = Convert.ToDouble(settings.multipliers.humidity, invC);
                cumulus.Calib.Hum.Mult2      = Convert.ToDouble(settings.multipliers.humidity2, invC);
                cumulus.Calib.Rain.Mult      = Convert.ToDouble(settings.multipliers.rainfall, invC);
                cumulus.Calib.Solar.Mult     = Convert.ToDouble(settings.multipliers.solar, invC);
                cumulus.Calib.UV.Mult        = Convert.ToDouble(settings.multipliers.uv, invC);
                cumulus.Calib.WetBulb.Mult   = Convert.ToDouble(settings.multipliers.wetbulb, invC);

                // spike removal
                cumulus.Spike.TempDiff      = Convert.ToDouble(settings.spikeremoval.outdoortemp, invC);
                cumulus.Spike.HumidityDiff  = Convert.ToDouble(settings.spikeremoval.humidity, invC);
                cumulus.Spike.WindDiff      = Convert.ToDouble(settings.spikeremoval.windspeed, invC);
                cumulus.Spike.GustDiff      = Convert.ToDouble(settings.spikeremoval.windgust, invC);
                cumulus.Spike.MaxHourlyRain = Convert.ToDouble(settings.spikeremoval.maxhourlyrain, invC);
                cumulus.Spike.MaxRainRate   = Convert.ToDouble(settings.spikeremoval.maxrainrate, invC);
                cumulus.Spike.PressDiff     = Convert.ToDouble(settings.spikeremoval.pressure, invC);

                // limits
                cumulus.Limit.TempHigh  = Convert.ToDouble(settings.limits.temphigh, invC);
                cumulus.Limit.TempLow   = Convert.ToDouble(settings.limits.templow, invC);
                cumulus.Limit.DewHigh   = Convert.ToDouble(settings.limits.dewhigh, invC);
                cumulus.Limit.PressHigh = Convert.ToDouble(settings.limits.presshigh, invC);
                cumulus.Limit.PressLow  = Convert.ToDouble(settings.limits.presslow, invC);
                cumulus.Limit.WindHigh  = Convert.ToDouble(settings.limits.windhigh, invC);

                cumulus.ErrorLogSpikeRemoval = settings.log;

                // Save the settings
                cumulus.WriteIniFile();

                // Clear the spike alarm
                cumulus.SpikeAlarm.Triggered = false;

                // Log the new values
                cumulus.LogMessage("Setting new calibration values...");
                cumulus.LogOffsetsMultipliers();

                context.Response.StatusCode = 200;
            }
            catch (Exception ex)
            {
                cumulus.LogMessage(ex.Message);
                context.Response.StatusCode = 500;
                return(ex.Message);
            }
            return("success");
        }