Method: Roi#precise_time_to_match_dut
- Defined in:
- lib/roi/roi.rb
#precise_time_to_match_dut(other_dut, timeout, args = {}) ⇒ Object
Public: Measures the precise time for the given Roi to match on the specified DUT.
other_dut - Platform (or subclass) instance of DUT to match. timeout - Integer total milliseconds to allow before timing out. key - String key press to trigger evaluation (default: nil).
If default, no key will be pressed.
delay - Integer total milliseconds to delay before starting evaluation (default: 0). report - Boolean indicating whether to report measurements to ITMS (default: true). NOT YET IMPLEMENTED.
Returns the Float total milliseconds for the Roi to disappear.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/roi/roi.rb', line 235 def precise_time_to_match_dut(other_dut, timeout, args={}) #TODO: this probably needs some work for the new EE msg = "Measuring precise time for #{info} to match DUT #{other_dut.model}:#{other_dut.slot}" logger.roi(self, args.merge(:message => msg, :screenshot => false)) key = args[:key] delay = args.fetch(:delay, 0) other_roi = args[:other_roi] left_frames = [] right_frames = [] test_case.add_teardown('Cleaning up captured frames') do json = get_json_for_test.merge(files: (left_frames + right_frames).map {|frm| frm['path']}) test_case.send(:tmc_delete, '/api/images', json: json ) end # Press key if specified unless key.nil? do_trigger(key, :duts => [dut, other_dut]) end # Delay if specified if delay > 0 sleep(delay / 1000.0) # this is native sleep end # Capture frames for the duration json1 = get_json_for_iter.merge(durationMs: timeout) threads = [ Thread.new do resp = test_case.send(:tmc_post, "/api/images/record/#{dut.slot}", json: json1) left_frames += resp.fetch('images') end, Thread.new do resp = test_case.send(:tmc_post, "/api/images/record/#{other_dut.slot}", json: json1) right_frames += resp.fetch('images') end ] threads.each { |thr| thr.join } # wait all threads if left_frames.empty? || right_frames.empty? raise 'Not enough images captured for analysis!' end # Send frames for processing if other_roi.nil? right_roi = rectangle else right_roi = other_roi.rectangle end right_roi.update(:threshold => threshold) unless right_roi.nil? json2 = get_json_for_compare_2(rectangle, right_roi, left_frames: left_frames, right_frames: right_frames) result = test_case.send(:tmc_post, '/api/roi/video/actions', json: json2)['value'] # TODO: figure out which frame(s) and display them logger.roi(self, args.merge(message: "#{result.nil? ? 'no ' : ''}matching frames found".capitalize, screenshot: false)) logger.duration(result, message: 'Time to match') unless result.nil? result end |