mirror of
https://github.com/westonrobot/ugv_sdk
synced 2023-04-08 06:32:14 +08:00
async_port: fixed return error in SetupPort()
This commit is contained in:
@@ -35,7 +35,10 @@ bool AsyncCAN::SetupPort() {
|
||||
memcpy(ifr.ifr_name, port_.c_str(), iface_name_size);
|
||||
|
||||
const int ioctl_result = ioctl(can_fd_, SIOCGIFINDEX, &ifr);
|
||||
if (ioctl_result < 0) StopService();
|
||||
if (ioctl_result < 0) {
|
||||
StopService();
|
||||
return false;
|
||||
}
|
||||
|
||||
struct sockaddr_can addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
@@ -44,12 +47,15 @@ bool AsyncCAN::SetupPort() {
|
||||
|
||||
const int bind_result =
|
||||
bind(can_fd_, (struct sockaddr *)&addr, sizeof(addr));
|
||||
if (bind_result < 0) StopService();
|
||||
if (bind_result < 0) {
|
||||
StopService();
|
||||
return false;
|
||||
}
|
||||
|
||||
port_opened_ = true;
|
||||
std::cout << "Start listening to port: " << port_ << std::endl;
|
||||
} catch (std::system_error &e) {
|
||||
std::cout << e.what();
|
||||
std::cout << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,8 @@ bool AsyncSerial::SetupPort() {
|
||||
port_opened_ = true;
|
||||
std::cout << "Start listening to port: " << port_ << "@" << baud_rate_
|
||||
<< std::endl;
|
||||
|
||||
} catch (std::system_error &e) {
|
||||
std::cout << e.what();
|
||||
std::cout << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,12 @@
|
||||
#include "ugv_sdk/utilities/stopwatch.hpp"
|
||||
|
||||
namespace westonrobot {
|
||||
void ProtocolDectctor::Connect(std::string can_name) {
|
||||
bool ProtocolDectctor::Connect(std::string can_name) {
|
||||
can_ = std::make_shared<AsyncCAN>(can_name);
|
||||
can_->SetReceiveCallback(
|
||||
std::bind(&ProtocolDectctor::ParseCANFrame, this, std::placeholders::_1));
|
||||
can_->StartListening();
|
||||
return can_->StartListening();
|
||||
}
|
||||
void ProtocolDectctor::Connect(std::string uart_name, uint32_t baudrate) {}
|
||||
|
||||
ProtocolVersion ProtocolDectctor::DetectProtocolVersion(uint32_t timeout_sec) {
|
||||
msg_v1_detected_ = false;
|
||||
|
||||
Reference in New Issue
Block a user