Пример #1
0
 def _decode_(self, decodePacket):
     """Decodes the provided packet snippet into a signed integer of length self.size.
     
     decodePacket -- the ordered list of bytes to be converted into an unsigned integer.
     """
     twosComplementInteger = utilities.bytesToUnsignedInteger(decodePacket)
     return utilities.twosComplementToSignedInteger(twosComplementInteger, self.bitSize)
Пример #2
0
 def _decode_(self, decodePacket):
     """Decodes the provided packet snippet into an unsigned integer ostensibly representing a checksum.
     
     decodePacket -- the ordered list of bytes to be converted into an unsigned integer.
     
     Note that no checksum validation is performed here.
     """
     return utilities.bytesToUnsignedInteger(decodePacket)
Пример #3
0
 def _decode_(self, decodePacket):
     """Decodes the provided packet snippet into a dictionary of bitfield names and values.
     
     decodePacket -- the ordered list of bytes to be converted into a dictionary.
     """
     inputValue = utilities.bytesToUnsignedInteger(decodePacket)
     decodeDictionary = {}   #stores bitName:bitValue pairs
     for bitPosition in self.bitPositionBitNameDictionary:   #iterate over all bit positions in bitfield definition
         bitName = self.bitPositionBitNameDictionary[bitPosition]    #grab bit name
         bitValue = bool(inputValue&(1<<bitPosition))    #test if bit in inputValue is set
         decodeDictionary.update({bitName:bitValue})    #update the decode dictionary
     return decodeDictionary
Пример #4
0
 def _decode_(self, decodePacket):
     """Decodes the provided packet snippet into a fixed point signed decimal.
     
     decodePacket -- the ordered list of bytes to be converted into a fixed point decimal.
     """
     twosComplementRepresentation = utilities.bytesToUnsignedInteger(decodePacket)
     twosComplementRepresentation = twosComplementRepresentation&(2**(self.bitSize) - 1) #mask off any unwanted bits
     if self.integerBits > 0: #signed value
         signedInteger = utilities.twosComplementToSignedInteger(twosComplementRepresentation, self.bitSize)
     else:   #no integer bits, unsigned value
         signedInteger = twosComplementRepresentation
     bitShiftedValue = float(signedInteger)/(2**self.fractionalBits)
     return bitShiftedValue
Пример #5
0
 def _decode_(self, decodePacket):
     """Decodes the provided packet snippet into an unsigned integer.
     
     decodePacket -- the ordered list of bytes to be converted into an unsigned integer.
     """
     return utilities.bytesToUnsignedInteger(decodePacket)