mirror of
https://github.com/AndrewX192/lenovo-sa120-fanspeed-utility
synced 2025-12-06 01:23:19 +00:00
Merge pull request #5 from kroy-the-rabbit/master
Allows script to set fan speed on multiple enclosures
This commit is contained in:
@@ -33,51 +33,49 @@ for chk_device in devices_to_check:
|
|||||||
out = check_output(["sg_ses", dev_node], stderr=STDOUT)
|
out = check_output(["sg_ses", dev_node], stderr=STDOUT)
|
||||||
if 'ThinkServerSA120' in out:
|
if 'ThinkServerSA120' in out:
|
||||||
device = dev_node
|
device = dev_node
|
||||||
break
|
print("Enclosure found on " + device);
|
||||||
|
|
||||||
|
print_speeds(device)
|
||||||
|
print("Reading current configuration...")
|
||||||
|
out = check_output(["sg_ses", "-p", "0x2", device, "--raw"]).decode('utf-8')
|
||||||
|
s = out.split()
|
||||||
|
|
||||||
|
for i in range(0, 6):
|
||||||
|
print("Setting fan {} to {}".format(i, fan))
|
||||||
|
idx = 88 + 4 * i
|
||||||
|
s[idx+0] = "80"
|
||||||
|
s[idx+1] = "00"
|
||||||
|
s[idx+2] = "00"
|
||||||
|
s[idx+3] = format(1 << 5 | fan & 7, "x")
|
||||||
|
|
||||||
|
output = StringIO()
|
||||||
|
off = 0
|
||||||
|
count = 0
|
||||||
|
line = ''
|
||||||
|
|
||||||
|
while True:
|
||||||
|
output.write(s[off])
|
||||||
|
off = off + 1
|
||||||
|
count = count + 1
|
||||||
|
if count == 8 :
|
||||||
|
output.write(" ")
|
||||||
|
elif count == 16:
|
||||||
|
output.write("\n")
|
||||||
|
count=0
|
||||||
|
else:
|
||||||
|
output.write(" ")
|
||||||
|
if off >= len(s):
|
||||||
|
break
|
||||||
|
|
||||||
|
output.write("\n")
|
||||||
|
p = Popen(['sg_ses', '-p', '0x2', device, '--control', '--data', '-'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
|
||||||
|
print("Set fan speeds... Waiting to get fan speeds (ctrl+c to skip)")
|
||||||
|
print(p.communicate(input=bytearray(output.getvalue(), 'utf-8'))[0].decode('utf-8'))
|
||||||
|
time.sleep(10)
|
||||||
|
print_speeds(device)
|
||||||
except:
|
except:
|
||||||
print("Enclosure not found on " + dev_node)
|
print("Enclosure not found on " + dev_node)
|
||||||
|
|
||||||
if device == "":
|
if device == "":
|
||||||
print("Could not find enclosure")
|
print("Could not find enclosure")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("Enclosure found on " + device);
|
|
||||||
|
|
||||||
print_speeds(device)
|
|
||||||
print("Reading current configuration...")
|
|
||||||
out = check_output(["sg_ses", "-p", "0x2", device, "--raw"]).decode('utf-8')
|
|
||||||
s = out.split()
|
|
||||||
|
|
||||||
for i in range(0, 6):
|
|
||||||
print("Setting fan {} to {}".format(i, fan))
|
|
||||||
idx = 88 + 4 * i
|
|
||||||
s[idx+0] = "80"
|
|
||||||
s[idx+1] = "00"
|
|
||||||
s[idx+2] = "00"
|
|
||||||
s[idx+3] = format(1 << 5 | fan & 7, "x")
|
|
||||||
|
|
||||||
output = StringIO()
|
|
||||||
off = 0
|
|
||||||
count = 0
|
|
||||||
line = ''
|
|
||||||
|
|
||||||
while True:
|
|
||||||
output.write(s[off])
|
|
||||||
off = off + 1
|
|
||||||
count = count + 1
|
|
||||||
if count == 8 :
|
|
||||||
output.write(" ")
|
|
||||||
elif count == 16:
|
|
||||||
output.write("\n")
|
|
||||||
count=0
|
|
||||||
else:
|
|
||||||
output.write(" ")
|
|
||||||
if off >= len(s):
|
|
||||||
break
|
|
||||||
|
|
||||||
output.write("\n")
|
|
||||||
p = Popen(['sg_ses', '-p', '0x2', device, '--control', '--data', '-'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
|
|
||||||
print("Set fan speeds... Waiting to get fan speeds (ctrl+c to skip)")
|
|
||||||
print(p.communicate(input=bytearray(output.getvalue(), 'utf-8'))[0].decode('utf-8'))
|
|
||||||
time.sleep(10)
|
|
||||||
print_speeds(device)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user