Skip to content

Commit

Permalink
Merge pull request #164 from mcrossley/master
Browse files Browse the repository at this point in the history
b3215
  • Loading branch information
mcrossley authored Nov 20, 2022
2 parents 096c15f + a4cafc7 commit ba34246
Show file tree
Hide file tree
Showing 13 changed files with 2,775 additions and 162 deletions.
30 changes: 3 additions & 27 deletions CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,7 @@ private void doTriggered(bool value)
{
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {ActionParams}");
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments
start.Arguments = ActionParams;
// Enter the executable to run, including the complete path
start.FileName = Action;
// Don"t show a console window
start.CreateNoWindow = true;
// Run the external process
Process.Start(start);
Utils.RunExternalTask(Action, ActionParams, false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -219,15 +211,7 @@ private void doUpTriggered(bool value)
{
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {ActionParams}");
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments
start.Arguments = ActionParams;
// Enter the executable to run, including the complete path
start.FileName = Action;
// Don"t show a console window
start.CreateNoWindow = true;
// Run the external process
Process.Start(start);
Utils.RunExternalTask(Action, ActionParams, false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -284,15 +268,7 @@ private void doDownTriggered(bool value)
{
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {ActionParams}");
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments
start.Arguments = ActionParams;
// Enter the executable to run, including the complete path
start.FileName = Action;
// Don"t show a console window
start.CreateNoWindow = true;
// Run the external process
Process.Start(start);
Utils.RunExternalTask(Action, ActionParams, false);
}
catch (Exception ex)
{
Expand Down
85 changes: 63 additions & 22 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,20 @@ public Cumulus(int HTTPport, bool DebugEnabled, string startParms)
LogMessage("No start-up PING");
}

// do we have a start-up task to run?
if (!string.IsNullOrEmpty(ProgramOptions.StartupTask))
{
LogMessage($"Running start-up task: {ProgramOptions.StartupTask}, arguments: {ProgramOptions.StartupTaskParams}, wait: {ProgramOptions.StartupTaskWait}");
try
{
Utils.RunExternalTask(ProgramOptions.StartupTask, ProgramOptions.StartupTaskParams, ProgramOptions.StartupTaskWait);
}
catch (Exception ex)
{
LogMessage($"Error running start-up task: {ex.Message}");
}
}

GC.Collect();

LogMessage("Data path = " + Datapath);
Expand Down Expand Up @@ -2856,8 +2870,15 @@ internal void RealtimeTimerTick(object sender, ElapsedEventArgs elapsedEventArgs

if (!string.IsNullOrEmpty(RealtimeProgram))
{
LogDebugMessage($"Realtime[{cycle}]: Execute realtime program - {RealtimeProgram}");
ExecuteProgram(RealtimeProgram, RealtimeParams);
try
{
LogDebugMessage($"Realtime[{cycle}]: Execute realtime program - {RealtimeProgram}");
Utils.RunExternalTask(RealtimeProgram, RealtimeParams, false);
}
catch(Exception ex)
{
LogDebugMessage($"Realtime[{cycle}]: Error in realtime program - {RealtimeProgram}. Error: {ex.Message}");
}
}
}

Expand Down Expand Up @@ -3885,10 +3906,20 @@ private void ReadIniFile()
}

ProgramOptions.EnableAccessibility = ini.GetValue("Program", "EnableAccessibility", false);

ProgramOptions.StartupPingHost = ini.GetValue("Program", "StartupPingHost", "");

ProgramOptions.StartupPingEscapeTime = ini.GetValue("Program", "StartupPingEscapeTime", 999);
ProgramOptions.StartupDelaySecs = ini.GetValue("Program", "StartupDelaySecs", 0);
ProgramOptions.StartupDelayMaxUptime = ini.GetValue("Program", "StartupDelayMaxUptime", 300);

ProgramOptions.StartupTask = ini.GetValue("Program", "StartupTask", "");
ProgramOptions.StartupTaskParams = ini.GetValue("Program", "StartupTaskParams", "");
ProgramOptions.StartupTaskWait = ini.GetValue("Program", "StartupTaskWait", false);

ProgramOptions.ShutdownTask = ini.GetValue("Program", "ShutdownTask", "");
ProgramOptions.ShutdownTaskParams = ini.GetValue("Program", "ShutdownTaskParams", "");

ProgramOptions.DataStoppedExit = ini.GetValue("Program", "DataStoppedExit", false);
ProgramOptions.DataStoppedMins = ini.GetValue("Program", "DataStoppedMins", 10);
ProgramOptions.Culture.RemoveSpaceFromDateSeparator = ini.GetValue("Culture", "RemoveSpaceFromDateSeparator", false);
Expand Down Expand Up @@ -5185,7 +5216,7 @@ private void ReadIniFile()
// MySQL - dayfile
MySqlSettings.Dayfile.Enabled = ini.GetValue("MySQL", "DayfileMySqlEnabled", false);
MySqlSettings.Dayfile.TableName = ini.GetValue("MySQL", "DayfileTable", "Dayfile");

// MySQL - custom seconds
MySqlSettings.CustomSecs.Commands[0] = ini.GetValue("MySQL", "CustomMySqlSecondsCommandString", "");
for (var i = 1; i < 10; i++)
Expand Down Expand Up @@ -5239,7 +5270,7 @@ private void ReadIniFile()
CustomHttpSecondsEnabled = ini.GetValue("HTTP", "CustomHttpSecondsEnabled", false);
CustomHttpSecondsInterval = ini.GetValue("HTTP", "CustomHttpSecondsInterval", 10);
if (CustomHttpSecondsInterval < 1) { CustomHttpSecondsInterval = 1; }

// Custom HTTP - minutes
CustomHttpMinutesStrings[0] = ini.GetValue("HTTP", "CustomHttpMinutesString", "");
for (var i = 1; i < 10; i++)
Expand Down Expand Up @@ -5380,6 +5411,13 @@ internal void WriteIniFile()
ini.SetValue("Program", "StartupDelaySecs", ProgramOptions.StartupDelaySecs);
ini.SetValue("Program", "StartupDelayMaxUptime", ProgramOptions.StartupDelayMaxUptime);

ini.SetValue("Program", "StartupTask", ProgramOptions.StartupTask);
ini.SetValue("Program", "StartupTaskParams", ProgramOptions.StartupTaskParams);
ini.SetValue("Program", "StartupTaskWait", ProgramOptions.StartupTaskWait);

ini.SetValue("Program", "ShutdownTask", ProgramOptions.ShutdownTask);
ini.SetValue("Program", "ShutdownTaskParams", ProgramOptions.ShutdownTaskParams);

ini.SetValue("Program", "DataStoppedExit", ProgramOptions.DataStoppedExit);
ini.SetValue("Program", "DataStoppedMins", ProgramOptions.DataStoppedMins);

Expand Down Expand Up @@ -8299,24 +8337,22 @@ public void Stop()
}
catch { }
}
LogMessage("Station shutdown complete");
}

public void ExecuteProgram(string externalProgram, string externalParams)
{
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo()
// do we have a shutdown task to run?
if (!string.IsNullOrEmpty(ProgramOptions.ShutdownTask))
{
// Enter in the command line arguments
Arguments = externalParams,
// Enter the executable to run, including the complete path
FileName = externalProgram,
// Don't show a console window
CreateNoWindow = true
};
LogMessage($"Running shutdown task: {ProgramOptions.ShutdownTask}, arguments: {ProgramOptions.ShutdownTaskParams}");
try
{
Utils.RunExternalTask(ProgramOptions.ShutdownTask, ProgramOptions.ShutdownTaskParams, false);
}
catch (Exception ex)
{
LogMessage($"Error running shutdown task: {ex.Message}");
}
}

// Run the external process
Process.Start(start);
LogMessage("Station shutdown complete");
}

public void DoHTMLFiles(DateTime ts)
Expand Down Expand Up @@ -8397,7 +8433,7 @@ public void DoHTMLFiles(DateTime ts)
LogDebugMessage("Interval: Executing program " + ExternalProgram + " " + ExternalParams);
try
{
ExecuteProgram(ExternalProgram, ExternalParams);
Utils.RunExternalTask(ExternalProgram, ExternalParams, false);
LogDebugMessage("Interval: External program started");
}
catch (Exception ex)
Expand Down Expand Up @@ -9099,7 +9135,7 @@ private bool UploadFile(FtpClient conn, string localfile, string remotefile, int
// continue on error
}
}

if (DeleteBeforeUpload)
{
// delete the existing file
Expand Down Expand Up @@ -10830,7 +10866,7 @@ public async void CustomHttpRolloverUpdate()
LogDebugMessage("CustomHttpRollover: " + ex.Message);
}
}

updatingCustomHttpRollover = false;
}
}
Expand Down Expand Up @@ -11162,6 +11198,11 @@ public class ProgramOptionsClass
public int StartupPingEscapeTime { get; set; }
public int StartupDelaySecs { get; set; }
public int StartupDelayMaxUptime { get; set; }
public string StartupTask { get; set; }
public string StartupTaskParams { get; set; }
public bool StartupTaskWait { get; set; }
public string ShutdownTask { get; set; }
public string ShutdownTaskParams { get; set; }
public bool DebugLogging { get; set; }
public bool DataLogging { get; set; }
public bool WarnMultiple { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions CumulusMX/CumulusMX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@
<Content Include="sqlite3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Updates.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
21 changes: 17 additions & 4 deletions CumulusMX/DavisStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal class DavisStation : WeatherStation
private const int TcpWaitTimeMs = 2500;
private int maxArchiveRuns = 2;
private bool stop;
private int loggerInterval;

private readonly Stopwatch awakeStopWatch = new Stopwatch();

Expand Down Expand Up @@ -329,6 +330,9 @@ private void CheckLoggerInterval()
var bytesRead = 0;
byte[] readBuffer = new byte[40];

// default the logger interval to the CMX interval - change it later if we find different
loggerInterval = cumulus.logints[cumulus.DataLogInterval];

// response should be (5 mins):
// ACK VAL CKS1 CKS2
// 0x06-05-50-3F
Expand Down Expand Up @@ -421,7 +425,9 @@ private void CheckLoggerInterval()

if (bytesRead > 0 && readBuffer[0] != cumulus.logints[cumulus.DataLogInterval])
{
var msg = $"** WARNING: Your station logger interval {readBuffer[0]} mins does not match your Cumulus MX logging interval {cumulus.logints[cumulus.DataLogInterval]} mins";
// change the logger interval to the value we just discovered
loggerInterval = readBuffer[0];
var msg = $"** WARNING: Your station logger interval {loggerInterval} mins does not match your Cumulus MX logging interval {cumulus.logints[cumulus.DataLogInterval]} mins";
cumulus.LogConsoleMessage(msg);
cumulus.LogMessage("CheckLoggerInterval: " + msg);

Expand Down Expand Up @@ -452,6 +458,8 @@ private void SetLoggerInterval(int interval)
return;
}

// logger updated OK, so change our internal tracking value too
loggerInterval = interval;
cumulus.LogMessage("SetLoggerInterval: Logger interval changed OK");
}
catch (TimeoutException)
Expand Down Expand Up @@ -484,6 +492,8 @@ private void SetLoggerInterval(int interval)
return;
}

// logger updated OK, so change our internal tracking value too
loggerInterval = interval;
cumulus.LogMessage("SetLoggerInterval: Logger interval changed OK");
}
catch (System.IO.IOException ex)
Expand Down Expand Up @@ -2075,11 +2085,14 @@ private void GetArchiveData()

bool midnightraindone = luhour == 0;

// work out the next logger interval after the last CMX update
var nextLoggerTime = Utils.RoundTimeUpToInterval(cumulus.LastUpdateTime, TimeSpan.FromMinutes(loggerInterval));

// construct date and time of last record read
int vantageDateStamp = cumulus.LastUpdateTime.Day + cumulus.LastUpdateTime.Month*32 + (cumulus.LastUpdateTime.Year - 2000)*512;
int vantageTimeStamp = (100*cumulus.LastUpdateTime.Hour + cumulus.LastUpdateTime.Minute);
int vantageDateStamp = nextLoggerTime.Day + nextLoggerTime.Month*32 + (nextLoggerTime.Year - 2000) * 512;
int vantageTimeStamp = (100 * nextLoggerTime.Hour + nextLoggerTime.Minute);

cumulus.LogMessage($"GetArchiveData: Last Archive Date: {cumulus.LastUpdateTime}");
cumulus.LogMessage($"GetArchiveData: Last Archive Date: {nextLoggerTime}");
cumulus.LogDebugMessage("GetArchiveData: Date: " + vantageDateStamp);
cumulus.LogDebugMessage("GetArchiveData: Time: " + vantageTimeStamp);

Expand Down
Loading

0 comments on commit ba34246

Please sign in to comment.