mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Fixes to update module and api.
This commit is contained in:
parent
b6528e4752
commit
581ea273b2
@ -62,20 +62,20 @@ function M.download_POST(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if argClearGcode then
|
if argClearGcode then
|
||||||
response:addData('gcode_clear',true)
|
response:addData('gcode_clear',true)
|
||||||
local rv,msg = printer:clearGcode()
|
local rv,msg = printer:clearGcode()
|
||||||
|
|
||||||
if not rv then
|
if not rv then
|
||||||
response:setError(msg)
|
response:setError(msg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vEnt,msg = updater.findVersion(argVersion)
|
vEnt,msg = updater.findVersion(argVersion)
|
||||||
if vEnt == nil then
|
if vEnt == nil then
|
||||||
response:setFail("error searching version index (" .. msg .. ")")
|
response:setFail("error searching version index (" .. msg .. ")")
|
||||||
return
|
return
|
||||||
else if vEnt == false then
|
elseif vEnt == false then
|
||||||
response:setFail("no such version")
|
response:setFail("no such version")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -99,7 +99,16 @@ function M.install_POST(request, response)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local rv,msg = updater.flashImageVersion(argVersion)
|
vEnt,msg = updater.findVersion(argVersion)
|
||||||
|
if vEnt == nil then
|
||||||
|
response:setFail("error searching version index (" .. msg .. ")")
|
||||||
|
return
|
||||||
|
elseif vEnt == false then
|
||||||
|
response:setFail("no such version")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local rv,msg = updater.flashImageVersion(vEnt)
|
||||||
|
|
||||||
if not rv then response:setFail("installation failed (" .. msg .. ")")
|
if not rv then response:setFail("installation failed (" .. msg .. ")")
|
||||||
else response:setSuccess()
|
else response:setSuccess()
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
-- copy improved fileSize back to utils (add unit tests!)
|
-- copy improved fileSize back to utils (add unit tests!)
|
||||||
-- create new utils usable by updater as well as api? (remove dependencies on uci and logger etc)
|
-- create new utils usable by updater as well as api? (remove dependencies on uci and logger etc)
|
||||||
-- note: take care not to print any text in module functions, as this breaks http responses
|
-- note: take care not to print any text in module functions, as this breaks http responses
|
||||||
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?)
|
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?) <- create api call to get all info on all versions?
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@ -64,6 +64,7 @@ end
|
|||||||
|
|
||||||
-- splits the return status from os.execute (see: http://stackoverflow.com/questions/16158436/how-to-shift-and-mask-bits-from-integer-in-lua)
|
-- splits the return status from os.execute (see: http://stackoverflow.com/questions/16158436/how-to-shift-and-mask-bits-from-integer-in-lua)
|
||||||
local function splitExitStatus(exitStatus)
|
local function splitExitStatus(exitStatus)
|
||||||
|
if exitStatus == -1 then return -1,-1 end
|
||||||
local cmdStatus = math.floor(exitStatus / 256)
|
local cmdStatus = math.floor(exitStatus / 256)
|
||||||
local systemStatus = exitStatus - cmdStatus * 256
|
local systemStatus = exitStatus - cmdStatus * 256
|
||||||
return cmdStatus, systemStatus
|
return cmdStatus, systemStatus
|
||||||
@ -183,7 +184,7 @@ end
|
|||||||
-- returns return value of command
|
-- returns return value of command
|
||||||
local function runCommand(command, dryRun)
|
local function runCommand(command, dryRun)
|
||||||
D("about to run: '" .. command .. "'")
|
D("about to run: '" .. command .. "'")
|
||||||
return (not dryRun) and os.execute(command) or 0
|
return (not dryRun) and os.execute(command) or -1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function removeFile(filePath)
|
local function removeFile(filePath)
|
||||||
@ -263,14 +264,18 @@ end
|
|||||||
|
|
||||||
function M.getStatus()
|
function M.getStatus()
|
||||||
if not baseUrl then baseUrl = M.DEFAULT_BASE_URL end
|
if not baseUrl then baseUrl = M.DEFAULT_BASE_URL end
|
||||||
|
local unknownVersion = { major = 0, minor = 0, patch = 0 }
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
local verTable,msg = M.getAvailableVersions()
|
local verTable,msg = M.getAvailableVersions()
|
||||||
if not verTable then return nil,msg end
|
if not verTable then
|
||||||
|
D("could not obtain available versions (" .. msg .. ")")
|
||||||
|
-- TODO: set an error state in result to signify we probably do not have internet access?
|
||||||
|
end
|
||||||
|
|
||||||
local newest = verTable[#verTable]
|
local newest = verTable and verTable[#verTable]
|
||||||
result.currentVersion = M.getCurrentVersion()
|
result.currentVersion = M.getCurrentVersion()
|
||||||
result.newestVersion = newest and newest.version or { major = 0, minor = 0, patch = 0 }
|
result.newestVersion = newest and newest.version or unknownVersion
|
||||||
result.stateCode, result.stateText = getState()
|
result.stateCode, result.stateText = getState()
|
||||||
result.stateCode = tonumber(result.stateCode)
|
result.stateCode = tonumber(result.stateCode)
|
||||||
|
|
||||||
@ -316,6 +321,7 @@ end
|
|||||||
-- verTable is optional, getAvailableVersions will be used to obtain it if nil
|
-- verTable is optional, getAvailableVersions will be used to obtain it if nil
|
||||||
function M.findVersion(version, verTable)
|
function M.findVersion(version, verTable)
|
||||||
local msg = nil
|
local msg = nil
|
||||||
|
version = M.parseVersion(version)
|
||||||
if not verTable then verTable,msg = M.getAvailableVersions() end
|
if not verTable then verTable,msg = M.getAvailableVersions() end
|
||||||
|
|
||||||
if not verTable then return nil,msg end
|
if not verTable then return nil,msg end
|
||||||
|
Loading…
Reference in New Issue
Block a user