Class: RSMP::SignalGroup

Inherits:
Component show all
Defined in:
lib/rsmp/tlc.rb

Constant Summary

Constants inherited from Component

Component::AGGREGATED_STATUS_KEYS

Instance Attribute Summary collapse

Attributes inherited from Component

#aggregated_status, #aggregated_status_bools, #alarms, #c_id, #grouped, #node, #statuses

Instance Method Summary collapse

Methods inherited from Component

#aggregated_status_changed, #alarm, #clear_aggregated_status, #log, #set_aggregated_status, #set_aggregated_status_bools

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(node:, id:, plan:) ⇒ SignalGroup

Returns a new instance of SignalGroup.


628
629
630
631
632
# File 'lib/rsmp/tlc.rb', line 628

def initialize node:, id:, plan:
  super node: node, id: id, grouped: false
  @plan = plan
  move 0
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.


626
627
628
# File 'lib/rsmp/tlc.rb', line 626

def plan
  @plan
end

#stateObject (readonly)

Returns the value of attribute state.


626
627
628
# File 'lib/rsmp/tlc.rb', line 626

def state
  @state
end

Instance Method Details

#get_state(pos) ⇒ Object


634
635
636
637
638
639
640
# File 'lib/rsmp/tlc.rb', line 634

def get_state pos
  if pos > @plan.length
    '.'
  else
    @plan[pos]
  end
end

#get_status(code, name = nil) ⇒ Object


671
672
673
674
675
676
677
678
# File 'lib/rsmp/tlc.rb', line 671

def get_status code, name=nil
  case code
  when 'S0025'
    return send("handle_#{code.downcase}", code, name)
  else
    raise InvalidMessage.new "unknown status code #{code}"
  end
end

#handle_command(command_code, arg) ⇒ Object


646
647
648
649
650
651
652
653
# File 'lib/rsmp/tlc.rb', line 646

def handle_command command_code, arg
  case command_code
  when 'M0010', 'M0011'
    return send("handle_#{command_code.downcase}", arg)
  else
    raise UnknownCommand.new "Unknown command #{command_code}"
  end
end

#handle_m0010(arg) ⇒ Object

Start of signal group. Orders a signal group to green


656
657
658
659
660
661
# File 'lib/rsmp/tlc.rb', line 656

def handle_m0010 arg
  @node.verify_security_code 2, arg['securityCode']
  if RSMP::Tlc.from_rsmp_bool arg['status']
    log "Start signal group #{c_id}, go to green", level: :info
  end
end

#handle_m0011(arg) ⇒ Object

Stop of signal group. Orders a signal group to red


664
665
666
667
668
669
# File 'lib/rsmp/tlc.rb', line 664

def handle_m0011 arg
  @node.verify_security_code 2, arg['securityCode']
  if RSMP::Tlc.from_rsmp_bool arg['status']
    log "Stop signal group #{c_id}, go to red", level: :info
  end
end

#handle_s0025(status_code, status_name = nil) ⇒ Object


680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/rsmp/tlc.rb', line 680

def handle_s0025 status_code, status_name=nil
  now = @node.clock.to_s
  case status_name
  when 'minToGEstimate'
    RSMP::Tlc.make_status now
  when 'maxToGEstimate'
    RSMP::Tlc.make_status now
  when 'likelyToGEstimate'
    RSMP::Tlc.make_status now
  when 'ToGConfidence'
    RSMP::Tlc.make_status 0
  when 'minToREstimate'
    RSMP::Tlc.make_status now
  when 'maxToREstimate'
    RSMP::Tlc.make_status now
  when 'likelyToREstimate'
    RSMP::Tlc.make_status now
  when 'ToRConfidence'
    RSMP::Tlc.make_status 0
  end
end

#move(pos) ⇒ Object


642
643
644
# File 'lib/rsmp/tlc.rb', line 642

def move pos
  @state = get_state pos
end