blob: 375fd42126bbc419d28c624fc213f56231417974 [file] [log] [blame]
#include "tlbmc/hal/sysfs/i2c.h"
#include <cstdint>
#include <string>
#include "absl/strings/str_cat.h"
#include "hal_common_config.pb.h"
namespace milotic_tlbmc {
boost::filesystem::path I2cSysfs::GetBusPath(uint64_t bus) const {
boost::filesystem::path path(config_.i2c_sysfs_path);
path /= "i2c-";
return absl::StrCat(path.string(), bus);
}
bool I2cSysfs::IsDevicePresent(const HalCommonConfig& config) const {
boost::filesystem::path path = GetBusPath(config.bus());
path /= GetDeviceDirectoryName(config);
return boost::filesystem::exists(path);
}
std::string I2cSysfs::GetDeviceDirectoryName(
const HalCommonConfig& config) const {
return absl::StrCat(config.bus(), "-",
absl::Hex(config.address(), absl::kZeroPad4));
}
} // namespace milotic_tlbmc