28
28
#include < cstdlib>
29
29
#include < cstring>
30
30
#include < iioutil/connectionprovider.h>
31
- #include < iomanip>
32
- #include < iostream>
33
31
#include < iterator>
34
32
#include < list>
35
33
#include < math.h>
36
34
#include < numeric>
37
35
#include < string>
38
- #include < thread>
39
36
#include < vector>
40
37
41
38
static const size_t maxAttrSize = 512 ;
@@ -252,13 +249,17 @@ double ADMTController::getChannelValue(const char *deviceName, const char *chann
252
249
253
250
double *scaleVal = new double (1 );
254
251
int scaleRet = iio_channel_attr_read_double (channel, scaleAttr, scaleVal);
255
- if (scaleRet != 0 )
252
+ if (scaleRet != 0 ) {
253
+ delete scaleVal;
256
254
return static_cast <double >(UINT64_MAX); // return QString("Cannot read scale attribute");
255
+ }
257
256
scale = *scaleVal;
257
+ delete scaleVal;
258
258
259
259
char *offsetDst = new char [maxAttrSize];
260
260
iio_channel_attr_read (channel, offsetAttr, offsetDst, maxAttrSize);
261
261
offsetAttrVal = std::atoi (offsetDst);
262
+ delete[] offsetDst;
262
263
263
264
iio_buffer *iioBuffer = iio_device_create_buffer (admtDevice, bufferSize, false );
264
265
if (iioBuffer == NULL )
@@ -273,14 +274,9 @@ double ADMTController::getChannelValue(const char *deviceName, const char *chann
273
274
if (numBytesRead < 0 )
274
275
return static_cast <double >(UINT64_MAX); // return QString("Cannot refill buffer.");
275
276
276
- pointerIncrement = reinterpret_cast <ptrdiff_t >(iio_buffer_step (iioBuffer));
277
- pointerEnd = static_cast <int8_t *>(iio_buffer_end (iioBuffer));
278
-
279
277
const struct iio_data_format *format = iio_channel_get_data_format (channel);
280
278
const struct iio_data_format channelFormat = *format;
281
279
unsigned int repeat = channelFormat.repeat ;
282
- uint8_t bitLength = static_cast <uint8_t >(channelFormat.bits );
283
- size_t offset = static_cast <uint8_t >(channelFormat.shift );
284
280
285
281
QString result;
286
282
std::list<char > rawSamples;
@@ -726,7 +722,6 @@ void ADMTController::getPreCalibrationFFT(const vector<double> &PANG, vector<dou
726
722
void ADMTController::postcalibrate (vector<double > PANG, int cycleCount, int samplesPerCycle, bool CCW)
727
723
{
728
724
int circshiftData = 0 ;
729
- QString result = " " ;
730
725
731
726
/* Check CCW flag to know if array is to be reversed */
732
727
if (CCW)
@@ -1220,12 +1215,12 @@ int ADMTController::getAbsAngleTurnCount(uint16_t registerValue)
1220
1215
// Bits 15:8: Turn count in quarter turns
1221
1216
uint8_t turnCount = (registerValue & 0xFF00 ) >> 8 ;
1222
1217
1223
- if (turnCount <= 0xD5 ) {
1218
+ if (turnCount <= 0xD7 ) {
1224
1219
// Straight binary turn count
1225
1220
return turnCount / 4 ; // Convert from quarter turns to whole turns
1226
- } else if (turnCount == 0xD6 ) {
1221
+ } else if (turnCount >= 0xD8 && turnCount <= 0xDB ) {
1227
1222
// Invalid turn count
1228
- return -1 ;
1223
+ return -10 ;
1229
1224
} else {
1230
1225
// 2's complement turn count
1231
1226
int8_t signedTurnCount = static_cast <int8_t >(turnCount); // Handle as signed value
@@ -1688,9 +1683,7 @@ int ADMTController::streamIO()
1688
1683
iio_library_get_version (&major, &minor, git_tag);
1689
1684
bool has_repeat = ((major * 10000 ) + minor) >= 8 ? true : false ;
1690
1685
1691
- double *scaleAttrValue = new double (1 );
1692
1686
int offsetAttrValue = 0 ;
1693
- char *offsetDst = new char [maxAttrSize];
1694
1687
1695
1688
if (!m_iioCtx)
1696
1689
return result; // Check if the context is valid
@@ -1703,13 +1696,19 @@ int ADMTController::streamIO()
1703
1696
iio_device_find_channel (admtDevice, channelName, isOutput); // Find the rotation channel
1704
1697
if (channel == NULL )
1705
1698
return result;
1706
- iio_channel_enable (channel); // Enable the channel
1699
+ iio_channel_enable (channel);
1700
+ double *scaleAttrValue = new double (1 );
1707
1701
int scaleRet = iio_channel_attr_read_double (channel, scaleAttrName, scaleAttrValue); // Read the scale attribute
1708
- if (scaleRet != 0 )
1702
+ if (scaleRet != 0 ) {
1703
+ delete scaleAttrValue;
1709
1704
return scaleRet;
1705
+ }
1706
+
1707
+ char *offsetDst = new char [maxAttrSize];
1710
1708
iio_channel_attr_read (channel, offsetAttrName, offsetDst,
1711
1709
maxAttrSize); // Read the offset attribute
1712
1710
offsetAttrValue = atoi (offsetDst);
1711
+ delete[] offsetDst;
1713
1712
struct iio_buffer *buffer = iio_device_create_buffer (admtDevice, samples, isCyclic); // Create a buffer
1714
1713
1715
1714
while (!stopStream) {
@@ -1739,6 +1738,7 @@ int ADMTController::streamIO()
1739
1738
}
1740
1739
}
1741
1740
1741
+ delete scaleAttrValue;
1742
1742
iio_buffer_destroy (buffer);
1743
1743
return 0 ;
1744
1744
}
@@ -1765,9 +1765,7 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
1765
1765
iio_library_get_version (&major, &minor, git_tag);
1766
1766
bool has_repeat = ((major * 10000 ) + minor) >= 8 ? true : false ;
1767
1767
1768
- double *scaleAttrValue = new double (1 );
1769
1768
int offsetAttrValue = 0 ;
1770
- char *offsetDst = new char [maxAttrSize];
1771
1769
1772
1770
if (!m_iioCtx)
1773
1771
return ; // result; // Check if the context is valid
@@ -1779,11 +1777,16 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
1779
1777
struct iio_channel *channel =
1780
1778
iio_device_find_channel (admtDevice, channelName, isOutput); // Find the rotation channel
1781
1779
if (channel == NULL )
1782
- return ; // result;
1783
- iio_channel_enable (channel); // Enable the channel
1780
+ return ;
1781
+ iio_channel_enable (channel);
1782
+ double *scaleAttrValue = new double (1 );
1784
1783
int scaleRet = iio_channel_attr_read_double (channel, scaleAttrName, scaleAttrValue); // Read the scale attribute
1785
- if (scaleRet != 0 )
1784
+ if (scaleRet != 0 ) {
1785
+ delete scaleAttrValue;
1786
1786
return ; // scaleRet;
1787
+ }
1788
+
1789
+ char *offsetDst = new char [maxAttrSize];
1787
1790
iio_channel_attr_read (channel, offsetAttrName, offsetDst,
1788
1791
maxAttrSize); // Read the offset attribute
1789
1792
offsetAttrValue = atoi (offsetDst);
@@ -1831,6 +1834,9 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
1831
1834
}
1832
1835
1833
1836
Q_EMIT streamBufferedData (bufferedValues);
1837
+
1838
+ delete scaleAttrValue;
1839
+ delete[] offsetDst;
1834
1840
}
1835
1841
1836
1842
void ADMTController::handleStreamBufferedData (const QVector<double > &value) { streamBufferedValues = value; }
0 commit comments