mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-11-05 13:29:06 +01:00
Communication: Clear disconnected on open
This commit is contained in:
committed by
Kyle Schwarz
parent
9f747df692
commit
9e49c315ed
@@ -512,6 +512,7 @@ if(LIBICSNEO_BUILD_UNIT_TESTS)
|
|||||||
test/unit/icsneoc2.cpp
|
test/unit/icsneoc2.cpp
|
||||||
test/unit/ethphyregistertest.cpp
|
test/unit/ethphyregistertest.cpp
|
||||||
test/unit/tc10test.cpp
|
test/unit/tc10test.cpp
|
||||||
|
test/unit/communicationtest.cpp
|
||||||
test/unit/periodictest.cpp
|
test/unit/periodictest.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ bool Communication::open() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A heartbeat timeout marks the driver disconnected and leaves the cleanup to the user, a new open starts connected
|
||||||
|
driver->setIsDisconnected(false);
|
||||||
if(!driver->open())
|
if(!driver->open())
|
||||||
return false;
|
return false;
|
||||||
spawnThreads();
|
spawnThreads();
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "icsneo/icsneocpp.h"
|
||||||
|
#include "icsneo/communication/driver.h"
|
||||||
|
#include "icsneo/device/tree/radmoon2/radmoon2zl.h"
|
||||||
|
|
||||||
|
using namespace icsneo;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class ReopenTestDriver : public Driver {
|
||||||
|
public:
|
||||||
|
explicit ReopenTestDriver(const device_eventhandler_t& handler) : Driver(handler) {}
|
||||||
|
|
||||||
|
bool open() override { opened = true; return true; }
|
||||||
|
bool isOpen() override { return opened; }
|
||||||
|
bool close() override { opened = false; return true; }
|
||||||
|
driver_finder_t getFinder() override { return [](std::vector<FoundDevice>&) {}; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool writeInternal(const std::vector<uint8_t>&) override { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool opened = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// The heartbeat marks the driver disconnected and the user closes and opens again. Drivers like Servd stop their
|
||||||
|
// threads while disconnected, so the reopened connection must not start disconnected.
|
||||||
|
TEST(Communication, OpenAfterDisconnectIsConnected) {
|
||||||
|
FoundDevice found;
|
||||||
|
std::memcpy(found.serial, "RN0001", 6);
|
||||||
|
found.makeDriver = [](device_eventhandler_t handler, neodevice_t&) {
|
||||||
|
return std::make_unique<ReopenTestDriver>(handler);
|
||||||
|
};
|
||||||
|
auto device = std::make_shared<RADMoon2ZL>(found);
|
||||||
|
ASSERT_TRUE(device->com->open());
|
||||||
|
|
||||||
|
device->com->driver->setIsDisconnected(true);
|
||||||
|
ASSERT_TRUE(device->com->close());
|
||||||
|
ASSERT_TRUE(device->com->open());
|
||||||
|
EXPECT_FALSE(device->com->isDisconnected());
|
||||||
|
EXPECT_TRUE(device->com->close());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user