Compare commits
No commits in common. "1f593d05422392dbd46df6dc4b8f567f37bf3ea5" and "5dd175bb0074e401359573b14b95b9a9bf793214" have entirely different histories.
1f593d0542
...
5dd175bb00
@ -36,9 +36,6 @@ Packet format is uniform between master <-> slaves and is structured like so:
|
||||
itemquant: int()
|
||||
destination: int()
|
||||
location: [int(),int(),int()]
|
||||
|
||||
// Dump for additional body data
|
||||
body: any
|
||||
}
|
||||
```
|
||||
|
||||
@ -52,7 +49,6 @@ Packet format is uniform between master <-> slaves and is structured like so:
|
||||
| `itemname` | false | string | The unlocalized name of an item. Used for querying, crafting, movement, etc. |
|
||||
| `itemquant` | false | int | Quantity of the aforementioned item |
|
||||
| `destination` | false | int | The CC ID of the intended recipient of the item |
|
||||
| `body` | false | any | Any additional body data per the requirements of a query, such as a detailed list of inventory contents |
|
||||
|
||||
### Slave Node Initialization
|
||||
|
||||
@ -67,6 +63,8 @@ Packet format is uniform between master <-> slaves and is structured like so:
|
||||
|
||||
### Inventory Search (query)
|
||||
|
||||
* A sender node (master or slave) sends out a `ping`
|
||||
* All available slaves respond with `pong`
|
||||
* The sender node sends a packet with type `query`. Field `itemname` is populated with an item to query for.
|
||||
* Each available slave responds with type `query`.
|
||||
* `itemname` is populated with data from the previous packet
|
||||
|
@ -24,7 +24,6 @@ modem_side = peripheral.getName(modem)
|
||||
-- Master globals
|
||||
m_slaves = {}
|
||||
-- Slave globals
|
||||
s_chest = peripheral.wrap("top") or nil
|
||||
|
||||
-- Common functions
|
||||
function c_mainLoop(loopfunc)
|
||||
@ -34,7 +33,7 @@ function c_mainLoop(loopfunc)
|
||||
end
|
||||
end
|
||||
function c_waitForMessage()
|
||||
-- Waits for a message on the modem, timing out after some duration
|
||||
-- Waits for a message on the modem, timing out after 1 second
|
||||
local sender, message = rednet.receive(packet_magic, 1)
|
||||
if message then
|
||||
if
|
||||
@ -75,9 +74,7 @@ function m_loop()
|
||||
if msg["type"] == "pong" then
|
||||
local source = msg["sourceid"]
|
||||
print("Received pong from slave: " .. source)
|
||||
if (not m_slaves[source]) then
|
||||
m_slaves[source] = {}
|
||||
end
|
||||
m_slaves[source] = source
|
||||
end
|
||||
end
|
||||
function m_ping()
|
||||
@ -100,21 +97,9 @@ function s_loop()
|
||||
-- Respond to pings with pongs
|
||||
print("Received ping from master: " .. msg["sourceid"])
|
||||
c_sendMessage({type="pong"})
|
||||
elseif (msg["type"] == "query") then
|
||||
-- Analyze the attached inventory and see if we have the item
|
||||
else
|
||||
print("Unknown message: " .. textutils.serialize(msg))
|
||||
end
|
||||
-- If we have any items, we should stow them away. Put them in our chest if
|
||||
-- we can fit it, otherwise pass it along
|
||||
for i=1,16 do
|
||||
turtle.select(i)
|
||||
while turtle.getItemCount(i) > 0 do
|
||||
-- We have items in this slot -- push up until we can't anymore
|
||||
if not turtle.dropUp() then break end
|
||||
end
|
||||
if turtle.getItemCount(i) > 0 then turtle.drop() end
|
||||
end
|
||||
end
|
||||
|
||||
-- Application entrypoint
|
||||
@ -131,9 +116,6 @@ function main ()
|
||||
elseif (mode == "slave") then
|
||||
print("Beginning initialization as slave...")
|
||||
rednet.open(modem_side)
|
||||
if not s_chest then
|
||||
error("No connected inventory. Place one above this node.", 0)
|
||||
end
|
||||
|
||||
print("Entering main loop")
|
||||
c_mainLoop(s_loop)
|
||||
|
Loading…
Reference in New Issue
Block a user