blob: d6d4547750391691d0753c22a2e971dc6ed20630 [file]
#include "tlbmc/hal/sysfs/i2c.h"
#include <cstdint>
#include <string>
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "boost/system/error_code.hpp" // NOLINT
#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);
boost::system::error_code ec;
bool exists = boost::filesystem::exists(path, ec);
if (ec) {
LOG(ERROR) << "Error checking exists for path '" << path
<< "': " << ec.message();
return false;
}
return exists;
}
std::string I2cSysfs::GetDeviceDirectoryName(
const HalCommonConfig& config) const {
return absl::StrCat(config.bus(), "-",
absl::Hex(config.address(), absl::kZeroPad4));
}
} // namespace milotic_tlbmc