frontend overhaul, minor backend bugfixes
This commit is contained in:
parent
acc38950e7
commit
c1325c0eda
28 changed files with 767 additions and 481 deletions
|
@ -13,6 +13,7 @@ barcoIP: str
|
|||
telnetPort: int
|
||||
mqttPort: int
|
||||
mqttIP: str
|
||||
barcoReached: bool
|
||||
|
||||
cmdMap = {
|
||||
'power': 'POWR',
|
||||
|
@ -23,7 +24,7 @@ reverseCmdMap = {v: k for k, v in cmdMap.items()}
|
|||
|
||||
|
||||
def parse_barco_response(raw: str):
|
||||
global room, barcoPosition
|
||||
global room, barcoPosition, barcoReached
|
||||
raw = raw[1:-1] # strip square brackets
|
||||
#print(raw)
|
||||
if raw.startswith("ERR"):
|
||||
|
@ -33,6 +34,7 @@ def parse_barco_response(raw: str):
|
|||
#print(cmd + " " + status)
|
||||
cmd = reverseCmdMap[cmd]
|
||||
status = '1' if status == '01' else '0'
|
||||
barcoReached = True
|
||||
return cmd, status
|
||||
|
||||
|
||||
|
@ -91,7 +93,7 @@ async def barco_telnet_query_status(writer, select: str):
|
|||
|
||||
|
||||
async def main():
|
||||
global room
|
||||
global room, barcoReached
|
||||
global barcoPosition, barcoIP, telnetPort, mqttIP, mqttPort
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit("No position provided")
|
||||
|
@ -102,20 +104,26 @@ async def main():
|
|||
g62Barcos = {k: v for k,v in conf["barco_G62"].items()}
|
||||
currentBarco = g62Barcos[barcoPosition]
|
||||
barcoIP = currentBarco['ip']
|
||||
telnetPort = currentBarco["port"]
|
||||
telnetPort = int(currentBarco["port"])
|
||||
|
||||
room = conf["global"]["room"]
|
||||
mqttPort = conf["global"]["mqttPort"]
|
||||
mqttPort = int(conf["global"]["mqttPort"])
|
||||
mqttIP = conf["global"]["mqttIp"]
|
||||
barcoReached = False
|
||||
try:
|
||||
barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort)
|
||||
barcoReached = True
|
||||
except Exception as e:
|
||||
print("Connection failed: " + barcoIP + ": " + str(e))
|
||||
barcoReached = False
|
||||
finally:
|
||||
async with aiomqtt.Client(mqttIP, mqttPort) as client:
|
||||
task_status_query_barco = asyncio.create_task(barco_telnet_query_status(barcoWriter, barcoPosition))
|
||||
task_status_reader_barco = asyncio.create_task(barco_telnet_read_status(client, barcoReader, barcoPosition))
|
||||
task_control_barco = asyncio.create_task(barco_telnet_command(client, barcoWriter, barcoPosition))
|
||||
|
||||
barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort)
|
||||
async with aiomqtt.Client(mqttIP, mqttPort) as client:
|
||||
task_status_query_barco = asyncio.create_task(barco_telnet_query_status(barcoWriter, barcoPosition))
|
||||
task_status_reader_barco = asyncio.create_task(barco_telnet_read_status(client, barcoReader, barcoPosition))
|
||||
task_control_barco = asyncio.create_task(barco_telnet_command(client, barcoWriter, barcoPosition))
|
||||
|
||||
await asyncio.gather(task_status_query_barco, task_status_reader_barco, task_control_barco)
|
||||
|
||||
await asyncio.gather(task_status_query_barco, task_status_reader_barco, task_control_barco)
|
||||
await client.publish(f"{room}/projectors/{barcoPosition}/error", payload=("UNREACHABLE" if not barcoReached else "OK"))
|
||||
|
||||
### fuj to, ne tk delat
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue