main
Valentin Ochs 2022-11-11 16:37:44 +01:00
parent 37188e852c
commit cb5a93c136
7 changed files with 11 additions and 27 deletions

View File

@ -21,6 +21,7 @@ msgs = {
class Reader(util.Loggable):
def __init__(self, should_open_immediately_cb = None):
super().__init__("bell")
self.tmp = bytes()
self.data = []
self.lock = threading.RLock()
@ -57,7 +58,6 @@ class Reader(util.Loggable):
def data_received(self, data):
self.tmp += data
data= self.tmp
# log(data)
while len(data) >= 7:
while len(data) >= 7 and (data[0] != 0xA8 or data[-1] != 0xA3 or self.chksum(data[1:-2]) != data[-2]):
@ -153,6 +153,7 @@ class Reader(util.Loggable):
class Control(util.Loggable):
def __init__(self, port, open_immediately_cb = None):
super().__init__("bell")
self._port = port
self._task = None
self._cb = open_immediately_cb

View File

@ -10,6 +10,7 @@ from ..util import Loggable
class Communication(Loggable):
def __init__(self, port: Union[os.PathLike, IO]):
super().__init__("door")
self._mutex: RLock = RLock()
self._write_mutex: Lock = Lock()

View File

@ -10,6 +10,7 @@ from . import constants
class Control(util.Loggable):
def __init__(self, config, mqtt_client=None):
super().__init__("door")
self._config = config
self._mutex = RLock()

View File

@ -6,6 +6,7 @@ from threading import Thread, RLock
class TokenControl(util.Loggable):
def __init__(self, token_path, fifo_path, control):
super().__init__("door")
self._token_path = token_path
self._fifo_path = fifo_path
self._control = control

View File

@ -11,6 +11,7 @@ from .util import timestamp
class DoorControlNfc(util.Loggable):
"""Validates tokens read from a socket and tells a DoorControl to toggle its target"""
def __init__(self, config, control, mqtt_client = None):
super().__init__("nfc")
self._config = config
self._nfc = self._open_nfc_fifo()
self._control = control

View File

@ -12,6 +12,7 @@ from .door.constants import state_names
class DoorControlSocket(util.Loggable):
class LineBuffer(util.Loggable):
def __init__(self, f, handler):
super().__init__("socket", "DoorControlSocket")
self.data = b''
self.f = f
self.handler = handler
@ -34,6 +35,7 @@ class DoorControlSocket(util.Loggable):
return True
def __init__(self, config, control, nfc):
super().__init__("socket")
self._config = config
self._control = control
self._nfc = nfc
@ -133,28 +135,3 @@ class DoorControlSocket(util.Loggable):
self._stop = True
self._cond.notify()
self._task.join()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_43363220195053573A002C0-if01")
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
parser.add_argument("--log_file", default="/tmp/nfc.log")
parser.add_argument("--state_timeout", type=float, default=10)
parser.add_argument("--state_timeout_speed", type=float, default=3)
parser.add_argument("--repeat_time", type=float, default=COMMAND_IDLE_TIME)
parser.add_argument("--mqtt_host", default="10.10.21.2")
config = parser.parse_args()
util.init_logging()
def start():
dc = DoorControl(config)
dc._comms.start()
t = Thread(target=dc.run)
t.start()
return dc

View File

@ -57,8 +57,10 @@ def timestamp() -> str:
return now().strftime("%Y-%m-%d %H:%M:%S")
class Loggable:
def __init__(self, *path):
self._logger_path = path
def _logger(self) -> logging.Logger:
return logger(type(self).__name__)
return logger(*self._logger_path, type(self).__name__)
class Event:
def __init__(self, lock = None):