Skip to content

Commit

Permalink
b3047
Browse files Browse the repository at this point in the history
See Updates.txt
  • Loading branch information
mcrossley committed Feb 3, 2019
1 parent 9396c55 commit 7715899
Show file tree
Hide file tree
Showing 19 changed files with 651 additions and 376 deletions.
16 changes: 8 additions & 8 deletions CumulusMX/CalibrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using fastJSON;
using Newtonsoft.Json;
using Unosquare.Labs.EmbedIO;

namespace CumulusMX
Expand Down Expand Up @@ -34,10 +34,10 @@ public string UpdateCalibrationConfig(IHttpContext context)

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

// de-serialize it to the settings structure
var settings = JSON.ToObject<JsonCalibrationSettingsData>(json);
// process the settings
cumulus.LogMessage("Updating calibration settings");
// 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);
Expand Down Expand Up @@ -124,10 +124,10 @@ public string GetCalibrationAlpacaFormData()
spikeremoval = spikeremoval
};

return JSON.ToJSON(data);
}
return JsonConvert.SerializeObject(data);
}

public string GetCalibrationAlpacaFormOptions()
public string GetCalibrationAlpacaFormOptions()
{
using (StreamReader sr = new StreamReader(calibrationOptionsFile))
{
Expand Down
152 changes: 136 additions & 16 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Cumulus
{
/////////////////////////////////
public string Version = "3.0.0";
public string Build = "3047test";
public string Build = "3047";
/////////////////////////////////

private static string appGuid = "57190d2e-7e45-4efb-8c09-06a176cef3f3";
Expand Down Expand Up @@ -147,6 +147,7 @@ public struct TExtraFiles
public bool process;
public bool binary;
public bool realtime;
public bool endofday;
public bool FTP;
public bool UTF8;
}
Expand Down Expand Up @@ -367,6 +368,7 @@ public struct TExtraFiles
public string ComportName;
public string DefaultComportName;
public int ImetBaudRate;
public int DavisBaudRate;

public int VendorID;
public int ProductID;
Expand Down Expand Up @@ -643,6 +645,8 @@ public struct TExtraFiles
public double NOAARainNormNov;
public double NOAARainNormDec;

public bool EODfilesNeedFTP = false;

public bool IsOSX;

private const double DEFAULTFCLOWPRESS = 950.0;
Expand Down Expand Up @@ -2652,6 +2656,9 @@ private string GetLoggingFileName(string directory)

private void ReadIniFile()
{
var DavisBaudRates = new List<int> { 1200, 2400, 4800, 9600, 14400, 19200 };
var ImetBaudRates = new List<int> { 19200, 115200 };

LogMessage("Reading Cumulus.ini file");
//DateTimeToString(LongDate, "ddddd", Now);

Expand Down Expand Up @@ -2679,6 +2686,22 @@ private void ReadIniFile()

ComportName = ini.GetValue("Station", "ComportName", DefaultComportName);
ImetBaudRate = ini.GetValue("Station", "ImetBaudRate", 19200);
// Check we have a valid value
if (!ImetBaudRates.Contains(ImetBaudRate))
{
// nope, that isn't allowed, set the default
LogMessage("Error, the value for ImetBaudRate in the ini file " + ImetBaudRate + " is not valid, using default 19200.");
ImetBaudRate = 19200;
}

DavisBaudRate = ini.GetValue("Station", "DavisBaudRate", 19200);
// Check we have a valid value
if (!DavisBaudRates.Contains(DavisBaudRate))
{
// nope, that isn't allowed, set the default
LogMessage("Error, the value for DavisBaudRate in the ini file " + DavisBaudRate + " is not valid, using default 19200.");
DavisBaudRate = 19200;
}

VendorID = ini.GetValue("Station", "VendorID", -1);
ProductID = ini.GetValue("Station", "ProductID", -1);
Expand Down Expand Up @@ -2775,7 +2798,7 @@ private void ReadIniFile()
DataLogInterval = 2;
}

SyncFOReads = ini.GetValue("Station", "SyncFOReads", false);
SyncFOReads = ini.GetValue("Station", "SyncFOReads", true);
FOReadAvoidPeriod = ini.GetValue("Station", "FOReadAvoidPeriod", 3);
FineOffsetReadTime = ini.GetValue("Station", "FineOffsetReadTime", 150);

Expand Down Expand Up @@ -2964,6 +2987,7 @@ private void ReadIniFile()
ExtraFiles[i].realtime = ini.GetValue("FTP site", "ExtraRealtime" + i, false);
ExtraFiles[i].FTP = ini.GetValue("FTP site", "ExtraFTP" + i, true);
ExtraFiles[i].UTF8 = ini.GetValue("FTP site", "ExtraUTF" + i, false);
ExtraFiles[i].endofday = ini.GetValue("FTP site", "ExtraEOD" + i, false);
}

ExternalProgram = ini.GetValue("FTP site", "ExternalProgram", "");
Expand Down Expand Up @@ -3434,6 +3458,7 @@ internal void WriteIniFile()
ini.SetValue("Station", "ErrorLogSpikeRemoval", ErrorLogSpikeRemoval);

//ini.SetValue("Station", "ImetBaudRate", ImetBaudRate);
//ini.SetValue("Station", "DavisBaudRate", DavisBaudRate);

ini.SetValue("Station", "RG11portName", RG11Port);
ini.SetValue("Station", "RG11TBRmode", RG11TBRmode);
Expand Down Expand Up @@ -3490,6 +3515,7 @@ internal void WriteIniFile()
ini.SetValue("FTP site", "ExtraRealtime" + i, ExtraFiles[i].realtime);
ini.SetValue("FTP site", "ExtraFTP" + i, ExtraFiles[i].FTP);
ini.SetValue("FTP site", "ExtraUTF" + i, ExtraFiles[i].UTF8);
ini.SetValue("FTP site", "ExtraEOD" + i, ExtraFiles[i].endofday);
}

ini.SetValue("FTP site", "ExternalProgram", ExternalProgram);
Expand Down Expand Up @@ -4418,6 +4444,8 @@ private WeatherStation Station
public string ReportPath = "Reports";
public string LatestError;
public DateTime LatestErrorTS = DateTime.MinValue;
//public DateTime defaultRecordTS = new DateTime(2000, 1, 1, 0, 0, 0);
public DateTime defaultRecordTS = DateTime.MinValue;
public string wxnowfile = "wxnow.txt";
private readonly string IndexTFile;
private readonly string TodayTFile;
Expand Down Expand Up @@ -5379,7 +5407,7 @@ public void DoHTMLFiles()
// handle any extra files
for (int i = 0; i < numextrafiles; i++)
{
if (!ExtraFiles[i].realtime)
if (!ExtraFiles[i].realtime && !ExtraFiles[i].endofday)
{
var uploadfile = ExtraFiles[i].local;
if (uploadfile == "<currentlogfile>")
Expand Down Expand Up @@ -5509,20 +5537,26 @@ private void DoFTPLogin()
string remotePath = (ftp_directory.EndsWith("/") ? ftp_directory : ftp_directory + "/");
if (NOAANeedFTP)
{
// upload NOAA reports
LogMessage("Uploading NOAA reports");
FtpTrace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " Uploading NOAA reports");

var uploadfile = ReportPath + NOAALatestMonthlyReport;
var remotefile = NOAAFTPDirectory + '/' + NOAALatestMonthlyReport;
try
{
// upload NOAA reports
LogMessage("Uploading NOAA reports");
FtpTrace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " Uploading NOAA reports");

UploadFile(conn, uploadfile, remotefile);
var uploadfile = ReportPath + NOAALatestMonthlyReport;
var remotefile = NOAAFTPDirectory + '/' + NOAALatestMonthlyReport;

uploadfile = ReportPath + NOAALatestYearlyReport;
remotefile = NOAAFTPDirectory + '/' + NOAALatestYearlyReport;
UploadFile(conn, uploadfile, remotefile);

UploadFile(conn, uploadfile, remotefile);
uploadfile = ReportPath + NOAALatestYearlyReport;
remotefile = NOAAFTPDirectory + '/' + NOAALatestYearlyReport;

UploadFile(conn, uploadfile, remotefile);
}
catch (Exception e)
{
LogMessage(e.Message);
}
NOAANeedFTP = false;
}

Expand All @@ -5540,18 +5574,34 @@ private void DoFTPLogin()

remotefile = remotefile.Replace("<currentlogfile>", Path.GetFileName(GetLogFileName(DateTime.Now)));

if ((uploadfile != "") && (File.Exists(uploadfile)) && (remotefile != "") && !ExtraFiles[i].realtime && ExtraFiles[i].FTP)
if ((uploadfile != "") &&
(File.Exists(uploadfile)) &&
(remotefile != "") &&
!ExtraFiles[i].realtime &&
EODfilesNeedFTP == ExtraFiles[i].endofday &&
ExtraFiles[i].FTP)
{
// all checks OK, file needs to be uploaded
if (ExtraFiles[i].process)
{
// we've already processed the file
uploadfile = uploadfile + "tmp";
}
try
{
UploadFile(conn, uploadfile, remotefile);
}
catch (Exception e)
{
LogMessage(e.Message);
}

UploadFile(conn, uploadfile, remotefile);
}
}
if (EODfilesNeedFTP)
{
EODfilesNeedFTP = false;
}
//LogDebugMessage("Done uploading extra files");
// standard files
if (IncludeStandardFiles)
Expand Down Expand Up @@ -6163,6 +6213,77 @@ internal void CustomMysqlRolloverTimerTick()
}
}

public void DoExtraEndOfDayFiles()
{
int i;

// handle any extra files that only require EOD processing
for (i = 0; i < numextrafiles; i++)
{
if (ExtraFiles[i].endofday)
{
var uploadfile = ExtraFiles[i].local;
if (uploadfile == "<currentlogfile>")
{
uploadfile = GetLogFileName(DateTime.Now);
}
var remotefile = ExtraFiles[i].remote;
remotefile = remotefile.Replace("<currentlogfile>", Path.GetFileName(GetLogFileName(DateTime.Now)));

if ((uploadfile != "") && (File.Exists(uploadfile)) && (remotefile != ""))
{
if (ExtraFiles[i].process)
{
LogDebugMessage("Processing extra file "+uploadfile);
// process the file
var utf8WithoutBom = new System.Text.UTF8Encoding(false);
var encoding = UTF8encode ? utf8WithoutBom : System.Text.Encoding.GetEncoding("iso-8859-1");
tokenParser.encoding = encoding;
tokenParser.SourceFile = uploadfile;
var output = tokenParser.ToString();
uploadfile += "tmp";
try
{
using (StreamWriter file = new StreamWriter(uploadfile, false, encoding))
{
file.Write(output);

file.Close();
}
}
catch (Exception ex)
{
LogDebugMessage("Error writing file " + uploadfile);
LogDebugMessage(ex.Message);
}
//LogDebugMessage("Finished processing extra file " + uploadfile);
}

if (ExtraFiles[i].FTP)
{
// FTP the file at the next interval
EODfilesNeedFTP = true;
}
else
{
// just copy the file
LogDebugMessage("Copying extra file " + uploadfile);
try
{
File.Copy(uploadfile, remotefile, true);
}
catch (Exception ex)
{
LogDebugMessage("Error copying extra file: " + ex.Message);
}
//LogDebugMessage("Finished copying extra file " + uploadfile);
}
}
}
}
}


private void MySqlCatchup()
{
var mySqlConn = new MySqlConnection();
Expand Down Expand Up @@ -6708,7 +6829,6 @@ public class DiaryData
{
[PrimaryKey]
public DateTime Timestamp { get; set; }

public string entry { get; set; }
public int snowFalling { get; set; }
public int snowLying { get; set; }
Expand Down
11 changes: 4 additions & 7 deletions CumulusMX/CumulusMX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@
<Reference Include="Devart.Data.MySql">
<HintPath>..\packages\Devart.Data.MySql.dll</HintPath>
</Reference>
<Reference Include="fastJSON, Version=2.2.0.0, Culture=neutral, PublicKeyToken=6b75a806b86095cd, processorArchitecture=MSIL">
<HintPath>..\packages\fastJSON.2.2.0.1\lib\net40\fastJSON.dll</HintPath>
<Reference Include="FluentFTP, Version=19.2.3.0, Culture=neutral, PublicKeyToken=f4af092b1d8df44f, processorArchitecture=MSIL">
<HintPath>..\packages\FluentFTP.19.2.3\lib\net45\FluentFTP.dll</HintPath>
</Reference>
<Reference Include="FluentFTP, Version=19.2.2.0, Culture=neutral, PublicKeyToken=f4af092b1d8df44f, processorArchitecture=MSIL">
<HintPath>..\packages\FluentFTP.19.2.2\lib\net45\FluentFTP.dll</HintPath>
</Reference>
<Reference Include="HidSharp, Version=2.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HidSharp.2.0.5\lib\net35\HidSharp.dll</HintPath>
<Reference Include="HidSharp, Version=2.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HidSharp.2.0.8\lib\net35\HidSharp.dll</HintPath>
</Reference>
<Reference Include="LinqToTwitter.AspNet, Version=3.1.1.15391, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
14 changes: 7 additions & 7 deletions CumulusMX/DataEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using fastJSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -15,12 +15,12 @@ internal class DataEditor
{
private WeatherStation station;
private Cumulus cumulus;

internal DataEditor(Cumulus cumulus, WeatherStation station)
{
this.station = station;
this.cumulus = cumulus;

}

//internal string EditRainToday(HttpListenerContext context)
Expand All @@ -37,7 +37,7 @@ internal string EditRainToday(IHttpContext context)
string[] kvPair = text.Split('=');
string key = kvPair[0];
string raintodaystring = kvPair[1];

if (!String.IsNullOrEmpty(raintodaystring))
{
try
Expand Down Expand Up @@ -69,7 +69,7 @@ internal string GetRainTodayEditData()
var json = "{\"raintoday\":\"" + station.RainToday.ToString(cumulus.RainFormat, InvC) +
"\",\"raincounter\":\"" + station.Raincounter.ToString(cumulus.RainFormat, InvC) +
"\",\"startofdayrain\":\"" + station.raindaystart.ToString(cumulus.RainFormat, InvC) +
"\",\"rainmult\":\"" + cumulus.RainMult.ToString("F3", InvC) +
"\",\"rainmult\":\"" + cumulus.RainMult.ToString("F3", InvC) +
"\",\"step\":\"" + step + "\"}";

return json;
Expand All @@ -87,7 +87,7 @@ internal string EditDiary(IHttpContext context)
text = reader.ReadToEnd();
}

var newData = JSON.ToObject<DiaryData>(text);
var newData = JsonConvert.DeserializeObject<DiaryData>(text);

// write new/updated entry to the database
var result = cumulus.DiaryDB.InsertOrReplace(newData);
Expand All @@ -114,7 +114,7 @@ internal string DeleteDiary(IHttpContext context)
text = reader.ReadToEnd();
}

var record = JSON.ToObject<DiaryData>(text);
var record = JsonConvert.DeserializeObject<DiaryData>(text);

// Delete the corresponding entry from the database
var result = cumulus.DiaryDB.Delete(record);
Expand Down
Loading

0 comments on commit 7715899

Please sign in to comment.