]> git.aero2k.de Git - sirius.git/commitdiff
Emulator: Decode binary payload of a device command.
authorTom Hunger <tehunger@gmail.com>
Fri, 13 Mar 2015 22:22:22 +0000 (22:22 +0000)
committerTom Hunger <tehunger@gmail.com>
Fri, 13 Mar 2015 22:22:22 +0000 (22:22 +0000)
sirius/emulate/commands.py

index ca7f5bfc192f0ea03d4cd5b1f4cf832a461781c4..6be25e2af11c3e2fdca486af84f3bde485cfbe42 100644 (file)
@@ -11,6 +11,8 @@ import json
 import re
 import random
 import time
+import struct
+import base64
 
 from flask.ext import script
 
@@ -52,6 +54,13 @@ def heartbeat(ws):
             assert False # unreachable
 
 
+def _decode_binary(base64_data):
+    bdata = base64.b64decode(base64_data)
+    _, _, command, print_id, _, length = struct.unpack("<BBHIII", bdata[:16])
+
+    print("command", command, print_id, length)
+
+
 def _decode(data):
     try:
         data = json.loads(data)
@@ -68,6 +77,8 @@ def _decode(data):
         payload = data['binary_payload']
         command_id = data['command_id']
 
+        _decode_binary(payload)
+
         # TODO(tom): Decode binary payload for debugging.
 
         return {u'device_address': State.device_address,