xx

Files at this revision

API Documentation at this revision

Comitter:
anfontanelli
Date:
Tue Sep 14 12:09:42 2021 +0000
Parent:
11:04d8899b5d82
Commit message:
A

Changed in this revision

RoboClaw.cpp Show annotated file Show diff for this revision Revisions of this file
RoboClaw.h Show annotated file Show diff for this revision Revisions of this file
UARTserial_mio/UARTSerial_mio.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 04d8899b5d82 -r 6a4969d25627 RoboClaw.cpp
--- a/RoboClaw.cpp	Wed Nov 06 10:57:21 2019 +0000
+++ b/RoboClaw.cpp	Tue Sep 14 12:09:42 2021 +0000
@@ -5,14 +5,14 @@
 #define SetDWORDval(arg) (uint8_t)(arg>>24),(uint8_t)(arg>>16),(uint8_t)(arg>>8),(uint8_t)arg
 #define SetWORDval(arg) (uint8_t)(arg>>8),(uint8_t)arg
 
-RoboClaw::RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx) : _roboclaw(rx, tx){
+RoboClaw::RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx, double _read_timeout) : _roboclaw(rx, tx){
     _roboclaw.set_baud(baudrate);//_roboclaw.baud(baudrate);
        
     rx_in = 0;
     address = adr;
-    readTime = 0.0;
-    readTimer.start();
-    read_timeout = 2.0;
+    //readTime = 0.0;
+    //readTimer.start();
+    read_timeout = _read_timeout;
     
 }
 
@@ -148,7 +148,7 @@
     }else{
         //printf("crc: %x \r\n", crc_get());
         //printf("received crc: %x \r\n", received_crc);
-        printf("err \r\n");
+        //printf("err \r\n");
 
 
         return false;        
diff -r 04d8899b5d82 -r 6a4969d25627 RoboClaw.h
--- a/RoboClaw.h	Wed Nov 06 10:57:21 2019 +0000
+++ b/RoboClaw.h	Tue Sep 14 12:09:42 2021 +0000
@@ -23,7 +23,7 @@
 public:
     /** Create RoboClaw instance
     */
-    RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx);
+    RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx, double _read_timeout);
     
     /** Forward and Backward functions
     * @param address address of the device
@@ -108,9 +108,9 @@
     char rx_buffer[7];
     // Circular buffer pointers
     // volatile makes read-modify-write atomic 
-    Timer readTimer;
-    double readTime;
-    double readTimePrec;
+    //Timer readTimer;
+    //double readTime;
+    //double readTimePrec;
     volatile int rx_in;
     double read_timeout;
     // Line buffers for sprintf and sscanf
diff -r 04d8899b5d82 -r 6a4969d25627 UARTserial_mio/UARTSerial_mio.cpp
--- a/UARTserial_mio/UARTSerial_mio.cpp	Wed Nov 06 10:57:21 2019 +0000
+++ b/UARTserial_mio/UARTSerial_mio.cpp	Tue Sep 14 12:09:42 2021 +0000
@@ -257,7 +257,7 @@
 
     api_lock();
 
-    while (_rxbuf.size()!=length) {
+    while (_rxbuf.size()!=length && tm<=timeout) {
         if (!_blocking) {
             api_unlock();
             return -EAGAIN;
@@ -270,10 +270,11 @@
     }
     
     //printf("tm: %f\r\n",tm);
-
-    while (data_read < length && !_rxbuf.empty()) {
+    tm = 0.0;
+    while (data_read < length && !_rxbuf.empty()  && tm<=timeout) {
         _rxbuf.pop(*ptr++);
         data_read++;
+        tm = tm + 0.001; //10/1000
     }
 
     core_util_critical_section_enter();