Mentor: Carlos Fernandez
-
Compile the C source code into a shared library:
gcc -shared -o libdummy_ectool.so -fPIC dummy_ectool.c
-
Run the Python script:
python3 fw-fanctrl.py
This is the Python main script that works with the dummy_ectool
library.
It does the following:
- Declares functions to read and write the fan speed.
- Declares a function to read the fan status.
- Contains an example usage block that shows how to call the functions.
This Python script is a wrapper for the libdummy_ectool.so
shared library, as it:
- Loads the shared library using the
ctypes
module. - Specifies the C function signatures (i.e., argument types and return types).
- Offers Python functions that invoke the respective C functions.
This is a C source file that performs the fan control logic, as it:
- Declares functions to obtain and set the fan speed.
- Declares a function to retrieve the fan status.
- Utilizes a global variable to emulate the fan speed.
The dummy_ectool.c
source file is compiled into a shared library (libdummy_ectool.so
) with the gcc
compiler. The flags:
-shared
: Instructs the compiler to produce a shared library.-fPIC
: Produces position-independent code, which is necessary for shared libraries.
The dummy_ectool.py
script imports the shared library with ctypes.CDLL()
and declares the function signatures for the C functions. It also specifies argument types and return types.
The fw-fanctrl.py
script loads the dummy_ectool
module, allowing access to the C functions. The program follows through with testing:
- Displays the fan status and current speed.
- Sets the fan speed to 3000 RPM and displays the new fan status and speed.
- Attempts to set the fan speed to 6000 RPM, causing an error due to the correct range being 0-5000 RPM. This step tests the error handling mechanism.
This is only a proof of concept, large scale implementation will follow through.