Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
 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()
Esempio n. 5
0
 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()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
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
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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()
Esempio n. 13
0
 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)
Esempio n. 14
0
 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()
Esempio n. 15
0
 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
Esempio n. 16
0
 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)
Esempio n. 17
0
 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)
Esempio n. 18
0
 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
Esempio n. 19
0
 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)
Esempio n. 20
0
 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
Esempio n. 21
0
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
Esempio n. 22
0
 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
Esempio n. 23
0
 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)
Esempio n. 24
0
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
Esempio n. 25
0
 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
Esempio n. 26
0
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
Esempio n. 27
0
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
Esempio n. 28
0
 def __init__(self, binaryString=None):
     """default constructor"""
     BinaryUnit.__init__(self, binaryString, TC_SEGMENT_HEADER_BYTE_SIZE,
                         TC_SEGMENT_HEADER_ATTRIBUTES)
Esempio n. 29
0
 def __init__(self, binaryString=None):
   """default constructor"""
   BinaryUnit.__init__(self,
                       binaryString,
                       TC_SEGMENT_HEADER_BYTE_SIZE,
                       TC_SEGMENT_HEADER_ATTRIBUTES)
Esempio n. 30
0
 def __init__(self, binaryString=None):
   """default constructor"""
   BinaryUnit.__init__(self,
                       binaryString,
                       CLCW_BYTE_SIZE,
                       CLCW_ATTRIBUTES)
Esempio n. 31
0
 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)
Esempio n. 32
0
 def __init__(self, binaryString=None):
     """default constructor"""
     BinaryUnit.__init__(self, binaryString, CLCW_BYTE_SIZE,
                         CLCW_ATTRIBUTES)
Esempio n. 33
0
 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)
Esempio n. 34
0
 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)
Esempio n. 35
0
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