Module: ROS::TCPROS::Message
- Included in:
- Client, Server, ServiceClient, ServiceServer
- Defined in:
- lib/ros/tcpros/message.rb
Overview
functions for TCPROS
Instance Method Summary collapse
-
#protocol ⇒ String
Prototol string ‘TCPROS’.
-
#read_all(socket) ⇒ String
read the size of data and read it from socket.
-
#read_header(socket) ⇒ Header
read a connection header from socket.
-
#write_header(socket, header) ⇒ Object
write a connection header to socket.
-
#write_msg(socket, msg) ⇒ String
write message to socket.
Instance Method Details
#protocol ⇒ String
Returns prototol string ‘TCPROS’.
70 71 72 |
# File 'lib/ros/tcpros/message.rb', line 70 def protocol 'TCPROS' end |
#read_all(socket) ⇒ String
read the size of data and read it from socket.
41 42 43 44 45 46 47 48 |
# File 'lib/ros/tcpros/message.rb', line 41 def read_all(socket) total_bytes = socket.recv(4).unpack("V")[0] if total_bytes and total_bytes > 0 socket.recv(total_bytes) else '' end end |
#read_header(socket) ⇒ Header
read a connection header from socket
54 55 56 57 58 |
# File 'lib/ros/tcpros/message.rb', line 54 def read_header(socket) header = ::ROS::TCPROS::Header.new header.deserialize(read_all(socket)) header end |
#write_header(socket, header) ⇒ Object
write a connection header to socket.
64 65 66 67 |
# File 'lib/ros/tcpros/message.rb', line 64 def write_header(socket, header) header.serialize(socket) socket.flush end |
#write_msg(socket, msg) ⇒ String
write message to socket.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ros/tcpros/message.rb', line 26 def write_msg(socket, msg) sio = StringIO.new('', 'r+') len = msg.serialize(sio) sio.rewind data = sio.read len = data.length data = [len, data].pack("La#{len}") socket.write(data) data end |