power-utils: Initially use i2c in updater
Create I2CDevice in updater and invoke read() in doUpdate(), that could
be used in future.
Use mocked I2CInterface in updater's unit test case.
Tested: Manually verify on Witherspoon that the i2c device is opened
and closed during PSU code update.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ie3d9f0565a2ceb000f489647a58ca967a2ef0c38
diff --git a/tools/power-utils/updater.cpp b/tools/power-utils/updater.cpp
index e26d1b0..749b5dd 100644
--- a/tools/power-utils/updater.cpp
+++ b/tools/power-utils/updater.cpp
@@ -60,6 +60,17 @@
return devicePath;
}
+std::pair<uint8_t, uint8_t> parseDeviceName(const std::string& devName)
+{
+ // Get I2C bus id and device address, e.g. 3-0068
+ // is parsed to bus id 3, device address 0x68
+ auto pos = devName.find('-');
+ assert(pos != std::string::npos);
+ uint8_t busId = std::stoi(devName.substr(0, pos));
+ uint8_t devAddr = std::stoi(devName.substr(pos + 1), nullptr, 16);
+ return {busId, devAddr};
+}
+
} // namespace internal
bool update(const std::string& psuInventoryPath, const std::string& imageDir)
@@ -79,6 +90,7 @@
}
updater.bindUnbind(false);
+ updater.createI2CDevice();
int ret = updater.doUpdate();
updater.bindUnbind(true);
return ret == 0;
@@ -231,7 +243,15 @@
int Updater::doUpdate()
{
// TODO
+ uint8_t data;
+ i2c->read(0x00, data);
return 0;
}
+void Updater::createI2CDevice()
+{
+ auto [id, addr] = internal::parseDeviceName(devName);
+ i2c = i2c::create(id, addr);
+}
+
} // namespace updater