Go to the documentation of this file.00001 #include "timestamp_injector.h"
00002
00003 using namespace RosIntrospection;
00004
00005 template <typename T> T readFromBuffer( uint8_t** buffer)
00006 {
00007 T destination = (*( reinterpret_cast<T*>( *buffer ) ) );
00008 *buffer += sizeof(T);
00009 return destination;
00010 }
00011
00012 inline void SkipBytesInBuffer( uint8_t** buffer, int vector_size, const BuiltinType& type )
00013 {
00014 if( type == STRING)
00015 {
00016 for (int i=0; i<vector_size; i++){
00017 int32_t string_size = readFromBuffer<int32_t>( buffer );
00018 *buffer += string_size;
00019 }
00020 }
00021 else{
00022 *buffer += vector_size * BuiltinTypeSize[ static_cast<int>(type) ];
00023 }
00024 }
00025
00026 void injectTimeImpl(const ROSTypeList& type_list,
00027 const ROSType &type,
00028 bool header_timestamp_message,
00029 uint8_t** buffer_ptr,
00030 const ros::Time& new_timestamp)
00031 {
00032 int array_size = type.arraySize();
00033 if( array_size == -1)
00034 {
00035 array_size = readFromBuffer<int32_t>( buffer_ptr );
00036 }
00037
00038 if( type.typeID() == OTHER )
00039 {
00040 for (int v=0; v<array_size; v++)
00041 {
00042 for(const ROSMessage& msg: type_list)
00043 {
00044 if( msg.type().msgName() == type.msgName() &&
00045 msg.type().pkgName() == type.pkgName() )
00046 {
00047 for (const ROSField& field : msg.fields() )
00048 {
00049 const auto& field_type = field.type();
00050 if( !field.isConstant()) {
00051
00052 bool is_header_timestamp = (
00053 field_type.typeID() == TIME &&
00054 field_type.isArray() == false &&
00055 field.name() == "stamp" &&
00056 msg.type().msgName() == "Header" &&
00057 msg.type().pkgName() == "std_msgs" );
00058
00059 if( !is_header_timestamp &&
00060 field_type.typeID() != OTHER &&
00061 field_type.typeID() != STRING
00062 && field_type.arraySize() == 1)
00063 {
00064
00065 *buffer_ptr += BuiltinTypeSize[ static_cast<int>(field_type.typeID()) ];
00066 }
00067 else{
00068
00069 injectTimeImpl(type_list, field_type, is_header_timestamp, buffer_ptr, new_timestamp);
00070 }
00071 }
00072 }
00073 break;
00074 }
00075 }
00076 }
00077 }
00078 else if( header_timestamp_message )
00079 {
00080 uint32_t *sec = reinterpret_cast<uint32_t*>( *buffer_ptr );
00081 *buffer_ptr += sizeof(uint32_t);
00082 uint32_t *nsec = reinterpret_cast<uint32_t*>( *buffer_ptr );
00083 *buffer_ptr += sizeof(uint32_t);
00084 *sec = new_timestamp.sec;
00085 *nsec = new_timestamp.nsec;
00086 }
00087 else{
00088 SkipBytesInBuffer( buffer_ptr, array_size, type.typeID() );
00089 }
00090 }
00091
00092
00093
00094
00095
00096 void injectTime(const ROSTypeList &type_map, ROSType type, uint8_t *buffer_ptr, const ros::Time &new_timestamp)
00097 {
00098 uint8_t** buffer = &buffer_ptr;
00099 injectTimeImpl( type_map, type, false, buffer, new_timestamp );
00100 }