|
| 1 | +Steps to run: |
| 2 | +1. gcc -shared -o libdummy_ectool.so -fPIC dummy_ectool.c |
| 3 | +2. python3 fw-fanctrl.py |
| 4 | + |
| 5 | +# Explanation of Files |
| 6 | +## fw-fanctrl.py |
| 7 | +This is the Python main script that works with the dummy_ectool library. It does the following: |
| 8 | +1. Declares functions to read and write the fan speed. |
| 9 | +2. Declares a function to read the fan status. |
| 10 | +3. Contains an example usage block that shows how to call the functions. |
| 11 | + |
| 12 | +## dummy_ectool.py |
| 13 | +This Python script is a wrapper of the libdummy_ectool.so shared library. It: |
| 14 | +1. Loads the shared library using the ctypes module. |
| 15 | +2. Specifies the C function signatures (i.e., argument types and return types). |
| 16 | +3. Offers Python functions that invoke the respective C functions. |
| 17 | + |
| 18 | +## dummy_ectool.c |
| 19 | +This is a C source file that performs the fan control logic. It: |
| 20 | +1. Declares functions to obtain and set the fan speed. |
| 21 | +2. Declares a function to retrieve the fan status. |
| 22 | +3. Utilizes a global variable to emulate the fan speed. |
| 23 | + |
| 24 | +# How the Program Works |
| 25 | +The dummy_ectool.c source file is compiled into a shared library (libdummy_ectool.so) with the gcc compiler. The flags: |
| 26 | + |
| 27 | +-shared: Instructs the compiler to produce a shared library. |
| 28 | +-fPIC: Produces position-independent code, which is necessary for shared libraries. |
| 29 | + |
| 30 | +The dummy_ectool.py script imports the shared library with ctypes.CDLL() and declares the function signatures for the C functions. It also declares argument types and return types. |
| 31 | + |
| 32 | +The fw-fanctrl.py command loads the dummy_ectool module, through which the access to the C functions is allowed. The program then: |
| 33 | + |
| 34 | +Displays the fan status and current speed. |
| 35 | +Sets the fan speed to 3000 RPM and displays the new fan status and speed. |
| 36 | +Tries to set the fan speed to 6000 RPM, causing an error due to the correct range being 0-5000 RPM. This checks for the error handling. |
| 37 | + |
| 38 | +THIS IS ONLY A PROOF OF CONCEPT FOR GSOC AND LARGE SCALE IMPLEMENTATION WILL FOLLOW THROUGH. |
0 commit comments