Class: MobyController::QT::Comms::QtMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb

Overview

MobyController

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_flag, message_data) ⇒ QtMessage

Returns a new instance of QtMessage.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 116

def initialize( message_flag, message_data )

  # message flag
  @flag = message_flag

  # no compression by default
  @compression = 1

  @data = message_data

  @size = @data.size

  # calculate crc only when requested
  @crc = nil

end

Instance Attribute Details

#compressionObject (readonly)

Returns the value of attribute compression.



112
113
114
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 112

def compression
  @compression
end

#dataObject (readonly)

Returns the value of attribute data.



112
113
114
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 112

def data
  @data
end

#flagObject (readonly)

Returns the value of attribute flag.



112
113
114
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 112

def flag
  @flag
end

#message_idObject

Returns the value of attribute message_id.



114
115
116
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 114

def message_id
  @message_id
end

#sizeObject (readonly)

Returns the value of attribute size.



112
113
114
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 112

def size
  @size
end

Instance Method Details

#crcObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 133

def crc

  if @crc.nil?

    # calculate outgoing message crc; sent in message header to receiver for data validation
    @crc = TDriver::Checksum.crc16_ibm( @data ) 

  else

    @crc

  end
  
end

#deflate(level = 9) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 155

def deflate( level = 9 )

  unless @compression == 2

    @compression = 2

    data_size = @data.size

    # qUncompress required the data length at the beginning so append it - the bytes need to be arranged in the below method (see QByteArray::qUncompress)
    @data = [ ( data_size & 0xff000000 ) >> 24, ( data_size & 0x00ff0000 ) >> 16, ( data_size & 0x0000ff00 ) >> 8, ( data_size & 0x000000ff ), Zlib::Deflate.deflate( @data, level ) ].pack('C4a*')

    # update data size
    @size = @data.size

    # recalculate crc
    @crc = nil

  end
  
end

#make_binary_message(message_id) ⇒ Object



148
149
150
151
152
153
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb', line 148

def make_binary_message( message_id )


  [ @flag, @size, crc, @compression, message_id, @data ].pack( 'CISCIa*' )

end