Skip to content

Commit

Permalink
Add port name to logs (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
KraPete authored Dec 4, 2024
1 parent d1cacf9 commit 8488a6a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wb-mqtt-serial (2.149.1) stable; urgency=medium

* Add port name to logs

-- Vladimir Romanov <v.romanov@wirenboard.com> Tue, 03 Dec 2024 11:30:19 +0500

wb-mqtt-serial (2.149.0) stable; urgency=medium

* Add template for WBE2-I-OPENTHERM-FW-1-7-3
Expand Down
6 changes: 5 additions & 1 deletion src/serial_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ TSerialDevice::TSerialDevice(PDeviceConfig config, PPort port, PProtocol protoco

std::string TSerialDevice::ToString() const
{
return Protocol()->GetName() + ":" + DeviceConfig()->SlaveId;
auto portDescription = Port()->GetDescription();
if (!portDescription.empty()) {
portDescription += " ";
}
return portDescription + Protocol()->GetName() + ":" + DeviceConfig()->SlaveId;
}

PRegisterRange TSerialDevice::CreateRegisterRange() const
Expand Down
7 changes: 4 additions & 3 deletions test/fake_serial_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace
const auto DB_PATH = "/tmp/wb-mqtt-serial-test.db";
}

TFakeSerialPort::TFakeSerialPort(TLoggedFixture& fixture, const std::string& portName)
TFakeSerialPort::TFakeSerialPort(TLoggedFixture& fixture, const std::string& portName, bool emptyDescription)
: Fixture(fixture),
AllowOpen(true),
IsPortOpen(false),
Expand All @@ -31,7 +31,8 @@ TFakeSerialPort::TFakeSerialPort(TLoggedFixture& fixture, const std::string& por
RespPos(0),
DumpPos(0),
BaudRate(9600),
PortName(portName)
PortName(portName),
EmptyDescription(emptyDescription)
{}

void TFakeSerialPort::SetExpectedFrameTimeout(const std::chrono::microseconds& timeout)
Expand Down Expand Up @@ -273,7 +274,7 @@ std::chrono::microseconds TFakeSerialPort::GetSendTimeBytes(double bytesNumber)

std::string TFakeSerialPort::GetDescription(bool verbose) const
{
return PortName;
return EmptyDescription ? "" : PortName;
}

void TFakeSerialPort::SetBaudRate(size_t value)
Expand Down
5 changes: 4 additions & 1 deletion test/fake_serial_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class TFakeSerialPort: public TPort, public TExpector
BadFileDescriptorOnWriteAndRead //! Port can be successfully open, but all operations fail with EBADF
};

TFakeSerialPort(WBMQTT::Testing::TLoggedFixture& fixture, const std::string& portName);
TFakeSerialPort(WBMQTT::Testing::TLoggedFixture& fixture,
const std::string& portName,
bool emptyDescription = true);

void SetExpectedFrameTimeout(const std::chrono::microseconds& timeout);
void CheckPortOpen() const override;
Expand Down Expand Up @@ -70,6 +72,7 @@ class TFakeSerialPort: public TPort, public TExpector
std::chrono::microseconds ExpectedFrameTimeout = std::chrono::microseconds(-1);
size_t BaudRate;
std::string PortName;
bool EmptyDescription;
};

typedef std::shared_ptr<TFakeSerialPort> PFakeSerialPort;
Expand Down
2 changes: 1 addition & 1 deletion test/serial_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ TEST_F(TSerialClientIntegrationTest, SlaveIdCollision)

auto factory = [=](const Json::Value& port_data, PRPCConfig rpcConfig) -> std::pair<PPort, bool> {
auto path = port_data["path"].asString();
return std::make_pair(std::make_shared<TFakeSerialPort>(*this, path), false);
return std::make_pair(std::make_shared<TFakeSerialPort>(*this, path, false), false);
};

EXPECT_THROW(LoadConfig(GetDataFilePath("configs/config-collision-test.json"),
Expand Down

0 comments on commit 8488a6a

Please sign in to comment.