Skip to content

Commit

Permalink
Added support for {sec, nsec} qvariantmaps for time and duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanFabian committed Oct 6, 2021
1 parent 6ba56af commit 99d61d4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/message_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,28 @@ bool fillMessage( BabelFish &fish, ros_babel_fish::Message &msg, const QVariant
ros::WallTime wall_time = value.value<WallTime>().getRosTime();
return fillValue<ros::Time>( msg, ros::Time( wall_time.sec, wall_time.nsec ), MessageTypes::Time );
}
if ( value.canConvert<QVariantMap>())
{
const QVariantMap &map = value.value<QVariantMap>();
if ( msg.type() == MessageTypes::Time )
{
uint32_t sec = 0;
if ( map.contains( "sec" )) sec = map["sec"].toUInt();
uint32_t nsec = 0;
if ( map.contains( "nsec" )) nsec = map["nsec"].toUInt();
msg.as<ValueMessage<ros::Time>>().setValue( ros::Time( sec, nsec ));
return true;
}
else if ( msg.type() == MessageTypes::Duration )
{
int32_t sec = 0;
if ( map.contains( "sec" )) sec = map["sec"].toInt();
int32_t nsec = 0;
if ( map.contains( "nsec" )) nsec = map["nsec"].toInt();
msg.as<ValueMessage<ros::Duration>>().setValue( ros::Duration( sec, nsec ));
return true;
}
}
ROS_WARN( "Unsupported QVariant type '%s' encountered while filling message!", value.typeName());
break;
}
Expand Down

0 comments on commit 99d61d4

Please sign in to comment.