-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Problem: I2CExplore can't include Utils because it'll cause circular dependency as below: I2CExplorer -> ConfigValidator -> Utils -> I2CExplorer To avoid this, move I2CAddr as a separate library, the graph more or less becomes: I2CAddr -> ConfigValidator -> Utils -> I2CExplorer Reviewed By: somasun Differential Revision: D62396774 fbshipit-source-id: d54f56cd0080b868b4568ad1cf90d315737c0f52
- Loading branch information
1 parent
a9496b0
commit 158a52f
Showing
4 changed files
with
68 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include <fmt/format.h> | ||
#include <re2/re2.h> | ||
|
||
namespace facebook::fboss::platform::platform_manager { | ||
|
||
inline const re2::RE2 kI2cAddrRe{"0x[0-9a-f]{2}"}; | ||
|
||
struct I2cAddr { | ||
public: | ||
explicit I2cAddr(uint16_t addr) : addr_(addr) {} | ||
explicit I2cAddr(const std::string& addr) | ||
: addr_(std::stoi(addr, nullptr, 16 /* base */)) { | ||
if (!re2::RE2::FullMatch(addr, kI2cAddrRe)) { | ||
throw std::invalid_argument("Invalid i2c addr: " + addr); | ||
} | ||
} | ||
bool operator==(const I2cAddr& b) const { | ||
return addr_ == b.addr_; | ||
} | ||
// Returns string in the format 0x0f | ||
std::string hex2Str() const { | ||
return fmt::format("{:#04x}", addr_); | ||
} | ||
// Returns string in the format 000f | ||
std::string hex4Str() const { | ||
return fmt::format("{:04x}", addr_); | ||
} | ||
// Returns integer | ||
uint16_t raw() const { | ||
return addr_; | ||
} | ||
|
||
private: | ||
uint16_t addr_{0}; | ||
}; | ||
|
||
} // namespace facebook::fboss::platform::platform_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters