diff --git a/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.cpp b/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.cpp index e54df43396623295f90fcbbf3371fce6d560a47b..d289f974ba3248e7b8408bdc2a2c99a7ac9dc830 100644 --- a/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.cpp +++ b/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.cpp @@ -27,11 +27,11 @@ constexpr int SecondColumnOffset = 4; -CybertronTopologyMessage::CybertronTopologyMessage() +CybertronTopologyMessage::CybertronTopologyMessage(const std::string& channel) : RenderableMessage(nullptr, 1), second_column_(SecondColumnType::MessageFrameRatio), - page_item_count_(24), col1_width_(8), + specified_channel_(channel), all_channels_map_() {} CybertronTopologyMessage::~CybertronTopologyMessage(void) { @@ -75,6 +75,10 @@ void CybertronTopologyMessage::TopologyChanged( const std::string& channelName = changeMsg.role_attr().channel_name(); const std::string& msgTypeName = changeMsg.role_attr().message_type(); + if (!specified_channel_.empty() && specified_channel_ != channelName) { + return; + } + if ((int)channelName.length() > col1_width_) { col1_width_ = channelName.length(); } @@ -106,17 +110,16 @@ void CybertronTopologyMessage::TopologyChanged( if (!ChannelMessage::isErrorCode(channelMsg)) { if (::apollo::cybertron::proto::RoleType::ROLE_WRITER == changeMsg.role_type()) { + if (msgTypeName != apollo::cybertron::message::MessageType< + apollo::cybertron::message::RawMessage>()) { + channelMsg->set_message_type(msgTypeName); + } + channelMsg->add_writer(nodeName); } else { channelMsg->add_reader(nodeName); } - - if (msgTypeName != apollo::cybertron::message::MessageType< - apollo::cybertron::message::RawMessage>()) { - channelMsg->set_message_type(msgTypeName); - } } - } else { auto iter = all_channels_map_.find(channelName); @@ -144,18 +147,6 @@ void CybertronTopologyMessage::ChangeState(const Screen* s, int key) { second_column_ = SecondColumnType::MessageType; break; - // case CTRL('d'): - // case KEY_NPAGE: - // ++page_index_; - // if (page_index_ >= pages_) page_index_ = pages_ - 1; - // break; - - // case CTRL('u'): - // case KEY_PPAGE: - // --page_index_; - // if (page_index_ < 1) page_index_ = 0; - // break; - case ' ': { ChannelMessage* child = static_cast(Child(*line_no())); if (child) { @@ -173,7 +164,6 @@ void CybertronTopologyMessage::Render(const Screen* s, int key) { ChangeState(s, key); SplitPages(key); - // display table title s->AddStr(0, 0, Screen::WHITE_BLACK, "Channels"); switch (second_column_) { case SecondColumnType::MessageType: @@ -186,19 +176,20 @@ void CybertronTopologyMessage::Render(const Screen* s, int key) { break; } - // display concrete channel info - Screen::ColorPair color; - std::ostringstream outStr; - auto iter = all_channels_map_.cbegin(); - const int skip_item_count = page_index_ * page_item_count_; - for (int i = 0; i < skip_item_count; ++i) { + register int tmp = page_index_ * page_item_count_; + register int line = 0; + while (line < tmp) { ++iter; + ++line; } - int y = 1; // start line index - const int end_y = s->Height(); - for (; iter != all_channels_map_.cend() && y < end_y; ++iter, ++y) { + Screen::ColorPair color; + std::ostringstream outStr; + + tmp = page_item_count_ + 1; + for (line = 1; iter != all_channels_map_.cend() && line < tmp; + ++iter, ++line) { color = Screen::RED_BLACK; if (!ChannelMessage::isErrorCode(iter->second)) { @@ -212,27 +203,28 @@ void CybertronTopologyMessage::Render(const Screen* s, int key) { } s->SetCurrentColor(color); - s->AddStr(0, y, iter->first.c_str()); + s->AddStr(0, line, iter->first.c_str()); if (!ChannelMessage::isErrorCode(iter->second)) { switch (second_column_) { case SecondColumnType::MessageType: - s->AddStr(col1_width_ + SecondColumnOffset, y, + s->AddStr(col1_width_ + SecondColumnOffset, line, iter->second->message_type().c_str()); break; case SecondColumnType::MessageFrameRatio: { outStr.str(""); outStr << std::fixed << std::setprecision(2) << iter->second->frame_ratio(); - s->AddStr(col1_width_ + SecondColumnOffset, y, outStr.str().c_str()); + s->AddStr(col1_width_ + SecondColumnOffset, line, + outStr.str().c_str()); } break; } } else { ChannelMessage::ErrorCode errcode = ChannelMessage::castPtr2ErrorCode(iter->second); - s->AddStr(col1_width_ + SecondColumnOffset, y, + s->AddStr(col1_width_ + SecondColumnOffset, line, ChannelMessage::errCode2Str(errcode)); } - s->ClearCurrentColor(color); + s->ClearCurrentColor(); } } diff --git a/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.h b/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.h index 1006eb0bcae9b863c1bfecb72c6de1ec2c1cd1fa..ba2369548cd472e9df9b05e35a84caecb5fb121c 100644 --- a/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.h +++ b/framework/cybertron/tools/cvt/monitor/cybertron_topology_message.h @@ -18,6 +18,7 @@ #define TOOLS_CVT_MONITOR_CYBERTRON_TOPOLOGY_MESSAGE_H_ #include +#include #include "renderable_message.h" namespace apollo { @@ -33,7 +34,7 @@ class ChannelMessage; class CybertronTopologyMessage : public RenderableMessage { public: - explicit CybertronTopologyMessage(); + explicit CybertronTopologyMessage(const std::string& channel); ~CybertronTopologyMessage(); void Render(const Screen* s, int key) override; @@ -42,14 +43,16 @@ class CybertronTopologyMessage : public RenderableMessage { void TopologyChanged(const apollo::cybertron::proto::ChangeMsg& change_msg); private: + CybertronTopologyMessage(const CybertronTopologyMessage&) = delete; + CybertronTopologyMessage& operator = (const CybertronTopologyMessage&) = delete; + void ChangeState(const Screen* s, int key); enum class SecondColumnType { MessageType, MessageFrameRatio }; SecondColumnType second_column_; - int page_item_count_; int col1_width_; - + const std::string& specified_channel_; std::map all_channels_map_; }; diff --git a/framework/cybertron/tools/cvt/monitor/general_channel_message.cpp b/framework/cybertron/tools/cvt/monitor/general_channel_message.cpp index a3160b9fd2caa9c259260ffb475d4cbbda20ac40..68c693bac664f4bd651023dbb9282475434b6dc1 100644 --- a/framework/cybertron/tools/cvt/monitor/general_channel_message.cpp +++ b/framework/cybertron/tools/cvt/monitor/general_channel_message.cpp @@ -55,7 +55,7 @@ void GeneralChannelMessage::Render(const Screen* s, int key) { s->AddStr(0, lineNo++, "MessageType: "); s->AddStr(message_type().c_str()); - if(is_enabled()) { + if (is_enabled()) { switch (current_state_) { case State::ShowDebugString: RenderDebugString(s, key, lineNo); @@ -67,23 +67,23 @@ void GeneralChannelMessage::Render(const Screen* s, int key) { } else { s->AddStr(0, lineNo++, "Channel has been closed"); } - s->ClearCurrentColor(Screen::WHITE_BLACK); + s->ClearCurrentColor(); } -void GeneralChannelMessage::RenderInfo(const Screen* s, int key, unsigned lineNo) { - int pageItemCount = s->Height() - lineNo; - pages_ = (readers_.size() + writers_.size() + lineNo) / - pageItemCount + - 1; +void GeneralChannelMessage::RenderInfo(const Screen* s, int key, + unsigned lineNo) { + page_item_count_ = s->Height() - lineNo; + pages_ = (readers_.size() + writers_.size() + lineNo) / page_item_count_ + 1; SplitPages(key); bool hasReader = true; std::vector* vec = &readers_; auto iter = vec->cbegin(); - int y = page_index_ * pageItemCount; + int y = page_index_ * page_item_count_; if (y < vec->size()) { - while (y < page_index_ * pageItemCount) { + y = 0; + while (y < page_index_ * page_item_count_) { ++iter; ++y; } @@ -117,7 +117,7 @@ void GeneralChannelMessage::RenderInfo(const Screen* s, int key, unsigned lineNo } void GeneralChannelMessage::RenderDebugString(const Screen* s, int key, - unsigned lineNo) { + unsigned lineNo) { if (has_message_come()) { if (raw_msg_class_ == nullptr) { auto rawFactory = apollo::cybertron::message::ProtobufFactory::Instance(); @@ -132,17 +132,19 @@ void GeneralChannelMessage::RenderDebugString(const Screen* s, int key, std::ostringstream outStr; outStr << std::fixed << std::setprecision(2) << frame_ratio(); s->AddStr(outStr.str().c_str()); - + decltype(channel_message_) channelMsg = CopyMsgPtr(); if (raw_msg_class_->ParseFromString(channelMsg->message)) { - int lcount = - lineCount(*raw_msg_class_, s->Width()); - int pageItemCount = s->Height() - lineNo; - pages_ = lcount / pageItemCount + 1; + int lcount = lineCount(*raw_msg_class_, s->Width()); + page_item_count_ = s->Height() - lineNo; + pages_ = lcount / page_item_count_ + 1; SplitPages(key); - GeneralMessageBase::PrintMessage(this, *raw_msg_class_, s, lineNo, 0, - page_index_ * pageItemCount); + int jumpLines = page_index_ * page_item_count_; + if(jumpLines){ + jumpLines -= (jumpLines/4); + } + GeneralMessageBase::PrintMessage(this, *raw_msg_class_, jumpLines, s, lineNo, 0); } else { s->AddStr(0, lineNo++, "Cannot parse the raw message"); } diff --git a/framework/cybertron/tools/cvt/monitor/general_channel_message.h b/framework/cybertron/tools/cvt/monitor/general_channel_message.h index 583a0f0e3064bd24e8d2f9d76f72f236f928d6eb..c68199edee4807c7390729f9114dc702daa23a31 100644 --- a/framework/cybertron/tools/cvt/monitor/general_channel_message.h +++ b/framework/cybertron/tools/cvt/monitor/general_channel_message.h @@ -54,8 +54,6 @@ class GeneralChannelMessage enum class State { ShowDebugString, ShowInfo } current_state_; - // int pages_; - // int page_index_; google::protobuf::Message* raw_msg_class_; friend class RepeatedItemsMessage; diff --git a/framework/cybertron/tools/cvt/monitor/general_message.cpp b/framework/cybertron/tools/cvt/monitor/general_message.cpp index 511de3a0f48a5bbaacc664f5463f62356e3a7780..9e5357fe5a666da3cf5e00a0f505f82dc0218cfe 100644 --- a/framework/cybertron/tools/cvt/monitor/general_message.cpp +++ b/framework/cybertron/tools/cvt/monitor/general_message.cpp @@ -18,86 +18,18 @@ #include "general_channel_message.h" #include "screen.h" +#include #include +namespace { +constexpr int INT_FLOAT_PRECISION = 6; +constexpr int DOULBE_PRECISION = 9; +} // namespace + RenderableMessage* GeneralMessage::Child(int lineNo) const { return GeneralMessageBase::Child(lineNo); } -void GeneralMessage::PrintRepeatedField(const Screen* s, unsigned& lineNo, - int indent, int index, int jumpLines) { - std::ostringstream outStr; - std::ios_base::fmtflags old_flags; - const std::string& fieldName = field_->name(); - outStr << fieldName << ": "; - - if (field_->is_repeated()) { - outStr << "[" << index << "] "; - } - - switch (field_->cpp_type()) { -#define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \ - case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \ - old_flags = outStr.flags(); \ - outStr << std::fixed << std::setprecision(PRECISION) \ - << field_->is_repeated() \ - ? reflection_ptr_->GetRepeated##METHOD(*message_ptr_, field_, index) \ - : reflection_ptr_->Get##METHOD(*message_ptr_, field_); \ - outStr.flags(old_flags); \ - break - - OUTPUT_FIELD(INT32, Int32, 6); - OUTPUT_FIELD(INT64, Int64, 6); - OUTPUT_FIELD(UINT32, UInt32, 6); - OUTPUT_FIELD(UINT64, UInt64, 6); - OUTPUT_FIELD(FLOAT, Float, 6); - OUTPUT_FIELD(DOUBLE, Double, 9); - OUTPUT_FIELD(BOOL, Bool, 6); -#undef OUTPUT_FIELD - - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { - std::string scratch; - const std::string& value = - field_->is_repeated() - ? reflection_ptr_->GetRepeatedStringReference( - *message_ptr_, field_, index, &scratch) - : reflection_ptr_->GetStringReference(*message_ptr_, field_, - &scratch); - outStr << value.substr(jumpLines); - break; - } - - case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: { - int enum_value = - field_->is_repeated() - ? reflection_ptr_->GetRepeatedEnumValue(*message_ptr_, field_, - index) - : reflection_ptr_->GetEnumValue(*message_ptr_, field_); - const google::protobuf::EnumValueDescriptor* enum_desc = - field_->enum_type()->FindValueByNumber(enum_value); - if (enum_desc != nullptr) { - outStr << enum_desc->name(); - } else { - outStr << enum_value; - } - break; - } - - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - s->AddStr(indent, lineNo++, outStr.str().c_str()); - GeneralMessageBase::PrintMessage( - this, field_->is_repeated() - ? reflection_ptr_->GetRepeatedMessage(*message_ptr_, field_, - index) - : reflection_ptr_->GetMessage(*message_ptr_, field_), - s, lineNo, indent + 2, jumpLines + 1); - outStr.str(""); - break; - } - - s->AddStr(indent, lineNo++, outStr.str().c_str()); -} - GeneralMessage::GeneralMessage(GeneralMessageBase* parent, const google::protobuf::Message* msg, const google::protobuf::Reflection* reflection, @@ -163,13 +95,15 @@ void GeneralMessage::Render(const Screen* s, int key) { int lcount = lineCountOfField(*message_ptr_, s->Width(), field_, reflection_ptr_); - int pageItemCount = s->Height() - lineNo; - pages_ = lcount / pageItemCount + 1; + page_item_count_ = s->Height() - lineNo; + pages_ = lcount / page_item_count_ + 1; SplitPages(key); - PrintRepeatedField(s, lineNo, 0, itemIndex_, page_index_ * pageItemCount); + int jumpLines = page_index_ * page_item_count_; + // PrintRepeatedField(s, lineNo, 0, itemIndex_, jumpLines); + GeneralMessageBase::PrintField(this, *message_ptr_, jumpLines, s, lineNo, 0, reflection_ptr_, field_, itemIndex_); } } - s->ClearCurrentColor(Screen::WHITE_BLACK); + s->ClearCurrentColor(); } diff --git a/framework/cybertron/tools/cvt/monitor/general_message.h b/framework/cybertron/tools/cvt/monitor/general_message.h index e8802fcb47bd63c4f816a408d7e4da225d080ce9..8a8c7c9ee58f53df855a724feb93c9478585cd91 100644 --- a/framework/cybertron/tools/cvt/monitor/general_message.h +++ b/framework/cybertron/tools/cvt/monitor/general_message.h @@ -44,8 +44,8 @@ class GeneralMessage : public GeneralMessageBase { GeneralMessage(const GeneralMessage&) = delete; GeneralMessage& operator=(const GeneralMessage&) = delete; - void PrintRepeatedField(const Screen* s, unsigned& lineNo, int indent, - int index, int jumpLines); + // void PrintRepeatedField(const Screen* s, unsigned& lineNo, int indent, + // int index, int& jumpLines); int itemIndex_; diff --git a/framework/cybertron/tools/cvt/monitor/general_message_base.cpp b/framework/cybertron/tools/cvt/monitor/general_message_base.cpp index 54e1c9ce148203077807185da442b4290b25c1eb..a07eaa1a0b75f7ca95511f7a86771055f994f053 100644 --- a/framework/cybertron/tools/cvt/monitor/general_message_base.cpp +++ b/framework/cybertron/tools/cvt/monitor/general_message_base.cpp @@ -21,6 +21,11 @@ #include +namespace { +constexpr int INT_FLOAT_PRECISION = 6; +constexpr int DOULBE_PRECISION = 9; +} // namespace + int GeneralMessageBase::lineCount(const google::protobuf::Message& msg, int screenWidth) { const google::protobuf::Reflection* reflection = msg.GetReflection(); @@ -60,7 +65,7 @@ int GeneralMessageBase::lineCountOfField( case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: const google::protobuf::Message& childMsg = reflection->GetMessage(msg, field); - ret += lineCount(childMsg, screenWidth) + 1; + ret += lineCount(childMsg, screenWidth); break; } // end switch @@ -71,8 +76,8 @@ int GeneralMessageBase::lineCountOfField( void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg, const google::protobuf::Message& msg, - const Screen* s, unsigned& lineNo, - int indent, int jumpLines) { + int& jumpLines, const Screen* s, + unsigned& lineNo, int indent) { const google::protobuf::Reflection* reflection = msg.GetReflection(); const google::protobuf::Descriptor* descriptor = msg.GetDescriptor(); std::vector fields; @@ -83,108 +88,144 @@ void GeneralMessageBase::PrintMessage(GeneralMessageBase* baseMsg, reflection->ListFields(msg, &fields); } - int i = 0; - // jump lines - for (; i < fields.size() && jumpLines > 1; ++i) { + for (int i = 0; i < fields.size(); ++i) { + bool isWriten = false; const google::protobuf::FieldDescriptor* field = fields[i]; - --jumpLines; - - if (!field->is_repeated()) { - switch (field->cpp_type()) { - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { - std::string scratch; - const std::string& value = - reflection->GetStringReference(msg, field, &scratch); - jumpLines -= value.size() / s->Width(); - break; + if (field->is_repeated()) { + if (jumpLines) { + --jumpLines; + } else { + std::ostringstream outStr; + const std::string& fieldName = field->name(); + outStr << fieldName << ": "; + outStr << "+[" << reflection->FieldSize(msg, field) << " items ]"; + GeneralMessage* item = + new GeneralMessage(baseMsg, &msg, reflection, field); + + if (item) { + baseMsg->insertRepeatedMessage(lineNo, item); } + s->AddStr(indent, lineNo++, outStr.str().c_str()); + } + } else { + PrintField(baseMsg, msg, jumpLines, s, lineNo, indent, reflection, field, + -1); + } // end else + } // end for - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - jumpLines -= - lineCount(reflection->GetMessage(msg, field), s->Width()); - break; - } // end switch - } + const google::protobuf::UnknownFieldSet& unknown_fields = + reflection->GetUnknownFields(msg); + if (!unknown_fields.empty()) { + Screen::ColorPair c = s->Color(); + s->ClearCurrentColor(); + s->SetCurrentColor(Screen::RED_BLACK); + s->AddStr(indent, lineNo++, "Have Unknown Fields"); + s->ClearCurrentColor(); + s->SetCurrentColor(c); } +} +void GeneralMessageBase::PrintField( + GeneralMessageBase* baseMsg, const google::protobuf::Message& msg, + int& jumpLines, const Screen* s, unsigned& lineNo, int indent, + const google::protobuf::Reflection* ref, + const google::protobuf::FieldDescriptor* field, int index) { std::ostringstream outStr; std::ios_base::fmtflags old_flags; - for (; i < fields.size(); ++i) { - const google::protobuf::FieldDescriptor* field = fields[i]; - const std::string& fieldName = field->name(); - outStr << fieldName << ": "; - if (field->is_repeated()) { - outStr << "+[" << reflection->FieldSize(msg, field) << " items]"; - - GeneralMessage* item = - new GeneralMessage(baseMsg, &msg, reflection, field); - - if (item) { - baseMsg->insertRepeatedMessage(lineNo, item); - } - } else { - switch (field->cpp_type()) { -#define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \ - case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \ - old_flags = outStr.flags(); \ - outStr << std::fixed << std::setprecision(PRECISION) \ - << reflection->Get##METHOD(msg, field); \ - outStr.flags(old_flags); \ + switch (field->cpp_type()) { +#define OUTPUT_FIELD(CPPTYPE, METHOD, PRECISION) \ + case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: \ + if (jumpLines) { \ + --jumpLines; \ + } else { \ + const std::string& fieldName = field->name(); \ + outStr << fieldName << ": "; \ + if (field->is_repeated()) { \ + outStr << "[" << index << "] "; \ + } \ + old_flags = outStr.flags(); \ + outStr << std::fixed << std::setprecision(PRECISION) \ + << (field->is_repeated() \ + ? ref->GetRepeated##METHOD(msg, field, index) \ + : ref->Get##METHOD(msg, field)); \ + outStr.flags(old_flags); \ + s->AddStr(indent, lineNo++, outStr.str().c_str()); \ + } \ break - OUTPUT_FIELD(INT32, Int32, 6); - OUTPUT_FIELD(INT64, Int64, 6); - OUTPUT_FIELD(UINT32, UInt32, 6); - OUTPUT_FIELD(UINT64, UInt64, 6); - OUTPUT_FIELD(FLOAT, Float, 6); - OUTPUT_FIELD(DOUBLE, Double, 9); - OUTPUT_FIELD(BOOL, Bool, 6); + OUTPUT_FIELD(INT32, Int32, INT_FLOAT_PRECISION); + OUTPUT_FIELD(INT64, Int64, INT_FLOAT_PRECISION); + OUTPUT_FIELD(UINT32, UInt32, INT_FLOAT_PRECISION); + OUTPUT_FIELD(UINT64, UInt64, INT_FLOAT_PRECISION); + OUTPUT_FIELD(FLOAT, Float, INT_FLOAT_PRECISION); + OUTPUT_FIELD(DOUBLE, Double, DOULBE_PRECISION); + OUTPUT_FIELD(BOOL, Bool, INT_FLOAT_PRECISION); #undef OUTPUT_FIELD - case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: { - int enum_value = reflection->GetEnumValue(msg, field); - - const google::protobuf::EnumValueDescriptor* enum_desc = - field->enum_type()->FindValueByNumber(enum_value); - if (enum_desc != nullptr) { - outStr << enum_desc->name(); - } else { - outStr << enum_value; - } - break; + case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { + std::string scratch; + const std::string& value = + field->is_repeated() + ? ref->GetRepeatedStringReference(msg, field, index, &scratch) + : ref->GetStringReference(msg, field, &scratch); + int lines = value.size() / s->Width() + 1; + if (lines > jumpLines) { + const std::string& fieldName = field->name(); + outStr << fieldName << ": "; + if (field->is_repeated()) { + outStr << "[" << index << "] "; } + outStr << value.substr(jumpLines * s->Width()); + s->AddStr(indent, lineNo, outStr.str().c_str()); + lineNo += (lines - jumpLines); + jumpLines = 0; - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { - std::string scratch; - const std::string& value = - reflection->GetStringReference(msg, field, &scratch); - outStr << value; - break; - } + } else { + jumpLines -= lines; + } + break; + } - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - s->AddStr(indent, lineNo++, outStr.str().c_str()); - PrintMessage(baseMsg, reflection->GetMessage(msg, field), s, lineNo, - indent + 2); - outStr.str(""); - break; - } // end switch - } // end else - - s->AddStr(indent, lineNo++, outStr.str().c_str()); - outStr.str(""); - } // end for + case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: { + if (jumpLines) { + --jumpLines; + } else { + const std::string& fieldName = field->name(); + outStr << fieldName << ": "; + if (field->is_repeated()) { + outStr << "[" << index << "] "; + } + int enum_value = field->is_repeated() + ? ref->GetRepeatedEnumValue(msg, field, index) + : ref->GetEnumValue(msg, field); + const google::protobuf::EnumValueDescriptor* enum_desc = + field->enum_type()->FindValueByNumber(enum_value); + if (enum_desc != nullptr) { + outStr << enum_desc->name(); + } else { + outStr << enum_value; + } + s->AddStr(indent, lineNo++, outStr.str().c_str()); + } + break; + } - const google::protobuf::UnknownFieldSet& unknown_fields = - reflection->GetUnknownFields(msg); - if (!unknown_fields.empty()) { - Screen::ColorPair c = s->Color(); - s->ClearCurrentColor(c); - s->SetCurrentColor(Screen::RED_BLACK); - s->AddStr(indent, lineNo++, "Have Unknown Fields"); - s->ClearCurrentColor(Screen::RED_BLACK); - s->SetCurrentColor(c); + case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: + if (!jumpLines) { + const std::string& fieldName = field->name(); + outStr << fieldName << ": "; + if (field->is_repeated()) { + outStr << "[" << index << "] "; + } + s->AddStr(indent, lineNo++, outStr.str().c_str()); + } + GeneralMessageBase::PrintMessage( + baseMsg, + field->is_repeated() ? ref->GetRepeatedMessage(msg, field, index) + : ref->GetMessage(msg, field), + jumpLines, s, lineNo, indent + 2); + break; } } diff --git a/framework/cybertron/tools/cvt/monitor/general_message_base.h b/framework/cybertron/tools/cvt/monitor/general_message_base.h index d0bd2b185fa7262eef18316adf70c032342248ec..4b12f200d7def405921b19b7a2b320c806ca49cc 100644 --- a/framework/cybertron/tools/cvt/monitor/general_message_base.h +++ b/framework/cybertron/tools/cvt/monitor/general_message_base.h @@ -26,9 +26,13 @@ class GeneralMessageBase : public RenderableMessage { protected: enum { Type = 0 }; static void PrintMessage(GeneralMessageBase* baseMsg, - const google::protobuf::Message& msg, - const Screen* s, unsigned& lineNo, int indent, - int jumpLines = 0); + const google::protobuf::Message& msg, int& jumpLines, + const Screen* s, unsigned& lineNo, int indent); + static void PrintField(GeneralMessageBase* baseMsg, + const google::protobuf::Message& msg, int& jumpLines, + const Screen* s, unsigned& lineNo, int indent, + const google::protobuf::Reflection* ref, const google::protobuf::FieldDescriptor* field, + int index); static int lineCount(const google::protobuf::Message& msg, int screenWidth); static int lineCountOfField(const google::protobuf::Message& msg, diff --git a/framework/cybertron/tools/cvt/monitor/main.cpp b/framework/cybertron/tools/cvt/monitor/main.cpp index 1749c9c0599106b887291d70738476a32f2ed223..f372acfdcf6680a724675802a84aa973417e472b 100644 --- a/framework/cybertron/tools/cvt/monitor/main.cpp +++ b/framework/cybertron/tools/cvt/monitor/main.cpp @@ -31,23 +31,56 @@ void SigResizeHandle(int) { Screen::Instance()->Resize(); } void printHelp(const char* cmdName) { std::cout << "Usage:\n" - << cmdName << " run this tool\n" + << cmdName << " [option]\nOption:\n" << " -h print help info\n" - << "\nInteractive Command:\n" + << " -c specify one channel\n" + << "Interactive Command:\n" << Screen::InteractiveCmdStr << std::endl; } + +enum COMMAND { + TOO_MANY_PARAMETER, + HELP, // 2 + NO_OPTION, // 1 + CHANNEL // 3 -> 4 +}; + +COMMAND parseOption(int argc, char* const argv[], std::string& commandVal){ + if(argc > 4) return TOO_MANY_PARAMETER; + int index = 1; + while(true) { + const char* opt = argv[index]; + if(opt == nullptr) break; + if(strcmp(opt, "-h") == 0) return HELP; + if(strcmp(opt, "-c") == 0) { + if(argv[index + 1]){ + commandVal = argv[index + 1]; + return CHANNEL; + } + } + + ++index; + } + + return NO_OPTION; +} + + } // namespace int main(int argc, char* argv[]) { - if (argc > 2) { - std::cout << "Too many parameters\n"; - printHelp(argv[0]); - return 0; - } else if (argc == 2) { - if (strcmp(argv[1], "-h") == 0) { + std::string val; + + COMMAND com = parseOption(argc, argv, val); + + switch(com){ + case TOO_MANY_PARAMETER: + std::cout << "Too many paramtes\n"; + case HELP: printHelp(argv[0]); return 0; - } + + default:; } apollo::cybertron::Init(argv[0]); @@ -60,7 +93,7 @@ int main(int argc, char* argv[]) { GeneralChannelMessage::Instance); f->SetDefaultChildFactory("apollo::cybertron::message::RawMessage"); - CybertronTopologyMessage topologyMsg; + CybertronTopologyMessage topologyMsg(val); auto topologyCallback = [&topologyMsg](const apollo::cybertron::proto::ChangeMsg& change_msg) { diff --git a/framework/cybertron/tools/cvt/monitor/renderable_message.h b/framework/cybertron/tools/cvt/monitor/renderable_message.h index 07614ea452eb7cd87263c745cb9c56c3c7704b1b..d4c400f61ae77ec97a35754480ee4ea8f5931acd 100644 --- a/framework/cybertron/tools/cvt/monitor/renderable_message.h +++ b/framework/cybertron/tools/cvt/monitor/renderable_message.h @@ -40,7 +40,7 @@ class Screen; class RenderableMessage { public: explicit RenderableMessage(RenderableMessage* parent = nullptr, int lineNo = 0) - : line_no_(lineNo), pages_(1), page_index_(0), parent_(parent) {} + : line_no_(lineNo), pages_(1), page_index_(0), page_item_count_(24), parent_(parent) {} virtual ~RenderableMessage() { parent_ = nullptr; } @@ -55,6 +55,8 @@ class RenderableMessage { } virtual RenderableMessage* Child(int /* lineNo */) const { return nullptr; } + + int page_item_count(void)const{ return page_item_count_; } protected: int* line_no(void) { return &line_no_; } @@ -65,6 +67,7 @@ class RenderableMessage { int line_no_; int pages_; int page_index_; + int page_item_count_; RenderableMessage* parent_; friend class Screen; diff --git a/framework/cybertron/tools/cvt/monitor/screen.cpp b/framework/cybertron/tools/cvt/monitor/screen.cpp index 7595cd94b6c5e2379f1e74412d3da12a772b1354..3e79adb93cf5a437806b74823a0d3a8eca105211 100644 --- a/framework/cybertron/tools/cvt/monitor/screen.cpp +++ b/framework/cybertron/tools/cvt/monitor/screen.cpp @@ -111,6 +111,7 @@ int Screen::Width(void) const { return COLS; } int Screen::Height(void) const { return LINES; } void Screen::SetCurrentColor(ColorPair color) const { + if(color == INVALID) return; if (IsInit()) { current_color_pair_ = color; attron(COLOR_PAIR(color)); @@ -128,9 +129,9 @@ void Screen::AddStr(const char* str) const { } } -void Screen::ClearCurrentColor(ColorPair color) const { +void Screen::ClearCurrentColor(void) const { if (IsInit()) { - attroff(COLOR_PAIR(color)); + attroff(COLOR_PAIR(current_color_pair_)); current_color_pair_ = INVALID; } } @@ -159,14 +160,14 @@ void Screen::HighlightLine(int lineNo) { ch &= A_CHARTEXT; if (ch == ' ') mvaddch(lineNo + highlight_direction_, x, ch); } - ClearCurrentColor(WHITE_BLACK); + ClearCurrentColor(); SetCurrentColor(BLACK_WHITE); for (int x = 0; x < Width(); ++x) { int ch = mvinch(lineNo, x); mvaddch(lineNo, x, ch & A_CHARTEXT); } - ClearCurrentColor(BLACK_WHITE); + ClearCurrentColor(); } } @@ -296,5 +297,5 @@ void Screen::ShowInteractiveCmd(int) { ptr = sub + 1; } - ClearCurrentColor(Screen::WHITE_BLACK); + ClearCurrentColor(); } diff --git a/framework/cybertron/tools/cvt/monitor/screen.h b/framework/cybertron/tools/cvt/monitor/screen.h index cac778ca2d4c7bdd149ea4fd562b4a8294a1bf7b..0b949195648e29baf4c2b6042c4957dfe8202dd4 100644 --- a/framework/cybertron/tools/cvt/monitor/screen.h +++ b/framework/cybertron/tools/cvt/monitor/screen.h @@ -57,7 +57,7 @@ class Screen final { void AddStr(int x, int y, const char* str) const; void AddStr(const char* str) const; void MoveOffsetXY(int offsetX, int offsetY) const; - void ClearCurrentColor(ColorPair color) const; + void ClearCurrentColor(void) const; void SetCurrentRenderMessage(RenderableMessage* const renderObj) { if (renderObj) { diff --git a/modules/tools/visualizer/channel_reader.h b/modules/tools/visualizer/channel_reader.h index 098c7bb277fe4d841b4179631da990408fb32259..44230dc4bb128aeaf3c9aa8a0d0afda8b35aeb80 100644 --- a/modules/tools/visualizer/channel_reader.h +++ b/modules/tools/visualizer/channel_reader.h @@ -47,34 +47,34 @@ class CyberChannReader : public QThread { } } + bool InstallCallbackAndOpen(CyberChannelCallback channelCallback, + const std::string& channelName, const std::string& nodeName) { + + return InstallCallback(channelCallback) && OpenChannel(channelName, nodeName); + } + bool InstallCallback(CyberChannelCallback channelCallback) { if (channelCallback != nullptr) { channel_callback_ = channelCallback; return true; } else { + std::cerr << "Parameter readerCallback is null" << std::endl; return false; } } - bool InstallCallbackAndOpen(CyberChannelCallback channelCallback, - const std::string& channelName) { - if (channelCallback == nullptr || channelName.empty()) { - std::cout << "Parameter readerCallback is null" << std::endl; + bool OpenChannel(const std::string& channelName, const std::string& nodeName) { + if(channelName.empty() || nodeName.empty()){ + std::cerr << "Channel Name or Node Name must be not empty" << std::endl; return false; } - channel_callback_ = channelCallback; - - return OpenChannel(channelName); - } - - bool OpenChannel(const std::string& channelName) { if (channel_node_ != nullptr || channel_reader_ != nullptr || !channel_callback_) { return false; } - return CreateChannel(channelName); + return CreateChannel(channelName, nodeName); } const std::string& NodeName(void) const { return channel_node_->Name(); } @@ -87,9 +87,9 @@ class CyberChannReader : public QThread { void run() override { apollo::cybertron::WaitForShutdown(); } private: - bool CreateChannel(const std::string& channelName) { + bool CreateChannel(const std::string& channelName, const std::string& nodeName) { if (channel_node_ == nullptr) { - channel_node_ = apollo::cybertron::CreateNode("CyberChannReader"); + channel_node_ = apollo::cybertron::CreateNode(nodeName); if (channel_node_ == nullptr) { return false; } diff --git a/modules/tools/visualizer/main_window.cc b/modules/tools/visualizer/main_window.cc index d7d160e7822d6236a6671c38c38b1d68d09d2539..b5bb4978c29e5d1a7e01143af792e9abfdec7cc6 100644 --- a/modules/tools/visualizer/main_window.cc +++ b/modules/tools/visualizer/main_window.cc @@ -653,10 +653,11 @@ void MainWindow::PlayRenderableObject(bool b) { [this](const std::shared_ptr& pdata) { this->PointCloudReaderCallback(pdata); }; - + std::string nodeName("Visualizer-"); + nodeName.append(pointcloud_top_item_->text(0).toStdString()); if (!pointcloud_channel_Reader_->InstallCallbackAndOpen( - pointCallback, - pointcloud_comboBox_->currentText().toStdString())) { + pointCallback, pointcloud_comboBox_->currentText().toStdString(), + nodeName)) { QMessageBox::warning( this, tr("Settup Channel Callback"), tr("Channel Callback cannot be installed!!!\nPlease check it!"), @@ -704,8 +705,9 @@ void MainWindow::ImageReaderCallback( << std::endl; } } else { - std::cerr << "----Dynamic Texture is nullptr or apollo.drivers.Image is nullptr" - << std::endl; + std::cerr + << "----Dynamic Texture is nullptr or apollo.drivers.Image is nullptr" + << std::endl; } theVideoImgProxy->reader_mutex_.unlock(); } @@ -746,9 +748,12 @@ void MainWindow::DoPlayVideoImage(bool b, VideoImgProxy* theVideoImg) { this->ImageReaderCallback(pdata, theVideoImg); }; + std::string nodeName("Visualizer-"); + nodeName.append(theVideoImg->root_item_.text(0).toStdString()); if (!theVideoImg->channel_reader_->InstallCallbackAndOpen( - videoCallback, theVideoImg->channel_name_combobox_.currentText() - .toStdString())) { + videoCallback, + theVideoImg->channel_name_combobox_.currentText().toStdString(), + nodeName)) { QMessageBox::warning( this, tr("Settup Channel Callback"), tr("Channel Callback cannot be installed!!!\nPlease check it!"), @@ -787,8 +792,10 @@ void MainWindow::DoPlayVideoImage(bool b, VideoImgProxy* theVideoImg) { void MainWindow::ChangePointCloudChannel() { if (pointcloud_channel_Reader_ != nullptr) { pointcloud_channel_Reader_->CloseChannel(); + std::string nodeName("Visualizer-"); + nodeName.append(pointcloud_top_item_->text(0).toStdString()); pointcloud_channel_Reader_->OpenChannel( - pointcloud_comboBox_->currentText().toStdString()); + pointcloud_comboBox_->currentText().toStdString(), nodeName); } } @@ -799,7 +806,10 @@ void MainWindow::ChangeVideoImgChannel() { if (theVideoImg->channel_reader_ != nullptr) { theVideoImg->channel_reader_->CloseChannel(); - theVideoImg->channel_reader_->OpenChannel(obj->currentText().toStdString()); + std::string nodeName("Visualizer-"); + nodeName.append(theVideoImg->root_item_.text(0).toStdString()); + theVideoImg->channel_reader_->OpenChannel(obj->currentText().toStdString(), + nodeName); } }