Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Fixes for Classic with git changes, Added Checksums for files, Fixed …
Browse files Browse the repository at this point in the history
…Crashing, Version increment, Added Motorshield change for Classic
  • Loading branch information
dexslab committed Mar 13, 2020
1 parent 1bb4fcf commit 9a56cfe
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 26 deletions.
23 changes: 20 additions & 3 deletions Models/BaseStationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using ArduinoUploader.Hardware;
Expand All @@ -18,6 +19,8 @@ public struct Config
public List<Board> SupportedBoards { get; set; }
public List<MotorShield> SupportedMotorShields { get; set; }
public string DisplayName { get; set; }


}

public struct Dependency
Expand All @@ -26,6 +29,8 @@ public struct Dependency

public string Link { get; set; }
public string FileName { get; set; }

public string checksum { get; set; }
}

public static class BaseStationSettings
Expand All @@ -41,7 +46,7 @@ public static class BaseStationSettings
Dependencies = new List<Dependency>()
{
new Dependency{Name = "platformio", FileName = "get-platformio.py", Link = "https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py" },
new Dependency{Name = "python", FileName = "python.zip", Link = "https://www.python.org/ftp/python/3.8.2/python-3.8.2-embed-amd64.zip" }
new Dependency{Name = "python", FileName = "python.zip", Link = "https://www.python.org/ftp/python/3.8.2/python-3.8.2-embed-amd64.zip", checksum = "1a98565285491c0ea65450e78afe6f8d" }
},
InitCommand = "platformio init",
BuildCommand = "platformio run",
Expand All @@ -63,10 +68,10 @@ public static class BaseStationSettings
{
Name = "BaseStationClassic",
DisplayName = "Base Station Classic",
Git = "https://github.com/DCC-EX/BaseStationClassic.git",
Git = "https://github.com/DCC-EX/BaseStation-Classic.git",
Dependencies = new List<Dependency>()
{
new Dependency{ Name = "arduino-1.8.12", FileName = "arduino-1.8.12.zip", Link = "https://downloads.arduino.cc/arduino-1.8.12-windows.zip" }
new Dependency{ Name = "arduino-1.8.12", FileName = "arduino-1.8.12.zip", Link = "https://downloads.arduino.cc/arduino-1.8.12-windows.zip", checksum = "92471d21a38c33a8095dc243cd7e8e28" }
},
//BuildCommand = $@"{ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\arduino-builder -compile -logger=machine -hardware { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware -tools { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\tools-builder -tools { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -built-in-libraries { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\libraries -fqbn=arduino:avr:uno -ide-version=10812 -build-path { Directory.GetCurrentDirectory()}\BaseStationClassic\Build -warnings=all -build-cache { Directory.GetCurrentDirectory()}\BaseStationClassic\Cache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avrdude.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -verbose { Directory.GetCurrentDirectory()}\BaseStationClassic\DCCpp\DCCpp.ino",
BuildCommand = $@"-compile -logger=machine -hardware { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware -tools { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\tools-builder -tools { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -built-in-libraries { Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\libraries -fqbn={{0}} -ide-version=10812 -build-path { Directory.GetCurrentDirectory()}\BaseStationClassic\Build -warnings=all -build-cache { Directory.GetCurrentDirectory()}\BaseStationClassic\Cache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avrdude.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path={ Directory.GetCurrentDirectory()}\arduino-1.8.12\arduino-1.8.12\hardware\tools\avr -verbose { Directory.GetCurrentDirectory()}\BaseStationClassic\DCCpp\DCCpp.ino",
Expand Down Expand Up @@ -124,5 +129,17 @@ public static string GetWiringDiagram(ArduinoModel model, MotorShieldType type)
}
return wiringDiagram;
}

public static string CalculateMD5(string filename)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
109 changes: 88 additions & 21 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace BaseStationInstaller.ViewModels

{
public class MainWindowViewModel : ViewModelBase
public class MainWindowViewModel : ViewModelBase, IArduinoUploaderLogger
{
public MainWindowViewModel()
{
Expand Down Expand Up @@ -327,20 +327,28 @@ private async Task DownloadPreReqs()
{
if (!Directory.Exists($@".\{dep.Name}") && dep.FileName.Contains(".zip"))
{
ZipFile.ExtractToDirectory($@"./{dep.FileName}", $@"./{dep.Name}");
if (dep.checksum.Equals(BaseStationSettings.CalculateMD5($@"./{dep.Name}"))) {
ZipFile.ExtractToDirectory($@"./{dep.FileName}", $@"./{dep.Name}");
}
else
{
File.Delete($@"./{dep.Name}");
Busy = false;
RefreshingPorts = false;
Thread.Sleep(5000);
Status = "Prequisite download failed please try again";
CommandManager.InvalidateRequerySuggested();
return;
}
}
}
}
Status = $"Gitting {SelectedConfig.DisplayName}";
await GitCode();
if (SelectedConfig.Name == "BaseStation")
{
GetPlatformIO();
}
else if (SelectedConfig.Name == "BaseStationClassic")
{
CompileSketch();
}
await GitCode();
}

private void GetPlatformIO()
Expand Down Expand Up @@ -369,6 +377,15 @@ private void GetPlatformIO()

private void CompileSketch()
{
Status = "Changing MotorShield options";
Progress = 5;
string[] config = File.ReadAllLines(@".\BaseStationClassic\DCCpp\Config.h");
Progress = 10;
config[16] = $"#define MOTOR_SHIELD_TYPE {(int)SelectedMotorShield.ShieldType}";
Progress = 15;
File.WriteAllLines(@".\BaseStationClassic\DCCpp\Config.h", config);
Progress = 20;
Thread.Sleep(1000);
Status = "Compiling Base Station Classic Sketch";

if (!Directory.Exists(@".\BaseStationClassic\Build"))
Expand All @@ -387,38 +404,38 @@ private void CompileSketch()
start.WindowStyle = ProcessWindowStyle.Hidden;
Process process = new Process();
process.StartInfo = start;
//process.Start();
//process.WaitForExit();
process.Start();
process.WaitForExit();
Progress = 50;
start.Arguments = String.Format($@"{SelectedConfig.BuildCommand}", SelectedBoard.FQBN);
Console.WriteLine(start.Arguments);
//process.Start();
//process.WaitForExit();
process.Start();
process.WaitForExit();
Status = $"Compilation Complete";
RefreshingPorts = true;
Thread.Sleep(1000);
Status = $"Uploading to {SelectedComPort}";
Progress = 75;
if (File.Exists(@"./upload.log"))
{
File.Delete(@"./upload.log");
}
ArduinoSketchUploader uploader = new ArduinoSketchUploader(
new ArduinoSketchUploaderOptions()
{
FileName = $@"{Directory.GetCurrentDirectory()}\BaseStationClassic\Build\DCCpp.ino.hex",
PortName = SelectedComPort,
ArduinoModel = SelectedBoard.Platform
});
},this);
try
{
uploader.UploadSketch();
Status = "Upload Completed Successfully";
Status = "Upload Completed Successfully. Please check upload.log for more details";
}
catch (Exception e)
{
Status = "Upload Failed!!! Please check upload.log for more details";
if (File.Exists(@"./upload.log"))
{
File.Delete(@"./upload.log");
}
File.WriteAllText(@"./upload.log", $"Message: {e.Message} {Environment.NewLine} StackTrace: {e.StackTrace}");
Status = "Upload Failed!!! Please check upload.log for more details";
File.AppendAllText(@"./upload.log", $"Message: {e.Message} {Environment.NewLine} StackTrace: {e.StackTrace}");
}
Progress = 100;
Thread.Sleep(1000);
Expand Down Expand Up @@ -449,19 +466,69 @@ private void Client_DownloadFileCompleted(object sender, System.ComponentModel.A

private async Task GitCode()
{
CloneOptions options = new CloneOptions();
options.RepositoryOperationCompleted = new LibGit2Sharp.Handlers.RepositoryOperationCompleted(GotCode);
Progress = 0;
if (!Directory.Exists($"./{SelectedConfig.Name}"))
{
Repository.Clone(SelectedConfig.Git, $"./{SelectedConfig.Name}");
Repository.Clone(SelectedConfig.Git, $"./{SelectedConfig.Name}", options);
} else
{
if (!Repository.IsValid($"./{SelectedConfig.Name}") )
{
Directory.Delete($"./{SelectedConfig.Name}",true);
Repository.Clone(SelectedConfig.Git, $"./{SelectedConfig.Name}", options);
}
else
{
CompileSketch();
}
}

}

private void GotCode(RepositoryOperationContext context)
{
if (SelectedConfig.Name.Equals("BaseStationClassic")) {
CompileSketch();
}
}

private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Progress = e.ProgressPercentage;
}

#endregion
public void Error(string message, Exception e)
{
File.AppendAllText(@"./upload.log", $"Message: {e.Message} {Environment.NewLine} StackTrace: {e.StackTrace}");
}

public void Warn(string message)
{
File.AppendAllText(@"./upload.log", $"{message}{Environment.NewLine}");
}

public void Info(string message)
{
Status = message;
File.AppendAllText(@"./upload.log", $"{message}{Environment.NewLine}");
}

public void Debug(string message)
{
#if DEBUG
File.AppendAllText(@"./upload.log", $"{message}");
#endif
}

public void Trace(string message)
{
#if DEBUG
File.AppendAllText(@"./upload.log", $"{message}");
#endif
}

#endregion
}
}

0 comments on commit 9a56cfe

Please sign in to comment.