I guess they are.
This is the function which gets called after the thread has changed the data ( m_can[i] ), the thread emits scrolltable function which ends up calling the code below:
void DATreeModel::setCanData( int nAmount, int nCount )
{
int row = rowCount();
beginInsertRows
(QModelIndex(), row, row
+ nAmount
- 1 );
// insert nAmount of rows
mutex.lock();
for( int i = 0; i < nAmount; i++ )
{
m_Data.append(m_can[i].strId);
m_Data.append(m_can[i].strTime);
m_Data.append(m_can[i].strData);
strCount.sprintf( "%i", nCount );
m_Data.append(strCount);
nCount++;
}
mutex.unlock();
endInsertRows();
}
void DATreeModel::setCanData( int nAmount, int nCount )
{
int row = rowCount();
beginInsertRows(QModelIndex(), row, row + nAmount - 1 ); // insert nAmount of rows
QMutex mutex;
mutex.lock();
for( int i = 0; i < nAmount; i++ )
{
m_Data.append(m_can[i].strId);
m_Data.append(m_can[i].strTime);
m_Data.append(m_can[i].strData);
QString strCount;
strCount.sprintf( "%i", nCount );
m_Data.append(strCount);
nCount++;
}
mutex.unlock();
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
This is the thread code :
void CanRead::run()
{
m_nCount = 0;
m_bCancelled = false;
unsigned long nMsgAmount = 1;
unsigned int iCanId = 0;
while( !m_bCancelled )
{
#ifdef __CANON_
unsigned long numMsgs = 1;
PASSTHRU_MSG *pRxMsg = NULL;
pRxMsg = theApp->GetMessageDetail( &numMsgs, 0 );
nMsgAmount = numMsgs; // store amount of messages we got
strData = "";
int index = 0;
// Read can data, store in buffer ( read say N amount and then emit? )
while ( numMsgs && !m_bCancelled )
{
mutex.lock();
szTemp = "";
m_can[index].strData = "";
iCanId = 0;
for ( int iLoop = 0; iLoop < 4; iLoop++)
{
iCanId = (iCanId << 8 ) | pRxMsg->Data[iLoop];
}
strId.sprintf( "%d", iCanId );
strCanId = strId;
QString strName
= theApp
->m_dcb.
GetMessageName( strId
);
if( strName != "" )
m_can[index].strId = strName;
else
{
if( pRxMsg->RxStatus & 0x100 )
{
m_can[index].strId.sprintf( "%X X", iCanId);
strCanId.sprintf( "%X X", iCanId );
}
else
{
m_can[index].strId.sprintf( "%03X", iCanId);
strCanId.sprintf( "%03X", iCanId );
}
}
for ( int iLoop = 4; (unsigned)iLoop < (pRxMsg->DataSize ); iLoop++)
{
szTemp.sprintf("%02X ", pRxMsg->Data[iLoop]);
m_can[index].strData += szTemp;
strData += szTemp;
}
m_can[index].strTime.sprintf("%04d", pRxMsg->Timestamp);
numMsgs--;
m_nCount++;
mutex.unlock();
} // end while ( ulNoMsgs )
#else // some dummy data for testing
QString strId
= theApp
->m_dcb.
GetMessageName( "1911" );
if( strId != "" )
m_can[0].strId = strId;
else
m_can[0].strId = "0xfea";
m_can[0].strData = "222222222222";
m_can[0].strTime = "----";
m_nCount += nMsgAmount;
strCanId = "1911";
strData = "2222222222";
#endif
// send out signal
if( nMsgAmount > 0 )
emit scrolltable( m_nCount - 2, nMsgAmount );
msleep(10);
} // end while ( true )
}
void CanRead::run()
{
m_nCount = 0;
m_bCancelled = false;
unsigned long nMsgAmount = 1;
QString szTemp = "";
unsigned int iCanId = 0;
QString strCanId = "";
QString strData = "";
QMutex mutex;
while( !m_bCancelled )
{
#ifdef __CANON_
unsigned long numMsgs = 1;
PASSTHRU_MSG *pRxMsg = NULL;
pRxMsg = theApp->GetMessageDetail( &numMsgs, 0 );
nMsgAmount = numMsgs; // store amount of messages we got
strData = "";
int index = 0;
// Read can data, store in buffer ( read say N amount and then emit? )
while ( numMsgs && !m_bCancelled )
{
mutex.lock();
szTemp = "";
m_can[index].strData = "";
iCanId = 0;
for ( int iLoop = 0; iLoop < 4; iLoop++)
{
iCanId = (iCanId << 8 ) | pRxMsg->Data[iLoop];
}
QString strId;
strId.sprintf( "%d", iCanId );
strCanId = strId;
QString strName = theApp->m_dcb.GetMessageName( strId );
if( strName != "" )
m_can[index].strId = strName;
else
{
if( pRxMsg->RxStatus & 0x100 )
{
m_can[index].strId.sprintf( "%X X", iCanId);
strCanId.sprintf( "%X X", iCanId );
}
else
{
m_can[index].strId.sprintf( "%03X", iCanId);
strCanId.sprintf( "%03X", iCanId );
}
}
for ( int iLoop = 4; (unsigned)iLoop < (pRxMsg->DataSize ); iLoop++)
{
szTemp.sprintf("%02X ", pRxMsg->Data[iLoop]);
m_can[index].strData += szTemp;
strData += szTemp;
}
m_can[index].strTime.sprintf("%04d", pRxMsg->Timestamp);
numMsgs--;
m_nCount++;
mutex.unlock();
} // end while ( ulNoMsgs )
#else // some dummy data for testing
QString strId = theApp->m_dcb.GetMessageName( "1911" );
if( strId != "" )
m_can[0].strId = strId;
else
m_can[0].strId = "0xfea";
m_can[0].strData = "222222222222";
m_can[0].strTime = "----";
m_nCount += nMsgAmount;
strCanId = "1911";
strData = "2222222222";
#endif
// send out signal
if( nMsgAmount > 0 )
emit scrolltable( m_nCount - 2, nMsgAmount );
msleep(10);
} // end while ( true )
}
To copy to clipboard, switch view to plain text mode
Kind regards,
Steve
Bookmarks