]> git.aero2k.de Git - sirius.git/commitdiff
base-64 encode device messages.
authorTom Hunger <tehunger@gmail.com>
Thu, 15 Jan 2015 15:47:32 +0000 (15:47 +0000)
committerTom Hunger <tehunger@gmail.com>
Thu, 15 Jan 2015 16:02:50 +0000 (16:02 +0000)
Note that there's still a bug that prevents image printing from working.
To be investigated.

notes/capture_notes.md
sirius/coding/encoders.py
sirius/protocol/messages.py

index ace53e9ba152fce2f9194cc58662c2521eacef2a..28f927e7c4f4f5254466f317678df274de06bec9 100644 (file)
@@ -108,3 +108,10 @@ itself is online.
     - claim code (entered by user)
     - address
 - users
+
+
+# What happens when we send down an illegal print command:
+
+DEBUG:sirius.protocol.protocol_loop:Received UnknownEvent(raw_dict={u'device_address': u'000d6f000273ce0b', u'timestamp': 1421336620.588616, u'transfer_time': 3.43, u'bridge_address': u'000d6f0001b3719d', u'return_code': 144, u'rssi_stats': [-19, -19, -19], u'type': u'DeviceCommandResponse', u'command_id': 0}).
+
+Note the `return_code`.
index 19a056b2301fe2a562992cd3534213774bfc69a7..70be6d68d0cd5e55c3bc0f1d2e065ff63a295473 100644 (file)
@@ -2,6 +2,7 @@
 dictionaries that can be encoded directly as json.
 """
 import struct
+import base64
 
 from sirius.coding import image_encoding
 from sirius.coding import claiming
@@ -86,16 +87,18 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
     elif type(command) == messages.SetDeliveryAndPrint:
         pixel_count, pixels = image_encoding.rle_image(command.pixels)
         return make({
-            'binary_payload': _encode_printer_message(
-                0x1, pixel_count, pixels, command_id),
+            'binary_payload': base64.b64encode(_encode_printer_message(
+                0x1, pixel_count, pixels, command_id)),
+            'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
 
     elif type(command) == messages.SetDelivery:
         pixel_count, pixels = image_encoding.rle_image(command.pixels)
         return make({
-            'binary_payload': _encode_printer_message(
-                0x2, pixel_count, pixels, command_id),
+            'binary_payload': base64.b64encode(_encode_printer_message(
+                0x2, pixel_count, pixels, command_id)),
+            'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
 
index f3fd387dfa5a29c4979291f5e8b4cf94eac7ed76..c0c4df8dae132237152a0992cab5d29e47a1b17b 100644 (file)
@@ -56,10 +56,12 @@ BridgeCommandResponse = namedtuple('BridgeCommandResponse', [
 ])
 
 SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [
+    'device_address',
     'pixels', # 384 pixels wide
 ])
 
 SetDelivery = namedtuple('SetDelivery', [
+    'device_address',
     'pixels',
 ])