From: Roman Bazalevskiy Date: Mon, 2 Apr 2018 14:15:49 +0000 (+0300) Subject: Человекочитаемые команды для привязки-отвязки (первый подход к снаряду). X-Git-Url: https://git.rvb.name/mqtt-noolite.git/commitdiff_plain/dda5094610cb182ba33ab5035b47c4856b93ad43?ds=inline;hp=76301219aec0432004732f0706c822bc6a4c9d46 Человекочитаемые команды для привязки-отвязки (первый подход к снаряду). --- diff --git a/nmd/nl_mqtt.py b/nmd/nl_mqtt.py index 5261d43..25f96da 100644 --- a/nmd/nl_mqtt.py +++ b/nmd/nl_mqtt.py @@ -60,6 +60,7 @@ class MqttDriver(metaclass=Singleton): await self.commands_to_send_queue.put(payload) else: try: + mtrf_command = None address = subtopic.split('/') if len(address)==2: channel = int(address[0]) @@ -77,14 +78,14 @@ class MqttDriver(metaclass=Singleton): print("%s: %s (%s)" % (command,channel,id)) if command == "on": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 2 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 2, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 2, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 2 } elif command == "off": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 0 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 0, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 0, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: @@ -92,26 +93,26 @@ class MqttDriver(metaclass=Singleton): elif command == "brightness": brightness = int(payload) if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 6, "d0": brightness, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 6, "d0": brightness } elif command == "state": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 128 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 128, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 128, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } elif command == "load_preset": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 7 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 7, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 7, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 7 } elif command == "save_preset": if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 8 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 8, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 8, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: @@ -121,13 +122,41 @@ class MqttDriver(metaclass=Singleton): d0 = delay % 256 d1 = delay // 256 if id == '.': - mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } + mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1, "ctr": 1 } elif id: mtrf_command = { "mode": 2, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } else: mtrf_command = { "mode": 0, "ch": channel, "cmd": 25, "fmt": 6, "d0": d0, "d1": d1 } + elif command == "bind": + if id == 'tx-f': + mtrf_command = { "mode": 2, "ch": channel, "cmd": 15 } + elif id == 'tx': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 15 } + elif id == 'rx': + mtrf_command = { "mode": 1, "ch": channel, "cmd": 15 } + elif id == 'rx-f': + mtrf_command = { "mode": 3, "ch": channel, "cmd": 15 } + else: + mtrf_command = { "mode": 0, "ch": channel, "cmd": 15 } + elif command == "unbind": + if id == '.' or id == 'tx-f': + mtrf_command = { "mode": 2, "ch": channel, "cmd": 9 } + elif id == 'tx': + mtrf_command = { "mode": 0, "ch": channel, "cmd": 9 } + elif id == 'rx': + mtrf_command = { "mode": 1, "ch": channel, "cmd": 9, "ctr": 5 } + elif id == 'rx-f': + mtrf_command = { "mode": 3, "ch": channel, "cmd": 9, "ctr": 5 } + else: + mtrf_command = { "mode": 0, "ch": channel, "cmd": 9 } + elif command == "service": + if id == '.': + mtrf_command = { "mode": 2, "ch": channel, "cmd": 131, "d0": 1 } + elif id: + mtrf_command = { "mode": 2, "ch": channel, "cmd": 131, "d0": 1, "id0": int(id[0:2],16), "id1": int(id[2:4],16), "id2": int(id[4:6],16), "id3": int(id[6:8],16), "ctr": 8 } - await self.commands_to_send_queue.put(mtrf_command) + if mtrf_command: + await self.commands_to_send_queue.put(mtrf_command) except Exception as e: logger.exception(e)