[Fawkes Git] branch/timn/robotino-direct: 2 revs updated. (0.5.0-3113-g11850b7)

Tim Niemueller niemueller at kbsg.rwth-aachen.de
Thu Jun 16 10:45:33 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, timn/robotino-direct has been updated
        to  11850b75b65468ccae033b9a1768fe43f3d113f3 (commit)
       via  7aae7cfbde27ae218844cd12e6f0e0555c0dfa5c (commit)
      from  7d9de92414f9268b847db72a06a8493ef47ab148 (commit)

http://git.fawkesrobotics.org/fawkes.git/timn/robotino-direct

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 7aae7cfbde27ae218844cd12e6f0e0555c0dfa5c
Author:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
AuthorDate: Wed Jun 15 12:23:31 2016 +0100
Commit:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
CommitDate: Wed Jun 15 12:23:31 2016 +0100

    robotino: improve checksum error handling
    
    Allow disabling warnings on checksum errors, add two configurable errors
    bounds after which recovery is tried or the connection is considered
    beyond repair and re-opened.

http://git.fawkesrobotics.org/fawkes.git/commit/7aae7cf
http://trac.fawkesrobotics.org/changeset/7aae7cf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 11850b75b65468ccae033b9a1768fe43f3d113f3
Author:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
AuthorDate: Wed Jun 15 12:24:18 2016 +0100
Commit:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
CommitDate: Wed Jun 15 12:24:18 2016 +0100

    robotino: default parameters for checksum error handling

http://git.fawkesrobotics.org/fawkes.git/commit/11850b7
http://trac.fawkesrobotics.org/changeset/11850b7

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 cfg/conf.d/robotino.yaml                    |   10 ++++++++++
 src/plugins/robotino/direct_com_message.cpp |   21 +++++++++++++++++++--
 src/plugins/robotino/direct_com_message.h   |    9 +++++++++
 src/plugins/robotino/direct_com_thread.cpp  |   26 ++++++++++++++++++++++++++
 src/plugins/robotino/direct_com_thread.h    |    6 +++++-
 5 files changed, 69 insertions(+), 3 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* 7aae7cfbde27ae218844cd12e6f0e0555c0dfa5c - - - - - - - - - -
Author:  Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
Date:    Wed Jun 15 12:23:31 2016 +0100
Subject: robotino: improve checksum error handling

 src/plugins/robotino/direct_com_message.cpp |   21 +++++++++++++++++++--
 src/plugins/robotino/direct_com_message.h   |    9 +++++++++
 src/plugins/robotino/direct_com_thread.cpp  |   26 ++++++++++++++++++++++++++
 src/plugins/robotino/direct_com_thread.h    |    6 +++++-
 4 files changed, 59 insertions(+), 3 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robotino/direct_com_message.cpp b/src/plugins/robotino/direct_com_message.cpp
index 07a0abe..cdae1d8 100644
--- a/src/plugins/robotino/direct_com_message.cpp
+++ b/src/plugins/robotino/direct_com_message.cpp
@@ -35,6 +35,23 @@ const unsigned char DirectRobotinoComMessage::MSG_DATA_MANGLE = 0x20;
 const unsigned int DirectRobotinoComMessage::MSG_METADATA_SIZE = 5;
 /// @endcond INTERNAL
 
+/** @class DirectRobotinoComMessage::ChecksumError "direct_com_message.h"
+ * Excpetion thrown on checksum errors.
+ */
+
+/** Constructor.
+ * @param expected expected checksum
+ * @param received actually received checksm
+ * @param byte1 First byte of actually received checksum
+ * @param byte2 Second byte of actually received checksum
+ */
+DirectRobotinoComMessage::ChecksumError::ChecksumError(unsigned int expected, unsigned int received,
+                                                       unsigned char byte1, unsigned char byte2)
+	: Exception("Checksum verification error for Robotino message, "
+	            "expected %u, got %u (%02x %02x)", expected, received, byte1, byte2)
+{
+}
+
 /** @class DirectRobotinoComMessage "direct_com_message.h"
  * Robotino communication message.
  *
@@ -812,8 +829,8 @@ DirectRobotinoComMessage::check_checksum() const
 	uint16_t checksum_v = checksum();
 	uint16_t packet_checksum = parse_uint16(&data_[payload_size_ + 3]);
 	if (checksum_v != packet_checksum) {
-		throw Exception("Checksum verification error for Robotino message, expected %u, got %u (%02x %02x)",
-		                checksum_v, packet_checksum, data_[payload_size_ + 3], data_[payload_size_ + 4]);
+		throw ChecksumError(checksum_v, packet_checksum,
+		                    data_[payload_size_ + 3], data_[payload_size_ + 4]);
 	}
 }
 
diff --git a/src/plugins/robotino/direct_com_message.h b/src/plugins/robotino/direct_com_message.h
index ba3556e..3b8b1de 100644
--- a/src/plugins/robotino/direct_com_message.h
+++ b/src/plugins/robotino/direct_com_message.h
@@ -21,6 +21,8 @@
 #ifndef __PLUGINS_ROBOTINO_DIRECT_COM_MESSAGE_H_
 #define __PLUGINS_ROBOTINO_DIRECT_COM_MESSAGE_H_
 
+#include <core/exception.h>
+
 #include <cstdint>
 #include <boost/asio.hpp>
 
@@ -142,6 +144,13 @@ class DirectRobotinoComMessage
 	static const unsigned int  MSG_METADATA_SIZE;
 	/// @endcond INTERNAL
 
+	class ChecksumError : public fawkes::Exception
+	{
+	public:
+		ChecksumError(unsigned int expected, unsigned int received,
+		              unsigned char byte1, unsigned char byte2);
+	};
+
 	DirectRobotinoComMessage();
 	DirectRobotinoComMessage(command_id_t cmdid);
 	DirectRobotinoComMessage(const unsigned char *msg, size_t msg_size);
diff --git a/src/plugins/robotino/direct_com_thread.cpp b/src/plugins/robotino/direct_com_thread.cpp
index 9fb3a63..0830a29 100644
--- a/src/plugins/robotino/direct_com_thread.cpp
+++ b/src/plugins/robotino/direct_com_thread.cpp
@@ -74,6 +74,9 @@ DirectRobotinoComThread::init()
 	cfg_nodata_timeout_ = config->get_uint("/hardware/robotino/direct/no-data-timeout");
 	cfg_drive_update_interval_ = config->get_uint("/hardware/robotino/direct/drive-update-interval");
 	cfg_read_timeout_ = config->get_uint("/hardware/robotino/direct/read-timeout");
+	cfg_log_checksum_errors_ = config->get_bool("/hardware/robotino/direct/checksums/log-errors");
+	cfg_checksum_error_recover_ = config->get_bool("/hardware/robotino/direct/checksums/recover-bound");
+	cfg_checksum_error_critical_ = config->get_bool("/hardware/robotino/direct/checksums/critical-bound");
 	
 	// -------------------------------------------------------------------------- //
 
@@ -101,6 +104,7 @@ DirectRobotinoComThread::init()
 
 	open_device(/* wait for replies */ true);
 	open_tries_ = 0;
+	checksum_errors_ = 0;
 
 	{ // Disable all digital outputs initially
 		DirectRobotinoComMessage req(DirectRobotinoComMessage::CMDID_SET_ALL_DIGITAL_OUTPUTS);
@@ -152,8 +156,30 @@ DirectRobotinoComThread::loop()
 	if (opened_) {
 		try {
 			DirectRobotinoComMessage::pointer m = read_packet();
+			checksum_errors_ = 0;
 			process_message(m);
 			update_nodata_timer();
+		} catch (DirectRobotinoComMessage::ChecksumError &ce) {
+			if (! finalize_prepared && opened_) {
+				checksum_errors_ += 1;
+				if (cfg_log_checksum_errors_) {
+					logger->log_warn(name(), "%s [%u consecutive errors]",
+					                 ce.what_no_backtrace(), checksum_errors_);
+				}
+				if (checksum_errors_ >= cfg_checksum_error_recover_) {
+					logger->log_warn(name(), "Large number of consecutive checksum errors, trying recover");
+					input_buffer_.consume(input_buffer_.size());
+					try {
+						DirectRobotinoComMessage req(DirectRobotinoComMessage::CMDID_GET_HW_VERSION);
+						send_message(req);
+						request_data();
+					} catch (Exception &e) {}
+				} else if (checksum_errors_ >= cfg_checksum_error_critical_) {
+					logger->log_error(name(), "Critical number of consecutive checksum errors, re-opening");
+					input_buffer_.consume(input_buffer_.size());
+					close_device();
+				}
+			}
 		} catch (Exception &e) {
 			if (! finalize_prepared) {
 				if (opened_) {
diff --git a/src/plugins/robotino/direct_com_thread.h b/src/plugins/robotino/direct_com_thread.h
index 6ee3660..e6db480 100644
--- a/src/plugins/robotino/direct_com_thread.h
+++ b/src/plugins/robotino/direct_com_thread.h
@@ -107,11 +107,15 @@ class DirectRobotinoComThread
 	unsigned int    cfg_nodata_timeout_;
 	unsigned int    cfg_drive_update_interval_;
 	unsigned int    cfg_read_timeout_;
-
+	bool            cfg_log_checksum_errors_;
+	bool            cfg_checksum_error_recover_;
+	bool            cfg_checksum_error_critical_;
 	
 	bool opened_;
 	unsigned int open_tries_;
 
+	unsigned int checksum_errors_;
+
 	uint8_t         digital_outputs_;
 
 	boost::asio::io_service       io_service_;

- *commit* 11850b75b65468ccae033b9a1768fe43f3d113f3 - - - - - - - - - -
Author:  Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
Date:    Wed Jun 15 12:24:18 2016 +0100
Subject: robotino: default parameters for checksum error handling

 cfg/conf.d/robotino.yaml |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/cfg/conf.d/robotino.yaml b/cfg/conf.d/robotino.yaml
index 44aa840..d12e879 100644
--- a/cfg/conf.d/robotino.yaml
+++ b/cfg/conf.d/robotino.yaml
@@ -58,6 +58,16 @@ hardware/robotino:
     # Timeout in milliseconds for a single read operation
     read-timeout: 200
 
+    checksums:
+      # Log all checksum errors as a warning?
+      # If disabled only recover and critical errors are logged
+      log-errors: true
+      # The number of consecutive checksum errors after which to attempt
+      # recovery (flushing buffer, sending ping)
+      recover-bound: 2
+      # The number of consecutive checksum errors after which to consider
+      # the connection dead and try to re-establish the connection
+      critical-bound: 25
 
   # The motor and drive settings and limits are enforced for direct
   # communication, for the openrobotino driver, these values are




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list