def renderQuantity(value): tell('- {} quantity'.format( 'signed' if value['signed'] else 'unsigned')) k = getNumber(value['scaling']) fract = value['fractionalBits'] unit = value['unit'] tell('- scaling factor: {}'.format(k)) tell('- fractional bits: {}'.format(fract)) if unit: tell('- unit: "{}"'.format(unit)) if fract == 0: lsb = ":math:`{}` {}".format(k, unit or '') tell("- LSB = {}".format(lsb)) else: b = '{2^{' + str(fract) + '}}' lsb1 = ":math:`{} / {}` {}".format(k, b, unit) c = '{' + str(pow(2, fract)) + '}' d = pow(2, fract) lsb2 = ":math:`{} / {}` {}".format(k, c, unit) lsb3 = ":math:`\\approx {}` {}".format(float(k) / d, unit) tell("- LSB = {} = {} {}".format(lsb1, lsb2, lsb3)) for const in value['constraints']: tell('- value :math:`{}` {}'.format(constrainToString(const), unit)) tell('')
def constrainToString(constrain): return '{} {}'.format(constrain['type'], str(getNumber(constrain['value'])))