View difference between Paste ID: hPgETVn1 and N8G4R5iy
SHOW: | | - or go back to the newest paste.
1
--[[
2-
tanks = {}
2+
    send_tank_info_v2 v2.0 for OpenPeripheral 0.4.1
3
    Copyright (C) 2014 DEXTER
4-
  unga = peripheral.getMethods(side)
4+
 
5-
  if unga then
5+
    This program is free software: you can redistribute it and/or modify
6-
  for k,v in pairs(unga) do
6+
    it under the terms of the GNU General Public License as published by
7-
    if v == "getTankInfo" then
7+
    the Free Software Foundation, either version 3 of the License, or
8-
      p = peripheral.wrap(side)
8+
    (at your option) any later version.
9
 
10-
      info = p.getTankInfo("unknown")
10+
    This program is distributed in the hope that it will be useful,
11-
      --print(tostring(info[1]))
11+
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
      --for i,j in pairs(info[1]) do
12+
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13-
      --  print(tostring(i),':',tostring(j))
13+
    GNU General Public License for more details.
14-
      --end
14+
 
15-
      local data={id=os.getComputerID(), position=side, data=info[1]}
15+
    You should have received a copy of the GNU General Public License
16-
      table.insert(tanks, data)
16+
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
--]]
18
19
-- The modem channel to send tank data on
20
-- This has to be the same channel you set in the display_tanks program
21
modem_channel = 3
22-
for i,v in ipairs(tanks) do
22+
23-
  print(v.data.capacity)
23+
-- Tank data will be sent in every sleep_timeout seconds
24-
  --print(tostring(v))
24+
sleep_timeout = 0.5
25-
  for m,n in pairs(v) do
25+
26-
    print(m,n)
26+
--------------------------------------
27
-- DO NOT MODIFY ANYTHING FROM HERE --
28
--------------------------------------
29
30
modem = peripheral.find("modem")
31
if not modem then
32
  error("Please attach one wireless modem.")
33
end
34
35
sides = {"left", "right", "front", "back", "top", "bottom"}
36
while true do
37
local tanks = {}
38
for i,side in ipairs(sides) do
39
  local isTank = peripheral.getMethods(side)
40
  if isTank then
41
    for k,v in pairs(isTank) do
42
      if v == "getTankInfo" then
43
        local p = peripheral.wrap(side)
44
        local info = p.getTankInfo("unknown")
45
        for m,n in ipairs(info) do
46
          local data={position=side, data=n}
47
          table.insert(tanks, data)
48
        end
49
      end
50
    end
51
  end
52
end
53
54
send_data={id=os.getComputerID(), tanks=tanks}
55
serialized_data = textutils.serialize(send_data)
56
57
modem.transmit(modem_channel,modem_channel,serialized_data)
58
59
sleep(sleep_timeout)
60
61
end