Work on README, add duplicated logic for targeting
This commit is contained in:
parent
c8806be02d
commit
9f2b3a8050
@ -14,9 +14,7 @@ The master node must have a modem attached and be within range of all slave node
|
||||
|
||||
## Communication Protocol
|
||||
|
||||
Port 42914 is used for Master => Slave broadcasting
|
||||
|
||||
Port 42915 is used for Slave => Master return broadcasting
|
||||
Messages are sent over rednet with the protocol `ccstoragenet`.
|
||||
|
||||
### Packet Format
|
||||
|
||||
@ -52,17 +50,15 @@ Packet format is uniform between master <-> slaves and is structured like so:
|
||||
| `itemquant` | false | int | Quantity of the aforementioned item |
|
||||
| `destination` | false | int | The CC ID of the intended recipient of the item |
|
||||
|
||||
Messages are sent over rednet with the protocol `ccstoragenet`.
|
||||
|
||||
### Slave Node Initialization
|
||||
|
||||
* The slave starts up
|
||||
* The slave starts up and immediately listens for messages
|
||||
|
||||
### Master Node Initialization
|
||||
|
||||
* The master node starts up
|
||||
* The master node sends a packet with type `ping`.
|
||||
* The master node listens for `pong` packets for a configurable timeout.
|
||||
* The master node listens for `pong` packets from all slaves.
|
||||
* The `sourceid` of all `pong` packets is recorded for statistics displays. This cached data is only used for user display. Node availability is evaluated at request time.
|
||||
|
||||
### Inventory Search (query)
|
||||
|
@ -22,6 +22,7 @@ print("Computer " .. os.getComputerID() .. " configured as " .. mode)
|
||||
modem = peripheral.find("modem") or error("No modem attached", 0)
|
||||
modem_side = peripheral.getName(modem)
|
||||
-- Master globals
|
||||
m_slaves = {}
|
||||
-- Slave globals
|
||||
|
||||
-- Common functions
|
||||
@ -36,9 +37,10 @@ function c_waitForMessage()
|
||||
local sender, message = rednet.receive(packet_magic, 1)
|
||||
if message then
|
||||
if
|
||||
(not message["type"]) or -- Message type is required
|
||||
(message["sourcetype"] == mode) or -- Ignore packets from our class of machines
|
||||
(message["networkid"] ~= networkid) -- Ignore packets from other networks
|
||||
(not message["type"]) or -- Message type is required
|
||||
(message["sourcetype"] == mode) or -- Ignore packets from our class of machines
|
||||
(message["networkid"] ~= networkid) or -- Ignore packets from other networks
|
||||
(message["targetid"] and message["targetid"] ~= os.getComputerID) -- Ignore packets for other machines
|
||||
then
|
||||
print("Discarded nonconformant message")
|
||||
return nil
|
||||
@ -74,6 +76,9 @@ function m_loop()
|
||||
print("Received pong from slave: " .. msg["sourceid"])
|
||||
end
|
||||
end
|
||||
function m_ping()
|
||||
c_sendMessage({type="ping"})
|
||||
end
|
||||
|
||||
-- Slave functions
|
||||
function s_loop()
|
||||
|
Loading…
Reference in New Issue
Block a user