Skip to content

Commit

Permalink
Update backend endpoint for returning latest packet states (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
aywaldron committed Oct 8, 2019
1 parent 24a36dd commit a32e330
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ def handle():
__setResponseToEventStream()
yield 'data: %s\n\n' % json.dumps(msg)


@App.route('/tlm/realtime/openmct')
def handle():
"""Return telemetry packets in realtime to client"""
Expand Down Expand Up @@ -697,7 +698,7 @@ def add_dntoeu_value(field, packet, dntoeus):
return dntoeus


last_packets = { }
packet_states = { }
def get_packet_delta(pkt_defn, packet):
"""
Keeps track of last packets recieved of all types recieved
Expand All @@ -713,8 +714,8 @@ def get_packet_delta(pkt_defn, packet):
json_pkt = ait_pkt.toJSON()

# first packet of this type
if pkt_defn.name not in last_packets:
last_packets[pkt_defn.name] = json_pkt
if pkt_defn.name not in packet_states:
packet_states[pkt_defn.name] = json_pkt
delta = json_pkt

dntoeus = {}
Expand All @@ -725,10 +726,10 @@ def get_packet_delta(pkt_defn, packet):
else:
delta, dntoeus = {}, {}
for field, new_value in json_pkt.items():
last_value = last_packets[pkt_defn.name][field]
last_value = packet_states[pkt_defn.name][field]
if new_value != last_value:
delta[field] = new_value
last_packets[pkt_defn.name][field] = new_value
packet_states[pkt_defn.name][field] = new_value
dntoeus = add_dntoeu_value(field, ait_pkt, dntoeus)

return delta, dntoeus
Expand Down Expand Up @@ -783,25 +784,7 @@ def handle():
@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
})
return json.dumps(packet_states)


@App.route('/tlm/query', method='POST')
Expand Down

0 comments on commit a32e330

Please sign in to comment.