lib/wifly/connection.rb in wifly-0.0.1 vs lib/wifly/connection.rb in wifly-0.0.2

- old
+ new

@@ -1,9 +1,7 @@ module Wifly class Connection - HELLO = '*HELLO*CMD\r\n' - attr_accessor :address, :port, :version ## # address => the hostname or IP address of the wifly device # port => the port for communicating with the wifly @@ -22,14 +20,14 @@ # along with another CRLF and the command prompt string. # Something like "lites\r\r\n<2.32> " # Since the string has a predictable length, we can do a blocking read. # def send_command(str, return_len=0) - str += '\r' + str += "\r" socket.write(str) - expected_return_length = str.length + '\r\n#{prompt}'.length + return_len - socket.read(expected_return_length).gsub(prompt,'') + expected_return_length = str.length + "\r\n#{prompt}".length + return_len + socket.read(expected_return_length).gsub(prompt,'') end def close socket.close end @@ -43,11 +41,11 @@ "<#{version}> " end def initialize_socket sock = Socket.tcp(address, port) - sock.write('$$$\r') # enter command mode - sock.read(HELLO.length) # read off the response, "*HELLO*CMD\r\n" + sock.write(COMMAND_MODE) # enter command mode + sock.read(HELLO.length) # read off the response sock end end end \ No newline at end of file