Skip to content

Commit

Permalink
Add tracking of dntoeus on backend (#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 9175608 commit 05e4171
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def addTelemetry (self, uid, packet):
delta = replace_datetimes(delta)

for session in self.values():
print(session)
counter = session.updateCounter(pkt_name)
print(session.tlm_counters)
item = (pkt_name, delta, dntoeus, counter)
session.deltas.append(item)
item = (uid, packet, session.tlm_counters[pkt_name])
Expand Down Expand Up @@ -732,7 +730,11 @@ def add_dntoeu_value(field, packet, dntoeus):
"""
field_defn = packet._defn.fieldmap[field]
if field_defn.dntoeu:
dntoeus[field] = field_defn.dntoeu.eval(packet)
value = field_defn.dntoeu.eval(packet)
# to send to frontend
dntoeus[field] = value
# track on backend
packet_states[packet._defn.name]['dntoeu'][field] = value

return dntoeus

Expand All @@ -754,21 +756,23 @@ def get_packet_delta(pkt_defn, packet):

# first packet of this type
if pkt_defn.name not in packet_states:
packet_states[pkt_defn.name] = json_pkt
packet_states[pkt_defn.name] = {}
packet_states[pkt_defn.name]['raw'] = json_pkt
delta = json_pkt

dntoeus = {}
packet_states[pkt_defn.name]['dntoeu'] = {}
for field, value in json_pkt.items():
dntoeus = add_dntoeu_value(field, ait_pkt, dntoeus)

# previous packets of this type received
else:
delta, dntoeus = {}, {}
for field, new_value in json_pkt.items():
last_value = packet_states[pkt_defn.name][field]
last_value = packet_states[pkt_defn.name]['raw'][field]
if new_value != last_value:
delta[field] = new_value
packet_states[pkt_defn.name][field] = new_value
packet_states[pkt_defn.name]['raw'][field] = new_value
dntoeus = add_dntoeu_value(field, ait_pkt, dntoeus)

return delta, dntoeus
Expand Down Expand Up @@ -799,7 +803,6 @@ def handle():
while not wsock.closed:
try:
name, delta, dntoeus, counter = session.deltas.popleft(timeout=30)
log.info(delta)
log.info('packet #{}'.format(counter))

wsock.send(json.dumps({
Expand Down Expand Up @@ -829,8 +832,9 @@ def handle():
def handle():
"""Return latest telemetry packet to client"""
for pkt_type, state in packet_states.items():
packet_states[pkt_type] = replace_datetimes(state)
packet_states[pkt_type]['raw'] = replace_datetimes(state['raw'])

log.info(packet_states)
with Sessions.current() as session:
counters = session.tlm_counters
return json.dumps({'states': packet_states,
Expand Down

0 comments on commit 05e4171

Please sign in to comment.