From c28ec462e2c939623c4ea2a3c31cc40c0a6735a0 Mon Sep 17 00:00:00 2001 From: Anna Waldron Date: Wed, 2 Oct 2019 10:57:40 -0700 Subject: [PATCH] Send new dntoeu values from backend to frontend (#105) --- ait/gui/__init__.py | 48 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/ait/gui/__init__.py b/ait/gui/__init__.py index a251e07b..1fe3974c 100644 --- a/ait/gui/__init__.py +++ b/ait/gui/__init__.py @@ -681,31 +681,57 @@ def handle(): pass +def add_dntoeu_value(field, packet, dntoeus): + """ + Returns dntoeu value of field from packet. + + Params: + field: str name of field to evaluate + packet: AIT Packet + dntoeus: dict of dntoeu values to add to + """ + field_defn = packet._defn.fieldmap[field] + if field_defn.dntoeu: + dntoeus[field] = field_defn.dntoeu.eval(packet) + + return dntoeus + + last_packets = { } def get_packet_delta(pkt_defn, packet): """ Keeps track of last packets recieved of all types recieved - and checks returns only fields that have changed since last - packet. + and returns only fields that have changed since last packet. Params: pkt_defn: Packet definition - packet: Packet in JSON format + packet: Binary packet data Returns: delta: JSON of packet fields that have changed """ + ait_pkt = ait.core.tlm.Packet(pkt_defn, data=packet) + json_pkt = ait_pkt.toJSON() + + # first packet of this type if pkt_defn.name not in last_packets: - last_packets[pkt_defn.name] = packet - delta = packet + last_packets[pkt_defn.name] = json_pkt + delta = json_pkt + + dntoeus = {} + for field, value in json_pkt.items(): + dntoeus = add_dntoeu_value(field, ait_pkt, dntoeus) + + # previous packets of this type received else: - delta = { } - for field, new_value in packet.items(): + delta, dntoeus = {}, {} + for field, new_value in json_pkt.items(): last_value = last_packets[pkt_defn.name][field] if new_value != last_value: delta[field] = new_value last_packets[pkt_defn.name][field] = new_value + dntoeus = add_dntoeu_value(field, ait_pkt, dntoeus) - return delta + return delta, dntoeus @App.route('/tlm/realtime') @@ -730,12 +756,12 @@ def handle(): pkt_defn = v break - json_pkt = ait.core.tlm.Packet(pkt_defn, data=data).toJSON() - delta = get_packet_delta(pkt_defn, json_pkt) + delta, dntoeus = get_packet_delta(pkt_defn, data) wsock.send(json.dumps({ 'packet': pkt_defn.name, - 'data': delta + 'data': delta, + 'dntoeus': dntoeus })) except IndexError: