Top Level Namespace

Defined Under Namespace

Classes: AggrRule, ClientWorldConnection, ClientWorldModel, IDMask, Response, SensorSample, SolutionData, SolutionType, SolverAggregator, SolverWorldModel, StepResponse, TransientRequest, WMAttribute, WMData

Constant Summary collapse

KEEP_ALIVE =

Keep alive message

0
SNAPSHOT_REQUEST =

Request a snapshot of the current world model state

1
RANGE_REQUEST =

Request a snapshot of the wm state in a time range

2
STREAM_REQUEST =

Request a stream of data from the world model

3
ATTRIBUTE_ALIAS =

Alias an attribute from the world model

4
ORIGIN_ALIAS =

Alias an origin from the world model

5
REQUEST_COMPLETE =

Finish a request

6
CANCEL_REQUEST =

Cancel a request

7
DATA_RESPONSE =

Message contains a data response from the world model

8
URI_SEARCH =

Search names in the world model

9
URI_RESPONSE =

Response to a uri search message.

10
ORIGIN_PREFERENCE =

Set a preference for some data origins

11

Instance Method Summary collapse

Instance Method Details

#getMsecTimeObject

Function to fetch the current time in milliseconds. This is the time format used in the Owl system and is included in every attribute pushed into the world model and every attribute retrieved from the world model.



7
8
9
10
# File 'lib/libowl/wm_data.rb', line 7

def getMsecTime()
  t = Time.now
  return t.tv_sec * 1000 + t.usec/10**3
end

#packuint128(val) ⇒ Object

Pack a 128 bit unsigned integer into a buffer



37
38
39
40
41
# File 'lib/libowl/buffer_manip.rb', line 37

def packuint128(val)
  #TODO FIXME
  #There is no 128 bit type in ruby so pad with zeros for now
  return [0].pack('N') + [0].pack('N') + [val / 2**32].pack('N') + [val % 2**32].pack('N')
end

#packuint64(val) ⇒ Object

Pack a 64 bit unsigned integer into a buffer



26
27
28
# File 'lib/libowl/buffer_manip.rb', line 26

def packuint64(val)
  return [val / 2**32].pack('N') + [val % 2**32].pack('N')
end

#readUnsizedUTF16(buff) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/libowl/buffer_manip.rb', line 85

def readUnsizedUTF16(buff)
  len = buff.length / 2
  rest = buff
  #puts "len is #{len} and rest is #{rest.length} bytes long"
  str = ""
  for i in 1..len do
    if (rest.length >= 2)
      #For now act as if the first byte will always be 0
      c = rest.unpack('UU')[1]
      rest = rest[2, rest.length - 1]
      str << c
    end
  end
  return str
end

#readUTF16(buff) ⇒ Object

Read a sized UTF16 string (as encoded by the strToSizedUTF16 function) and return the string.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/libowl/buffer_manip.rb', line 69

def readUTF16(buff)
  len = buff.unpack('N')[0] / 2
  rest = buff[4, buff.length - 1]
  #puts "len is #{len} and rest is #{rest.length} bytes long"
  str = ""
  for i in 1..len do
    if (rest.length >= 2)
      #For now act as if the first byte will always be 0
      c = rest.unpack('UU')[1]
      rest = rest[2, rest.length - 1]
      str << c
    end
  end
  return str
end

#splitURIFromRest(buff) ⇒ Object

Take in a buffer with a sized URI in UTF 16 format. Return the string that was at the beginning of the buffer and the rest of the buffer after the string



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/libowl/buffer_manip.rb', line 105

def splitURIFromRest(buff)
  #The first four bytes are for the length of the string
  strlen = buff.unpack('N')[0]
  str = buff[0,strlen+4]
  #Make another container for everything after the string
  rest = buff[strlen+4,buff.length - 1]
  if (rest == nil)
    rest = []
  end
  if (strlen != 0)
    return (readUTF16 str), rest
  else
    return '', rest
  end
end

#strToSizedUTF16(str) ⇒ Object

Put a string into a buffer as a UTF16 string and put the length of the string (in characters) at the beginning of the buffer as a 4-byte big-endian integer



62
63
64
65
# File 'lib/libowl/buffer_manip.rb', line 62

def strToSizedUTF16(str)
  buff = strToUnicode(str)
  return "#{[buff.length].pack('N')}#{buff}"
end

#strToUnicode(str) ⇒ Object

Put a string into a buffer as a UTF16 string.



52
53
54
55
56
57
58
# File 'lib/libowl/buffer_manip.rb', line 52

def strToUnicode(str)
  unistr = ""
  str.each_char { |c|
    unistr << "\x00#{c}"
  }
  return unistr
end

#unpackuint128(buff) ⇒ Object

Unpack a uint128_t big-endian integer from the buffer



44
45
46
47
48
49
# File 'lib/libowl/buffer_manip.rb', line 44

def unpackuint128(buff)
  #TODO FIXME
  #There is no 128 bit type in ruby so pad with zeros for now
  ignore1, ignore2, high, low = buff.unpack('NNNN')
  return high * 2**32 + low
end

#unpackuint64(buff) ⇒ Object

Unpack a uint64_t big-endian integer from the buffer



31
32
33
34
# File 'lib/libowl/buffer_manip.rb', line 31

def unpackuint64(buff)
  high, low = buff.unpack('NN')
  return high * 2**32 + low
end