Skip to content

Commit

Permalink
Merge pull request #178 from NASA-AMMOS/issue-138-start-invocations-t…
Browse files Browse the repository at this point in the history
…ime-issue

Harness start invocation should send entire time value
  • Loading branch information
nttoole committed May 24, 2022
2 parents e879a2f + ded92fd commit fe54ef1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
18 changes: 13 additions & 5 deletions ait/dsn/sle/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,7 @@ def _generate_encoded_credentials(self, current_time, random_number, username, p
The password to use to create the credentials.
'''
hash_input = HashInput()
days = (current_time - dt.datetime(1958, 1, 1)).days
millisecs = (current_time - current_time.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() * 1000
microsecs = int(round(millisecs % 1 * 1000))
millisecs = int(millisecs)
credential_time = struct.pack('!HIH', days, millisecs, microsecs)
credential_time = generate_encoded_time(current_time)

hash_input['time'] = credential_time
hash_input['randomNumber'] = random_number
Expand All @@ -444,6 +440,10 @@ def _generate_encoded_credentials(self, current_time, random_number, username, p

return encode(isp1_creds)

def _generate_encoded_time(self, datetime_):
return generate_encoded_time(datetime_)


def conn_handler(handler):
''' Handler for processing data received from the DSN into PDUs'''
hb_time = int(time.time())
Expand Down Expand Up @@ -509,3 +509,11 @@ def data_processor(handler):
continue

handler._handle_pdu(decoded_pdu)


def generate_encoded_time(datetime_):
days = (datetime_ - CCSDS_EPOCH).days
millisecs = (datetime_ - datetime_.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() * 1000
microsecs = int(round(millisecs % 1 * 1000))
millisecs = int(millisecs)
return struct.pack('!HIH', (datetime_ - CCSDS_EPOCH).days, millisecs, microsecs)
4 changes: 2 additions & 2 deletions ait/dsn/sle/raf.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ def start(self, start_time, end_time, frame_quality=2):
if start_time is None:
start_invoc['rafStartInvocation']['startTime']['undefined'] = None
else:
start_time = struct.pack('!HIH', (start_time - common.CCSDS_EPOCH).days, 0, 0)
start_time = self._generate_encoded_time(start_time)
start_invoc['rafStartInvocation']['startTime']['known']['ccsdsFormat'] = start_time

if end_time is None:
start_invoc['rafStartInvocation']['stopTime']['undefined'] = None
else:
stop_time = struct.pack('!HIH', (end_time - common.CCSDS_EPOCH).days, 0, 0)
stop_time = self._generate_encoded_time(end_time)
start_invoc['rafStartInvocation']['stopTime']['known']['ccsdsFormat'] = stop_time

start_invoc['rafStartInvocation']['requestedFrameQuality'] = frame_quality
Expand Down
4 changes: 2 additions & 2 deletions ait/dsn/sle/rcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ def start(self, start_time, end_time, spacecraft_id=None,
if start_time is None:
start_invoc['rcfStartInvocation']['startTime']['undefined'] = None
else:
start_time = struct.pack('!HIH', (start_time - common.CCSDS_EPOCH).days, 0, 0)
start_time = self._generate_encoded_time(start_time)
start_invoc['rcfStartInvocation']['startTime']['known']['ccsdsFormat'] = start_time

if end_time is None:
start_invoc['rcfStartInvocation']['stopTime']['undefined'] = None
else:
stop_time = struct.pack('!HIH', (end_time - common.CCSDS_EPOCH).days, 0, 0)
stop_time = self._generate_encoded_time(end_time)
start_invoc['rcfStartInvocation']['stopTime']['known']['ccsdsFormat'] = stop_time

req_gvcid = GvcId()
Expand Down
13 changes: 13 additions & 0 deletions ait/dsn/sle/test/common_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
import ait.dsn.sle.common as common
import datetime as dt
import struct


def test_generate_encoded_time():
datetime_ = dt.datetime(1958, 1, 1) + dt.timedelta(days=10000, milliseconds=3308, microseconds=721)
encoded_time = common.generate_encoded_time(datetime_)
days, ms, us = struct.unpack('!HIH', bytearray(encoded_time))
assert days == 10000
assert ms == 3308
assert us == 721

0 comments on commit fe54ef1

Please sign in to comment.