# for this to work, I have to put the following line at line 38 of
# flask_sockets, to inject it into the environment
# environment.environ['HTTP_SEC_WEBSOCKET_PROTOCOL'] = 'bergcloud-bridge-v1'
-
+def protocol_name():
+ print "asked for protocol"
+ return 'bergcloud-bridge-v1'
def create_app(config_name):
app = Flask(__name__)
bootstrap.init_app(app)
db.init_app(app)
sockets.init_app(app)
-
+
+ # maybe this sets the HTTP_SEC_WEBSOCKET_PROTOCOL ?
+ app.protocol_name = protocol_name
+
# attach routes and custom error pages
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
#ws.send(j)
if event['type'] == 'DeviceEvent':
counting += 1
- if counting == 10:
+ if counting == 4:
gevent.sleep(0.5)
j = commands.set_delivery_and_print().to_json()
ws.send(j)
# firmware_update
TEST_FILE_ID = 1
-TEST_PNG_FN = '/Users/matt/Documents/dev-unversioned/sirius2/iconrethink.png'
+#TEST_PNG_FN = '/Users/matt/Documents/dev-unversioned/sirius2/iconrethink.png'
+TEST_PNG_FN = '/Users/matt/Documents/dev/sirius/tests/iconrethink.png'
# some constants
DEVICE_TYPE = '\x01' # rBergCloud::Barringer::DEVICE_TYPE in weminuche-server
# device type c, reserved byte c,
# command_name <H (short), file_id <L (long),
# unimplemented CRC (long is zero)
- command_header = struct.pack("<BBHLL", 1, 0, 1, 1, 0)
+ command_header = struct.pack("<BBHII", 1, 0, 1, 123, 0)
# get the encoded image now, because we'll need the data later
pixel_count, encoded_image = rle_image(png_fn)
n2 = n3_remainder / 256
n1 = n3_remainder % 256
printer_data = struct.pack("<8B", 0x1b, 0x2a, n1, n2, n3, 0, 0, 48)
- header_region = struct.pack("<BL", 0, len(printer_control) + len(printer_data))
+ header_region = struct.pack("<BI", 0, len(printer_control) + len(printer_data))
header_region += printer_control + printer_data
# payload including the header
- payload = struct.pack("<LB", len(header_region) + len(encoded_image) + 1, 0)
+ payload = struct.pack("<IB", len(header_region) + len(encoded_image) + 1, 0)
payload += header_region + encoded_image
- entire_payload = command_header + struct.pack("<L", len(payload)) + payload
+ entire_payload = command_header + struct.pack("<I", len(payload)) + payload
return entire_payload
# encode using our custom encoding
lengths = [g[1] for g in groups]
x = bytearray(rle(lengths))
- output = struct.pack("<%ds" % len(x), str(x))
+ compressed_data = struct.pack("<%dB" % len(x), *x)
+ # first byte is compressed type, always 1
+ output = struct.pack("<BL", 0x01, len(compressed_data)) + compressed_data
# return (number of pixels, output)
return len(pixels), output
+
+# ~~~~
+# Test
+# ~~~~
+
+if __name__ == '__main__':
+ # just see whether the output results in the same number of
+ # pixels as the input
+ TEST_PNG_FN = '/Users/matt/Documents/dev-unversioned/sirius2/iconrethink.png'
+ pixel_count, rle_encoded = rle_image(TEST_PNG_FN)
+
+ output_length = 0
+ length_codes = {}
+ for length, code in TRANSLATE:
+ length_codes[code] = length
+
+ for b in rle_encoded:
+ length = ord(b)
+ if length in length_codes.keys():
+ length = length_codes[length]
+ output_length += length
+
+ # Good, it matches
+ print "Input length: %d" % pixel_count
+ print "Output length: %d" % output_length
+
+
\ No newline at end of file