Skip to content

Commit

Permalink
Request full packet from backend on page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
aywaldron authored and Futabay committed May 19, 2020
1 parent df28e93 commit 8841588
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
24 changes: 24 additions & 0 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,30 @@ def handle():
pass


@App.route('/tlm/latest', method='GET')
def handle():
"""Return latest telemetry packet to client"""
with Sessions.current() as session:
tlmdict = ait.core.tlm.getDefaultDict()
uid, data = session.telemetry.popleft(timeout=30)
pkt_defn = None
for k, v in tlmdict.iteritems():
if v.uid == uid:
pkt_defn = v
break

ait_pkt = ait.core.tlm.Packet(pkt_defn, data=data)
json_pkt = ait_pkt.toJSON()
for field, value in json_pkt.items():
dntoeus = add_dntoeu_value(field, ait_pkt, {})

return json.dumps({
'packet': pkt_defn.name,
'data': json_pkt,
'dntoeus': dntoeus
})


@App.route('/tlm/query', method='POST')
def handle():
""""""
Expand Down
2 changes: 1 addition & 1 deletion ait/gui/static/js/ait/gui/Plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DygraphsBackend
if (!names) return

let row = [ this._plot._time.get(packet) ]

console.log(packet)
// For each series of data, if it's in the current packet
// that we're updating, add the associated point. Otherwise,
// add a null value. Dygraphs requires that the data added
Expand Down
24 changes: 20 additions & 4 deletions ait/gui/static/js/ait/tlm.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,33 @@ class TelemetryStream
let data = JSON.parse(event.data)
let packet_name = data['packet']
let delta = data['data']
let dntoeus = data['dntoeus']

console.log(this._pkt_states)

// add delta to last full packet
// want full packet inserted in packet buffer & emitted as event
if ( Object.keys(delta).length !== 0 ) {
if ( packet_name in this._pkt_states ) {
if ( packet_name in this._pkt_states ) {
if ( Object.keys(delta).length !== 0 ) {
for ( var field in delta ) {
this._pkt_states[packet_name][field] = this._pkt_states[packet_name][field] + delta[field]
}
} else {
this._pkt_states[packet_name] = delta
}
} else {
console.log('name not in states')
// delta is empty - request full packet from backend
if ( Object.keys(delta).length == 0 ) {
m.request({ url: '/tlm/latest' }).then( (latest) => {
packet_name = latest['packet']
delta = latest['data']
dntoeus = latest['dntoeus']
console.log('here')
console.log(delta)
})
console.log(delta)
}

this._pkt_states[packet_name] = delta
}

// Since WebSockets can stay open indefinitely, the AIT GUI
Expand Down

0 comments on commit 8841588

Please sign in to comment.