PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
vendors.cpp
Go to the documentation of this file.
1
3
4#include "profinet/vendors.h"
5
6#include <algorithm>
7#include <cstdio>
8#include <format>
9
11
12namespace profinet
13{
14
15std::optional<std::string> LookupVendor(std::uint16_t vendorId)
16{
17 const auto* begin = detail::kVendorTable;
19 const auto* const it = std::lower_bound(begin, end, vendorId,
20 [](const auto& entry, std::uint16_t id)
21 { return entry.first < id; });
22 if (it != end && it->first == vendorId)
23 {
24 return std::string(it->second);
25 }
26 return std::nullopt;
27}
28
29std::string GetVendorName(std::uint16_t vendorId)
30{
31 if (auto name = LookupVendor(vendorId))
32 {
33 return *name;
34 }
35 // {:04X} formats the vendorId as a 4-digit, zero-padded hexadecimal value
36 return std::format("Unknown (0x{:04X})", vendorId);
37}
38
39} // namespace profinet
constexpr std::pair< std::uint16_t, std::string_view > kVendorTable[]
Definition vendorsData.h:19
constexpr std::size_t kVendorTableSize
std::optional< std::string > LookupVendor(std::uint16_t vendorId)
Look up a vendor name without a fallback string.
Definition vendors.cpp:15
std::string GetVendorName(std::uint16_t vendorId)
Get the vendor name for a 16-bit PROFINET vendor ID.
Definition vendors.cpp:29
Auto-generated PROFINET Vendor ID to vendor-name lookup table.
Declares PROFINET Vendor ID lookup utilities. The lookup table itself lives in vendors_data....