[Fawkes Git] branch/timn/robotino-direct: robotino: determine if controld3 is running in direct mode

Tim Niemueller niemueller at kbsg.rwth-aachen.de
Tue Apr 12 23:41:40 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  4734a2007ae5673f1c3543e45cc2967e3c681e50 (commit)
      from  65f0da04d5666dec75b0c1931147de84bbb25ca9 (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 4734a2007ae5673f1c3543e45cc2967e3c681e50
Author:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
AuthorDate: Tue Apr 12 23:41:07 2016 +0200
Commit:     Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
CommitDate: Tue Apr 12 23:41:07 2016 +0200

    robotino: determine if controld3 is running in direct mode
    
    Throw an exception if controld3 is still running. We need it to be
    stopped to take over communication with the base.

http://git.fawkesrobotics.org/fawkes.git/commit/4734a20
http://trac.fawkesrobotics.org/changeset/4734a20

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


- *Summary* -----------------------------------------------------------
 src/plugins/robotino/direct_com_thread.cpp |   62 ++++++++++++++++++++++++++++
 src/plugins/robotino/direct_com_thread.h   |    1 +
 src/plugins/robotino/robotino.mk           |    2 +-
 3 files changed, 64 insertions(+), 1 deletions(-)


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

- *commit* 4734a2007ae5673f1c3543e45cc2967e3c681e50 - - - - - - - - - -
Author:  Tim Niemueller <niemueller at kbsg.rwth-aachen.de>
Date:    Tue Apr 12 23:41:07 2016 +0200
Subject: robotino: determine if controld3 is running in direct mode

 src/plugins/robotino/direct_com_thread.cpp |   62 ++++++++++++++++++++++++++++
 src/plugins/robotino/direct_com_thread.h   |    1 +
 src/plugins/robotino/robotino.mk           |    2 +-
 3 files changed, 64 insertions(+), 1 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robotino/direct_com_thread.cpp b/src/plugins/robotino/direct_com_thread.cpp
index 1a77809..0b04679 100644
--- a/src/plugins/robotino/direct_com_thread.cpp
+++ b/src/plugins/robotino/direct_com_thread.cpp
@@ -38,6 +38,7 @@
 #include <boost/bind.hpp>
 #include <boost/lambda/bind.hpp>
 #include <boost/lambda/lambda.hpp>
+#include <boost/filesystem.hpp>
 
 using namespace fawkes;
 
@@ -73,6 +74,10 @@ DirectRobotinoComThread::init()
 
 	// -------------------------------------------------------------------------- //
 
+	if (find_controld3()) {
+		throw Exception("Found running controld3, stop using 'sudo initctl stop controld3'");
+	}
+
 	try {
 		cfg_device_ = config->get_string(("/hardware/robotino/direct/device"));
 	} catch (Exception &e) {
@@ -439,6 +444,63 @@ DirectRobotinoComThread::find_device_udev()
 	return cfg_device;
 }
 
+
+bool
+DirectRobotinoComThread::find_controld3()
+{
+	bool rv = false;
+	boost::filesystem::path p("/proc");
+
+	using namespace boost::filesystem;
+ 
+  try {
+	  if (boost::filesystem::exists(p) && boost::filesystem::is_directory(p)) {
+
+		  directory_iterator di;
+		  for (di = directory_iterator(p); di != directory_iterator(); ++di) {
+			  directory_entry &d = *di;
+			  //for (directory_entry &d : directory_iterator(p))
+			  std::string f = d.path().filename().native();
+			  bool is_process = true;
+			  for (std::string::size_type i = 0; i < f.length(); ++i) {
+				  if (! isdigit(f[i])) {
+					  is_process = false;
+					  break;
+				  }
+			  }
+			  if (is_process) {
+				  path pproc(d.path());
+				  pproc /= "stat";
+
+				  FILE *f = fopen(pproc.c_str(), "r");
+				  if (f) {
+					  int pid;
+					  char *procname;
+					  if (fscanf(f, "%d (%m[a-z0-9])", &pid, &procname) == 2) {
+						  
+						  if (strcmp("controld3", procname) == 0) {
+							  rv = true;
+						  }
+						  ::free(procname);
+					  }
+					  fclose(f);
+				  }
+			  }
+		  }
+
+	  } else {
+		  logger->log_warn(name(), "Cannot open /proc, cannot determine if controld3 is running");
+		  return false;
+	  }
+
+  } catch (const boost::filesystem::filesystem_error &ex) {
+	  logger->log_warn(name(), "Failure to determine if controld3 is running: %s", ex.what());
+	  return false;
+  }
+
+  return rv;
+}
+
 void
 DirectRobotinoComThread::open_device(bool wait_replies)
 {
diff --git a/src/plugins/robotino/direct_com_thread.h b/src/plugins/robotino/direct_com_thread.h
index f419604..1a53532 100644
--- a/src/plugins/robotino/direct_com_thread.h
+++ b/src/plugins/robotino/direct_com_thread.h
@@ -78,6 +78,7 @@ class DirectRobotinoComThread
 
  private:
 	std::string find_device_udev();
+	bool find_controld3();
 	void open_device(bool wait_replies);
 	void close_device();
 	void flush_device();
diff --git a/src/plugins/robotino/robotino.mk b/src/plugins/robotino/robotino.mk
index 5401f71..c8c0f62 100644
--- a/src/plugins/robotino/robotino.mk
+++ b/src/plugins/robotino/robotino.mk
@@ -50,7 +50,7 @@ ifeq ($(HAVE_LIBUSB),1)
   LDFLAGS_LIBUSB = $(shell $(PKGCONFIG) --libs 'libusb-1.0')
 endif
 
-ROBOTINO_DIRECT_REQ_BOOST_LIBS = thread asio system
+ROBOTINO_DIRECT_REQ_BOOST_LIBS = thread asio system filesystem
 HAVE_ROBOTINO_DIRECT_BOOST_LIBS = $(call boost-have-libs,$(ROBOTINO_DIRECT_REQ_BOOST_LIBS))
 ifeq ($(HAVE_ROBOTINO_DIRECT_BOOST_LIBS),1)
   CFLAGS_ROBOTINO_DIRECT_BOOST  = $(call boost-libs-cflags,$(ROBOTINO_DIRECT_REQ_BOOST_LIBS))




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


More information about the fawkes-commits mailing list