I am developing a TRDP based communication. I am using the TRDP project as a library in a QT project and it’s tested that it works. The idea is to init an object of class Trdp and call the methods sendPDMessage or sendMDMessage depending on the usage. But I do not receive any packets on the other side. Using Wireshark, I do not see any packets from the TRDP. If someone can help debugging this and finding the problem, I will be thankful!
<code>#include "trdp.h"
Trdp::Trdp ( QObject * parent ) : QObject ( parent ) {
ip[0] = 127;
ip[1] = 0;
ip[2] = 0;
ip[3] = 1;
comId = PD_COMID;
this->pubHandle = NULL;
mdConfiguration = {
NULL,
NULL,
{3, 64, 2},
TRDP_FLAGS_NONE,
1000000u,
1000000u,
1000000u,
1000000u,
17225u,
0,
5u,
};
pdConfiguration = {
NULL,
NULL,
TRDP_PD_DEFAULT_SEND_PARAM,
TRDP_FLAGS_NONE,
1000000u,
TRDP_TO_SET_TO_ZERO,
0u,
};
dynamicConfig = { NULL, RESERVED_MEMORY, { 0 } };
processConfig = {
"Me",
"",
"",
TRDP_PROCESS_DEFAULT_CYCLE_TIME,
0,
TRDP_OPTION_NONE
};
ownIP = vos_dottedIP("127.0.0.1");
dstIP = vos_dottedIP("127.0.0.1");
rv = 0;
if ( tlc_init ( &this->dbgOut, NULL, &dynamicConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error!";
}
if ( tlc_openSession ( &appHandle,
ownIP,
0,
NULL,
&pdConfiguration,
&mdConfiguration,
&processConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error! 2";
}
memset ( trdpBuffer, 0, sizeof ( trdpBuffer ) );
}
void Trdp::dbgOut (
void *pRefCon,
TRDP_LOG_T category,
const CHAR8 *pTime,
const CHAR8 *pFile,
UINT16 LineNumber,
const CHAR8 *pMsgStr)
{ }
// Add this method to initialize a publisher for PD messages
void Trdp::initPDPublisher() {
TRDP_PUB_T pubHandle = NULL;
TRDP_ERR_T err = tlp_publish(
this->appHandle, // Application session handle
&pubHandle, // Publisher handle to be initialized
NULL, // User reference
NULL, // Callback function for receiving data (not needed for publishing)
0, // Service ID (0 for default)
comId, // Communication ID
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
ownIP, // Source IP address
dstIP, // Destination IP address
1000000u, // Interval
0u, // Packet time-to-live
TRDP_FLAGS_NONE, // Flags
NULL, // Marshalling function
NULL, // Data pointer (NULL for initialization)
0 // Data size (0 for initialization)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error initializing PD publisher: " << err;
} else {
this->pubHandle = pubHandle; // Store the initialized pubHandle for later use
qDebug() << "PD Publisher initialized successfully.";
}
}
TRDP_ERR_T Trdp::sendPDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending PD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
// Ensure pubHandle is initialized; call initPDPublisher() before this if not already done
if (this->pubHandle == NULL) {
qDebug() << "Publisher not initialized. Initializing now.";
initPDPublisher();
if (this->pubHandle == NULL) {
qDebug() << "Failed to initialize publisher. Cannot send PD message.";
return TRDP_INIT_ERR;
}
}
TRDP_ERR_T err = tlp_put(
this->appHandle, // Use class member appHandle
this->pubHandle, // Use the initialized publisher handle
data, // Data to send
dataSize // Size of the data to send
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending PD message: " << err;
}
return err;
}
// Method for sending MD messages
TRDP_ERR_T Trdp::sendMDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending MD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
TRDP_ERR_T err = tlm_request(
this->appHandle, // Application session handle
NULL, // Message handle (NULL for auto)
NULL, // User reference
NULL, // Callback function (NULL for no callback)
1, // Service ID (1 for default)
PD_COMID + 1, // ComId (0 for default)
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
vos_dottedIP("127.0.0.1"), // Destination IP address
TRDP_FLAGS_DEFAULT, // Flags
0, // Priority (0 for default)
1000000u, // Timeout (in microseconds)
NULL, // Marshalling function
data, // Data pointer
dataSize, // Data size
NULL, // Response timeout (NULL for no response)
NULL // Response callback (NULL for no callback)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending MD message: " << err;
} else {
qDebug() << "MD message sent successfully.";
}
return err;
}
</code>
<code>#include "trdp.h"
Trdp::Trdp ( QObject * parent ) : QObject ( parent ) {
ip[0] = 127;
ip[1] = 0;
ip[2] = 0;
ip[3] = 1;
comId = PD_COMID;
this->pubHandle = NULL;
mdConfiguration = {
NULL,
NULL,
{3, 64, 2},
TRDP_FLAGS_NONE,
1000000u,
1000000u,
1000000u,
1000000u,
17225u,
0,
5u,
};
pdConfiguration = {
NULL,
NULL,
TRDP_PD_DEFAULT_SEND_PARAM,
TRDP_FLAGS_NONE,
1000000u,
TRDP_TO_SET_TO_ZERO,
0u,
};
dynamicConfig = { NULL, RESERVED_MEMORY, { 0 } };
processConfig = {
"Me",
"",
"",
TRDP_PROCESS_DEFAULT_CYCLE_TIME,
0,
TRDP_OPTION_NONE
};
ownIP = vos_dottedIP("127.0.0.1");
dstIP = vos_dottedIP("127.0.0.1");
rv = 0;
if ( tlc_init ( &this->dbgOut, NULL, &dynamicConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error!";
}
if ( tlc_openSession ( &appHandle,
ownIP,
0,
NULL,
&pdConfiguration,
&mdConfiguration,
&processConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error! 2";
}
memset ( trdpBuffer, 0, sizeof ( trdpBuffer ) );
}
void Trdp::dbgOut (
void *pRefCon,
TRDP_LOG_T category,
const CHAR8 *pTime,
const CHAR8 *pFile,
UINT16 LineNumber,
const CHAR8 *pMsgStr)
{ }
// Add this method to initialize a publisher for PD messages
void Trdp::initPDPublisher() {
TRDP_PUB_T pubHandle = NULL;
TRDP_ERR_T err = tlp_publish(
this->appHandle, // Application session handle
&pubHandle, // Publisher handle to be initialized
NULL, // User reference
NULL, // Callback function for receiving data (not needed for publishing)
0, // Service ID (0 for default)
comId, // Communication ID
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
ownIP, // Source IP address
dstIP, // Destination IP address
1000000u, // Interval
0u, // Packet time-to-live
TRDP_FLAGS_NONE, // Flags
NULL, // Marshalling function
NULL, // Data pointer (NULL for initialization)
0 // Data size (0 for initialization)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error initializing PD publisher: " << err;
} else {
this->pubHandle = pubHandle; // Store the initialized pubHandle for later use
qDebug() << "PD Publisher initialized successfully.";
}
}
TRDP_ERR_T Trdp::sendPDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending PD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
// Ensure pubHandle is initialized; call initPDPublisher() before this if not already done
if (this->pubHandle == NULL) {
qDebug() << "Publisher not initialized. Initializing now.";
initPDPublisher();
if (this->pubHandle == NULL) {
qDebug() << "Failed to initialize publisher. Cannot send PD message.";
return TRDP_INIT_ERR;
}
}
TRDP_ERR_T err = tlp_put(
this->appHandle, // Use class member appHandle
this->pubHandle, // Use the initialized publisher handle
data, // Data to send
dataSize // Size of the data to send
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending PD message: " << err;
}
return err;
}
// Method for sending MD messages
TRDP_ERR_T Trdp::sendMDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending MD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
TRDP_ERR_T err = tlm_request(
this->appHandle, // Application session handle
NULL, // Message handle (NULL for auto)
NULL, // User reference
NULL, // Callback function (NULL for no callback)
1, // Service ID (1 for default)
PD_COMID + 1, // ComId (0 for default)
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
vos_dottedIP("127.0.0.1"), // Destination IP address
TRDP_FLAGS_DEFAULT, // Flags
0, // Priority (0 for default)
1000000u, // Timeout (in microseconds)
NULL, // Marshalling function
data, // Data pointer
dataSize, // Data size
NULL, // Response timeout (NULL for no response)
NULL // Response callback (NULL for no callback)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending MD message: " << err;
} else {
qDebug() << "MD message sent successfully.";
}
return err;
}
</code>
#include "trdp.h"
Trdp::Trdp ( QObject * parent ) : QObject ( parent ) {
ip[0] = 127;
ip[1] = 0;
ip[2] = 0;
ip[3] = 1;
comId = PD_COMID;
this->pubHandle = NULL;
mdConfiguration = {
NULL,
NULL,
{3, 64, 2},
TRDP_FLAGS_NONE,
1000000u,
1000000u,
1000000u,
1000000u,
17225u,
0,
5u,
};
pdConfiguration = {
NULL,
NULL,
TRDP_PD_DEFAULT_SEND_PARAM,
TRDP_FLAGS_NONE,
1000000u,
TRDP_TO_SET_TO_ZERO,
0u,
};
dynamicConfig = { NULL, RESERVED_MEMORY, { 0 } };
processConfig = {
"Me",
"",
"",
TRDP_PROCESS_DEFAULT_CYCLE_TIME,
0,
TRDP_OPTION_NONE
};
ownIP = vos_dottedIP("127.0.0.1");
dstIP = vos_dottedIP("127.0.0.1");
rv = 0;
if ( tlc_init ( &this->dbgOut, NULL, &dynamicConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error!";
}
if ( tlc_openSession ( &appHandle,
ownIP,
0,
NULL,
&pdConfiguration,
&mdConfiguration,
&processConfig ) != TRDP_NO_ERR )
{
qDebug ( ) << "Init error! 2";
}
memset ( trdpBuffer, 0, sizeof ( trdpBuffer ) );
}
void Trdp::dbgOut (
void *pRefCon,
TRDP_LOG_T category,
const CHAR8 *pTime,
const CHAR8 *pFile,
UINT16 LineNumber,
const CHAR8 *pMsgStr)
{ }
// Add this method to initialize a publisher for PD messages
void Trdp::initPDPublisher() {
TRDP_PUB_T pubHandle = NULL;
TRDP_ERR_T err = tlp_publish(
this->appHandle, // Application session handle
&pubHandle, // Publisher handle to be initialized
NULL, // User reference
NULL, // Callback function for receiving data (not needed for publishing)
0, // Service ID (0 for default)
comId, // Communication ID
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
ownIP, // Source IP address
dstIP, // Destination IP address
1000000u, // Interval
0u, // Packet time-to-live
TRDP_FLAGS_NONE, // Flags
NULL, // Marshalling function
NULL, // Data pointer (NULL for initialization)
0 // Data size (0 for initialization)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error initializing PD publisher: " << err;
} else {
this->pubHandle = pubHandle; // Store the initialized pubHandle for later use
qDebug() << "PD Publisher initialized successfully.";
}
}
TRDP_ERR_T Trdp::sendPDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending PD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
// Ensure pubHandle is initialized; call initPDPublisher() before this if not already done
if (this->pubHandle == NULL) {
qDebug() << "Publisher not initialized. Initializing now.";
initPDPublisher();
if (this->pubHandle == NULL) {
qDebug() << "Failed to initialize publisher. Cannot send PD message.";
return TRDP_INIT_ERR;
}
}
TRDP_ERR_T err = tlp_put(
this->appHandle, // Use class member appHandle
this->pubHandle, // Use the initialized publisher handle
data, // Data to send
dataSize // Size of the data to send
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending PD message: " << err;
}
return err;
}
// Method for sending MD messages
TRDP_ERR_T Trdp::sendMDMessage(const void *pData, UINT32 dataSize) {
qDebug() << "Sending MD message" << reinterpret_cast<const UINT8 *>(pData) << "with size" << dataSize;
const UINT8* data = reinterpret_cast<const UINT8 *>(pData);
TRDP_ERR_T err = tlm_request(
this->appHandle, // Application session handle
NULL, // Message handle (NULL for auto)
NULL, // User reference
NULL, // Callback function (NULL for no callback)
1, // Service ID (1 for default)
PD_COMID + 1, // ComId (0 for default)
0, // etbTopoCnt (0 for default)
0, // etbConfigCnt (0 for default)
vos_dottedIP("127.0.0.1"), // Destination IP address
TRDP_FLAGS_DEFAULT, // Flags
0, // Priority (0 for default)
1000000u, // Timeout (in microseconds)
NULL, // Marshalling function
data, // Data pointer
dataSize, // Data size
NULL, // Response timeout (NULL for no response)
NULL // Response callback (NULL for no callback)
);
if (err != TRDP_NO_ERR) {
qDebug() << "Error sending MD message: " << err;
} else {
qDebug() << "MD message sent successfully.";
}
return err;
}