reworked and fixed tse controller to work with new layout, fixed random bugs in barco code -- note: due to testing, some actions are commented out, uncomment those for actual deployment

This commit is contained in:
0xEmm 2024-12-05 22:28:11 +01:00
parent 1984db16bf
commit d42b296bae
3 changed files with 94 additions and 88 deletions

View file

@ -5,7 +5,7 @@ import telnetlib3
import toml
from socket import gethostname
mainBarcoIP = '192.168.192.12'
mainBarcoIP = 'localhost' #'192.168.192.12'
sideBarcoIP = '192.168.192.13'
# TODO all the checks and stuff
@ -32,25 +32,25 @@ def parse_barco_response(raw: str):
async def barco_telnet_command(client, writer, select: str):
onSub = f"p1/projectors/{select}/#"
onSub = f"p01/projectors/{select}/#"
#print('TEST', onSub)
onMatch = f"p1/projectors/{select}/command/+"
onMatch = f"p01/projectors/{select}/command/+"
await client.subscribe(onSub)
async with client.messages() as msgs:
async for mesg in msgs:
# print(mesg.topic.value)
# print(mesg.payload.decode())
# print('on', select)
#async with client.messages as msgs:
async for mesg in client.messages:
# print(mesg.topic.value)
# print(mesg.payload.decode())
# print('on', select)
if mesg.topic.matches(onMatch):
# 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' # 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)
writer.write(barcoCmd)
if mesg.topic.matches(onMatch):
# print("test")
cmd = mesg.topic.value.split("/")[-1]
#val = '1' if mesg.payload.decode() == 'ON' else '0'
val = '1' if mesg.payload.decode() == '1' 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)
writer.write(barcoCmd)
async def barco_telnet_read_status(client, reader, select: str):
@ -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/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
await client.publish(f"p01/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
async def barco_telnet_query_status(writer, select: str):
@ -88,17 +88,17 @@ async def main():
#mainBarcoIP = conf[gethostname()]['projektor_glavni']
#sideBarcoIP = conf[gethostname()]['projektor_stranski']
mainReader, mainWriter = await telnetlib3.open_connection(mainBarcoIP, 3023)
sideReader, sideWriter = await telnetlib3.open_connection(sideBarcoIP, 3023)
#sideReader, sideWriter = await telnetlib3.open_connection(sideBarcoIP, 3023)
async with aiomqtt.Client('localhost', 1883) as client:
task_status_query_main = asyncio.create_task(barco_telnet_query_status(mainWriter, 'glavni'))
task_status_reader_main = asyncio.create_task(barco_telnet_read_status(client, mainReader, 'glavni'))
task_control_main = asyncio.create_task(barco_telnet_command(client, mainWriter, 'glavni'))
task_status_query_side = asyncio.create_task(barco_telnet_query_status(sideWriter, 'stranski'))
task_status_reader_side = asyncio.create_task(barco_telnet_read_status(client, sideReader, 'stranski'))
task_control_side = asyncio.create_task(barco_telnet_command(client, sideWriter, 'stranski'))
#task_status_query_side = asyncio.create_task(barco_telnet_query_status(sideWriter, 'stranski'))
#task_status_reader_side = asyncio.create_task(barco_telnet_read_status(client, sideReader, 'stranski'))
#task_control_side = asyncio.create_task(barco_telnet_command(client, sideWriter, 'stranski'))
await asyncio.gather(task_status_query_main, task_status_reader_main, task_control_main,
task_status_query_side, task_status_reader_side, task_control_side)
await asyncio.gather(task_status_query_main, task_status_reader_main, task_control_main)#,
#task_status_query_side, task_status_reader_side, task_control_side)
### fuj to, ne tk delat