lebalusch

Communications Test Listener

May 25th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. -- Code for updater to go here.
  2. --[[info]]
  3. --[[
  4. -- Program: communication Tester  Listener http://pastebin.com/Ju9Lgy7R
  5. -- Version: v1.0 Alpha
  6. -- Size: 3.0 KB
  7. -- Author:  Leba Lusch
  8. -- Created: 25/05/15
  9. -- Dependencies:    yes
  10. Communications Tester Broadcaster http://pastebin.com/hAHtp36n
  11. link :
  12. -- Use:
  13. Tests communications capacity of your wireless / wired network.  Can be used to Test the range suitability.
  14. This script does the listening.  It will tell you the distance to the computer running the Broadcaster script as well as other useful info.
  15.  
  16. I have tried to make as many needed comments in the script to help people that want to learn.
  17.  
  18. -- Credits:
  19.  
  20. All those that have Created and contributed to making Lua & Computercraft what it is today.
  21.  
  22.  
  23. --Links:
  24.  
  25.  http://www.lua.org/
  26.  http://www.computercraft.info/
  27.  http://www.computercraft.info/forum2
  28.  http://www.minecraft.net
  29. ]]
  30. --[[Licence]]
  31. --[[
  32. THE SOFTWARE IS PROVIDED "AS IS",
  33. WITHOUT WARRANTY OF ANY KIND,
  34. EXPRESS OR IMPLIED,
  35. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  36. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  37. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  38. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  39. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  40.  
  41. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
  42. IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
  43. ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  44.  
  45. YOU MAY NOT USE ANY PART OF THIS SOFTWARE UNLESS YOU CREDIT THE AUTHOR FOUND ABOVE IN YOUR HEADER.
  46. YOU MAY NOT USE ANY PART OF THIS SOFTWARE IN A COMERCIAL PRODUCT FOR PROFIT,
  47. OR SOFTWARE THAT DOES NOT ALLOW THE USER FULL ACCESS TO THE CODE.
  48.  
  49. ]]
  50.  
  51. local programName = "Communication Tester  Listener v1.0 Alpha"
  52. local modem = peripheral.wrap("top")
  53.  
  54. local function newPage()-- clears page and sets cursor to top left of page (works)
  55.     term.clear()
  56.     term.setCursorPos(1,1)
  57.     write(programName)
  58.     write("\n") --new line
  59. end
  60.  
  61. function ASK()
  62.    
  63.     print("Program Started...\n")
  64.     print("\n Please make sure your modem is on the top of your pc\nor this can be changed in the script")
  65.     print("Also set the broadcaster up first on the other PC")
  66.     print("\nWhat Channel should I listen to 1 to 65535:\n")
  67.     local RX =tonumber(read())
  68.     whatChan = RX
  69. modem.open(RX)
  70.  
  71. end
  72.  
  73. --code
  74.     modem.closeAll()
  75.     newPage()
  76.     ASK()
  77.  
  78. while true do --The loop
  79.     newPage()
  80.     print ("\nNow listening channel "..whatChan)
  81.     local event, modemSide, senderChannel,
  82.     replyChannel, message, senderDistance = os.pullEvent("modem_message")
  83.  
  84.     print("\n\nI just received a message from Channel: "..senderChannel)
  85.     print("I should apparently reply on Channel: "..replyChannel)
  86.     print("The modem receiving this is located on the "..modemSide.." side")
  87.     print("The message was: "..message)
  88.     print("The sender is: "..senderDistance.." blocks away from me.")
  89.     sleep(10)
  90.     print("To exit you can ctrl + T out")
  91.     sleep(1)
  92.     print("\nResetting Listener---")
  93.     sleep(5)
  94.     end
Advertisement
Add Comment
Please, Sign In to add comment