Skip to content

Commit

Permalink
Add max 32 bit int as max packet counter (#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 62b97e4 commit 58d6801
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ def get_packet_delta(pkt_defn, packet):

# previous packets of this type received
else:
counters[pkt_defn.name] += 1
count = counters[pkt_defn.name]
count = count + 1 if count < 2**31 - 1 else 0
counters[pkt_defn.name] = count
delta, dntoeus = {}, {}
for field, new_value in json_pkt.items():
last_value = packet_states[pkt_defn.name][field]
Expand Down Expand Up @@ -774,6 +776,7 @@ def handle():
delta, dntoeus, counter = get_packet_delta(pkt_defn, data)
delta = replace_datetimes(delta)
log.info(delta)
log.info('Packet #{}'.format(counter))

wsock.send(json.dumps({
'packet': pkt_defn.name,
Expand Down
6 changes: 4 additions & 2 deletions ait/gui/static/js/ait/tlm.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,11 @@ class TelemetryStream
checkCounter (packetName, counter) {
// returns true if counter is as expected, false if not
let lastCounter = this._counters[packetName]
if ( counter == lastCounter + 1 ) {
if ( counter == lastCounter + 1) {
return true
}
} else if ( lastCounter == Math.pow(2, 31) - 1 && counter == 0 ) {
return true
}
console.log('counter mismatch: had ' + lastCounter + ' , got ' + counter)
return false
}
Expand Down

0 comments on commit 58d6801

Please sign in to comment.