Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a device tree reader for ip-devices #838

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/include/villas/kernel/devices/ip_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class IpDevice : public PlatformDevice {
IpDevice() = delete;
IpDevice(
const std::filesystem::path valid_path) //! Dont allow unvalidated paths
: PlatformDevice(valid_path) {};
: PlatformDevice(valid_path){};

public:
size_t addr() const;
std::string ip_name() const;

static std::vector<villas::kernel::devices::IpDevice>
from_directory(std::filesystem::path devices_directory);
};

} // namespace devices
Expand Down
4 changes: 2 additions & 2 deletions common/include/villas/kernel/devices/platform_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class PlatformDevice : public Device {
public:
PlatformDevice(const std::filesystem::path path)
: PlatformDevice(path, std::filesystem::path(PROBE_DEFAULT),
path / std::filesystem::path(OVERRIDE_DEFAULT)) {};
path / std::filesystem::path(OVERRIDE_DEFAULT)){};

PlatformDevice(const std::filesystem::path path,
const std::filesystem::path probe_path,
const std::filesystem::path override_path)
: m_path(path), m_probe_path(probe_path),
m_override_path(override_path) {};
m_override_path(override_path){};

// Implement device interface
std::optional<std::unique_ptr<Driver>> driver() const override;
Expand Down
20 changes: 20 additions & 0 deletions common/lib/kernel/devices/ip_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <villas/exceptions.hpp>
#include <villas/kernel/devices/ip_device.hpp>
#include <villas/utils.hpp>

using villas::kernel::devices::IpDevice;

Expand Down Expand Up @@ -52,3 +53,22 @@ bool IpDevice::is_path_valid(const std::filesystem::path unsafe_path) {

return true;
}

std::vector<villas::kernel::devices::IpDevice>
IpDevice::from_directory(std::filesystem::path devices_directory) {
std::vector<villas::kernel::devices::IpDevice> devices;

const std::vector<std::string> devicetree_names =
villas::utils::read_names_in_directory(devices_directory);

for (auto devicetree_name : devicetree_names) {
auto path_to_device =
devices_directory / std::filesystem::path(devicetree_name);
try {
auto device = villas::kernel::devices::IpDevice::from(path_to_device);
devices.push_back(device);
} catch (std::runtime_error &e) {
}
}
return devices;
}