Skip to content
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

Allow array index on graph widget #1402

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TELEMETRY <%= target_name %> HEALTH_STATUS BIG_ENDIAN "Health and status from th
STATE CONNECTED 1 GREEN
STATE UNAVAILABLE 0 YELLOW
APPEND_ITEM BLOCKTEST 80 BLOCK "Block data"
APPEND_ITEM BRACKET[0] 8 UINT "Regular item with brackets in the name"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's unusual to add items to the demo but it was the only way to really test it

ITEM PACKET_TIME 0 0 DERIVED "Ruby time based on TIMESEC and TIMEUS"
READ_CONVERSION unix_time_conversion.rb TIMESEC TIMEUS
ITEM TEMP1HIGH 0 0 DERIVED "High-water mark for TEMP1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def read(count_100hz, time)
cycle_tlm_item(packet, 'temp3', -30.0, 80.0, 2.0)
end
cycle_tlm_item(packet, 'temp4', 0.0, 20.0, -0.1)
cycle_tlm_item(packet, 'bracket[0]', 0, 255, 10)

packet.timesec = time.tv_sec - @time_offset
packet.timeus = time.tv_usec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ VERTICAL
ARRAY <%= target_name %> HEALTH_STATUS ARY
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[0] RAW
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[1] WITH_UNITS
# This item is actually called BRACKET[0] as the name
# thus we have to escape the value here to avoid it
# being treated like an array item
LABELVALUE <%= target_name %> HEALTH_STATUS BRACKET[[0]]
LABELSPARKLINE <%= target_name %> HEALTH_STATUS ARY[1]
SETTING HISTORY 60s
LABELSPARKLINE <%= target_name %> HEALTH_STATUS BRACKET[[0]]
SETTING HISTORY 60s
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting all these case to work correctly was interesting

ARRAY <%= target_name %> HEALTH_STATUS ARY 300 65 nil 8 FORMATTED
ARRAY <%= target_name %> HEALTH_STATUS ARY2 300 65 nil 5 WITH_UNITS
TEXTBOX <%= target_name %> HEALTH_STATUS ARY 200 65
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TELEMETRY <%= target_name %> HEALTH_STATUS BIG_ENDIAN "Health and status from th
STATE CONNECTED 1 GREEN
STATE UNAVAILABLE 0 YELLOW
APPEND_ITEM BLOCKTEST 80 BLOCK "Block data"
APPEND_ITEM BRACKET[0] 8 UINT "Regular item with brackets in the name"
ITEM PACKET_TIME 0 0 DERIVED "Ruby time based on TIMESEC and TIMEUS"
READ_CONVERSION openc3/conversions/unix_time_conversion.py TIMESEC TIMEUS
ITEM TEMP1HIGH 0 0 DERIVED "High-water mark for TEMP1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def read(self, count_100hz, time):
self.bad_temp2 = True
self.cycle_tlm_item(packet, "temp3", -30.0, 80.0, 2.0)
self.cycle_tlm_item(packet, "temp4", 0.0, 20.0, -0.1)
self.cycle_tlm_item(packet, "bracket[0]", 0, 255, 10)

packet.write("timesec", int(time - self.time_offset))
packet.write("timeus", int((time % 1) * 1000000))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ VERTICAL
ARRAY <%= target_name %> HEALTH_STATUS ARY
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[0] RAW
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[1] WITH_UNITS
# This item is actually called BRACKET[0] as the name
# thus we have to escape the value here to avoid it
# being treated like an array item
LABELVALUE <%= target_name %> HEALTH_STATUS BRACKET[[0]]
LABELSPARKLINE <%= target_name %> HEALTH_STATUS ARY[1]
SETTING HISTORY 60s
LABELSPARKLINE <%= target_name %> HEALTH_STATUS BRACKET[[0]]
SETTING HISTORY 60s
ARRAY <%= target_name %> HEALTH_STATUS ARY 300 65 nil 8 FORMATTED
ARRAY <%= target_name %> HEALTH_STATUS ARY2 300 65 nil 5 WITH_UNITS
TEXTBOX <%= target_name %> HEALTH_STATUS ARY 200 65
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,29 @@ export default {
}
})
if (this.screen) {
this.items.map((item) =>
this.items = this.items.map((item) => {
let itemName = item.itemName
// Remove double bracket escaping. This means they actually have an item
// with a bracket in the name, not an array index.
if (item.itemName.includes('[[')) {
// Change the actual item and the the name we're passing to the screen
item.itemName = item.itemName.replace('[[', '[').replace(']]', ']')
itemName = item.itemName
} else if (item.itemName.includes('[')) {
// Brackets mean array indexes (normally, but see above)
let match = item.itemName.match(/\[(\d+)\]/)
this.arrayIndex = parseInt(match[1])
// Here we keep the original item name with the brackets but change
// the item we're passing to the screen to the non-bracket item
itemName = item.itemName.replace(match[0], '')
}
this.screen.addItem(
`${item.targetName}__${item.packetName}__${item.itemName}__${item.valueType}`,
),
)
`${item.targetName}__${item.packetName}__${itemName}__${item.valueType}`,
true,
)
// Return the mapped values since we may have removed bracket escaping
return item
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key to getting this work was reassigning this.items to the mapped version which returns the escaped bracket names

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't support an array item with a real bracket in the name. That's probably ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're naming an array item with brackets then you're really asking for trouble!

}
},
destroyed() {
Expand Down
Loading