Человекочитаемые команды для привязки-отвязки (первый подход к снаряду).
authorRoman Bazalevskiy <rvb@rvb.name>
Mon, 2 Apr 2018 14:15:49 +0000 (17:15 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Mon, 2 Apr 2018 14:15:49 +0000 (17:15 +0300)
nmd/nl_mqtt.py

index 5261d43bc6e8525131bf3c08d3c1226f579ed4a9..25f96da05b21e419fabe42eb63a857eb304c4c9f 100644 (file)
@@ -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)