mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 02:53:49 +01:00
Merge pull request #70 from Doodle3D/feature/print-fetch
Feature/print fetch
This commit is contained in:
commit
ade1b2793b
4
Makefile
4
Makefile
@ -126,6 +126,10 @@ define Package/wifibox/install
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/logrotate-wifibox.conf $(1)/etc/logrotate.d/wifibox.conf
|
||||
|
||||
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/print-fetch.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/print-fetch.lua $(1)/bin/print-fetch
|
||||
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/FIRMWARE-VERSION $(1)/etc/wifibox-version
|
||||
|
||||
|
@ -418,4 +418,10 @@ M.doodle3d_update_baseUrl = {
|
||||
description = ''
|
||||
}
|
||||
|
||||
M.gcode_server = {
|
||||
default = 'http://gcodeserver.doodle3d.com',
|
||||
type = 'string',
|
||||
description =''
|
||||
}
|
||||
|
||||
return M
|
||||
|
@ -185,6 +185,69 @@ local function addSequenceNumbering(printer, response)
|
||||
end
|
||||
end
|
||||
|
||||
function M.fetch_POST(request, response)
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
local controllerIP = accessManager.getController()
|
||||
local hasControl = false
|
||||
if controllerIP == "" then
|
||||
accessManager.setController(request.remoteAddress)
|
||||
hasControl = true
|
||||
elseif controllerIP == request.remoteAddress then
|
||||
hasControl = true
|
||||
end
|
||||
|
||||
if not hasControl then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
||||
response:addData('gcode_clear',true)
|
||||
local rv,msg = printer:clearGcode()
|
||||
|
||||
if rv == false then
|
||||
response:addData('status', msg)
|
||||
response:setFail("could not clear gcode (" .. msg .. ")")
|
||||
elseif rv == nil then
|
||||
response:setError(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local gcodeFiles = " "
|
||||
local startCode = request:get("start_code")
|
||||
if startCode ~= nil then
|
||||
gcodeFiles = gcodeFiles .. '/tmp/startcode '
|
||||
io.open('/tmp/startcode', 'w+').write(startCode)
|
||||
end
|
||||
|
||||
local endCode = request:get("end_code")
|
||||
if endCode ~= nil then
|
||||
gcodeFiles = gcodeFiles .. '/tmp/endcode '
|
||||
io.open('/tmp/endcode', 'w+').write(endCode)
|
||||
end
|
||||
|
||||
local socket = printer:getId()
|
||||
if socket == nil then
|
||||
response:setError("no socket found")
|
||||
return
|
||||
end
|
||||
local remote = settings.get('gcode.server')
|
||||
if remote == nil then
|
||||
response:setError("no gcode server configured")
|
||||
return
|
||||
end
|
||||
local id = request:get("id")
|
||||
if id == nil then
|
||||
response:setError("no id supplied")
|
||||
return
|
||||
end
|
||||
io.popen("print-fetch " .. socket .. " " .. remote .. " " .. id .. gcodeFiles)
|
||||
response:setSuccess()
|
||||
end
|
||||
|
||||
--requires: gcode(string) (the gcode to be appended)
|
||||
--accepts: id(string) (the printer ID to append to)
|
||||
--accepts: clear(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
||||
|
108
src/script/print-fetch.lua
Executable file
108
src/script/print-fetch.lua
Executable file
@ -0,0 +1,108 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local function log(message)
|
||||
os.execute("logger " .. message)
|
||||
print(message)
|
||||
end
|
||||
|
||||
if (table.getn(arg) == 0) then
|
||||
print("Usage: ./print-fetch {printerSocket} {remoteURL} {id} [startGcode] [endGCode]")
|
||||
return
|
||||
end
|
||||
|
||||
log("starting gcode fetch program")
|
||||
|
||||
package.cpath = package.cpath .. '/usr/lib/lua/?.so'
|
||||
JSON = (loadfile "/usr/share/lua/wifibox/util/JSON.lua")()
|
||||
|
||||
local p3d = require("print3d")
|
||||
|
||||
local printer = p3d.getPrinter(arg[1])
|
||||
if printer == nil then
|
||||
log("error connecting to printer")
|
||||
return
|
||||
end
|
||||
|
||||
local remote = arg[2]
|
||||
|
||||
local finished = false
|
||||
|
||||
local id = arg[3]
|
||||
|
||||
log("gcode file id: " .. id)
|
||||
log("gcode server: " .. remote)
|
||||
|
||||
local info = JSON:decode(io.popen("wget -qO - " .. remote .. "/info/" .. id):read("*a"))
|
||||
|
||||
local current_line = 0
|
||||
local total_lines = tonumber(info["lines"])
|
||||
local started = false
|
||||
|
||||
log("total lines: " .. total_lines)
|
||||
|
||||
local startCode = nil
|
||||
local endCode = nil
|
||||
|
||||
function countlines(file)
|
||||
return tonumber(io.popen("wc -l < " .. file):read('*a'))
|
||||
end
|
||||
|
||||
function readGCodeArg(argi)
|
||||
local gcodeFile = arg[argi]
|
||||
total_lines = total_lines + countlines(gcodeFile)
|
||||
return io.open(gcodeFile):read('*a')
|
||||
end
|
||||
|
||||
if table.getn(arg) >= 5 then
|
||||
startCode = readGCodeArg(4)
|
||||
endCode = readGCodeArg(5)
|
||||
end
|
||||
|
||||
if startCode ~= nil then
|
||||
log("appending start gcode")
|
||||
printer:appendGcode(startCode)
|
||||
end
|
||||
|
||||
while(not finished)
|
||||
do
|
||||
local f = io.popen("wget -qO - " .. remote .. "/fetch/" .. id .. "/" .. current_line)
|
||||
local line = f:read()
|
||||
while line ~= nil do
|
||||
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||
current_line = current_line + 1
|
||||
line = f:read()
|
||||
end
|
||||
|
||||
if not started then
|
||||
started = true
|
||||
print("send print start command")
|
||||
printer:startPrint()
|
||||
end
|
||||
|
||||
if current_line >= total_lines then
|
||||
log("finished fetching gcode")
|
||||
if endCode ~= nil then
|
||||
log("appending end gcode")
|
||||
printer:appendGcode(endCode)
|
||||
end
|
||||
finished = true
|
||||
break
|
||||
end
|
||||
|
||||
|
||||
local accepts_new_gcode = false
|
||||
|
||||
while (not accepts_new_gcode)
|
||||
do
|
||||
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
|
||||
local percentageBufferSize = bufferSize / maxBufferSize
|
||||
|
||||
if percentageBufferSize < 0.8 then
|
||||
print("buffer below 80% capacity, sending new gcode")
|
||||
accepts_new_gcode = true
|
||||
else
|
||||
print("buffer above 80% capacity")
|
||||
os.execute("sleep 10")
|
||||
end
|
||||
end
|
||||
end
|
@ -10,3 +10,4 @@ config settings 'system'
|
||||
|
||||
config settings 'general'
|
||||
option printer_type 'ultimaker'
|
||||
option gcode_server 'http://gcodeserver.doodle3d.com'
|
||||
|
Loading…
Reference in New Issue
Block a user