Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Improved stability, code cleanup, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MARTINrichard05 committed Jun 29, 2024
1 parent da98d3e commit e11d91e
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 62 deletions.
76 changes: 55 additions & 21 deletions daemon/RyzenTuningDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,50 @@
key = sys.argv[1]
user = sys.argv[2]

if sys.argv[3] == "1":
verbose = True
else:
verbose = False

print("Verbose mode :", verbose)

workingDir = "/home/"+user+"/.var/app/com.nyaker.RyzenTuningUtility/daemon"

address = ('localhost', 6000)

listener = Listener(address, authkey=bytes(key, 'ascii'))

backupvals = {}
timeout = 0.02
cmdout_buffer = []

def logg(msg,cat):
'''cat 0 : full running log, cat 1 : info, 2 : warning, 3 : error, 4 : debug'''
if verbose != "0":
if cat == 0:
print(str(msg))
if cat > 0 and cat < 5:
cats = ["INFO", "WARNING", "ERROR", "DEBUG"]
if cat >= verbose:
print("["+cats[cat-1]+"] : "+str(msg))

def getraw(value):
# if we have read this value
global cmdout_buffer
cmdout = None

rawoutput = None
try:
cmdout = subprocess.check_output([workingDir+'/ryzenadj/ryzenadj', '-i']).decode('utf-8').split('\n')
except:
return backupvals[value]

if cmdout_buffer != []:
if time.time() - cmdout_buffer[1] < timeout:
cmdout = cmdout_buffer[0]

if cmdout is None:
try:
cmdout = subprocess.check_output([workingDir+'/ryzenadj/ryzenadj', '-i']).decode('utf-8').split('\n')
cmdout_buffer = [cmdout, time.time()]
except:
return backupvals[value]

for line in cmdout:
if value in line:
Expand Down Expand Up @@ -52,6 +81,7 @@ def getVal(value):
"max_skin_temp": float(getraw("STT LIMIT APU")),
"skin_temp": float(getraw("STT VALUE APU")),
}

elif value == "temp":
return getraw("THM VALUE CORE")
elif value == "max_temp":
Expand All @@ -65,9 +95,9 @@ def getVal(value):
elif value == "max_peak_power":
return getraw("PPT LIMIT FAST")
elif value == "skin_temp_limit":
return getraw("STAPM LIMIT")
return getraw("STT LIMIT APU")
elif value == "skin_temp":
return getraw("STAPM VALUE")
return getraw("STT VALUE APU")
else:
return None

Expand Down Expand Up @@ -125,20 +155,24 @@ def main_loop():
conn = listener.accept()
running = True
while running:
while conn.poll():
msg = conn.recv()
if msg == "EXIT":
running = False
elif msg[0] == "set":
decompose_and_set(msg)
elif msg[0] == "get":
conn.send(getVal(msg[1]))
elif msg == "TEST":
cmdout = subprocess.run([workingDir + '/ryzenadj/ryzenadj', '-h'], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')
conn.send(cmdout)

# Other code can go here
time.sleep(0.05)
try :
while conn.poll():
msg = conn.recv()
if msg == "EXIT":
running = False
elif msg[0] == "set":
decompose_and_set(msg)
elif msg[0] == "get":
conn.send(getVal(msg[1]))
elif msg == "TEST":
cmdout = subprocess.run([workingDir + '/ryzenadj/ryzenadj', '-h'], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n')
conn.send(cmdout)

# Other code can go here
time.sleep(0.05)
except :
logg("Daemon error", 3)
running = False

main_loop()
print("------Daemon Stopped----")
logg("Daemon closed", 1)
Loading

0 comments on commit e11d91e

Please sign in to comment.