Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
smbus_float.py 698 B
def smbus_2bytes_to_float(data):
    #PMBus Specification, part II, section 7.1
    expo = ((data & 0xf8)>>3)  #5 bit 2's complement
    if expo >= 2**4: expo-=2**5
    if expo == 1: #PK: Reference to this special case?
        expo = -7
    mantisse = ((data & 0x7)<<8) + ((data & 0xff00) >> 8) #11 bits 2's complement
    if mantisse >= 2**10: mantisse-=2**11;
    output = mantisse * 2**expo
    return output

def smbus_2bytes_to_float_exp12(data,expo=-12):
    mantisse = ((data & 0xff)<<8) + ((data & 0xff00) >> 8)
#    print(data,mantisse,expo)
    output = mantisse * 2**expo
    return output

def smbus_2bytes_to_float_exp13(data):
    return smbus_2bytes_to_float_exp12(data,expo=-13)