Compare commits
18 Commits
Author | SHA1 | Date |
---|---|---|
Rick Companje | 924285b51e | |
Rick Companje | d453818455 | |
peteruithoven | 550e151153 | |
Simon Voordouw | 2ee6b05e61 | |
Simon Voordouw | c3e4ec88a8 | |
Simon Voordouw | 59c71a34ba | |
Simon Voordouw | e5de852087 | |
Rick Companje | 02fc0ea91b | |
Simon Voordouw | 634465fdd6 | |
Simon Voordouw | 1bbb327178 | |
Simon Voordouw | fdbc07b377 | |
Simon Voordouw | c536fe3221 | |
Simon Voordouw | db259bbfc6 | |
Simon Voordouw | 22b6abfd8b | |
Simon Voordouw | 2883a066ef | |
Simon Voordouw | 8adc74876e | |
Simon Voordouw | 753672e164 | |
Simon Voordouw | 0acc20f498 |
|
@ -1,4 +1,13 @@
|
|||
Changelog
|
||||
|
||||
# 0.11.0 (12 jul 2017)
|
||||
# 0.11.0-c (10 jul 2017)
|
||||
- fix: Also closing file descriptor after removing current print file (commit 550e151)
|
||||
|
||||
# 0.11.0-b (6 jul 2017)
|
||||
- show id of current print in d3dapi/info/status when printing in 'fetch' mode.
|
||||
- code reuse and cleanup for control, kill and status
|
||||
|
||||
# 0.11.0-a (23 jun 2017)
|
||||
- Added 'fetch' functionality to let the WiFi-Box print from a remote server. This enables the WiFi-Box to print large g-code files. (yeah!)
|
||||
- Added support for the Renkforce RF100 printer.
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.11.0-a
|
||||
0.11.0
|
|
@ -48,6 +48,36 @@ function M.temperature(request, response)
|
|||
end
|
||||
end
|
||||
|
||||
local function setCurrentPrint(id)
|
||||
local cpfileName = "/tmp/current-print"
|
||||
if id == nil then
|
||||
io.popen('rm ' .. cpfileName):close()
|
||||
return true
|
||||
end
|
||||
|
||||
local cpfile = io.open(cpfileName, 'w+')
|
||||
if cpfile == nil then
|
||||
return false
|
||||
end
|
||||
cpfile:write(id)
|
||||
cpfile:close()
|
||||
return true
|
||||
end
|
||||
|
||||
local function getCurrentPrint()
|
||||
local idfile = io.open('/tmp/current-print')
|
||||
if idfile ~= nil then
|
||||
return idfile:read('*a')
|
||||
end
|
||||
end
|
||||
|
||||
local function stopFetch()
|
||||
log:verbose(MOD_ABBR, "stopping print-fetch and removing start/endgcode")
|
||||
io.popen("killall print-fetch"):close()
|
||||
io.popen("rm /tmp/startcode /tmp/endcode"):close()
|
||||
setCurrentPrint(nil)
|
||||
end
|
||||
|
||||
function M.progress(request, response)
|
||||
local argId = request:get("id")
|
||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
|
@ -56,11 +86,7 @@ function M.progress(request, response)
|
|||
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
||||
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
|
||||
|
||||
local idfile = io.open('/tmp/currentprint')
|
||||
local printId
|
||||
if idfile ~= nil then
|
||||
printId = idfile:read('*a')
|
||||
end
|
||||
local printId = getCurrentPrint()
|
||||
|
||||
|
||||
response:addData('id', argId)
|
||||
|
@ -166,14 +192,13 @@ function M.stop_POST(request, response)
|
|||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
stopFetch()
|
||||
|
||||
if(argGcode == nil) then
|
||||
argGcode = ""
|
||||
end
|
||||
local rv,msg = printer:stopPrint(argGcode)
|
||||
|
||||
io.popen("killall print-fetch")
|
||||
io.popen("rm /tmp/currentprint /tmp/startcode /tmp/endcode")
|
||||
|
||||
|
||||
response:addData('id', argId)
|
||||
if rv then
|
||||
|
@ -200,32 +225,24 @@ local function addSequenceNumbering(printer, response)
|
|||
end
|
||||
|
||||
function M.fetch_POST(request, response)
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
else
|
||||
accessManager.setController(request.remoteAddress)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
local state = printer:getState()
|
||||
if state ~= "idle" then
|
||||
response:setError("printer is not idle")
|
||||
response:setFail("printer is not idle")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
||||
response:addData('gcode_clear',true)
|
||||
stopFetch()
|
||||
local rv,msg = printer:clearGcode()
|
||||
|
||||
if rv == false then
|
||||
|
@ -257,7 +274,6 @@ function M.fetch_POST(request, response)
|
|||
return
|
||||
end
|
||||
endCodeFile:write(endCode)
|
||||
|
||||
end
|
||||
|
||||
local socket = printer:getId()
|
||||
|
@ -275,14 +291,9 @@ function M.fetch_POST(request, response)
|
|||
response:setError("no id supplied")
|
||||
return
|
||||
end
|
||||
local cpfile = io.open("/tmp/currentprint", 'w+')
|
||||
if cpfile == nil then
|
||||
response:setError("could not save id")
|
||||
return
|
||||
end
|
||||
cpfile:write(id)
|
||||
cpfile:close()
|
||||
setCurrentPrint(id)
|
||||
|
||||
log:info(MOD_ABBR, " starting fetch print. id: " .. id .. " server: " .. gcodeServer)
|
||||
io.popen("print-fetch " .. socket .. " " .. gcodeServer .. " " .. id .. gcodeFiles)
|
||||
|
||||
response:setSuccess()
|
||||
|
@ -300,20 +311,12 @@ end
|
|||
-- a fail with a (formal, i.e., parseable) status argument will be returned;
|
||||
-- additionally, current sequence number and total will be returned (both are -1 if they have not been set)
|
||||
function M.print_POST(request, response)
|
||||
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
|
||||
if not accessManager.hasControl(request.remoteAddress) then
|
||||
response:setFail("No control access")
|
||||
return
|
||||
else
|
||||
accessManager.setController(request.remoteAddress)
|
||||
end
|
||||
|
||||
local argId = request:get("id")
|
||||
local argGcode = request:get("gcode")
|
||||
local argClear = utils.toboolean(request:get("clear"))
|
||||
|
@ -329,6 +332,8 @@ function M.print_POST(request, response)
|
|||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||
if not printer or not printer:hasSocket() then return end
|
||||
|
||||
stopFetch()
|
||||
|
||||
response:addData('id', argId)
|
||||
|
||||
if argGcode == nil or argGcode == '' then
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#!/usr/bin/lua
|
||||
|
||||
local function log(message)
|
||||
os.execute("logger " .. message)
|
||||
print(message)
|
||||
os.execute("logger " .. message)
|
||||
print(message)
|
||||
end
|
||||
|
||||
if (table.getn(arg) == 0) then
|
||||
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
||||
return
|
||||
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
||||
return
|
||||
end
|
||||
|
||||
log("starting gcode fetch program")
|
||||
|
@ -19,8 +19,8 @@ local p3d = require("print3d")
|
|||
|
||||
local printer = p3d.getPrinter(arg[1])
|
||||
if printer == nil then
|
||||
log("error connecting to printer")
|
||||
return
|
||||
log("error connecting to printer")
|
||||
return
|
||||
end
|
||||
|
||||
local gcodeServer = arg[2]
|
||||
|
@ -35,8 +35,8 @@ log("gcode server: " .. gcodeServer)
|
|||
local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a"))
|
||||
|
||||
if info == nil then
|
||||
log("could not retrieve file info")
|
||||
return
|
||||
log("could not retrieve file info")
|
||||
return
|
||||
end
|
||||
|
||||
local current_line = 0
|
||||
|
@ -49,64 +49,64 @@ local startCode = nil
|
|||
local endCode = nil
|
||||
|
||||
function countlines(file)
|
||||
return tonumber(io.popen("wc -l < " .. file):read('*a'))
|
||||
return tonumber(io.popen("wc -l < " .. file):read('*a'))
|
||||
end
|
||||
|
||||
function readGCodeArg(argi)
|
||||
local gcodeFile = arg[argi]
|
||||
return io.open(gcodeFile):read('*a')
|
||||
local gcodeFile = arg[argi]
|
||||
return io.open(gcodeFile):read('*a')
|
||||
end
|
||||
|
||||
if table.getn(arg) >= 5 then
|
||||
startCode = readGCodeArg(4)
|
||||
endCode = readGCodeArg(5)
|
||||
startCode = readGCodeArg(4)
|
||||
endCode = readGCodeArg(5)
|
||||
end
|
||||
|
||||
if startCode ~= nil then
|
||||
log("appending start gcode")
|
||||
printer:appendGcode(startCode)
|
||||
log("appending start gcode")
|
||||
printer:appendGcode(startCode)
|
||||
end
|
||||
|
||||
while(not finished)
|
||||
do
|
||||
local f = io.popen("wget -qO - " .. gcodeServer .. "/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, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||
local f = io.popen("wget -qO - " .. gcodeServer .. "/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
|
||||
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")
|
||||
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, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue