-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSensor.cpp
58 lines (52 loc) · 2 KB
/
Sensor.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
// Copyright [2018] <Alexander Hurd>"
#include "SoapySidekiq.hpp"
std::vector<std::string> SoapySidekiq::listSensors(void) const {
std::vector<std::string> sensors;
sensors.push_back("temperature");
sensors.push_back("acceleration");
return sensors;
}
SoapySDR::ArgInfo SoapySidekiq::getSensorInfo(const std::string &key) const {
return SoapySDR::Device::getSensorInfo(key);
}
std::string SoapySidekiq::readSensor(const std::string &key) const {
if (key.compare("temperature")) {
int8_t temp = 0;
if (skiq_read_temp(card, &temp) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_temp (card %i)", card);
}
return std::to_string(temp);
}
bool supported = false;
if (key.compare("acceleration")) {
if (!skiq_is_accel_supported(card, &supported)) {
SoapySDR_logf(SOAPY_SDR_WARNING, "Acceleration not supported by card %i", card);
return "{}";
}
if (skiq_write_accel_state(card, 1) != 0) {// enable
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_write_accel_state (card %i)", card);
return "{}";
}
int16_t x_data = 0;
int16_t y_data = 0;
int16_t z_data = 0;
if (skiq_read_accel(card, &x_data, &y_data, &z_data) != 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_read_accel (card %i)", card);
return "{}";
}
if (skiq_write_accel_state(card, 0) != 0) { // disable
SoapySDR_logf(SOAPY_SDR_ERROR, "Failure: skiq_write_accel_state (card %i)", card);
return "{}";
};
std::stringstream ss;
ss << "{\"x\":" << x_data << " \"y\":" << y_data << " \"z\":" << z_data << "}"; // json format
return ss.str();
}
return SoapySDR::Device::readSensor(key);
}
std::vector<std::string> SoapySidekiq::listSensors(const int direction, const size_t channel) const {
return SoapySDR::Device::listSensors(direction, channel);
}
std::string SoapySidekiq::readSensor(const int direction, const size_t channel, const std::string &key) const {
return SoapySDR::Device::readSensor(direction, channel, key);
}