Hello,
I’m trying to send a string from Qt to Isaac using TCP but when I do my app throw a bad alloc error because I don’t use any proto.
So now I trying using a pingProto by adapting this Qt app found on github, just changing the proto and port/addresse but just after the start of udp :
INFO engine/alice/components/UdpSubscriber.cpp@67: Starting UDP subscriber on port 6005
I get the following error :
PANIC engine/alice/backend/udp_packetizer.cpp@249: Package index 0/0 ouf of range (this should not be an assert)
I want to do it in TCP but since the code I found use UDP I just want to try UDP before going to TCP.
Any idea why I get this error ?
this is the function in udp_packetizer :
// Mark the package as received
const size_t package_index = package_header.getPackageIndex();
ASSERT(package_index < puzzle.packages_received.size(),
"Package index %zd/%zd ouf of range (this should not be an assert)",
package_index, puzzle.packages_received.size());
{
if (!puzzle.packages_received[package_index]) {
puzzle.packages_received[package_index] = true;
} else {
LOG_WARNING("Duplicated package %d (this should not be an assert)", package_index);
return;
}
}
in my JSON :
"udp_rx":{
"port": 6005,
"message_assembly_slot_count": 1
}
This is my qt UDP sender (no warning displayed in Qt) :
#include "positionsender.h"
#include <QUdpSocket>
#include <QTimer>
#include <QDebug>
#include <capnp/message.h>
#include <capnp/serialize.h>
#include "PingProto.capnp.h"
using ::capnp::word;
using ::kj::ArrayPtr;
typedef ::kj::Array<word> WordArray;
PositionSender::PositionSender(QObject* parent)
: QObject(parent)
, m_delayMsec(16) // this works out to ~58.82352941176 Hz
, m_dest(QHostAddress::LocalHost)
, m_destPort(6005)
, m_socket(new QUdpSocket(this))
, m_sendTimer(new QTimer(this))
{
connect(m_sendTimer, &QTimer::timeout, this, &PositionSender::sendPosition);
m_sendTimer->setTimerType(Qt::PreciseTimer);
initPositions();
}
void PositionSender::initPositions()
{
::capnp::MallocMessageBuilder message;
L3::PingProto::Builder position = message.initRoot<L3::PingProto>();
position.setMessage("Hello There"); // booogus values
WordArray array = ::capnp::messageToFlatArray(message);
ArrayPtr<unsigned char> messageBytes(array.asBytes());
QByteArray messageBuffer((const char*)messageBytes.begin(), messageBytes.size());
m_positionBuffers.append(messageBuffer);
}
void PositionSender::setRate(int rateHz)
{
m_delayMsec = qRound(1000.0/rateHz);
}
void PositionSender::setDestination(QHostAddress dest, quint16 destPort)
{
m_dest = dest;
m_destPort = destPort;
}
void PositionSender::start()
{
m_sendTimer->start(m_delayMsec);
}
void PositionSender::stop()
{
m_sendTimer->stop();
}
void PositionSender::sendPosition()
{
static QList<QByteArray>::Iterator bufIter = m_positionBuffers.begin();
QByteArray& messageBuffer = *(bufIter++);
if(bufIter == m_positionBuffers.end()) bufIter = m_positionBuffers.begin();
qint64 bytesSent = m_socket->writeDatagram(messageBuffer, m_dest, m_destPort);
if (bytesSent < 0)
{
qWarning() << qPrintable("Error sending datagram:") << m_socket->errorString();
return;
}
if (bytesSent != messageBuffer.size())
{
qWarning() << qPrintable("Partial send") << QString::number(bytesSent) + "/" + QString::number(messageBuffer.size()) << qPrintable("bytes sent");
return;
}
}
Thanks !
Regards,
Planktos