22 #pragma GCC diagnostic push 23 #pragma GCC diagnostic ignored "-Wignored-attributes" 24 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 25 #include <Eigen/Dense> 26 #pragma GCC diagnostic pop 35 struct iio_channel_info;
72 class IIO :
public std::vector<IIODevice> {
81 std::ifstream nameFile((devicePath+
"/name").c_str());
98 vector<std::string> excluded;
99 excluded.push_back(
".");
100 excluded.push_back(
"..");
108 for (
unsigned int i=0; i<ds.size(); i++) {
109 std::string devicePath(iioDir);
113 if (
findChipName(devicePath).find(chipName)!=std::string::npos) {
114 push_back(
IIODevice(devicePath, chipName));
115 operator[](
size()-1).scanDevice();
140 chCnt+=
operator[](i).getChCnt();
148 printf(
"Device %d\t",i);
149 operator[](i).printInfo();
162 std::stringstream deviceDetail;
163 deviceDetail<<
" Device "<<i;
193 uint frameSize=operator[](0).getChFrameSize();
197 if (
operator[](i).getChFrameSize() != frameSize)
221 template<
typename TYPE>
226 std::stringstream msg;
227 msg<<
"The provided array type has "<<
sizeof(TYPE)<<
" bytes per sample, where as the IIO devices have "<<
getChFrameSize()<<
" bytes per sample\n";
231 if (array.rows()!=N*operator[](0).getChCnt() && array.cols()!=
getDeviceCnt())
232 array.resize(N*
operator[](0).getChCnt(),
getDeviceCnt());
240 template<
typename TYPE>
244 return array.rows()/operator[](0).getChCnt();
253 template<
typename TYPE>
254 int read(
uint N,
const Eigen::Array<TYPE, Eigen::Dynamic, Eigen::Dynamic> &array) {
256 std::stringstream msg;
257 msg<<
"The provided array type has "<<
sizeof(TYPE)<<
" bytes per sample, where as the IIO devices have "<<
getChFrameSize()<<
" bytes per sample\n";
260 if (array.rows()!=N*operator[](0).getChCnt() && array.cols()>
getDeviceCnt()) {
261 std::stringstream msg;
262 msg<<
"The provided array is not shaped correctly, size=("<<array.rows()<<
", "<<array.cols()<<
") but size=(N*device ch cnt, device cnt) is required, where size=("<<N*
getChCnt()<<
", "<<
getDeviceCnt()<<
")\n";
269 if (toRead>N) toRead=
N;
270 for (
int i=0; i <array.cols(); i++) {
271 int ret=operator[](i).read(toRead, (
void*)array.col(i).data());
273 std::stringstream msg;
274 msg<<
"Couldn't read the desired number of samples from device "<<i<<std::endl;
294 operator[](i).enable(enable);
304 int chBufCnt=operator[](0).getChannelBufferCnt();
306 if (
operator[](i).getChannelBufferCnt()!=chBufCnt)
319 chBufCnt=operator[](0).setChannelBufferCnt(chBufCnt);
321 if (
operator[](i).setChannelBufferCnt(chBufCnt)!=chBufCnt){
int getChannelBufferCnt()
static const char * iioDir
The sys fs location of iio devcies "/sys/bus/iio/devices/".
#define IIO_FRAEMSIZE_MISMATCH_ERROR
The channel frame sizes differ between devices.
virtual int evaluateError(int errorNum)
int getDevFrameSize(void)
#define IIO_BAD_DEVICE_NAME_ERROR
Error when the specified device name is bad or can't be found.
int setChannelBufferCnt(int chBufCnt)
int findDevicesByChipName(std::string chipName)
int getReadArraySampleCount(Eigen::Array< TYPE, Eigen::Dynamic, Eigen::Dynamic > &array)
#define NO_ERROR
There is no error.
int read(uint N, const Eigen::Array< TYPE, Eigen::Dynamic, Eigen::Dynamic > &array)
#define IIODEVICE_CHBUFCNT_ERROR
One of the devices has a different buffer size to the other devices.
The iio_channel_info structure is external.
#define IIODEVICE_READ_ERROR
There was an error whilst reading from a device.
int findAll(const std::vector< std::string > &dontInclude)
int getReadArray(uint N, Eigen::Array< TYPE, Eigen::Dynamic, Eigen::Dynamic > &array)
#define IIO_ARRAY_FRAME_MISMATCH_ERROR
The sample type of the provided array doesn't match the sample type of the devices.
std::string findChipName(std::string devicePath)
#define IIO_ARRAY_SIZE_MISMATCH_ERROR
The provided array doesn't match the number of channels and requested samples.
#define IIO_NODEVICES_ERROR
There are no devices.
void keepWithPattern(const std::string pattern)