diff --git a/ait/gui/__init__.py b/ait/gui/__init__.py index 0ba9dc3d..be35717a 100644 --- a/ait/gui/__init__.py +++ b/ait/gui/__init__.py @@ -682,6 +682,33 @@ def handle(): pass +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. + + Params: + pkt_defn: Packet definition + packet: Packet in JSON format + Returns: + delta: JSON of packet fields that have changed + """ + if pkt_defn.name not in last_packets: + last_packets[pkt_defn.name] = packet + delta = packet + else: + delta = { } + for field, new_value in packet.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 + + return delta + + @App.route('/tlm/realtime') def handle(): """Return telemetry packets in realtime to client""" @@ -704,9 +731,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) + wsock.send(json.dumps({ 'packet': pkt_defn.name, - 'data': ait.core.tlm.Packet(pkt_defn, data=data).toJSON() + 'data': delta })) except IndexError: