Cannot get MOP data
已完成I'm implementing mop function for Onboard-SDK-ROS connecting and transfer data bw OSDK & MSDK.
I could connect its, but cannot get data from recvData function
Could any one give me some indication to do it? Thank you.
bool VehicleNode::startSubscribeForGetDataMopCallback(SendDataMop::Request& request, SendDataMop::Response& response)
{
ROS_INFO_STREAM("Start subscribe for geting MOP Data callback");
if(ptr_wrapper_ == nullptr)
{
ROS_ERROR_STREAM("Vehicle modules is nullptr");
return false;
}
MopPipeline *OM_Pipeline = NULL;
bool ret = ptr_wrapper_->getMopPipeline(request.id, OM_Pipeline);
if (!ret || OM_Pipeline == NULL) {
response.result = ret;
ROS_ERROR_STREAM("OM_Pipeline is nullptr");
return 0;
}
pthread_t thread_publish;
int result = pthread_create(&thread_publish, NULL, threadPublishMopDataTo, OM_Pipeline);
if(result != 0) {
DERROR("Server send mop data create failed!\n");
} else {
DSTATUS("Server send mop data create success!\n");
}
return response.result != 0;
}
void* VehicleNode::threadPublishMopDataTo(void *arg)
{
MopPipeline *OM_Pipeline = (MopPipeline *)arg;
if (!OM_Pipeline)
std::runtime_error("Error param");
uint8_t *recvBuf;
const uint8_t RELIABLE_RECV_ONCE_BUFFER_SIZE = 100 * 1024;
recvBuf = (uint8_t *)OsdkOsal_Malloc(RELIABLE_RECV_ONCE_BUFFER_SIZE);
if (recvBuf == NULL) {
DERROR("[File-Service] OsdkOsal_Malloc recv buffer error");
return NULL;
}
MopPipeline::DataPackType readPack = {(uint8_t *) recvBuf, RELIABLE_RECV_ONCE_BUFFER_SIZE};
// OsdkOsal_TaskSleepMs(5000);
// receive data
MopErrCode mopRet = MOP_PASSED;
while(ros::ok())
{
memset(recvBuf, 0, RELIABLE_RECV_ONCE_BUFFER_SIZE);
readPack.length = RELIABLE_RECV_ONCE_BUFFER_SIZE;
mopRet = OM_Pipeline->recvData(readPack, &readPack.length);
if (mopRet != MOP_PASSED) {
if (mopRet == MOP_TIMEOUT) {
DSTATUS("[File-Service] receive timeout");
} else if (mopRet == MOP_CONNECTIONCLOSE) {
DSTATUS("[File-Service] connection of pipeline [%d] closed", OM_Pipeline->getId());
DSTATUS("[File-Service] disconnect from cilent now stop task");
break;
} else {
DERROR("[File-Service] recv data from client error,stat:%lld", mopRet);
}
OsdkOsal_TaskSleepMs(1000);
} else {
if (readPack.length > 0) {
DSTATUS("Receive buf {%d ...}", recvBuf[0]);
// publish
dji_osdk_ros::MopData mop_data;
mop_data.data.resize(readPack.length);
for (int i=0; i<readPack.length; i++)
{
mop_data.data[i] = readPack.data[i];
}
mop_publisher_.publish(mop_data);
}
}
}
}
-
mopRet = OM_Pipeline->recvData(readPack, &readPack.length);
I call Linux API with the code. But I always get result:
[File-Service] recv data from cilent, len: 0
With SDK sample, I saw recvData will listen and return result MOP_PASSED after 5s
But with ROS, recvData always return result MOP_PASSED immediately.
请先登录再写评论。
评论
6 条评论