Skip to content

Commit

Permalink
Service: get EC firmware version every time a new config is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparronator9999 committed Feb 16, 2025
1 parent ecb66d5 commit 8fcbd0d
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ protected override void OnStart(string[] args)
{
Log.Info(Strings.GetString("svcStarting"));

// Load the service config.
bool confLoaded = LoadConf();

// Install WinRing0 to get EC access
try
{
Expand All @@ -109,31 +106,8 @@ protected override void OnStart(string[] args)
}
Log.Info(Strings.GetString("drvLoadSuccess"));


if (confLoaded && Config.FirmVerSupported)
{
EcInfo = new();
if (_EC.ReadString(0xA0, 0xC, out string ecVer) && ecVer.Length == 0xC)
{
EcInfo.Version = ecVer;
Log.Debug($"EC firmware version: {ecVer}");
}
if (_EC.ReadString(0xAC, 0x10, out string ecDate) && ecDate.Length == 0x10)
{
try
{
string temp = $"{ecDate.Substring(4, 4)}-{ecDate.Substring(0, 2)}-{ecDate.Substring(2, 2)}" +
$"T{ecDate.Substring(8, 2).Replace(' ', '0')}:{ecDate.Substring(11, 2)}:{ecDate.Substring(14, 2)}";
EcInfo.Date = DateTime.ParseExact(temp, "s", CultureInfo.InvariantCulture);
Log.Debug($"EC firmware date: {EcInfo.Date:G}");
}
catch (FormatException ex)
{
Log.Error($"Failed to parse EC firmware date: {ex.Message}");
Log.Debug($"EC firmware date (raw): {ecDate}");
}
}
}
// Load the last applied YAMDCC config.
bool confLoaded = LoadConf();

// Set up IPC server
Log.Info("Starting IPC server...");
Expand Down Expand Up @@ -403,6 +377,32 @@ private bool LoadConf()
{
Config = YAMDCC_Config.Load(Paths.CurrentConf);
Log.Info(Strings.GetString("cfgLoaded"));

if (Config.FirmVerSupported)
{
EcInfo = new();
if (_EC.ReadString(0xA0, 0xC, out string ecVer) && ecVer.Length == 0xC)
{
EcInfo.Version = ecVer;
Log.Debug($"EC firmware version: {ecVer}");
}
if (_EC.ReadString(0xAC, 0x10, out string ecDate) && ecDate.Length == 0x10)
{
try
{
string temp = $"{ecDate.Substring(4, 4)}-{ecDate.Substring(0, 2)}-{ecDate.Substring(2, 2)}" +
$"T{ecDate.Substring(8, 2).Replace(' ', '0')}:{ecDate.Substring(11, 2)}:{ecDate.Substring(14, 2)}";
EcInfo.Date = DateTime.ParseExact(temp, "s", CultureInfo.InvariantCulture);
Log.Debug($"EC firmware date: {EcInfo.Date:G}");
}
catch (FormatException ex)
{
Log.Error($"Failed to parse EC firmware date: {ex.Message}");
Log.Debug($"EC firmware date (raw): {ecDate}");
}
}
}

return true;
}
catch (Exception ex)
Expand Down

0 comments on commit 8fcbd0d

Please sign in to comment.