Add some specs idk it doesn't matter i just found out that a wired net does this a million times better lol

This commit is contained in:
Salt 2024-02-26 01:03:04 -06:00
parent ba51252476
commit 1f593d0542
2 changed files with 24 additions and 2 deletions

View File

@ -36,6 +36,9 @@ 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
}
```
@ -49,6 +52,7 @@ 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

View File

@ -24,6 +24,7 @@ modem_side = peripheral.getName(modem)
-- Master globals
m_slaves = {}
-- Slave globals
s_chest = peripheral.wrap("top") or nil
-- Common functions
function c_mainLoop(loopfunc)
@ -33,7 +34,7 @@ function c_mainLoop(loopfunc)
end
end
function c_waitForMessage()
-- Waits for a message on the modem, timing out after 1 second
-- Waits for a message on the modem, timing out after some duration
local sender, message = rednet.receive(packet_magic, 1)
if message then
if
@ -74,7 +75,9 @@ function m_loop()
if msg["type"] == "pong" then
local source = msg["sourceid"]
print("Received pong from slave: " .. source)
m_slaves[source] = source
if (not m_slaves[source]) then
m_slaves[source] = {}
end
end
end
function m_ping()
@ -97,9 +100,21 @@ 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
@ -116,6 +131,9 @@ 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)