I want to benchmark a TCP Connection to an ECU (Transferrate)
For that, i want so send some Data. The amout of data can be set in my GUI from x KB to x GB.
The transferSize is calculated from the values set in the GUI. Buffer Size is 1024:
#define BENCHMARK_TRANSFER_BUFFER_SIZE 1024
void logic::TransferAndLatencyEthernetBenchmark::transferDataTcp(TCPClient& tcpclient)
{
uint32_t toSend = transferSize;
uint32_t currentSendSize = 0;
while (toSend > 0)
{
if (toSend / BENCHMARK_TRANSFER_BUFFER_SIZE >= 1)
{
currentSendSize = BENCHMARK_TRANSFER_BUFFER_SIZE;
}
else if ((toSend / BENCHMARK_TRANSFER_BUFFER_SIZE) == 0)
{
currentSendSize = toSend % BENCHMARK_TRANSFER_BUFFER_SIZE;
}
toSend -= currentSendSize;
tcpclient.sendData(transferSendBuffer, currentSendSize);
}
}
So iam calling the tcpclient.sendData(transferSendBuffer, currentSendSize) function als long as toSend > 0:
...
QDataStream out;
....
void TCPClient::sendData(uint8_t* buffer, uint32_t size)
{
qDebug() << "current send size: " << size << " - Transfer send buffer: " << (const char*)buffer;
for (int i=0; i<size; i++)
{
buffer[i] = 'a';
}
out.setDevice(socket_aurix);
out.writeBytes((const char*)buffer, size);
}
Iam pretty new on Qt (C++ in generel) and iam sure iam doing it wrong ;) It actually works but crashed when i try so send bigger amouts of data.
What would be a better way to initialize the fill the array instead of the for loop?
What what be a better approach in generel to use QDataStream?
Many thanks.