Class: RSMP::DetectorLogic

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:) ⇒ DetectorLogic

Returns a new instance of DetectorLogic.


706
707
708
709
710
# File 'lib/rsmp/tlc.rb', line 706

def initialize node:, id:
  super node: node, id: id, grouped: false
  @forced = 0
  @value = 0
end

Instance Attribute Details

#forcedObject (readonly)

Returns the value of attribute forced.


704
705
706
# File 'lib/rsmp/tlc.rb', line 704

def forced
  @forced
end

#statusObject (readonly)

Returns the value of attribute status.


704
705
706
# File 'lib/rsmp/tlc.rb', line 704

def status
  @status
end

#valueObject (readonly)

Returns the value of attribute value.


704
705
706
# File 'lib/rsmp/tlc.rb', line 704

def value
  @value
end

Instance Method Details

#force_detector_logic(status, value) ⇒ Object


788
789
790
791
# File 'lib/rsmp/tlc.rb', line 788

def force_detector_logic status, value
  @forced = status
  @value = value
end

#get_status(code, name = nil) ⇒ Object


712
713
714
715
716
717
718
719
# File 'lib/rsmp/tlc.rb', line 712

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

#handle_command(command_code, arg) ⇒ Object


773
774
775
776
777
778
779
780
# File 'lib/rsmp/tlc.rb', line 773

def handle_command command_code, arg
  case command_code
  when 'M0008'
    handle_m0008 arg
  else
    raise UnknownCommand.new "Unknown command #{command_code}"
  end
end

#handle_m0008(arg) ⇒ Object


782
783
784
785
786
# File 'lib/rsmp/tlc.rb', line 782

def handle_m0008 arg
  @node.verify_security_code 2, arg['securityCode']
  force_detector_logic arg['status']=='True', arg['value']='True'
  arg
end

#handle_s0201(status_code, status_name = nil) ⇒ Object


721
722
723
724
725
726
727
728
# File 'lib/rsmp/tlc.rb', line 721

def handle_s0201 status_code, status_name=nil
  case status_name
  when 'starttime'
    RSMP::Tlc.make_status @node.clock.to_s
  when 'vehicles'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0202(status_code, status_name = nil) ⇒ Object


730
731
732
733
734
735
736
737
# File 'lib/rsmp/tlc.rb', line 730

def handle_s0202 status_code, status_name=nil
  case status_name
  when 'starttime'
    RSMP::Tlc.make_status @node.clock.to_s
  when 'speed'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0203(status_code, status_name = nil) ⇒ Object


739
740
741
742
743
744
745
746
# File 'lib/rsmp/tlc.rb', line 739

def handle_s0203 status_code, status_name=nil
  case status_name
  when 'starttime'
    RSMP::Tlc.make_status @node.clock.to_s
  when 'occupancy'
    RSMP::Tlc.make_status 0
  end
end

#handle_s0204(status_code, status_name = nil) ⇒ Object


748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/rsmp/tlc.rb', line 748

def handle_s0204 status_code, status_name=nil
  case status_name
  when 'starttime'
    RSMP::Tlc.make_status @node.clock.to_s
  when 'P'
    RSMP::Tlc.make_status 0
  when 'PS'
    RSMP::Tlc.make_status 0
  when 'L'
    RSMP::Tlc.make_status 0
  when 'LS'
    RSMP::Tlc.make_status 0
  when 'B'
    RSMP::Tlc.make_status 0
  when 'SP'
    RSMP::Tlc.make_status 0
  when 'MC'
    RSMP::Tlc.make_status 0
  when 'C'
    RSMP::Tlc.make_status 0
  when 'F'
    RSMP::Tlc.make_status 0
  end
end