Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b63537b
Initial Commit. For Automation of firmware updatation
codedecoded01723 Dec 27, 2024
7a209ad
Initial commit for tickets #25 and #80
codedecoded01723 Dec 30, 2024
e63fdbd
Relsolved the renaming a logging session
codedecoded01723 Jan 17, 2025
d10ba1d
Included tickets
codedecoded01723 Jan 17, 2025
56b3a86
Merge branch 'feat-check-firmware-version-and-update-firmware-if-nece…
codedecoded01723 Jan 17, 2025
ffeed32
Merge branch 'main' into feat-renaming-a-logging-session-does-not-per…
tylerkron Jan 21, 2025
5cbd485
Merge branch 'main' into feat-check-firmware-version-and-update-firmw…
codedecoded01723 Jan 22, 2025
f5b6cb5
Merge branch 'feat-renaming-a-logging-session-does-not-persist(#90)' …
codedecoded01723 Jan 22, 2025
925f89c
When export file name is not changing :fixed
codedecoded01723 Jan 22, 2025
c8d9cb7
Merge branch 'feat-renaming-a-logging-session-does-not-persist(#90)' …
codedecoded01723 Jan 22, 2025
89bbc1e
All required small changes and pending tickets included of MS1 and MS2 .
codedecoded01723 Jan 22, 2025
7e657e2
Tried to manage the serial device manager exceptions .
codedecoded01723 Jan 25, 2025
b09ef92
Merge branch 'main' into feat-check-firmware-version-and-update-firmw…
Jan 25, 2025
e27a391
A few small refactors
Jan 25, 2025
ae453ef
A little more refactoring
Jan 26, 2025
5bb06fb
scpi commands need a carriage return and a new line. These were missing.
Jan 27, 2025
1301b61
a few cleanup updates. Needs a few more updates before a PR
Jan 27, 2025
0d551a9
updated to wix5
tylerkron Feb 1, 2025
65f5554
switched to x64
tylerkron Feb 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Daqifi.Desktop.Bootloader/Daqifi.Desktop.Bootloader.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="hidlibrary" Version="3.3.40" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Daqifi.Desktop.Common\Daqifi.Desktop.Common.csproj" />
</ItemGroup>

</Project>
68 changes: 68 additions & 0 deletions Daqifi.Desktop.Bootloader/FirmwareDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Daqifi.Desktop.Common.Loggers;
using Newtonsoft.Json.Linq;

namespace Daqifi.Desktop.Bootloader;

public class FirmwareDownloader
{
private const string FirmwareApiUrl = "https://api.github.com/repos/daqifi/daqifi-nyquist-firmware/releases";
private readonly AppLogger _appLogger = AppLogger.Instance;

public string Download()
{
try
{
var handler = new HttpClientHandler { AllowAutoRedirect = true };
using var client = new HttpClient(handler);
client.DefaultRequestHeaders.UserAgent.ParseAdd("DaqifiFirmwareUpdater/1.0");

var response = client.GetAsync(FirmwareApiUrl).Result;
if (!response.IsSuccessStatusCode)
{
_appLogger.Error($"Failed to fetch firmware release info. Status Code: {response.StatusCode}");
return string.Empty;
}

var jsonResponse = response.Content.ReadAsStringAsync().Result;
var releaseData = JArray.Parse(jsonResponse);
var latestRelease = releaseData.FirstOrDefault();
var assets = latestRelease["assets"] as JArray;
var hexFileAsset = assets?.FirstOrDefault(a => a["name"]?.ToString().EndsWith(".hex") == true);

if (hexFileAsset == null)
{
_appLogger.Error("No .hex firmware file found in the release assets.");
return string.Empty;
}

var firmwareDownloadUrl = hexFileAsset["browser_download_url"]?.ToString();
var fileName = hexFileAsset["name"]?.ToString();
var daqifiFolderPath = Path.Combine(Path.GetTempPath(), "DAQiFi");
Directory.CreateDirectory(daqifiFolderPath);
var filePath = Path.Combine(daqifiFolderPath, fileName);

if (File.Exists(filePath))
{
File.Delete(filePath);
}

var hexFileResponse = client.GetAsync(firmwareDownloadUrl).Result;
if (!hexFileResponse.IsSuccessStatusCode)
{
_appLogger.Error($"Failed to download firmware file. Status Code: {hexFileResponse.StatusCode}");
return null;
}

using var contentStream = hexFileResponse.Content.ReadAsStream();
using var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
contentStream.CopyTo(fileStream);

return filePath;
}
catch (Exception ex)
{
_appLogger.Error("Error while downloading firmware: " + ex.Message);
return string.Empty;
}
}
}
5 changes: 0 additions & 5 deletions Daqifi.Desktop.Bootloader/Pic32Bootloader.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using HidLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;

namespace Daqifi.Desktop.Bootloader
{
Expand Down
114 changes: 114 additions & 0 deletions Daqifi.Desktop.Bootloader/WiFiDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System.ComponentModel;
using Daqifi.Desktop.Common.Loggers;
using Newtonsoft.Json.Linq;
using System.IO.Compression;

namespace Daqifi.Desktop.Bootloader;

public class WiFiDownloader
{
private const string GithubApiUrl = "https://api.github.com/repos/daqifi/winc1500-Manual-UART-Firmware-Update/releases/latest";
private const string UserAgent = "Mozilla/5.0 (compatible; DAQiFiApp/1.0)";
private readonly AppLogger _appLogger = AppLogger.Instance;

public async Task<(string extractFolderPath, string latestVersion)> DownloadAndExtractWiFiAsync(
BackgroundWorker backgroundWorker)
{
var daqifiFolderPath = Path.Combine(Path.GetTempPath(), "DAQiFi");
try
{
using var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
var response = await client.GetAsync(GithubApiUrl);

if (!response.IsSuccessStatusCode)
{
_appLogger.Error($"Failed to fetch GitHub API data. Status Code: {response.StatusCode}");
return (string.Empty, string.Empty);
}

var jsonResponse = await response.Content.ReadAsStringAsync();
var releaseData = JObject.Parse(jsonResponse);

var latestVersion = releaseData["tag_name"]?.ToString()?.Trim();
var zipballUrl = releaseData["zipball_url"]?.ToString();

if (string.IsNullOrEmpty(zipballUrl))
{
_appLogger.Error("No zipball URL found for the latest release.");
return (string.Empty, string.Empty);
}

backgroundWorker.ReportProgress(10, "Starting download...");

var zipFileName = $"daqifi-winc1500-Manual-UART-Firmware-Update-{latestVersion}.zip";
var zipFilePath = Path.Combine(daqifiFolderPath, zipFileName);

try
{
using var zipResponse = await client.GetAsync(zipballUrl);
await using var contentStream = await zipResponse.Content.ReadAsStreamAsync();
await using var fileStream = new FileStream(zipFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
if (zipResponse.IsSuccessStatusCode)
{
var totalBytes = zipResponse.Content.Headers.ContentLength ?? 1;
long bytesRead = 0;
var buffer = new byte[8192];

int read;
while ((read = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
fileStream.Write(buffer, 0, read);
bytesRead += read;
int progress = (int)((double)bytesRead / totalBytes * 50) + 10;
backgroundWorker.ReportProgress(progress, $"Downloading... {progress}%");
}
}
else
{
throw new Exception("Failed to download the zipball file.");
}
}
catch (Exception ex)
{
_appLogger.Error($"Error during download: {ex.Message}");
return (string.Empty, string.Empty);
}

backgroundWorker.ReportProgress(70, "Extracting files...");

string extractFolderPath =
Path.Combine(daqifiFolderPath, $"daqifi-winc1500-Manual-UART-Firmware-Update-{latestVersion}");

if (Directory.Exists(extractFolderPath))
{
await Task.Delay(500);

for (int i = 0; i < 3; i++)
{
try
{
Directory.Delete(extractFolderPath, true);
break;
}
catch (IOException)
{
if (i == 2) throw;

Check failure on line 96 in Daqifi.Desktop.Bootloader/WiFiDownloader.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Daqifi.Desktop.Bootloader/WiFiDownloader.cs#L96

Add curly braces around the nested statement(s) in this 'if' block.
await Task.Delay(500);
}
}
}

Directory.CreateDirectory(extractFolderPath);
ZipFile.ExtractToDirectory(zipFilePath, extractFolderPath);

backgroundWorker.ReportProgress(100, "Extraction completed.");
return (extractFolderPath, latestVersion);
}
catch (Exception ex)
{
_appLogger.Error($"Error: {ex.Message}");
return (string.Empty, string.Empty);
}
}
}
23 changes: 13 additions & 10 deletions Daqifi.Desktop.Common/Daqifi.Desktop.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bugsnag.AspNet.Core" Version="3.1.0" />
<PackageReference Include="NLog" Version="5.0.1" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bugsnag.AspNet.Core" Version="3.1.0" />
<PackageReference Include="NLog" Version="5.0.1" />
</ItemGroup>

</Project>
15 changes: 9 additions & 6 deletions Daqifi.Desktop.DataModel/Daqifi.Desktop.DataModel.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
</PropertyGroup>
</Project>
4 changes: 3 additions & 1 deletion Daqifi.Desktop.DataModel/Device/DeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
{
public class DeviceInfo
{
public string DeviceName { get; set; }

Check warning on line 5 in Daqifi.Desktop.DataModel/Device/DeviceInfo.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'DeviceName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string IpAddress { get; set; }

Check warning on line 7 in Daqifi.Desktop.DataModel/Device/DeviceInfo.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'IpAddress' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string MacAddress { get; set; }

Check warning on line 9 in Daqifi.Desktop.DataModel/Device/DeviceInfo.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'MacAddress' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public uint Port { get; set; }

public bool IsPowerOn { get; set; }

public string DeviceSerialNo { get; set; }

Check warning on line 15 in Daqifi.Desktop.DataModel/Device/DeviceInfo.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'DeviceSerialNo' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string DeviceVersion { get; set; }

Check warning on line 17 in Daqifi.Desktop.DataModel/Device/DeviceInfo.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'DeviceVersion' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
28 changes: 16 additions & 12 deletions Daqifi.Desktop.IO/Daqifi.Desktop.IO.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.28.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Daqifi.Desktop.Common\Daqifi.Desktop.Common.csproj" />
<ProjectReference Include="..\Daqifi.Desktop.DataModel\Daqifi.Desktop.DataModel.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.28.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Daqifi.Desktop.Common\Daqifi.Desktop.Common.csproj" />
<ProjectReference Include="..\Daqifi.Desktop.DataModel\Daqifi.Desktop.DataModel.csproj" />
</ItemGroup>
</Project>
26 changes: 25 additions & 1 deletion Daqifi.Desktop.IO/Messages/Producers/ScpiMessagePoducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static class ScpiMessagePoducer
public static IMessage Reboot => new ScpiMessage("SYSTem:REboot");
public static IMessage SystemInfo => new ScpiMessage("SYSTem:SYSInfoPB?");

public static IMessage ForceBootloader => new ScpiMessage("SYSTem:FORceBoot");

public static IMessage Echo(int echo)
{
Expand Down Expand Up @@ -196,7 +197,12 @@ public static IMessage SetPassword(string password)
{
return new ScpiMessage($"SYSTem:COMMunicate:LAN:PASs \"{password}\"");
}


public static IMessage EnabledLan()
{
return new ScpiMessage("SYSTem:COMMunicate:LAN:ENabled 1");
}

public static IMessage ApplyLan()
{
return new ScpiMessage("SYSTem:COMMunicate:LAN:APPLY");
Expand All @@ -206,6 +212,24 @@ public static IMessage SaveLan()
{
return new ScpiMessage("SYSTem:COMMunicate:LAN:SAVE");
}

public static IMessage SetLanFWUpdateMode()
{
return new ScpiMessage("SYSTem:COMMUnicate:LAN:FWUpdate");
}

public static IMessage GetWIFIModuleVersion()
{
return new ScpiMessage("SYSTem:COMMunicate:LAN:GETChipINFO");
}

#endregion

#region USB
public static IMessage SetUsbTransparencyMode(int mode)
{
return new ScpiMessage($"SYSTem:USB:SetTransparentMode {mode}");
}
#endregion
}
}
Loading
Loading