mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Merge branch 'feature/printerdriver' of https://github.com/Doodle3D/doodle3d-firmware into feature/printerdriver
Conflicts: src/rest/api/api_info.lua src/rest/api/api_printer.lua
This commit is contained in:
commit
e0c4c81d75
@ -11,9 +11,10 @@ local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
|||||||
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
|
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
|
||||||
local WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
local WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
||||||
local WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_LOG_FILENAME
|
local WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_LOG_FILENAME
|
||||||
local ULTIFI_PATH = '/tmp/UltiFi'
|
|
||||||
local SYSLOG_FILENAME = 'syslog'
|
local SYSLOG_FILENAME = 'syslog'
|
||||||
local ULTIFI_LOG_FILENAME = 'server.log'
|
local PRINT3D_BASEPATH = '/tmp'
|
||||||
|
local PRINT3D_LOG_FILENAME_PREFIX = 'print3d-'
|
||||||
|
local PRINT3D_LOG_FILENAME_SUFFIX = '.log'
|
||||||
local LOG_COLLECT_ARCHIVE_FILENAME = LOG_COLLECT_DIRNAME .. '.tgz'
|
local LOG_COLLECT_ARCHIVE_FILENAME = LOG_COLLECT_DIRNAME .. '.tgz'
|
||||||
local LOG_COLLECT_ARCHIVE_FILE = TMP_DIR .. '/' .. LOG_COLLECT_ARCHIVE_FILENAME
|
local LOG_COLLECT_ARCHIVE_FILE = TMP_DIR .. '/' .. LOG_COLLECT_ARCHIVE_FILENAME
|
||||||
|
|
||||||
@ -42,63 +43,57 @@ end
|
|||||||
function M.logfiles(request, response)
|
function M.logfiles(request, response)
|
||||||
local rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
local rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
||||||
local rv,msg = lfs.chdir(TMP_DIR)
|
local rv,msg = lfs.chdir(TMP_DIR)
|
||||||
|
|
||||||
local ultip,msg = lfs.attributes(ULTIFI_PATH, 'mode')
|
|
||||||
|
|
||||||
|
|
||||||
--[[ create temporary files ]]--
|
--[[ create temporary files ]]--
|
||||||
|
|
||||||
local rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
|
local rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
|
||||||
|
|
||||||
local rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
local rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||||
|
|
||||||
if ultip and ultip == 'directory' then
|
for file in lfs.dir(PRINT3D_BASEPATH) do
|
||||||
for file in lfs.dir(ULTIFI_PATH) do
|
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
||||||
if file ~= '.' and file ~= '..' then
|
local srcLogFile = PRINT3D_BASEPATH .. '/' .. file
|
||||||
local srcLogFile = ULTIFI_PATH .. '/' .. file .. '/' .. ULTIFI_LOG_FILENAME
|
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
||||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file .. '-' .. ULTIFI_LOG_FILENAME
|
|
||||||
local rv,sig,code = redirectedExecute('cp ' .. srcLogFile .. ' ' .. tgtLogFile)
|
local rv,sig,code = redirectedExecute('cp ' .. srcLogFile .. ' ' .. tgtLogFile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
local rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
||||||
|
|
||||||
|
|
||||||
--[[ add response content ]]--
|
--[[ add response content ]]--
|
||||||
|
|
||||||
local rv,msg = response:setBinaryFileData(LOG_COLLECT_ARCHIVE_FILE, LOG_COLLECT_ARCHIVE_FILENAME, 'application/x-compressed')
|
local rv,msg = response:setBinaryFileData(LOG_COLLECT_ARCHIVE_FILE, LOG_COLLECT_ARCHIVE_FILENAME, 'application/x-compressed')
|
||||||
if not rv then
|
if not rv then
|
||||||
response:setError("could not set binary data from file '" .. LOG_COLLECT_ARCHIVE_FILE .. "' (" .. msg .. ")")
|
response:setError("could not set binary data from file '" .. LOG_COLLECT_ARCHIVE_FILE .. "' (" .. msg .. ")")
|
||||||
else
|
else
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[ remove temporary files ]]--
|
--[[ remove temporary files ]]--
|
||||||
|
|
||||||
if ultip and ultip == 'directory' then
|
for file in lfs.dir(LOG_COLLECT_DIR) do
|
||||||
for file in lfs.dir(ULTIFI_PATH) do
|
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
||||||
if file ~= '.' and file ~= '..' then
|
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
||||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file .. '-' .. ULTIFI_LOG_FILENAME
|
local rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
|
||||||
local rv,sig,code = redirectedExecute('rm ' .. tgtLogFile)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_LOG_FILENAME)
|
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_LOG_FILENAME)
|
||||||
|
|
||||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||||
|
|
||||||
local rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
local rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
||||||
|
|
||||||
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_ARCHIVE_FILE)
|
local rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_ARCHIVE_FILE)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.access(request, response)
|
function M.access(request, response)
|
||||||
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
||||||
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
|
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
|
||||||
|
|
||||||
-- when there is a controller we check if the printer is idle,
|
-- when there is a controller we check if the printer is idle,
|
||||||
-- if so, it should be done printing and we can clear the controller
|
-- if so, it should be done printing and we can clear the controller
|
||||||
if accessManager.getController() ~= "" then
|
if accessManager.getController() ~= "" then
|
||||||
@ -107,7 +102,7 @@ function M.access(request, response)
|
|||||||
local rv,msg = printer:getState()
|
local rv,msg = printer:getState()
|
||||||
if rv then
|
if rv then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
if(state == "idle") then -- TODO: define in constants somewhere
|
if(state == "idle") then -- TODO: define in constants somewhere
|
||||||
accessManager.setController("") -- clear controller
|
accessManager.setController("") -- clear controller
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -115,9 +110,10 @@ function M.access(request, response)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local hasControl = accessManager.hasControl(request.remoteAddress)
|
local hasControl = accessManager.hasControl(request.remoteAddress)
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
|
|
||||||
response:addData('has_control', hasControl)
|
response:addData('has_control', hasControl)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -138,7 +134,6 @@ function M.status(request, response)
|
|||||||
if(rv == false) then return end
|
if(rv == false) then return end
|
||||||
end
|
end
|
||||||
response:addData('v', 10)
|
response:addData('v', 10)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -11,12 +11,6 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local ULTIFI_BASE_PATH = '/tmp/UltiFi'
|
|
||||||
local TEMPERATURE_FILE = 'temp.out'
|
|
||||||
local PROGRESS_FILE = 'progress2.out'
|
|
||||||
local COMMAND_FILE = 'command.in'
|
|
||||||
local GCODE_TMP_FILE = 'combined.gc'
|
|
||||||
|
|
||||||
function M._global(request, response)
|
function M._global(request, response)
|
||||||
-- TODO: list all printers (based on /dev/ttyACM* and /dev/ttyUSB*)
|
-- TODO: list all printers (based on /dev/ttyACM* and /dev/ttyUSB*)
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
@ -49,16 +43,17 @@ function M.progress(request, response)
|
|||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
if not printer then return false end
|
if not printer then return false end
|
||||||
|
|
||||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `numLines` the message in such case.
|
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
||||||
local currentLine,totalLines = printer:getProgress()
|
local currentLine,bufferedLines,totalLines = printer:getProgress()
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if currentLine then
|
if currentLine then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('current_line', currentLine)
|
response:addData('current_line', currentLine)
|
||||||
|
response:addData('buffered_lines', bufferedLines)
|
||||||
response:addData('total_lines', totalLines)
|
response:addData('total_lines', totalLines)
|
||||||
else
|
else
|
||||||
response:setError(totalLines)
|
response:setError(bufferedLines)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -141,7 +136,7 @@ function M.print_POST(request, response)
|
|||||||
elseif controllerIP == request.remoteAddress then
|
elseif controllerIP == request.remoteAddress then
|
||||||
hasControl = true
|
hasControl = true
|
||||||
end
|
end
|
||||||
|
|
||||||
log:info(" hasControl: "..utils.dump(hasControl))
|
log:info(" hasControl: "..utils.dump(hasControl))
|
||||||
if not hasControl then
|
if not hasControl then
|
||||||
response:setFail("No control access")
|
response:setFail("No control access")
|
||||||
|
Loading…
Reference in New Issue
Block a user