Move source file
This commit is contained in:
parent
0982a213dd
commit
f4ed8aa368
|
@ -12,19 +12,6 @@ OPEN_THRESHOLD = 190
|
||||||
CLOSED_THRESHOLD = 160
|
CLOSED_THRESHOLD = 160
|
||||||
CLOSED_WANT = 40
|
CLOSED_WANT = 40
|
||||||
|
|
||||||
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=5)
|
|
||||||
parser.add_argument("--mqtt_host", default="10.10.21.2")
|
|
||||||
|
|
||||||
config = parser.parse_args()
|
|
||||||
|
|
||||||
def timestamp():
|
def timestamp():
|
||||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
@ -433,26 +420,42 @@ class DoorControl:
|
||||||
DoorControl.action_names[self.action()],
|
DoorControl.action_names[self.action()],
|
||||||
(datetime.datetime.now() - self.start_time).total_seconds()))
|
(datetime.datetime.now() - self.start_time).total_seconds()))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
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=5)
|
||||||
|
parser.add_argument("--mqtt_host", default="10.10.21.2")
|
||||||
|
|
||||||
dc = DoorControl(config)
|
config = parser.parse_args()
|
||||||
|
|
||||||
buffers = {}
|
dc = DoorControl(config)
|
||||||
while True:
|
|
||||||
readable = select.select([ dc.serial_port.fileno(), dc.nfc_fifo, dc.control_socket ] + dc.comm_channels, [], [], 1 / UPDATE_RATE)[0]
|
|
||||||
|
|
||||||
for c in readable:
|
buffers = {}
|
||||||
if c == dc.serial_port.fileno():
|
while True:
|
||||||
dc.handle_door_line()
|
readable = select.select([ dc.serial_port.fileno(), dc.nfc_fifo, dc.control_socket ] + dc.comm_channels, [], [], 1 / UPDATE_RATE)[0]
|
||||||
elif c == dc.nfc_fifo:
|
|
||||||
dc.handle_nfc_token()
|
for c in readable:
|
||||||
elif c == dc.control_socket:
|
if c == dc.serial_port.fileno():
|
||||||
dc.logger.info("Got connection")
|
dc.handle_door_line()
|
||||||
sock = dc.control_socket.accept()[0]
|
elif c == dc.nfc_fifo:
|
||||||
buffers[sock] = dc.LineBuffer(sock, dc.handle_cmd)
|
dc.handle_nfc_token()
|
||||||
dc.comm_channels += [sock]
|
elif c == dc.control_socket:
|
||||||
else:
|
dc.logger.info("Got connection")
|
||||||
if not buffers[c].update():
|
sock = dc.control_socket.accept()[0]
|
||||||
dc.logger.info("Lost connection")
|
buffers[sock] = dc.LineBuffer(sock, dc.handle_cmd)
|
||||||
del buffers[c]
|
dc.comm_channels += [sock]
|
||||||
dc.comm_channels.remove(c)
|
else:
|
||||||
dc.handle_door_state()
|
if not buffers[c].update():
|
||||||
|
dc.logger.info("Lost connection")
|
||||||
|
del buffers[c]
|
||||||
|
dc.comm_channels.remove(c)
|
||||||
|
dc.handle_door_state()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user