Class: Validator::StatusHelpers::SignalPriorityRequestHelper

Inherits:
RSMP::Queue
  • Object
show all
Includes:
CommandHelpers, Validator::StatusHelpers
Defined in:
spec/support/signal_priority_request_helper.rb

Instance Method Summary collapse

Methods included from CommandHelpers

#build_command_list, #disable_emergency_route, #enable_emergency_route, #force_detector_logic, #force_input, #force_input_and_confirm, #force_output, #get_dynamic_bands, #prepare, #require_security_codes, #reset_clock, #resume_alarm, #send_command_and_confirm, #set_clock, #set_cycle_time, #set_day_table, #set_dynamic_bands, #set_emergency_route, #set_fixed_time, #set_functional_position, #set_input, #set_offset, #set_plan, #set_security_code, #set_series_of_inputs, #set_signal_start, #set_signal_start_or_stop, #set_signal_stop, #set_timeout_for_dynamic_bands, #set_traffic_situation, #set_trigger_level, #set_week_table, #stop_sending_watchdogs, #suspend_alarm, #switch_dark_mode, #switch_fixed_time, #switch_input, #switch_normal_control, #switch_plan, #switch_traffic_situation, #switch_yellow_flash, #unset_traffic_situation, #verify_startup_sequence, #wait_normal_control, #with_alarm_activated, #with_clock_set, #wrong_security_code

Methods included from Validator::StatusHelpers

#convert_status_list, #request_status_and_confirm, #unsubscribe_from_all, #use_sOc?, #verify_status, #wait_for_groups, #wait_for_status

Constructor Details

#initialize(site, component:, signal_group_id:, timeout:, task:) ⇒ SignalPriorityRequestHelper

Returns a new instance of SignalPriorityRequestHelper.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'spec/support/signal_priority_request_helper.rb', line 44

def initialize site, component:, signal_group_id:, timeout:, task:
  super( site,
    filter: RSMP::Filter.new(
      type: 'StatusUpdate',
      ingoing: true,
      outgoing: false,
      component: component
    ),
    task: task
  )
  @site = site
  @component = component
  @signal_group_id = signal_group_id
  @request_id = SecureRandom.uuid()[0..3]
  @matcher = S0033Matcher.new({"cCI"=>"S0033", "q"=>"recent"}, request_id: @request_id)
  @subscribe_list = [{'sCI'=>'S0033','n'=>'status','uRt'=>'0'}]
  @subscribe_list.map! { |item| item.merge!('sOc' => true) } if use_sOc?(@site)
  @unsubscribe_list = [{'sCI'=>'S0033','n'=>'status'}]
  @got = []
  @timeout = timeout
end

Instance Method Details

#cancelObject



105
106
107
108
109
110
111
# File 'spec/support/signal_priority_request_helper.rb', line 105

def cancel
  command_list = build_command_list :M0022, :requestPriority, {
    requestId: @request_id,
    type: 'cancel'
  }
  @site.send_command @component, command_list
end

#expect(state) ⇒ Object



113
114
115
116
117
118
# File 'spec/support/signal_priority_request_helper.rb', line 113

def expect state
  @matcher.state = state
  message = wait_for_message timeout: @timeout
rescue RSMP::TimeoutError
  raise RSMP::TimeoutError.new("Priority request did not reach state #{state} within #{@timeout}s")
end

#request(level: 7, eta: 2, vehicleType: 'car') ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'spec/support/signal_priority_request_helper.rb', line 73

def request(
  level: 7,
  eta: 2,
  vehicleType: 'car'
)
  command_list = build_command_list(:M0022, :requestPriority, {
    requestId: @request_id,
    signalGroupId: @signal_group_id,
    type: 'new',
    level: level,
    eta: eta,
    vehicleType: vehicleType
  })
  @site.send_command @component, command_list
end

#request_unrelated(level: 7, eta: 2, vehicleType: 'car') ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'spec/support/signal_priority_request_helper.rb', line 89

def request_unrelated(
  level: 7,
  eta: 2,
  vehicleType: 'car'
)
  command_list = build_command_list( :M0022, :requestPriority, {
    requestId: SecureRandom.uuid()[0..3],
    signalGroupId: @signal_group_id,
    type: 'new',
    level: level,
    eta: eta,
    vehicleType: vehicleType
  })
  @site.send_command @component, command_list
end

#run(&block) ⇒ Object



66
67
68
69
70
71
# File 'spec/support/signal_priority_request_helper.rb', line 66

def run &block
  start
  yield
ensure
  stop
end