Commit 340ac129 authored by Oleg Nikulin's avatar Oleg Nikulin

Получение температуры нескольких дисков от hddtemp. Нужные диски указываются в конфиге

parent 312fe2d1
......@@ -3,6 +3,11 @@
"baudrate": 19200,
"pollIntervalSec": 2,
"arduinoTimeoutSec": 0.25,
"drives":
[
"/dev/nvme0n1"
],
"controlGroups":
[
{
......
......@@ -4,7 +4,7 @@ import termios
input_thread_running = False
initialized = False
temperatures = [30, 45, 50]
temperatures = [0] * 3
......@@ -156,7 +156,7 @@ if __name__ == "__main__":
if args.manual:
input_thread = threading.Thread(target = temp_input)
input_thread.daemon = True
temp = '50,51,52'
temperatures = [30, 45, 50]
if port is None:
print('Serial device is not specified (neither in config nor in command line)')
......@@ -165,6 +165,18 @@ if __name__ == "__main__":
print('Baudrate is not specified (neither in config nor in command line)')
exit()
if not args.manual:
drivesLen = len(config['drives'])
if drivesLen == 0:
print('No drives are specified in config. At least one drive must be specified')
exit()
if drivesLen > 3:
print(f'{drivesLen} drives are specified in config. Note that only 3 drives are supported, so only the first 3 will be used.')
if len(config['controlGroups']) != 3:
print('Incorrect number of control groups in config. There should be 3 control groups.')
exit()
serial_port = open_serial(port, baudrate)
......@@ -179,17 +191,31 @@ if __name__ == "__main__":
output = str(subprocess.Popen(['netcat', 'localhost', '7634'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT).communicate()[0]) #получаем output от hddtemp
#b'|/dev/sda2|ST340014A|41|C|'
if output == "b''":
print('Hddtemp output is empty, make sure it is running. If not, launch it with #hddtemp -d')
print('Hddtemp output is empty, make sure it is running. If not, launch it: #systemctl start hddtemp.service')
#exit()
#вычленяем значение температуры:
temp_pos_end = output.find('|C|')
temp_pos_start = output.rfind('|', 0, temp_pos_end) + 1
temp = output[temp_pos_start:temp_pos_end]
try:
temperatures[0] = int(temp)
except ValueError:
print('Error: Failed to get a temperature value from hddtemp output')
else:
driveCount = len(config['drives'])
if driveCount > 3:
driveCount = 3
for i in range(driveCount):
drive = config['drives'][i]
drive_pos = output.find(drive)
if drive_pos == -1:
print(f'Drive {drive} not found in hddtemp output')
continue
try:
#вычленяем значение температуры:
temp_pos_end = output.find('|C|', drive_pos)
if temp_pos_end == -1: raise ValueError
temp_pos_start = output.rfind('|', drive_pos, temp_pos_end) + 1
if temp_pos_start == -1: raise ValueError
temp = output[temp_pos_start:temp_pos_end]
temperatures[i] = int(temp)
except ValueError:
print(f'Failed to parse a temperature value from hddtemp output for drive {drive}')
continue
if (poll(serial_port)):
if args.manual and not input_thread_running:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment