-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRegistation.cpp
72 lines (59 loc) · 2.41 KB
/
Registation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright [2018] <Alexander Hurd>"
#include <unistd.h>
#include "SoapySidekiq.hpp"
#include <SoapySDR/Registry.hpp>
static std::vector<SoapySDR::Kwargs> findSidekiq(const SoapySDR::Kwargs &args) {
std::vector<SoapySDR::Kwargs> results;
uint8_t number_of_cards = 0;
uint8_t card_list[SKIQ_MAX_NUM_CARDS];
char *serial_str;
pid_t card_owner;
skiq_xport_type_t type = skiq_xport_type_auto;
/* query the list of all Sidekiq cards on the PCIe interface */
if(skiq_get_cards(type, &number_of_cards, card_list) != 0){
SoapySDR_log(SOAPY_SDR_ERROR, "Failure: skiq_get_cards");
}
for (int i = 0; i < number_of_cards; i++) {
SoapySDR::Kwargs devInfo;
bool deviceAvailable = false;
/* determine the serial number based on the card number */
if(skiq_read_serial_string(i, &serial_str) != 0){
SoapySDR_log(SOAPY_SDR_ERROR, "Failure: skiq_read_serial_string");
}
/* get card availability */
skiq_is_card_avail(i, &card_owner);
deviceAvailable = (card_owner == getpid()); // owner must be this process(pid)
if (!deviceAvailable) {
SoapySDR_logf(SOAPY_SDR_WARNING, "Unable to access card #%d, owner pid (%d)", i, card_owner);
}
std::string deviceLabel = "Epiq Solutions - Sidekiq :: " + std::string(serial_str);
devInfo["card"] = std::to_string(i);
devInfo["label"] = deviceLabel;
devInfo["available"] = deviceAvailable ? "Yes" : "No";
devInfo["product"] = "Sidekiq";
devInfo["serial"] = std::string(serial_str);
devInfo["manufacturer"] = "Epiq Solutions";
SoapySidekiq::sidekiq_devices.push_back(devInfo);
}
// filtering
for (int i = 0; i < number_of_cards; i++) {
SoapySDR::Kwargs devInfo = SoapySidekiq::sidekiq_devices[i];
if (args.count("card") != 0) {
if (args.at("card") != devInfo.at("card")) {
continue;
}
SoapySDR_logf(SOAPY_SDR_DEBUG, "Found device by card %s", devInfo.at("card").c_str());
} else if (args.count("serial") != 0) {
if (devInfo.at("serial") != args.at("serial")) {
continue;
}
SoapySDR_logf(SOAPY_SDR_DEBUG, "Found device by serial %s", args.at("serial").c_str());
}
results.push_back(SoapySidekiq::sidekiq_devices[i]);
}
return results;
}
static SoapySDR::Device *makeSidekiq(const SoapySDR::Kwargs &args) {
return new SoapySidekiq(args);
}
static SoapySDR::Registry registerSidekiq("sidekiq", &findSidekiq, &makeSidekiq, SOAPY_SDR_ABI_VERSION);