mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 15:13:52 +01:00
Reset of piControl via ioctl
The reset of piControl was made with a call of `piControlReset` or `piTest`.
This commit is contained in:
@@ -5,9 +5,10 @@ __copyright__ = "Copyright (C) 2020 Sven Sager"
|
||||
__license__ = "GPLv3"
|
||||
|
||||
import os
|
||||
from fcntl import ioctl
|
||||
from json import loads
|
||||
from re import match as rematch
|
||||
from subprocess import Popen, PIPE
|
||||
from subprocess import PIPE, Popen
|
||||
|
||||
import proginit
|
||||
|
||||
@@ -16,7 +17,6 @@ def _setuprt(pid, evt_exit):
|
||||
"""Konfiguriert Programm fuer den RT-Scheduler.
|
||||
@param pid PID, der angehoben werden soll
|
||||
@return None"""
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.debug("enter _setuprt()")
|
||||
|
||||
dict_change = {
|
||||
@@ -36,10 +36,7 @@ def _setuprt(pid, evt_exit):
|
||||
count -= 1
|
||||
if count == 0:
|
||||
kpidps.kill()
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"ps timeout to get rt prio info - no rt active"
|
||||
)
|
||||
proginit.logger.error("ps timeout to get rt prio info - no rt active")
|
||||
return None
|
||||
|
||||
evt_exit.wait(0.5)
|
||||
@@ -51,10 +48,7 @@ def _setuprt(pid, evt_exit):
|
||||
lst_kpids = kpiddat.split()
|
||||
except Exception:
|
||||
kpidps.kill()
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"can not get pid and prio - no rt active"
|
||||
)
|
||||
proginit.logger.error("can not get pid and prio - no rt active")
|
||||
return None
|
||||
|
||||
while len(lst_kpids) > 0:
|
||||
@@ -64,11 +58,7 @@ def _setuprt(pid, evt_exit):
|
||||
|
||||
# Daten prüfen
|
||||
if not kpid.isdigit():
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"pid={0} and prio={1} are not valid - no rt active"
|
||||
"".format(kpid, kprio)
|
||||
)
|
||||
proginit.logger.error("pid={0} and prio={1} are not valid - no rt active".format(kpid, kprio))
|
||||
return None
|
||||
kpid = int(kpid)
|
||||
|
||||
@@ -81,43 +71,32 @@ def _setuprt(pid, evt_exit):
|
||||
if kprio < 10:
|
||||
# Profile anpassen
|
||||
ec = os.system("/usr/bin/env chrt -fp {0} {1}".format(
|
||||
dict_change[ps_change], kpid
|
||||
dict_change[ps_change],
|
||||
kpid
|
||||
))
|
||||
if ec != 0:
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"could not adjust scheduler - no rt active"
|
||||
)
|
||||
proginit.logger.error("could not adjust scheduler - no rt active")
|
||||
return None
|
||||
|
||||
# SCHED_RR für pid setzen
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.info("set scheduler profile of pid {0}".format(pid))
|
||||
|
||||
ec = os.system("/usr/bin/env chrt -p 1 {0}".format(pid))
|
||||
if ec != 0 and proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"could not set scheduler profile of pid {0}"
|
||||
"".format(pid)
|
||||
)
|
||||
if ec != 0:
|
||||
proginit.logger.error("could not set scheduler profile of pid {0}".format(pid))
|
||||
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.debug("leave _setuprt()")
|
||||
|
||||
|
||||
def _zeroprocimg():
|
||||
"""Setzt Prozessabbild auf NULL."""
|
||||
procimg = "/dev/piControl0" if proginit.pargs is None \
|
||||
else proginit.pargs.procimg
|
||||
procimg = "/dev/piControl0" if proginit.pargs is None else proginit.pargs.procimg
|
||||
|
||||
if os.access(procimg, os.W_OK):
|
||||
with open(procimg, "w+b", 0) as f:
|
||||
f.write(bytes(4096))
|
||||
else:
|
||||
if proginit.logger is not None:
|
||||
proginit.logger.error(
|
||||
"zeroprocimg can not write to piControl device"
|
||||
)
|
||||
proginit.logger.error("zeroprocimg can not write to piControl device")
|
||||
|
||||
|
||||
def get_revpiled_address(configrsc_bytes):
|
||||
@@ -143,9 +122,7 @@ def get_revpiled_address(configrsc_bytes):
|
||||
if device.get("productType", "0") == "135":
|
||||
# On the Flat device the LEDs are 2 Bytes (last Bit is wd)
|
||||
byte_address += 1
|
||||
proginit.logger.debug(
|
||||
"found revpi_led_address on {0} byte".format(byte_address)
|
||||
)
|
||||
proginit.logger.debug("found revpi_led_address on {0} byte".format(byte_address))
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
@@ -163,3 +140,30 @@ def refullmatch(regex, string):
|
||||
"""
|
||||
m = rematch(regex, string)
|
||||
return m is not None and m.end() == len(string)
|
||||
|
||||
|
||||
def pi_control_reset():
|
||||
"""
|
||||
Reset the piControl driver.
|
||||
|
||||
:return: 0 on success, >0 on failure
|
||||
"""
|
||||
if proginit.pargs is None:
|
||||
return 1
|
||||
|
||||
try:
|
||||
fd = os.open(proginit.pargs.procimg, os.O_WRONLY)
|
||||
except Exception:
|
||||
proginit.logger.warning("could not open piControl to reset driver")
|
||||
return 1
|
||||
|
||||
try:
|
||||
# KB_RESET _IO('K', 12 ) // reset the piControl driver including the config file
|
||||
ioctl(fd, 19212)
|
||||
proginit.logger.info("reset piControl driver")
|
||||
return 0
|
||||
except Exception as e:
|
||||
proginit.logger.warning("could not reset piControl driver")
|
||||
return 1
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "GPLv3"
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
@@ -14,16 +15,14 @@ forked = False
|
||||
globalconffile = None
|
||||
logapp = "revpipyloadapp.log"
|
||||
logplc = "revpipyload.log"
|
||||
logger = None
|
||||
logger = logging.getLogger()
|
||||
pargs = None
|
||||
picontrolreset = "/opt/KUNBUS/piControlReset"
|
||||
rapcatalog = None
|
||||
startdir = None
|
||||
|
||||
|
||||
def cleanup():
|
||||
"""Clean up program."""
|
||||
# NOTE: Pidfile wirklich löschen?
|
||||
if pargs is not None and pargs.daemon:
|
||||
if os.path.exists("/var/run/revpipyload.pid"):
|
||||
os.remove("/var/run/revpipyload.pid")
|
||||
@@ -116,11 +115,6 @@ def configure():
|
||||
"".format(", ".join(lst_rsc))
|
||||
)
|
||||
|
||||
# piControlReset suchen
|
||||
global picontrolreset
|
||||
if not os.access(picontrolreset, os.F_OK | os.X_OK):
|
||||
picontrolreset = "/usr/bin/piTest -x"
|
||||
|
||||
# rap Katalog an bekannten Stellen prüfen und laden
|
||||
global rapcatalog
|
||||
lst_rap = [
|
||||
@@ -160,11 +154,6 @@ def configure():
|
||||
global globalconffile
|
||||
globalconffile = pargs.conffile
|
||||
|
||||
# Program logger
|
||||
global logger
|
||||
if logger is None:
|
||||
logger = logging.getLogger()
|
||||
|
||||
# Alle handler entfernen
|
||||
for lhandler in logger.handlers:
|
||||
logger.removeHandler(lhandler)
|
||||
|
||||
@@ -48,7 +48,7 @@ import logsystem
|
||||
import picontrolserver
|
||||
import plcsystem
|
||||
import proginit
|
||||
from helper import refullmatch, get_revpiled_address
|
||||
from helper import get_revpiled_address, pi_control_reset, refullmatch
|
||||
from shared.ipaclmanager import IpAclManager
|
||||
from watchdogs import ResetDriverWatchdog
|
||||
from xrpcserver import SaveXMLRPCServer
|
||||
@@ -475,10 +475,7 @@ class RevPiPyLoad:
|
||||
self.xsrv.register_function(
|
||||
3, self.xml_plcuploadclean, "plcuploadclean")
|
||||
self.xsrv.register_function(
|
||||
3,
|
||||
lambda: os.system(proginit.picontrolreset),
|
||||
"resetpicontrol"
|
||||
)
|
||||
3, pi_control_reset, "resetpicontrol")
|
||||
self.xsrv.register_function(
|
||||
3, self.xml_mqttstart, "mqttstart")
|
||||
self.xsrv.register_function(
|
||||
@@ -1113,7 +1110,7 @@ class RevPiPyLoad:
|
||||
return xmldata
|
||||
return Binary()
|
||||
|
||||
def xml_plcdownload_file(self, file_name:str):
|
||||
def xml_plcdownload_file(self, file_name: str):
|
||||
"""
|
||||
Download a single file from work directory.
|
||||
|
||||
@@ -1380,7 +1377,7 @@ class RevPiPyLoad:
|
||||
-3 Konnte Konfiguraiton nicht schreiben
|
||||
-4 Module in Konfiguration enthalten, die es nicht gibt
|
||||
-5 Kein RAP Katalog zur Ueberpruefung gefunden
|
||||
Positive Zahl ist exitcode von piControlReset
|
||||
Positive Zahl ist exitcode von pi_control_reset
|
||||
|
||||
"""
|
||||
proginit.logger.debug("xmlrpc call setpictoryrsc")
|
||||
@@ -1421,7 +1418,7 @@ class RevPiPyLoad:
|
||||
return -3
|
||||
else:
|
||||
if reset:
|
||||
return os.system(proginit.picontrolreset)
|
||||
return pi_control_reset()
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user