Переглянути джерело

Implemented detection for lua functions before uploading in prepare. Issue #4.

cheloftus 8 роки тому
батько
коміт
08d673043b
2 змінених файлів з 10 додано та 1 видалено
  1. 1 0
      lib/luacode.py
  2. 9 1
      lib/uploader.py

+ 1 - 0
lib/luacode.py

@@ -30,4 +30,5 @@ function recv_name(d) d = string.gsub(d, '\000', '') file.remove(d) file.open(d,
 function recv() uart.setup(0,{baud},8,0,1,0) uart.on('data', '\000', recv_name, 0) uart.write(0, 'C') end
 function shafile(f) file.open(f, "r") print(crypto.toHex(crypto.hash("sha1",file.read()))) file.close() end
 """
+LUA_FUNCTIONS = ['recv_block', 'recv_name','recv','shafile']
 UART_SETUP = 'uart.setup(0,{baud},8,0,1,1)'

+ 9 - 1
lib/uploader.py

@@ -11,7 +11,7 @@ import serial
 # Copyright (C) 2015-2016 Peter Magnusson <peter@birchroad.net>
 
 from .utils import default_port
-from .luacode import SAVE_LUA, LIST_FILES, UART_SETUP
+from .luacode import DOWNLOAD_FILE, SAVE_LUA, LUA_FUNCTIONS, LIST_FILES, UART_SETUP
 
 log = logging.getLogger(__name__)
 
@@ -115,6 +115,14 @@ class Uploader(object):
         """
         log.info('Preparing esp for transfer.')
 
+        for fn in LUA_FUNCTIONS:
+            d = self.exchange('print({0})'.format(fn))
+            if d.find('function:') == -1:
+                break
+        else:
+            log.debug('Found all required lua functions, no need to upload them')
+            return
+            
         data = SAVE_LUA.format(baud=self._port.baudrate)
         ##change any \r\n to just \n and split on that
         lines = data.replace('\r', '').split('\n')