Skip to content

Commit

Permalink
#93 Make derived arrays behave the same as normal array items
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Mar 23, 2015
1 parent 5f91f6c commit 7333a3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cosmos/packets/packet.rb
Expand Up @@ -357,7 +357,7 @@ def read_item(item, value_type = :CONVERTED, buffer = @buffer)

# Convert from value to state if possible
if item.states
if item.array_size
if Array === value
value = value.map do |val, index|
if item.states.key(val)
item.states.key(val)
Expand All @@ -374,7 +374,7 @@ def read_item(item, value_type = :CONVERTED, buffer = @buffer)
end
end
else
if item.array_size
if Array === value
value = value.map do |val, index|
apply_format_string_and_units(item, val, value_type)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/packets/packet_spec.rb
Expand Up @@ -449,6 +449,12 @@ module Cosmos
expect(@p.read_item(i, :WITH_UNITS, "\x02\x04")).to eql ["TRUE","FALSE"]
expect(@p.read("ITEM", :WITH_UNITS, "\x08")).to eql ["0x4 V"]
expect(@p.read_item(i, :WITH_UNITS, "\x08")).to eql ["0x4 V"]
@p.define_item("item2",0, 0, :DERIVED)
i = @p.get_item("ITEM2")
i.units = "V"
i.read_conversion = GenericConversion.new("[1,2,3,4,5]")
expect(@p.read("ITEM2", :FORMATTED, "")).to eql ["1", "2", "3", "4", "5"]
expect(@p.read("ITEM2", :WITH_UNITS, "")).to eql ["1 V", "2 V", "3 V", "4 V", "5 V"]
end
end

Expand Down

0 comments on commit 7333a3f

Please sign in to comment.