mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Correcting some bad logic and making my test run forever to try to judge some basic performance characteristics.
This commit is contained in:
parent
f81268fdf0
commit
50972cbf41
@ -106,12 +106,17 @@ IF(SERIAL_BUILD_TESTS)
|
||||
|
||||
# Compile the Serial Listener Test program
|
||||
add_executable(serial_listener_tests tests/serial_listener_tests.cc)
|
||||
add_executable(serial_tests tests/serial_tests.cc)
|
||||
# Link the Test program to the serial library
|
||||
target_link_libraries(serial_listener_tests ${GTEST_BOTH_LIBRARIES}
|
||||
serial)
|
||||
target_link_libraries(serial_tests ${GTEST_BOTH_LIBRARIES}
|
||||
serial)
|
||||
|
||||
# # See: http://code.google.com/p/googlemock/issues/detail?id=146
|
||||
# add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
|
||||
add_test(AllTestsIntest_serial serial_listener_tests)
|
||||
add_test(AllTestsIntest_serial serial_tests)
|
||||
ENDIF(SERIAL_BUILD_TESTS)
|
||||
|
||||
## Setup install and uninstall
|
||||
|
||||
@ -226,8 +226,8 @@ Serial::SerialImpl::read (size_t size) {
|
||||
fd_set readfds;
|
||||
memset(buf, 0, (size + 1) * sizeof(*buf));
|
||||
ssize_t bytes_read = 0;
|
||||
while (message.length() < size) {
|
||||
if (timeout_ == -1) {
|
||||
while (bytes_read < size) {
|
||||
if (timeout_ != -1) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd_, &readfds);
|
||||
struct timeval timeout;
|
||||
@ -244,7 +244,7 @@ Serial::SerialImpl::read (size_t size) {
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout_ == 1 || FD_ISSET(fd_, &readfds)) {
|
||||
if (timeout_ == -1 || FD_ISSET(fd_, &readfds)) {
|
||||
ssize_t newest_read = ::read(fd_,
|
||||
buf + bytes_read,
|
||||
size - static_cast<size_t>(bytes_read));
|
||||
|
||||
@ -16,14 +16,15 @@ using std::endl;
|
||||
using serial::Serial;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Serial s("/dev/tty.usbserial-A900adHq", 9600, 2000);
|
||||
Serial s("/dev/tty.usbserial-A900adHq", 115200, 2000);
|
||||
s.flush();
|
||||
int count = 0;
|
||||
while (count < 10) {
|
||||
while (1) {
|
||||
size_t available = s.available();
|
||||
cout << "avialable: " << available << endl;
|
||||
string line = s.readline();
|
||||
cout << count << ": " << line;
|
||||
count++;
|
||||
}
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user