Skip to content

Commit

Permalink
Issue #189 and #190 - Fix data formatting with new data diffing
Browse files Browse the repository at this point in the history
Update the handling of Field format calls to fix issues encountered with
formatting time data and to handle the new diffed data changes. Format
calls are now always run over the raw data of a field instead the "human
readable" data when dealing with complex types or when the value of the
field is not a "number". This could result from enumerated values on
non-complex field. Manipulations can then be performed as necessary on
the data prior to the format call if the data type requires it. For
example, in the case of a Time object we decode the raw value into a Date
object prior to formatting it so the sprintf library handles it properly.

The dtype definitions for Time32 and Time64 have been updated so they
can be used to decode Date objects from raw values. Note, there's no
clean up done here of the other code in dtype that is effectively dead
given the changes to the front / backend transmission formats. That
needs handled in a follow on ticket.

Note, there is the possibility for semi-strange situations to occur with
packet caching and the current format handling. For example, consider a
command field that is not labelled as raw with values that are undefined
opcodes. The "human readable" packet diff will mark this field as
"Unidentified Cmd" any time the opcode doesn't decode properly. As such,
this field could be incorrectly cached and ignored if the raw value
changed but the "human readable" value didn't since the cache check
occurs on the initial pulled value (which relies on raw = true / false).
Effectively, this means that users may need to be more explicit with
marking fields as raw=true.

Similarly, formatting on a given raw / not value isn't always consistent
since we need to support time value formatting. Unfortunately there
isn't a great way to handle this without significantly reducing
functionality and the caveats (e.g., you can't dump a time field to hex)
aren't likely to cause too much pain and suffering.
  • Loading branch information
MJJoyce committed Jan 21, 2021
1 parent 2d2f36c commit 138ccec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
27 changes: 14 additions & 13 deletions ait/gui/static/js/ait/dtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,17 @@ class Time8Type extends TimeType

class Time32Type extends TimeType
{
decode (view, offset=0) {
if (!inBounds(view, 4, offset)) return null

const tv_sec = view.getUint32(offset, false)
return new Date(GPSEpoch + (tv_sec * 1000))
decode (raw) {
return new Date(GPSEpoch + (raw * 1000))
}
}


class Time64Type extends TimeType
{
decode (view, offset=0) {
if (!inBounds(view, 8, offset)) return null

const tv_sec = view.getUint32(offset, false)
const tv_nsec = view.getUint32(offset + 4, false)

return new Date(GPSEpoch + (tv_sec * 1000) + (tv_nsec / 1e6))
decode (raw) {
const parts = String(raw).split('.').map(x => parseInt(x))
return new Date(GPSEpoch + (parts[0] * 1000) + (parts[1] / 1e6))
}
}

Expand Down Expand Up @@ -273,5 +266,13 @@ function get (typename) {
return type
}

function isComplexType(typeName) {
return typeName === 'CMD16' ||
typeName === 'EVR16' ||
typeName === 'TIME8' ||
typeName === 'TIME32' ||
typeName === 'TIME64'
}


export { PrimitiveType, get }
export { PrimitiveType, get, isComplexType }
33 changes: 12 additions & 21 deletions ait/gui/static/js/ait/gui/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {sprintf} from 'sprintf-js'
import * as strftime from 'strftime'

import { CommandDefinition } from '../cmd.js'
import { isComplexType } from '../dtype.js'
import { EVRDefinition } from '../evr.js'

/**
Expand Down Expand Up @@ -303,32 +304,22 @@ const Field =
if (value === undefined || value === null) {
value = 'N/A'
}
else if (value instanceof CommandDefinition) {
value = value.name ? value.name : (value.opcode ? value.opcode : 'Unidentified Cmd')
}
else if (value instanceof EVRDefinition) {
value = value.name ? value.name : (value.code ? value.code : 'Unidentified EVR')
}
else if(Array.isArray(value)) {
// If we're handling an array value that means the field is a ArrayType.
// ArrayType elements are displayed as separate hex dumps of their contents.
let elemSize = 2 * this._fieldDefn.type._nbytes / this._fieldDefn.type._num_elems
let valAcc = ''
let format = `0x%0${elemSize}X `
for (let i of value) {
valAcc += sprintf(format, i)
}

value = valAcc
}
else {
if (vnode.attrs.format) {
const defn = ait.tlm.dict[this._pname]._fields[this._fname]
const type = defn && defn.type

value = (type && type.isTime) ?
strftime.utc()(vnode.attrs.format, value) :
sprintf(vnode.attrs.format, value)
if (this._raw === false && isComplexType(type._name) ||
typeof(value) !== "number") {
value = this.getValue(packet, true)
}

if (type && type.isTime) {
value = type.decode(value)
value = strftime.utc()(vnode.attrs.format, value)
} else {
value = sprintf(vnode.attrs.format, value)
}
} else {
// If the Field doesn't have a format specified and is
// displaying a float we default to 5 digits after the
Expand Down

0 comments on commit 138ccec

Please sign in to comment.