Moved controller source into folder
This commit is contained in:
parent
c1325c0eda
commit
c2d277663f
14 changed files with 148 additions and 124 deletions
33
controller/tse_serial/tse_serial_interpreter.py
Normal file
33
controller/tse_serial/tse_serial_interpreter.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class RelayState:
|
||||
relay_id: int
|
||||
state: bool
|
||||
|
||||
|
||||
def resp_to_relay_state(cmd: str) -> RelayState:
|
||||
state = True if cmd.find("ON") > -1 else False #TODO maybe better handling of other
|
||||
#state = False if cmd.find("OFF") > -1 and state == None else None
|
||||
id = None
|
||||
if cmd.startswith("T"):
|
||||
id = int(cmd[1]) + (8 if cmd[2] == "B" else 0)
|
||||
elif cmd.startswith("re_"):
|
||||
id = int(cmd[3]) + (8 if cmd[4] == "B" else 0)
|
||||
else:
|
||||
id = None
|
||||
r_state = RelayState(id, state)
|
||||
return r_state
|
||||
|
||||
|
||||
def relay_state_to_cmd(r_state: RelayState) -> str:
|
||||
#r[NUM][CMD]
|
||||
cmd = 8 if r_state.state else 9
|
||||
id = r_state.relay_id
|
||||
# banka B
|
||||
if id > 8:
|
||||
cmd -= 2
|
||||
id -= 8
|
||||
return f"r{id}{cmd}"
|
||||
#return "r" + str(id) + str(cmd)
|
Loading…
Add table
Add a link
Reference in a new issue