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)

Instance Method Details

- (String) protocol

Returns prototol string ‘TCPROS’

Returns:

  • (String)

    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.

Parameters:

  • socket (IO)

    socket for reading

Returns:

  • (String)

    received data



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

Parameters:

  • socket (String)

    socket for reading

Returns:



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.

Parameters:

  • socket (IO)

    socket for writing.

  • header (Header)

    header data



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.

Parameters:

  • socket (IO)

    socket for writing

  • msg (Message)

    message for writing

Returns:

  • (String)

    wrote data



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