Skip to content

Commit a166b39

Browse files
committed
Implement PawnIO driver + interface changes.
1 parent ffd3f8a commit a166b39

30 files changed

Lines changed: 1088 additions & 193 deletions

ConsoleOutputTest/ConsoleOutputTest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<ApplicationManifest>Resources\app.manifest</ApplicationManifest>
99
<Description>Sample application for RAMSPDToolkit.</Description>
1010
<Copyright>Florian K.</Copyright>
11-
<AssemblyVersion>1.2.2</AssemblyVersion>
12-
<FileVersion>1.2.2</FileVersion>
11+
<AssemblyVersion>1.3</AssemblyVersion>
12+
<FileVersion>1.3</FileVersion>
1313
<Version>$(AssemblyVersion)</Version>
1414
<Configurations>Debug;Release</Configurations>
1515
</PropertyGroup>

ConsoleOutputTest/TestClass.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ public void DoTest()
5151
//Check for Windows OS and load driver
5252
if (OperatingSystem.IsWindows())
5353
{
54-
//Init OLS driver
55-
DriverManager.InitDriver(InternalDriver.OLS);
56-
57-
//Check if OLS driver was initalized and could be loaded
58-
if (DriverManager.DriverImplementation == InternalDriver.OLS
59-
&& DriverManager.Driver.Load())
54+
//Init driver
55+
if (DriverManager.LoadDriver(DriverImplementation.WinRing0))
6056
{
61-
Log("***** Driver is open. *****");
57+
Log($"***** Driver {DriverManager.DriverImplementation} is open. *****");
6258
}
6359
else
6460
{
@@ -136,7 +132,7 @@ public void DoTest()
136132
if (OperatingSystem.IsWindows())
137133
{
138134
//Finished, must do cleanup
139-
DriverManager.Driver.Unload();
135+
DriverManager.UnloadDriver();
140136
Log("***** Closed driver. *****");
141137
}
142138
}

GZipSingleFile/GZipper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace GZipSingleFile
44
{
55
internal class GZipper
66
{
7-
public static void CompressFile(string source, string destination)
7+
public static void CompressFile(string source, string destination, bool trashByte)
88
{
99
using FileStream sourceFile = new(source, FileMode.Open);
1010
using FileStream targetFile = new(destination, FileMode.OpenOrCreate);
@@ -14,6 +14,11 @@ public static void CompressFile(string source, string destination)
1414
var buffer = new byte[1024];
1515
int read;
1616

17+
if (trashByte)
18+
{
19+
gzipStream.Write([7]);
20+
}
21+
1722
while ((read = sourceFile.Read(buffer, 0, buffer.Length)) > 0)
1823
{
1924
gzipStream.Write(buffer, 0, read);

GZipSingleFile/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void Main(string[] args)
2121

2222
Console.WriteLine($"Zipping file '{file}'");
2323

24-
GZipper.CompressFile(file, file + ".gz");
24+
GZipper.CompressFile(file, file + ".gz", false);
2525

2626
DoExit();
2727
}
@@ -31,4 +31,4 @@ static void DoExit()
3131
Console.WriteLine("Press enter to exit...");
3232
Console.ReadLine();
3333
}
34-
}
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright (c) 2025 Florian K.
7+
*
8+
* Code inspiration, improvements and fixes are from, but not limited to, following projects:
9+
* LibreHardwareMonitor; Linux Kernel; OpenRGB; WinRing0 (QCute)
10+
*/
11+
12+
using System.Collections;
13+
14+
namespace RAMSPDToolkit.Extensions
15+
{
16+
/// <summary>
17+
/// Extension class for <see cref="object"/>.
18+
/// </summary>
19+
public static class ObjectExtensions
20+
{
21+
/// <summary>
22+
/// Checks if the current object matches (Equals) any of the specified objects.
23+
/// </summary>
24+
/// <param name="obj">The current object.</param>
25+
/// <param name="value1">An object to check for equality.</param>
26+
/// <param name="value2">An object to check for equality.</param>
27+
/// <returns>If any specified object is equal to the current object.</returns>
28+
public static bool Any<T>(this T obj, T value1, T value2)
29+
{
30+
return obj.Equals(value1) || obj.Equals(value2);
31+
}
32+
33+
/// <summary>
34+
/// Checks if the current object matches (Equals) any of the specified objects.
35+
/// </summary>
36+
/// <param name="obj">The current object.</param>
37+
/// <param name="value1">An object to check for equality.</param>
38+
/// <param name="value2">An object to check for equality.</param>
39+
/// <param name="values">A variable list of objects to check for equality.</param>
40+
/// <returns>If any specified object is equal to the current object.</returns>
41+
public static bool Any<T>(this T obj, T value1, T value2, params T[] values)
42+
{
43+
if (Any(obj, value1, value2))
44+
return true;
45+
foreach (var o in values)
46+
if (obj.Equals(o))
47+
return true;
48+
return false;
49+
}
50+
51+
/// <summary>
52+
/// Checks if the current object matches (Equals) any of the objects in specified <see cref="IEnumerable"/>.
53+
/// </summary>
54+
/// <param name="obj">The current object.</param>
55+
/// <param name="collection">A collection of objects to check for equality.</param>
56+
/// <returns>If any object in <see cref="IEnumerable"/> is equal to the current object.</returns>
57+
public static bool Any<T>(this T obj, IEnumerable<T> collection)
58+
{
59+
foreach (var o in collection)
60+
if (obj.Equals(o))
61+
return true;
62+
return false;
63+
}
64+
}
65+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright (c) 2025 Florian K.
7+
*
8+
* Code inspiration, improvements and fixes are from, but not limited to, following projects:
9+
* LibreHardwareMonitor; Linux Kernel; OpenRGB; WinRing0 (QCute)
10+
*/
11+
12+
namespace RAMSPDToolkit.I2CSMBus.Interop.PawnIO
13+
{
14+
internal sealed class PawnIOConstants
15+
{
16+
public const string I801ModuleFilename = "SmbusI801.gz";
17+
public const string Piix4ModuleFilename = "SmbusPIIX4.gz";
18+
public const string NCT6793ModuleFilename = "SmbusNCT6793.gz";
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright (c) 2025 Florian K.
7+
*
8+
* Code inspiration, improvements and fixes are from, but not limited to, following projects:
9+
* LibreHardwareMonitor; Linux Kernel; OpenRGB; WinRing0 (QCute)
10+
*/
11+
12+
namespace RAMSPDToolkit.I2CSMBus.Interop.PawnIO
13+
{
14+
/// <summary>
15+
/// Identifies PawnIO SMBus type.
16+
/// </summary>
17+
public enum PawnIOSMBusIdentifier
18+
{
19+
I801,
20+
Piix4,
21+
NCT6793,
22+
}
23+
}

RAMSPDToolkit/I2CSMBus/Interop/Shared/SharedConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public sealed class SharedConstants
2626
public const int EPROTO = 134; //Protocol error
2727
public const int ETIMEDOUT = 138; //Connection timed out
2828

29+
public const int S_TIMEOUT = 2147024775;
30+
2931
internal const int MAX_RETRIES = 450;
3032

3133
/* PCI Address Constants */

RAMSPDToolkit/I2CSMBus/SMBusManager.cs

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
* LibreHardwareMonitor; Linux Kernel; OpenRGB; WinRing0 (QCute)
1010
*/
1111

12+
using RAMSPDToolkit.Extensions;
1213
using RAMSPDToolkit.Logging;
14+
using RAMSPDToolkit.Windows.Driver;
15+
using RAMSPDToolkit.Windows.Driver.Implementations;
1316
using OS = RAMSPDToolkit.Software.OperatingSystem;
1417

1518
namespace RAMSPDToolkit.I2CSMBus
@@ -21,7 +24,7 @@ public static class SMBusManager
2124
{
2225
#region Fields
2326

24-
static List<SMBusInterface> _RegisteredSMBuses = new List<SMBusInterface>();
27+
static List<SMBusInterface> _RegisteredSMBuses = new();
2528

2629
#endregion
2730

@@ -44,6 +47,26 @@ public static IReadOnlyList<SMBusInterface> RegisteredSMBuses
4447

4548
#region Public
4649

50+
/// <summary>
51+
/// Adds your own implementation of an instance of <see cref="SMBusInterface"/> to <see cref="RegisteredSMBuses"/>.
52+
/// </summary>
53+
/// <param name="smbus">SMBus instance to add.</param>
54+
public static void AddSMBus(SMBusInterface smbus)
55+
{
56+
_RegisteredSMBuses.Add(smbus);
57+
}
58+
59+
/// <summary>
60+
/// Removes specified instance of <see cref="SMBusInterface"/> from <see cref="RegisteredSMBuses"/>.
61+
/// </summary>
62+
/// <param name="smbus">SMBus instance to remove.</param>
63+
/// <returns>True if SMBus is successfully removed; otherwise false.<br/>
64+
/// This method also returns false if SMBus was not found in <see cref="RegisteredSMBuses"/>.</returns>
65+
public static bool RemoveSMBus(SMBusInterface smbus)
66+
{
67+
return _RegisteredSMBuses.Remove(smbus);
68+
}
69+
4770
/// <summary>
4871
/// Gets first SMBus in <see cref="RegisteredSMBuses"/> with specified type.
4972
/// </summary>
@@ -67,20 +90,29 @@ public static void DetectSMBuses()
6790

6891
if (OS.IsWindows())
6992
{
70-
//smbusDetectMethods.Add(I2CSMBusAmdAdl.SMBusDetect);
71-
72-
if (UseWMI)
93+
if (DriverManager.DriverImplementation == DriverImplementation.PawnIO)
7394
{
74-
smbusDetectMethods.Add(SMBusI801 .SMBusDetect);
75-
smbusDetectMethods.Add(SMBusPiix4.SMBusDetect);
95+
smbusDetectMethods.Add(SMBusPawnIO.SMBusDetect);
7696
}
7797
else
7898
{
79-
smbusDetectMethods.Add(WindowsSMBusDetector.DetectSMBuses);
99+
if (DriverManager.DriverImplementation.Any(DriverImplementation.WinRing0, DriverImplementation.Custom))
100+
{
101+
if (UseWMI)
102+
{
103+
smbusDetectMethods.Add(SMBusI801 .SMBusDetect);
104+
smbusDetectMethods.Add(SMBusPiix4.SMBusDetect);
105+
}
106+
else
107+
{
108+
smbusDetectMethods.Add(WindowsSMBusDetector.DetectSMBuses);
109+
}
110+
111+
//smbusDetectMethods.Add(I2CSMBusAmdAdl.SMBusDetect);
112+
//smbusDetectMethods.Add(SMBusNVAPI .SMBusDetect);
113+
smbusDetectMethods.Add(SMBusNCT6775.SMBusDetect);
114+
}
80115
}
81-
82-
//smbusDetectMethods.Add(SMBusNVAPI .SMBusDetect);
83-
smbusDetectMethods.Add(SMBusNCT6775.SMBusDetect);
84116
}
85117
else if (OS.IsLinux())
86118
{
@@ -96,14 +128,5 @@ public static void DetectSMBuses()
96128
}
97129

98130
#endregion
99-
100-
#region Internal
101-
102-
internal static void AddSMBus(SMBusInterface smbus)
103-
{
104-
_RegisteredSMBuses.Add(smbus);
105-
}
106-
107-
#endregion
108131
}
109132
}

0 commit comments

Comments
 (0)