Class: Odn

Inherits:
Stb show all
Defined in:
lib/platform/stb/odn/odn.rb

Overview

Adds to or modifies the Stb platform with Odn-specific functionality.

Direct Known Subclasses

Odn1080, Odn720

Instance Attribute Summary

Attributes inherited from Platform

#id, #keys, #remotes, #roi, #screens

Instance Method Summary collapse

Methods inherited from Stb

#in_standby?, #password, #power_on?, #username

Methods included from RoiHelper

#roi_resolution

Methods inherited from Platform

#alt_parental_controls_pin, #app_version, #audio_level, #audio_level_left, #audio_level_right, #audio_present?, #capture_audio, #capture_frames, #capture_screen, #device_type_is?, #device_type_not?, #entitlements, #has_power?, #height, #high_def?, #ip_address, #is_generic?, #lock, #mac_address, #model, #name, #parental_controls_pin, #password, #platform, #power_cycle, #power_off, #power_on, #power_on?, #press_key, #record_audio, #record_video, #remote_type=, #remote_type_is?, #reset_video, #resolution, #save_last_screen_captured, #slot, #snmp_get, #snmp_set, #software_version, #stop_audio, #stop_video, #upload_screenshot, #username, #width

Constructor Details

#initialize(*args) ⇒ Odn

Returns a new instance of Odn.



10
11
12
13
14
15
# File 'lib/platform/stb/odn/odn.rb', line 10

def initialize(*args)
  super(*args)
  @screens = OdnScreens.new(self)
  @roi = OdnRois.new(self)
  set_keys(OdnKeys.new)
end

Instance Method Details

#clear_tuner_caches?(start_channel = 511, num_channel_changes = 6) ⇒ Boolean

Public: use this to clear tuner caches

start_channel - starting channel number num_channel_changes - number of channel changes to perform

return true if number of successful channels equals to the number of expected channel changes (num_channel_changes), false otherwise

Returns:

  • (Boolean)


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/platform/stb/odn/odn.rb', line 300

def clear_tuner_caches?(start_channel=511, num_channel_changes=6)
  logger.info("Clearing tuner cache...")
  screens.live_tv.set_channel?(start_channel)
  sleep(6.sec)
  cur_chan_num = start_channel
  good_tunes = 0
  tries = 0
  while (good_tunes < num_channel_changes and tries < 30)
    press_key.CHANNEL_UP( :sleep_time => 5.sec )
    next_chan_num = get_channel_number_from_info_banner()
    if (next_chan_num == -1)
      tries += 1
      next
    end
    if (next_chan_num > cur_chan_num)
      good_tunes += 1
    end
    cur_chan_num = next_chan_num
    tries += 1
  end

  good_tunes == num_channel_changes
end

#get_available_heapObject

Public: get available heap size data in the STB via snmp

Returns the available heap value



429
430
431
432
433
434
435
436
437
# File 'lib/platform/stb/odn/odn.rb', line 429

def get_available_heap()
  begin
    r = snmp_get(".1.3.6.1.4.1.4491.2.3.1.1.4.8.2.0")
    logger.info("available_heap=#{r}")
    r.to_i
  rescue StandardError => e
    0
  end
end

#get_channel_number_from_guideObject

Public: get current channel number (string) from the guide

returns current channel number (string)



32
33
34
35
36
37
# File 'lib/platform/stb/odn/odn.rb', line 32

def get_channel_number_from_guide()
  fail("Failed to launch guide") unless screens.guide.navigate?
  current_channel_number = screens.guide.get_current_channel_number()
  press_key.EXIT    # exit from the guide
  current_channel_number
end

#get_channel_number_from_info_bannerObject

Public: get current channel number (string) from the info banner

returns current channel number (string)



42
43
44
45
# File 'lib/platform/stb/odn/odn.rb', line 42

def get_channel_number_from_info_banner()
  current_channel_number = screens.live_tv.get_current_channel_number()
  current_channel_number
end

#get_heap_sizeObject

Public: get heap size data in the STB via snmp

Returns the heap size value



416
417
418
419
420
421
422
423
424
# File 'lib/platform/stb/odn/odn.rb', line 416

def get_heap_size()
  begin
    r = snmp_get(".1.3.6.1.4.1.4491.2.3.1.1.4.8.1.0")
    logger.info("heap_size=#{r}")
    r.to_i
  rescue StandardError => e
    0
  end
end

#get_largest_blockObject

Public: get largest block data in the STB via snmp

Returns the largest block value



403
404
405
406
407
408
409
410
411
# File 'lib/platform/stb/odn/odn.rb', line 403

def get_largest_block()
  begin
    r = snmp_get(".1.3.6.1.4.1.4491.2.3.1.1.4.7.1.0")
    logger.info("largest_block=#{r}")
    r.to_i
  rescue StandardError => e
    0
  end
end

#init?Boolean

Public: Initializes the Spectrum STB and brings it to the Live TV screen.

Returns a Boolean true if the device was initialized, otherwise false.

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/platform/stb/odn/odn.rb', line 20

def init?
  if super
    press_key.EXIT(:sleep_time => 3.sec)  # exit the banner which prevents us from doing some operations
    true
  else
    false
  end
end

#measure_burst_tune(channels, burst_type) ⇒ Object

Public: measure burst tune

channels - burst_type -

Returns nothing



221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
# File 'lib/platform/stb/odn/odn.rb', line 221

def measure_burst_tune(channels, burst_type)
  debug_log = false
  start_chan = channels[0]
  final_chan = channels[1]

  if (channels.length > 2)
    channel_tunes = channels[2]
  else
    channel_tunes = "5"
  end
  start_chan_num = (Integer(start_chan) rescue nil)
  final_chan_num = (Integer(final_chan) rescue nil)
  channel_tunes = (Integer(channel_tunes) rescue nil)
  chan_up = true
  if (start_chan_num != nil and final_chan_num != nil)
    chan_up = false if (final_chan_num < start_chan_num)
  end
  channel_tunes = 5 if (channel_tunes == nil)

  guide_chan_ROI = roi.text.guide_focused_program_channel
  guide_chan_ROI.expectedText = final_chan.to_s

  logger.info("Initializing on channel: #{start_chan}") if (debug_log)
  screens.live_tv.set_channel?(from_channel)
  fail("Could not get initial video displayed on channel #{start_chan}") unless (verify_expected_channel?(start_chan))
  logger.info("Initial channel displayed") if (debug_log)

  startTime = Time.now
  (1..channel_tunes).each do |k|
    if chan_up
      press_key.CHANNEL_UP( :sleep_time => 0.sec )
      dir = 'up'
    else
      press_key.CHANNEL_DOWN( :sleep_time => 0.sec )
      dir = 'down'
    end
    if (k == 1)
      logger.info("Warning: Video did not pause") unless roi.video.fullscreen_video.wait_until_not_displayed?(timeout=2000, :priority => :high)
    end
    sleep(500.ms)
  end
  fail("Video not playing") unless roi.video.fullscreen_video.displayed?
  stopTime = Time.now

  logger.info("Video playing", :screenshot => true, :use_last_image => false)
  (1..3).each do |i|
    press_key.GUIDE
    break if guide_chan_ROI.displayed?
    fail("Could not verify final channel number") if (i > 2)
    press_key.EXIT
  end
  dataValue = time_diff_milli(startTime, stopTime).to_s
  logger.duration(dataValue, :message => "Burst tune #{burst_type} | #{dataValue}")
  report_result(:start_time => startTime, :stop_time => stopTime)
end

#measure_guide_tune(from_channel, to_channel) ⇒ Object

Public: measures tuning in guide

from_channel - channel number we are starting from to_channel - channel number we are going to tune to

Returns nothing



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/platform/stb/odn/odn.rb', line 191

def measure_guide_tune(from_channel, to_channel)
  logger.info("Guide tune from channel #{from_channel} to #{to_channel}")
  screenROI = roi.image.
  timeout=15
  fail("Failed to launch guide") unless screens.guide.navigate?
  screens.guide.set_channel?(from_channel, :press_select => false)
  sleep(3.sec)
  filename = capture_screen("tmp_stb_#{$stb_id}.jpg")
  screenROI.ref_img = filename
  sleep(5.sec)
  logger.info("Initial screen", :screenshot => true, :use_last_image => false, :image_suffix => "image")
  screens.guide.set_channel?(to_channel, :press_select => false)
  times[0] = Time.now
  if screenROI.wait_until_not_displayed?(timeout=15000, :priority => :high)
    times[1] = Time.now
  else
    times[1] = times[0]  # failed case
  end
  dataValue = time_diff_milli(times[0], times[1])
  fail("Failed to go to channel #{to_channel}") if (dataValue == 0)
  report_result(:start_time => times[0], :stop_time => times[1])
  logger.duration(dataValue, :message => "Time to channel #{to_channel}")
end

#measure_tune(from_channel_type, to_channel_type, from_channel, to_channel, tune_type = 'direct', cache_clear = false) ⇒ Object

Public: measure tune time

from_channel_type - type of channel we are starting from to_channel_type - type of channel we are going to tune to from_channel - channel number we are starting from to_channel - channel number we are going to tune to tune_type - type of tune we are performing (direct or guide) cache_clear - flag to indicate if we need to clear the cache

Returns nothing but posts results of the start time and the end time



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/platform/stb/odn/odn.rb', line 83

def measure_tune(from_channel_type, to_channel_type, from_channel, to_channel, tune_type='direct', cache_clear=false)
  if (from_channel_type == to_channel_type and to_channel_type == 'mod')
    measure_tune_guide_mod_mod(from_channel_type, to_channel_type, from_channel, to_channel, tune_type='direct')
    return
  end
  debug_log = false
  if (from_channel_type == 'analog' or to_channel_type == 'analog')
    error("Box['#{fetch_stb_model}'] not supported.") unless stb_capable_of? 'ANALOG'
  end
  fail("From and to channels cannot be the same") if (from_channel == to_channel)
  fail("Failed to initialize STB") unless init?
  logger.info("#{tune_type} tune from channel: #{from_channel} to channel: #{to_channel}")
  #Verify video on from_channel
  if (cache_clear)
    start_clear_chan=(@test_case.test_data[:clear_tuner_cache_start_channel] == nil)? 516 : @test_case.test_data[:clear_tuner_cache_start_channel]
    fail("Could not clear tuner cache") unless clear_tuner_caches?(start_clear_chan, 6)
  end
  fail("Could not get video on from_channel: #{from_channel}") if (initialize_execution(from_channel) == false)
  fail("Tuned to wrong from channel: #{from_channel}") if (!verify_expected_channel?(from_channel))

  press_key.EXIT
  if (tune_type == 'guide')
    sleep(10.sec)
    press_key.GUIDE
    screens.guide.set_channel?(to_channel, :press_select => false)
    sleep(4.sec)
    logger.info("Screen before pressing select", :screenshot => true, :use_last_image => false, :image_suffix => "guide")
    press_key.SELECT( :sleep_time => 0.sec )
  else
    screens.live_tv.set_channel?(to_channel)
    logger.info("Screen before channel starts changing", :screenshot => true, :use_last_image => false, :image_suffix => "guide")
  end
  startTime = Time.now
  fail("Video did not go black after #{tune_type} tuning to channel: #{to_channel}") unless roi.black.channel_tune_black_screen.wait_until_displayed?(timeout=5000)

  stopTime = Time.now
  tuneTime = time_diff_milli(startTime, stopTime)
  logger.info("Video froze after: #{tuneTime.to_s}")
  fail("Video not playing after #{tune_type} tuning to channel: #{to_channel}") unless roi.black.channel_tune_black_screen.wait_until_displayed?(timeout=15000)
  stopTime = Time.now
  tuneTime = time_diff_milli(startTime, stopTime)
  fail("Test took too long") if (tuneTime > 15000)
  logger.info("Long tune time") if (tuneTime > 5000)
  press_key.EXIT
  fail("Could not verify to channel: #{to_channel}: for #{tune_type} tune") unless verify_expected_channel?(to_channel)
  report_result(:start_time => startTime, :stop_time => stopTime)
  logger.duration(tuneTime, :message => "#{from_channel_type} to #{to_channel_type} #{tune_type} tune|")
end

#measure_tune_guide_mod_mod(from_channel_type, to_channel_type, from_channel, to_channel, tune_type = 'direct') ⇒ Object

Public: measures tune in guide from MOD to MOD

from_channel_type - type of channel we are starting from to_channel_type - type of channel we are going to tune to from_channel - channel number we are starting from to_channel - channel number we are going to tune to tune_type - type of tune we are performing (direct or guide)

Returns nohting



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/platform/stb/odn/odn.rb', line 141

def measure_tune_guide_mod_mod(from_channel_type, to_channel_type, from_channel, to_channel, tune_type='direct')
  debug_log = false
  fail("From and to channels cannot be the same") if (from_channel == to_channel)
  screenROI = roi.image.guide_info

  logger.info("#{tune_type} tune from channel: #{from_channel} to channel: #{to_channel}")
  #Verify video on from_channel
  fail("Failed to initialize STB") unless init?
  screens.live_tv.navigate?
  screens.live_tv.set_channel(from_channel)
  fail("Tuned to wrong from channel: #{from_channel}") unless verify_expected_channel?(from_channel)
  fail("Could not get video on from_channel: #{from_channel}") unless screens.live_tv.displayed?
  press_key.EXIT

  if (tune_type == 'guide')
    press_key.GUIDE
    sleep(4.sec)
    screens.guide.set_channel?(to_channel)
    sleep(4.sec)
    filename = capture_screen("tmp_stb_#{$stb_id}.jpg")
    screenROI.ref_img = filename
    logger.info("Screen before pressing select", :screenshot => true, :use_last_image => false, :image_suffix => "image")
    press_key.SELECT(:sleep_time => 0.sec)
  else
    sleep(2.sec)
    filename = capture_screen("tmp_stb_#{$stb_id}.jpg")
    screenROI.ref_img = filename
    logger.info("Screen before pressing tuning to channel", :screenshot => true, :use_last_image => false, :image_suffix => "image")
    screens.live_tv.set_channel?(to_channel)
  end
  times[0] = Time.now
  if screenROI.wait_until_not_displayed?(timeout=15000, :priority => :high)
    times[1] = Time.now
  else
    times[1] = times[0]   # failed case
  end
  dataValue = time_diff_milli(times[0], times[1])
  fail("Failed to go to channel #{to_channel}") if (dataValue == 0)
  dataValue = dataValue.to_s
  report_result(:start_time => times[0], :stop_time => times[1])
  logger.duration(dataValue, :message => "#{from_channel_type} to #{to_channel_type} #{tune_type} tune|")
  press_key.EXIT
end

#odn_web_server_odn_diags_last_reboot(stb_ip = fetch_ip, last_reboot = "") ⇒ Object

Public: Use it to get last reboot time from web server

stb_ip -> IP address of box

Returns last reboot time string



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/platform/stb/odn/odn.rb', line 329

def odn_web_server_odn_diags_last_reboot(stb_ip = fetch_ip, last_reboot = "")
  begin
    logger.info("Establishing connection to ip: #{stb_ip}")
    http = Net::HTTP.new(stb_ip)
    resp = http.get("/odnDiagnostics").body
    if resp.include?("Last Boot Time:")
      resp = resp.slice((resp.index('Last Boot Time:')+'Last Boot Time:'.length)..resp.length-1)
      resp = resp.slice((resp.index('value_white">')+'value_white">'.length)..resp.length-1)
      resp = resp.slice(0..resp.index('</td>')-1)
      #logger.info("Reboot time read from STB:#{resp}")
      resp
    else
      logger.info("Reboot time not read from STB")
      last_reboot
    end
  rescue
    logger.info("Error reading Reboot time from STB")
    last_reboot
  end
end

#report_available_heap_to_sword(startTime, endTime) ⇒ Object

Public: get available heap size data and report to sword

Returns nothing



470
471
472
473
474
475
476
477
478
479
# File 'lib/platform/stb/odn/odn.rb', line 470

def report_available_heap_to_sword(startTime, endTime)
  startTime = Time.now if (startTime == 0)
  endTime = startTime if (endTime == 0)
  available_heap = get_available_heap().to_s
  if is_sword?
    # post_result(startTime.to_f, endTime.to_f, :return_no => available_heap)
    report_result(:start_time => startTime, :stop_time => endTime, :return_value => available_heap, :return_title => "available heap", :message => "available heap")
  end
  logger.duration(available_heap, :message => "Available heap|#{available_heap}")
end

#report_heap_size_to_sword(startTime, endTime) ⇒ Object

Public: get heap size data and report to sword

Returns nothing



456
457
458
459
460
461
462
463
464
465
# File 'lib/platform/stb/odn/odn.rb', line 456

def report_heap_size_to_sword(startTime, endTime)
  startTime = Time.now if (startTime == 0)
  endTime = startTime if (endTime == 0)
  heap_size = get_heap_size().to_s
  if is_sword?
    # post_result(startTime.to_f, endTime.to_f, :return_no => heap_size)
    report_result(:start_time => startTime, :stop_time => endTime, :return_value => heap_size, :return_title => "heap size", :message => "heap size")
  end
  logger.duration(heap_size, :message => "Heap size|#{heap_size}")
end

#report_largest_block_to_sword(startTime, endTime) ⇒ Object

Public: get largest block data and report to sword

Returns nothing



442
443
444
445
446
447
448
449
450
451
# File 'lib/platform/stb/odn/odn.rb', line 442

def report_largest_block_to_sword(startTime, endTime)
  startTime = Time.now if (startTime == 0)
  endTime = startTime if (endTime == 0)
  largest_block = get_largest_block().to_s
  if is_sword?
    # post_result(startTime.to_f, endTime.to_f, :return_no => largest_block)
    report_result(:start_time => startTime, :stop_time => endTime, :return_value => largest_block, :return_title => "largest block", :message => "largest block")
  end
  logger.duration(largest_block, :message => "Largest block|#{largest_block}")
end

#sleep_while_check_for_reboots(duration_min = 30, last_reboot = "") ⇒ Object

Public: sleep for the minutes provided and check for reboot time (and report it to sword)

duration_min - number of minutes to sleep

return last reboot in minutes



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/platform/stb/odn/odn.rb', line 355

def sleep_while_check_for_reboots(duration_min=30, last_reboot="")
  test_duration = true
  while (duration_min > 0)
    last_reboot_read = odn_web_server_odn_diags_last_reboot(ip_address, last_reboot)
    if (last_reboot != "") and (last_reboot_read != "") and (last_reboot_read != nil) and (last_reboot != nil)
      if ((!last_reboot_read.eql?(last_reboot)) and (last_reboot.length>10) and (last_reboot_read.length>10))
        begin
          reboot_time = Time.parse(last_reboot_read)
          # post_reboot_result(reboot_time)
          report_result(:start_time => reboot_time, :stop_time => reboot_time, :return_value => reboot_time, :return_title => 'REBOOT', :message => 'REBOOT')
        rescue
          # post_reboot_result(Time.now)
          report_result(:start_time => Time.now, :stop_time => Time.now, :return_value => Time.now, :return_title => 'REBOOT', :message => 'REBOOT')
        end
        logger.info("***STB Rebooted:#{last_reboot_read};;;;;;;#{last_reboot}***")
        last_reboot = last_reboot_read
        File.open("tmp/Last_reboot_stb_#{$stb_id}.txt", 'w') do |f|
          f.puts(last_reboot)
        end
      end
    end
    if (duration_min > 15)
      if (test_duration)
        sleep(90.sec)
      else
        sleep(15.min)
      end
    else
      if (test_duration)
        sleep((duration_min/10).sec)
      else
        sleep(duration_min.min)
      end
    end
    # TO DO:  are we sure about the following line?  Based on the about if-block, we don't always sleep for 15 minutes...
    duration_min = duration_min - 15
  end

  if (last_reboot == "" or last_reboot == nil)
    last_reboot_read
  else
    last_reboot
  end
end

#time_diff_milli(t1, t2) ⇒ Object

Public: compares 2 time values and returns the difference in milliseconds

t1 - start time t2 - end time

return delta (in ms) of the 2 timestamps



283
284
285
286
287
288
289
290
291
292
# File 'lib/platform/stb/odn/odn.rb', line 283

def time_diff_milli(t1, t2)
  if t1.is_a?(DateTime)
    delta_s = (t2 - t1) * 24.0 * 60 * 60  # convert DateTime delta from days to seconds
  elsif t1.is_a?(Time)
    delta_s = t2 - t1  # Time delta already in seconds
  else
    return time_diff_milli(to_time(t1), to_time(t2))  # Unknown -- try to convert values to Time or DateTime
  end
  delta_s * 1000.0  # convert to ms
end

#verify_expected_channel?(channel_number) ⇒ Boolean

Public: verify if we are in the expected channel by checking with the guide or the info banner

channel_number - channel number user is expecting

Returns true if verified, false otherwise

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/platform/stb/odn/odn.rb', line 52

def verify_expected_channel?(channel_number)
  rti_flag = options.fetch(:rti_flag, 'false')
  $rti_flag = (rti_flag == 'true')

  current_channel_number = -1
  if ($rti_flag == false)
    logger.info("Before guide_banner_verify_channel_number")
    current_channel_number = get_channel_number_from_guide()
  else
    logger.info("Before info_banner_launch_and_verify_channel_number")
    current_channel_number = get_channel_number_from_info_banner()
  end
  if current_channel_number.match(/^\d+$/)
    current_channel_number = current_channel_number.to_i
  else
    current_channel_number = -1
  end
  fail("Failed to get the current channel number") if (current_channel_number <= 0)
  current_channel_number == channel_number
end