mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Update transport system.
Now transport system is using LibNetbox.
This commit is contained in:
parent
64e657bd14
commit
f4fcfe5be8
|
@ -1,5 +1,6 @@
|
||||||
local component=require("component")
|
local component=require("component")
|
||||||
require("libevent")
|
require("libevent")
|
||||||
|
require("libnetbox")
|
||||||
require("util")
|
require("util")
|
||||||
|
|
||||||
--- Auto Configure
|
--- Auto Configure
|
||||||
|
@ -24,26 +25,28 @@ local idt={}
|
||||||
local function getNextID()
|
local function getNextID()
|
||||||
local nextid=1
|
local nextid=1
|
||||||
for k,v in pairs(idt) do
|
for k,v in pairs(idt) do
|
||||||
if(v>nextid) then nextid=v+1 end
|
if(k>nextid) then nextid=k+1 end
|
||||||
end
|
end
|
||||||
|
idt[nextid]=true
|
||||||
return nextid
|
return nextid
|
||||||
end
|
end
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
checkDevice()
|
checkDevice()
|
||||||
|
clientServiceStart()
|
||||||
|
|
||||||
network_card.open(10010)
|
OpenPort(10010)
|
||||||
|
|
||||||
print("Center Started. Press Ctrl+C to stop.")
|
print("Center Started. Press Ctrl+C to stop.")
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e=WaitEvent()
|
local e=WaitEvent()
|
||||||
if(e~=nil) then
|
if(e~=nil) then
|
||||||
if(e.event=="modem_message" and e.data[1]=="TSCM") then
|
if(e.event=="net_message" and e.data[1]=="TSCM") then
|
||||||
if(e.data[2]=="req") then
|
if(e.data[2]=="req") then
|
||||||
if(e.data[3]=="store") then
|
if(e.data[3]=="store") then
|
||||||
local id=getNextID()
|
local id=getNextID()
|
||||||
network_card.send(e.senderAddress,10011,"TSCM","ack","pass",id)
|
SendData(e.senderAddress,10011,"TSCM","ack","pass",id)
|
||||||
print("NextID: ",id)
|
print("NextID: ",id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,7 +56,8 @@ local function main()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
network_card.close(10010)
|
ClosePort(10010)
|
||||||
|
clientServiceStop()
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Transport System Center Started.")
|
print("Transport System Center Started.")
|
||||||
|
|
|
@ -2,25 +2,25 @@ local component=require("component")
|
||||||
local sides=require("sides")
|
local sides=require("sides")
|
||||||
local thread=require("thread")
|
local thread=require("thread")
|
||||||
require("libevent")
|
require("libevent")
|
||||||
|
require("libnetbox")
|
||||||
require("util")
|
require("util")
|
||||||
|
|
||||||
--- Auto Configure
|
--- Auto Configure
|
||||||
local digital_controller = proxy("digital_controller_box")
|
local digital_controller = proxy("digital_controller_box")
|
||||||
local digital_receiver = proxy("digital_receiver_box")
|
local digital_receiver = proxy("digital_receiver_box")
|
||||||
local out_ticket = proxy("routing_track")
|
local out_ticket = proxy("routing_track")
|
||||||
local network_card = proxy("modem")
|
|
||||||
|
|
||||||
--- Manually Configure
|
--- Manually Configure
|
||||||
local load_detector = proxy("digital_detector","0")
|
local load_detector = proxy("digital_detector","8")
|
||||||
local unload_detector = proxy("digital_detector","4")
|
local unload_detector = proxy("digital_detector","1")
|
||||||
|
|
||||||
local load_transposer = proxy("transposer","7")
|
local load_transposer = proxy("transposer","c")
|
||||||
local unload_transposer = proxy("transposer","6")
|
local unload_transposer = proxy("transposer","5")
|
||||||
|
|
||||||
local route_ab_load = proxy("routing_switch","0c")
|
local route_ab_load = proxy("routing_switch","c")
|
||||||
local route_ba_load = proxy("routing_switch","088")
|
local route_ba_load = proxy("routing_switch","6")
|
||||||
local route_ab_unload = proxy("routing_switch","08c")
|
local route_ab_unload = proxy("routing_switch","8")
|
||||||
local route_ba_unload = proxy("routing_switch","c")
|
local route_ba_unload = proxy("routing_switch","2")
|
||||||
|
|
||||||
--- Internal Variables
|
--- Internal Variables
|
||||||
local load_box_side
|
local load_box_side
|
||||||
|
@ -29,7 +29,6 @@ local loading=0 -- 0 Free 1 Ready 2 Processing
|
||||||
local unloading=0
|
local unloading=0
|
||||||
local lockway=0 -- 0 Free 1 Loading 2 Unloading
|
local lockway=0 -- 0 Free 1 Loading 2 Unloading
|
||||||
|
|
||||||
|
|
||||||
-- Value: 1 Green 2 Blinking Yellow 3 Yellow 4 Blinking Red 5 Red
|
-- Value: 1 Green 2 Blinking Yellow 3 Yellow 4 Blinking Red 5 Red
|
||||||
local green=1
|
local green=1
|
||||||
local byellow=2
|
local byellow=2
|
||||||
|
@ -53,7 +52,6 @@ local function checkDevice()
|
||||||
doCheckDevice(digital_controller)
|
doCheckDevice(digital_controller)
|
||||||
doCheckDevice(digital_receiver)
|
doCheckDevice(digital_receiver)
|
||||||
doCheckDevice(out_ticket)
|
doCheckDevice(out_ticket)
|
||||||
doCheckDevice(network_card)
|
|
||||||
|
|
||||||
doCheckDevice(load_detector)
|
doCheckDevice(load_detector)
|
||||||
doCheckDevice(unload_detector)
|
doCheckDevice(unload_detector)
|
||||||
|
@ -196,16 +194,16 @@ end
|
||||||
|
|
||||||
local function getNewTransID(cnt)
|
local function getNewTransID(cnt)
|
||||||
print("Getting new transfer id...")
|
print("Getting new transfer id...")
|
||||||
network_card.open(10011)
|
OpenPort(10011)
|
||||||
network_card.broadcast(10010,"TSCM","req","store",cnt)
|
BroadcastData(10010,"TSCM","req","store",cnt)
|
||||||
e=WaitEvent("modem_message",10)
|
e=WaitEvent("net_message",10)
|
||||||
local ret
|
local ret
|
||||||
if(e~=nil and e.data[1]=="TSCM" and e.data[2]=="ack" and e.data[3]=="pass") then
|
if(e~=nil and e.data[1]=="TSCM" and e.data[2]=="ack" and e.data[3]=="pass") then
|
||||||
ret=e.data[4]
|
ret=e.data[4]
|
||||||
else
|
else
|
||||||
ret=nil
|
ret=nil
|
||||||
end
|
end
|
||||||
network_card.close(10011)
|
ClosePort(10011)
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -344,6 +342,8 @@ local function main()
|
||||||
checkDevice()
|
checkDevice()
|
||||||
resetDevice()
|
resetDevice()
|
||||||
|
|
||||||
|
clientServiceStart()
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
print(
|
print(
|
||||||
"-------------\n" ..
|
"-------------\n" ..
|
||||||
|
@ -366,6 +366,8 @@ local function main()
|
||||||
|
|
||||||
resetDevice()
|
resetDevice()
|
||||||
unlockUnloadChest()
|
unlockUnloadChest()
|
||||||
|
|
||||||
|
clientServiceStop()
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Transport System Client Started.")
|
print("Transport System Client Started.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user