30constexpr int ReaderWriterOffset = 4;
31using apollo::cyber::record::kGB;
32using apollo::cyber::record::kKB;
33using apollo::cyber::record::kMB;
41 ret =
"Cannot Create Parser Object";
45 ret =
"Cannot Create Cyber Node";
49 ret =
"Cannot Create Cyber Reader";
53 ret =
"Message Type is Empty";
57 ret =
"Channel Name or Node Name is Empty";
61 ret =
"No Close Channel";
65 ret =
"Unknown Error Code";
93 auto interval = time_now - time_last_calc_;
94 if (interval.ToNanosecond() > 1000000000) {
95 int old = frame_counter_;
96 while (!frame_counter_.compare_exchange_strong(old, 0)) {
101 auto curMsgTime = msg_time_;
102 auto deltaTime = curMsgTime - last_time_;
104 last_time_ = curMsgTime;
105 time_last_calc_ = time_now;
111 const std::string& channel_name) {
112 if (channel_name.empty() || node_name_.empty()) {
115 if (channel_node_ !=
nullptr || channel_reader_ !=
nullptr) {
120 if (channel_node_ ==
nullptr) {
125 [
this, channel_name](
126 const std::shared_ptr<apollo::cyber::message::RawMessage>& raw_msg) {
127 UpdateRawMessage(raw_msg);
128 UpdateChannelName(channel_name);
133 channel_name, callback);
134 if (channel_reader_ ==
nullptr) {
135 channel_node_.reset();
145 current_state_ = State::ShowDebugString;
150 current_state_ = State::ShowInfo;
163 s->
AddStr(channel_reader_->GetChannelName().c_str());
169 switch (current_state_) {
170 case State::ShowDebugString:
171 RenderDebugString(s, key, &
line_no);
173 case State::ShowInfo:
185void GeneralChannelMessage::RenderInfo(
const Screen* s,
int key,
int* line_no) {
187 pages_ =
static_cast<int>(readers_.size() + writers_.size() + *
line_no) /
192 bool has_reader =
true;
193 std::vector<std::string>* vec = &readers_;
195 auto iter = vec->cbegin();
197 if (y < vec->size()) {
198 for (
unsigned i = 0; i < y; ++i) {
202 y -=
static_cast<unsigned int>(vec->size());
204 iter = vec->cbegin();
215 for (; iter != vec->cend(); ++iter) {
221 iter = vec->cbegin();
225 for (; iter != vec->cend(); ++iter) {
230void GeneralChannelMessage::RenderDebugString(
const Screen* s,
int key,
233 if (raw_msg_class_ ==
nullptr) {
234 auto rawFactory = apollo::cyber::message::ProtobufFactory::Instance();
235 raw_msg_class_ = rawFactory->GenerateMessageByType(
message_type());
238 if (raw_msg_class_ ==
nullptr) {
239 s->
AddStr(0, (*
line_no)++,
"Cannot Generate Message by Message Type");
243 std::ostringstream out_str;
246 s->
AddStr(out_str.str().c_str());
248 decltype(channel_message_) channel_msg = CopyMsgPtr();
250 if (channel_msg->message.size()) {
253 out_str << channel_msg->message.size() <<
" Bytes";
254 if (channel_msg->message.size() >= kGB) {
256 <<
static_cast<float>(channel_msg->message.size()) / kGB
258 }
else if (channel_msg->message.size() >= kMB) {
260 <<
static_cast<float>(channel_msg->message.size()) / kMB
262 }
else if (channel_msg->message.size() >= kKB) {
264 <<
static_cast<float>(channel_msg->message.size()) / kKB
267 s->
AddStr(out_str.str().c_str());
268 if (raw_msg_class_->ParseFromString(channel_msg->message)) {
282 s->
AddStr(0, (*
line_no)++,
"The size of this raw Message is Zero");
int Render(const Screen *s, int key) override
bool has_message_come(void) const
static bool IsErrorCode(void *ptr)
@ ChannelNameOrNodeNameIsEmpty
bool is_enabled(void) const
const std::string & message_type(void) const
static const char * ErrCode2Str(ErrorCode errCode)
double frame_ratio(void) override
static GeneralChannelMessage * CastErrorCode2Ptr(ErrorCode errCode)
static int LineCount(const google::protobuf::Message &msg, int screen_width)
static void PrintMessage(GeneralMessageBase *baseMsg, const google::protobuf::Message &msg, int *jump_lines, const Screen *s, int *line_no, int indent)
static constexpr int FrameRatio_Precision
void AddStr(int x, int y, ColorPair color, const char *str) const
void SetCurrentColor(ColorPair color) const
void ClearCurrentColor(void) const
double ToSecond() const
convert time to second.
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)