|
|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
event = require("event")
|
|
|
|
|
modem = require("component").modem
|
|
|
|
|
serializer = require("serialization")
|
|
|
|
|
local event = require("event")
|
|
|
|
|
local modem = require("component").modem
|
|
|
|
|
local serializer = require("serialization")
|
|
|
|
|
|
|
|
|
|
List = {last = -1}
|
|
|
|
|
local List = {last = -1}
|
|
|
|
|
|
|
|
|
|
function List:new()
|
|
|
|
|
local o = {}
|
|
|
|
|
@ -42,7 +42,7 @@ function List:remove(id)
|
|
|
|
|
return value
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
message_type = {
|
|
|
|
|
local message_type = {
|
|
|
|
|
request_noun = 1,
|
|
|
|
|
call_verb = 2,
|
|
|
|
|
noun_response = 3,
|
|
|
|
|
@ -54,13 +54,13 @@ message_type = {
|
|
|
|
|
listener_update = 9,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CFG_PORT = 1234
|
|
|
|
|
local CFG_PORT = 1234
|
|
|
|
|
|
|
|
|
|
bc = {}
|
|
|
|
|
local bc = {}
|
|
|
|
|
|
|
|
|
|
function bc:init(local_nouns, local_verbs)
|
|
|
|
|
local_nouns = local_nouns or {}
|
|
|
|
|
local_verbs = local_verbs or {}
|
|
|
|
|
local local_nouns = local_nouns or {}
|
|
|
|
|
local local_verbs = local_verbs or {}
|
|
|
|
|
local o = {}
|
|
|
|
|
setmetatable(o, self)
|
|
|
|
|
self.__index = self
|
|
|
|
|
@ -71,11 +71,10 @@ function bc:init(local_nouns, local_verbs)
|
|
|
|
|
o.listening_remotes = {}
|
|
|
|
|
-- Modem listener
|
|
|
|
|
function modem_listener(moden_msg, localAddress, remoteAddress, port, dist, message)
|
|
|
|
|
dbg = message
|
|
|
|
|
message = serializer.unserialize(message)
|
|
|
|
|
local message = serializer.unserialize(message)
|
|
|
|
|
if port == CFG_PORT then
|
|
|
|
|
if message.ty == message_type.request_noun then
|
|
|
|
|
msg = {ty=message_type.noun_response,
|
|
|
|
|
local msg = {ty=message_type.noun_response,
|
|
|
|
|
noun=message.noun,
|
|
|
|
|
value=o.local_nouns[message.noun]
|
|
|
|
|
}
|
|
|
|
|
@ -161,7 +160,7 @@ function bc:get_noun(n)
|
|
|
|
|
while i < 5 do
|
|
|
|
|
local _, _, remoteAddr, port, _, msg = event.pull("modem_message")
|
|
|
|
|
if port == CFG_PORT and remoteAddr == self.remote_nouns[n] then
|
|
|
|
|
message = serializer.unserialize(msg)
|
|
|
|
|
local message = serializer.unserialize(msg)
|
|
|
|
|
if message.ty == message_type.noun_response and message.noun == n then
|
|
|
|
|
return message.value
|
|
|
|
|
end
|
|
|
|
|
|