dbus-sdr: sensorcommands: Add a basic handler to set sensor readings

FEATURE_DYNAMIC_SENSORS_WRITE is used to enable the set sensor handler.
To enable the sensor writes add `--enable-dynamic_sensors_write` to the
compile flags.

Convert sensor writes to double from raw IPMI value.
The 8-bit value in the IPMI Set Sensor command is not a
literal value. It is a floating point value encoded using
the m, b, rExp, and bExp that are reported in the SDR.

Convert the raw 8-bit value to a floating point value according to the
IPMI spec. This implementation only supports linear sensors.
sdr_convert_sensor_reading() from ipmitool is a good reference should
you need a more feature complete implementation in the future [1].

  [1]: https://github.com/ipmitool/ipmitool/blob/42a023ff0726c80e8cc7d30315b987fe568a981d/lib/ipmi_sdr.c#L360

Interpreting bSigned correctly if IPMI indicates the byte is signed
Breaking up the complicated math expression into multiple lines
Making sure std::pow uses the correct type override of double
Adding the input byte to the logging

Tested:

// Before
$ ipmitool sensor list | grep fan
fan0_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan1_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan2_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan3_pwm         | 68.600     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan4_pwm         | 89.768     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan0_tach        | 8428.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan1_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan2_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan3_tach        | 8918.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan4_tach        | 8134.000   | RPM        | ok    | na        | na        | na        | na        | na        | na

// After setting fan3 to 0 pwm.
$ ipmitool sensor list | grep fan
fan0_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan1_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan2_pwm         | 69.776     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan3_pwm         | 3.920      | unspecified | ok    | na        | na        | na        | na        | na        | na
fan4_pwm         | 89.768     | unspecified | ok    | na        | na        | na        | na        | na        | na
fan0_tach        | 8428.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan1_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan2_tach        | 8330.000   | RPM        | ok    | na        | na        | na        | na        | na        | na
fan3_tach        | 0.000      | RPM        | ok    | na        | na        | na        | na        | na        | na
fan4_tach        | 8134.000   | RPM        | ok    | na        | na        | na        | na        | na        | na       | na        | na        | na        | na

Signed-off-by: Peter Lundgren <peterlundgren@google.com>
Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: Ib26c443480382224092a83662e060df3b759da5c
Signed-off-by: Willy Tu <wltu@google.com>
2 files changed