Skip to content
Snippets Groups Projects
Commit 46184797 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

Ability to get unix timestamp from timecode

parent 51ea1874
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ from edos.ccsds import ( ...@@ -21,7 +21,7 @@ from edos.ccsds import (
GROUP_STANDALONE GROUP_STANDALONE
) )
from edosl0util.timecode import cds_stamp from edosl0util.timecode import cds_stamp, cds_to_timestamp
class BaseStruct(c.BigEndianStructure): class BaseStruct(c.BigEndianStructure):
...@@ -52,8 +52,13 @@ class AquaCucTimecode(BaseStruct): ...@@ -52,8 +52,13 @@ class AquaCucTimecode(BaseStruct):
] ]
EPOCH = datetime(1958, 1, 1) EPOCH = datetime(1958, 1, 1)
EPOCH_SECS = (EPOCH - datetime(1970, 1, 1)).total_seconds()
SUB_SECOND_UNITS = 15.2 SUB_SECOND_UNITS = 15.2
def astimestamp(self):
tc = self.timecode
return cds_to_timestamp(tc.days, tc.milliseconds, tc.microseconds, self.EPOCH_SECS)
def asdatetime(self): def asdatetime(self):
""" """
Return converted to UTC where leap seconds are as defined in `leap_seconds`. Return converted to UTC where leap seconds are as defined in `leap_seconds`.
...@@ -75,6 +80,10 @@ class DaySegmentedTimecode(BaseStruct): ...@@ -75,6 +80,10 @@ class DaySegmentedTimecode(BaseStruct):
] ]
EPOCH = datetime(1958, 1, 1) EPOCH = datetime(1958, 1, 1)
EPOCH_SECS = (EPOCH - datetime(1970, 1, 1)).total_seconds()
def astimestamp(self):
return cds_to_timestamp(self.days, self.milliseconds, self.microseconds, self.EPOCH_SECS)
def asdatetime(self): def asdatetime(self):
return cds_stamp(self.days, self.milliseconds, self.microseconds) return cds_stamp(self.days, self.milliseconds, self.microseconds)
......
...@@ -14,8 +14,15 @@ def unixtime(dt): ...@@ -14,8 +14,15 @@ def unixtime(dt):
return (UNIX_EPOCH - dt).total_seconds() return (UNIX_EPOCH - dt).total_seconds()
def cds_to_timestamp(days, millis, micros, epoch):
"""
CDS to unix timestamp seconds.
"""
return epoch + (86400 * days) + (millis / 1000.) + (micros / 1000000)
def cds_stamp(days, millis, micros, epoch=JPSS_EPOCH): def cds_stamp(days, millis, micros, epoch=JPSS_EPOCH):
""" """
CCSDS Day Segmented timecode to UTC datetime. CCSDS Day Segmented timecode to UTC datetime.
""" """
return JPSS_EPOCH + timedelta(days=days, microseconds=1000 * millis + micros) return JPSS_EPOCH + timedelta(days=days, microseconds=1000 * millis + micros)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment