Skip to content

Commit dfeaaf4

Browse files
committed
#10 fix:Some code optimization
1 parent 786e67a commit dfeaaf4

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

infinite_sense_core/src/messenger.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void Messenger::Sub(const std::string& topic, const std::function<void(const std
6767
LOG(WARNING) << "Subscription receive failed for topic: " << topic;
6868
continue;
6969
}
70-
std::string received_topic(static_cast<char*>(topic_msg.data()), topic_msg.size());
71-
if (received_topic != topic) {
70+
if (std::string received_topic(static_cast<char*>(topic_msg.data()), topic_msg.size());
71+
received_topic != topic) {
7272
continue;
7373
}
7474
std::string data(static_cast<char*>(data_msg.data()), data_msg.size());
@@ -93,8 +93,8 @@ void Messenger::SubStruct(const std::string& topic, const std::function<void(con
9393
LOG(WARNING) << "Subscription to topic [" << topic << "] failed.";
9494
continue;
9595
}
96-
std::string received_topic(static_cast<char*>(topic_msg.data()), topic_msg.size());
97-
if (received_topic != topic) {
96+
if (std::string received_topic(static_cast<char*>(topic_msg.data()), topic_msg.size());
97+
received_topic != topic) {
9898
continue;
9999
}
100100
callback(data_msg.data(), data_msg.size());

infinite_sense_core/src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void NetManager::Receive() const {
5454
unsigned short source_port = 0;
5555

5656
while (started_) {
57-
int size = net_ptr_->recvFrom(buffer.data(), k_buffer_size, source_address, source_port);
57+
const int size = net_ptr_->recvFrom(buffer.data(), k_buffer_size, source_address, source_port);
5858
if (size <= 0) {
5959
std::this_thread::sleep_for(std::chrono::milliseconds(1));
6060
continue;

infinite_sense_core/src/ptp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void Ptp::SetUsbPtr(const std::shared_ptr<serial::Serial>& serial_ptr) {
1717
}
1818

1919
void Ptp::SetNetPtr(const std::shared_ptr<UDPSocket>& net_ptr, const std::string& target_ip,
20-
unsigned short port) {
20+
const unsigned short port) {
2121
net_ptr_ = net_ptr;
2222
target_ip_ = target_ip;
2323
port_ = port;
@@ -56,7 +56,7 @@ void Ptp::HandleTimeSyncResponse(const nlohmann::json& data) {
5656
const int64_t delay = static_cast<int64_t>(t4 - t3 + time_t2_ - time_t1_) / 2;
5757
const int64_t offset = static_cast<int64_t>(time_t2_ - time_t1_ - t4 + t3) / 2;
5858

59-
nlohmann::json response = {
59+
const nlohmann::json response = {
6060
{func_name, func_type_b},
6161
{func_type_a, delay},
6262
{func_type_b, offset},
@@ -73,7 +73,7 @@ void Ptp::HandleTimeSyncResponse(const nlohmann::json& data) {
7373
void Ptp::SendPtpData() const {
7474
const uint64_t mark = GetCurrentTimeUs();
7575

76-
nlohmann::json data = {
76+
const nlohmann::json data = {
7777
{func_name, func_type_a},
7878
{func_type_a, mark},
7979
};

infinite_sense_core/src/usb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace infinite_sense {
77

8-
UsbManager::UsbManager(std::string port, int baud_rate) : port_(std::move(port)), started_(false) {
8+
UsbManager::UsbManager(std::string port, const int baud_rate) : port_(std::move(port)), started_(false) {
99
serial_ptr_ = std::make_unique<serial::Serial>();
1010
try {
1111
serial_ptr_->setPort(port_);

0 commit comments

Comments
 (0)