luacode.py 886 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2015-2016 Peter Magnusson <peter@birchroad.net>
  4. SAVE_LUA = \
  5. r"""
  6. function recv_block(d)
  7. if string.byte(d, 1) == 1 then
  8. size = string.byte(d, 2)
  9. uart.write(0,'\006')
  10. if size > 0 then
  11. file.write(string.sub(d, 3, 3+size-1))
  12. else
  13. file.close()
  14. uart.on('data')
  15. uart.setup(0,9600,8,0,1,1)
  16. end
  17. else
  18. uart.write(0, '\021' .. d)
  19. uart.setup(0,9600,8,0,1,1)
  20. uart.on('data')
  21. end
  22. end
  23. 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
  24. function recv() uart.setup(0,9600,8,0,1,0) uart.on('data', '\000', recv_name, 0) uart.write(0, 'C') end
  25. function shafile(f) file.open(f, "r") print(crypto.toHex(crypto.hash("sha1",file.read()))) file.close() end
  26. """