luacode.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2015-2016 Peter Magnusson <peter@birchroad.net>
  4. DOWNLOAD_FILE = "file.open('{filename}') print(file.seek('end', 0)) file.seek('set', {bytes_read}) uart.write(0, file.read({chunk_size}))file.close()"
  5. LIST_FILES = 'for key,value in pairs(file.list()) do print(key,value) end'
  6. SAVE_LUA = \
  7. r"""
  8. function recv_block(d)
  9. if string.byte(d, 1) == 1 then
  10. size = string.byte(d, 2)
  11. uart.write(0,'\006')
  12. if size > 0 then
  13. file.write(string.sub(d, 3, 3+size-1))
  14. else
  15. file.close()
  16. uart.on('data')
  17. uart.setup(0,{baud},8,0,1,1)
  18. end
  19. else
  20. uart.write(0, '\021' .. d)
  21. uart.setup(0,{baud},8,0,1,1)
  22. uart.on('data')
  23. end
  24. end
  25. function recv_name(d) d = string.gsub(d, '\000', '') file.remove(d) file.open(d, 'w') uart.on('data', 130, recv_block, 0) uart.write(0, '\006') end
  26. function recv() uart.setup(0,{baud},8,0,1,0) uart.on('data', '\000', recv_name, 0) uart.write(0, 'C') end
  27. function shafile(f) file.open(f, "r") print(crypto.toHex(crypto.hash("sha1",file.read()))) file.close() end
  28. """
  29. UART_SETUP = 'uart.setup(0,{baud},8,0,1,1)'