OC-PsychOS/modules/drivers/net.lua

28 lines
649 B
Lua
Raw Normal View History

net = {}
net.id = computer.address():sub(1,8)
net.vlan = 1
net.np = 4096
net.tm = {}
function net.send(id,po,msg) -- id, port, message
2017-07-30 19:12:10 +10:00
event.push("sendmsg",id,po,msg)
end
spawn("network daemon",function ()
for a,t in component.list("modem") do
table.insert(net.tm,component.proxy(a))
component.proxy(a).open(net.vlan)
2017-07-30 19:12:10 +10:00
end
while true do
local ev = {event.pull()}
2017-07-30 19:12:10 +10:00
if ev[1] == "sendmsg" then
local eT = ev
for k,v in ipairs(net.tm) do
v.broadcast(net.vlan,net.np,eT[2],net.id,eT[3],eT[4])
2017-07-30 19:12:10 +10:00
end
elseif ev[1] == "modem_message" then
if ev[7] == net.id then
2017-07-30 19:12:10 +10:00
event.push("net_msg",ev[8],ev[9],ev[10])
end
end
end
end)