]> Git Repo - serial.git/commitdiff
Testing my changes to make sure they are consistant.
authorJohn Harrison <[email protected]>
Mon, 30 Jan 2012 22:33:58 +0000 (16:33 -0600)
committerJohn Harrison <[email protected]>
Mon, 30 Jan 2012 22:33:58 +0000 (16:33 -0600)
examples/serial_example.cc
serial.cmake
src/impl/unix.cc
src/serial.cc

index b3a3636b7fce8cdd8c86dc8141c586f3dc08b4d5..788764d2c3762d642db4f1997c9cfa2381241914 100644 (file)
@@ -1,11 +1,21 @@
 #include <string>
 #include <iostream>
 #include <stdio.h>
+#include <time.h>
+
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
 
 #include <boost/thread.hpp>
 
 #include "serial/serial.h"
 
+using std::string;
+using std::cout;
+using std::endl;
+
 int run(int argc, char **argv)
 {
     if(argc < 3) {
@@ -18,7 +28,7 @@ int run(int argc, char **argv)
     sscanf(argv[2], "%lu", &baud);
 
     // port, baudrate, timeout in milliseconds
-    serial::Serial serial(port, baud, 30000);
+    serial::Serial serial(port, baud, 10000);
     
     std::cout << "Is the serial port open?";
     if(serial.isOpen())
@@ -28,13 +38,77 @@ int run(int argc, char **argv)
     
     int count = 0;
     while (count >= 0) {
-        size_t bytes_wrote = serial.write("Testing.\n");
-        std::string result = serial.readline();
+      struct timespec start, end;
+      double diff;
+
+      #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+      clock_serv_t cclock;
+      mach_timespec_t mts;
+      host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      start.tv_sec = mts.tv_sec;
+      start.tv_nsec = mts.tv_nsec;
+
+      #else
+      clock_gettime(CLOCK_REALTIME, &start);
+      #endif
+
+      size_t bytes_wrote = serial.write("Testing.\n");
+
+      #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+      host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      end.tv_sec = mts.tv_sec;
+      end.tv_nsec = mts.tv_nsec;
+
+      #else
+      clock_gettime(CLOCK_REALTIME, &end);
+      #endif
+
+      end.tv_sec -= start.tv_sec;
+      end.tv_nsec -= start.tv_nsec;
+      printf("write: %05lu.%09lu\n", end.tv_sec, end.tv_nsec);
+
+      #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+      host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      start.tv_sec = mts.tv_sec;
+      start.tv_nsec = mts.tv_nsec;
+
+      #else
+      clock_gettime(CLOCK_REALTIME, &start);
+      #endif
+
+      std::string result = serial.readline();
+      #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+      host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+      clock_get_time(cclock, &mts);
+      mach_port_deallocate(mach_task_self(), cclock);
+      end.tv_sec = mts.tv_sec;
+      end.tv_nsec = mts.tv_nsec;
+
+      #else
+      clock_gettime(CLOCK_REALTIME, &end);
+      #endif
+
+
+      end.tv_sec -= start.tv_sec;
+      end.tv_nsec -= start.tv_nsec;
+      printf("read: %05lu.%09lu\n", end.tv_sec, end.tv_nsec);
+      
+      if (result == string("Testing.\n")) {
+      }
+      else {
         std::cout << ">" << count << ">" << bytes_wrote << ">";
         std::cout << result.length() << "<" << result << std::endl;
+        cout << "No" << endl;
+      }
         
-        count += 1;
-        boost::this_thread::sleep(boost::posix_time::milliseconds(100));
+      count += 1;
+      boost::this_thread::sleep(boost::posix_time::milliseconds(100));
     }
     
     return 0;
index 8fa0f68ad0e8fac6b601f167236c23b32b263bf5..328b91e4baf6962c87aa7c734d2d6ffa270a01c9 100644 (file)
@@ -15,7 +15,7 @@ IF(EXISTS /usr/bin/clang)
   set(CMAKE_CXX_COMPILER /usr/bin/clang++)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
   # set(CMAKE_CXX_FLAGS "-ferror-limit=5 -std=c++0x -stdlib=libc++")
-  set(CMAKE_CXX_FLAGS "-ferror-limit=5 -O3 -Wall -Weffc++ -pedantic -pedantic-errors -Wextra  -Wall -Waggregate-return -Wcast-align -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion -Wdisabled-optimization -Wfloat-equal  -Wformat  -Wformat=2 -Wformat-nonliteral -Wformat-security  -Wformat-y2k -Wimplicit  -Wimport  -Winit-self  -Winline -Winvalid-pch   -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute   -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wparentheses  -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default -Wswitch-enum -Wtrigraphs  -Wuninitialized -Wunknown-pragmas  -Wunreachable-code -Wunused -Wunused-function  -Wunused-label  -Wunused-parameter -Wunused-value  -Wunused-variable  -Wvariadic-macros -Wvolatile-register-var  -Wwrite-strings")
+  set(CMAKE_CXX_FLAGS "-ferror-limit=5 -Wall -Weffc++ -pedantic -pedantic-errors -Wextra  -Wall -Waggregate-return -Wcast-align -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion -Wdisabled-optimization -Wfloat-equal  -Wformat  -Wformat=2 -Wformat-nonliteral -Wformat-security  -Wformat-y2k -Wimplicit  -Wimport  -Winit-self  -Winline -Winvalid-pch   -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute   -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wparentheses  -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default -Wswitch-enum -Wtrigraphs  -Wuninitialized -Wunknown-pragmas  -Wunreachable-code -Wunused -Wunused-function  -Wunused-label  -Wunused-parameter -Wunused-value  -Wunused-variable  -Wvariadic-macros -Wvolatile-register-var  -Wwrite-strings")
   set(CMAKE_BUILD_TYPE Debug)
 ENDIF(EXISTS /usr/bin/clang)
 
index dae30debc484182f8fb08f8b429129f1c1d51d7c..c621d04df49fe77ccbeb8812438d1a435b52877b 100644 (file)
@@ -368,8 +368,11 @@ Serial::SerialImpl::read (char* buf, size_t size)
   }
   fd_set readfds;
   ssize_t bytes_read = 0;
+  int count = 0;
   while (true)
   {
+    count++;
+    // printf("Counting: %u\n", count);
     if (timeout_ != -1)
     {
       FD_ZERO (&readfds);
index 92623f5c2e02927349bc3deebc51326c6655b5f6..112436c9b29630a4475c4f10924c16d9efba3a9f 100644 (file)
@@ -89,8 +89,10 @@ Serial::read (size_t size)
     string result (read_cache_.substr (0, size));
     read_cache_.clear ();
 
+       int count = 0;
     while (true)
     {
+         // printf("%u\n", count++);
       char buf[256];
       size_t chars_read = pimpl_->read (buf, 256);
       if (chars_read > 0)
This page took 0.032332 seconds and 4 git commands to generate.