From e595fb97ce728064d66ec6e7ba4fbf06c03fe36d Mon Sep 17 00:00:00 2001 From: 0xEmm Date: Thu, 7 Nov 2024 17:07:29 +0100 Subject: [PATCH] added systemd service config files and misc changes, still need to finish writing the reworked tse box controller --- barco.service | 16 ++++++++++++ barco_telnet/barco_telnet_control.py | 10 ++++---- eth0.notwork | 8 ++++++ extron_audio.service | 13 ++++++++++ interfaces.save | 3 +++ mqtt_init.service | 11 ++++++++ projector_motors.service | 12 +++++++++ tse_box.service | 15 +++++++++++ tse_releji_mapping.txt | 13 ++++++++++ tse_serial/tse_serial_controler.py | 38 +++++++++++++++++++++++++--- 10 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 barco.service create mode 100644 eth0.notwork create mode 100644 extron_audio.service create mode 100644 interfaces.save create mode 100644 mqtt_init.service create mode 100644 projector_motors.service create mode 100644 tse_box.service create mode 100644 tse_releji_mapping.txt diff --git a/barco.service b/barco.service new file mode 100644 index 0000000..653b8b8 --- /dev/null +++ b/barco.service @@ -0,0 +1,16 @@ +[Unit] +Description=Barco projector control +After=mqtt_init.service + + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/barco_telnet_control.py +User=rpi +Group=rpi +Type=simple +Restart=always + + +[Install] +WantedBy=mqtt_init.service + diff --git a/barco_telnet/barco_telnet_control.py b/barco_telnet/barco_telnet_control.py index f5f9947..fbc4c5e 100644 --- a/barco_telnet/barco_telnet_control.py +++ b/barco_telnet/barco_telnet_control.py @@ -32,9 +32,9 @@ def parse_barco_response(raw: str): async def barco_telnet_command(client, writer, select: str): - onSub = f"p1/projektorji/{select}/#" - print('TEST', onSub) - onMatch = f"p1/projektorji/{select}/ukaz/+" + onSub = f"p1/projectors/{select}/#" + #print('TEST', onSub) + onMatch = f"p1/projectors/{select}/command/+" await client.subscribe(onSub) async with client.messages() as msgs: async for mesg in msgs: @@ -46,7 +46,7 @@ async def barco_telnet_command(client, writer, select: str): # print("test") cmd = mesg.topic.value.split("/")[-1] #val = '1' if mesg.payload.decode() == 'ON' else '0' - val = '1' if mesg.payload.decode() == 'ON' else '0' + val = '1' if mesg.payload.decode() == 'ON' else '0' # refactor to direct 0 and 1 barcoCmd = f"[{cmdMap[cmd]}{val}]" print("Received: [" + mesg.topic.value + "] payload: [" + mesg.payload.decode() + "]") print("Sending command to Barco: " + barcoCmd) @@ -62,7 +62,7 @@ async def barco_telnet_read_status(client, reader, select: str): if parsed == None: continue #TODO alert for errors print(f"Updating topic [{parsed[0]}] with value [{parsed[1]}]") - await client.publish(f"p1/projektorji/{select}/status/{parsed[0]}", payload=parsed[1]) + await client.publish(f"p1/projectors/{select}/status/{parsed[0]}", payload=parsed[1]) async def barco_telnet_query_status(writer, select: str): diff --git a/eth0.notwork b/eth0.notwork new file mode 100644 index 0000000..7f7c756 --- /dev/null +++ b/eth0.notwork @@ -0,0 +1,8 @@ +[Match] + +Name=eth0 + +[Network] +Address=192.168.192.42 +Gateway=192.168.192.1 + diff --git a/extron_audio.service b/extron_audio.service new file mode 100644 index 0000000..61708da --- /dev/null +++ b/extron_audio.service @@ -0,0 +1,13 @@ +[Unit] +Description=Extron audio matrix control +After=mqtt_init.service + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/extron_audio_matrix_telnet_control.py +Type=simple +Restart=always + +[Install] +WantedBy=mqtt_init.service + + diff --git a/interfaces.save b/interfaces.save new file mode 100644 index 0000000..830d585 --- /dev/null +++ b/interfaces.save @@ -0,0 +1,3 @@ +# interfaces(5) file used by ifup(8) and ifdown(8) +# Include files from /etc/network/interfaces.d: +source /etc/network/interfaces.d/* diff --git a/mqtt_init.service b/mqtt_init.service new file mode 100644 index 0000000..a1e82ca --- /dev/null +++ b/mqtt_init.service @@ -0,0 +1,11 @@ +[Unit] +Description=Sets up MQTT topics +After=multi-user.target + +[Service] +ExecStart =/usr/bin/python3 /home/rpi/mqtt_init_topics.py +Type=simple + +[Install] +WantedBy=multi-user.target + diff --git a/projector_motors.service b/projector_motors.service new file mode 100644 index 0000000..3bdd6fe --- /dev/null +++ b/projector_motors.service @@ -0,0 +1,12 @@ +[Unit] +Description=Control for projector motors +After=mqtt_init.service + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/projector_motors.py +Restart=always +Type=simple + +[Install] +WantedBy=mqtt_init.service + diff --git a/tse_box.service b/tse_box.service new file mode 100644 index 0000000..0e5acdb --- /dev/null +++ b/tse_box.service @@ -0,0 +1,15 @@ +[Unit] +Description=TSE serial control +After=mqtt_init.service + +[Service] +ExecStart=/usr/bin/python3 /home/rpi/tse_serial_controler.py /home/rpi/tse_serial_interpreter.py +Type=simple +Restart=always +User=rpi +Group=rpi + +[Install] +WantedBy=mqtt_init.service + + diff --git a/tse_releji_mapping.txt b/tse_releji_mapping.txt new file mode 100644 index 0000000..c16944b --- /dev/null +++ b/tse_releji_mapping.txt @@ -0,0 +1,13 @@ +1 - sistem +2 - ozvocenje +3 - projektorji +4 - ? +5 - platno 1 dol +6 - platno 1 gor +7 - platno 2 dol +8 - platno 2 gor +9 - sencilo dol +10 - sencilo gor +11 - ? +12 - ? + diff --git a/tse_serial/tse_serial_controler.py b/tse_serial/tse_serial_controler.py index a5f2310..484cd40 100644 --- a/tse_serial/tse_serial_controler.py +++ b/tse_serial/tse_serial_controler.py @@ -4,8 +4,10 @@ import aioserial import aiomqtt from tse_serial_interpreter import * +room = 'p1' #TODO make be do get fronm file of configuration + aser: aioserial.AioSerial = aioserial.AioSerial( - port='/dev/cu.usbserial-14240', + port='/dev/cu.usbserial-14240', #TODO not hardcode it baudrate=1200, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS, @@ -13,13 +15,43 @@ aser: aioserial.AioSerial = aioserial.AioSerial( ) # TODO adjust serial on actual TSE interface +mapping = { + "master": 1, + "audio": 2, + "projectors": 3, + + "platno_glavni_dol": 5, + "platno_glavni_gor": 6, + "platno_stranski_dol": 7, + "platno_stranski_gor": 8, + "sencilo_dol": 9, + "sencilo_gor": 10 + + #ostalo reserved +} + +reverse_lookup = {v: k for k, v in mapping.items()} + +def parse_topic_from_mqtt(topic: str): + topicArr = topic.split() + + + async def task_status2mqtt(statusClient: aiomqtt.Client): while True: data = await aser.read_until_async() data = data.decode(errors='ignore').strip() print("TSE box sent: " + data) relState = resp_to_relay_state(data) - publishTopic = f"p1/tseRelays/{relState.relay_id}/status" + command = reverse_lookup[relState.relay_id] + action = relState.state + #TODO havent figured out a clean way to + # get out the action from topic yet as they are + # not always on the same level + + # probably just do it the most straight forward way + # with some more code + publishTopic = f"{room}/" publishPayload = "ON" if relState.state else "OFF" print("Publishing [" + publishPayload + "] to topic [" + publishTopic + "]") await statusClient.publish(publishTopic, payload=publishPayload) @@ -34,7 +66,7 @@ async def task_command2serial(controlClient: aiomqtt.Client): msgTopic = mesg.topic.value cmnd = mesg.payload.decode() print("Received: [" + msgTopic + "] payload: [" + cmnd + "]") - relay = int(mesg.topic.value.split("/")[-2]) + relay = int(mesg.topic.value.split("/")[-2]) #TODO different by case cmnd = cmnd == "ON" relState = RelayState(relay, cmnd) setRelay = relay_state_to_cmd(relState)