SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ | |
| 2 | - | send_tank_info_v2 v2.0 for OpenPeripheral 0.4.1 |
| 2 | + | send_tank_info_v3 v3.0 for OpenPeripheral 0.4.1 |
| 3 | - | Copyright (C) 2014 DEXTER |
| 3 | + | Copyright (C) 2016 Duisburger98 |
| 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify | |
| 6 | it under the terms of the GNU General Public License as published by | |
| 7 | the Free Software Foundation, either version 3 of the License, or | |
| 8 | (at your option) any later version. | |
| 9 | ||
| 10 | This program is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | GNU General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU General Public License | |
| 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 | ||
| 23 | -- Tank data will be sent in every sleep_timeout seconds | |
| 24 | sleep_timeout = 0.5 | |
| 25 | ||
| 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 |