2828#include < cstdlib>
2929#include < cstring>
3030#include < iioutil/connectionprovider.h>
31- #include < iomanip>
32- #include < iostream>
3331#include < iterator>
3432#include < list>
3533#include < math.h>
3634#include < numeric>
3735#include < string>
38- #include < thread>
3936#include < vector>
4037
4138static const size_t maxAttrSize = 512 ;
@@ -252,13 +249,17 @@ double ADMTController::getChannelValue(const char *deviceName, const char *chann
252249
253250 double *scaleVal = new double (1 );
254251 int scaleRet = iio_channel_attr_read_double (channel, scaleAttr, scaleVal);
255- if (scaleRet != 0 )
252+ if (scaleRet != 0 ) {
253+ delete scaleVal;
256254 return static_cast <double >(UINT64_MAX); // return QString("Cannot read scale attribute");
255+ }
257256 scale = *scaleVal;
257+ delete scaleVal;
258258
259259 char *offsetDst = new char [maxAttrSize];
260260 iio_channel_attr_read (channel, offsetAttr, offsetDst, maxAttrSize);
261261 offsetAttrVal = std::atoi (offsetDst);
262+ delete[] offsetDst;
262263
263264 iio_buffer *iioBuffer = iio_device_create_buffer (admtDevice, bufferSize, false );
264265 if (iioBuffer == NULL )
@@ -273,14 +274,9 @@ double ADMTController::getChannelValue(const char *deviceName, const char *chann
273274 if (numBytesRead < 0 )
274275 return static_cast <double >(UINT64_MAX); // return QString("Cannot refill buffer.");
275276
276- pointerIncrement = reinterpret_cast <ptrdiff_t >(iio_buffer_step (iioBuffer));
277- pointerEnd = static_cast <int8_t *>(iio_buffer_end (iioBuffer));
278-
279277 const struct iio_data_format *format = iio_channel_get_data_format (channel);
280278 const struct iio_data_format channelFormat = *format;
281279 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 );
284280
285281 QString result;
286282 std::list<char > rawSamples;
@@ -726,7 +722,6 @@ void ADMTController::getPreCalibrationFFT(const vector<double> &PANG, vector<dou
726722void ADMTController::postcalibrate (vector<double > PANG, int cycleCount, int samplesPerCycle, bool CCW)
727723{
728724 int circshiftData = 0 ;
729- QString result = " " ;
730725
731726 /* Check CCW flag to know if array is to be reversed */
732727 if (CCW)
@@ -1220,12 +1215,12 @@ int ADMTController::getAbsAngleTurnCount(uint16_t registerValue)
12201215 // Bits 15:8: Turn count in quarter turns
12211216 uint8_t turnCount = (registerValue & 0xFF00 ) >> 8 ;
12221217
1223- if (turnCount <= 0xD5 ) {
1218+ if (turnCount <= 0xD7 ) {
12241219 // Straight binary turn count
12251220 return turnCount / 4 ; // Convert from quarter turns to whole turns
1226- } else if (turnCount == 0xD6 ) {
1221+ } else if (turnCount >= 0xD8 && turnCount <= 0xDB ) {
12271222 // Invalid turn count
1228- return -1 ;
1223+ return -10 ;
12291224 } else {
12301225 // 2's complement turn count
12311226 int8_t signedTurnCount = static_cast <int8_t >(turnCount); // Handle as signed value
@@ -1688,9 +1683,7 @@ int ADMTController::streamIO()
16881683 iio_library_get_version (&major, &minor, git_tag);
16891684 bool has_repeat = ((major * 10000 ) + minor) >= 8 ? true : false ;
16901685
1691- double *scaleAttrValue = new double (1 );
16921686 int offsetAttrValue = 0 ;
1693- char *offsetDst = new char [maxAttrSize];
16941687
16951688 if (!m_iioCtx)
16961689 return result; // Check if the context is valid
@@ -1703,13 +1696,19 @@ int ADMTController::streamIO()
17031696 iio_device_find_channel (admtDevice, channelName, isOutput); // Find the rotation channel
17041697 if (channel == NULL )
17051698 return result;
1706- iio_channel_enable (channel); // Enable the channel
1699+ iio_channel_enable (channel);
1700+ double *scaleAttrValue = new double (1 );
17071701 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;
17091704 return scaleRet;
1705+ }
1706+
1707+ char *offsetDst = new char [maxAttrSize];
17101708 iio_channel_attr_read (channel, offsetAttrName, offsetDst,
17111709 maxAttrSize); // Read the offset attribute
17121710 offsetAttrValue = atoi (offsetDst);
1711+ delete[] offsetDst;
17131712 struct iio_buffer *buffer = iio_device_create_buffer (admtDevice, samples, isCyclic); // Create a buffer
17141713
17151714 while (!stopStream) {
@@ -1739,6 +1738,7 @@ int ADMTController::streamIO()
17391738 }
17401739 }
17411740
1741+ delete scaleAttrValue;
17421742 iio_buffer_destroy (buffer);
17431743 return 0 ;
17441744}
@@ -1765,9 +1765,7 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
17651765 iio_library_get_version (&major, &minor, git_tag);
17661766 bool has_repeat = ((major * 10000 ) + minor) >= 8 ? true : false ;
17671767
1768- double *scaleAttrValue = new double (1 );
17691768 int offsetAttrValue = 0 ;
1770- char *offsetDst = new char [maxAttrSize];
17711769
17721770 if (!m_iioCtx)
17731771 return ; // result; // Check if the context is valid
@@ -1779,11 +1777,16 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
17791777 struct iio_channel *channel =
17801778 iio_device_find_channel (admtDevice, channelName, isOutput); // Find the rotation channel
17811779 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 );
17841783 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;
17861786 return ; // scaleRet;
1787+ }
1788+
1789+ char *offsetDst = new char [maxAttrSize];
17871790 iio_channel_attr_read (channel, offsetAttrName, offsetDst,
17881791 maxAttrSize); // Read the offset attribute
17891792 offsetAttrValue = atoi (offsetDst);
@@ -1831,6 +1834,9 @@ void ADMTController::bufferedStreamIO(int totalSamples, int targetSampleRate)
18311834 }
18321835
18331836 Q_EMIT streamBufferedData (bufferedValues);
1837+
1838+ delete scaleAttrValue;
1839+ delete[] offsetDst;
18341840}
18351841
18361842void ADMTController::handleStreamBufferedData (const QVector<double > &value) { streamBufferedValues = value; }
0 commit comments