CCSDS Time Package
This module contains the CCSDS specific time code implementations.
- class spacepackets.ccsds.time.CcsdsTimeCodeId(value)
Bases:
IntEnumAn enumeration.
- CCS = 5
- CDS = 4
- CUC_AGENCY_EPOCH = 2
- CUC_CCSDS_EPOCH = 1
- NONE = 0
- class spacepackets.ccsds.time.CcsdsTimeProvider
Bases:
ABC- abstract as_date_time() datetime
Retrieve a
datetime.datetimewith thedatetime.timezoneset to utc.
- len
Deprecated since version 0.14.0rc1: use len_packed instead
- abstract read_from_raw(timestamp: bytes | bytearray) CcsdsTimeProvider
- class spacepackets.ccsds.time.CdsShortTimestamp(ccsds_days: int, ms_of_day: int, init_dt_unix_stamp: bool = True)
Bases:
CcsdsTimeProviderUnpacks the time datafield of the TM packet. Right now, CDS Short timeformat is used, and the size of the time stamp is expected to be seven bytes.
>>> from spacepackets.ccsds.time import CcsdsTimeCodeId >>> cds_short_now = CdsShortTimestamp.now() >>> cds_short_now.len_packed 7 >>> hex(cds_short_now.pfield[0]) '0x40'
Create a stamp from the contained values directly.
>>> zero_stamp = CdsShortTimestamp(ccsds_days=0, ms_of_day=0) >>> zero_stamp.ccsds_days 0 >>> zero_stamp.ms_of_day 0 >>> unix_zero_as_ccsds = CdsShortTimestamp(ccsds_days=convert_ccsds_days_to_unix_days(0), ms_of_day=0) # noqa: E501 >>> unix_zero_as_ccsds.ccsds_days -4383 >>> CdsShortTimestamp(0x0102, 0x03040506).pack().hex(sep=',') '40,01,02,03,04,05,06'
- CDS_SHORT_ID = 4
- TIMESTAMP_SIZE = 7
- classmethod empty(init_dt_unix_stamp: bool = True) CdsShortTimestamp
Empty instance containing only zero for all fields.
- Returns:
- classmethod from_current_time() CdsShortTimestamp
Deprecated since version 0.14.0rc1: use from_now instead
- classmethod from_date_time(dt: datetime) CdsShortTimestamp
Deprecated since version 0.24.0: use from_datetime instead
- classmethod from_datetime(dt: datetime) CdsShortTimestamp
- classmethod from_now() CdsShortTimestamp
Returns a seven byte CDS short timestamp with the current time.
Deprecated since version 0.24.0: use now instead
- classmethod from_unix_days(unix_days: int, ms_of_day: int) CdsShortTimestamp
- classmethod now() CdsShortTimestamp
Returns a seven byte CDS short timestamp with the current time.
- read_from_raw(data: bytes | bytearray) CdsShortTimestamp
Updates the instance from a given raw CDS short timestamp
- Parameters:
data
- Returns:
- classmethod unpack(data: bytes | bytearray) CdsShortTimestamp
Common Time Submodule
- class spacepackets.ccsds.time.common.CcsdsTimeCodeId(value)
Bases:
IntEnumAn enumeration.
- CCS = 5
- CDS = 4
- CUC_AGENCY_EPOCH = 2
- CUC_CCSDS_EPOCH = 1
- NONE = 0
- class spacepackets.ccsds.time.common.CcsdsTimeProvider
Bases:
ABC- abstract as_date_time() datetime
Retrieve a
datetime.datetimewith thedatetime.timezoneset to utc.
- len
Deprecated since version 0.14.0rc1: use len_packed instead
- abstract read_from_raw(timestamp: bytes | bytearray) CcsdsTimeProvider
- spacepackets.ccsds.time.common.DAYS_CCSDS_TO_UNIX = -4383
The day offset to convert from CCSDS days to UNIX days.
- spacepackets.ccsds.time.common.convert_ccsds_days_to_unix_days(ccsds_days: int) int
Convert CCSDS days to Unix days.
CCSDS epoch: 1958-01-01 00:00:00. Unix epoch: 1970-01-01 00:00:00.
- spacepackets.ccsds.time.common.convert_unix_days_to_ccsds_days(unix_days: int) int
Convert Unix days to CCSDS days.
CCSDS epoch: 1958-01-01 00:00:00. Unix epoch: 1970-01-01 00:00:00.
- spacepackets.ccsds.time.common.read_p_field(p_field: int) CcsdsTimeCodeId
Read the p field and return the CCSDS Time Code ID.
- Parameters:
p_field
- Returns:
- Raises:
IndexError – P field has invalid value
CDS Time Submodule
- class spacepackets.ccsds.time.cds.CdsShortTimestamp(ccsds_days: int, ms_of_day: int, init_dt_unix_stamp: bool = True)
Bases:
CcsdsTimeProviderUnpacks the time datafield of the TM packet. Right now, CDS Short timeformat is used, and the size of the time stamp is expected to be seven bytes.
>>> from spacepackets.ccsds.time import CcsdsTimeCodeId >>> cds_short_now = CdsShortTimestamp.now() >>> cds_short_now.len_packed 7 >>> hex(cds_short_now.pfield[0]) '0x40'
Create a stamp from the contained values directly.
>>> zero_stamp = CdsShortTimestamp(ccsds_days=0, ms_of_day=0) >>> zero_stamp.ccsds_days 0 >>> zero_stamp.ms_of_day 0 >>> unix_zero_as_ccsds = CdsShortTimestamp(ccsds_days=convert_ccsds_days_to_unix_days(0), ms_of_day=0) # noqa: E501 >>> unix_zero_as_ccsds.ccsds_days -4383 >>> CdsShortTimestamp(0x0102, 0x03040506).pack().hex(sep=',') '40,01,02,03,04,05,06'
- CDS_SHORT_ID = 4
- TIMESTAMP_SIZE = 7
- classmethod empty(init_dt_unix_stamp: bool = True) CdsShortTimestamp
Empty instance containing only zero for all fields.
- Returns:
- classmethod from_current_time() CdsShortTimestamp
Deprecated since version 0.14.0rc1: use from_now instead
- classmethod from_date_time(dt: datetime) CdsShortTimestamp
Deprecated since version 0.24.0: use from_datetime instead
- classmethod from_datetime(dt: datetime) CdsShortTimestamp
- classmethod from_now() CdsShortTimestamp
Returns a seven byte CDS short timestamp with the current time.
Deprecated since version 0.24.0: use now instead
- classmethod from_unix_days(unix_days: int, ms_of_day: int) CdsShortTimestamp
- classmethod now() CdsShortTimestamp
Returns a seven byte CDS short timestamp with the current time.
- read_from_raw(data: bytes | bytearray) CdsShortTimestamp
Updates the instance from a given raw CDS short timestamp
- Parameters:
data
- Returns:
- classmethod unpack(data: bytes | bytearray) CdsShortTimestamp
- class spacepackets.ccsds.time.cds.LenOfDaysSegment(value)
Bases:
IntEnumAn enumeration.
- DAYS_16_BITS = 0
- DAYS_24_BITS = 1
- spacepackets.ccsds.time.cds.len_of_day_seg_from_pfield(pfield: int) LenOfDaysSegment
Extract length of day segment from the pfield