mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Create combined gcode file in printer-specific directory; add mass-flashing script (WIP).
This commit is contained in:
parent
d1a58fc564
commit
016d18c93a
60
extra/scripts/auto-flash.sh
Executable file
60
extra/scripts/auto-flash.sh
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Adapted from: http://wiki.openwrt.org/toh/tp-link/tl-mr3020?s[]=3020#oem.mass.flashing
|
||||||
|
|
||||||
|
# Pass the firmware file to be flashed as the first parameter.
|
||||||
|
#
|
||||||
|
# The second curl call will time out, but it's expected. Once the
|
||||||
|
# script exits you can unplug the ethernet cable and proceed to the
|
||||||
|
# next router, but KEEP each router ON POWER until the new image is
|
||||||
|
# fully written! When flashing is done the router automatically
|
||||||
|
# reboots (as shown by all the leds flashing once).
|
||||||
|
|
||||||
|
#IMAGE_FILE_DEFAULT=bin/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin
|
||||||
|
IMAGE_FILE_DEFAULT=bin/ar71xx/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin
|
||||||
|
|
||||||
|
QUIET=no
|
||||||
|
IMAGE_FILE=$IMAGE_FILE_DEFAULT
|
||||||
|
|
||||||
|
while getopts hqf: arg; do
|
||||||
|
case $arg in
|
||||||
|
h)
|
||||||
|
echo "$0: automatically flash an openwrt image to a TP-Link MR3020;"
|
||||||
|
echo " default image file: '$IMAGE_FILE_DEFAULT';"
|
||||||
|
echo " pass -q to be less verbose and optionally specify a different image file."
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
q)
|
||||||
|
QUIET=yes
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
IMAGE_FILE=$OPTARG
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -f $IMAGE_FILE ]; then
|
||||||
|
echo "$0: image '$IMAGE_FILE' does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $QUIET == "yes" ]; then
|
||||||
|
exec > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
curl \
|
||||||
|
--user admin:admin \
|
||||||
|
--user-agent 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0' \
|
||||||
|
--referer 'http://192.168.0.254/userRpm/SoftwareUpgradeRpm.htm' \
|
||||||
|
--form "Filename=@$IMAGE_FILE" -F 'Upgrade=Upgrade' \
|
||||||
|
http://192.168.0.254/incoming/Firmware.htm
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
curl \
|
||||||
|
--max-time 2 \
|
||||||
|
--user admin:admin \
|
||||||
|
--user-agent 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0' \
|
||||||
|
--referer 'http://192.168.0.254/incoming/Firmware.htm' \
|
||||||
|
http://192.168.0.254/userRpm/FirmwareUpdateTemp.htm
|
@ -12,7 +12,7 @@ local ULTIFI_BASE_PATH = '/tmp/UltiFi'
|
|||||||
local TEMPERATURE_FILE = 'temp.out'
|
local TEMPERATURE_FILE = 'temp.out'
|
||||||
local PROGRESS_FILE = 'progress2.out'
|
local PROGRESS_FILE = 'progress2.out'
|
||||||
local COMMAND_FILE = 'command.in'
|
local COMMAND_FILE = 'command.in'
|
||||||
local GCODE_TMP_FILE = '/tmp/UltiFi/combined.gc'
|
local GCODE_TMP_FILE = 'combined.gc'
|
||||||
|
|
||||||
-- returns full path + ultifi path or nil
|
-- returns full path + ultifi path or nil
|
||||||
local function printerExists(id)
|
local function printerExists(id)
|
||||||
@ -66,13 +66,15 @@ local function sendGcode(printerPath, gcode)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addToGcodeFile(gcode)
|
local function addToGcodeFile(printerPath, gcode)
|
||||||
if not gcode or type(gcode) ~= 'string' then return nil,"missing gcode data" end
|
if not gcode or type(gcode) ~= 'string' then return nil,"missing gcode data" end
|
||||||
|
|
||||||
local gcf,msg = io.open(GCODE_TMP_FILE, 'a+')
|
local gtFile = printerPath .. '/' .. GCODE_TMP_FILE
|
||||||
|
|
||||||
|
local gcf,msg = io.open(gtFile, 'a+')
|
||||||
if not gcf then return nil,msg end
|
if not gcf then return nil,msg end
|
||||||
|
|
||||||
log:debug("appending " .. gcode:len() .. " bytes of gcode to " .. GCODE_TMP_FILE)
|
log:debug("appending " .. gcode:len() .. " bytes of gcode to " .. gtFile)
|
||||||
gcf:write(gcode)
|
gcf:write(gcode)
|
||||||
gcf:write("\n")
|
gcf:write("\n")
|
||||||
gcf:close()
|
gcf:close()
|
||||||
@ -83,14 +85,15 @@ end
|
|||||||
-- assumes printerPath exists, returns true if successful, false if command file already exists and is non-empty (i.e. printer busy),
|
-- assumes printerPath exists, returns true if successful, false if command file already exists and is non-empty (i.e. printer busy),
|
||||||
-- nil+err if file could not be opened
|
-- nil+err if file could not be opened
|
||||||
local function printGcodeFile(printerPath)
|
local function printGcodeFile(printerPath)
|
||||||
|
local gtFile = printerPath .. '/' .. GCODE_TMP_FILE
|
||||||
local cmdPath = printerPath .. '/' .. COMMAND_FILE
|
local cmdPath = printerPath .. '/' .. COMMAND_FILE
|
||||||
local cmdf,msg = io.open(cmdPath, 'a+') -- 'a+' is important, do not overwrite current contents in any case
|
local cmdf,msg = io.open(cmdPath, 'a+') -- 'a+' is important, do not overwrite current contents in any case
|
||||||
|
|
||||||
if not cmdf then return nil,msg end
|
if not cmdf then return nil,msg end
|
||||||
if utils.fileSize(cmdf) > 0 then return false end
|
if utils.fileSize(cmdf) > 0 then return false end
|
||||||
|
|
||||||
log:debug("starting print of gcode in " .. GCODE_TMP_FILE)
|
log:debug("starting print of gcode in " .. gtFile)
|
||||||
cmdf:write('(SENDFILE=' .. GCODE_TMP_FILE)
|
cmdf:write('(SENDFILE=' .. gtFile)
|
||||||
cmdf:close()
|
cmdf:close()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -277,6 +280,8 @@ end
|
|||||||
--accepts: last(bool) (chunks will be concatenated and only when this argument is true will printing be started)
|
--accepts: last(bool) (chunks will be concatenated and only when this argument is true will printing be started)
|
||||||
function M.print_POST(request, response)
|
function M.print_POST(request, response)
|
||||||
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
||||||
|
local gtFile = ultipath .. '/' .. GCODE_TMP_FILE
|
||||||
|
|
||||||
if argId == nil then return end
|
if argId == nil then return end
|
||||||
|
|
||||||
local argGcode = request:get("gcode")
|
local argGcode = request:get("gcode")
|
||||||
@ -289,14 +294,14 @@ function M.print_POST(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if argIsFirst == true then
|
if argIsFirst == true then
|
||||||
log:debug("clearing all gcode in " .. GCODE_TMP_FILE)
|
log:debug("clearing all gcode in " .. gtFile)
|
||||||
response:addData('gcode_clear',true)
|
response:addData('gcode_clear',true)
|
||||||
os.remove(GCODE_TMP_FILE)
|
os.remove(gtFile)
|
||||||
end
|
end
|
||||||
|
|
||||||
local rv,msg
|
local rv,msg
|
||||||
|
|
||||||
rv,msg = addToGcodeFile(argGcode)
|
rv,msg = addToGcodeFile(ultipath, argGcode)
|
||||||
if rv == nil then
|
if rv == nil then
|
||||||
response:setError("could not add gcode")
|
response:setError("could not add gcode")
|
||||||
response:addData('msg', msg)
|
response:addData('msg', msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user