提交 7eaf7224 编写于 作者: Z Zeus 提交者: Liangliang Zhang

Cyber_monitor and Visualizer (#691)

* Modules: fix visualizer camera node name issue; Frmaework: fix cyber_monitor page down and incompletely shwo data issues

* Framework : fix monitor bug

* Modules: fix visualizer camera node name issue; Frmaework: fix cyber_monitor page down and incompletely shwo data issues

* Framework : fix monitor bug

* Framework: add channel option (-c) for cyber_monitor

* Framework: fix cyber_monitr option character ('-f' -> '-c')
上级 434015b5
......@@ -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<ChannelMessage*>(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();
}
}
......@@ -18,6 +18,7 @@
#define TOOLS_CVT_MONITOR_CYBERTRON_TOPOLOGY_MESSAGE_H_
#include <map>
#include <string>
#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<std::string, ChannelMessage*> all_channels_map_;
};
......
......@@ -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<std::string>* 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");
}
......
......@@ -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;
......
......@@ -18,86 +18,18 @@
#include "general_channel_message.h"
#include "screen.h"
#include <iomanip>
#include <sstream>
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();
}
......@@ -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_;
......
......@@ -21,6 +21,11 @@
#include <iomanip>
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<const google::protobuf::FieldDescriptor*> 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;
}
}
......
......@@ -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,
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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();
}
......@@ -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) {
......
......@@ -47,34 +47,34 @@ class CyberChannReader : public QThread {
}
}
bool InstallCallbackAndOpen(CyberChannelCallback<T> channelCallback,
const std::string& channelName, const std::string& nodeName) {
return InstallCallback(channelCallback) && OpenChannel(channelName, nodeName);
}
bool InstallCallback(CyberChannelCallback<T> channelCallback) {
if (channelCallback != nullptr) {
channel_callback_ = channelCallback;
return true;
} else {
std::cerr << "Parameter readerCallback is null" << std::endl;
return false;
}
}
bool InstallCallbackAndOpen(CyberChannelCallback<T> 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;
}
......
......@@ -653,10 +653,11 @@ void MainWindow::PlayRenderableObject(bool b) {
[this](const std::shared_ptr<apollo::drivers::PointCloud>& 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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册