Skip to content

Commit

Permalink
proper support for m0013
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Aug 7, 2023
1 parent 0fd6059 commit c3e0cf8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/rsmp/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ def notify_error e, options={}
@error_queue.enqueue e
end

def defer item
@deferred << item
def defer key, item=nil
@deferred << [key, item]
end

def process_deferred
cloned = @deferred.clone # clone in case do_deferred restarts the current task
@deferred.clear
cloned.each do |item|
do_deferred item
cloned.each do |pair|
do_deferred pair.first, pair.last
end
end

def do_deferred item
def do_deferred key,item=nil
end

def clear_deferred
Expand Down
40 changes: 40 additions & 0 deletions lib/rsmp/tlc/traffic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,45 @@ def handle_m0012 arg, options={}

def handle_m0013 arg, options={}
@node.verify_security_code 2, arg['securityCode']
set, clear = [], []
arg['status'].split(';').map do |part|
offset, set_bits, clear_bits = part.split(',').map { |i| i.to_i }
set_bits.to_s(2).reverse.each_char.with_index do |bit,i|
set << i + offset if bit == '1'
end
clear_bits.to_s(2).reverse.each_char.with_index do |bit,i|
clear << i + offset if bit == '1'
end
end

set = set.uniq.sort
clear = clear.uniq.sort

# if input is both activated and deacticvated, there is no need to acticate first
set -= (set & clear)

[set,clear].each do |inputs|
inputs.each do |input|
if input<1
raise MessageRejected.new("Cannot acticate inputs #{set} and deactive inputs #{clear}: input #{input} is invalid (must be 1 or higher)"
) if input<1
end
if input>@inputs.size
raise MessageRejected.new("Cannot acticate inputs #{set} and deactive inputs #{clear}: input #{input} is invalid (only #{@inputs.size} inputs present)")
end
end
end

log "Activating inputs #{set} and deactivating inputs #{clear}", level: :info

set.each do |input|
change = @inputs.set input, true
input_logic input, change if change != nil
end
clear.each do |input|
change = @inputs.set input, false
input_logic input, change if change != nil
end
end

def find_plan plan_nr
Expand Down Expand Up @@ -432,6 +471,7 @@ def handle_m0019 arg, options={}
log "Releasing input #{input}", level: :info
end
change = @inputs.set_forcing input, force, forced_value

input_logic input, change if change != nil
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rsmp/tlc/traffic_controller_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def self.make_status value, q='recent'
end
end

def do_deferred item
case item
def do_deferred key, item=nil
case key
when :restart
log "Restarting TLC", level: :info
restart
Expand Down

0 comments on commit c3e0cf8

Please sign in to comment.