From 2b2305d02c43368e83294c496080535fa705fdce Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 11 Jan 2023 18:36:28 +0000 Subject: [PATCH] Upload files to 'Controller' --- Controller/wheatDaemon.lua | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Controller/wheatDaemon.lua diff --git a/Controller/wheatDaemon.lua b/Controller/wheatDaemon.lua new file mode 100644 index 0000000..d96cf9c --- /dev/null +++ b/Controller/wheatDaemon.lua @@ -0,0 +1,72 @@ +require("Wheat") +local path = "/wheat/config.txt" +local hostPC = 30 +sleep(1) +rednet.open("right") +rednet.send(hostPC, "started", "spruceCut") +local wheat = Wheat:new() + +function toMatrix(str) + local matrix = {} + assert(type(str) == "string") + assert(str:sub(1,1) == "{", "the string must begin with a \"{\"") + local len = str:len() + assert(str:sub(len,len) == "}", "the string must end with a \"}\"") + local s1, ob = str:gsub("{", "{") + local s2, cb = str:gsub("}", "}") + assert(ob == cb, "the string must have the same amount of opening brackets as closing brackets") + + str = str:sub(2, len - 1) + len = len - 2 + + if(str:sub(1,1) == "{") then + + end +end + +function toArray(str) + local len = str:len() + local comma = str:sub(",") + local arr = {} + while(type(comma)=="number") do + arr[#arr+1] = str:sub(1, comma-1) + str = str:sub(comma + 1, len) + len = str:len() + comma = str:sub(",") + end + return arr +end + +function answer(message, id) + sleep(0.1) + rednet.send(id, message, "received") + sleep(0.1) + if(message == "init") then + wheat:readConfig(path) + wheat:createMatrix() + rednet.send(id, "init finished", "confirm") + elseif(message == "getMatrix") then + rednet.send(id, wheat:getMatrixString(), "confirm") + elseif(message == "plantCrop") then + wheat:plantAll() + rednet.send(id, "plant finished", "confirm") + elseif(message == "harvest") then + wheat:harvestAll() + rednet.send(id, "harvest finished", "confirm") + elseif(message == "getFuelLevel") then + rednet.send(id, tostring(wheat:getFuelLevel()), "confirm") + elseif(message == "refuel") then + --wheat:refuel() + rednet.send(id, "refueled", "confirm") + end + rednet.send(id, "could not resolve message", "error") +end + +local function main() + while true do + local id, message = rednet.receive() + answer(message, id) + end +end + +main() \ No newline at end of file