Skip to content

Fix packet decom of array data #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions openc3.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
"path": "../openc3.com"
},
{
"path": "../openc3-cosmos-enterprise"
"path": "../cosmos-enterprise"
},
{
"path": "../cosmos-playwright"
}
],
"settings": {
"vetur.validation.template": false,
"eslint.validate": [
"vue",
"html",
"javascript"
],
"eslint.workingDirectories": [
"./openc3-cosmos-init/plugins"
],
"eslint.validate": ["vue", "html", "javascript"],
"eslint.workingDirectories": ["./openc3-cosmos-init/plugins"],
"eslint.packageManager": "yarn",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
Expand All @@ -40,7 +34,7 @@
"files.trimTrailingWhitespace": true,
"git.ignoreLimitWarning": true,
"ruby.rubocop.onSave": true,
"ruby.format": "rubocop",
"ruby.format": "rubocop"
},
"files.associations": {}
}
}
2 changes: 1 addition & 1 deletion openc3/lib/openc3/models/cvt_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/utilities/store'
Expand Down
5 changes: 3 additions & 2 deletions openc3/lib/openc3/packets/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'digest'
Expand Down Expand Up @@ -561,7 +561,8 @@ def get_item(name)
# can be any type.
def read_item(item, value_type = :CONVERTED, buffer = @buffer, given_raw = nil)
if given_raw
value = given_raw
# Must clone this since value is returned
value = given_raw.clone
else
value = super(item, :RAW, buffer)
end
Expand Down
19 changes: 18 additions & 1 deletion openc3/spec/models/cvt_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'spec_helper'
Expand Down Expand Up @@ -51,6 +51,23 @@ def check_temp1
update_temp1()
check_temp1()
end

it "decoms and sets" do
packet = Packet.new("TGT", "PKT", :BIG_ENDIAN, 'packet', "\x01\x02")
packet.append_item("ary", 8, :UINT, 16)
i = packet.get_item("ARY")
i.read_conversion = GenericConversion.new("value * 2")
i.format_string = "0x%x"
i.units = 'V'

json_hash = CvtModel.build_json_from_packet(packet)
CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: 'DEFAULT')

expect(CvtModel.get_item("TGT", "PKT", "ARY", type: :RAW, scope: "DEFAULT")).to eql [1, 2]
expect(CvtModel.get_item("TGT", "PKT", "ARY", type: :CONVERTED, scope: "DEFAULT")).to eql [2, 4]
expect(CvtModel.get_item("TGT", "PKT", "ARY", type: :FORMATTED, scope: "DEFAULT")).to eql ["0x2", "0x4"]
expect(CvtModel.get_item("TGT", "PKT", "ARY", type: :WITH_UNITS, scope: "DEFAULT")).to eql ["0x2 V", "0x4 V"]
end
end

describe "self.del" do
Expand Down
18 changes: 17 additions & 1 deletion openc3/spec/packets/packet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'spec_helper'
Expand Down Expand Up @@ -1626,6 +1626,22 @@ module OpenC3
end

describe "decom" do
it "creates decommutated array data" do
p = Packet.new("tgt", "pkt")
i1 = p.append_item("test1", 8, :UINT, 16)
i1.read_conversion = GenericConversion.new("value * 2")
i1.format_string = "0x%X"
i1.units = 'C'

buffer = "\x01\x02"
p.buffer = buffer
vals = p.decom
expect(vals['TEST1']).to eql [1, 2]
expect(vals['TEST1__C']).to eql [2, 4]
expect(vals['TEST1__F']).to eql ['0x2', '0x4']
expect(vals['TEST1__U']).to eql ['0x2 C', '0x4 C']
end

it "creates decommutated data" do
p = Packet.new("tgt", "pkt")
i1 = p.append_item("test1", 8, :UINT, 16)
Expand Down