diff --git a/src/slam_wrapper.cpp b/src/slam_wrapper.cpp index 47464f8..7da65b4 100644 --- a/src/slam_wrapper.cpp +++ b/src/slam_wrapper.cpp @@ -23,26 +23,24 @@ } void SlamWrapper::qt_notice_handler(const void *message) { - int index_, begin_, end_, feedback_, arrive_; - auto seq = static_cast(message); - std::string str_, notice_; + const auto seq = static_cast(message); + std::string str_; - begin_ = seq->data().find("index:", 0); // Instruction unique identifier - end_ = seq->data().find(";", begin_); + int begin_ = seq->data().find("index:", 0); // Instruction unique identifier + int end_ = seq->data().find(";", begin_); str_ = seq->data().substr(begin_ + 6, end_ - begin_ - 6); - index_ = atoi(str_.c_str()); + const int index_ = atoi(str_.c_str()); begin_ = seq->data().find("notice:", 0); // Prompt message end_ = seq->data().find(";", begin_); - notice_ = seq->data().substr(begin_ + 7, end_ - begin_ - 7); + const std::string notice_ = seq->data().substr(begin_ + 7, end_ - begin_ - 7); if (index_ <= 10000) { // Command execution feedback begin_ = seq->data().find("feedback:", 0); end_ = seq->data().find(";", begin_); str_ = seq->data().substr(begin_ + 9, end_ - begin_ - 9); - feedback_ = atoi(str_.c_str()); - if (feedback_ == 0 || feedback_ == -1) + if (const int feedback_ = atoi(str_.c_str()); feedback_ == 0 || feedback_ == -1) std::cout << "\033[1;31m" << "Command execution failed with index = " << index_ << "." << "\033[0m"; @@ -52,7 +50,7 @@ begin_ = seq->data().find("arrive:", 0); end_ = seq->data().find(";", begin_); str_ = seq->data().substr(begin_ + 7, end_ - begin_ - 7); - arrive_ = atoi(str_.c_str()); + const int arrive_ = atoi(str_.c_str()); std::cout << " I arrived node " << arrive_ << ". " << notice_ << std::endl; if (arrive_ == 1) { //发送暂停指令