gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
IIOChannel.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16 */
17 #ifndef IIOCHANNEL_H_
18 #define IIOCHANNEL_H_
19 
20 #include <iostream>
21 #include <fstream>
22 #include <sstream>
23 
24 #include "Debug.H"
25 #define IIO_BAD_DEVICE_NAME_ERROR IIO_ERROR_OFFSET-1
26 #define IIO_BAD_DEVICE_TRIGGER_ERROR IIO_ERROR_OFFSET-2
27 #define IIO_BAD_CH_ARRAY_ERROR IIO_ERROR_OFFSET-3
28 #define IIODEVICE_FILE_OPEN_ERROR IIO_ERROR_OFFSET-4
29 #define IIODEVICE_NOCHANNELS_ERROR IIO_ERROR_OFFSET-5
30 #define IIODEVICE_READANDWRITE_ERROR IIO_ERROR_OFFSET-6
31 #define IIODEVICE_WRITEABLE_ERROR IIO_ERROR_OFFSET-7
32 #define IIODEVICE_OPEN_ERROR IIO_ERROR_OFFSET-8
33 #define IIODEVICE_FRAEMSIZE_MISMATCH_ERROR IIO_ERROR_OFFSET-9
34 #define IIO_FRAEMSIZE_MISMATCH_ERROR IIO_ERROR_OFFSET-9
35 #define IIO_NODEVICES_ERROR IIO_ERROR_OFFSET-10
36 #define IIO_ARRAY_FRAME_MISMATCH_ERROR IIO_ERROR_OFFSET-11
37 #define IIO_ARRAY_SIZE_MISMATCH_ERROR IIO_ERROR_OFFSET-12
38 #define IIODEVICE_READ_ERROR IIO_ERROR_OFFSET-13
39 #define IIODEVICE_ENABLEFILE_ERROR IIO_ERROR_OFFSET-14
40 #define IIODEVICE_LENGTHFILE_ERROR IIO_ERROR_OFFSET-15
41 #define IIODEVICE_CHBUFCNT_ERROR IIO_ERROR_OFFSET-16
42 #define IIODEVICE_RESIZEBUF_NEW_ERROR IIO_ERROR_OFFSET-17
43 #define IIOMMAP_ALLOCATE_ERROR IIO_ERROR_OFFSET-18
44 #define IIOMMAP_QUERY_ERROR IIO_ERROR_OFFSET-19
45 #define IIOMMAP_MMAP_ERROR IIO_ERROR_OFFSET-20
46 #define IIOMMAP_ENQUEUE_ERROR IIO_ERROR_OFFSET-21
47 #define IIOMMAP_NOINIT_ERROR IIO_ERROR_OFFSET-22
48 #define IIOMMAP_WRONGOPEN_ERROR IIO_ERROR_OFFSET-23
49 #define IIOMMAP_BLOCK_SIZE_MISMATCH_ERROR IIO_ERROR_OFFSET-24
50 
51 #ifndef uint
52 typedef unsigned int uint;
53 #endif
54 
57 class IIODebug : public Debug {
58 public:
62 #ifndef NDEBUG
63  errors[IIO_BAD_DEVICE_NAME_ERROR]=std::string("IIO: Empty or invalid device name specified for opening the device. ");
64  errors[IIO_BAD_DEVICE_TRIGGER_ERROR]=std::string("IIO: Trigger couldn't be found. ");
65  errors[IIO_BAD_CH_ARRAY_ERROR]=std::string("Problem reading scan element information for the channel array. ");
66  errors[IIODEVICE_FILE_OPEN_ERROR]=std::string("Problem opening a subfile for the device. ");
67  errors[IIODEVICE_NOCHANNELS_ERROR]=std::string("There are no channels, please scan elements first. ");
68  errors[IIODEVICE_READANDWRITE_ERROR]=std::string("This class can not read and write to different channels - YET! Please expand the functionality. ");
69  errors[IIODEVICE_WRITEABLE_ERROR]=std::string("This class can not write to channels - YET! Please expand the functionality. ");
70  errors[IIODEVICE_OPEN_ERROR]=std::string("The device couldn't be opened for reading. ");
71  errors[IIODEVICE_FRAEMSIZE_MISMATCH_ERROR]=std::string("The channels in one device have different word lengths, not able to handle this functionality YET!, please expand functionality. ");
72  errors[IIO_FRAEMSIZE_MISMATCH_ERROR]=std::string("The device's channels have different word lengths, not able to handle this functionality YET!, please expand functionality. ");
73  errors[IIO_NODEVICES_ERROR]=std::string("No devices have been found, run the method IIO::findDevicesByChipName first. ");
74  errors[IIO_ARRAY_FRAME_MISMATCH_ERROR]=std::string("The provided array has an incorrect type size. It doesn't match a single channel byte count. ");
75  errors[IIO_ARRAY_SIZE_MISMATCH_ERROR]=std::string("The provided array is not large enough or is too large to capture the specified number of samples. ");
76  errors[IIODEVICE_READ_ERROR]=std::string("Error whilst reading. ");
77  errors[IIODEVICE_ENABLEFILE_ERROR]=std::string("Error whilst trying to open the buffer enable file. ");
78  errors[IIODEVICE_LENGTHFILE_ERROR]=std::string("Error whilst trying to open the buffer length file. ");
79  errors[IIODEVICE_CHBUFCNT_ERROR]=std::string("Error one (or more) of the devices has a different DMA buffer size to the rest of the devices. The size is in the buffer/length file on the iio file system and should have the same size and channel count for all devices.");
80  errors[IIODEVICE_RESIZEBUF_NEW_ERROR]=std::string("Error couldn't malloc the required read buffer.");
81  errors[IIOMMAP_ALLOCATE_ERROR]=std::string("Error failed to allocate memory buffers using ioctl. ");
82  errors[IIOMMAP_QUERY_ERROR]=std::string("Error query ioctl for the allocated memory buffer. Did you allocate them using ioctl first ? ");
83  errors[IIOMMAP_MMAP_ERROR]=std::string("Error memory mapping the memory block. ");
84  errors[IIOMMAP_ENQUEUE_ERROR]=std::string("Error enqueueing the memory mapped memory block. ");
85  errors[IIOMMAP_NOINIT_ERROR]=std::string("Error the memory mapped IIO blocks aren't initialised, do that first. ");
86  errors[IIOMMAP_WRONGOPEN_ERROR]=std::string("Error when using MMAP, you must use the IIOMMap::open(int) method, noth the IIOMMap::open() method. ");
87  errors[IIOMMAP_BLOCK_SIZE_MISMATCH_ERROR]=std::string("Error when about to copy memory from the mmaped block to the user provided memory.\nMemory byte count mismatch. ");
88 
89 #endif
90  }
91 };
92 
95 class IIOChannel {
96 public:
97 // unsigned int offset; ///< The offset [explain this more]
98  unsigned int index;
99  std::string chName;
100  std::string chGenericName;
102  bool isSigned;
106 
112  int scanElements(std::string scanPath, uint cIndex){
113  int ret=NO_ERROR;
114  // get the index
115  std::ifstream inputF((scanPath+"/"+chName+"_index").c_str());
116  if (!inputF.good())
117  return IIODebug().evaluateError(IIODEVICE_FILE_OPEN_ERROR, " Couldn't open the index file "+scanPath+"/"+chName+"_index");
118  inputF>>index;
119  inputF.close();
120 
121  // Get the type information for this channel ...
122  // one example : "le:u16/32>>0", another example : "le:u16/32>>16"
123  std::stringstream typeInfo;
124  inputF.open((scanPath+"/"+chName+"_type").c_str()); // Using the chName_type file,
125  if (!inputF.good())
126  return IIODebug().evaluateError(IIODEVICE_FILE_OPEN_ERROR, " Couldn't open the type file "+scanPath+"/"+chName+"_type");
127  typeInfo << inputF.rdbuf(); // get all of the type info in the std::string stream
128 
129  // break the type info up into parameters.
130  std::string token(10,'\0'); // check the endian-ness
131  typeInfo.getline((char*)token.c_str(), 10, ':');
132  if (token.find("le")!=std::string::npos)
133  isLittleEndian=true;
134 
135  char signedChar, slash; // slash is for irrelevent characters like the '/' and '>'
136  typeInfo>>signedChar>>bitCnt>>slash>>deviceBitCnt>>slash>>slash>>bitShiftCnt;
137  if (signedChar=='u')
138  isSigned=false;
139  return ret;
140  }
141 
142  void printInfo(){
143  std::cout<<"Name\t\t"<<chName<<std::endl;
144  std::cout<<"Generic name\t"<<chGenericName<<std::endl;
145  //std::cout<<"Offset "<<offset<<"\t index "<<index<<std::endl;
146  std::cout<<"Index\t\t"<<index<<std::endl;
147  if (isSigned)
148  std::cout<<"signed, ";
149  else
150  std::cout<<"unsigned, ";
151  if (isLittleEndian)
152  std::cout<<"little endian"<<std::endl;
153  else
154  std::cout<<"big endian"<<std::endl;
155  std::cout<<"This channel has "<<bitCnt<<" bits, which require shifting down by "<<bitShiftCnt<<" bits."<<std::endl;
156  std::cout<<"This device has "<<deviceBitCnt<<" bits in one frame of DMA data shifting."<<std::endl;
157  }
158 
162  bool isReadCh(void){
163  if (chGenericName.find("in")!=std::string::npos)
164  return true;
165  return false;
166  }
167 };
168 
169 #endif // IIOCHANNEL_H_
bool isReadCh(void)
Definition: IIOChannel.H:162
#define IIOMMAP_ALLOCATE_ERROR
Couldn&#39;t allocate the iio memory buffers in the kernel using ioctl.
Definition: IIOChannel.H:43
#define IIODEVICE_FILE_OPEN_ERROR
Error when trying to open an IIODevice subdirectory file.
Definition: IIOChannel.H:28
#define IIODEVICE_OPEN_ERROR
Couldn&#39;t open the device.
Definition: IIOChannel.H:32
#define IIOMMAP_WRONGOPEN_ERROR
The wrong open method was called.
Definition: IIOChannel.H:48
#define IIO_FRAEMSIZE_MISMATCH_ERROR
The channel frame sizes differ between devices.
Definition: IIOChannel.H:34
#define IIO_BAD_DEVICE_TRIGGER_ERROR
Error when the specified trigger doesn&#39;t exist.
Definition: IIOChannel.H:26
#define IIOMMAP_NOINIT_ERROR
The MMapedBlocks system is not initialised.
Definition: IIOChannel.H:47
bool isSigned
Indicates whether the data is signed or unsigned.
Definition: IIOChannel.H:102
#define IIO_BAD_DEVICE_NAME_ERROR
Error when the specified device name is bad or can&#39;t be found.
Definition: IIOChannel.H:25
bool isLittleEndian
Indicates whether the channel is little endian.
Definition: IIOChannel.H:101
#define IIOMMAP_QUERY_ERROR
Couldn&#39;t query the iio device for allocated kernel memory.
Definition: IIOChannel.H:44
std::string chName
The name of each of the enabled channels.
Definition: IIOChannel.H:99
std::map< int, std::string > errors
This will contain a map between error numbers and descriptive std::strings for the errors...
Definition: Debug.H:115
IIODebug()
Definition: IIOChannel.H:61
#define NO_ERROR
There is no error.
Definition: Debug.H:33
#define IIODEVICE_ENABLEFILE_ERROR
There was an error when trying to open the buffer enable file.
Definition: IIOChannel.H:39
uint bitShiftCnt
The number of bits to shift the channel word down by to get a proper reading.
Definition: IIOChannel.H:105
#define IIODEVICE_CHBUFCNT_ERROR
One of the devices has a different buffer size to the other devices.
Definition: IIOChannel.H:41
#define IIODEVICE_READ_ERROR
There was an error whilst reading from a device.
Definition: IIOChannel.H:38
#define IIODEVICE_READANDWRITE_ERROR
Don&#39;t know how to hbandle read and write yet.
Definition: IIOChannel.H:30
unsigned int uint
Definition: Box.H:28
#define IIO_ARRAY_FRAME_MISMATCH_ERROR
The sample type of the provided array doesn&#39;t match the sample type of the devices.
Definition: IIOChannel.H:36
uint deviceBitCnt
The number of bits in one device word - this is all the channels combined into a device frame...
Definition: IIOChannel.H:104
std::string chGenericName
The generic name of each of the enabled channels.
Definition: IIOChannel.H:100
unsigned int index
The index in the interleaved stream.
Definition: IIOChannel.H:98
#define IIODEVICE_WRITEABLE_ERROR
Don&#39;t know how to write yet.
Definition: IIOChannel.H:31
#define IIO_ARRAY_SIZE_MISMATCH_ERROR
The provided array doesn&#39;t match the number of channels and requested samples.
Definition: IIOChannel.H:37
#define IIOMMAP_ENQUEUE_ERROR
Couldn&#39;t enqueue the mmaped block.
Definition: IIOChannel.H:46
Definition: Debug.H:112
void printInfo()
Definition: IIOChannel.H:142
int scanElements(std::string scanPath, uint cIndex)
Definition: IIOChannel.H:112
#define IIOMMAP_BLOCK_SIZE_MISMATCH_ERROR
The user and mmaped block sizes don&#39;t match.
Definition: IIOChannel.H:49
#define IIO_NODEVICES_ERROR
There are no devices.
Definition: IIOChannel.H:35
uint bitCnt
The number of bits in one word of data for one channel.
Definition: IIOChannel.H:103
#define IIODEVICE_NOCHANNELS_ERROR
Error when trying to open the device, but the channels aren&#39;t initialised.
Definition: IIOChannel.H:29
#define IIODEVICE_RESIZEBUF_NEW_ERROR
One of the devices has a different buffer size to the other devices.
Definition: IIOChannel.H:42
#define IIO_BAD_CH_ARRAY_ERROR
Error when the channel array can&#39;t be built or populated.
Definition: IIOChannel.H:27
#define IIOMMAP_MMAP_ERROR
Couldn&#39;t execute mmap.
Definition: IIOChannel.H:45
unsigned int uint
The uint type definition.
Definition: IIOChannel.H:52
#define IIODEVICE_FRAEMSIZE_MISMATCH_ERROR
The frame sizes differ between channels on one device.
Definition: IIOChannel.H:33
#define IIODEVICE_LENGTHFILE_ERROR
There was an error when trying to open the buffer length file.
Definition: IIOChannel.H:40
gtkIOStream: /tmp/gtkiostream/include/IIO/IIOChannel.H Source File
GTK+ IOStream  Beta