feat(inferium-harvester): implement fetchRemotePlan
This commit is contained in:
parent
cdb0e6e84f
commit
e883deba5a
@ -2,11 +2,13 @@ local utils = require('libs/utils')
|
|||||||
local turtleUtils = require('libs/turtle-utils')
|
local turtleUtils = require('libs/turtle-utils')
|
||||||
local config = require('config/harvesting')
|
local config = require('config/harvesting')
|
||||||
|
|
||||||
local VERSION = "0.5.0"
|
local VERSION = "0.6.0"
|
||||||
local IDLE_TIME = 2
|
local IDLE_TIME = 2
|
||||||
local WAIT_ITEM_IDLE_TIME = 5
|
local WAIT_ITEM_IDLE_TIME = 5
|
||||||
local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2
|
local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2
|
||||||
local MIN_FREE_SLOTS_BEFORE_COMPACT = 4
|
local MIN_FREE_SLOTS_BEFORE_COMPACT = 4
|
||||||
|
local INFERIUM_QUERY_PORT = 111
|
||||||
|
local INFERIUM_REPLY_PORT = 112
|
||||||
|
|
||||||
-- a table with the list of current crops
|
-- a table with the list of current crops
|
||||||
local localPlan = nil
|
local localPlan = nil
|
||||||
@ -256,9 +258,39 @@ local function retrieveLocalPlan()
|
|||||||
goBackToHome()
|
goBackToHome()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: fetch timeout ?
|
||||||
local function fetchRemotePlan()
|
local function fetchRemotePlan()
|
||||||
-- TODO
|
local fallbackPlan = config.defaultRemotePlan or {}
|
||||||
return config.defaultRemotePlan or {}
|
|
||||||
|
local modem = peripheral.find("modem")
|
||||||
|
|
||||||
|
if not modem then
|
||||||
|
return fallbackPlan
|
||||||
|
end
|
||||||
|
|
||||||
|
modem.open(INFERIUM_REPLY_PORT)
|
||||||
|
|
||||||
|
local message = { type = 'getplan', payload = { computerId = os.getComputerID() } }
|
||||||
|
modem.transmit(INFERIUM_QUERY_PORT, INFERIUM_REPLY_PORT, textutils.serialize(message))
|
||||||
|
|
||||||
|
local channel, replyRawMessage
|
||||||
|
repeat
|
||||||
|
_, _, channel, _, replyRawMessage = os.pullEvent("modem_message")
|
||||||
|
until channel == INFERIUM_REPLY_PORT
|
||||||
|
|
||||||
|
modem.close(INFERIUM_REPLY_PORT)
|
||||||
|
|
||||||
|
if not replyRawMessage then
|
||||||
|
return fallbackPlan
|
||||||
|
end
|
||||||
|
|
||||||
|
local replyMessage = textutils.unserialize(replyRawMessage)
|
||||||
|
|
||||||
|
if replyMessage and replyMessage.payload then
|
||||||
|
return replyMessage.payload
|
||||||
|
end
|
||||||
|
|
||||||
|
return fallbackPlan
|
||||||
end
|
end
|
||||||
|
|
||||||
local function removeSeeds(seeds)
|
local function removeSeeds(seeds)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user