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)
-
- (String) protocol
Prototol string 'TCPROS'.
-
- (String) read_all(socket)
read the size of data and read it from socket.
-
- (Header) read_header(socket)
read a connection header from socket.
-
- (Object) write_header(socket, header)
write a connection header to socket.
-
- (String) write_msg(socket, msg)
write message to socket.
Instance Method Details
- (String) protocol
Returns prototol string ‘TCPROS’
70 71 72 |
# File 'lib/ros/tcpros/message.rb', line 70 def protocol 'TCPROS' end |
- (String) read_all(socket)
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 |
- (Header) read_header(socket)
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 |
- (Object) write_header(socket, header)
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 |
- (String) write_msg(socket, msg)
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 |