MCPcopy Create free account
hub / github.com/PiSCSI/piscsi / Init

Method Init

cpp/hal/sbc_version.cpp:77–107  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Determine which version of single board computer (Pi) is being used based upon the device tree model string. ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

75//
76//---------------------------------------------------------------------------
77void SBC_Version::Init()
78{
79 ifstream input_stream(SBC_Version::m_device_tree_model_path);
80
81 if (input_stream.fail()) {
82#if defined(__x86_64__) || defined(__X86__)
83 // We expect this to fail on x86
84 spdlog::warn("Detected " + GetAsString());
85 sbc_version = sbc_version_type::sbc_unknown;
86 return;
87#else
88 spdlog::error("Failed to open " + SBC_Version::m_device_tree_model_path + ". Are you running as root?");
89 throw invalid_argument("Failed to open /proc/device-tree/model");
90#endif
91 }
92
93 stringstream str_buffer;
94 str_buffer << input_stream.rdbuf();
95 const string device_tree_model = str_buffer.str();
96
97 for (const auto& [key, value] : proc_device_tree_mapping) {
98 if (device_tree_model.starts_with(key)) {
99 sbc_version = value;
100 spdlog::info("Detected " + GetAsString());
101 return;
102 }
103 }
104
105 sbc_version = sbc_version_type::sbc_raspberry_pi_4;
106 spdlog::error("Unable to determine single board computer type. Defaulting to Raspberry Pi 4");
107}
108
109bool SBC_Version::IsRaspberryPi()
110{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected