def convertToCDS(pyTime, timeFormat): """returns a CDS binary data unit representation of time""" days = int(pyTime) // UTIL.TIME.SECONDS_OF_DAY secsOfDay = pyTime - (days * UTIL.TIME.SECONDS_OF_DAY) milsOfDay = secsOfDay * 1000.0 mils = int(milsOfDay) milsFine = milsOfDay - mils if timeFormat == TIME_FORMAT_CDS1: mils = int(round(secsOfDay * 1000.0)) timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) elif timeFormat == TIME_FORMAT_CDS2: mics = int(round(secsOfDay * 1000000.0)) mils = mics // 1000 mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics elif timeFormat == TIME_FORMAT_CDS3: pics = int(round(secsOfDay * 1000000000000.0)) mils = pics // 1000000000 pics %= 1000000000 timeDU = BinaryUnit("\0" * CDS3_TIME_BYTE_SIZE, CDS3_TIME_BYTE_SIZE, CDS3_TIME_ATTRIBUTES) timeDU.pics = pics else: return None timeDU.days = days timeDU.mils = mils return timeDU
def convertToCUC(pyTime, timeFormat): """returns a CUC binary data unit representation of time""" coarseTime = int(pyTime) if timeFormat == TIME_FORMAT_CUC0: timeDU = BinaryUnit("\0" * CUC0_TIME_BYTE_SIZE, CUC0_TIME_BYTE_SIZE, CUC0_TIME_ATTRIBUTES) elif timeFormat == TIME_FORMAT_CUC1: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC1_TIME_BYTE_SIZE, CUC1_TIME_BYTE_SIZE, CUC1_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x100) elif timeFormat == TIME_FORMAT_CUC2: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC2_TIME_BYTE_SIZE, CUC2_TIME_BYTE_SIZE, CUC2_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x10000) elif timeFormat == TIME_FORMAT_CUC3: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC3_TIME_BYTE_SIZE, CUC3_TIME_BYTE_SIZE, CUC3_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x1000000) elif timeFormat == TIME_FORMAT_CUC4: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC4_TIME_BYTE_SIZE, CUC4_TIME_BYTE_SIZE, CUC4_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x100000000) else: return None timeDU.coarse = coarseTime return timeDU
def convertToCUC(pyTime, fineTimeSize): """returns a CUC binary data unit representation of time""" coarseTime = int(pyTime) if fineTimeSize == 0: timeDU = BinaryUnit("\0" * CUC0_TIME_BYTE_SIZE, CUC0_TIME_BYTE_SIZE, CUC0_TIME_ATTRIBUTES) elif fineTimeSize == 1: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC1_TIME_BYTE_SIZE, CUC1_TIME_BYTE_SIZE, CUC1_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x100) elif fineTimeSize == 2: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC2_TIME_BYTE_SIZE, CUC2_TIME_BYTE_SIZE, CUC2_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x10000) elif fineTimeSize == 3: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC3_TIME_BYTE_SIZE, CUC3_TIME_BYTE_SIZE, CUC3_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x1000000) else: # fineTimeSize == 4: fineTime = pyTime - coarseTime timeDU = BinaryUnit("\0" * CUC4_TIME_BYTE_SIZE, CUC4_TIME_BYTE_SIZE, CUC4_TIME_ATTRIBUTES) timeDU.fine = int(fineTime * 0x100000000) timeDU.coarse = coarseTime return timeDU
def initAttributes(self): """hook for initializing attributes, delegates to parent class""" BinaryUnit.initAttributes(self) self.pduType = PDU_TYPE_NULL self.subType = SUB_TYPE_NULL self.field1 = FIELD1_NULL self.setDataFieldLength()
def __init__(self, binaryString=None, attributesSize2=0, attributeMap2=None): """default constructor: initialise with header size""" BinaryUnit.__init__(self, binaryString, PDU_HEADER_BYTE_SIZE, PDU_HEADER_ATTRIBUTES, attributesSize2, attributeMap2)
def createCDS(byteArray): """returns a CDS binary data unit representation of time""" # note: this function determines the timeFormat from the byteArray length, # createCCSDS is more secure if len(byteArray) == CDS1_TIME_BYTE_SIZE: return BinaryUnit(byteArray, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) elif len(byteArray) == CDS2_TIME_BYTE_SIZE: return BinaryUnit(byteArray, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) return None
def __init__(self, binaryString=None): # default constructor: initialise with header size emptyData = (binaryString == None) if emptyData: binaryString = "\0" * TC_SEGMENT_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, TC_SEGMENT_HEADER_BYTE_SIZE, TC_SEGMENT_HEADER_ATTRIBUTES)
def __init__(self, binaryString=None): # default constructor: initialise with CLCW size emptyData = (binaryString == None) if emptyData: binaryString = "\0" * CLCW_BYTE_SIZE BinaryUnit.__init__(self, binaryString, CLCW_BYTE_SIZE, CLCW_ATTRIBUTES)
def __init__(self, binaryString=None, attributesSize1=0, attributeMap1=None, attributesSize2=0, attributeMap2=None): """initialise the date structure with binaryString and attribute maps""" BinaryUnit.__init__(self, binaryString, attributesSize1, attributeMap1, attributesSize2, attributeMap2)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * TC_FRAME_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, TC_FRAME_HEADER_BYTE_SIZE, TC_FRAME_HEADER_ATTRIBUTES) self.clipToFrameLength()
def __init__(self, binaryString=None): """default constructor: initialise with header size""" # note: correct packetSize is not forced! emptyData = (binaryString == None) if emptyData: binaryString = "\0" * TM_FRAME_DU_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, TM_FRAME_DU_HEADER_BYTE_SIZE, TM_FRAME_DU_ATTRIBUTES)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * PRIMARY_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, PRIMARY_HEADER_BYTE_SIZE, PRIMARY_HEADER_ATTRIBUTES) if emptyData: self.setPacketLength()
def __init__(self, binaryString=None): """default constructor: initialise with header size""" # note: correct packetSize is not forced! emptyData = (binaryString == None) if emptyData: binaryString = "\0" * PDU_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, PDU_HEADER_BYTE_SIZE, PDU_HEADER_ATTRIBUTES) if emptyData: self.pduType = PDU_TYPE_NULL self.subType = SUB_TYPE_NULL self.field1 = FIELD1_NULL
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (TC_DU_HEADER_BYTE_SIZE + TC_CLTU_RESPONSE_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, TC_DU_HEADER_BYTE_SIZE, TC_DU_HEADER_ATTRIBUTES, TC_CLTU_RESPONSE_ATTRIBUTES) if emptyData: # CLTU response self.dataUnitType = TC_CLTU_RESPONSE_DU_TYPE self.packetSize = len(self)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (TC_DU_HEADER_BYTE_SIZE + TC_PACKET_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, TC_DU_HEADER_BYTE_SIZE, TC_DU_HEADER_ATTRIBUTES, TC_PACKET_HEADER_ATTRIBUTES) if emptyData: # AD packet / BD segment self.dataUnitType = TC_PACKET_HEADER_DU_TYPE self.packetSize = len(self)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (CCSDS.PACKET.PRIMARY_HEADER_BYTE_SIZE + TC_PACKET_DATAFIELD_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, CCSDS.PACKET.PRIMARY_HEADER_BYTE_SIZE, CCSDS.PACKET.PRIMARY_HEADER_ATTRIBUTES, TC_PACKET_DATAFIELD_HEADER_ATTRIBUTES) if emptyData: self.setPacketLength() self.packetType = CCSDS.PACKET.TC_PACKET_TYPE self.dataFieldHeaderFlag = 1
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (TC_DU_HEADER_BYTE_SIZE + TC_LINK_STATUS_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, TC_DU_HEADER_BYTE_SIZE, TC_DU_HEADER_ATTRIBUTES, TC_LINK_STATUS_ATTRIBUTES) if emptyData: # Link status self.dataUnitType = TC_LINK_STATUS_DU_TYPE self.packetSize = len(self)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (PDU_HEADER_BYTE_SIZE + TM_SCOE_SEC_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, PDU_HEADER_BYTE_SIZE, PDU_HEADER_ATTRIBUTES, TM_SCOE_SEC_HEADER_ATTRIBUTES) if emptyData: self.setDataFieldLength() self.pduType = PDU_TYPE_TM self.subType = SUB_TYPE_SCOE self.field1 = FIELD1_NULL self.structureType = TM_SCOE_STRUCTURE_TYPE
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (PDU_HEADER_BYTE_SIZE + TC_SCOE_SEC_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, PDU_HEADER_BYTE_SIZE, PDU_HEADER_ATTRIBUTES, TC_SCOE_SEC_HEADER_ATTRIBUTES) if emptyData: self.setDataFieldLength() self.pduType = PDU_TYPE_TC self.subType = SUB_TYPE_SCOE self.field1 = FIELD1_NULL self.structureType = TC_SCOE_STRUCTURE_TYPE self.telecommandOrigin = TC_ORIGIN_CCS self.telecommandEchoStatus = TC_ECHO_STATUS_OK
def __init__(self, binaryString=None, enableSecondaryHeader=False): # default constructor: initialise with primary header size emptyData = (binaryString == None) if emptyData: if enableSecondaryHeader: binaryString = "\0" * (TM_FRAME_PRIMARY_HEADER_BYTE_SIZE + TM_FRAME_SECONDARY_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, TM_FRAME_PRIMARY_HEADER_BYTE_SIZE, TM_FRAME_PRIMARY_HEADER_ATTRIBUTES, TM_FRAME_SECONDARY_HEADER_ATTRIBUTES) self.secondaryHeaderFlag = 1 else: binaryString = "\0" * TM_FRAME_PRIMARY_HEADER_BYTE_SIZE BinaryUnit.__init__(self, binaryString, TM_FRAME_PRIMARY_HEADER_BYTE_SIZE, TM_FRAME_PRIMARY_HEADER_ATTRIBUTES) self.secondaryHeaderFlag = 0 else: BinaryUnit.__init__(self, binaryString, TM_FRAME_PRIMARY_HEADER_BYTE_SIZE, TM_FRAME_PRIMARY_HEADER_ATTRIBUTES) # enable also the attributes of the secondary header # if the corresponding flag is set if self.secondaryHeaderFlag: object.__setattr__(self, "attributeMap2", TM_FRAME_SECONDARY_HEADER_ATTRIBUTES)
def convertToCDS(pyTime, hasMicro): """returns a CDS binary data unit representation of time""" # split seconds and micros secs = int(pyTime) mics = int(round((pyTime - secs) * 1000000)) # convert into CDS components days = secs / SECONDS_OF_DAY secs %= SECONDS_OF_DAY mils = (secs * 1000) + (mics / 1000) if hasMicro: mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics else: timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) timeDU.days = days timeDU.mils = mils return timeDU
def __init__(self, binaryString=None): """default constructor: initialise with header size""" emptyData = (binaryString == None) if emptyData: binaryString = "\0" * (PDU_HEADER_BYTE_SIZE + TC_SPACE_SEC_HEADER_BYTE_SIZE) BinaryUnit.__init__(self, binaryString, PDU_HEADER_BYTE_SIZE, PDU_HEADER_ATTRIBUTES, TC_SPACE_SEC_HEADER_ATTRIBUTES) if emptyData: self.setDataFieldLength() self.pduType = PDU_TYPE_TC self.subType = SUB_TYPE_SPACE self.field1 = FIELD1_NULL self.structureType = TC_SPACE_STRUCTURE_TYPE self.telecommandType = TC_TYPE_PACKET self.telecommandOrigin = TC_ORIGIN_CCS self.telecommandProtMode = TC_PROT_MODE self.ancillaryInformation = TC_ANCILLARY_INFORMATION self.telecommandEchoStatus = TC_ECHO_STATUS_OK self.sequenceFlags = TC_SEQUENCE_FLAGS_UN_SEGMENTED
def createCCSDS(byteArray, timeFormat): """returns a CDS or CUC binary data unit representation of time""" if timeFormat == TIME_FORMAT_CDS1: return BinaryUnit(byteArray, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CDS2: return BinaryUnit(byteArray, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CDS3: return BinaryUnit(byteArray, CDS3_TIME_BYTE_SIZE, CDS3_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CUC0: return BinaryUnit(byteArray, CUC0_TIME_BYTE_SIZE, CUC0_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CUC1: return BinaryUnit(byteArray, CUC1_TIME_BYTE_SIZE, CUC1_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CUC2: return BinaryUnit(byteArray, CUC2_TIME_BYTE_SIZE, CUC2_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CUC3: return BinaryUnit(byteArray, CUC3_TIME_BYTE_SIZE, CUC3_TIME_ATTRIBUTES) if timeFormat == TIME_FORMAT_CUC4: return BinaryUnit(byteArray, CUC4_TIME_BYTE_SIZE, CUC4_TIME_ATTRIBUTES) return None
def convertToCDS(pyTime, timeFormat): """returns a CDS binary data unit representation of time""" # split seconds and micros secs = int(pyTime) mics = int(round((pyTime - secs) * 1000000)) # convert into CDS components days = secs / UTIL.TIME.SECONDS_OF_DAY secs %= UTIL.TIME.SECONDS_OF_DAY mils = (secs * 1000) + (mics / 1000) if timeFormat == TIME_FORMAT_CDS1: timeDU = BinaryUnit("\0" * CDS1_TIME_BYTE_SIZE, CDS1_TIME_BYTE_SIZE, CDS1_TIME_ATTRIBUTES) elif timeFormat == TIME_FORMAT_CDS2: mics %= 1000 timeDU = BinaryUnit("\0" * CDS2_TIME_BYTE_SIZE, CDS2_TIME_BYTE_SIZE, CDS2_TIME_ATTRIBUTES) timeDU.mics = mics else: return None timeDU.days = days timeDU.mils = mils return timeDU
def __init__(self, binaryString=None): """default constructor""" BinaryUnit.__init__(self, binaryString, TC_SEGMENT_HEADER_BYTE_SIZE, TC_SEGMENT_HEADER_ATTRIBUTES)
def __init__(self, binaryString=None): """default constructor""" BinaryUnit.__init__(self, binaryString, CLCW_BYTE_SIZE, CLCW_ATTRIBUTES)
def __init__(self, binaryString=None): """default constructor: initialise with header size""" BinaryUnit.__init__(self, binaryString, TM_FRAME_DU_HEADER_BYTE_SIZE, TM_FRAME_DU_ATTRIBUTES)