Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODEM_SIDE= 'top'
- function send(id,data,r)
- c= 0
- while true do
- c= c+1
- rednet.send(id,data)
- ids,message= rednet.receive(1)
- if (ids == id and message == #data..'') then
- return true
- end
- if (c == r) then break end
- end
- end
- function parseD(filename)
- lines= {}
- tokens= {}
- path= fs.open(filename,'r')
- while true do
- temp= path.readLine()
- if (temp == nil) then break end
- lines[#lines+1]= temp
- end
- s= {}
- c= 0
- for i=1,#lines do
- for q=1,#lines[i] do
- c= c+1
- s[c]= string.sub(lines[i],q,q)
- end
- end
- temp= ''
- forS= false
- i= 0
- while i<#s do
- i= i+1
- forS= false
- if (s[i] == ';') then
- forS= true
- tokens[#tokens+1]= temp
- temp= ''
- end
- if (s[i] == '=') then
- forS= true
- tokens[#tokens+1]= temp
- tokens[#tokens+1]= '='
- temp= ''
- end
- if (forS~= true) then
- if (s[i+1] == nil) then
- temp= temp..s[i]
- tokens[#tokens+1]= temp
- end
- temp= temp..s[i]
- end
- end
- name_list= {}
- id_list= {}
- i= 0
- while i<#tokens do
- i= i+1
- if (tokens[i+1] == '=') then
- name_list[#name_list+1]= tokens[i]
- id_list[#id_list+1]= tokens[i+2]
- i= i+2
- end
- end
- return name_list,id_list
- end
- function receive(timeout)
- while true do
- id,message= rednet.receive(timeout)
- if (id ~= nil and #message~= nil) then
- rednet.send(id,#message..'')
- return id,message
- end
- end
- end
- function getData(arr)
- arr1= {}
- arr2= {}
- length= #arr-1
- for i=2,#arr do
- if (i-1 <= length/2) then
- --print('1')
- arr1[#arr1+1]= arr[i]
- elseif (i-1 >= length/2) then
- --print('2')
- arr2[#arr2+1]= arr[i]
- end
- end
- return arr1,arr2
- end
- function drawA(arr1,arr2)
- term.clear()
- term.setCursorPos(1,1)
- for i=1,#arr1 do
- print(arr1[i],'=',arr2[i])
- end
- end
- function loadF(filename)
- ids= {}
- path= fs.open(filename,'r')
- while true do
- temp= path.readLine()
- if (temp == nil) then break end
- ids[#ids+1]= tonumber(temp)
- end
- return ids
- end
- function addtoSys(arr1,arr2)
- for i=1,#arr1 do
- stat= false
- for d=1,#ID_LIST do
- if (ID_LIST[d] == arr1[i]) then
- AMOUNT_LIST[d]= tonumber(AMOUNT_LIST[d])+tonumber(arr2[i])
- stat= true
- break
- end
- end
- if (stat == false) then
- ID_LIST[#ID_LIST+1]= arr1[i]
- AMOUNT_LIST[#AMOUNT_LIST+1]= arr2[i]
- end
- end
- end
- IDs_LIST= loadF('id')
- ID_LIST= {}
- AMOUNT_LIST= {}
- count= 1
- ID_NOW= IDs_LIST[count]
- rednet.open(MODEM_SIDE)
- while true do
- send(ID_NOW+0,'start',100)
- id,message= receive()
- --print(id,message)
- data= textutils.unserialize(message)
- n= #data-1
- temp= 'DATA:'..n..''
- if (id == ID_NOW and data[1] == temp) then
- il,al= getData(data)
- addtoSys(il,al)
- count= count+1
- if (count > #IDs_LIST) then
- drawA(ID_LIST,AMOUNT_LIST)
- count= 1
- AMOUNT_LIST= {}
- ID_LIST= {}
- end
- ID_NOW= IDs_LIST[count]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement