Skip to content

Commit

Permalink
Merge pull request #1569 from OpenC3/received_count
Browse files Browse the repository at this point in the history
RECEIVED_COUNT returns 0 if packet not received
  • Loading branch information
jmthomas authored Sep 26, 2024
2 parents ebc6cbf + 3346f3c commit c777b81
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
16 changes: 11 additions & 5 deletions openc3/lib/openc3/models/cvt_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,21 @@ def self.get_item(target_name, packet_name, item_name, type:, cache_timeout: nil
result, types = self._handle_item_override(target_name, packet_name, item_name, type: type, cache_timeout: cache_timeout, scope: scope)
return result if result
hash = get(target_name: target_name, packet_name: packet_name, cache_timeout: cache_timeout, scope: scope)
hash.values_at(*types).each do |result|
if result
hash.values_at(*types).each do |cvt_value|
if cvt_value
if type == :FORMATTED or type == :WITH_UNITS
return result.to_s
return cvt_value.to_s
end
return result
return cvt_value
end
end
return nil
# RECEIVED_COUNT is a special case where it is 0 if it doesn't exist
# This allows scripts to check against the value to see if the packet was ever received
if item_name == "RECEIVED_COUNT"
return 0
else
return nil
end
end

# Return all item values and limit state from the CVT
Expand Down
15 changes: 10 additions & 5 deletions openc3/python/openc3/models/cvt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ def get_item(
if result is not None:
return result
hash = cls.get(target_name, packet_name, scope=scope)
for result in [hash[x] for x in types if x in hash]:
if result is not None:
for cvt_value in [hash[x] for x in types if x in hash]:
if cvt_value is not None:
if type == "FORMATTED" or type == "WITH_UNITS":
return str(result)
return result
return None
return str(cvt_value)
return cvt_value
# RECEIVED_COUNT is a special case where it is 0 if it doesn't exist
# This allows scripts to check against the value to see if the packet was ever received
if item_name == "RECEIVED_COUNT":
return 0
else:
return None

# Return all item values and limit state from the CVT
#
Expand Down
3 changes: 1 addition & 2 deletions playwright/tests/bucket-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ test('navigate logs and tools bucket', async ({ page, utils }) => {
await expect(
page.getByText('DEFAULT__INST__ALL__rt__raw').first(),
).toBeVisible()
await expect(page.getByText('1970')).not.toBeVisible()

await page.getByText('tools').click()
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/tools%2F/)
if (process.env.ENTERPRISE === '1') {
await expect(page.locator('tbody > tr')).toHaveCount(19)
await expect(page.locator('tbody > tr')).toHaveCount(20)
} else {
await expect(page.locator('tbody > tr')).toHaveCount(17)
}
Expand Down
27 changes: 11 additions & 16 deletions playwright/tests/data-extractor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ test('fills values', async ({ page, utils }) => {
break
} else if (lines[i].includes('HEALTH_STATUS')) {
// Look for the second line containing HEALTH_STATUS
// console.log("Found first HEALTH_STATUS on line " + i);
if (firstHS === -2) {
firstHS = -1
} else {
Expand Down Expand Up @@ -381,8 +380,8 @@ test('works with UTC date / times', async ({ page, utils }) => {
expect(
isWithinInterval(startTime, {
// Start time is automatically 1hr in the past
start: subMinutes(now, 61),
end: subMinutes(now, 59),
start: subMinutes(now, 62),
end: subMinutes(now, 58),
}),
).toBeTruthy()
let endTimeString =
Expand All @@ -391,8 +390,8 @@ test('works with UTC date / times', async ({ page, utils }) => {
expect(
isWithinInterval(endTime, {
// end time is now
start: subMinutes(now, 1),
end: addMinutes(now, 1),
start: subMinutes(now, 2),
end: addMinutes(now, 2),
}),
).toBeTruthy()

Expand All @@ -411,29 +410,25 @@ test('works with UTC date / times', async ({ page, utils }) => {
await expect(page.locator('#openc3-nav-drawer')).toBeHidden()

now = new Date()
// The date is now in UTC but we parse it like it is local time
// add the timezone offset to get it to UTC
now = addMinutes(now, now.getTimezoneOffset())
startTimeString =
(await page.inputValue('[data-test=start-time]'))?.trim() || ''
startTime = parse(startTimeString, 'HH:mm:ss.SSS', now)
// so subtrack off the timezone offset to get it back to local time
let localStartTime = subMinutes(startTime, now.getTimezoneOffset())
expect(
isWithinInterval(localStartTime, {
isWithinInterval(startTime, {
// Start time is automatically 1hr in the past
start: subMinutes(now, 61),
end: subMinutes(now, 59),
start: subMinutes(now, 62),
end: subMinutes(now, 58),
}),
).toBeTruthy()
// The date is now in UTC but we parse it like it is local time
endTimeString = (await page.inputValue('[data-test=end-time]'))?.trim() || ''
endTime = parse(endTimeString, 'HH:mm:ss.SSS', now)
// so subtrack off the timezone offset to get it back to local time
endTime = subMinutes(endTime, now.getTimezoneOffset())
expect(
isWithinInterval(endTime, {
// end time is now
start: subMinutes(now, 1),
end: addMinutes(now, 1),
start: subMinutes(now, 2),
end: addMinutes(now, 2),
}),
).toBeTruthy()

Expand Down

0 comments on commit c777b81

Please sign in to comment.