MCPcopy Create free account
hub / github.com/Beckhoff/ADS / PciScan

Method PciScan

AdsLib/RouterAccess.cpp:73–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73bool RouterAccess::PciScan(const uint64_t pci_id, std::ostream &os) const
74{
75#define ROUTERADSGRP_ACCESS_HARDWARE 0x00000005
76#define ROUTERADSOFFS_A_HW_SEARCHPCIBUS 0x00000003
77
78 SearchPciBusResNew res{};
79 uint32_t bytesRead;
80
81 const auto req = SearchPciBusReq{ pci_id };
82 const auto status = device.ReadWriteReqEx2(
83 ROUTERADSGRP_ACCESS_HARDWARE, ROUTERADSOFFS_A_HW_SEARCHPCIBUS,
84 sizeof(res), &res, sizeof(req), &req, &bytesRead);
85
86 if (ADSERR_NOERR != status) {
87 LOG_ERROR(__FUNCTION__ << "(): failed with: 0x" << std::hex
88 << status << '\n');
89 return false;
90 }
91
92 if (res.slot.size() < res.nFound()) {
93 LOG_WARN(__FUNCTION__ << "(): data seems corrupt. Slot count 0x"
94 << std::hex << res.nFound()
95 << " exceeds maximum 0x"
96 << res.slot.size() << " -> truncating\n");
97 }
98
99 auto limit = std::min<size_t>(res.slot.size(), res.nFound());
100 os << "PCI devices found: " << std::dec << limit << '\n';
101 for (const auto &slot : res.slot) {
102 if (!limit--) {
103 break;
104 }
105 os << slot << '\n';
106 }
107 return !os.good();
108}
109}
110}

Callers 1

RunPCIScanFunction · 0.80

Calls 3

ReadWriteReqEx2Method · 0.80
sizeMethod · 0.80
nFoundMethod · 0.80

Tested by

no test coverage detected