mydexterid

send_tank_info

Jun 30th, 2013
4,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. --[[
  2.     send_tank_info v1.0 for OpenCCSensors 0.1.4c
  3.     Copyright (C) 2013 DEXTER
  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. -- Position of your modem
  20. modem_position = "left"
  21.  
  22. -- Position of your sensor
  23. sensor_position = "right"
  24.  
  25. -- The modem channel to send sensor data on
  26. -- This has to be the same channel you set in the display_tanks program
  27. modem_channel = 3
  28.  
  29. -- Time (in seconds) when new sensor data will be sent to the display
  30. sleep_timeout = 0.5
  31.  
  32. -- The positions of your tanks
  33. -- This is relative to your sensor. Coordinates are: X, Y, Z
  34. tanks={
  35. "0,0,-1",
  36. "-1,0,0",
  37. "-1,0,-1",
  38. "1,0,-1",
  39. "1,0,0",
  40. "1,0,1"
  41. }
  42.  
  43. --------------------------------------
  44. -- DO NOT MODIFY ANYTHING FROM HERE --
  45. --------------------------------------
  46.  
  47. os.loadAPI("ocs/apis/sensor")
  48.  
  49. sens = sensor.wrap(sensor_position)
  50. modem = peripheral.wrap(modem_position)
  51.  
  52. while true do
  53.   local data_table={}
  54.   for i, v in ipairs(tanks) do
  55.     target_details = sens.getTargetDetails(v)
  56.  
  57.     table.insert(data_table, target_details)
  58.   end
  59.   local send_data={id=os.getComputerID(), data=data_table}
  60.  
  61.   serialized_data = textutils.serialize(send_data)
  62.  
  63.   modem.transmit(modem_channel,modem_channel,serialized_data)
  64.  
  65.   sleep(sleep_timeout)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment