From: Tom Hunger Date: Thu, 15 Jan 2015 15:47:32 +0000 (+0000) Subject: base-64 encode device messages. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=9925f606d8ae41ea58be4379fb3c09b446c44362;p=sirius.git base-64 encode device messages. Note that there's still a bug that prevents image printing from working. To be investigated. --- diff --git a/notes/capture_notes.md b/notes/capture_notes.md index ace53e9..28f927e 100644 --- a/notes/capture_notes.md +++ b/notes/capture_notes.md @@ -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`. diff --git a/sirius/coding/encoders.py b/sirius/coding/encoders.py index 19a056b..70be6d6 100644 --- a/sirius/coding/encoders.py +++ b/sirius/coding/encoders.py @@ -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', }) diff --git a/sirius/protocol/messages.py b/sirius/protocol/messages.py index f3fd387..c0c4df8 100644 --- a/sirius/protocol/messages.py +++ b/sirius/protocol/messages.py @@ -56,10 +56,12 @@ BridgeCommandResponse = namedtuple('BridgeCommandResponse', [ ]) SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [ + 'device_address', 'pixels', # 384 pixels wide ]) SetDelivery = namedtuple('SetDelivery', [ + 'device_address', 'pixels', ])