Skip to content

Commit

Permalink
Merge pull request #202 from mcrossley/main
Browse files Browse the repository at this point in the history
4.1.2 - b4026
  • Loading branch information
mcrossley authored Jul 22, 2024
2 parents a062eba + 957e123 commit 5bcca9d
Show file tree
Hide file tree
Showing 19 changed files with 578 additions and 381 deletions.
17 changes: 17 additions & 0 deletions CumulusMX/ConvertUnits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ public static double WindMPHToUser(double value)
};
}

/// <summary>
/// Converts wind supplied in knots to user units
/// </summary>
/// <param name="value">Wind in knots</param>
/// <returns>Wind in configured units</returns>
public static double WindKnotsToUser(double value)
{
return Program.cumulus.Units.Wind switch
{
0 => value * 0.5144444,
1 => value * 1.150779,
2 => value * 1.852,
3 => value,
_ => 0,
};
}

/// <summary>
/// Converts wind supplied in kph to user units
/// </summary>
Expand Down
328 changes: 188 additions & 140 deletions CumulusMX/Cumulus.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CumulusMX/CumulusMX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>4.001.1.4025</Version>
<Version>4.1.2.4026</Version>
<Copyright>Copyright © 2015-$([System.DateTime]::Now.ToString('yyyy')) Cumulus MX</Copyright>
</PropertyGroup>

Expand Down
17 changes: 14 additions & 3 deletions CumulusMX/DataStruct.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

Expand All @@ -9,15 +10,15 @@ public class DataStruct(Cumulus cumulus, double outdoorTemp, int outdoorHum, dou
int indoorHum, double pressure, double windLatest, double windAverage, double recentmaxgust, double windRunToday, int bearing, int avgbearing,
double rainToday, double rainYesterday, double rainMonth, double rainYear, double rainRate, double rainLastHour, double heatIndex, double humidex,
double appTemp, double tempTrend, double pressTrend, double highGustToday, string highGustTodayTime, double highWindToday, int highGustBearingToday,
string windUnit, int bearingRangeFrom10, int bearingRangeTo10, string windRoseData, double highTempToday, double lowTempToday, string highTempTodayToday,
string windUnit, string windRunUnit, int bearingRangeFrom10, int bearingRangeTo10, string windRoseData, double highTempToday, double lowTempToday, string highTempTodayToday,
string lowTempTodayTime, double highPressToday, double lowPressToday, string highPressTodayTime, string lowPressTodayTime, double highRainRateToday,
string highRainRateTodayTime, int highHumToday, int lowHumToday, string highHumTodayTime, string lowHumTodayTime, string pressUnit, string tempUnit,
string rainUnit, double highDewpointToday, double lowDewpointToday, string highDewpointTodayTime, string lowDewpointTodayTime, double lowWindChillToday,
string lowWindChillTodayTime, int solarRad, int highSolarRadToday, string highSolarRadTodayTime, double uvindex, double highUVindexToday,
string highUVindexTodayTime, string forecast, string sunrise, string sunset, string moonrise, string moonset, double highHeatIndexToday,
string highHeatIndexTodayTime, double highAppTempToday, double lowAppTempToday, string highAppTempTodayTime, string lowAppTempTodayTime,
int currentSolarMax, double alltimeHighPressure, double alltimeLowPressure, double sunshineHours, string domWindDir, string lastRainTipISO,
double highHourlyRainToday, string highHourlyRainTodayTime, string highBeaufortToday, string beaufort, string beaufortDesc, string lastDataRead,
double highHourlyRainToday, string highHourlyRainTodayTime, string highBeaufortToday, string beaufort, string beaufortDesc, DateTime lastDataRead,
bool dataStopped, double stormRain, string stormRainStart, int cloudbase, string cloudbaseUnit, double last24hourRain,
double feelsLike, double highFeelsLikeToday, string highFeelsLikeTodayTime, double lowFeelsLikeToday, string lowFeelsLikeTodayTime,
double highHumidexToday, string highHumidexTodayTime, List<DashboardAlarms> alarms)
Expand Down Expand Up @@ -162,6 +163,9 @@ public string LowWindChillTodayRounded
[DataMember]
public string WindUnit { get; } = windUnit;

[DataMember]
public string WindRunUnit { get; } = windRunUnit;

[DataMember]
public string RainUnit { get; } = rainUnit;

Expand Down Expand Up @@ -600,7 +604,14 @@ public string Build
public string BeaufortDesc { get; } = beaufortDesc;

[DataMember]
public string LastDataRead { get; } = lastDataRead;
public string LastDataRead { get; } = lastDataRead.ToLocalTime().ToString(cumulus.ProgramOptions.TimeFormatLong);

[DataMember]
public string LastDataReadDate
{
get => lastDataRead.ToLocalTime().ToString("d");
}


[DataMember]
public bool DataStopped { get; } = dataStopped;
Expand Down
71 changes: 31 additions & 40 deletions CumulusMX/DavisCloudStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ private void GetHistoricData(BackgroundWorker worker)
DoHumidex(timestamp);
DoCloudBaseHeatIndex(timestamp);

if (cumulus.StationOptions.CalculateSLP && StationPressure > 0)
{
var abs = cumulus.Calib.Press.Calibrate(StationPressure);
var slp = MeteoLib.GetSeaLevelPressure(AltitudeM(cumulus.Altitude), ConvertUnits.UserPressToHpa(abs), ConvertUnits.UserTempToC(OutdoorTemperature), cumulus.Latitude);
DoPressure(ConvertUnits.PressMBToUser(slp), timestamp);
}

// Log all the data
_ = cumulus.DoLogFile(timestamp, false);
cumulus.MySqlRealtimeFile(999, false, timestamp);
Expand Down Expand Up @@ -1006,21 +1013,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
lsidLastUpdate[sensor.lsid] = rec.ts;
var ts = Utils.FromUnixTime(rec.ts);

if (cumulus.StationOptions.CalculateSLP)
{
if (rec.bar_absolute.HasValue)
{
var abs = ConvertUnits.PressINHGToHpa(rec.bar_absolute.Value);
abs = cumulus.Calib.Press.Calibrate(abs);
var slp = MeteoLib.GetSeaLevelPressure(AltitudeM(cumulus.Altitude), abs, ConvertUnits.UserTempToC(OutdoorTemperature), cumulus.Latitude);
DoPressure(ConvertUnits.PressMBToUser(slp), ts);
}
else
{
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Baro data (absolute)");
}
}
else
if (!cumulus.StationOptions.CalculateSLP)
{
if (rec.bar_sea_level.HasValue)
{
Expand Down Expand Up @@ -1258,7 +1251,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
}
else
{
cumulus.LogErrorMessage("DecodeCurrent: Warning, no valid Humidity data");
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Humidity data");
}
}
catch (Exception ex)
Expand All @@ -1271,7 +1264,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
{
if (data.temp_out.HasValue && data.temp_out < -98)
{
cumulus.LogErrorMessage("DecodeCurrent: Warning, no valid Primary temperature value found [-99]");
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Primary temperature value found [-99]");
}
else
{
Expand All @@ -1284,7 +1277,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
}
else
{
cumulus.LogErrorMessage("DecodeCurrent: Warning, no valid Temperature data");
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Temperature data");
}
}
}
Expand All @@ -1303,7 +1296,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
}
else
{
cumulus.LogErrorMessage("DecodeCurrent: Warning, no valid Dew Point data");
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Dew Point data");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -1385,7 +1378,7 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
}
else
{
cumulus.LogDebugMessage("DecodeCurrent: Warning, no valid Wind data");
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Wind data");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -1478,10 +1471,6 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)

DoUV(data.uv.Value, lastRecordTime);
}
else
{
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid UV data");
}
}
catch (Exception ex)
{
Expand All @@ -1502,15 +1491,11 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
{
cumulus.LogDebugMessage("DecodeCurrent: using solar data");
DoSolarRad(data.solar_rad.Value, lastRecordTime);
}
else
{
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Solar data");
}

if (data.et_year.HasValue && !cumulus.StationOptions.CalculatedET && (data.et_year.Value >= 0) && (data.et_year.Value < 32000))
{
DoET(ConvertUnits.RainINToUser(data.et_year.Value), lastRecordTime);
if (data.et_year.HasValue && !cumulus.StationOptions.CalculatedET && (data.et_year.Value >= 0) && (data.et_year.Value < 32000))
{
DoET(ConvertUnits.RainINToUser(data.et_year.Value), lastRecordTime);
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -2080,6 +2065,20 @@ private void DecodeCurrent(List<WlCurrentSensor> sensors)
DoHumidex(dateTime);
DoCloudBaseHeatIndex(dateTime);

if (cumulus.StationOptions.CalculateSLP)
{
if (StationPressure > 0)
{
var slp = MeteoLib.GetSeaLevelPressure(AltitudeM(cumulus.Altitude), ConvertUnits.UserPressToHpa(StationPressure), ConvertUnits.UserTempToC(OutdoorTemperature), cumulus.Latitude);
DoPressure(ConvertUnits.PressMBToUser(slp), dateTime);
}
else
{
cumulus.LogWarningMessage("DecodeCurrent: Warning, no valid Baro data (absolute)");
}
}


DoForecast(string.Empty, false);

UpdateStatusPanel(DateTime.Now);
Expand Down Expand Up @@ -3282,14 +3281,6 @@ private void DecodeHistoric(int dataType, int sensorType, string json, bool curr
cumulus.LogWarningMessage("DecodeHistoric: Warning, no valid Baro data (sea level)");
}
}
else if (data13baro.bar_absolute != null)
{
ts = Utils.FromUnixTime(data13baro.ts);
var abs = ConvertUnits.PressINHGToHpa((double) data13baro.bar_absolute);
abs = cumulus.Calib.Press.Calibrate(abs);
var slp = MeteoLib.GetSeaLevelPressure(AltitudeM(cumulus.Altitude), abs, ConvertUnits.UserTempToC(OutdoorTemperature), cumulus.Latitude);
DoPressure(ConvertUnits.PressMBToUser(slp), ts);
}
else
{
cumulus.LogWarningMessage("DecodeHistoric: Warning, no valid Baro data (absolute)");
Expand Down
Loading

0 comments on commit 5bcca9d

Please sign in to comment.