Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Breaking Changes
now obtained through the streaming port instead of an RPC.
This new feature is implemented through a breaking change in the definition of data fields in `stateExt.thrift`

* `ISerialDevice` interface was refactored to use `yarp::dev::ReturnValue`. Some methods changed their signature
to improve interface usability.
Affected devices: `serialPort_nwc_yarp`, `serialPort_nws_yarp`, `fakeSerialPort`, `serialDeviceDriver`

### libYARP_sig

* Removed field `topIsLow` from `yarp::sig::Image`
106 changes: 56 additions & 50 deletions src/devices/fake/fakeSerialPort/FakeSerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,119 +38,125 @@ bool FakeSerialPort::close()
return true;
}

bool FakeSerialPort::setDTR(bool value)
ReturnValue FakeSerialPort::setDTR(bool value)
{
return true;
return ReturnValue_ok;
}

bool FakeSerialPort::send(const Bottle& msg)
ReturnValue FakeSerialPort::sendString(const std::string& msg)
{
if (msg.size() > 0)
{
int message_size = msg.get(0).asString().length();
size_t message_size = msg.size();

if (message_size > 0)
{
if (verbose)
{
yCDebug(FAKESERIALPORT, "Sending string: %s", msg.get(0).asString().c_str());
}
}
else
if (message_size > 0)
{
if (verbose)
{
if (verbose)
{
yCDebug(FAKESERIALPORT, "The input command bottle contains an empty string.");
}
return false;
yCDebug(FAKESERIALPORT, "Sending string: %s", msg.c_str());
}
}
else
{
if (verbose)
{
yCDebug(FAKESERIALPORT, "The input command bottle is empty. \n");
yCDebug(FAKESERIALPORT, "The string contains an empty string.");
}
return false;
return yarp::dev::ReturnValue::return_code::return_value_error_method_failed;
}

return true;
return ReturnValue_ok;
}

bool FakeSerialPort::send(const char *msg, size_t size)
ReturnValue FakeSerialPort::sendByte(unsigned char byt)
{
if (size > 0)
yCInfo(FAKESERIALPORT, "sent byte : %c \n", byt);
return ReturnValue_ok;
}

ReturnValue FakeSerialPort::sendBytes(const std::vector<unsigned char>& msg)
{
if (msg.size() > 0)
{
if (verbose)
{
yCDebug(FAKESERIALPORT, "Sending string: %s", msg);
}

// Write message in the serial device
size_t bytes_written = size;
size_t bytes_written = msg.size();

if (bytes_written == -1)
{
yCError(FAKESERIALPORT, "Unable to write to serial port");
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}
else
{
if (verbose) {
yCDebug(FAKESERIALPORT, "The input message is empty. \n");
}
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}

yCInfo (FAKESERIALPORT, "sent command: %s \n",msg);
return true;
return ReturnValue_ok;
}

int FakeSerialPort::receiveChar(char& c)
ReturnValue FakeSerialPort::receiveByte(unsigned char& c)
{
char chr='c';
char chr='R';

size_t bytes_read = 1;

if (bytes_read == -1)
{
yCError(FAKESERIALPORT, "Error in SerialDeviceDriver::receive()");
return 0;
return ReturnValue::return_code::return_value_error_method_failed;
}

if (bytes_read == 0)
{
return 0;
return ReturnValue::return_code::return_value_error_method_failed;
}

c=chr;
return 1;
return ReturnValue_ok;
}

int FakeSerialPort::flush()
ReturnValue FakeSerialPort::flush()
{
return 1;
size_t dummy_counter = 0;
return flush(dummy_counter);
}

int FakeSerialPort::receiveBytes(unsigned char* bytes, const int size)
ReturnValue FakeSerialPort::flush(size_t& flushed)
{
for (size_t i=0; i< size; i++)
bytes[i]='0'+i;
return size;
flushed = 3;
return ReturnValue_ok;
}

int FakeSerialPort::receiveLine(char* buffer, const int MaxLineLength)
ReturnValue FakeSerialPort::receiveBytes(std::vector<unsigned char>& line, const int MaxSize)
{
line.clear();
line.resize(1000);
for (size_t i = 0; i < MaxSize; i++)
{
line[i]= ('0' + i);
}
return ReturnValue_ok;
}

ReturnValue FakeSerialPort::receiveLine(std::vector<char>& line, const int MaxLineLength)
{
int i;
for (i = 0; i < MaxLineLength -1; ++i)
{
char recv_ch;
int n = receiveChar(recv_ch);
if (n <= 0)
unsigned char recv_ch;
auto ret = receiveByte(recv_ch);
if (!ret)
{
//this invalidates the whole line, because no line terminator \n was found
return 0;
return ReturnValue::return_code::return_value_error_method_failed;

//use this commented code here if you do NOT want to invalidate the line
//buffer[i] = '\0';
Expand All @@ -168,7 +174,7 @@ int FakeSerialPort::receiveLine(char* buffer, const int MaxLineLength)
return i;
}

bool FakeSerialPort::receive(Bottle& msg)
ReturnValue FakeSerialPort::receiveString(std::string& msg)
{
char message[10] = "123456789";

Expand All @@ -178,11 +184,11 @@ bool FakeSerialPort::receive(Bottle& msg)
if (bytes_read == -1)
{
yCError(FAKESERIALPORT, "Error in SerialDeviceDriver::receive()");
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}

if (bytes_read == 0) { //nothing there
return true;
return ReturnValue_ok;
}

message[bytes_read] = 0;
Expand All @@ -193,8 +199,8 @@ bool FakeSerialPort::receive(Bottle& msg)
}


// Put message in the bottle
msg.addString(message);
// Return the message
msg=message;

return true;
return ReturnValue_ok;
}
18 changes: 10 additions & 8 deletions src/devices/fake/fakeSerialPort/FakeSerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ class FakeSerialPort :
bool open(yarp::os::Searchable& config) override;
bool close() override;

bool send(const Bottle& msg) override;
bool send(const char *msg, size_t size) override;
bool receive(Bottle& msg) override;
int receiveChar(char& chr) override;
int receiveBytes(unsigned char* bytes, const int size) override;
int receiveLine(char* line, const int MaxLineLength) override;
bool setDTR(bool value) override;
int flush() override;
yarp::dev::ReturnValue sendString(const std::string& msg) override;
yarp::dev::ReturnValue sendBytes(const std::vector<unsigned char>& line) override;
yarp::dev::ReturnValue sendByte(unsigned char byte) override;
yarp::dev::ReturnValue receiveString(std::string& msg) override;
yarp::dev::ReturnValue receiveBytes(std::vector<unsigned char>& line, const int MaxSize) override;
yarp::dev::ReturnValue receiveByte(unsigned char& chr) override;
yarp::dev::ReturnValue receiveLine(std::vector<char>& line, const int MaxLineLength) override;
yarp::dev::ReturnValue setDTR(bool enable) override;
yarp::dev::ReturnValue flush() override;
yarp::dev::ReturnValue flush(size_t& flushed_chars) override;
};

#endif
12 changes: 7 additions & 5 deletions src/devices/fake/fakeSerialPort/tests/fakeSerialPort_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <yarp/os/Network.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/WrapperSingle.h>
//#include <yarp/dev/tests/ILocalization2DTest.h>
#include <yarp/dev/tests/ISerialTest.h>

#include <catch2/catch_amalgamated.hpp>
#include <harness.h>
Expand All @@ -23,10 +23,10 @@ TEST_CASE("dev::fakeSerialPort", "[yarp::dev]")

SECTION("Checking fakeSerialPort device")
{
yarp::dev::ISerialDevice* iser=nullptr;
yarp::dev::ISerialDevice* iser = nullptr;
PolyDriver ddfake;

//open the device
// open the device
{

Property pdev_cfg;
Expand All @@ -38,8 +38,10 @@ TEST_CASE("dev::fakeSerialPort", "[yarp::dev]")
REQUIRE(iser);
}

iser->flush();
//yarp::dev::tests::exec_iLocalization2D_test_1(iser);
// tests
{
yarp::dev::tests::exec_iSerial_test_1(iser);
}

//"Close all polydrivers and check"
{
Expand Down
Loading
Loading