Skip to content

Commit

Permalink
Add delta to current packet state before emitting event (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
aywaldron authored and Futabay committed May 19, 2020
1 parent 1f930d4 commit c5887fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 9 additions & 9 deletions ait/gui/static/js/ait/gui/Plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ class DygraphsBackend

plot (data) {
const pname = data['packet']
let delta = data['data']
let packet = data['data']
const names = this._plot._packets[pname]

if (!names) return

let row = [ this._plot._time.get(delta) ]
let row = [ this._plot._time.get(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
// to the plot maintains the same "shape" as the labels.
this._series.forEach((id) => {
if (id.startsWith(pname)) {
row.push(delta[id.split('.')[1]])
row.push(packet[id.split('.')[1]])
} else {
row.push(null)
}
Expand Down Expand Up @@ -210,16 +210,16 @@ class HighchartsBackend

plot(data) {
const pname = data['packet']
let delta = data['data']
let packet = data['data']
const names = this._plot._packets[pname]
if (!names) return

names.forEach( (name) => {
const series = this._plot._chart.get(pname + '.' + name)

if (series) {
const x = this._plot._time.get(delta).getTime()
const y = delta[name]
const x = this._plot._time.get(packet).getTime()
const y = packet[name]

series.addPoint([x, y], false)

Expand Down Expand Up @@ -356,10 +356,10 @@ class HighchartsBackend
const Plot =
{
/**
* Plots data from the given delta.
* Plots data from the given packet.
*/
plot (delta) {
this._backend.plot(delta)
plot (packet) {
this._backend.plot(packet)
},


Expand Down
20 changes: 16 additions & 4 deletions ait/gui/static/js/ait/tlm.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class TelemetryStream
this._socket = new WebSocket(url)
this._stale = 0
this._url = url
this._pkt_states = { }

// Re-map telemetry dictionary to be keyed by a PacketDefinition
// 'id' instead of 'name'.
Expand Down Expand Up @@ -388,6 +389,18 @@ class TelemetryStream
let packet_name = data['packet']
let delta = data['data']

// 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 ) {
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
}
}

// Since WebSockets can stay open indefinitely, the AIT GUI
// server will occasionally probe for dropped client
// connections by sending empty packets (data.byteLength == 0)
Expand All @@ -405,10 +418,9 @@ class TelemetryStream
this._stale = 0
this._interval = setInterval(this.onStale.bind(this), 5000)

console.log(packet_name)
console.log(delta)
ait.packets.insert(packet_name, delta)
this._emit('packet', data)
ait.packets.insert(packet_name, this._pkt_states[packet_name])
this._emit('packet', {'packet': packet_name,
'data': this._pkt_states[packet_name]})
}


Expand Down

0 comments on commit c5887fb

Please sign in to comment.